First steps of making the pixel shader uid struct more compact.

This commit is contained in:
NeoBrainX 2013-05-01 11:39:30 +02:00
parent 9cb263ad48
commit 32b78a8572
5 changed files with 181 additions and 205 deletions

View File

@ -54,8 +54,8 @@ static void GenerateLightShader(T& object, LightingUidData& uid_data, int index,
else if (coloralpha == 2) else if (coloralpha == 2)
swizzle = "w"; swizzle = "w";
uid_data.lit_chans[litchan_index].attnfunc = chan.attnfunc; uid_data.attnfunc |= chan.attnfunc << (2*litchan_index);
uid_data.lit_chans[litchan_index].diffusefunc = chan.diffusefunc; uid_data.diffusefunc |= chan.diffusefunc << (2*litchan_index);
if (!(chan.attnfunc & 1)) if (!(chan.attnfunc & 1))
{ {
// atten disabled // atten disabled
@ -124,7 +124,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
object.Write("{\n"); object.Write("{\n");
uid_data.lit_chans[j].matsource = xfregs.color[j].matsource; uid_data.matsource |= xfregs.color[j].matsource << j;
if (color.matsource) // from vertex if (color.matsource) // from vertex
{ {
if (components & (VB_HAS_COL0 << j)) if (components & (VB_HAS_COL0 << j))
@ -139,10 +139,10 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
object.Write("mat = %s[%d];\n", materialsName, j+2); object.Write("mat = %s[%d];\n", materialsName, j+2);
} }
uid_data.lit_chans[j].enablelighting = xfregs.color[j].enablelighting; uid_data.enablelighting |= xfregs.color[j].enablelighting << j;
if (color.enablelighting) if (color.enablelighting)
{ {
uid_data.lit_chans[j].ambsource = xfregs.color[j].ambsource; uid_data.ambsource |= xfregs.color[j].ambsource << j;
if (color.ambsource) // from vertex if (color.ambsource) // from vertex
{ {
if (components & (VB_HAS_COL0<<j) ) if (components & (VB_HAS_COL0<<j) )
@ -163,7 +163,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
} }
// check if alpha is different // check if alpha is different
uid_data.lit_chans[j+2].matsource = xfregs.alpha[j].matsource; uid_data.matsource |= xfregs.alpha[j].matsource << (j+2);
if (alpha.matsource != color.matsource) if (alpha.matsource != color.matsource)
{ {
if (alpha.matsource) // from vertex if (alpha.matsource) // from vertex
@ -180,10 +180,10 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
} }
} }
uid_data.lit_chans[j+2].enablelighting = xfregs.alpha[j].enablelighting; uid_data.enablelighting |= xfregs.alpha[j].enablelighting << (j+2);
if (alpha.enablelighting) if (alpha.enablelighting)
{ {
uid_data.lit_chans[j+2].ambsource = xfregs.alpha[j].ambsource; uid_data.ambsource |= xfregs.alpha[j].ambsource << (j+2);
if (alpha.ambsource) // from vertex if (alpha.ambsource) // from vertex
{ {
if (components & (VB_HAS_COL0<<j) ) if (components & (VB_HAS_COL0<<j) )
@ -207,12 +207,12 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
{ {
// both have lighting, test if they use the same lights // both have lighting, test if they use the same lights
int mask = 0; int mask = 0;
uid_data.lit_chans[j].attnfunc = color.attnfunc; uid_data.attnfunc |= color.attnfunc << (2*j);
uid_data.lit_chans[j+2].attnfunc = alpha.attnfunc; uid_data.attnfunc |= alpha.attnfunc << (2*(j+2));
uid_data.lit_chans[j].diffusefunc = color.diffusefunc; uid_data.diffusefunc |= color.diffusefunc << (2*j);
uid_data.lit_chans[j+2].diffusefunc = alpha.diffusefunc; uid_data.diffusefunc |= alpha.diffusefunc << (2*(j+2));
uid_data.lit_chans[j].light_mask = color.GetFullLightMask(); uid_data.light_mask |= color.GetFullLightMask() << (8*j);
uid_data.lit_chans[j+2].light_mask = alpha.GetFullLightMask(); uid_data.light_mask |= alpha.GetFullLightMask() << (8*(j+2));
if(color.lightparams == alpha.lightparams) if(color.lightparams == alpha.lightparams)
{ {
mask = color.GetFullLightMask() & alpha.GetFullLightMask(); mask = color.GetFullLightMask() & alpha.GetFullLightMask();
@ -244,7 +244,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com
const int lit_index = color.enablelighting ? j : (j+2); const int lit_index = color.enablelighting ? j : (j+2);
int coloralpha = color.enablelighting ? 1 : 2; int coloralpha = color.enablelighting ? 1 : 2;
uid_data.lit_chans[lit_index].light_mask = workingchannel.GetFullLightMask(); uid_data.light_mask |= workingchannel.GetFullLightMask() << (8*lit_index);
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
{ {
if (workingchannel.GetFullLightMask() & (1<<i)) if (workingchannel.GetFullLightMask() & (1<<i))

View File

@ -241,6 +241,8 @@ static void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE Api
pixel_shader_uid_data& uid_data = (&out.template GetUidData<pixel_shader_uid_data>() != NULL) pixel_shader_uid_data& uid_data = (&out.template GetUidData<pixel_shader_uid_data>() != NULL)
? out.template GetUidData<pixel_shader_uid_data>() : dummy_data; ? out.template GetUidData<pixel_shader_uid_data>() : dummy_data;
ERROR_LOG(VIDEO, "%lu", sizeof(pixel_shader_uid_data));
out.SetBuffer(text); out.SetBuffer(text);
if (out.GetBuffer() != NULL) if (out.GetBuffer() != NULL)
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
@ -257,9 +259,9 @@ static void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE Api
numStages, numTexgen, bpmem.genMode.numindstages); numStages, numTexgen, bpmem.genMode.numindstages);
uid_data.dstAlphaMode = dstAlphaMode; uid_data.dstAlphaMode = dstAlphaMode;
uid_data.genMode.numindstages = bpmem.genMode.numindstages; uid_data.genMode_numindstages = bpmem.genMode.numindstages;
uid_data.genMode.numtevstages = bpmem.genMode.numtevstages; uid_data.genMode_numtevstages = bpmem.genMode.numtevstages;
uid_data.genMode.numtexgens = bpmem.genMode.numtexgens; uid_data.genMode_numtexgens = bpmem.genMode.numtexgens;
if (ApiType == API_OPENGL) if (ApiType == API_OPENGL)
{ {
@ -466,7 +468,7 @@ static void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE Api
for (unsigned int i = 0; i < numTexgen; ++i) for (unsigned int i = 0; i < numTexgen; ++i)
{ {
// optional perspective divides // optional perspective divides
uid_data.texMtxInfo[i].projection = xfregs.texMtxInfo[i].projection; uid_data.texMtxInfo_n_projection |= xfregs.texMtxInfo[i].projection << i;
if (xfregs.texMtxInfo[i].projection == XF_TEXPROJ_STQ) if (xfregs.texMtxInfo[i].projection == XF_TEXPROJ_STQ)
{ {
out.Write("\tif (uv%d.z != 0.0f)", i); out.Write("\tif (uv%d.z != 0.0f)", i);
@ -496,7 +498,7 @@ static void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE Api
unsigned int texcoord = bpmem.tevindref.getTexCoord(i); unsigned int texcoord = bpmem.tevindref.getTexCoord(i);
unsigned int texmap = bpmem.tevindref.getTexMap(i); unsigned int texmap = bpmem.tevindref.getTexMap(i);
uid_data.tevindref.SetValues(i, texcoord, texmap); uid_data.SetTevindrefValues(i, texcoord, texmap);
if (texcoord < numTexgen) if (texcoord < numTexgen)
{ {
out.SetConstantsUsed(C_INDTEXSCALE+i/2,C_INDTEXSCALE+i/2); out.SetConstantsUsed(C_INDTEXSCALE+i/2,C_INDTEXSCALE+i/2);
@ -566,7 +568,7 @@ static void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE Api
// Note: depth textures are disabled if early depth test is enabled // Note: depth textures are disabled if early depth test is enabled
uid_data.ztex_op = bpmem.ztex2.op; uid_data.ztex_op = bpmem.ztex2.op;
uid_data.per_pixel_depth = per_pixel_depth; uid_data.per_pixel_depth = per_pixel_depth;
uid_data.fog.fsel = bpmem.fog.c_proj_fsel.fsel; uid_data.fog_fsel = bpmem.fog.c_proj_fsel.fsel;
// depth texture can safely be ignored if the result won't be written to the depth buffer (early_ztest) and isn't used for fog either // depth texture can safely be ignored if the result won't be written to the depth buffer (early_ztest) and isn't used for fog either
bool skip_ztexture = !per_pixel_depth && !bpmem.fog.c_proj_fsel.fsel; bool skip_ztexture = !per_pixel_depth && !bpmem.fog.c_proj_fsel.fsel;
@ -687,13 +689,12 @@ static void WriteStage(T& out, pixel_shader_uid_data& uid_data, int n, API_TYPE
out.Write("// TEV stage %d\n", n); out.Write("// TEV stage %d\n", n);
uid_data.bHasIndStage |= bHasIndStage << n; uid_data.bHasIndStage |= bHasIndStage << n;
if (n < 8) { uid_data.tevorders_n_texcoord1 |= texcoord << (3 * n); } uid_data.tevorders_n_texcoord |= texcoord << (3 * n);
else uid_data.tevorders_n_texcoord2 |= texcoord << (3 * n - 24);
if (bHasIndStage) if (bHasIndStage)
{ {
uid_data.tevind_n.bs |= bpmem.tevind[n].bs << (2*n); uid_data.tevind_n_bs |= bpmem.tevind[n].bs << (2*n);
uid_data.tevind_n.bt |= bpmem.tevind[n].bt << (2*n); uid_data.tevind_n_bt |= bpmem.tevind[n].bt << (2*n);
uid_data.tevind_n.fmt |= bpmem.tevind[n].fmt << (2*n); uid_data.tevind_n_fmt |= bpmem.tevind[n].fmt << (2*n);
out.Write("// indirect op\n"); out.Write("// indirect op\n");
// perform the indirect op on the incoming regular coordinates using indtex%d as the offset coords // perform the indirect op on the incoming regular coordinates using indtex%d as the offset coords
@ -708,12 +709,12 @@ static void WriteStage(T& out, pixel_shader_uid_data& uid_data, int n, API_TYPE
out.Write("float3 indtevcrd%d = indtex%d * %s;\n", n, bpmem.tevind[n].bt, tevIndFmtScale[bpmem.tevind[n].fmt]); out.Write("float3 indtevcrd%d = indtex%d * %s;\n", n, bpmem.tevind[n].bt, tevIndFmtScale[bpmem.tevind[n].fmt]);
// bias // bias
uid_data.tevind_n.Set_bias(n, bpmem.tevind[n].bias); uid_data.Set_tevind_bias(n, bpmem.tevind[n].bias);
if (bpmem.tevind[n].bias != ITB_NONE ) if (bpmem.tevind[n].bias != ITB_NONE )
out.Write("indtevcrd%d.%s += %s;\n", n, tevIndBiasField[bpmem.tevind[n].bias], tevIndBiasAdd[bpmem.tevind[n].fmt]); out.Write("indtevcrd%d.%s += %s;\n", n, tevIndBiasField[bpmem.tevind[n].bias], tevIndBiasAdd[bpmem.tevind[n].fmt]);
// multiply by offset matrix and scale // multiply by offset matrix and scale
uid_data.tevind_n.Set_mid(n, bpmem.tevind[n].mid); uid_data.Set_tevind_mid(n, bpmem.tevind[n].mid);
if (bpmem.tevind[n].mid != 0) if (bpmem.tevind[n].mid != 0)
{ {
if (bpmem.tevind[n].mid <= 3) if (bpmem.tevind[n].mid <= 3)
@ -750,9 +751,9 @@ static void WriteStage(T& out, pixel_shader_uid_data& uid_data, int n, API_TYPE
// --------- // ---------
// Wrapping // Wrapping
// --------- // ---------
uid_data.tevind_n.Set_sw(n, bpmem.tevind[n].sw); uid_data.Set_tevind_sw(n, bpmem.tevind[n].sw);
uid_data.tevind_n.Set_tw(n, bpmem.tevind[n].tw); uid_data.Set_tevind_tw(n, bpmem.tevind[n].tw);
uid_data.tevind_n.fb_addprev |= bpmem.tevind[n].fb_addprev << n; uid_data.tevind_n_fb_addprev |= bpmem.tevind[n].fb_addprev << n;
// wrap S // wrap S
if (bpmem.tevind[n].sw == ITW_OFF) if (bpmem.tevind[n].sw == ITW_OFF)
@ -779,8 +780,26 @@ static void WriteStage(T& out, pixel_shader_uid_data& uid_data, int n, API_TYPE
TevStageCombiner::ColorCombiner &cc = bpmem.combiners[n].colorC; TevStageCombiner::ColorCombiner &cc = bpmem.combiners[n].colorC;
TevStageCombiner::AlphaCombiner &ac = bpmem.combiners[n].alphaC; TevStageCombiner::AlphaCombiner &ac = bpmem.combiners[n].alphaC;
uid_data.combiners[n].colorC.hex = cc.hex & 0xFFFFFF; uid_data.cc_n_d = cc.d;
uid_data.combiners[n].alphaC.hex = ac.hex & 0xFFFFFF; uid_data.cc_n_c = cc.c;
uid_data.cc_n_b = cc.b;
uid_data.cc_n_a = cc.a;
uid_data.cc_n_bias = cc.bias;
uid_data.cc_n_op = cc.op;
uid_data.cc_n_clamp = cc.clamp;
uid_data.cc_n_shift = cc.shift;
uid_data.cc_n_dest = cc.dest;
uid_data.ac_n_rswap = ac.rswap;
uid_data.ac_n_tswap = ac.tswap;
uid_data.ac_n_d = ac.d;
uid_data.ac_n_c = ac.c;
uid_data.ac_n_b = ac.b;
uid_data.ac_n_a = ac.a;
uid_data.ac_n_bias = ac.bias;
uid_data.ac_n_op = ac.op;
uid_data.ac_n_clamp = ac.clamp;
uid_data.ac_n_shift = ac.shift;
uid_data.ac_n_dest = ac.dest;
if(cc.a == TEVCOLORARG_RASA || cc.a == TEVCOLORARG_RASC if(cc.a == TEVCOLORARG_RASA || cc.a == TEVCOLORARG_RASC
|| cc.b == TEVCOLORARG_RASA || cc.b == TEVCOLORARG_RASC || cc.b == TEVCOLORARG_RASA || cc.b == TEVCOLORARG_RASC
@ -790,10 +809,10 @@ static void WriteStage(T& out, pixel_shader_uid_data& uid_data, int n, API_TYPE
|| ac.c == TEVALPHAARG_RASA || ac.d == TEVALPHAARG_RASA) || ac.c == TEVALPHAARG_RASA || ac.d == TEVALPHAARG_RASA)
{ {
const int i = bpmem.combiners[n].alphaC.rswap; const int i = bpmem.combiners[n].alphaC.rswap;
uid_data.tevksel[i*2 ].swap1 = bpmem.tevksel[i*2 ].swap1; uid_data.tevksel_n_swap1 = bpmem.tevksel[i*2 ].swap1 << (2 * (i*2 ));
uid_data.tevksel[i*2+1].swap1 = bpmem.tevksel[i*2+1].swap1; uid_data.tevksel_n_swap1 = bpmem.tevksel[i*2+1].swap1 << (2 * (i*2+1));
uid_data.tevksel[i*2 ].swap2 = bpmem.tevksel[i*2 ].swap2; uid_data.tevksel_n_swap2 = bpmem.tevksel[i*2 ].swap2 << (2 * (i*2 ));
uid_data.tevksel[i*2+1].swap2 = bpmem.tevksel[i*2+1].swap2; uid_data.tevksel_n_swap2 = bpmem.tevksel[i*2+1].swap2 << (2 * (i*2+1));
char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap]; char *rasswap = swapModeTable[bpmem.combiners[n].alphaC.rswap];
out.Write("rastemp = %s.%s;\n", tevRasTable[bpmem.tevorders[n / 2].getColorChan(n & 1)], rasswap); out.Write("rastemp = %s.%s;\n", tevRasTable[bpmem.tevorders[n / 2].getColorChan(n & 1)], rasswap);
@ -813,14 +832,14 @@ static void WriteStage(T& out, pixel_shader_uid_data& uid_data, int n, API_TYPE
} }
const int i = bpmem.combiners[n].alphaC.tswap; const int i = bpmem.combiners[n].alphaC.tswap;
uid_data.tevksel[i*2 ].swap1 = bpmem.tevksel[i*2 ].swap1; uid_data.tevksel_n_swap1 = bpmem.tevksel[i*2 ].swap1 << (2 * (i*2 ));
uid_data.tevksel[i*2+1].swap1 = bpmem.tevksel[i*2+1].swap1; uid_data.tevksel_n_swap1 = bpmem.tevksel[i*2+1].swap1 << (2 * (i*2+1));
uid_data.tevksel[i*2 ].swap2 = bpmem.tevksel[i*2 ].swap2; uid_data.tevksel_n_swap2 = bpmem.tevksel[i*2 ].swap2 << (2 * (i*2 ));
uid_data.tevksel[i*2+1].swap2 = bpmem.tevksel[i*2+1].swap2; uid_data.tevksel_n_swap2 = bpmem.tevksel[i*2+1].swap2 << (2 * (i*2+1));
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);
uid_data.tevindref.SetTexmap(i, texmap); uid_data.SetTevindrefTexmap(i, texmap);
SampleTexture<T>(out, "textemp", "tevcoord", texswap, texmap, ApiType); SampleTexture<T>(out, "textemp", "tevcoord", texswap, texmap, ApiType);
} }
else else
@ -834,8 +853,8 @@ static void WriteStage(T& out, pixel_shader_uid_data& uid_data, int n, API_TYPE
{ {
int kc = bpmem.tevksel[n / 2].getKC(n & 1); int kc = bpmem.tevksel[n / 2].getKC(n & 1);
int ka = bpmem.tevksel[n / 2].getKA(n & 1); int ka = bpmem.tevksel[n / 2].getKA(n & 1);
uid_data.tevksel[n/2].set_kcsel(n & 1, kc); uid_data.set_tevksel_kcsel(n/2, n & 1, kc);
uid_data.tevksel[n/2].set_kasel(n & 1, ka); uid_data.set_tevksel_kasel(n/2, n & 1, ka);
out.Write("konsttemp = float4(%s, %s);\n", tevKSelTableC[kc], tevKSelTableA[ka]); out.Write("konsttemp = float4(%s, %s);\n", tevKSelTableC[kc], tevKSelTableA[ka]);
if(kc > 7 || ka > 7) if(kc > 7 || ka > 7)
{ {
@ -1086,9 +1105,9 @@ static void WriteAlphaTest(T& out, pixel_shader_uid_data& uid_data, API_TYPE Api
// using discard then return works the same in cg and dx9 but not in dx11 // using discard then return works the same in cg and dx9 but not in dx11
out.Write("\tif(!( "); out.Write("\tif(!( ");
uid_data.alpha_test.comp0 = bpmem.alpha_test.comp0; uid_data.alpha_test_comp0 = bpmem.alpha_test.comp0;
uid_data.alpha_test.logic = bpmem.alpha_test.comp1; uid_data.alpha_test_logic = bpmem.alpha_test.comp1;
uid_data.alpha_test.logic = bpmem.alpha_test.logic; uid_data.alpha_test_logic = bpmem.alpha_test.logic;
// Lookup the first component from the alpha function table // Lookup the first component from the alpha function table
int compindex = bpmem.alpha_test.comp0; int compindex = bpmem.alpha_test.comp0;
@ -1117,7 +1136,7 @@ static void WriteAlphaTest(T& out, pixel_shader_uid_data& uid_data, API_TYPE Api
// when the alpha test fail. This is not a correct implementation because // when the alpha test fail. This is not a correct implementation because
// even if the depth test fails the fragment could be alpha blended, but // even if the depth test fails the fragment could be alpha blended, but
// we don't have a choice. // we don't have a choice.
uid_data.alpha_test.use_zcomploc_hack = bpmem.zcontrol.early_ztest && bpmem.zmode.updateenable; uid_data.alpha_test_use_zcomploc_hack = bpmem.zcontrol.early_ztest && bpmem.zmode.updateenable;
if (!(bpmem.zcontrol.early_ztest && bpmem.zmode.updateenable)) if (!(bpmem.zcontrol.early_ztest && bpmem.zmode.updateenable))
{ {
out.Write("\t\tdiscard;\n"); out.Write("\t\tdiscard;\n");
@ -1143,11 +1162,11 @@ static const char *tevFogFuncsTable[] =
template<class T> template<class T>
static void WriteFog(T& out, pixel_shader_uid_data& uid_data) static void WriteFog(T& out, pixel_shader_uid_data& uid_data)
{ {
uid_data.fog.fsel = bpmem.fog.c_proj_fsel.fsel; uid_data.fog_fsel = bpmem.fog.c_proj_fsel.fsel;
if(bpmem.fog.c_proj_fsel.fsel == 0) if(bpmem.fog.c_proj_fsel.fsel == 0)
return; // no Fog return; // no Fog
uid_data.fog.proj = bpmem.fog.c_proj_fsel.proj; uid_data.fog_proj = bpmem.fog.c_proj_fsel.proj;
out.SetConstantsUsed(C_FOG, C_FOG+1); out.SetConstantsUsed(C_FOG, C_FOG+1);
if (bpmem.fog.c_proj_fsel.proj == 0) if (bpmem.fog.c_proj_fsel.proj == 0)
@ -1166,7 +1185,7 @@ static void WriteFog(T& out, pixel_shader_uid_data& uid_data)
// x_adjust = sqrt((x-center)^2 + k^2)/k // x_adjust = sqrt((x-center)^2 + k^2)/k
// ze *= x_adjust // ze *= x_adjust
// this is completely theoretical as the real hardware seems to use a table intead of calculating the values. // this is completely theoretical as the real hardware seems to use a table intead of calculating the values.
uid_data.fog.RangeBaseEnabled = bpmem.fogRange.Base.Enabled; uid_data.fog_RangeBaseEnabled = bpmem.fogRange.Base.Enabled;
if (bpmem.fogRange.Base.Enabled) if (bpmem.fogRange.Base.Enabled)
{ {
out.SetConstantsUsed(C_FOG+2, C_FOG+2); out.SetConstantsUsed(C_FOG+2, C_FOG+2);

View File

@ -55,162 +55,119 @@ const s_svar PSVar_Loc[] = { {I_COLORS, C_COLORS, 4 },
{I_PMATERIALS, C_PMATERIALS, 4 }, {I_PMATERIALS, C_PMATERIALS, 4 },
}; };
// TODO: Packing?
//#pragma pack(4)
struct pixel_shader_uid_data struct pixel_shader_uid_data
{ {
u32 components; u32 components;
DSTALPHA_MODE dstAlphaMode; // TODO: as u32 :2 u32 dstAlphaMode : 2;
AlphaTest::TEST_RESULT Pretest; // TODO: As :2 u32 Pretest : 2;
u32 nIndirectStagesUsed : 8;
struct {
u32 numtexgens : 4;
u32 numtevstages : 4;
u32 numindstages : 3;
} genMode;
struct
{
u32 unknown : 1;
u32 projection : 1; // XF_TEXPROJ_X
u32 inputform : 2; // XF_TEXINPUT_X
u32 texgentype : 3; // XF_TEXGEN_X
u32 sourcerow : 5; // XF_SRCGEOM_X
u32 embosssourceshift : 3; // what generated texcoord to use
u32 embosslightshift : 3; // light index that is used
} texMtxInfo[8];
struct
{
u32 bi0 : 3; // indirect tex stage 0 ntexmap
u32 bc0 : 3; // indirect tex stage 0 ntexcoord
u32 bi1 : 3;
u32 bc1 : 3;
u32 bi2 : 3;
u32 bc3 : 3;
u32 bi4 : 3;
u32 bc4 : 3;
inline void SetValues(int index, u32 texcoord, u32 texmap)
{
if (index == 0) { bc0 = texcoord; bi0 = texmap; }
else if (index == 1) { bc1 = texcoord; bi1 = texmap; }
else if (index == 2) { bc3 = texcoord; bi2 = texmap; }
else if (index == 3) { bc4 = texcoord; bi4 = texmap; }
}
inline void SetTexmap(int index, u32 texmap)
{
if (index == 0) { bi0 = texmap; }
else if (index == 1) { bi1 = texmap; }
else if (index == 2) { bi2 = texmap; }
else if (index == 3) { bi4 = texmap; }
}
} tevindref;
u32 tevorders_n_texcoord1 : 24; // 8 x 3 bit u32 genMode_numtexgens : 4;
u32 tevorders_n_texcoord2 : 24; // 8 x 3 bit u32 genMode_numtevstages : 4;
struct u32 genMode_numindstages : 3;
u32 nIndirectStagesUsed : 8;
u32 texMtxInfo_n_unknown : 8; // 8x1 bit
u32 texMtxInfo_n_projection : 8; // 8x1 bit
u32 texMtxInfo_n_inputform : 16; // 8x2 bits
u32 texMtxInfo_n_texgentype : 24; // 8x3 bits
u64 texMtxInfo_n_sourcerow : 40; // 8x5 bits
u32 texMtxInfo_n_embosssourceshift : 24; // 8x3 bits
u32 texMtxInfo_n_embosslightshift : 24; // 8x3 bits
u32 tevindref_bi0 : 3;
u32 tevindref_bc0 : 3;
u32 tevindref_bi1 : 3;
u32 tevindref_bc1 : 3;
u32 tevindref_bi2 : 3;
u32 tevindref_bc3 : 3;
u32 tevindref_bi4 : 3;
u32 tevindref_bc4 : 3;
inline void SetTevindrefValues(int index, u32 texcoord, u32 texmap)
{ {
u32 sw1 : 24; // 8 x 3 bit if (index == 0) { tevindref_bc0 = texcoord; tevindref_bi0 = texmap; }
u32 sw2 : 24; // 8 x 3 bit else if (index == 1) { tevindref_bc1 = texcoord; tevindref_bi1 = texmap; }
u32 tw1 : 24; // 8 x 3 bit else if (index == 2) { tevindref_bc3 = texcoord; tevindref_bi2 = texmap; }
u32 tw2 : 24; // 8 x 3 bit else if (index == 3) { tevindref_bc4 = texcoord; tevindref_bi4 = texmap; }
u32 fb_addprev : 16; // 16 x 1 bit }
u32 bs : 32; // 16 x 2 bit inline void SetTevindrefTexmap(int index, u32 texmap)
u32 fmt : 32; // 16 x 2 bit {
u32 bt : 32; // 16 x 2 bit if (index == 0) { tevindref_bi0 = texmap; }
u32 bias1 : 24; // 8 x 3 bit else if (index == 1) { tevindref_bi1 = texmap; }
u32 bias2 : 24; // 8 x 3 bit else if (index == 2) { tevindref_bi2 = texmap; }
u32 mid1 : 32; // 8 x 4 bit else if (index == 3) { tevindref_bi4 = texmap; }
u32 mid2 : 32; // 8 x 4 bit }
u64 tevorders_n_texcoord : 48; // 16 x 3 bits
u64 tevind_n_sw : 48; // 16 x 3 bits
u64 tevind_n_tw : 48; // 16 x 3 bits
u32 tevind_n_fb_addprev : 16; // 16 x 1 bit
u32 tevind_n_bs : 32; // 16 x 2 bits
u32 tevind_n_fmt : 32; // 16 x 2 bits
u32 tevind_n_bt : 32; // 16 x 2 bits
u64 tevind_n_bias : 48; // 16 x 3 bits
u64 tevind_n_mid : 64; // 16 x 4 bits
// NOTE: These assume that the affected bits are zero before calling // NOTE: These assume that the affected bits are zero before calling
void Set_sw(int index, u32 val) void Set_tevind_sw(int index, u64 val)
{ {
if (index < 8) sw1 |= val << (3*index); tevind_n_sw |= val << (3*index);
else sw2 |= val << (3*index - 24);
} }
void Set_tw(int index, u32 val) void Set_tevind_tw(int index, u64 val)
{ {
if (index < 8) tw1 |= val << (3*index); tevind_n_tw |= val << (3*index);
else tw2 |= val << (3*index - 24);
} }
void Set_bias(int index, u32 val) void Set_tevind_bias(int index, u64 val)
{ {
if (index < 8) bias1 |= val << (3*index); tevind_n_bias |= val << (3*index);
else bias2 |= val << (3*index - 24);
} }
void Set_mid(int index, u32 val) void Set_tevind_mid(int index, u64 val)
{ {
if (index < 8) mid1 |= val << (4*index); tevind_n_mid |= val << (4*index);
else mid2 |= val << (4*index - 32);
} }
} tevind_n;
struct u32 tevksel_n_swap1 : 16; // 8x2 bits
{ u32 tevksel_n_swap2 : 16; // 8x2 bits
u32 swap1 : 2; u64 tevksel_n_kcsel0 : 40; // 8x5 bits
u32 swap2 : 2; u64 tevksel_n_kasel0 : 40; // 8x5 bits
u32 kcsel0 : 5; u64 tevksel_n_kcsel1 : 40; // 8x5 bits
u32 kasel0 : 5; u64 tevksel_n_kasel1 : 40; // 8x5 bits
u32 kcsel1 : 5; void set_tevksel_kcsel(int index, int i, u32 value) { if (i) tevksel_n_kcsel1 |= value << (5*index); else tevksel_n_kcsel0 |= value << (5*index); }
u32 kasel1 : 5; void set_tevksel_kasel(int index, int i, u32 value) { if( i) tevksel_n_kasel1 |= value << (5*index); else tevksel_n_kasel0 |= value << (5*index); }
void set_kcsel(int i, u32 value) { if (i) kcsel1 = value; else kcsel0 = value; } u64 cc_n_d : 64; // 16x4 bits
void set_kasel(int i, u32 value) { if( i) kasel1 = value; else kasel0 = value; } u64 cc_n_c : 64; // 16x4 bits
} tevksel[8]; u64 cc_n_b : 64; // 16x4 bits
u64 cc_n_a : 64; // 16x4 bits
u32 cc_n_bias : 32; // 16x2 bits
u32 cc_n_op : 16; // 16x1 bit
u32 cc_n_clamp : 16; // 16x1 bit
u32 cc_n_shift : 32; // 16x2 bits
u32 cc_n_dest : 32; // 16x2 bits
struct u32 ac_n_rswap : 32; // 16x2 bits
{ u32 ac_n_tswap : 32; // 16x2 bits
union { u64 ac_n_d : 48; // 16x3 bits
struct //abc=8bit,d=10bit u64 ac_n_c : 48; // 16x3 bits
{ u64 ac_n_b : 48; // 16x3 bits
u32 d : 4; // TEVSELCC_X u64 ac_n_a : 48; // 16x3 bits
u32 c : 4; // TEVSELCC_X u32 ac_n_bias : 32; // 16x2 bits
u32 b : 4; // TEVSELCC_X u32 ac_n_op : 16; // 16x1 bit
u32 a : 4; // TEVSELCC_X u32 ac_n_clamp : 16; // 16x1 bit
u32 ac_n_shift : 32; // 16x2 bits
u32 ac_n_dest : 32; // 16x2 bits
u32 bias : 2; u32 alpha_test_comp0 : 3;
u32 op : 1; u32 alpha_test_comp1 : 3;
u32 clamp : 1; u32 alpha_test_logic : 2;
u32 alpha_test_use_zcomploc_hack : 1;
u32 shift : 2; u32 fog_proj : 1;
u32 dest : 2; //1,2,3 u32 fog_fsel : 3;
}; u32 fog_RangeBaseEnabled : 1;
u32 hex : 24;
} colorC;
union {
struct
{
u32 rswap : 2;
u32 tswap : 2;
u32 d : 3; // TEVSELCA_
u32 c : 3; // TEVSELCA_
u32 b : 3; // TEVSELCA_
u32 a : 3; // TEVSELCA_
u32 bias : 2; //GXTevBias
u32 op : 1;
u32 clamp : 1;
u32 shift : 2;
u32 dest : 2; //1,2,3
};
u32 hex : 24;
} alphaC;
} combiners[16];
struct
{
u32 comp0 : 3;
u32 comp1 : 3;
u32 logic : 2;
u32 use_zcomploc_hack : 1;
} alpha_test;
union {
struct
{
u32 proj : 1; // 0 - perspective, 1 - orthographic
u32 fsel : 3; // 0 - off, 2 - linear, 4 - exp, 5 - exp2, 6 - backward exp, 7 - backward exp2
u32 RangeBaseEnabled : 1;
};
u32 hex : 4;
} fog;
u32 ztex_op : 2; u32 ztex_op : 2;
@ -221,6 +178,7 @@ struct pixel_shader_uid_data
LightingUidData lighting; LightingUidData lighting;
}; };
//#pragma pack()
typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid; typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid;
typedef ShaderCode PixelShaderCode; // TODO: Obsolete typedef ShaderCode PixelShaderCode; // TODO: Obsolete

View File

@ -199,22 +199,21 @@ static void DeclareUniform(T& object, API_TYPE api_type, bool using_ubos, const
object.Write(";\n"); object.Write(";\n");
} }
#pragma pack(4)
/** /**
* Common uid data used for shader generators that use lighting calculations. * Common uid data used for shader generators that use lighting calculations.
* Expected to be stored as a member called "lighting". * Expected to be stored as a member called "lighting".
*/ */
struct LightingUidData struct LightingUidData
{ {
struct u32 matsource : 4; // 4x1 bit
{ u32 enablelighting : 4; // 4x1 bit
u32 matsource : 1; u32 ambsource : 4; // 4x1 bit
u32 enablelighting : 1; u32 diffusefunc : 8; // 4x2 bits
u32 ambsource : 1; u32 attnfunc : 8; // 4x2 bits
u32 diffusefunc : 2; u32 light_mask : 32; // 4x8 bits
u32 attnfunc : 2;
u32 light_mask : 8;
} lit_chans[4];
}; };
#pragma pack()
/** /**
* Checks if there has been * Checks if there has been