gfx-rs / naga

Universal shader translation in Rust

Home Page:https://github.com/gfx-rs/wgpu/tree/trunk/naga

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vulkan validation error: "OpTypeStruct containing an OpTypeRuntimeArray must be decorated with Block or BufferBlock"

SludgePhD opened this issue · comments

commented

I ran into an issue in webonnx/wonnx#161 that causes a large amount of validation errors (due to the large number of shaders compiled by that project). This was surfaced when I updated the validation layers (I'm now at 1.3.243.0-1 of vulkan-validation-layers on Arch Linux), and I think the root cause is naga emitting invalid SPIR-V.

The validation errors all look like this:

[2023-04-18T00:42:44Z ERROR wgpu_hal::vulkan::instance] VALIDATION [UNASSIGNED-CoreValidation-Shader-InconsistentSpirv (0x6bbb14)]
        Validation Error: [ UNASSIGNED-CoreValidation-Shader-InconsistentSpirv ] Object 0: handle = 0x7f1894544910, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x6bbb14 | SPIR-V module not valid: [VUID-StandaloneSpirv-OpTypeRuntimeArray-04680] Vulkan, OpTypeStruct containing an OpTypeRuntimeArray must be decorated with Block or BufferBlock.
      %ArrayVector = OpTypeStruct %_runtimearr_Vec4
    
[2023-04-18T00:42:44Z ERROR wgpu_hal::vulkan::instance]         objects: (type: DEVICE, hndl: 0x7f1894544910, name: ?)

And I think the reason we're seeing them is that every shader starts with a preamble like this:

type Scalar = f32;
type Vec3 = vec3<f32>;
type Vec4 = vec4<f32>;

struct Array {
	data: array<Scalar>
};

struct ArrayVector {
	data: array<Vec4>
};

type Mat3x3 = mat3x3<f32>;
type Mat4x4 = mat4x4<f32>;
type Mat4x3 = mat4x3<f32>;

struct ArrayMatrix {
	data: array<Mat4x4>
};

struct ArrayMatrix3 {
	data: array<Mat3x3>
};