Skip to content

Commit

Permalink
Vulkan ARM mali Z hack: Modify the matrix instead of the shader.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Sep 8, 2019
1 parent 0462c01 commit f76adfd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
3 changes: 0 additions & 3 deletions Common/Vulkan/VulkanContext.h
Expand Up @@ -363,6 +363,3 @@ std::string FormatDriverVersion(const VkPhysicalDeviceProperties &props);


// Simple heuristic. // Simple heuristic.
bool IsHashMaliDriverVersion(const VkPhysicalDeviceProperties &props); bool IsHashMaliDriverVersion(const VkPhysicalDeviceProperties &props);

// For the ARM Mali depth scale hack.
#define DEPTH_SCALE_HACK_VALUE 0.9999f
5 changes: 5 additions & 0 deletions GPU/Common/ShaderUniforms.cpp
Expand Up @@ -151,6 +151,10 @@ void BaseUpdateUniforms(UB_VS_FS_Base *ub, uint64_t dirtyUniforms, bool flipView
flippedMatrix = flippedMatrix * g_display_rot_matrix; 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()); CopyMatrix4x4(ub->proj, flippedMatrix.getReadPtr());
} }


Expand All @@ -164,6 +168,7 @@ 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) { if (g_Config.iRenderingMode == FB_NON_BUFFERED_MODE && g_display_rotation != DisplayRotation::ROTATE_0) {
proj_through = proj_through * g_display_rot_matrix; proj_through = proj_through * g_display_rot_matrix;
} }
proj_through[10] *= 0.999f;
CopyMatrix4x4(ub->proj_through, proj_through.getReadPtr()); CopyMatrix4x4(ub->proj_through, proj_through.getReadPtr());
} }


Expand Down
3 changes: 3 additions & 0 deletions GPU/GPUState.h
Expand Up @@ -500,6 +500,9 @@ enum {
GPU_PREFER_REVERSE_COLOR_ORDER = FLAG_BIT(31), GPU_PREFER_REVERSE_COLOR_ORDER = FLAG_BIT(31),
}; };


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

struct KnownVertexBounds { struct KnownVertexBounds {
u16 minU; u16 minU;
u16 minV; u16 minV;
Expand Down
4 changes: 0 additions & 4 deletions GPU/Vulkan/VertexShaderGeneratorVulkan.cpp
Expand Up @@ -636,10 +636,6 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) {
} }
WRITE(p, " gl_Position = outPos;\n"); WRITE(p, " gl_Position = outPos;\n");


if (gstate_c.Supports(GPU_NEEDS_DEPTH_SCALE_HACK)) {
WRITE(p, " gl_Position.z *= %f;\n", DEPTH_SCALE_HACK_VALUE);
}

WRITE(p, "}\n"); WRITE(p, "}\n");
return true; return true;
} }

0 comments on commit f76adfd

Please sign in to comment.