google / shaderc

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

Compute shaders compiling to spir-v version 1.6 generates Vulkan validation error due to OpExecutionMode #1414

Open Wlammm opened 7 months ago

Wlammm commented 7 months ago

Compiling this shader (TestShader.comp):

version 450

layout (local_size_x = 256) in;

void main() { // Compute shader code }

using this code:

shaderc::Compiler compiler; shaderc::CompileOptions options; options.SetTargetEnvironment(shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_3); options.SetWarningsAsErrors(); options.SetGenerateDebugInfo(); options.SetTargetSpirv(shaderc_spirv_version_1_6); options.SetOptimizationLevel(shaderc_optimization_level_performance); shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(shaderSource, shaderc_compute_shader, inputFileName, options);

generates this validation error when running vkCreateShaderModule:

{ Validation } Validation Error: [ VUID-RuntimeSpirv-LocalSizeId-06434 ] | MessageID = 0xf95e08b7 | vkCreateShaderModule(): SPIR-V OpExecutionMode LocalSizeId is used but maintenance4 feature was not enabled. The Vulkan spec states: If Execution Mode LocalSizeId is used, maintenance4 must be enabled

This does not happen if I change the target spir-v version to shaderc_spirv_version_1_5. This does not happen if I compile it directly with glslc.exe -c TestShader.comp.

Tested on Vulkan version 1.3 with Vulkan SDK version 1.3.280.0 and whatever shaderc version is included there.

felix-ri commented 2 months ago

I have a similar issue with compiling this simple MeshShader with this commandline glslc --target-env=vulkan1.3 --target-spv=spv1.6 .\MeshShader.glsl:

#version 450
#extension GL_EXT_mesh_shader : enable
#pragma shader_stage(mesh)

layout(local_size_x = 128, local_size_y = 1, local_size_z = 1) in;

layout(triangles) out;
layout(max_vertices = 256, max_primitives = 256) out;

void main()
{
}

This results in OpExecutionModeId LocalSizeId 128 1 1, which seems wrong to me, as the 128 should not specify any Id, but the literal Workgroup Size.

Compiling it with --target-spv=spv1.5 results in OpExecutionMode LocalSize 128 1 1, which seems to be correct to me.

Compiling it with --target-spv=spv1.6 results in OpExecutionModeId LocalSizeId 128 1 1, which is wrong.