From 448e19629d7930c5ad7df370b63f26bbfbee4874 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 29 Aug 2018 13:12:19 +1000 Subject: [PATCH] Vulkan: Drop usage of VK_NV_glsl extension It's not providing a large performance improvement anymore, after the more recent drivers introduced a new shader compiler. --- .../VideoBackends/Vulkan/ShaderCompiler.cpp | 69 ------------------- .../VideoBackends/Vulkan/VulkanContext.cpp | 1 - .../Core/VideoBackends/Vulkan/VulkanContext.h | 4 +- 3 files changed, 1 insertion(+), 73 deletions(-) diff --git a/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp b/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp index 82f0e825a5da..d430c8bab98d 100644 --- a/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp +++ b/Source/Core/VideoBackends/Vulkan/ShaderCompiler.cpp @@ -39,11 +39,6 @@ static bool CompileShaderToSPV(SPIRVCodeVector* out_code, EShLanguage stage, const char* stage_filename, const char* source_code, size_t source_code_length, const char* header, size_t header_length); -// Copy GLSL source code to a SPIRVCodeVector, for use with VK_NV_glsl_shader. -static void CopyGLSLToSPVVector(SPIRVCodeVector* out_code, const char* stage_filename, - const char* source_code, size_t source_code_length, - const char* header, size_t header_length); - // Regarding the UBO bind points, we subtract one from the binding index because // the OpenGL backend requires UBO #0 for non-block uniforms (at least on NV). // This allows us to share the same shaders but use bind point #0 in the Vulkan @@ -226,42 +221,6 @@ bool CompileShaderToSPV(SPIRVCodeVector* out_code, EShLanguage stage, const char return true; } -void CopyGLSLToSPVVector(SPIRVCodeVector* out_code, const char* stage_filename, - const char* source_code, size_t source_code_length, const char* header, - size_t header_length) -{ - std::string full_source_code; - if (header_length > 0) - { - full_source_code.reserve(header_length + source_code_length); - full_source_code.append(header, header_length); - full_source_code.append(source_code, source_code_length); - } - else - { - full_source_code.append(source_code, source_code_length); - } - - if (g_ActiveConfig.iLog & CONF_SAVESHADERS) - { - static int counter = 0; - std::string filename = StringFromFormat("%s%s_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), - stage_filename, counter++); - - std::ofstream stream; - File::OpenFStream(stream, filename, std::ios_base::out); - if (stream.good()) - stream << full_source_code << std::endl; - } - - size_t padding = full_source_code.size() % 4; - if (padding != 0) - full_source_code.append(4 - padding, '\n'); - - out_code->resize(full_source_code.size() / 4); - std::memcpy(out_code->data(), full_source_code.c_str(), full_source_code.size()); -} - bool InitializeGlslang() { static bool glslang_initialized = false; @@ -384,13 +343,6 @@ const TBuiltInResource* GetCompilerResourceLimits() bool CompileVertexShader(SPIRVCodeVector* out_code, const char* source_code, size_t source_code_length) { - if (g_vulkan_context->SupportsNVGLSLExtension()) - { - CopyGLSLToSPVVector(out_code, "vs", source_code, source_code_length, SHADER_HEADER, - sizeof(SHADER_HEADER) - 1); - return true; - } - return CompileShaderToSPV(out_code, EShLangVertex, "vs", source_code, source_code_length, SHADER_HEADER, sizeof(SHADER_HEADER) - 1); } @@ -398,13 +350,6 @@ bool CompileVertexShader(SPIRVCodeVector* out_code, const char* source_code, bool CompileGeometryShader(SPIRVCodeVector* out_code, const char* source_code, size_t source_code_length) { - if (g_vulkan_context->SupportsNVGLSLExtension()) - { - CopyGLSLToSPVVector(out_code, "gs", source_code, source_code_length, SHADER_HEADER, - sizeof(SHADER_HEADER) - 1); - return true; - } - return CompileShaderToSPV(out_code, EShLangGeometry, "gs", source_code, source_code_length, SHADER_HEADER, sizeof(SHADER_HEADER) - 1); } @@ -412,13 +357,6 @@ bool CompileGeometryShader(SPIRVCodeVector* out_code, const char* source_code, bool CompileFragmentShader(SPIRVCodeVector* out_code, const char* source_code, size_t source_code_length) { - if (g_vulkan_context->SupportsNVGLSLExtension()) - { - CopyGLSLToSPVVector(out_code, "ps", source_code, source_code_length, SHADER_HEADER, - sizeof(SHADER_HEADER) - 1); - return true; - } - return CompileShaderToSPV(out_code, EShLangFragment, "ps", source_code, source_code_length, SHADER_HEADER, sizeof(SHADER_HEADER) - 1); } @@ -426,13 +364,6 @@ bool CompileFragmentShader(SPIRVCodeVector* out_code, const char* source_code, bool CompileComputeShader(SPIRVCodeVector* out_code, const char* source_code, size_t source_code_length) { - if (g_vulkan_context->SupportsNVGLSLExtension()) - { - CopyGLSLToSPVVector(out_code, "cs", source_code, source_code_length, COMPUTE_SHADER_HEADER, - sizeof(COMPUTE_SHADER_HEADER) - 1); - return true; - } - return CompileShaderToSPV(out_code, EShLangCompute, "cs", source_code, source_code_length, COMPUTE_SHADER_HEADER, sizeof(COMPUTE_SHADER_HEADER) - 1); } diff --git a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp index 32bd44900326..52f0088239f1 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp +++ b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp @@ -418,7 +418,6 @@ bool VulkanContext::SelectDeviceExtensions(ExtensionList* extension_list, bool e if (enable_surface && !SupportsExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME, true)) return false; - m_supports_nv_glsl_extension = SupportsExtension(VK_NV_GLSL_SHADER_EXTENSION_NAME, false); return true; } diff --git a/Source/Core/VideoBackends/Vulkan/VulkanContext.h b/Source/Core/VideoBackends/Vulkan/VulkanContext.h index 1e9841c02963..ec20ded1c883 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanContext.h +++ b/Source/Core/VideoBackends/Vulkan/VulkanContext.h @@ -83,7 +83,7 @@ class VulkanContext { return m_device_features.occlusionQueryPrecise == VK_TRUE; } - bool SupportsNVGLSLExtension() const { return m_supports_nv_glsl_extension; } + // Helpers for getting constants VkDeviceSize GetUniformBufferAlignment() const { @@ -131,8 +131,6 @@ class VulkanContext VkPhysicalDeviceFeatures m_device_features = {}; VkPhysicalDeviceProperties m_device_properties = {}; VkPhysicalDeviceMemoryProperties m_device_memory_properties = {}; - - bool m_supports_nv_glsl_extension = false; }; extern std::unique_ptr g_vulkan_context;