SPIRV-Cross/reference/shaders-msl-no-opt/packing/isolated-scalar-access.comp
Hans-Kristian Arntzen fa5b206d97 MSL: Workaround broken vector -> scalar access chain in MSL.
On MSL, the compiler refuses to allow access chains into a normal vector type.
What happens in practice instead is a read-modify-write where a vector type is
loaded, modified and written back.

The workaround is to convert a vector into a pointer-to-scalar before
the access chain continues to add the scalar index.
2020-07-06 10:03:44 +02:00

27 lines
552 B
Plaintext

#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct SSBO
{
float4 v;
float4x4 cm;
float4x4 rm;
packed_float3 v3;
float f;
};
kernel void main0(device SSBO& _12 [[buffer(0)]])
{
threadgroup float4 shared_vec4;
threadgroup float3 shared_vec3;
((device float*)&_12.v)[0u] = 10.0;
_12.v3[1u] = 40.0;
((device float*)&_12.cm[1])[2u] = 20.0;
((device float*)&_12.rm[1u])[3] = 30.0;
((threadgroup float*)&shared_vec4)[2u] = 40.0;
((threadgroup float*)&shared_vec3)[1u] = 1.0;
}