I've just downloaded the lastest Vulkan SDK version (1.3.224.1) and when I try to compile a shader using shaderc
I get this error: error: OpenGL compatibility profile is not supported
.
I've cloned Hazel-2D Engine: https://github.com/TheCherno/Hazel by The Cherno just to check if it works fine because it builds the same Vulkan SDK things as in my project and has the same shaderc
and spirv-cross
code. It works in hazel but does not work inside my project.
shader code:
#version 450 core
layout(location = 0) in vec2 a_position;
layout(location = 1) in vec2 a_uv;
layout(location = 0) out vec2 v_uv;
void main()
{
v_uv = a_uv;
vec4 position = vec4(a_position, 0.0, 1.0);
gl_Position = position;
}
#version 450 core
layout(location = 0) out vec4 f_color;
layout(location = 0) in vec2 v_uv;
void main()
{
f_color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
}
I guess it's not important to show the whole premake script since the project builds fine. I'll show just the most important part: dependencies are defined like this:
VULKAN_SDK = os.getenv("VULKAN_SDK")
IncludeDir["VulkanSDK"] = "%{VULKAN_SDK}/Include"
LibraryDir = {}
LibraryDir["VulkanSDK"] = "%{VULKAN_SDK}/Lib"
Library = {}
Library["ShaderC_Debug"] = "%{LibraryDir.VulkanSDK}/shaderc_sharedd.lib"
Library["SPIRV_Cross_Debug"] = "%{LibraryDir.VulkanSDK}/spirv-cross-cored.lib"
Library["SPIRV_Cross_GLSL_Debug"] = "%{LibraryDir.VulkanSDK}/spirv-cross-glsld.lib"
Library["SPIRV_Tools_Debug"] = "%{LibraryDir.VulkanSDK}/SPIRV-Toolsd.lib"
and linked like this:
includedirs {
--other things...
"%{IncludeDir.VulkanSDK}",
}
filter "configurations:Debug"
symbols "On"
links {
"%{Library.ShaderC_Debug}",
"%{Library.SPIRV_Cross_Debug}",
"%{Library.SPIRV_Cross_GLSL_Debug}",
"%{Library.SPIRV_Tools_Debug}",
}
What I do first is compile Vulkan GLSL code into a spirv binaries (+ caching, but to provide a minimal example I removed it):
std::unordered_map<uint32_t, std::vector<uint32_t>> Shader::CompileGLSLToVulkanSpirvAndCache(const std::unordered_map<uint32_t, std::string>& shaderSource)
{
std::unordered_map<uint32_t, std::vector<uint32_t>> resultBinaries;
shaderc::Compiler compiler;
shaderc::CompileOptions options;
options.SetTargetEnvironment(shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_2);
uint32_t shadersCount = static_cast<uint32_t>(shaderSource.size());
resultBinaries.reserve(shadersCount);
for(const auto& [type, source] : shaderSource) {
shaderc::SpvCompilationResult compilationResult = compiler.CompileGlslToSpv(source, GLShaderTypeToShadercShaderType(type), filepath.generic_string().c_str(), options);
if(compilationResult.GetCompilationStatus() != shaderc_compilation_status_success) {
EngineLogError(compilationResult.GetErrorMessage());
__debugbreak();
}
resultBinaries[type] = std::vector<uint32_t>(compilationResult.cbegin(), compilationResult.cend());
}
return resultBinaries;
}
and then using spirv_cross::CompilerGLSL
I compile the vulkan spirv binaries to opengl spirv.
std::unordered_map<uint32_t, std::vector<uint32_t>> Shader::CompileFromVulkanToOpengl(const std::unordered_map<uint32_t, std::vector<uint32_t>>& vulkanBinaries)
{
std::unordered_map<uint32_t, std::vector<uint32_t>> resultBinaries;
shaderc::Compiler compiler;
shaderc::CompileOptions options;
options.SetTargetEnvironment(shaderc_target_env_opengl_compat, shaderc_env_version_opengl_4_5);
uint32_t shadersCount = static_cast<uint32_t>(vulkanBinaries.size());
resultBinaries.reserve(shadersCount);
for(const auto& [type, binaries] : vulkanBinaries) {
spirv_cross::CompilerGLSL glsl(binaries);
std::string source = glsl.compile();
shaderc::SpvCompilationResult compilationResult = compiler.CompileGlslToSpv(source, GLShaderTypeToShadercShaderType(type), filepath.generic_string().c_str(), options);
if(compilationResult.GetCompilationStatus() != shaderc_compilation_status_success) {
EngineLogError(compilationResult.GetErrorMessage());
__debugbreak();
}
resultBinaries[type] = std::vector<uint32_t>(compilationResult.cbegin(), compilationResult.cend());
}
return resultBinaries;
}
and CompileFromVulkanToOpengl
this function returns this error: error: OpenGL compatibility profile is not supported
.
How to fix it? Why it works in hazel 2d and does not work in my project?
OpenGL Info:
OpenGL Info:
Vendor: NVIDIA Corporation
Renderer: NVIDIA GeForce GTX 1080/PCIe/SSE2
Version: 4.6.0 NVIDIA 516.94