llvm / llvm/llvm-project

[SPIRV] GetDimensions needs to use OpImageQuerySizeLod for resources with 1D, 2D, 3D, and Cube dimensions

Open
#197,837 0 comments 0 reactions 0 assignees View on GitHub
clang:HLSL:SPIRV HLSL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The GetDimensions methods for resources that have 1D, 2D, 3D, and Cube dimensions need to use `OpImageQuerySizeLod`, not `OpImageQuerySize`, even if we don't use the `levels` output.

Consider:
```hlsl
[[vk::binding(0, 0)]] Texture2D Tex1 : register(t0);
[[vk::binding(1, 0)]] RWBuffer Out : register(u1);

[numthreads(1, 1, 1)]
void main() {
uint uwidth, uheight;

Tex1.GetDimensions(uwidth, uheight);
Out[0] = (float)uwidth;
Out[1] = (float)uheight;
}
```
Compiler Explorer: https://hlsl.godbolt.org/z/34vo68hEP

[OpImageQuerySize] requires that its Image object is only 2D or 3D if it is multisampled or if it is only used without a sampler:
> Image must be an object whose type is [OpTypeImage](https://registry.khronos.org/SPIR-V/specs/1.1/SPIRV.html#OpTypeImage). Its [Dim](https://registry.khronos.org/SPIR-V/specs/1.1/SPIRV.html#Dim) operand must be one of Rect or Buffer, or if its MS is 1, it can be 2D, or, if its Sampled Type is 0 or 2, it can be 2D or 3D. It cannot be an image with level of detail; there is no implicit level-of-detail consumed by this instruction. See [OpImageQuerySizeLod](https://registry.khronos.org/SPIR-V/specs/1.1/SPIRV.html#OpImageQuerySizeLod) for querying images having level of detail.

This is enforced by `spirv-val`.

[OpImageQuerySizeLod], on the other hand, can only be used with non-multisampled resources that have a Dim of 1D, 2D, 3D, or Cube.
> Image must be an object whose type is [OpTypeImage](https://registry.khronos.org/SPIR-V/specs/1.1/SPIRV.html#OpTypeImage). Its [Dim](https://registry.khronos.org/SPIR-V/specs/1.1/SPIRV.html#Dim) operand must be one of 1D, 2D, 3D, or Cube, and its MS must be 0. See [OpImageQuerySize](https://registry.khronos.org/SPIR-V/specs/1.1/SPIRV.html#OpImageQuerySize) for querying image types without level of detail.

[OpImageQuerySize]: https://registry.khronos.org/SPIR-V/specs/1.1/SPIRV.html#OpImageQuerySize
[OpImageQuerySizeLod]: https://registry.khronos.org/SPIR-V/specs/1.1/SPIRV.html#OpImageQuerySizeLod

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.