diff options
| author | kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> | 2024-03-27 13:30:34 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-27 13:30:34 -0700 |
| commit | 56928794d0800824dc91e150cb345b5fec24d930 (patch) | |
| tree | 63f07c0dfad1eb998a683f089755280fde1cc73b /tests | |
| parent | b346a9333ae6d09f053db60b3006e6e074332ac2 (diff) | |
Fix incorrect SPV stride for unsized array (#3837)
* Fix incorrect SPV stride for unsized array (#3825)
In '-emit-spirv-directly' mode, slang generates the stride 0
for unsized array in `OpDecorate` instructions.
For unsized array, the stride is invalid, but we need to provide
a non-zero value to pass the spirv validator.
* Decorate struct with unsized array field as 'Block'
For the struct having unsized array fields, it has to be decorated
as "Block", otherwise it will fails the spirv-val.
So we add a check at in 'emitGlobalInst' when emitting spirv for
'kIROp_StructType', where if there is unsized array field inside
the struct, emit a decorate instruction for above purpose.
* Update decoration for kIROp_SizeAndAlignmentDecoration
When add a decoration node for kIROp_SizeAndAlignmentDecoration,
we implicitly convert the 64 bit size to 32 bit. In most cases, this
should not be a problem because we won't have that large data type.
However, we use 64-bit -1 to represent the size of unsized-array,
so in that case, the conversion will change the size to 0, which is
incorrect. So change that decoration to use 64-bit size.
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/bugs/gh-3825.slang | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/bugs/gh-3825.slang b/tests/bugs/gh-3825.slang new file mode 100644 index 000000000..1feadb588 --- /dev/null +++ b/tests/bugs/gh-3825.slang @@ -0,0 +1,23 @@ + +// Emit 0xFFFF as the stride value for the unsized array + +//TEST:SIMPLE(filecheck=CHECK): -entry fragment -stage fragment -emit-spirv-directly -target spirv-assembly -emit-spirv-directly +struct Descriptors { + uint count; + uint array[]; +} + +struct Context { + Descriptors *descriptors; +} + +[[vk::binding(0)]] ConstantBuffer<Context> context; + +// Dummy entry point. +[shader("fragment")] +float4 fragment(): SV_Target +{ + return float4(float(context.descriptors[0].array[0]), 1., 1., 1.); +} + +// CHECK: OpDecorate %_ptr_PhysicalStorageBuffer__runtimearr_uint ArrayStride 65535 |
