From bf9177a31943fd4637778317c8d4f06ec9df39c3 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 14 Apr 2018 21:57:19 -0700 Subject: Added vulkan shader module creation --- Graphics/GLSLTools/include/GLSLSourceBuilder.h | 8 +++++++- Graphics/GLSLTools/src/GLSL2SPIRV.cpp | 4 +++- Graphics/GLSLTools/src/GLSLSourceBuilder.cpp | 9 ++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) (limited to 'Graphics/GLSLTools') diff --git a/Graphics/GLSLTools/include/GLSLSourceBuilder.h b/Graphics/GLSLTools/include/GLSLSourceBuilder.h index c0ab5a7d..572ea180 100644 --- a/Graphics/GLSLTools/include/GLSLSourceBuilder.h +++ b/Graphics/GLSLTools/include/GLSLSourceBuilder.h @@ -29,6 +29,12 @@ namespace Diligent { -String BuildGLSLSourceString(const ShaderCreationAttribs &CreationAttribs); +enum TargetGLSLCompiler +{ + glslang, + driver +}; + +String BuildGLSLSourceString(const ShaderCreationAttribs &CreationAttribs, TargetGLSLCompiler TargetCompiler); } \ No newline at end of file diff --git a/Graphics/GLSLTools/src/GLSL2SPIRV.cpp b/Graphics/GLSLTools/src/GLSL2SPIRV.cpp index e36a3196..69cadd2c 100644 --- a/Graphics/GLSLTools/src/GLSL2SPIRV.cpp +++ b/Graphics/GLSLTools/src/GLSL2SPIRV.cpp @@ -201,7 +201,9 @@ std::vector GLSLtoSPIRV(const SHADER_TYPE ShaderType, const char * const char *ShaderStrings[] = { ShaderSource }; Shader.setStrings(ShaderStrings, 1); - if (!Shader.parse(&Resources, 100, false, messages)) + Shader.setAutoMapBindings(true); + Shader.setAutoMapLocations(true); + if (!Shader.parse(&Resources, 100, false, messages)) { LOG_ERROR_MESSAGE("Failed to parse shader source: \n", Shader.getInfoLog(), '\n', Shader.getInfoDebugLog()); return std::move(spirv); diff --git a/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp b/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp index 064f18aa..f9140a53 100644 --- a/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp +++ b/Graphics/GLSLTools/src/GLSLSourceBuilder.cpp @@ -32,7 +32,7 @@ namespace Diligent { -String BuildGLSLSourceString(const ShaderCreationAttribs &CreationAttribs) +String BuildGLSLSourceString(const ShaderCreationAttribs &CreationAttribs, TargetGLSLCompiler TargetCompiler) { String GLSLSource; @@ -169,6 +169,13 @@ String BuildGLSLSourceString(const ShaderCreationAttribs &CreationAttribs) "layout(std140) uniform;\n" ); + if(ShaderType == SHADER_TYPE_VERTEX && TargetCompiler == TargetGLSLCompiler::glslang) + { + // https://github.com/KhronosGroup/GLSL/blob/master/extensions/khr/GL_KHR_vulkan_glsl.txt + GLSLSource.append("#define gl_VertexID gl_VertexIndex\n" + "#define gl_InstanceID gl_InstanceIndex\n"); + } + const Char* ShaderTypeDefine = nullptr; switch (ShaderType) { -- cgit v1.2.3