summaryrefslogtreecommitdiffstats
path: root/Graphics/GLSLTools
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-07-05 19:18:53 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-07-05 19:18:53 +0000
commita5f7f7836865e02c265704b6b4abf7ab1916962d (patch)
treeec38a386d69d6e8690d532e54aad040ccab23f9e /Graphics/GLSLTools
parentAdded NDC attribs data to DeviceCaps structure (diff)
downloadDiligentCore-a5f7f7836865e02c265704b6b4abf7ab1916962d.tar.gz
DiligentCore-a5f7f7836865e02c265704b6b4abf7ab1916962d.zip
Added shader compiler error reporting in Vulkan
Diffstat (limited to 'Graphics/GLSLTools')
-rw-r--r--Graphics/GLSLTools/include/GLSL2SPIRV.h3
-rw-r--r--Graphics/GLSLTools/src/GLSL2SPIRV.cpp38
2 files changed, 36 insertions, 5 deletions
diff --git a/Graphics/GLSLTools/include/GLSL2SPIRV.h b/Graphics/GLSLTools/include/GLSL2SPIRV.h
index 75ef5872..5951af2c 100644
--- a/Graphics/GLSLTools/include/GLSL2SPIRV.h
+++ b/Graphics/GLSLTools/include/GLSL2SPIRV.h
@@ -25,12 +25,13 @@
#include <vector>
#include "Shader.h"
+#include "DataBlob.h"
namespace Diligent
{
void InitializeGlslang();
void FinalizeGlslang();
-std::vector<unsigned int> GLSLtoSPIRV(const SHADER_TYPE ShaderType, const char *ShaderSource);
+std::vector<unsigned int> GLSLtoSPIRV(const SHADER_TYPE ShaderType, const char* ShaderSource, IDataBlob** ppCompilerOutput);
} \ No newline at end of file
diff --git a/Graphics/GLSLTools/src/GLSL2SPIRV.cpp b/Graphics/GLSLTools/src/GLSL2SPIRV.cpp
index 81f2009a..5ee3d685 100644
--- a/Graphics/GLSLTools/src/GLSL2SPIRV.cpp
+++ b/Graphics/GLSLTools/src/GLSL2SPIRV.cpp
@@ -38,6 +38,7 @@
#include "GLSL2SPIRV.h"
#include "DebugUtilities.h"
+#include "DataBlobImpl.h"
namespace Diligent
{
@@ -267,7 +268,18 @@ public:
}
};
-std::vector<unsigned int> GLSLtoSPIRV(const SHADER_TYPE ShaderType, const char *ShaderSource)
+static void InitializeCompilerOutputBlob(const char* ShaderSource, const std::string& ErrorLog, IDataBlob** ppCompilerOutput)
+{
+ VERIFY_EXPR(ppCompilerOutput != nullptr);
+ auto SourceLen = strlen(ShaderSource);
+ auto* pOutputDataBlob = MakeNewRCObj<DataBlobImpl>()(SourceLen + 1 + ErrorLog.length() + 1);
+ char* DataPtr = reinterpret_cast<char*>(pOutputDataBlob->GetDataPtr());
+ memcpy(DataPtr, ErrorLog.data(), ErrorLog.length() + 1);
+ memcpy(DataPtr + ErrorLog.length() + 1, ShaderSource, SourceLen + 1);
+ pOutputDataBlob->QueryInterface(IID_DataBlob, reinterpret_cast<IObject**>(ppCompilerOutput));
+}
+
+std::vector<unsigned int> GLSLtoSPIRV(const SHADER_TYPE ShaderType, const char* ShaderSource, IDataBlob** ppCompilerOutput)
{
#if PLATFORM_ANDROID
@@ -291,13 +303,22 @@ std::vector<unsigned int> GLSLtoSPIRV(const SHADER_TYPE ShaderType, const char *
// Enable SPIR-V and Vulkan rules when parsing GLSL
EShMessages messages = (EShMessages)(EShMsgSpvRules | EShMsgVulkanRules);
- const char *ShaderStrings[] = { ShaderSource };
+ const char* ShaderStrings[] = { ShaderSource };
Shader.setStrings(ShaderStrings, 1);
Shader.setAutoMapBindings(true);
if (!Shader.parse(&Resources, 100, false, messages))
{
- LOG_ERROR_MESSAGE("Failed to parse shader source: \n", Shader.getInfoLog(), '\n', Shader.getInfoDebugLog());
+ std::string Log(Shader.getInfoLog());
+ if(*Shader.getInfoDebugLog() != '\0')
+ {
+ Log.push_back('\n');
+ Log.append(Shader.getInfoDebugLog());
+ }
+ LOG_ERROR_MESSAGE("Failed to parse shader source: \n", Log);
+ if(ppCompilerOutput != nullptr)
+ InitializeCompilerOutputBlob(ShaderSource, Log, ppCompilerOutput);
+
return {};
}
@@ -305,7 +326,16 @@ std::vector<unsigned int> GLSLtoSPIRV(const SHADER_TYPE ShaderType, const char *
Program.addShader(&Shader);
if (!Program.link(messages))
{
- LOG_ERROR_MESSAGE("Failed to link program: \n", Shader.getInfoLog(), '\n', Shader.getInfoDebugLog());
+ std::string Log(Shader.getInfoLog());
+ if(*Shader.getInfoDebugLog() != '\0')
+ {
+ Log.push_back('\n');
+ Log.append(Shader.getInfoDebugLog());
+ }
+ LOG_ERROR_MESSAGE("Failed to link program: \n", Log);
+ if(ppCompilerOutput != nullptr)
+ InitializeCompilerOutputBlob(ShaderSource, Log, ppCompilerOutput);
+
return {};
}