Skip to content

Commit

Permalink
Fix unroll, when storing to pointer to array
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Sep 28, 2023
1 parent 6e1fb9b commit 967ad0b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
22 changes: 22 additions & 0 deletions reference/shaders-hlsl/comp/ssbo-store-array.comp
Original file line number Diff line number Diff line change
@@ -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();
}
19 changes: 19 additions & 0 deletions shaders-hlsl/comp/ssbo-store-array.comp
Original file line number Diff line number Diff line change
@@ -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;
}


7 changes: 6 additions & 1 deletion spirv_hlsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> &composite_chain)
{
auto &type = get<SPIRType>(chain.basetype);
auto *ptype = &get<SPIRType>(chain.basetype);
while (ptype->pointer)
{
ptype = &get<SPIRType>(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();
Expand Down

0 comments on commit 967ad0b

Please sign in to comment.