rust-gpu icon indicating copy to clipboard operation
rust-gpu copied to clipboard

Declaring RuntimeArray without `Capability::RuntimeDescriptorArray` set on `SpirvBuilder` emits an unintuitive error message.

Open SiebenCorgie opened this issue 3 years ago • 0 comments

When trying to compile a shader with a runtime array descriptor without having Capability::RuntimeDescriptorArray enabled on SpirvBuilder emits an unintuitive error.

For instance the following main function:

#[spirv(fragment)]
pub fn main_fs(
   ...,
   #[spirv(push_constant)] push: &PushConst,
    #[spirv(descriptor_set = 0, binding = 0)] sampled_images: &RuntimeArray<SampledImage<Image!(2D, type=f32, sampled)>>,
    ...
) {
    //...
    let img = unsafe { sampled_images.index(push.texture_indices[0] as usize) };
    //...    
}

emits this error:

error: OpVariable, <id> '19[%sampled_images]', is attempting to create memory for an illegal type, OpTypeRuntimeArray.
       For Vulkan OpTypeRuntimeArray can only appear as the final member of an OpTypeStruct, thus cannot be instantiated via OpVariable
         %sampled_images = OpVariable %_ptr_UniformConstant__runtimearr_40 UniformConstant

While the error is correct without the capability, the use of RuntimeArray probably indicates that RuntimeDescriptorArrays is assumed to be present.

A small hint like: "Do you need to enabled the RuntimeDescriptorArray capability?" would be appropriate,

SiebenCorgie avatar Jun 07 '22 13:06 SiebenCorgie