KhronosGroup / KhronosGroup/SPIRV-Cross
MSL: Generated code incorrectly tries to assign unsafeArray to spvStorage
- Dominant language
- GLSL
- Stars
- 2.5k
- Forks
- 713
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 16
Description
I am trying to compile HLSL to Spirv then spirv to metal.
The following is shortened sample of my usecase:
```
StructuredBuffer buffer;
RWStructuredBuffer outBuffer;
struct Data
{
float4x4 transform[2];
};
groupshared Data gs_Data;
Data GenerateTransformData(in StructuredBuffer buffer, int startOffset)
{
Data d;
d.transform[0][0].xyzw = (buffer[startOffset+0].xyzw);
// ....
d.transform[1][0].xyzw = (buffer[startOffset+4].xyzw);
// ....
return d;
}
[numthreads(64, 1, 1)]
void CS_Main()
{
gs_Data = GenerateTransformData(buffer, 0);
outBuffer[0] = gs_Data.transform[0][0].xyzw;
// ....
}
```
This gets compiled to following Metal code: (I have not added the auto generated code for types)
```
struct Data
{
spvStorage_float4x4 transform[2];
};
constant float4x4 _26 = {};
struct spvDescriptorSetBuffer0
{
const device type_StructuredBuffer_v4float* _buffer [[id(0)]];
device type_RWStructuredBuffer_v4float* outBuffer [[id(1)]];
};
kernel void CS_Main(constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]])
{
threadgroup Data gs_Data;
float4x4 _30;
_30[0] = (*spvDescriptorSet0._buffer)._m0[0u];
float4x4 _33;
_33[0] = (*spvDescriptorSet0._buffer)._m0[4u];
spvUnsafeArray _34 = spvUnsafeArray({ _30, _33 });
gs_Data = Data{ _34 };
(*spvDescriptorSet0.outBuffer)._m0[0u] = gs_Data.transform[0][0u];
}
```
When I compile this with metal.exe I get the error:
```
splash.metal:966:21: error: no viable conversion from 'spvUnsafeArray' (aka
'spvUnsafeArray, 2>') to 'spvStorage_float4x4' (aka 'spvStorageMatrix')
gs_Data = Data{ _34 };
```
Probable fix for this is to unroll the spvUnsafeArraywhile assigning
```
gs_Data = Data{ { _34[0], _34[1] } };
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the HLSL to SPIR-V to Metal case and inspect the generated Metal initializer around `gs_Data = Data{ _34 }`. Confirm that `metal.exe` rejects the `spvUnsafeArray` to `spvStorage_float4x4` conversion; done means generated code compiles without that conversion error.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100