Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPIR-V shader causing validation errors at runtime

Tags:

vulkan

spir-v

I have a compute shader:

#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_gpu_shader_int64 : enable

layout(local_size_x_id = 0) in;

layout(set = 0, binding = 0) buffer Foo {
    u64vec2[256] scratchpad;
} foo;

layout(set = 0, binding = 1) uniform Bar {
    u64vec2 a;
    u64vec2 b;
} bar;

void main() {
    int foobar = 0;
    int baz = 0;
}

I compiled this with glslangValidator from LunarG SDK 1.0.65.0 and checked it using spirv-val, which returned nothing. I enabled shaderInt64when creating the VkDevice. When loading this shader using vkCreateShaderModule I get this validation error:

SPIR-V module not valid: Invalid instruction word count: 0

The validation error goes away when I do any of the following:

  • Remove the 64-bit extension and change all types to int
  • Remove either Foo or Bar buffers
  • Remove either variables in main
  • Remove layout(local_size_x_id = 0) in

My question is, is this a bug in the compiler or validation layers, or am I using one of these features incorrectly?

like image 598
vazgriz Avatar asked Feb 13 '26 09:02

vazgriz


1 Answers

If you are loading SPIR-V at runtime from file, you have to open the file in a binary mode (e.g. std::ifstream::binary in C++). Otherwise your binary may get changed when loading (i.e. usually the runtime tries to switch newline character(s) based on the platform it runs on).

Alternativelly you can load shaders statically (via #include) as a C++ inline file. You can create such file by glslc -mfmt=c or glslangValidator -V -x --vn variable_name.

like image 105
krOoze Avatar answered Feb 16 '26 20:02

krOoze