Merge pull request #13345 from Tilka/unswap_depth

Fix depth texture being incorrectly affected by swap table
This commit is contained in:
JosJuice 2025-03-15 14:30:19 +01:00 committed by GitHub
commit 3fb4084e25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 11 deletions

View file

@ -465,6 +465,11 @@ void Tev::Draw()
std::memset(texel, 0, 4); std::memset(texel, 0, 4);
} }
RawTexColor.r = texel[u32(ColorChannel::Red)];
RawTexColor.g = texel[u32(ColorChannel::Green)];
RawTexColor.b = texel[u32(ColorChannel::Blue)];
RawTexColor.a = texel[u32(ColorChannel::Alpha)];
const auto& swap = bpmem.tevksel.GetSwapTable(ac.tswap); const auto& swap = bpmem.tevksel.GetSwapTable(ac.tswap);
TexColor.r = texel[u32(swap[ColorChannel::Red])]; TexColor.r = texel[u32(swap[ColorChannel::Red])];
TexColor.g = texel[u32(swap[ColorChannel::Green])]; TexColor.g = texel[u32(swap[ColorChannel::Green])];
@ -549,13 +554,13 @@ void Tev::Draw()
switch (bpmem.ztex2.type) switch (bpmem.ztex2.type)
{ {
case ZTexFormat::U8: case ZTexFormat::U8:
ztex += TexColor[ALP_C]; ztex += RawTexColor[ALP_C];
break; break;
case ZTexFormat::U16: case ZTexFormat::U16:
ztex += TexColor[ALP_C] << 8 | TexColor[RED_C]; ztex += RawTexColor[ALP_C] << 8 | RawTexColor[RED_C];
break; break;
case ZTexFormat::U24: case ZTexFormat::U24:
ztex += TexColor[RED_C] << 16 | TexColor[GRN_C] << 8 | TexColor[BLU_C]; ztex += RawTexColor[RED_C] << 16 | RawTexColor[GRN_C] << 8 | RawTexColor[BLU_C];
break; break;
default: default:
PanicAlertFmt("Invalid ztex format {}", bpmem.ztex2.type); PanicAlertFmt("Invalid ztex format {}", bpmem.ztex2.type);

View file

@ -107,6 +107,7 @@ class Tev
// color order: ABGR // color order: ABGR
Common::EnumMap<TevColor, TevOutput::Color2> Reg; Common::EnumMap<TevColor, TevOutput::Color2> Reg;
std::array<TevColor, 4> KonstantColors; std::array<TevColor, 4> KonstantColors;
TevColor RawTexColor;
TevColor TexColor; TevColor TexColor;
TevColor RasColor; TevColor RasColor;
TevColor StageKonst; TevColor StageKonst;

View file

@ -1104,8 +1104,8 @@ ShaderCode GeneratePixelShaderCode(APIType api_type, const ShaderHostConfig& hos
out.Write("\tint4 c0 = " I_COLORS "[1], c1 = " I_COLORS "[2], c2 = " I_COLORS out.Write("\tint4 c0 = " I_COLORS "[1], c1 = " I_COLORS "[2], c2 = " I_COLORS
"[3], prev = " I_COLORS "[0];\n" "[3], prev = " I_COLORS "[0];\n"
"\tint4 rastemp = int4(0, 0, 0, 0), textemp = int4(0, 0, 0, 0), konsttemp = int4(0, 0, " "\tint4 rastemp = int4(0, 0, 0, 0), rawtextemp = int4(0, 0, 0, 0), "
"0, 0);\n" "textemp = int4(0, 0, 0, 0), konsttemp = int4(0, 0, 0, 0);\n"
"\tint3 comp16 = int3(1, 256, 0), comp24 = int3(1, 256, 256*256);\n" "\tint3 comp16 = int3(1, 256, 0), comp24 = int3(1, 256, 256*256);\n"
"\tint alphabump=0;\n" "\tint alphabump=0;\n"
"\tint3 tevcoord=int3(0, 0, 0);\n" "\tint3 tevcoord=int3(0, 0, 0);\n"
@ -1291,7 +1291,7 @@ ShaderCode GeneratePixelShaderCode(APIType api_type, const ShaderHostConfig& hos
// use the texture input of the last texture stage (textemp), hopefully this has been read and // use the texture input of the last texture stage (textemp), hopefully this has been read and
// is in correct format... // is in correct format...
out.SetConstantsUsed(C_ZBIAS, C_ZBIAS + 1); out.SetConstantsUsed(C_ZBIAS, C_ZBIAS + 1);
out.Write("\tzCoord = idot(" I_ZBIAS "[0].xyzw, textemp.xyzw) + " I_ZBIAS "[1].w {};\n", out.Write("\tzCoord = idot(" I_ZBIAS "[0].xyzw, rawtextemp.xyzw) + " I_ZBIAS "[1].w {};\n",
(uid_data->ztex_op == ZTexOp::Add) ? "+ zCoord" : ""); (uid_data->ztex_op == ZTexOp::Add) ? "+ zCoord" : "");
out.Write("\tzCoord = zCoord & 0xFFFFFF;\n"); out.Write("\tzCoord = zCoord & 0xFFFFFF;\n");
} }
@ -1614,8 +1614,9 @@ static void WriteStage(ShaderCode& out, const pixel_shader_uid_data* uid_data, i
if (stage.tevorders_enable && uid_data->genMode_numtexgens > 0) if (stage.tevorders_enable && uid_data->genMode_numtexgens > 0)
{ {
// Generate swizzle string to represent the texture color channel swapping // Generate swizzle string to represent the texture color channel swapping
out.Write("\ttextemp = sampleTextureWrapper({}u, tevcoord.xy, layer).{}{}{}{};\n", out.Write("\trawtextemp = sampleTextureWrapper({}u, tevcoord.xy, layer);\n",
stage.tevorders_texmap, rgba_swizzle[stage.tex_swap_r], stage.tevorders_texmap);
out.Write("\ttextemp = rawtextemp.{}{}{}{};\n", rgba_swizzle[stage.tex_swap_r],
rgba_swizzle[stage.tex_swap_g], rgba_swizzle[stage.tex_swap_b], rgba_swizzle[stage.tex_swap_g], rgba_swizzle[stage.tex_swap_b],
rgba_swizzle[stage.tex_swap_a]); rgba_swizzle[stage.tex_swap_a]);
} }

View file

@ -724,6 +724,7 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config,
out.Write("struct State {{\n" out.Write("struct State {{\n"
" int4 Reg[4];\n" " int4 Reg[4];\n"
" int4 RawTexColor;\n"
" int4 TexColor;\n" " int4 TexColor;\n"
" int AlphaBump;\n" " int AlphaBump;\n"
"}};\n" "}};\n"
@ -1090,10 +1091,10 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config,
" uint sampler_num = {};\n", " uint sampler_num = {};\n",
BitfieldExtract<&TwoTevStageOrders::texmap_even>("ss.order")); BitfieldExtract<&TwoTevStageOrders::texmap_even>("ss.order"));
out.Write("\n" out.Write("\n"
" int4 color = sampleTextureWrapper(sampler_num, tevcoord.xy, layer);\n" " s.RawTexColor = sampleTextureWrapper(sampler_num, tevcoord.xy, layer);\n"
" uint swap = {};\n", " uint swap = {};\n",
BitfieldExtract<&TevStageCombiner::AlphaCombiner::tswap>("ss.ac")); BitfieldExtract<&TevStageCombiner::AlphaCombiner::tswap>("ss.ac"));
out.Write(" s.TexColor = Swizzle(swap, color);\n"); out.Write(" s.TexColor = Swizzle(swap, s.RawTexColor);\n");
out.Write(" }} else {{\n" out.Write(" }} else {{\n"
" // Texture is disabled\n" " // Texture is disabled\n"
" s.TexColor = int4(255, 255, 255, 255);\n" " s.TexColor = int4(255, 255, 255, 255);\n"
@ -1371,7 +1372,7 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config,
" int ztex = int(" I_ZBIAS "[1].w); // fixed bias\n" " int ztex = int(" I_ZBIAS "[1].w); // fixed bias\n"
"\n" "\n"
" // Whatever texture was in our last stage, it's now our depth texture\n" " // Whatever texture was in our last stage, it's now our depth texture\n"
" ztex += idot(s.TexColor.xyzw, " I_ZBIAS "[0].xyzw);\n" " ztex += idot(s.RawTexColor.xyzw, " I_ZBIAS "[0].xyzw);\n"
" ztex += (bpmem_ztex_op == 1u) ? zCoord : 0;\n" " ztex += (bpmem_ztex_op == 1u) ? zCoord : 0;\n"
" zCoord = ztex & 0xFFFFFF;\n" " zCoord = ztex & 0xFFFFFF;\n"
" }}\n" " }}\n"