From ca5b07acffdd18618b2cc8b907e57d28e413df1e Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 4 Nov 2023 20:28:45 +1000 Subject: [PATCH] PostProcessing: Fix for Metal renderer --- src/util/postprocessing.cpp | 2 -- src/util/postprocessing_shader_fx.cpp | 29 ++++++++++++++----------- src/util/postprocessing_shader_glsl.cpp | 3 ++- src/util/shadergen.cpp | 2 +- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/util/postprocessing.cpp b/src/util/postprocessing.cpp index 0ee81d7be..12b350f1c 100644 --- a/src/util/postprocessing.cpp +++ b/src/util/postprocessing.cpp @@ -699,8 +699,6 @@ bool PostProcessing::Apply(GPUFramebuffer* final_target, s32 final_left, s32 fin if (!CheckTargets(target_format, target_width, target_height)) return false; - g_gpu_device->SetViewportAndScissor(final_left, final_top, final_width, final_height); - GPUTexture* input = s_input_texture.get(); GPUFramebuffer* input_fb = s_input_framebuffer.get(); GPUTexture* output = s_output_texture.get(); diff --git a/src/util/postprocessing_shader_fx.cpp b/src/util/postprocessing_shader_fx.cpp index c1f4bd110..d5a77061e 100644 --- a/src/util/postprocessing_shader_fx.cpp +++ b/src/util/postprocessing_shader_fx.cpp @@ -1281,10 +1281,23 @@ bool PostProcessing::ReShadeFXShader::Apply(GPUTexture* input, GPUFramebuffer* f for (const Pass& pass : m_passes) { GL_SCOPE_FMT("Draw pass {}", pass.name.c_str()); - GL_INS_FMT("Render Target: ID {} [{}]", pass.render_target, GetTextureNameForID(pass.render_target)); GPUFramebuffer* output_fb = GetFramebufferByID(pass.render_target, input, final_target); - g_gpu_device->SetFramebuffer(output_fb); + + if (!output_fb) + { + // Drawing to final buffer. + if (!g_gpu_device->BeginPresent(false)) + { + GL_POP(); + return false; + } + } + else + { + g_gpu_device->SetFramebuffer(output_fb); + } + g_gpu_device->SetPipeline(pass.pipeline.get()); // Set all inputs first, before the render pass starts. @@ -1292,7 +1305,7 @@ bool PostProcessing::ReShadeFXShader::Apply(GPUTexture* input, GPUFramebuffer* f for (const Sampler& sampler : pass.samplers) { GL_INS_FMT("Texture Sampler {}: ID {} [{}]", sampler.slot, sampler.texture_id, - GetTextureNameForID(sampler.texture_id)); + GetTextureNameForID(sampler.texture_id)); g_gpu_device->SetTextureSampler(sampler.slot, GetTextureByID(sampler.texture_id, input, final_target), sampler.sampler); bound_textures[sampler.slot] = true; @@ -1306,16 +1319,6 @@ bool PostProcessing::ReShadeFXShader::Apply(GPUTexture* input, GPUFramebuffer* f g_gpu_device->SetTextureSampler(i, nullptr, nullptr); } - if (!output_fb) - { - // Drawing to final buffer. - if (!g_gpu_device->BeginPresent(false)) - { - GL_POP(); - return false; - } - } - g_gpu_device->Draw(pass.num_vertices, 0); } diff --git a/src/util/postprocessing_shader_glsl.cpp b/src/util/postprocessing_shader_glsl.cpp index 0f6427f4f..6845fe501 100644 --- a/src/util/postprocessing_shader_glsl.cpp +++ b/src/util/postprocessing_shader_glsl.cpp @@ -176,6 +176,7 @@ bool PostProcessing::GLSLShader::Apply(GPUTexture* input, GPUFramebuffer* final_ g_gpu_device->SetPipeline(m_pipeline.get()); g_gpu_device->SetTextureSampler(0, input, m_sampler.get()); + g_gpu_device->SetViewportAndScissor(final_left, final_top, final_width, final_height); const u32 uniforms_size = GetUniformsSize(); void* uniforms = g_gpu_device->MapUniformBuffer(uniforms_size); @@ -377,7 +378,7 @@ static float4 o_col0; { if (m_use_glsl_interface_blocks) { - if (IsVulkan()) + if (IsVulkan() || IsMetal()) ss << "layout(location = 0) "; ss << "in VertexData {\n"; diff --git a/src/util/shadergen.cpp b/src/util/shadergen.cpp index 2c5508e10..f8d0c95f1 100644 --- a/src/util/shadergen.cpp +++ b/src/util/shadergen.cpp @@ -19,7 +19,7 @@ ShaderGen::ShaderGen(RenderAPI render_api, bool supports_dual_source_blend) m_spirv(render_api == RenderAPI::Vulkan || render_api == RenderAPI::Metal), m_supports_dual_source_blend(supports_dual_source_blend), m_use_glsl_interface_blocks(false) { -#if defined(ENABLE_OPENGL) || defined(ENABLE_VULKAN) +#if defined(ENABLE_OPENGL) || defined(ENABLE_VULKAN) || defined(__APPLE__) if (m_glsl) { #ifdef ENABLE_OPENGL