Repository navigation
Closed
KhronosGroup/SPIRV-Tools
#6535Description
Description
Using RWTexture2D<float4>[16][32] for example produces invalid SPIRV. Annotating this resource with [[vk::image_format("unknown")]] produces a validation error. It seems like this feature is unsupported, while with DXIL this works okay (though it flattens it to a 1D array).
Steps to Reproduce
//dxc -spirv -E mainCompute -T cs_6_5
RWTexture2D<float4> _test[16][32];
[numthreads(8, 8, 1)]
void mainCompute(uint2 id : SV_DispatchThreadID) {
_test[0][0][id] = float4(id, 0, 1);
}fatal error: generated SPIR-V is invalid: [VUID-StandaloneSpirv-UniformConstant-04655] UniformConstant OpVariable <id> '4[%_test]' has illegal type.
Variables identified with the UniformConstant storage class are used only as handles to refer to opaque resources. Such variables must be typed as OpTypeImage, OpTypeSampler, OpTypeSampledImage, OpTypeAccelerationStructureKHR, or an array of one of these types.
%_test = OpVariable %_ptr_UniformConstantarrarr_type_2d_image_uint_32_uint_16 UniformConstant
note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible
And
[[vk::image_format("unknown")]] RWTexture2D<float4> _test[16][32];
[numthreads(8, 8, 1)]
void mainCompute(uint2 id : SV_DispatchThreadID) {
_test[0][0][id] = float4(id, 0, 1);
}C:\local\Temp\ea8c1737-a2f4-421d-a3b7-88e1c5278ee6.hlsl:2:3: error: 'image_format' attribute only applies to RWTextures, Buffers and RWBuffers
[[vk::image_format("unknown")]] RWTexture2D<float4> _test[16][32];
^
Actual Behavior
Spirv to support this with arrays of arrays (if possible by spec), otherwise flattening the array or throwing an error that's clearer about lack of multi dimensional descriptor array support.
Environment
- DXC version: latest
- Host Operating System: N/A
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
- StatusShow more project fieldsTriaged
Activity
s-perron commentedon Nov 28, 2025
I gave this a little thought. We currently do a straight translation of the two dimensional array. This seems reasonable for DXC. Modifying the type while translating the AST will create many special case I don't want to deal with. I think the more reasonable solution is to write a spir-v pass to legalize this. It will look for resources that are multidimensional arrays in the appropriate storage class, and turns them into a single dimensional array.
The validation rules we are interested in avoiding are:
spirv-opt: Add LegalizeMultidimArrayPass
spirv-opt: Add LegalizeMultidimArrayPass
spirv-opt: Add LegalizeMultidimArrayPass (#6535)
[SPIRV] Update spir-v submodules and handle multi-dim array
[SPIRV] Update spir-v submodules and handle multi-dim array (#8167)
[SPIRV] Update spir-v submodules and handle multi-dim array (microsof…