glslang icon indicating copy to clipboard operation
glslang copied to clipboard

conditional assignment with complex types produces type mismatch error in spirv-val

Open pixeljetstream opened this issue 4 years ago • 1 comments

the code below compiles and ran (glslangValidator from vulkan sdk 1.2.198.1), but produces invalid spirv according to spirv-val. Replacing both #if 1 with if #if 0 one after another, removes the corresponding spirv validation errors.

#version 460

#extension GL_EXT_scalar_block_layout : enable
#extension GL_EXT_buffer_reference2 : enable
#extension GL_EXT_shader_8bit_storage : enable
#extension GL_EXT_shader_16bit_storage : enable
#extension GL_EXT_shader_explicit_arithmetic_types_float16 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int32 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : enable

layout (local_size_x=32) in;

struct PackedVertex {
  uint16_t x;
  uint16_t y;
};

layout(buffer_reference, buffer_reference_align = 4, scalar) restrict readonly buffer uints_in
{
    uint d[];
};

layout(buffer_reference, buffer_reference_align = 4, scalar) restrict readonly buffer PackedVertexs_in
{
    PackedVertex d[];
};

layout(buffer_reference, buffer_reference_align = 4, scalar) restrict writeonly buffer PackedVertexs_out
{
    PackedVertex d[];
};

struct Mesh {
  uints_in          inds;
  PackedVertexs_in  verts;
};

layout(scalar,binding=0) uniform MeshA {
  Mesh  meshA;
};
layout(scalar,binding=1) uniform MeshB {
  Mesh  meshB;
};

layout(push_constant) uniform PushConstant {
  PackedVertexs_out outVerts;
  bool useA;
};

void main()
{
  uint threadID = gl_GlobalInvocationID.x;

#if 1
  Mesh mesh = useA ? meshA : meshB;
#else
  // validation WAR 
  Mesh mesh;
  if (useA) {
    mesh = meshA;
  }
  else {
    mesh = meshB;
  }
#endif
  
  uint idx = mesh.inds.d[threadID];
  
  PackedVertex vtx0 = mesh.verts.d[idx * 2];
  
  for (uint i = 0; i < 2; i++) {
  #if 1
    PackedVertex  vtx = i > 0 ? mesh.verts.d[idx] : vtx0;
  #else
    PackedVertex  vtx;
    if (i > 0) {
      vtx = vtx0;
    }
    else {
      vtx = mesh.verts.d[idx];
    }
  #endif
    outVerts.d[threadID] = vtx;
  }
}

pixeljetstream avatar Dec 13 '21 11:12 pixeljetstream

I can reproduce. Looking at it now. Thanks!

jeremy-lunarg avatar Dec 15 '21 20:12 jeremy-lunarg