Merge pull request #12307 from hrydgard/mali-z-hardware-bug-workaround

Vulkan: Workaround ARM Mali depth hardware bug. Fixes #11937
This commit is contained in:
Henrik Rydgård 2019-09-09 01:05:00 +02:00 committed by GitHub
commit edcd5e1c7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 5 deletions

View File

@ -150,7 +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;
}
CopyMatrix4x4(ub->proj, flippedMatrix.getReadPtr());
}

View File

@ -495,6 +495,7 @@ 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_Z_EQUAL_W_HACK = FLAG_BIT(29),
GPU_PREFER_CPU_DOWNLOAD = FLAG_BIT(30),
GPU_PREFER_REVERSE_COLOR_ORDER = FLAG_BIT(31),
};

View File

@ -970,7 +970,7 @@ void DrawEngineVulkan::DoFlush() {
int scissorY2 = gstate.getScissorY2() + 1;
framebufferManager_->SetSafeSize(scissorX2, scissorY2);
if ((gstate_c.featureFlags & GPU_USE_CLEAR_RAM_HACK) && gstate.isClearModeColorMask() && (gstate.isClearModeAlphaMask() || gstate.FrameBufFormat() == GE_FORMAT_565)) {
if (gstate_c.Supports(GPU_USE_CLEAR_RAM_HACK) && gstate.isClearModeColorMask() && (gstate.isClearModeAlphaMask() || gstate.FrameBufFormat() == GE_FORMAT_565)) {
framebufferManager_->ApplyClearToMemory(scissorX1, scissorY1, scissorX2, scissorY2, result.color);
}
}

View File

@ -205,11 +205,16 @@ 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 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:
if (!PSP_CoreParameter().compat.flags().DisableAccurateDepth)
if (!PSP_CoreParameter().compat.flags().DisableAccurateDepth) {
features |= GPU_SUPPORTS_ACCURATE_DEPTH;
}
break;
}

View File

@ -175,8 +175,7 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) {
if (!useHWTransform && doTextureTransform && !isModeThrough) {
WRITE(p, "layout (location = %d) in vec3 texcoord;\n", (int)PspAttributeLocation::TEXCOORD);
texcoordInVec3 = true;
}
else
} else
WRITE(p, "layout (location = %d) in vec2 texcoord;\n", (int)PspAttributeLocation::TEXCOORD);
}
if (hasColor) {
@ -637,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;
}

View File

@ -134,6 +134,7 @@ public:
// TODO: This should be fixed at the source.
data.viewport.vp.maxDepth = clamp_value(vp.maxDepth, 0.0f, 1.0f);
data.viewport.vp.minDepth = clamp_value(vp.minDepth, 0.0f, 1.0f);
curRenderStep_->commands.push_back(data);
}