From 967ad0bb4da04969bfc541f586a44861aa549644 Mon Sep 17 00:00:00 2001 From: Try Date: Thu, 28 Sep 2023 23:58:51 +0200 Subject: [PATCH] Fix unroll, when storing to pointer to array #fixed #2196 --- .../shaders-hlsl/comp/ssbo-store-array.comp | 22 +++++++++++++++++++ shaders-hlsl/comp/ssbo-store-array.comp | 19 ++++++++++++++++ spirv_hlsl.cpp | 7 +++++- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 reference/shaders-hlsl/comp/ssbo-store-array.comp create mode 100644 shaders-hlsl/comp/ssbo-store-array.comp diff --git a/reference/shaders-hlsl/comp/ssbo-store-array.comp b/reference/shaders-hlsl/comp/ssbo-store-array.comp new file mode 100644 index 000000000..d078a3806 --- /dev/null +++ b/reference/shaders-hlsl/comp/ssbo-store-array.comp @@ -0,0 +1,22 @@ +struct Data +{ + uint arr[3]; +}; + +RWByteAddressBuffer _13 : register(u0); + +void comp_main() +{ + Data d1; + [unroll] + for (int _0ident = 0; _0ident < 3; _0ident++) + { + _13.Store(_0ident * 4 + 0, d1.arr[_0ident]); + } +} + +[numthreads(1, 1, 1)] +void main() +{ + comp_main(); +} diff --git a/shaders-hlsl/comp/ssbo-store-array.comp b/shaders-hlsl/comp/ssbo-store-array.comp new file mode 100644 index 000000000..dc2a508d8 --- /dev/null +++ b/shaders-hlsl/comp/ssbo-store-array.comp @@ -0,0 +1,19 @@ +#version 460 + +struct Data +{ + uint arr[3]; +}; + +layout(set = 0, binding = 0, std430) buffer B0 +{ + Data d[]; +}; + +void main() +{ + Data d1; + d[0].arr = d1.arr; +} + + diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index 8ba79b630..29b1e7709 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -4696,7 +4696,12 @@ void CompilerHLSL::emit_load(const Instruction &instruction) void CompilerHLSL::write_access_chain_array(const SPIRAccessChain &chain, uint32_t value, const SmallVector &composite_chain) { - auto &type = get(chain.basetype); + auto *ptype = &get(chain.basetype); + while (ptype->pointer) + { + ptype = &get(ptype->basetype); + } + auto &type = *ptype; // Need to use a reserved identifier here since it might shadow an identifier in the access chain input or other loops. auto ident = get_unique_identifier();