diff --git a/GPU/Common/GPUStateUtils.cpp b/GPU/Common/GPUStateUtils.cpp index 0353e3ac96..824d3827b1 100644 --- a/GPU/Common/GPUStateUtils.cpp +++ b/GPU/Common/GPUStateUtils.cpp @@ -676,7 +676,7 @@ void ConvertViewportAndScissor(bool useBufferedRendering, float renderWidth, flo float minz = gstate.getDepthRangeMin(); float maxz = gstate.getDepthRangeMax(); - if (gstate.isClippingEnabled() && (minz == 0 || maxz == 65535)) { + if (gstate.isDepthClampEnabled() && (minz == 0 || maxz == 65535)) { // Here, we should "clamp." But clamping per fragment would be slow. // So, instead, we just increase the available range and hope. // If depthSliceFactor is 4, it means (75% / 2) of the depth lies in each direction. diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 06b14867c4..a73023927f 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -58,7 +58,7 @@ struct GPUgstate { region2, lightingEnable, lightEnable[4], - clipEnable, + depthClampEnable, cullfaceEnable, textureMapEnable, // 0x1E GE_CMD_TEXTUREMAPENABLE fogEnable, @@ -392,8 +392,9 @@ struct GPUgstate { int getRegionX2() const { return (region2 & 0x3FF); } int getRegionY2() const { return (region2 >> 10) & 0x3FF; } + bool isDepthClampEnabled() const { return depthClampEnable & 1; } + // Note that the X1/Y1/Z1 here does not mean the upper-left corner, but half the dimensions. X2/Y2/Z2 are the center. - bool isClippingEnabled() const { return clipEnable & 1; } float getViewportXScale() const { return getFloat24(viewportxscale); } float getViewportYScale() const { return getFloat24(viewportyscale); } float getViewportZScale() const { return getFloat24(viewportzscale); } diff --git a/GPU/Software/Clipper.cpp b/GPU/Software/Clipper.cpp index 2dcb1dd919..85c9fc6efd 100644 --- a/GPU/Software/Clipper.cpp +++ b/GPU/Software/Clipper.cpp @@ -39,6 +39,7 @@ enum { static inline int CalcClipMask(const ClipCoords& v) { int mask = 0; + // This checks `x / w` compared to 1 or -1, skipping the division. if (v.x > v.w) mask |= CLIP_POS_X_BIT; if (v.x < -v.w) mask |= CLIP_NEG_X_BIT; if (v.y > v.w) mask |= CLIP_POS_Y_BIT; @@ -255,7 +256,9 @@ void ProcessLine(VertexData& v0, VertexData& v1) return; } - if (mask && gstate.isClippingEnabled()) { + if (mask && gstate.isDepthClampEnabled()) { + // TODO: Validate if this logic is correct / should be in depthClampEnabled. + // discard if any vertex is outside the near clipping plane if (mask & CLIP_NEG_Z_BIT) return; @@ -303,7 +306,9 @@ void ProcessTriangle(VertexData& v0, VertexData& v1, VertexData& v2) mask |= CalcClipMask(v1.clippos); mask |= CalcClipMask(v2.clippos); - if (mask && gstate.isClippingEnabled()) { + if (mask && gstate.isDepthClampEnabled()) { + // TODO: Validate if this logic is correct / should be in depthClampEnabled. + // discard if any vertex is outside the near clipping plane if (mask & CLIP_NEG_Z_BIT) return; diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index f1e7e9581b..911bdbf94f 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -105,7 +105,7 @@ static inline ScreenCoords ClipToScreenInternal(const ClipCoords& coords, bool * float z = coords.z * zScale / coords.w + zCenter; // This matches hardware tests - depth is clamped when this flag is on. - if (gstate.isClippingEnabled()) { + if (gstate.isDepthClampEnabled()) { if (z < 0.f) z = 0.f; if (z > 65535.f) diff --git a/GPU/Vulkan/StateMappingVulkan.cpp b/GPU/Vulkan/StateMappingVulkan.cpp index 1e78e352ef..68bc711a1d 100644 --- a/GPU/Vulkan/StateMappingVulkan.cpp +++ b/GPU/Vulkan/StateMappingVulkan.cpp @@ -247,7 +247,7 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag // Set cull bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled(); key.cullMode = wantCull ? (gstate.getCullMode() ? VK_CULL_MODE_FRONT_BIT : VK_CULL_MODE_BACK_BIT) : VK_CULL_MODE_NONE; - key.depthClampEnable = gstate.isClippingEnabled() && gstate_c.Supports(GPU_SUPPORTS_DEPTH_CLAMP); + key.depthClampEnable = gstate.isDepthClampEnabled() && gstate_c.Supports(GPU_SUPPORTS_DEPTH_CLAMP); } }