KhronosGroup / KhronosGroup/SPIRV-Cross
Metal: last member of vertex output block is always float4 in fragment shader?
- Dominant language
- GLSL
- Stars
- 2.5k
- Forks
- 713
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 16
Description
Hello.
I have an issue with one shader which has a pretty big struct used to pass data from vertex to fragment shader:
```
layout(location = 0) in VertexData
{
vec2 baseUv;
flat uvec2 albdoId;
vec3 emissiveColor;
flat float visibility;
flat uvec2 normalId;
flat float dispAmount;
flat uint materialIndex;
flat uint needsIndividualTransform;
flat mat2 baseUvFromNormalUv;
vec4 wsNormal;
vec3 wsTangent;
vec3 wsBitangent;
vec3 wsView;
} inoutData;
```
This struct gets converted to metal code in vertex shader correctly:
```
struct VertexData
{
float2 baseUv;
uint2 albdoId;
float3 emissiveColor;
float visibility;
uint2 normalId;
float dispAmount;
uint materialIndex;
uint needsIndividualTransform;
float2x2 baseUvFromNormalUv;
float4 wsNormal;
float3 wsTangent;
float3 wsBitangent;
float3 wsView;
};
```
but fragment shader has the last component type changed to float4:
```
struct VertexData
{
float2 baseUv;
uint2 albdoId;
float3 emissiveColor;
float visibility;
uint2 normalId;
float dispAmount;
uint materialIndex;
uint needsIndividualTransform;
float2x2 baseUvFromNormalUv;
float4 wsNormal;
float3 wsTangent;
float3 wsBitangent;
float4 wsView;
};
```
I have played a bit with this struct to find a workaround and it seems that the last member of the struct in fragment shader always* becomes type float4 after conversion to metal. E.g. I have added a dummy single float to keep wsView float3 and that's how generated metal looks like:
```
struct VertexData
{
float2 baseUv;
uint2 albdoId;
float3 emissiveColor;
float visibility;
uint2 normalId;
float dispAmount;
uint materialIndex;
uint needsIndividualTransform;
float2x2 baseUvFromNormalUv;
float4 wsNormal;
float3 wsTangent;
float3 wsBitangent;
float3 wsView;
float4 dummy;
};
```
Looks like a bug to me.
Thank you for the great job!
Contributor guide
No contributing guide indexed for this repository
Research direction
Start from the shader struct shown in the issue and reproduce its vertex-to-fragment conversion to Metal, comparing the generated structures. Trace the conversion path that handles the final member and consider the issue resolved when a final float3 member remains float3 without requiring a dummy field.
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
- 35/100