Permalink
Browse files

Vulkan: Avoid depth clamp with clip range.

Vulkan clamps to the clip range, not the full range.  So when clipping, we
don't really want to clamp at all.  Unfortunately, when one side is
clipping, we can't do it exactly right.

But many games clip depth, like Dissidia.  Fixes #11260.
  • Loading branch information...
unknownbrackets committed Sep 18, 2018
1 parent 44ba31f commit 985982764502c29591c3e006078357f0a3448663
Showing with 13 additions and 6 deletions.
  1. +2 −2 GPU/GPUCommon.cpp
  2. +11 −4 GPU/Vulkan/StateMappingVulkan.cpp
View
@@ -197,8 +197,8 @@ const CommonCommandTableEntry commonCommandTable[] = {
{ GE_CMD_DEPTHCLAMPENABLE, FLAG_FLUSHBEFOREONCHANGE, DIRTY_VIEWPORTSCISSOR_STATE | DIRTY_CULLRANGE | DIRTY_RASTER_STATE },
// Z clip
{ GE_CMD_MINZ, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHRANGE | DIRTY_VIEWPORTSCISSOR_STATE },
{ GE_CMD_MAXZ, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHRANGE | DIRTY_VIEWPORTSCISSOR_STATE },
{ GE_CMD_MINZ, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHRANGE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE },
{ GE_CMD_MAXZ, FLAG_FLUSHBEFOREONCHANGE, DIRTY_DEPTHRANGE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE },
// Region
{ GE_CMD_REGION1, FLAG_FLUSHBEFOREONCHANGE, DIRTY_FRAMEBUF | DIRTY_TEXTURE_PARAMS | DIRTY_VIEWPORTSCISSOR_STATE },
@@ -239,15 +239,22 @@ void DrawEngineVulkan::ConvertStateToVulkanKey(FramebufferManagerVulkan &fbManag
}
if (gstate_c.IsDirty(DIRTY_RASTER_STATE)) {
if (gstate.isModeClear()) {
if (gstate.isModeClear() || gstate.isModeThrough()) {
key.cullMode = VK_CULL_MODE_NONE;
// TODO: Or does it always clamp?
// TODO: Might happen in clear mode if not through...
key.depthClampEnable = false;
} else {
// Set cull
bool wantCull = !gstate.isModeThrough() && prim != GE_PRIM_RECTANGLES && gstate.isCullEnabled();
bool wantCull = 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.isDepthClampEnabled() && gstate_c.Supports(GPU_SUPPORTS_DEPTH_CLAMP);
if (gstate.getDepthRangeMin() == 0 || gstate.getDepthRangeMax() == 65535) {
// TODO: Still has a bug where we clamp to depth range if one is not the full range.
// But the alternate is not clamping in either direction...
key.depthClampEnable = gstate.isDepthClampEnabled() && gstate_c.Supports(GPU_SUPPORTS_DEPTH_CLAMP);
} else {
// We just want to clip in this case, the clamp would be clipped anyway.
key.depthClampEnable = false;
}
}
}

0 comments on commit 9859827

Please sign in to comment.