KhronosGroup / KhronosGroup/SPIRV-Cross

MSL: Shader input overrides are not applied for block, array, and struct types

Open
#2,305 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
GLSL
Stars
2.5k
Forks
713
Avg merge
2d 18h
Merged PRs (30d)
16

Description

I found this during investigation of Vulkan CTS failures related KhronosGroup/MoltenVK#2116. For the following fragment inputs shader input overrides are not applied at all. Setting breakpoints on all usages of `inputs_by_location` shows that none of those codepaths are taken.
```glsl
struct _14
{
vec4 _m0;
ivec3 _m1;
};

layout(location = 0) in _2
{
flat _14 _m0[3];
} _19;
```

This generates the following MSL, regardless whether `--msl-shader-input 1 any32 4` (which should widen the first `int3` to `int4`) was specified. Also, the `flat` specifier is not being propagated properly.
```cpp
struct main0_in
{
float4 m_19_m0_0_m0 [[user(locn0)]];
int3 m_19_m0_0_m1 [[user(locn1)]];
float4 m_19_m0_1_m0 [[user(locn2)]];
int3 m_19_m0_1_m1 [[user(locn3)]];
float4 m_19_m0_2_m0 [[user(locn4)]];
int3 m_19_m0_2_m1 [[user(locn5)]];
};
```

Note that this is a more complicated example, as this uses a struct within an array within a block, but as soon as any fragment inputs are within a block the shader inputs are ignored and not applied. Same happens with structs and arrays.
```glsl
in _2
{
layout(location = 0) vec2 _m0;
layout(location = 1) flat uvec2 _m1;
} _15;
```

Shader outputs for the vertex shader using the same setup but for stage outputs are generated correctly.

I've attached a sample fragment shader that uses the above input setup:
[17782185548125675323.spv.zip](https://github.com/KhronosGroup/SPIRV-Cross/files/14841895/17782185548125675323.spv.zip)
This is the simplest example using just a block as shown above which also fails:
[215374844162041042.spv.zip](https://github.com/KhronosGroup/SPIRV-Cross/files/14842079/215374844162041042.spv.zip)
And the tessellation shader with the same setup, where the shader outputs work correctly, if useful for debugging:
[15478294089967604931.spv.zip](https://github.com/KhronosGroup/SPIRV-Cross/files/14841951/15478294089967604931.spv.zip)

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure with the attached SPIR-V samples and compare the generated MSL for block, array, and struct fragment inputs. Trace the `inputs_by_location` codepaths and the `--msl-shader-input 1 any32 4` option; done means overrides and `flat` interpolation are applied for these inputs, while the reported stage-output behavior remains correct.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.