mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 13:57:57 -07:00
ShaderGenCommon: Replace the GenOutput enum by using typeid instead.
This commit is contained in:
parent
0e31943216
commit
364a5093d9
@ -18,15 +18,17 @@
|
|||||||
#ifndef _LIGHTINGSHADERGEN_H_
|
#ifndef _LIGHTINGSHADERGEN_H_
|
||||||
#define _LIGHTINGSHADERGEN_H_
|
#define _LIGHTINGSHADERGEN_H_
|
||||||
|
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
#include "ShaderGenCommon.h"
|
#include "ShaderGenCommon.h"
|
||||||
#include "NativeVertexFormat.h"
|
#include "NativeVertexFormat.h"
|
||||||
#include "XFMemory.h"
|
#include "XFMemory.h"
|
||||||
|
|
||||||
// T.uid_data needs to have a struct named lighting_uid
|
// T.uid_data needs to have a struct named lighting_uid
|
||||||
template<class T, GenOutput type>
|
template<class T,class UidType>
|
||||||
void GenerateLightShader(T& object, int index, int litchan_index, const char* lightsName, int coloralpha)
|
void GenerateLightShader(T& object, int index, int litchan_index, const char* lightsName, int coloralpha)
|
||||||
{
|
{
|
||||||
#define SetUidField(name, value) if (type == GO_ShaderUid) { object.GetUidData().name = value; };
|
#define SetUidField(name, value) if (typeid(T) == typeid(UidType)) { object.GetUidData().name = value; };
|
||||||
const LitChannel& chan = (litchan_index > 1) ? xfregs.alpha[litchan_index-2] : xfregs.color[litchan_index];
|
const LitChannel& chan = (litchan_index > 1) ? xfregs.alpha[litchan_index-2] : xfregs.color[litchan_index];
|
||||||
const char* swizzle = "xyzw";
|
const char* swizzle = "xyzw";
|
||||||
if (coloralpha == 1 ) swizzle = "xyz";
|
if (coloralpha == 1 ) swizzle = "xyz";
|
||||||
@ -92,7 +94,7 @@ void GenerateLightShader(T& object, int index, int litchan_index, const char* li
|
|||||||
// materials name is I_MATERIALS in vs and I_PMATERIALS in ps
|
// materials name is I_MATERIALS in vs and I_PMATERIALS in ps
|
||||||
// inColorName is color in vs and colors_ in ps
|
// inColorName is color in vs and colors_ in ps
|
||||||
// dest is o.colors_ in vs and colors_ in ps
|
// dest is o.colors_ in vs and colors_ in ps
|
||||||
template<class T, GenOutput type>
|
template<class T, class UidType>
|
||||||
void GenerateLightingShader(T& object, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest)
|
void GenerateLightingShader(T& object, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest)
|
||||||
{
|
{
|
||||||
for (unsigned int j = 0; j < xfregs.numChan.numColorChans; j++)
|
for (unsigned int j = 0; j < xfregs.numChan.numColorChans; j++)
|
||||||
@ -186,7 +188,7 @@ void GenerateLightingShader(T& object, int components, const char* materialsName
|
|||||||
{
|
{
|
||||||
if (mask & (1<<i))
|
if (mask & (1<<i))
|
||||||
{
|
{
|
||||||
GenerateLightShader<T,type>(object, i, j, lightsName, 3);
|
GenerateLightShader<T,UidType>(object, i, j, lightsName, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,9 +198,9 @@ void GenerateLightingShader(T& object, int components, const char* materialsName
|
|||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
if (!(mask&(1<<i)) && (color.GetFullLightMask() & (1<<i)))
|
if (!(mask&(1<<i)) && (color.GetFullLightMask() & (1<<i)))
|
||||||
GenerateLightShader<T,type>(object, i, j, lightsName, 1);
|
GenerateLightShader<T,UidType>(object, i, j, lightsName, 1);
|
||||||
if (!(mask&(1<<i)) && (alpha.GetFullLightMask() & (1<<i)))
|
if (!(mask&(1<<i)) && (alpha.GetFullLightMask() & (1<<i)))
|
||||||
GenerateLightShader<T,type>(object, i, j+2, lightsName, 2);
|
GenerateLightShader<T,UidType>(object, i, j+2, lightsName, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (color.enablelighting || alpha.enablelighting)
|
else if (color.enablelighting || alpha.enablelighting)
|
||||||
@ -212,7 +214,7 @@ void GenerateLightingShader(T& object, int components, const char* materialsName
|
|||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
if (workingchannel.GetFullLightMask() & (1<<i))
|
if (workingchannel.GetFullLightMask() & (1<<i))
|
||||||
GenerateLightShader<T,type>(object, i, lit_index, lightsName, coloralpha);
|
GenerateLightShader<T,UidType>(object, i, lit_index, lightsName, coloralpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
object.Write("%s%d = mat * saturate(lacc);\n", dest, j);
|
object.Write("%s%d = mat * saturate(lacc);\n", dest, j);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
#include "LightingShaderGen.h"
|
#include "LightingShaderGen.h"
|
||||||
#include "PixelShaderGen.h"
|
#include "PixelShaderGen.h"
|
||||||
@ -37,10 +38,10 @@
|
|||||||
// output is given by .outreg
|
// output is given by .outreg
|
||||||
// tevtemp is set according to swapmodetables and
|
// tevtemp is set according to swapmodetables and
|
||||||
|
|
||||||
template<class T, GenOutput type> static void WriteStage(char *&p, int n, API_TYPE ApiType);
|
template<class T> static void WriteStage(char *&p, int n, API_TYPE ApiType);
|
||||||
template<class T, GenOutput type> static void SampleTexture(T& out, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType);
|
template<class T> static void SampleTexture(T& out, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType);
|
||||||
template<class T, GenOutput type> static void WriteAlphaTest(T& out, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth);
|
template<class T> static void WriteAlphaTest(T& out, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth);
|
||||||
template<class T, GenOutput type> static void WriteFog(T& out);
|
template<class T> static void WriteFog(T& out);
|
||||||
|
|
||||||
static const char *tevKSelTableC[] = // KCSEL
|
static const char *tevKSelTableC[] = // KCSEL
|
||||||
{
|
{
|
||||||
@ -266,13 +267,13 @@ const char *WriteLocation(API_TYPE ApiType)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, GenOutput type>
|
template<class T>
|
||||||
void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
|
void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
|
||||||
{
|
{
|
||||||
// TODO: Can be optimized if using alpha pass
|
// TODO: Can be optimized if using alpha pass
|
||||||
#define SetUidField(name, value) if (type == GO_ShaderUid) {out.GetUidData().name = value; };
|
#define SetUidField(name, value) if (typeid(T) == typeid(PixelShaderUid)) {out.GetUidData().name = value; };
|
||||||
#define OR_UidField(name, value) if (type == GO_ShaderUid) {out.GetUidData().name |= value; };
|
#define OR_UidField(name, value) if (typeid(T) == typeid(PixelShaderUid)) {out.GetUidData().name |= value; };
|
||||||
if (type == GO_ShaderCode)
|
if (typeid(T) == typeid(PixelShaderCode))
|
||||||
{
|
{
|
||||||
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
|
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
|
||||||
out.SetBuffer(text);
|
out.SetBuffer(text);
|
||||||
@ -558,7 +559,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
|
|||||||
|
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
sprintf(buffer, "float3 indtex%d", i);
|
sprintf(buffer, "float3 indtex%d", i);
|
||||||
SampleTexture<T, type>(out, buffer, "tempcoord", "abg", texmap, ApiType);
|
SampleTexture<T>(out, buffer, "tempcoord", "abg", texmap, ApiType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,7 +576,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
|
|||||||
// Uid fields for BuildSwapModeTable are set in WriteStage
|
// Uid fields for BuildSwapModeTable are set in WriteStage
|
||||||
BuildSwapModeTable();
|
BuildSwapModeTable();
|
||||||
for (unsigned int i = 0; i < numStages; i++)
|
for (unsigned int i = 0; i < numStages; i++)
|
||||||
WriteStage<T, type>(out, i, ApiType); // build the equation for this stage
|
WriteStage<T>(out, i, ApiType); // build the equation for this stage
|
||||||
|
|
||||||
if (numStages)
|
if (numStages)
|
||||||
{
|
{
|
||||||
@ -604,7 +605,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
|
|||||||
AlphaTest::TEST_RESULT Pretest = bpmem.alpha_test.TestResult();
|
AlphaTest::TEST_RESULT Pretest = bpmem.alpha_test.TestResult();
|
||||||
SetUidField(Pretest, Pretest);
|
SetUidField(Pretest, Pretest);
|
||||||
if (Pretest == AlphaTest::UNDETERMINED)
|
if (Pretest == AlphaTest::UNDETERMINED)
|
||||||
WriteAlphaTest<T, type>(out, ApiType, dstAlphaMode, per_pixel_depth);
|
WriteAlphaTest<T>(out, ApiType, dstAlphaMode, per_pixel_depth);
|
||||||
|
|
||||||
|
|
||||||
// the screen space depth value = far z + (clip z / clip w) * z range
|
// the screen space depth value = far z + (clip z / clip w) * z range
|
||||||
@ -648,7 +649,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
WriteFog<T, type>(out);
|
WriteFog<T>(out);
|
||||||
out.Write("\tocol0 = prev;\n");
|
out.Write("\tocol0 = prev;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,7 +717,7 @@ static const char *TEVCMPAlphaOPTable[16] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<class T, GenOutput type>
|
template<class T>
|
||||||
static void WriteStage(T& out, int n, API_TYPE ApiType)
|
static void WriteStage(T& out, int n, API_TYPE ApiType)
|
||||||
{
|
{
|
||||||
int texcoord = bpmem.tevorders[n/2].getTexCoord(n&1);
|
int texcoord = bpmem.tevorders[n/2].getTexCoord(n&1);
|
||||||
@ -865,7 +866,7 @@ static void WriteStage(T& out, int n, API_TYPE ApiType)
|
|||||||
|
|
||||||
char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap];
|
char *texswap = swapModeTable[bpmem.combiners[n].alphaC.tswap];
|
||||||
int texmap = bpmem.tevorders[n/2].getTexMap(n&1);
|
int texmap = bpmem.tevorders[n/2].getTexMap(n&1);
|
||||||
SampleTexture<T, type>(out, "textemp", "tevcoord", texswap, texmap, ApiType);
|
SampleTexture<T>(out, "textemp", "tevcoord", texswap, texmap, ApiType);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
out.Write("textemp = float4(1.0f, 1.0f, 1.0f, 1.0f);\n");
|
out.Write("textemp = float4(1.0f, 1.0f, 1.0f, 1.0f);\n");
|
||||||
@ -1090,7 +1091,7 @@ static void WriteStage(T& out, int n, API_TYPE ApiType)
|
|||||||
out.Write("// TEV done\n");
|
out.Write("// TEV done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, GenOutput type>
|
template<class T>
|
||||||
void SampleTexture(T& out, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType)
|
void SampleTexture(T& out, const char *destination, const char *texcoords, const char *texswap, int texmap, API_TYPE ApiType)
|
||||||
{
|
{
|
||||||
out.SetConstantsUsed(C_TEXDIMS+texmap,C_TEXDIMS+texmap);
|
out.SetConstantsUsed(C_TEXDIMS+texmap,C_TEXDIMS+texmap);
|
||||||
@ -1120,7 +1121,7 @@ static const char *tevAlphaFunclogicTable[] =
|
|||||||
" == " // xnor
|
" == " // xnor
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T, GenOutput type>
|
template<class T>
|
||||||
static void WriteAlphaTest(T& out, API_TYPE ApiType, DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth)
|
static void WriteAlphaTest(T& out, API_TYPE ApiType, DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth)
|
||||||
{
|
{
|
||||||
static const char *alphaRef[2] =
|
static const char *alphaRef[2] =
|
||||||
@ -1188,7 +1189,7 @@ static const char *tevFogFuncsTable[] =
|
|||||||
"\tfog = 1.0f - fog;\n fog = pow(2.0f, -8.0f * fog * fog);\n" //backward exp2
|
"\tfog = 1.0f - fog;\n fog = pow(2.0f, -8.0f * fog * fog);\n" //backward exp2
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T, GenOutput type>
|
template<class T>
|
||||||
static void WriteFog(T& out)
|
static void WriteFog(T& out)
|
||||||
{
|
{
|
||||||
SetUidField(fog.fsel, bpmem.fog.c_proj_fsel.fsel);
|
SetUidField(fog.fsel, bpmem.fog.c_proj_fsel.fsel);
|
||||||
@ -1240,16 +1241,16 @@ static void WriteFog(T& out)
|
|||||||
|
|
||||||
void GetPixelShaderUid(PixelShaderUid& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
|
void GetPixelShaderUid(PixelShaderUid& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
|
||||||
{
|
{
|
||||||
GeneratePixelShader<PixelShaderUid, GO_ShaderUid>(object, dstAlphaMode, ApiType, components);
|
GeneratePixelShader<PixelShaderUid>(object, dstAlphaMode, ApiType, components);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneratePixelShaderCode(PixelShaderCode& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
|
void GeneratePixelShaderCode(PixelShaderCode& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
|
||||||
{
|
{
|
||||||
GeneratePixelShader<PixelShaderCode, GO_ShaderCode>(object, dstAlphaMode, ApiType, components);
|
GeneratePixelShader<PixelShaderCode>(object, dstAlphaMode, ApiType, components);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetPixelShaderConstantProfile(PixelShaderConstantProfile& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
|
void GetPixelShaderConstantProfile(PixelShaderConstantProfile& object, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
|
||||||
{
|
{
|
||||||
GeneratePixelShader<PixelShaderConstantProfile, GO_ShaderCode>(object, dstAlphaMode, ApiType, components);
|
GeneratePixelShader<PixelShaderConstantProfile>(object, dstAlphaMode, ApiType, components);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,11 +123,4 @@ private:
|
|||||||
std::vector<bool> constant_usage; // TODO: Is vector<bool> appropriate here?
|
std::vector<bool> constant_usage; // TODO: Is vector<bool> appropriate here?
|
||||||
};
|
};
|
||||||
|
|
||||||
enum GenOutput
|
|
||||||
{
|
|
||||||
GO_ShaderCode,
|
|
||||||
GO_ShaderUid,
|
|
||||||
GO_ShaderConstantProfile,
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // _SHADERGENCOMMON_H
|
#endif // _SHADERGENCOMMON_H
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
#include "NativeVertexFormat.h"
|
#include "NativeVertexFormat.h"
|
||||||
|
|
||||||
@ -80,13 +81,13 @@ void GenerateVSOutputStruct(T& object, u32 components, API_TYPE api_type)
|
|||||||
extern const char *WriteRegister(API_TYPE api_type, const char *prefix, const u32 num);
|
extern const char *WriteRegister(API_TYPE api_type, const char *prefix, const u32 num);
|
||||||
extern const char *WriteLocation(API_TYPE api_type);
|
extern const char *WriteLocation(API_TYPE api_type);
|
||||||
|
|
||||||
template<class T, GenOutput type>
|
template<class T>
|
||||||
void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
|
void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
|
||||||
{
|
{
|
||||||
#undef SetUidField
|
#undef SetUidField
|
||||||
#define SetUidField(name, value) if (type == GO_ShaderUid) {out.GetUidData().name = value; };
|
#define SetUidField(name, value) if (typeid(T) == typeid(VertexShaderUid)) {out.GetUidData().name = value; };
|
||||||
|
|
||||||
if (type == GO_ShaderCode)
|
if (typeid(T) == typeid(VertexShaderCode))
|
||||||
{
|
{
|
||||||
out.SetBuffer(text);
|
out.SetBuffer(text);
|
||||||
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
|
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
|
||||||
@ -275,7 +276,7 @@ void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This probably isn't necessary if pixel lighting is enabled.
|
// TODO: This probably isn't necessary if pixel lighting is enabled.
|
||||||
GenerateLightingShader<T,type>(out, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_");
|
GenerateLightingShader<T,VertexShaderUid>(out, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_");
|
||||||
|
|
||||||
if (xfregs.numChan.numColorChans < 2)
|
if (xfregs.numChan.numColorChans < 2)
|
||||||
{
|
{
|
||||||
@ -522,16 +523,16 @@ void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
|
|||||||
|
|
||||||
/// if (text[sizeof(text) - 1] != 0x7C)
|
/// if (text[sizeof(text) - 1] != 0x7C)
|
||||||
/// PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");
|
/// PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");
|
||||||
if (type == GO_ShaderCode)
|
if (typeid(T) == typeid(VertexShaderCode))
|
||||||
setlocale(LC_NUMERIC, ""); // restore locale
|
setlocale(LC_NUMERIC, ""); // restore locale
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetVertexShaderUid(VertexShaderUid& object, u32 components, API_TYPE api_type)
|
void GetVertexShaderUid(VertexShaderUid& object, u32 components, API_TYPE api_type)
|
||||||
{
|
{
|
||||||
GenerateVertexShader<VertexShaderUid, GO_ShaderUid>(object, components, api_type);
|
GenerateVertexShader<VertexShaderUid>(object, components, api_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenerateVertexShaderCode(VertexShaderCode& object, u32 components, API_TYPE api_type)
|
void GenerateVertexShaderCode(VertexShaderCode& object, u32 components, API_TYPE api_type)
|
||||||
{
|
{
|
||||||
GenerateVertexShader<VertexShaderCode, GO_ShaderCode>(object, components, api_type);
|
GenerateVertexShader<VertexShaderCode>(object, components, api_type);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user