Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU: Add a small error-compensation to depth clip #16380

Merged
merged 1 commit into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions GPU/Common/GeometryShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion GPU/Common/VertexShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down