GPU: Rename clipping flag to depth clamp.

It seems to just to depth clamp.  When depth clamp happens, it affects
clipping a little, but only for vertices that needed clamping.
This commit is contained in:
Unknown W. Brackets 2018-08-05 17:11:51 -07:00
parent 9cb58ef6a3
commit 77f0499f7f
5 changed files with 13 additions and 7 deletions

View File

@ -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.

View File

@ -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); }

View File

@ -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;

View File

@ -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)

View File

@ -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);
}
}