| Issue |
242106
|
| Summary |
[HLSL][SPIR-V] cbuffer padding (spirv.Padding) is lowered to i8 struct members, requiring Int8 and 8-bit uniform access
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
jzakharovnv
|
HLSL cbuffer padding is represented in IR as `target("spirv.Padding", N)`. The SPIR-V backend lowers it to an **8-bit integer struct member regardless of N**. An `OpTypeInt 8` member in a `Uniform` block needs `OpCapability Int8` and, in Vulkan, `uniformAndStorageBuffer8BitAccess`. Applications that don't enable that feature get validation errors such as `VUID-RuntimeSpirv-uniformAndStorageBuffer8BitAccess-06329`.
DXC emits no padding member at all, only `Offset` decorations. Member offsets here are already explicit, so the padding member only has to be a valid scalar that fits the gap.
This is the i8 stopgap mentioned during review of #167404 ("the first step will be to simply use int8").
### Repro
```hlsl
cbuffer CB : register(b0) { float a; float4 b; }; // 12 bytes of padding after 'a'
float4 main() : SV_Position { return b * a; }
```
```
clang --driver-mode=dxc -T vs_6_6 -E main -spirv -fspv-target-env=vulkan1.3 repro.hlsl -Fo out.spv
spirv-dis out.spv
```
IR-only equivalent (`llc -O0 -mtriple=spirv-unknown-vulkan1.3-compute`):
```llvm
%S = type <{ float, target("spirv.Padding", 12), <4 x float> }>
```
### Actual
```
OpCapability Int8
%spirv_Padding = OpTypeInt 8 0
%__cblayout_CB = OpTypeStruct %float %spirv_Padding %v4float
```
### Expected
The padding member type should not need 8-bit access when its size allows a wider type: `i32` if `N % 4 == 0`, `i16` if `N % 2 == 0`, else `i8`.
```
%__cblayout_CB = OpTypeStruct %float %uint %v4float
```
Offsets (0, 4, 16) are unchanged.
### Notes
- Resource name strings (the `@.str` operand of `llvm.spv.resource.handlefrombinding`) also emit `i8` arrays, so `OpCapability Int8` can still appear for that unrelated reason. This issue is only about the padding member type.
- A later pass that drops padding entirely (as DXC does) would make this moot. A width-based lowering is a small interim fix.
- Related but distinct: #180600 (extra padding after reconstituted arrays).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs