From e3b0050ca14248f01b1d08134ad9799c7963cdb5 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 3 May 2024 13:24:32 +1000 Subject: [PATCH] GPU/HW: Fix shader sampling with MSAA on --- src/util/shadergen.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/util/shadergen.cpp b/src/util/shadergen.cpp index 0b6ab97ec..e778181bd 100644 --- a/src/util/shadergen.cpp +++ b/src/util/shadergen.cpp @@ -590,8 +590,10 @@ void ShaderGen::DeclareFragmentEntryPoint( #ifdef ENABLE_VULKAN if (m_render_api == RenderAPI::Vulkan) { - ss << "layout(input_attachment_index = 0, set = 2, binding = 0) uniform subpassInput u_input_rt;\n"; - ss << "#define LAST_FRAG_COLOR subpassLoad(u_input_rt)\n"; + ss << "layout(input_attachment_index = 0, set = 2, binding = 0) uniform " + << (msaa ? "subpassInputMS" : "subpassInput") << " u_input_rt; \n"; + ss << "#define LAST_FRAG_COLOR " << (msaa ? "subpassLoad(u_input_rt, gl_SampleID)" : "subpassLoad(u_input_rt)") + << "\n"; } #endif #ifdef __APPLE__ @@ -600,13 +602,16 @@ void ShaderGen::DeclareFragmentEntryPoint( if (m_supports_framebuffer_fetch) { // Set doesn't matter, because it's transformed to color0. - ss << "layout(input_attachment_index = 0, set = 2, binding = 0) uniform subpassInput u_input_rt;\n"; - ss << "#define LAST_FRAG_COLOR subpassLoad(u_input_rt)\n"; + ss << "layout(input_attachment_index = 0, set = 2, binding = 0) uniform " + << (msaa ? "subpassInputMS" : "subpassInput") << " u_input_rt; \n"; + ss << "#define LAST_FRAG_COLOR " + << (msaa ? "subpassLoad(u_input_rt, gl_SampleID)" : "subpassLoad(u_input_rt)") << "\n"; } else { - ss << "layout(set = 2, binding = 0) uniform texture2D u_input_rt;\n"; - ss << "#define LAST_FRAG_COLOR texelFetch(u_input_rt, int2(gl_FragCoord.xy), 0)\n"; + ss << "layout(set = 2, binding = 0) uniform " << (msaa ? "texture2D" : "texture2DMS") << "u_input_rt;\n"; + ss << "#define LAST_FRAG_COLOR texelFetch(u_input_rt, int2(gl_FragCoord.xy), " << (msaa ? "gl_SampleID" : "0") + << ")\n"; } } #endif