Merge pull request #16380 from unknownbrackets/depth-clip-err

GPU: Add a small error-compensation to depth clip
This commit is contained in:
Henrik Rydgård 2022-11-13 10:11:42 +01:00 committed by GitHub
commit 1a0e5c1903
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -123,7 +123,8 @@ bool GenerateGeometryShader(const GShaderID &id, char *buffer, const ShaderLangu
if (!gstate_c.Use(GPU_USE_CLIP_DISTANCE)) {
// This is basically the same value as gl_ClipDistance would take, z + w.
if (vertexRangeCulling) {
p.C(" clip0[i] = projZ * outPos.w + outPos.w;\n");
// We add a small amount to prevent error as in #15816 (PSP Z is only 16-bit fixed point, anyway.)
p.F(" clip0[i] = projZ * outPos.w + outPos.w + %f;\n", 0.0625 / 65536.0);
} else {
// Let's not complicate the code overly for this case. We'll clipClampedDepth.
p.C(" clip0[i] = 0.0;\n");
@ -290,7 +291,8 @@ bool GenerateGeometryShader(const GShaderID &id, char *buffer, const ShaderLangu
p.F(" gl_ClipDistance%s = projZ * outPos.w + outPos.w;\n", clipSuffix1);
} else {
// We shouldn't need to worry about rectangles-as-triangles here, since we don't use geometry shaders for that.
p.F(" gl_ClipDistance%s = projZ * outPos.w + outPos.w;\n", clipSuffix0);
// We add a small amount to prevent error as in #15816 (PSP Z is only 16-bit fixed point, anyway.)
p.F(" gl_ClipDistance%s = projZ * outPos.w + outPos.w + %f;\n", clipSuffix0, 0.0625 / 65536.0);
}
p.C(" gl_Position = outPos;\n");
if (gstate_c.Use(GPU_USE_CLIP_DISTANCE)) {

View file

@ -1328,7 +1328,8 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag
const char *cull1 = compat.shaderLanguage == HLSL_D3D11 ? ".y" : "[1]";
if (gstate_c.Use(GPU_USE_CLIP_DISTANCE)) {
// TODO: Ignore triangles from GE_PRIM_RECTANGLES in transform mode, which should not clip to neg z.
WRITE(p, " %sgl_ClipDistance%s = projZ * outPos.w + outPos.w;\n", compat.vsOutPrefix, vertexRangeClipSuffix);
// We add a small amount to prevent error as in #15816 (PSP Z is only 16-bit fixed point, anyway.)
WRITE(p, " %sgl_ClipDistance%s = projZ * outPos.w + outPos.w + %f;\n", compat.vsOutPrefix, vertexRangeClipSuffix, 0.0625 / 65536.0);
}
if (gstate_c.Use(GPU_USE_CULL_DISTANCE)) {
// Cull any triangle fully outside in the same direction when depth clamp enabled.