mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -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_
|
||||
#define _LIGHTINGSHADERGEN_H_
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
#include "ShaderGenCommon.h"
|
||||
#include "NativeVertexFormat.h"
|
||||
#include "XFMemory.h"
|
||||
|
||||
// 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)
|
||||
{
|
||||
#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 char* swizzle = "xyzw";
|
||||
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
|
||||
// inColorName is color 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)
|
||||
{
|
||||
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))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)))
|
||||
GenerateLightShader<T,type>(object, i, j+2, lightsName, 2);
|
||||
GenerateLightShader<T,UidType>(object, i, j+2, lightsName, 2);
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <cmath>
|
||||
#include <assert.h>
|
||||
#include <locale.h>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "LightingShaderGen.h"
|
||||
#include "PixelShaderGen.h"
|
||||
@ -37,10 +38,10 @@
|
||||
// output is given by .outreg
|
||||
// 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, GenOutput type> 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, GenOutput type> static void WriteFog(T& out);
|
||||
template<class T> static void WriteStage(char *&p, int n, 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> static void WriteAlphaTest(T& out, API_TYPE ApiType,DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth);
|
||||
template<class T> static void WriteFog(T& out);
|
||||
|
||||
static const char *tevKSelTableC[] = // KCSEL
|
||||
{
|
||||
@ -266,13 +267,13 @@ const char *WriteLocation(API_TYPE ApiType)
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class T, GenOutput type>
|
||||
template<class T>
|
||||
void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
|
||||
{
|
||||
// TODO: Can be optimized if using alpha pass
|
||||
#define SetUidField(name, value) if (type == GO_ShaderUid) {out.GetUidData().name = value; };
|
||||
#define OR_UidField(name, value) if (type == GO_ShaderUid) {out.GetUidData().name |= value; };
|
||||
if (type == GO_ShaderCode)
|
||||
#define SetUidField(name, value) if (typeid(T) == typeid(PixelShaderUid)) {out.GetUidData().name = value; };
|
||||
#define OR_UidField(name, value) if (typeid(T) == typeid(PixelShaderUid)) {out.GetUidData().name |= value; };
|
||||
if (typeid(T) == typeid(PixelShaderCode))
|
||||
{
|
||||
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
|
||||
out.SetBuffer(text);
|
||||
@ -558,7 +559,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
|
||||
|
||||
char buffer[32];
|
||||
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
|
||||
BuildSwapModeTable();
|
||||
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)
|
||||
{
|
||||
@ -604,7 +605,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
|
||||
AlphaTest::TEST_RESULT Pretest = bpmem.alpha_test.TestResult();
|
||||
SetUidField(Pretest, Pretest);
|
||||
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
|
||||
@ -648,7 +649,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteFog<T, type>(out);
|
||||
WriteFog<T>(out);
|
||||
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)
|
||||
{
|
||||
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];
|
||||
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
|
||||
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");
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
out.SetConstantsUsed(C_TEXDIMS+texmap,C_TEXDIMS+texmap);
|
||||
@ -1120,7 +1121,7 @@ static const char *tevAlphaFunclogicTable[] =
|
||||
" == " // 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 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
|
||||
};
|
||||
|
||||
template<class T, GenOutput type>
|
||||
template<class T>
|
||||
static void WriteFog(T& out)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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?
|
||||
};
|
||||
|
||||
enum GenOutput
|
||||
{
|
||||
GO_ShaderCode,
|
||||
GO_ShaderUid,
|
||||
GO_ShaderConstantProfile,
|
||||
};
|
||||
|
||||
#endif // _SHADERGENCOMMON_H
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <math.h>
|
||||
#include <locale.h>
|
||||
#include <typeinfo>
|
||||
|
||||
#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 *WriteLocation(API_TYPE api_type);
|
||||
|
||||
template<class T, GenOutput type>
|
||||
template<class T>
|
||||
void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
|
||||
{
|
||||
#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);
|
||||
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.
|
||||
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)
|
||||
{
|
||||
@ -522,16 +523,16 @@ void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
|
||||
|
||||
/// if (text[sizeof(text) - 1] != 0x7C)
|
||||
/// PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");
|
||||
if (type == GO_ShaderCode)
|
||||
if (typeid(T) == typeid(VertexShaderCode))
|
||||
setlocale(LC_NUMERIC, ""); // restore locale
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
GenerateVertexShader<VertexShaderCode, GO_ShaderCode>(object, components, api_type);
|
||||
GenerateVertexShader<VertexShaderCode>(object, components, api_type);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user