summaryrefslogtreecommitdiffstats
path: root/Graphics/GLSLTools
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-04-15 04:57:19 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-04-15 04:57:19 +0000
commitbf9177a31943fd4637778317c8d4f06ec9df39c3 (patch)
tree1d1b9531babca5ab2545f039f0a6a5a08735cf10 /Graphics/GLSLTools
parentAdded GLSL to SPIRV shader compilation (diff)
downloadDiligentCore-bf9177a31943fd4637778317c8d4f06ec9df39c3.tar.gz
DiligentCore-bf9177a31943fd4637778317c8d4f06ec9df39c3.zip
Added vulkan shader module creation
Diffstat (limited to 'Graphics/GLSLTools')
-rw-r--r--Graphics/GLSLTools/include/GLSLSourceBuilder.h8
-rw-r--r--Graphics/GLSLTools/src/GLSL2SPIRV.cpp4
-rw-r--r--Graphics/GLSLTools/src/GLSLSourceBuilder.cpp9
3 files changed, 18 insertions, 3 deletions
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<unsigned int> 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)
{