diff --git a/GPU/Common/FragmentShaderGenerator.cpp b/GPU/Common/FragmentShaderGenerator.cpp index ad3f22af8c..f956217b38 100644 --- a/GPU/Common/FragmentShaderGenerator.cpp +++ b/GPU/Common/FragmentShaderGenerator.cpp @@ -90,7 +90,6 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu bool shaderDepal = id.Bit(FS_BIT_SHADER_DEPAL) && !texture3D; // combination with texture3D not supported. Enforced elsewhere too. bool bgraTexture = id.Bit(FS_BIT_BGRA_TEXTURE); bool colorWriteMask = id.Bit(FS_BIT_COLOR_WRITEMASK) && compat.bitwiseOps; - bool colorToDepth = id.Bit(FS_BIT_COLOR_TO_DEPTH); GEComparison alphaTestFunc = (GEComparison)id.Bits(FS_BIT_ALPHA_TEST_FUNC, 3); GEComparison colorTestFunc = (GEComparison)id.Bits(FS_BIT_COLOR_TEST_FUNC, 2); @@ -123,7 +122,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu bool readFramebufferTex = readFramebuffer && !gstate_c.Supports(GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH); bool needFragCoord = readFramebuffer || gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT); - bool writeDepth = gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT) || colorToDepth; + bool writeDepth = gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT); if (shaderDepal && !doTexture) { *errorString = "depal requires a texture"; @@ -136,11 +135,6 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu } if (compat.shaderLanguage == ShaderLanguage::GLSL_VULKAN) { - if (colorToDepth) { - WRITE(p, "precision highp int;\n"); - WRITE(p, "precision highp float;\n"); - } - if (useDiscardStencilBugWorkaround && !gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT)) { WRITE(p, "layout (depth_unchanged) out float gl_FragDepth;\n"); } @@ -293,7 +287,7 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, "};\n"); } } else if (ShaderLanguageIsOpenGL(compat.shaderLanguage)) { - if ((shaderDepal || colorWriteMask || colorToDepth) && gl_extensions.IsGLES) { + if ((shaderDepal || colorWriteMask) && gl_extensions.IsGLES) { WRITE(p, "precision highp int;\n"); } @@ -461,9 +455,6 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, "PS_OUT main( PS_IN In ) {\n"); WRITE(p, " PS_OUT outfragment;\n"); WRITE(p, " vec4 target;\n"); - if (colorToDepth) { - WRITE(p, " float gl_FragDepth;\n"); - } } else { WRITE(p, "void main() {\n"); } @@ -1070,22 +1061,6 @@ bool GenerateFragmentShader(const FShaderID &id, char *buffer, const ShaderLangu WRITE(p, " %s = vec4(0.0, 0.0, 0.0, %s.z); // blue to alpha\n", compat.fragColor0, compat.fragColor0); } - if (colorToDepth) { - DepthScaleFactors factors = GetDepthScaleFactors(); - - if (compat.bitwiseOps) { - WRITE(p, " highp float depthValue = float(int(%s.x * 31.99) | (int(%s.y * 63.99) << 5) | (int(%s.z * 31.99) << 11)) / 65535.0;\n", "v", "v", "v"); // compat.fragColor0, compat.fragColor0, compat.fragColor0); - } else { - // D3D9-compatible alternative - WRITE(p, " highp float depthValue = (floor(%s.x * 31.99) + floor(%s.y * 63.99) * 32.0 + floor(%s.z * 31.99) * 2048.0) / 65535.0;\n", "v", "v", "v"); // compat.fragColor0, compat.fragColor0, compat.fragColor0); - } - if (factors.scale != 1.0 || factors.offset != 0.0) { - WRITE(p, " gl_FragDepth = (depthValue / %f) + %f;\n", factors.scale / 65535.0f, factors.offset); - } else { - WRITE(p, " gl_FragDepth = depthValue;\n"); - } - } - if (gstate_c.Supports(GPU_ROUND_FRAGMENT_DEPTH_TO_16BIT)) { const double scale = DepthSliceFactor() * 65535.0; diff --git a/GPU/Common/FramebufferManagerCommon.cpp b/GPU/Common/FramebufferManagerCommon.cpp index eeae895d53..e0b05f76c7 100644 --- a/GPU/Common/FramebufferManagerCommon.cpp +++ b/GPU/Common/FramebufferManagerCommon.cpp @@ -280,8 +280,6 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame WARN_LOG_ONCE(color_equal_z, G3D, "Framebuffer bound with color addr == z addr, likely will not use Z in this pass: %08x", params.fb_address); } - RasterMode mode = RASTER_MODE_NORMAL; - // Find a matching framebuffer VirtualFramebuffer *vfb = nullptr; for (size_t i = 0; i < vfbs_.size(); ++i) { @@ -318,19 +316,6 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame vfb->height = drawing_height; } break; - } else if (params.fb_address == v->z_address && params.fmt != GE_FORMAT_8888 && params.fb_stride == v->z_stride && !params.isBlending) { - // Looks like the game might be intending to use color to write directly to a Z buffer. - // This is seen in Kuroyou 2. - - // Ignore this in this loop, BUT, we do a lookup in the depth tracking afterwards to - // make sure we get the latest one. - WARN_LOG_ONCE(color_matches_z, G3D, "Color framebuffer bound at %08x with likely intent to write explicit Z values using color. fmt = %s", params.fb_address, GeBufferFormatToString(params.fmt)); - // Seems impractical to use the other 16-bit formats for this due to the limited control over alpha, - // so we'll simply only support 565. - if (params.fmt == GE_FORMAT_565) { - mode = RASTER_MODE_COLOR_TO_DEPTH; - break; - } } else if (v->fb_stride == params.fb_stride && v->format == params.fmt) { u32 v_fb_first_line_end_ptr = v->fb_address + v->fb_stride * 4; // This should be * bpp, but leaving like this until after 1.13 to be safe. The God of War games use this for shadows. u32 v_fb_end_ptr = v->fb_address + v->fb_stride * v->height * bpp; @@ -368,24 +353,6 @@ VirtualFramebuffer *FramebufferManagerCommon::DoSetRenderFrameBuffer(const Frame } } - if (mode == RASTER_MODE_COLOR_TO_DEPTH) { - // Lookup in the depth tracking to find which VFB has the latest version of this Z buffer. - // Then bind it in color-to-depth mode. - // - // We do this by having a special render mode where we take color and move to - // depth in the fragment shader, and set color writes to off. - // - // We use a special fragment shader flag to convert color to depth. - vfb = GetLatestDepthBufferAt(params.fb_address /* !!! */, params.fb_stride); - if (vfb) { - vfb->depthBindSeq = GetBindSeqCount(); - } - // Avoid causing another depth copy on top. - gstate_c.usingDepth = true; - } - - gstate_c.SetFramebufferRenderMode(mode); - if (vfb) { if ((drawing_width != vfb->bufferWidth || drawing_height != vfb->bufferHeight)) { // Even if it's not newly wrong, if this is larger we need to resize up. diff --git a/GPU/Common/GPUStateUtils.cpp b/GPU/Common/GPUStateUtils.cpp index e86c056c5a..51f0e3f8eb 100644 --- a/GPU/Common/GPUStateUtils.cpp +++ b/GPU/Common/GPUStateUtils.cpp @@ -1018,16 +1018,6 @@ void ConvertMaskState(GenericMaskState &maskState, bool allowFramebufferRead) { return; } - if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) { - // Suppress color writes entirely in this mode. - maskState.applyFramebufferRead = false; - maskState.rgba[0] = false; - maskState.rgba[1] = false; - maskState.rgba[2] = false; - maskState.rgba[3] = false; - return; - } - // Invert to convert masks from the PSP's format where 1 is don't draw to PC where 1 is draw. uint32_t colorMask = ~((gstate.pmskc & 0xFFFFFF) | (gstate.pmska << 24)); diff --git a/GPU/Common/ShaderId.cpp b/GPU/Common/ShaderId.cpp index 1176200799..510e90e929 100644 --- a/GPU/Common/ShaderId.cpp +++ b/GPU/Common/ShaderId.cpp @@ -240,8 +240,6 @@ std::string FragmentShaderDesc(const FShaderID &id) { if (id.Bit(FS_BIT_COLOR_AGAINST_ZERO)) desc << "ColorTest0 " << alphaTestFuncs[id.Bits(FS_BIT_COLOR_TEST_FUNC, 2)] << " "; // first 4 match; else if (id.Bit(FS_BIT_COLOR_TEST)) desc << "ColorTest " << alphaTestFuncs[id.Bits(FS_BIT_COLOR_TEST_FUNC, 2)] << " "; // first 4 match - if (id.Bit(FS_BIT_COLOR_TO_DEPTH)) desc << "ColorToDepth "; - return desc.str(); } @@ -264,7 +262,6 @@ void ComputeFragmentShaderID(FShaderID *id_out, const Draw::Bugs &bugs) { bool doFlatShading = gstate.getShadeMode() == GE_SHADE_FLAT; bool useShaderDepal = gstate_c.useShaderDepal; bool colorWriteMask = IsColorWriteMaskComplex(gstate_c.allowFramebufferRead); - bool colorToDepth = gstate_c.renderMode == RasterMode::RASTER_MODE_COLOR_TO_DEPTH; // Note how we here recompute some of the work already done in state mapping. // Not ideal! At least we share the code. @@ -296,8 +293,6 @@ void ComputeFragmentShaderID(FShaderID *id_out, const Draw::Bugs &bugs) { id.SetBit(FS_BIT_3D_TEXTURE, gstate_c.curTextureIs3D); } - id.SetBit(FS_BIT_COLOR_TO_DEPTH, colorToDepth); - id.SetBit(FS_BIT_LMODE, lmode); if (enableAlphaTest) { // 5 bits total. diff --git a/GPU/Common/ShaderId.h b/GPU/Common/ShaderId.h index bcdf4f723c..8dcee32c1e 100644 --- a/GPU/Common/ShaderId.h +++ b/GPU/Common/ShaderId.h @@ -94,7 +94,6 @@ enum FShaderBit : uint8_t { FS_BIT_NO_DEPTH_CANNOT_DISCARD_STENCIL = 49, FS_BIT_COLOR_WRITEMASK = 50, FS_BIT_3D_TEXTURE = 51, - FS_BIT_COLOR_TO_DEPTH = 52, }; static inline FShaderBit operator +(FShaderBit bit, int i) { diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 7f1c86feb3..488aa86d30 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -265,10 +265,6 @@ SamplerCacheKey TextureCacheCommon::GetSamplingParams(int maxLevel, const TexCac } } - if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) { - forceFiltering = TEX_FILTER_FORCE_NEAREST; - } - switch (forceFiltering) { case TEX_FILTER_AUTO: break; @@ -2247,11 +2243,6 @@ bool TextureCacheCommon::PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEnt plan.scaleFactor = 1; } - // Don't upscale textures in color-to-depth mode. - if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) { - plan.scaleFactor = 1; - } - if ((entry->status & TexCacheEntry::STATUS_CHANGE_FREQUENT) != 0 && plan.scaleFactor != 1 && plan.slowScaler) { // Remember for later that we /wanted/ to scale this texture. entry->status |= TexCacheEntry::STATUS_TO_SCALE; diff --git a/GPU/D3D11/StateMappingD3D11.cpp b/GPU/D3D11/StateMappingD3D11.cpp index 79a169a8ab..da9ec068e6 100644 --- a/GPU/D3D11/StateMappingD3D11.cpp +++ b/GPU/D3D11/StateMappingD3D11.cpp @@ -293,14 +293,7 @@ void DrawEngineD3D11::ApplyDrawState(int prim) { GenericStencilFuncState stencilState; ConvertStencilFuncState(stencilState); - if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) { - // Enforce plain depth writing. - keys_.depthStencil.value = 0; - keys_.depthStencil.depthTestEnable = true; - keys_.depthStencil.depthWriteEnable = true; - keys_.depthStencil.stencilTestEnable = false; - keys_.depthStencil.depthCompareOp = D3D11_COMPARISON_ALWAYS; - } else if (gstate.isModeClear()) { + if (gstate.isModeClear()) { keys_.depthStencil.value = 0; keys_.depthStencil.depthTestEnable = true; keys_.depthStencil.depthCompareOp = D3D11_COMPARISON_ALWAYS; diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index 0de9c1774d..3d06b380e0 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -211,14 +211,7 @@ void DrawEngineDX9::ApplyDrawState(int prim) { ConvertStencilFuncState(stencilState); // Set Stencil/Depth - - if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) { - // Enforce plain depth writing. - dxstate.depthTest.enable(); - dxstate.depthFunc.set(D3DCMP_ALWAYS); - dxstate.depthWrite.set(true); - dxstate.stencilTest.disable(); - } else if (gstate.isModeClear()) { + if (gstate.isModeClear()) { // Depth Test dxstate.depthTest.enable(); dxstate.depthFunc.set(D3DCMP_ALWAYS); diff --git a/GPU/GLES/StateMappingGLES.cpp b/GPU/GLES/StateMappingGLES.cpp index 54c94ccbd3..6e498875f1 100644 --- a/GPU/GLES/StateMappingGLES.cpp +++ b/GPU/GLES/StateMappingGLES.cpp @@ -251,11 +251,7 @@ void DrawEngineGLES::ApplyDrawState(int prim) { GenericStencilFuncState stencilState; ConvertStencilFuncState(stencilState); - if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) { - // Enforce plain depth writing. - renderManager->SetStencilDisabled(); - renderManager->SetDepth(true, true, GL_ALWAYS); - } else if (gstate.isModeClear()) { + if (gstate.isModeClear()) { // Depth Test if (gstate.isClearModeDepthMask()) { framebufferManager_->SetDepthUpdated(); diff --git a/GPU/GPU.h b/GPU/GPU.h index ecb9ae33c4..18af975ae8 100644 --- a/GPU/GPU.h +++ b/GPU/GPU.h @@ -24,11 +24,6 @@ class GPUInterface; class GPUDebugInterface; class GraphicsContext; -enum RasterMode { - RASTER_MODE_NORMAL = 0, - RASTER_MODE_COLOR_TO_DEPTH = 1, -}; - // PSP rasterization has two outputs, color and depth. Stencil is packed // into the alpha channel of color (if exists), so possibly RASTER_COLOR // should be named RASTER_COLOR_STENCIL but it gets kinda hard to read. diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 3f30be89f7..6aaa79a8fd 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -555,14 +555,6 @@ struct GPUStateCache { Dirty(DIRTY_FRAGMENTSHADER_STATE | (is3D ? DIRTY_MIPBIAS : 0)); } } - void SetFramebufferRenderMode(RasterMode mode) { - if (mode != renderMode) { - // This mode modifies the fragment shader to write depth, the depth state to write without testing, and the blend state to write nothing to color. - // So we need to re-evaluate those states. - Dirty(DIRTY_FRAGMENTSHADER_STATE | DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_TEXTURE_PARAMS); - renderMode = mode; - } - } u32 featureFlags; @@ -616,9 +608,6 @@ struct GPUStateCache { // We detect this case and go into a special drawing mode. bool blueToAlpha; - // Some games try to write to the Z buffer using color. Catch that and actually do the writes to the Z buffer instead. - RasterMode renderMode; - // TODO: These should be accessed from the current VFB object directly. u32 curRTWidth; u32 curRTHeight; diff --git a/GPU/Vulkan/StateMappingVulkan.cpp b/GPU/Vulkan/StateMappingVulkan.cpp index 6aa176c864..166f3dc153 100644 --- a/GPU/Vulkan/StateMappingVulkan.cpp +++ b/GPU/Vulkan/StateMappingVulkan.cpp @@ -250,14 +250,7 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag GenericStencilFuncState stencilState; ConvertStencilFuncState(stencilState); - if (gstate_c.renderMode == RASTER_MODE_COLOR_TO_DEPTH) { - // Enforce plain depth writing. - key.depthTestEnable = true; - key.depthWriteEnable = true; - key.stencilTestEnable = false; - key.depthCompareOp = VK_COMPARE_OP_ALWAYS; - key.depthClampEnable = false; - } else if (gstate.isModeClear()) { + if (gstate.isModeClear()) { key.depthTestEnable = true; key.depthCompareOp = VK_COMPARE_OP_ALWAYS; key.depthWriteEnable = gstate.isClearModeDepthMask();