From 6d4c70c67d7ccc3fdd3f6210349ab43e5ab19550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 3 Jun 2026 15:59:36 +0200 Subject: [PATCH] Remove unnecessary scaling and then un-scaling of through-mode Z coordinates --- GPU/Common/VertexDecoderCommon.h | 10 ++-------- GPU/Common/VertexShaderGenerator.cpp | 10 +++------- GPU/Software/TransformUnit.cpp | 3 +-- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/GPU/Common/VertexDecoderCommon.h b/GPU/Common/VertexDecoderCommon.h index 696eee018d..f819ea363c 100644 --- a/GPU/Common/VertexDecoderCommon.h +++ b/GPU/Common/VertexDecoderCommon.h @@ -134,7 +134,7 @@ public: pos[2] = f[2]; } else { // Integer value passed in a float. Clamped to 0, 65535. - pos[2] = (int)f[2] * (1.0f / 65535.0f); + pos[2] = (int)f[2]; } } @@ -144,7 +144,7 @@ public: pos[0] = f[0]; pos[1] = f[1]; // Integer value passed in a float. Clamped to 0, 65535. - pos[2] = (int)f[2] * (1.0f / 65535.0f); + pos[2] = (int)f[2]; } void ReadPosNonThrough(float pos[3]) const { @@ -153,12 +153,6 @@ public: memcpy(pos, f, 12); } - void ReadPosThroughZ16(float pos[3]) const { - // Only DEC_FLOAT_3 is supported. - const float *f = (const float *)(data_ + decFmt_.posoff); - memcpy(pos, f, 12); - } - void ReadNrm(float nrm[3]) const { switch (decFmt_.nrmfmt) { case DEC_FLOAT_3: diff --git a/GPU/Common/VertexShaderGenerator.cpp b/GPU/Common/VertexShaderGenerator.cpp index 0170593798..b4694db13b 100644 --- a/GPU/Common/VertexShaderGenerator.cpp +++ b/GPU/Common/VertexShaderGenerator.cpp @@ -760,13 +760,9 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag } } WRITE(p, " %sv_fogdepth = fog;\n", compat.vsOutPrefix); - if (isModeThrough) { - WRITE(p, " vec4 outPos = position;\n"); - WRITE(p, " outPos.z *= 65536.0;\n"); // TODO: This multiplication should be moved to the vertex decoders for through mode. - } else { - // The viewport has already been applied here, along with the division. - WRITE(p, " vec4 outPos = position;\n"); - } + + // If non-through, the viewport has already been applied here. + WRITE(p, " vec4 outPos = position;\n"); if (fsMinmaxDiscard || fsDepthClamp) { WRITE(p, " %sv_zw = vec2(outPos.z * outPos.w, outPos.w);\n", compat.vsOutPrefix); diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 853a3ce4a2..92a8a6c1e6 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -350,8 +350,7 @@ ClipVertexData TransformUnit::ReadVertex(const VertexReader &vreader, const Tran ClipVertexData vertex; ModelCoords pos; - // VertexDecoder normally scales z, but we want it unscaled. - vreader.ReadPosThroughZ16(pos.AsArray()); + vreader.ReadPosThrough(pos.AsArray()); static Vec3Packedf lastTC; if (state.readUV) {