Skip to content

MSL: textureGatherOffsets broken for Metal 3.2+ #2558

@pablode

Description

@pablode

Consider this fragment shader:

#version 460

layout(binding = 0) uniform sampler2D someTex;

layout (location = 0) out vec4 fragColor;

void main()
{
    const ivec2 OFFSETS[4] = ivec2[](ivec2(-1, 0), ivec2(0, 1), ivec2(1, 0), ivec2(0, -1));
   
    vec4 fetches = textureGatherOffsets(someTex, ivec2(0), OFFSETS, 0);
    
    fragColor = fetches;
}

We can compile it with Metal 3.0:

➜  glslangValidator --target-env vulkan1.1 -o shader.spv shader.frag
shader.frag
➜  spirv-cross shader.spv --msl-version 30000 --msl --output shader.metal
➜  xcrun -sdk macosx metal -std=metal3.0 -c -o shader.air shader.metal

However with Metal 3.2 and above, we get this compilation error:

➜  spirv-cross shader.spv --msl-version 40000 --msl --output shader.metal
➜  xcrun -sdk macosx metal -std=metal4.0 -c -o shader.air shader.metal  
shader.metal:147:22: error: no matching function for call to 'spvGatherConstOffsets'
    float4 fetches = spvGatherConstOffsets(someTex, someTexSmplr, _30, component::x, float2(0.0));
                     ^~~~~~~~~~~~~~~~~~~~~
shader.metal:61:18: note: candidate template ignored: could not match 'device Tex<T, access::sample, void>' against 'texture2d<float>'
inline vec<T, 4> spvGatherConstOffsets(const device Tex<T>& t, sampler s, Toff coffsets, component c, Tp... params) METAL_CONST_ARG(c)
                 ^
shader.metal:87:18: note: candidate template ignored: could not match 'constant Tex<T, access::sample, void>' against 'texture2d<float>'
inline vec<T, 4> spvGatherConstOffsets(const constant Tex<T>& t, sampler s, Toff coffsets, component c, Tp... params) METAL_CONST_ARG(c)
                 ^
shader.metal:113:18: note: candidate template ignored: could not match 'void' against 0
inline vec<T, 4> spvGatherConstOffsets(const thread Tex<T>& t, sampler s, Toff coffsets, component c, Tp... params) METAL_CONST_ARG(c)
                 ^
1 error generated

System Info:
Mac mini (Apple M2 Pro), macOS Tahoe 26.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther progress depends on answer from issue creator.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions