glslang/Test/spv.structCopy.comp
Arcady Goldmints-Orlov adcc7e8163 Add tests for conditionals that return a struct value
There are 3 separate tests added to cover the 3 cases in
visitSelection(). With SPIR-V versions prior to 1.4, control flow is
generated, with GLSL generating code to execute only the appropriate
branch of the conditional while HLSL executes both branches and uses the
control flow to select the appropriate one. Finally, with SPIR-V
versions newer than 1.4, OpSelect can be used on structs.

Note that the hlsl.structcopy.comp and hlsl.structcopylogical.comp tests
have identical shader code, but are compiled with different versions of
SPIR-V and result in different codepaths being used and different SPIR-V
generated.
2023-04-03 12:33:59 -04:00

38 lines
572 B
Plaintext

#version 460
layout(local_size_x = 512, local_size_y = 1) in;
layout(std430) buffer;
struct MyStruct {
uint a;
uint b;
uint c;
};
layout(binding = 0) buffer MyStructs {
uint count;
MyStruct data[];
}
my_structs;
layout(binding = 1) buffer Output {
uint a;
uint b;
uint c;
}
o;
shared MyStruct s[512];
void main() {
s[0] = MyStruct(1, 2, 3);
uint id = gl_GlobalInvocationID.x;
MyStruct ms =
id > my_structs.count ? s[id - my_structs.count] : my_structs.data[id];
atomicAdd(o.a, ms.a);
atomicAdd(o.b, ms.b);
atomicAdd(o.c, ms.c);
}