Skip to content
Permalink
Browse files

Vulkan: Slim down and rename the Mali hack.

  • Loading branch information...
hrydgard committed Sep 8, 2019
1 parent f76adfd commit 70ec327b40fd61f6edfb57a44c351d067cb511a9
@@ -150,11 +150,6 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView
if (g_Config.iRenderingMode == FB_NON_BUFFERED_MODE && g_display_rotation != DisplayRotation::ROTATE_0) {
flippedMatrix = flippedMatrix * g_display_rot_matrix;
}

if (gstate_c.Supports(GPU_NEEDS_DEPTH_SCALE_HACK)) {
flippedMatrix[10] *= DEPTH_SCALE_HACK_VALUE;
}

CopyMatrix4x4(ub->proj, flippedMatrix.getReadPtr());
}

@@ -168,7 +163,6 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView
if (g_Config.iRenderingMode == FB_NON_BUFFERED_MODE && g_display_rotation != DisplayRotation::ROTATE_0) {
proj_through = proj_through * g_display_rot_matrix;
}
proj_through[10] *= 0.999f;
CopyMatrix4x4(ub->proj_through, proj_through.getReadPtr());
}

@@ -495,14 +495,11 @@ enum {
GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT = FLAG_BIT(26),
GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT = FLAG_BIT(27),
GPU_SUPPORTS_OES_TEXTURE_NPOT = FLAG_BIT(28),
GPU_NEEDS_DEPTH_SCALE_HACK = FLAG_BIT(29),
GPU_NEEDS_Z_EQUAL_W_HACK = FLAG_BIT(29),
GPU_PREFER_CPU_DOWNLOAD = FLAG_BIT(30),
GPU_PREFER_REVERSE_COLOR_ORDER = FLAG_BIT(31),
};

// For the ARM Mali depth scale hack.
#define DEPTH_SCALE_HACK_VALUE 0.9999f

struct KnownVertexBounds {
u16 minU;
u16 minV;
@@ -962,10 +962,7 @@ void DrawEngineVulkan::DoFlush() {

// We let the framebuffer manager handle the clear. It can use renderpasses to optimize on tilers.
// If non-buffered though, it'll just do a plain clear.
float depth = result.depth;
if (gstate_c.Supports(GPU_NEEDS_DEPTH_SCALE_HACK)) {
depth *= DEPTH_SCALE_HACK_VALUE;
}
// TODO: Don't we need to rescale result.depth if we use GPU_SCALE_DEPTH_FROM_24_TO_16_BIT and similar?
framebufferManager_->NotifyClear(gstate.isClearModeColorMask(), gstate.isClearModeAlphaMask(), gstate.isClearModeDepthMask(), result.color, result.depth);

int scissorX1 = gstate.getScissorX1();
@@ -205,10 +205,10 @@ void GPU_Vulkan::CheckGPUFeatures() {
if (!PSP_CoreParameter().compat.flags().DisableAccurateDepth || driverTooOld) {
features |= GPU_SUPPORTS_ACCURATE_DEPTH;
}
// These GPUs (up to some certain hardware version?) has a bug where draws that touch the upper range of Z
// depth test incorrectly. This is easily worked around by simply scaling Z down a tiny bit, with a small risk
// for artifacts - haven't seen any though.
features |= GPU_NEEDS_DEPTH_SCALE_HACK;
// These GPUs (up to some certain hardware version?) has a bug where draws where gl_Position.w == .z
// corrupt the depth buffer. This is easily worked around by simply scaling Z down a tiny bit when this case
// is detected. See: https://github.com/hrydgard/ppsspp/issues/11937
features |= GPU_NEEDS_Z_EQUAL_W_HACK;
break;
}
default:
@@ -636,6 +636,10 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) {
}
WRITE(p, " gl_Position = outPos;\n");

if (gstate_c.Supports(GPU_NEEDS_Z_EQUAL_W_HACK)) {
// See comment in GPU_Vulkan.cpp.
WRITE(p, " if (gl_Position.z == gl_Position.w) gl_Position.z *= 0.999999;\n");
}
WRITE(p, "}\n");
return true;
}

0 comments on commit 70ec327

Please sign in to comment.
You can’t perform that action at this time.