From 0253bacf5e85d5e7953288cdd8f25602d2f41b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 11 Jan 2026 20:32:32 +0100 Subject: [PATCH] Simplify line expansion --- GPU/Common/SoftwareTransformCommon.cpp | 40 ++++++++++++++------------ GPU/Common/SoftwareTransformCommon.h | 1 - GPU/D3D11/DrawEngineD3D11.cpp | 1 - GPU/GLES/DrawEngineGLES.cpp | 1 - GPU/Vulkan/DrawEngineVulkan.cpp | 1 - 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/GPU/Common/SoftwareTransformCommon.cpp b/GPU/Common/SoftwareTransformCommon.cpp index ae1627111b..d512c9e2d4 100644 --- a/GPU/Common/SoftwareTransformCommon.cpp +++ b/GPU/Common/SoftwareTransformCommon.cpp @@ -542,12 +542,14 @@ void SoftwareTransform::BuildDrawingParams(int prim, int vertexCount, u32 vertTy } void SoftwareTransform::CalcCullParams(float &minZValue, float &maxZValue) const { + // TODO: The below is probably completely bogus now. + // The projected Z can be up to 0x3F8000FF, which is where this constant is from. // It seems like it may only maintain 15 mantissa bits (excluding implied.) maxZValue = 1.000030517578125f * gstate.getViewportZScale(); minZValue = -maxZValue; // Scale and offset the Z appropriately, since we baked that into a projection transform. - if (params_.usesHalfZ) { + if (true) { // params_.usesHalfZ) { maxZValue = maxZValue * 0.5f + 0.5f + gstate.getViewportZCenter() * 0.5f; minZValue = minZValue * 0.5f + 0.5f + gstate.getViewportZCenter() * 0.5f; } else { @@ -707,10 +709,10 @@ bool SoftwareTransform::ExpandLines(int vertexCount, int &numDecodedVerts, int v u16 *newInds = inds + vertexCount; u16 *indsOut = newInds; - float dx = 1.0f * gstate_c.vpWidthScale * (1.0f / fabsf(gstate.getViewportXScale())); - float dy = 1.0f * gstate_c.vpHeightScale * (1.0f / fabsf(gstate.getViewportYScale())); - float du = 1.0f / gstate_c.curTextureWidth; - float dv = 1.0f / gstate_c.curTextureHeight; + float dx = 1.0f; + float dy = 1.0f; + float du = 1.0f; + float dv = 1.0f; if (throughmode) { dx = 1.0f; @@ -731,8 +733,8 @@ bool SoftwareTransform::ExpandLines(int vertexCount, int &numDecodedVerts, int v const TransformedVertex &transVtx2 = transformed[indsIn[i + 1]]; // Okay, let's calculate the perpendicular. - float horizontal = transVtx2.x * transVtx2.pos_w - transVtx1.x * transVtx1.pos_w; - float vertical = transVtx2.y * transVtx2.pos_w - transVtx1.y * transVtx1.pos_w; + float horizontal = transVtx2.x - transVtx1.x; + float vertical = transVtx2.y - transVtx1.y; Vec2f addWidth = Vec2f(-vertical, horizontal).Normalized(); @@ -740,13 +742,13 @@ bool SoftwareTransform::ExpandLines(int vertexCount, int &numDecodedVerts, int v float yoff = addWidth.y * dy; // bottom right - trans[0].CopyFromWithOffset(transVtx2, xoff * transVtx2.pos_w, yoff * transVtx2.pos_w); + trans[0].CopyFromWithOffset(transVtx2, xoff, yoff); // top right - trans[1].CopyFromWithOffset(transVtx1, xoff * transVtx1.pos_w, yoff * transVtx1.pos_w); + trans[1].CopyFromWithOffset(transVtx1, xoff, yoff); // top left - trans[2].CopyFromWithOffset(transVtx1, -xoff * transVtx1.pos_w, -yoff * transVtx1.pos_w); + trans[2].CopyFromWithOffset(transVtx1, -xoff, -yoff); // bottom left - trans[3].CopyFromWithOffset(transVtx2, -xoff * transVtx2.pos_w, -yoff * transVtx2.pos_w); + trans[3].CopyFromWithOffset(transVtx2, -xoff, -yoff); // Triangle: BR-TR-TL indsOut[0] = i * 2 + 0; @@ -779,21 +781,21 @@ bool SoftwareTransform::ExpandLines(int vertexCount, int &numDecodedVerts, int v const TransformedVertex &transVtxBL = (transVtxT.y != transVtxB.y || transVtxT.x > transVtxB.x) ? transVtxB : transVtxT; // Okay, let's calculate the perpendicular. - float horizontal = transVtxTL.x * transVtxTL.pos_w - transVtxBL.x * transVtxBL.pos_w; - float vertical = transVtxTL.y * transVtxTL.pos_w - transVtxBL.y * transVtxBL.pos_w; + float horizontal = transVtxTL.x - transVtxBL.x; + float vertical = transVtxTL.y - transVtxBL.y; Vec2f addWidth = Vec2f(-vertical, horizontal).Normalized(); // bottom right trans[0] = transVtxBL; - trans[0].x += addWidth.x * dx * trans[0].pos_w; - trans[0].y += addWidth.y * dy * trans[0].pos_w; + trans[0].x += addWidth.x * dx; + trans[0].y += addWidth.y * dy; trans[0].u += addWidth.x * du * trans[0].uv_w; trans[0].v += addWidth.y * dv * trans[0].uv_w; // top right trans[1] = transVtxTL; - trans[1].x += addWidth.x * dx * trans[1].pos_w; - trans[1].y += addWidth.y * dy * trans[1].pos_w; + trans[1].x += addWidth.x * dx; + trans[1].y += addWidth.y * dy; trans[1].u += addWidth.x * du * trans[1].uv_w; trans[1].v += addWidth.y * dv * trans[1].uv_w; @@ -856,8 +858,8 @@ bool SoftwareTransform::ExpandPoints(int vertexCount, int &maxIndex, int vertsSi // Create the bottom right version. TransformedVertex transVtxBR = transVtxTL; - transVtxBR.x += dx * transVtxTL.pos_w; - transVtxBR.y += dy * transVtxTL.pos_w; + transVtxBR.x += dx; + transVtxBR.y += dy; transVtxBR.u += du * transVtxTL.uv_w; transVtxBR.v += dv * transVtxTL.uv_w; diff --git a/GPU/Common/SoftwareTransformCommon.h b/GPU/Common/SoftwareTransformCommon.h index 1f5f630fa5..8c500b618a 100644 --- a/GPU/Common/SoftwareTransformCommon.h +++ b/GPU/Common/SoftwareTransformCommon.h @@ -58,7 +58,6 @@ struct SoftwareTransformParams { TextureCacheCommon *texCache; bool allowClear; bool allowSeparateAlphaClear; - bool usesHalfZ; }; // Converts an index buffer to make the provoking vertex the last. diff --git a/GPU/D3D11/DrawEngineD3D11.cpp b/GPU/D3D11/DrawEngineD3D11.cpp index 50de886257..a8dd24dd36 100644 --- a/GPU/D3D11/DrawEngineD3D11.cpp +++ b/GPU/D3D11/DrawEngineD3D11.cpp @@ -402,7 +402,6 @@ void DrawEngineD3D11::Flush() { params.texCache = textureCache_; params.allowClear = true; params.allowSeparateAlphaClear = false; // D3D11 doesn't support separate alpha clears - params.usesHalfZ = true; if (gstate.getShadeMode() == GE_SHADE_FLAT) { // We need to rotate the index buffer to simulate a different provoking vertex. diff --git a/GPU/GLES/DrawEngineGLES.cpp b/GPU/GLES/DrawEngineGLES.cpp index ff19b3220e..6d3a6ac804 100644 --- a/GPU/GLES/DrawEngineGLES.cpp +++ b/GPU/GLES/DrawEngineGLES.cpp @@ -351,7 +351,6 @@ void DrawEngineGLES::Flush() { params.texCache = textureCache_; params.allowClear = true; // Clear in OpenGL respects scissor rects, so we'll use it. params.allowSeparateAlphaClear = true; - params.usesHalfZ = false; // We need correct viewport values in gstate_c already. if (gstate_c.IsDirty(DIRTY_VIEWPORTSCISSOR_STATE)) { diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index a71b3adeee..ac19fa8402 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -420,7 +420,6 @@ void DrawEngineVulkan::Flush() { IndexBufferProvokingLastToFirst(prim, inds, vertexCount); } } - params.usesHalfZ = true; // We need to update the viewport early because it's checked for flipping in SoftwareTransform. // We don't have a "DrawStateEarly" in vulkan, so...