google / shaderc

A collection of tools, libraries, and tests for Vulkan shader compilation.
Other
1.86k stars 363 forks source link

When compiling shaders with target environment errors occur. #1410

Open AlanFayz opened 7 months ago

AlanFayz commented 7 months ago

I have been using shaderc in project to compile shaders in runtime rather than through the command line then provide the spirv file. when compiling the glsl file it works when using normal compiler options where nothing is set, however recently I needed some extra functionality with ray tracing which requires a higher version of spirv. I set the target enviorment here

shaderc::Compiler Compiler;
shaderc::CompileOptions Options;

Options.SetIncluder(std::make_unique<Includer>());
Options.SetTargetEnvironment(shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_3);

Where i set the target enviroment, however now I am recieving errors regarding curtain extensions being needed such as SPV_KHR_storage_buffer_storage_c

The exact error:

2 VUID-VkShaderModuleCreateInfo-pCode-08737 Validation Error: [ VUID-VkShaderModuleCreateInfo-pCode-08737 ] | MessageID = 0xa5625282 | vkCreateShaderModule(): pCreateInfo->pCode (spirv-val produced an error): 2nd operand of TypePointer: operand StorageBuffer(12) requires one of these extensions: SPV_KHR_storage_buffer_storage_class SPV_KHR_variable_pointers %_ptr_StorageBuffer_PerInstanceBuffer = OpTypePointer StorageBuffer %PerInstanceBuffer . The Vulkan spec states: If pCode is a pointer to SPIR-V code, pCode must adhere to the validation rules described by the Validation Rules within a Module section of the SPIR-V Environment appendix (https://vulkan.lunarg.com/doc/view/1.3.280.0/windows/1.3-extensions/vkspec.html#VUID-VkShaderModuleCreateInfo-pCode-08737)

Even when supplying these extensions despite them being core in vulkan 1.1 and I am using vulkan 1.3 It still gives these errors when compiling the shaders. When removing Options.SetTargetEnviroments(), it complains about needing a higher spirv version for raytracing

Exact Error:

assembly compilation failed ../Core/Source/Core/Render/Shaders/Miss.rmiss:2: error: 'GL_EXT_ray_tracing' : not supported for current targeted SPIR-V version

I have also tried to use Options.SetTargetSpirv() however this results in the same error.

My version:

C:\VulkanSDK\1.3.280.0\Bin>glslc --version shaderc v2023.8 v2024.0 spirv-tools v2024.1 v2022.4-451-g04896c46 glslang 11.1.0-937-gd73712b8

Cez02 commented 10 hours ago

Same situation here when using mesh shaders.