diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-05-22 23:19:39 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-05-22 23:19:39 +0000 |
| commit | 8151bc6df37372eb91011edede9ffbb258ebeab6 (patch) | |
| tree | c26b3f1cb425ff5069b04c02b8e36b106bea4549 /Graphics | |
| parent | Removed workarounds for GS, HS and DS in Vulkan tests (diff) | |
| download | DiligentCore-8151bc6df37372eb91011edede9ffbb258ebeab6.tar.gz DiligentCore-8151bc6df37372eb91011edede9ffbb258ebeab6.zip | |
Unified VULKAN shader define in VK and GL backends
Diffstat (limited to 'Graphics')
| -rw-r--r-- | Graphics/GLSLTools/include/SPIRVUtils.hpp | 10 | ||||
| -rw-r--r-- | Graphics/GLSLTools/src/SPIRVUtils.cpp | 10 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp | 8 | ||||
| -rw-r--r-- | Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h | 2 | ||||
| -rw-r--r-- | Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h | 2 |
5 files changed, 23 insertions, 9 deletions
diff --git a/Graphics/GLSLTools/include/SPIRVUtils.hpp b/Graphics/GLSLTools/include/SPIRVUtils.hpp index 50889f17..50025303 100644 --- a/Graphics/GLSLTools/include/SPIRVUtils.hpp +++ b/Graphics/GLSLTools/include/SPIRVUtils.hpp @@ -37,7 +37,13 @@ namespace Diligent void InitializeGlslang(); void FinalizeGlslang(); -std::vector<unsigned int> GLSLtoSPIRV(SHADER_TYPE ShaderType, const char* ShaderSource, int SourceCodeLen, IDataBlob** ppCompilerOutput); -std::vector<unsigned int> HLSLtoSPIRV(const ShaderCreateInfo& Attribs, IDataBlob** ppCompilerOutput); +std::vector<unsigned int> GLSLtoSPIRV(SHADER_TYPE ShaderType, + const char* ShaderSource, + int SourceCodeLen, + IDataBlob** ppCompilerOutput); + +std::vector<unsigned int> HLSLtoSPIRV(const ShaderCreateInfo& Attribs, + const char* ExtraDefinitions, + IDataBlob** ppCompilerOutput); } // namespace Diligent
\ No newline at end of file diff --git a/Graphics/GLSLTools/src/SPIRVUtils.cpp b/Graphics/GLSLTools/src/SPIRVUtils.cpp index 4da444e4..e02bc34e 100644 --- a/Graphics/GLSLTools/src/SPIRVUtils.cpp +++ b/Graphics/GLSLTools/src/SPIRVUtils.cpp @@ -85,7 +85,7 @@ EShLanguage ShaderTypeToShLanguage(SHADER_TYPE ShaderType) } } -TBuiltInResource InitResources() +static TBuiltInResource InitResources() { TBuiltInResource Resources; @@ -435,7 +435,9 @@ private: std::unordered_map<IncludeResult*, RefCntAutoPtr<IDataBlob>> m_DataBlobs; }; -std::vector<unsigned int> HLSLtoSPIRV(const ShaderCreateInfo& Attribs, IDataBlob** ppCompilerOutput) +std::vector<unsigned int> HLSLtoSPIRV(const ShaderCreateInfo& Attribs, + const char* ExtraDefinitions, + IDataBlob** ppCompilerOutput) { EShLanguage ShLang = ShaderTypeToShLanguage(Attribs.Desc.ShaderType); glslang::TShader Shader{ShLang}; @@ -476,9 +478,11 @@ std::vector<unsigned int> HLSLtoSPIRV(const ShaderCreateInfo& Attribs, IDataBlob if (const auto* ShaderTypeDefine = GetShaderTypeDefines(Attribs.Desc.ShaderType)) Defines += ShaderTypeDefine; + if (ExtraDefinitions != nullptr) + Defines += ExtraDefinitions; + if (Attribs.Macros != nullptr) { - Defines = g_HLSLDefinitions; Defines += '\n'; auto* pMacro = Attribs.Macros; while (pMacro->Name != nullptr && pMacro->Definition != nullptr) diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index 11385ae6..74293d1b 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -61,15 +61,19 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, DEV_CHECK_ERR(CreationAttribs.ByteCode == nullptr, "'ByteCode' must be null when shader is created from source code or a file"); DEV_CHECK_ERR(CreationAttribs.ByteCodeSize == 0, "'ByteCodeSize' must be 0 when shader is created from source code or a file"); + static constexpr char* VulkanDefine = + "#ifndef VULKAN\n" + "# define VULKAN 1\n" + "#endif\n"; if (CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL) { - m_SPIRV = HLSLtoSPIRV(CreationAttribs, CreationAttribs.ppCompilerOutput); + m_SPIRV = HLSLtoSPIRV(CreationAttribs, VulkanDefine, CreationAttribs.ppCompilerOutput); } else { auto GLSLSource = BuildGLSLSourceString(CreationAttribs, pRenderDeviceVk->GetDeviceCaps(), TargetGLSLCompiler::glslang, - "#define TARGET_API_VULKAN 1\n"); + VulkanDefine); m_SPIRV = GLSLtoSPIRV(m_Desc.ShaderType, GLSLSource.c_str(), static_cast<int>(GLSLSource.length()), diff --git a/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h b/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h index ad3bc2ab..b6f068c2 100644 --- a/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h +++ b/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h @@ -1040,7 +1040,7 @@ vec4 _frexp(vec4 f4, out vec4 fexp4) // Helper functions -#ifdef TARGET_API_VULKAN +#ifdef VULKAN #define NDC_MIN_Z 0.0 // Minimal z in the normalized device space diff --git a/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h b/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h index 042d4958..42d41d90 100644 --- a/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h +++ b/Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h @@ -1040,7 +1040,7 @@ "\n" "// Helper functions\n" "\n" -"#ifdef TARGET_API_VULKAN\n" +"#ifdef VULKAN\n" "\n" "#define NDC_MIN_Z 0.0 // Minimal z in the normalized device space\n" "\n" |
