From d24e8fda83018cd17524170ec23d18c303b33646 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 28 Oct 2024 23:20:15 +1000 Subject: [PATCH] GPU/HW: Only enable fbfetch/DSB when needed Thanks Adreno... --- src/core/gpu_hw_shadergen.cpp | 2 +- src/util/shadergen.cpp | 22 ++++++++++++++++------ src/util/shadergen.h | 3 ++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/core/gpu_hw_shadergen.cpp b/src/core/gpu_hw_shadergen.cpp index 4cb7fd1cf..997cd86e9 100644 --- a/src/core/gpu_hw_shadergen.cpp +++ b/src/core/gpu_hw_shadergen.cpp @@ -731,7 +731,7 @@ std::string GPU_HW_ShaderGen::GenerateBatchFragmentShader( texture_filtering != GPUTextureFilter::Nearest)); std::stringstream ss; - WriteHeader(ss, use_rov); + WriteHeader(ss, use_rov, shader_blending && !use_rov, use_dual_source); DefineMacro(ss, "TRANSPARENCY", render_mode != GPU_HW::BatchRenderMode::TransparencyDisabled); DefineMacro(ss, "TRANSPARENCY_ONLY_OPAQUE", render_mode == GPU_HW::BatchRenderMode::OnlyOpaque); DefineMacro(ss, "TRANSPARENCY_ONLY_TRANSPARENT", render_mode == GPU_HW::BatchRenderMode::OnlyTransparent); diff --git a/src/util/shadergen.cpp b/src/util/shadergen.cpp index dacd9185e..1e8380c18 100644 --- a/src/util/shadergen.cpp +++ b/src/util/shadergen.cpp @@ -151,8 +151,14 @@ TinyString ShaderGen::GetGLSLVersionString(RenderAPI render_api, u32 version) (glsl_es && major_version >= 3) ? " es" : ""); } -void ShaderGen::WriteHeader(std::stringstream& ss, bool enable_rov /* = false */) const +void ShaderGen::WriteHeader(std::stringstream& ss, bool enable_rov /* = false */, + bool enable_framebuffer_fetch /* = false */, + bool enable_dual_source_blend /* = false */) const { + DebugAssert((!enable_rov && !enable_framebuffer_fetch && !enable_dual_source_blend) || + (enable_rov && !enable_framebuffer_fetch && !enable_dual_source_blend) || + (enable_rov && !enable_framebuffer_fetch && !enable_dual_source_blend) || + (!enable_rov && !enable_framebuffer_fetch && enable_dual_source_blend)); if (m_shader_language == GPUShaderLanguage::GLSL || m_shader_language == GPUShaderLanguage::GLSLES) ss << m_glsl_version_string << "\n\n"; else if (m_spirv) @@ -169,7 +175,8 @@ void ShaderGen::WriteHeader(std::stringstream& ss, bool enable_rov /* = false */ #ifdef ENABLE_OPENGL // Extension enabling for OpenGL. - if (m_shader_language == GPUShaderLanguage::GLSL || m_shader_language == GPUShaderLanguage::GLSLES) + if (enable_framebuffer_fetch && + (m_shader_language == GPUShaderLanguage::GLSL || m_shader_language == GPUShaderLanguage::GLSLES)) { if (GLAD_GL_EXT_shader_framebuffer_fetch) ss << "#extension GL_EXT_shader_framebuffer_fetch : require\n"; @@ -180,10 +187,13 @@ void ShaderGen::WriteHeader(std::stringstream& ss, bool enable_rov /* = false */ if (m_shader_language == GPUShaderLanguage::GLSLES) { // Enable EXT_blend_func_extended for dual-source blend on OpenGL ES. - if (GLAD_GL_EXT_blend_func_extended) - ss << "#extension GL_EXT_blend_func_extended : require\n"; - if (GLAD_GL_ARB_blend_func_extended) - ss << "#extension GL_ARB_blend_func_extended : require\n"; + if (enable_dual_source_blend) + { + if (GLAD_GL_EXT_blend_func_extended) + ss << "#extension GL_EXT_blend_func_extended : require\n"; + if (GLAD_GL_ARB_blend_func_extended) + ss << "#extension GL_ARB_blend_func_extended : require\n"; + } // Test for V3D driver - we have to fudge coordinates slightly. if (std::strstr(reinterpret_cast(glGetString(GL_VENDOR)), "Broadcom") && diff --git a/src/util/shadergen.h b/src/util/shadergen.h index 50c823535..714acbb2b 100644 --- a/src/util/shadergen.h +++ b/src/util/shadergen.h @@ -42,7 +42,8 @@ protected: void DefineMacro(std::stringstream& ss, const char* name, bool enabled) const; void DefineMacro(std::stringstream& ss, const char* name, s32 value) const; - void WriteHeader(std::stringstream& ss, bool enable_rov = false) const; + void WriteHeader(std::stringstream& ss, bool enable_rov = false, bool enable_framebuffer_fetch = false, + bool enable_dual_source_blend = false) const; void WriteUniformBufferDeclaration(std::stringstream& ss, bool push_constant_on_vulkan) const; void DeclareUniformBuffer(std::stringstream& ss, const std::initializer_list& members, bool push_constant_on_vulkan) const;