Skip to content

Temporary sampler not generated for function parameter in MoltenVK only #858

@baldurk

Description

@baldurk

I have some code that looks like this in GLSL:

// binding = 5 + RESTYPE_x
layout(binding = 6) uniform sampler1DArray tex1DArray;
layout(binding = 7) uniform sampler2DArray tex2DArray;
layout(binding = 8) uniform sampler3D tex3D;
layout(binding = 9) uniform sampler2DMS tex2DMS;
layout(binding = 10) uniform sampler2DArray texYUV[2];

vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int sampleIdx, vec3 texRes,
                         uvec4 YUVDownsampleRate, uvec4 YUVAChannels)
{
  vec4 col;

  if(type == RESTYPE_TEX1D)
  {
    col = textureLod(tex1DArray, vec2(pos.x, slice), float(mipLevel));
  }
  else if(type == RESTYPE_TEX2D)
  {
     ...

When passed through MoltenVK it generates MSL like:


float4 SampleTextureFloat4(thread const int& type, thread const float2& pos, thread const float& slice, thread const int& mipLevel, thread const int& sampleIdx, thread const float3& texRes, thread const uint4& YUVDownsampleRate, thread const uint4& YUVAChannels, thread texture1d_array<float> tex1DArray, thread const sampler tex1DArraySmplr, thread texture2d_array<float> tex2DArray, thread const sampler tex2DArraySmplr, thread texture3d<float> tex3D, thread const sampler tex3DSmplr, thread texture2d_ms<float> tex2DMS, thread const sampler tex2DMSSmplr, thread const array<texture2d_array<float>, 2> texYUV, thread const array<sampler, 2> texYUVSmplr)
{
    texture1d_array<float> _64;
    float4 col;
    if (type == 1)
    {
        _64 = tex1DArray;
        float2 _69 = float2(pos.x, slice);
        col = _64.sample(_64Smplr, _69.x, uint(round(_69.y)));
    }
    else
    {

Which then fails to compile due to the missing _64Smplr. However when I run SPIRV-Cross standalone from the same revision it works OK and I don't know what MoltenVK is doing differently to cause it to generate different code. The options as near as I can tell are the same.

Here's the repro SPIR-V assembly: repro.spvas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugFeature which should work in SPIRV-Cross does not for some reason.in progressIssue is being actively worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions