mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Merge pull request #4291 from degasus/shader_gen
PixelShaderGen: Fix UID issues.
This commit is contained in:
@ -72,9 +72,9 @@ static void GenerateLightShader(ShaderCode& object, const LightingUidData& uid_d
|
||||
// inColorName is color in vs and colors_ in ps
|
||||
// dest is o.colors_ in vs and colors_ in ps
|
||||
void GenerateLightingShaderCode(ShaderCode& object, const LightingUidData& uid_data, int components,
|
||||
const char* inColorName, const char* dest)
|
||||
u32 numColorChans, const char* inColorName, const char* dest)
|
||||
{
|
||||
for (unsigned int j = 0; j < xfmem.numChan.numColorChans; j++)
|
||||
for (unsigned int j = 0; j < numColorChans; j++)
|
||||
{
|
||||
object.Write("{\n");
|
||||
|
||||
@ -200,4 +200,4 @@ void GetLightingShaderUid(LightingUidData& uid_data)
|
||||
uid_data.light_mask |= xfmem.alpha[j].GetFullLightMask() << (8 * (j + 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,5 +47,5 @@ static const char s_lighting_struct[] = "struct Light {\n"
|
||||
"};\n";
|
||||
|
||||
void GenerateLightingShaderCode(ShaderCode& object, const LightingUidData& uid_data, int components,
|
||||
const char* inColorName, const char* dest);
|
||||
u32 numColorChans, const char* inColorName, const char* dest);
|
||||
void GetLightingShaderUid(LightingUidData& uid_data);
|
||||
|
@ -207,7 +207,7 @@ PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode)
|
||||
// The lighting shader only needs the two color bits of the 23bit component bit array.
|
||||
uid_data->components =
|
||||
(VertexLoaderManager::g_current_components & (VB_HAS_COL0 | VB_HAS_COL1)) >> VB_COL_SHIFT;
|
||||
;
|
||||
uid_data->numColorChans = xfmem.numChan.numColorChans;
|
||||
GetLightingShaderUid(uid_data->lighting);
|
||||
}
|
||||
|
||||
@ -342,11 +342,10 @@ static void WriteTevRegular(ShaderCode& out, const char* components, int bias, i
|
||||
static void SampleTexture(ShaderCode& out, const char* texcoords, const char* texswap, int texmap,
|
||||
bool stereo, APIType ApiType);
|
||||
static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, APIType ApiType,
|
||||
DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth);
|
||||
bool per_pixel_depth);
|
||||
static void WriteFog(ShaderCode& out, const pixel_shader_uid_data* uid_data);
|
||||
|
||||
ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
|
||||
const pixel_shader_uid_data* uid_data)
|
||||
ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* uid_data)
|
||||
{
|
||||
ShaderCode out;
|
||||
|
||||
@ -501,21 +500,10 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
|
||||
out.Write("[earlydepthstencil]\n");
|
||||
}
|
||||
}
|
||||
else if (bpmem.UseEarlyDepthTest() &&
|
||||
(uid_data->fast_depth_calc || bpmem.alpha_test.TestResult() == AlphaTest::UNDETERMINED))
|
||||
{
|
||||
static bool warn_once = true;
|
||||
if (warn_once)
|
||||
WARN_LOG(VIDEO, "Early z test enabled but not possible to emulate with current "
|
||||
"configuration. Make sure to enable fast depth calculations. If this message "
|
||||
"still shows up your hardware isn't able to emulate the feature properly (a "
|
||||
"GPU with D3D 11.0 / OGL 4.2 support is required).");
|
||||
warn_once = false;
|
||||
}
|
||||
|
||||
if (ApiType == APIType::OpenGL || ApiType == APIType::Vulkan)
|
||||
{
|
||||
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
||||
if (uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
||||
{
|
||||
if (DriverDetails::HasBug(DriverDetails::BUG_BROKEN_FRAGMENT_SHADER_INDEX_DECORATION))
|
||||
{
|
||||
@ -587,8 +575,9 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
|
||||
{
|
||||
out.Write("void main(\n");
|
||||
out.Write(" out float4 ocol0 : SV_Target0,%s%s\n in float4 rawpos : SV_Position,\n",
|
||||
dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : SV_Target1," :
|
||||
"",
|
||||
uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ?
|
||||
"\n out float4 ocol1 : SV_Target1," :
|
||||
"",
|
||||
uid_data->per_pixel_depth ? "\n out float depth : SV_Depth," : "");
|
||||
|
||||
out.Write(" in %s float4 colors_0 : COLOR0,\n",
|
||||
@ -649,7 +638,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
|
||||
// out.SetConstantsUsed(C_PLIGHTS, C_PLIGHTS+31); // TODO: Can be optimized further
|
||||
// out.SetConstantsUsed(C_PMATERIALS, C_PMATERIALS+3);
|
||||
GenerateLightingShaderCode(out, uid_data->lighting, uid_data->components << VB_COL_SHIFT,
|
||||
"colors_", "col");
|
||||
uid_data->numColorChans, "colors_", "col");
|
||||
}
|
||||
|
||||
// HACK to handle cases where the tex gen is not enabled
|
||||
@ -716,7 +705,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
|
||||
// testing result)
|
||||
if (uid_data->Pretest == AlphaTest::UNDETERMINED ||
|
||||
(uid_data->Pretest == AlphaTest::FAIL && uid_data->late_ztest))
|
||||
WriteAlphaTest(out, uid_data, ApiType, dstAlphaMode, uid_data->per_pixel_depth);
|
||||
WriteAlphaTest(out, uid_data, ApiType, uid_data->per_pixel_depth);
|
||||
|
||||
if (uid_data->zfreeze)
|
||||
{
|
||||
@ -787,7 +776,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
|
||||
out.Write("\tdepth = float(zCoord) / 16777216.0;\n");
|
||||
}
|
||||
|
||||
if (dstAlphaMode == DSTALPHA_ALPHA_PASS)
|
||||
if (uid_data->dstAlphaMode == DSTALPHA_ALPHA_PASS)
|
||||
{
|
||||
out.SetConstantsUsed(C_ALPHA, C_ALPHA);
|
||||
out.Write("\tocol0 = float4(float3(prev.rgb), float(" I_ALPHA ".a)) / 255.0;\n");
|
||||
@ -799,7 +788,7 @@ ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
|
||||
}
|
||||
|
||||
// Use dual-source color blending to perform dst alpha in a single pass
|
||||
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
||||
if (uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
||||
{
|
||||
out.SetConstantsUsed(C_ALPHA, C_ALPHA);
|
||||
|
||||
@ -1195,7 +1184,7 @@ static const char* tevAlphaFunclogicTable[] = {
|
||||
};
|
||||
|
||||
static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_data, APIType ApiType,
|
||||
DSTALPHA_MODE dstAlphaMode, bool per_pixel_depth)
|
||||
bool per_pixel_depth)
|
||||
{
|
||||
static const char* alphaRef[2] = {I_ALPHA ".r", I_ALPHA ".g"};
|
||||
|
||||
@ -1222,7 +1211,7 @@ static void WriteAlphaTest(ShaderCode& out, const pixel_shader_uid_data* uid_dat
|
||||
out.Write(")) {\n");
|
||||
|
||||
out.Write("\t\tocol0 = float4(0.0, 0.0, 0.0, 0.0);\n");
|
||||
if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
||||
if (uid_data->dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND)
|
||||
out.Write("\t\tocol1 = float4(0.0, 0.0, 0.0, 0.0);\n");
|
||||
if (per_pixel_depth)
|
||||
{
|
||||
|
@ -52,7 +52,8 @@ struct pixel_shader_uid_data
|
||||
u32 zfreeze : 1;
|
||||
u32 msaa : 1;
|
||||
u32 ssaa : 1;
|
||||
u32 pad : 16;
|
||||
u32 numColorChans : 2;
|
||||
u32 pad : 14;
|
||||
|
||||
u32 texMtxInfo_n_projection : 8; // 8x1 bit
|
||||
u32 tevindref_bi0 : 3;
|
||||
@ -166,6 +167,5 @@ struct pixel_shader_uid_data
|
||||
|
||||
typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid;
|
||||
|
||||
ShaderCode GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, APIType ApiType,
|
||||
const pixel_shader_uid_data* uid_data);
|
||||
ShaderCode GeneratePixelShaderCode(APIType ApiType, const pixel_shader_uid_data* uid_data);
|
||||
PixelShaderUid GetPixelShaderUid(DSTALPHA_MODE dstAlphaMode);
|
||||
|
@ -250,7 +250,8 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da
|
||||
out.Write("o.colors_0 = float4(1.0, 1.0, 1.0, 1.0);\n");
|
||||
}
|
||||
|
||||
GenerateLightingShaderCode(out, uid_data->lighting, uid_data->components, "color", "o.colors_");
|
||||
GenerateLightingShaderCode(out, uid_data->lighting, uid_data->components, uid_data->numColorChans,
|
||||
"color", "o.colors_");
|
||||
|
||||
if (uid_data->numColorChans < 2)
|
||||
{
|
||||
|
Reference in New Issue
Block a user