Ubershaders: Fix 6-bit color truncation not being applied

This commit is contained in:
Stenzek 2017-07-31 23:29:28 +10:00
parent ed331918f0
commit 852e30bb8c
6 changed files with 17 additions and 15 deletions

View File

@ -134,18 +134,19 @@ static void BPWritten(const BPCmd& bp)
GeometryShaderManager::SetLinePtWidthChanged(); GeometryShaderManager::SetLinePtWidthChanged();
return; return;
case BPMEM_ZMODE: // Depth Control case BPMEM_ZMODE: // Depth Control
PRIM_LOG("zmode: test=%d, func=%d, upd=%d", (int)bpmem.zmode.testenable, (int)bpmem.zmode.func, PRIM_LOG("zmode: test=%u, func=%u, upd=%u", bpmem.zmode.testenable.Value(),
(int)bpmem.zmode.updateenable); bpmem.zmode.func.Value(), bpmem.zmode.updateenable.Value());
SetDepthMode(); SetDepthMode();
PixelShaderManager::SetZModeControl();
return; return;
case BPMEM_BLENDMODE: // Blending Control case BPMEM_BLENDMODE: // Blending Control
if (bp.changes & 0xFFFF) if (bp.changes & 0xFFFF)
{ {
PRIM_LOG("blendmode: en=%d, open=%d, colupd=%d, alphaupd=%d, dst=%d, src=%d, sub=%d, mode=%d", PRIM_LOG("blendmode: en=%u, open=%u, colupd=%u, alphaupd=%u, dst=%u, src=%u, sub=%u, mode=%u",
(int)bpmem.blendmode.blendenable, (int)bpmem.blendmode.logicopenable, bpmem.blendmode.blendenable.Value(), bpmem.blendmode.logicopenable.Value(),
(int)bpmem.blendmode.colorupdate, (int)bpmem.blendmode.alphaupdate, bpmem.blendmode.colorupdate.Value(), bpmem.blendmode.alphaupdate.Value(),
(int)bpmem.blendmode.dstfactor, (int)bpmem.blendmode.srcfactor, bpmem.blendmode.dstfactor.Value(), bpmem.blendmode.srcfactor.Value(),
(int)bpmem.blendmode.subtract, (int)bpmem.blendmode.logicmode); bpmem.blendmode.subtract.Value(), bpmem.blendmode.logicmode.Value());
// Set Blending Mode // Set Blending Mode
if (bp.changes) if (bp.changes)
@ -424,6 +425,7 @@ static void BPWritten(const BPCmd& bp)
g_renderer->SetColorMask(); // alpha writing needs to be disabled if the new pixel format g_renderer->SetColorMask(); // alpha writing needs to be disabled if the new pixel format
// doesn't have an alpha channel // doesn't have an alpha channel
} }
PixelShaderManager::SetZModeControl();
return; return;
case BPMEM_MIPMAP_STRIDE: // MipMap Stride Channel case BPMEM_MIPMAP_STRIDE: // MipMap Stride Channel

View File

@ -33,7 +33,7 @@ struct PixelShaderConstants
u32 fogRangeBase; // .y u32 fogRangeBase; // .y
u32 dstalpha; // .z u32 dstalpha; // .z
u32 ztex_op; // .w u32 ztex_op; // .w
u32 early_ztest; // .x (bool) u32 late_ztest; // .x (bool)
u32 rgba6_format; // .y (bool) u32 rgba6_format; // .y (bool)
u32 dither; // .z (bool) u32 dither; // .z (bool)
u32 bounding_box; // .w (bool) u32 bounding_box; // .w (bool)

View File

@ -379,7 +379,7 @@ void WritePixelShaderCommonHeader(ShaderCode& out, APIType ApiType, u32 num_texg
"\tuint bpmem_fogRangeBase;\n" "\tuint bpmem_fogRangeBase;\n"
"\tuint bpmem_dstalpha;\n" "\tuint bpmem_dstalpha;\n"
"\tuint bpmem_ztex_op;\n" "\tuint bpmem_ztex_op;\n"
"\tbool bpmem_early_ztest;\n" "\tbool bpmem_late_ztest;\n"
"\tbool bpmem_rgba6_format;\n" "\tbool bpmem_rgba6_format;\n"
"\tbool bpmem_dither;\n" "\tbool bpmem_dither;\n"
"\tbool bpmem_bounding_box;\n" "\tbool bpmem_bounding_box;\n"

View File

@ -447,17 +447,17 @@ void PixelShaderManager::SetGenModeChanged()
dirty = true; dirty = true;
} }
void PixelShaderManager::SetZControlChanged() void PixelShaderManager::SetZModeControl()
{ {
u32 early_ztest = bpmem.zcontrol.early_ztest ? 1 : 0; u32 late_ztest = bpmem.UseLateDepthTest();
u32 rgba6_format = u32 rgba6_format =
(bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24 && !g_ActiveConfig.bForceTrueColor) ? 1 : (bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24 && !g_ActiveConfig.bForceTrueColor) ? 1 :
0; 0;
u32 dither = rgba6_format && bpmem.blendmode.dither; u32 dither = rgba6_format && bpmem.blendmode.dither;
if (constants.early_ztest != early_ztest || constants.rgba6_format != rgba6_format || if (constants.late_ztest != late_ztest || constants.rgba6_format != rgba6_format ||
constants.dither != dither) constants.dither != dither)
{ {
constants.early_ztest = early_ztest; constants.late_ztest = late_ztest;
constants.rgba6_format = rgba6_format; constants.rgba6_format = rgba6_format;
constants.dither = dither; constants.dither = dither;
dirty = true; dirty = true;

View File

@ -45,7 +45,7 @@ public:
static void SetFogParamChanged(); static void SetFogParamChanged();
static void SetFogRangeAdjustChanged(); static void SetFogRangeAdjustChanged();
static void SetGenModeChanged(); static void SetGenModeChanged();
static void SetZControlChanged(); static void SetZModeControl();
static void SetBlendModeChanged(); static void SetBlendModeChanged();
static void SetBoundingBoxActive(bool active); static void SetBoundingBoxActive(bool active);

View File

@ -894,7 +894,7 @@ ShaderCode GenPixelShader(APIType ApiType, const ShaderHostConfig& host_config,
{ {
out.Write(" // If early depth is enabled, write to zbuffer before depth textures\n"); out.Write(" // If early depth is enabled, write to zbuffer before depth textures\n");
out.Write(" // If early depth isn't enabled, we write to the zbuffer here\n"); out.Write(" // If early depth isn't enabled, we write to the zbuffer here\n");
out.Write(" int zbuffer_zCoord = bpmem_early_ztest ? early_zCoord : zCoord;\n"); out.Write(" int zbuffer_zCoord = bpmem_late_ztest ? zCoord : early_zCoord;\n");
if (ApiType == APIType::D3D || ApiType == APIType::Vulkan) if (ApiType == APIType::D3D || ApiType == APIType::Vulkan)
out.Write(" depth = 1.0 - float(zbuffer_zCoord) / 16777216.0;\n"); out.Write(" depth = 1.0 - float(zbuffer_zCoord) / 16777216.0;\n");
else else