From ac6f04c15995061ebe8e0ddf62ecf7eb979afb65 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 9 Oct 2024 07:35:10 -0700 Subject: Fix spirv lowering logic around pointer to unsized array. (#5243) * Fix spirv lowering logic around pointer to unsized array. * Fix. --------- Co-authored-by: Ellie Hermaszewska --- tests/bugs/gh-3825.slang | 10 +++++++--- tests/spirv/ptr-unsized-array.slang | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 tests/spirv/ptr-unsized-array.slang (limited to 'tests') diff --git a/tests/bugs/gh-3825.slang b/tests/bugs/gh-3825.slang index 1feadb588..c7c325864 100644 --- a/tests/bugs/gh-3825.slang +++ b/tests/bugs/gh-3825.slang @@ -4,7 +4,7 @@ //TEST:SIMPLE(filecheck=CHECK): -entry fragment -stage fragment -emit-spirv-directly -target spirv-assembly -emit-spirv-directly struct Descriptors { uint count; - uint array[]; + uint4 array[]; } struct Context { @@ -17,7 +17,11 @@ struct Context { [shader("fragment")] float4 fragment(): SV_Target { - return float4(float(context.descriptors[0].array[0]), 1., 1., 1.); + return float4(float(context.descriptors->array[0].x), 1., 1., 1.); } -// CHECK: OpDecorate %_ptr_PhysicalStorageBuffer__runtimearr_uint ArrayStride 65535 +// CHECK: OpDecorate %_ptr_PhysicalStorageBuffer_Descriptors_natural ArrayStride 4 +// CHECK: %{{.*}} = OpPtrAccessChain %_ptr_PhysicalStorageBuffer_Descriptors_natural %{{.*}} %int_1 +// CHECK: OpBitcast %ulong +// CHECK: OpIAdd %ulong %{{.*}} %ulong_4 +// CHECK: OpBitcast %_ptr_PhysicalStorageBuffer \ No newline at end of file diff --git a/tests/spirv/ptr-unsized-array.slang b/tests/spirv/ptr-unsized-array.slang new file mode 100644 index 000000000..48added5c --- /dev/null +++ b/tests/spirv/ptr-unsized-array.slang @@ -0,0 +1,23 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +// CHECK: OpPtrAccessChain + +struct MeshVertex { + float3 Pos; + float2 TexCoord; +}; +struct MeshData { + float4x4 ModelMat; + MeshVertex Vertices[]; +}; +struct DispatchParams { + MeshData* Mesh; + float3* Dest; +}; + +[vk::push_constant] DispatchParams pc; + +[numthreads(64)] +void ComputeMain(uint tid: SV_DispatchThreadID) { + pc.Dest[tid] = pc.Mesh->Vertices[tid].Pos; +} \ No newline at end of file -- cgit v1.2.3