KhronosGroup / KhronosGroup/glslang

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

Open
#2,843 1 comment 0 reactions 1 assignee Claimed by @arcady-lunarg View on GitHub
bug GLSL/ESSL SPIR-V
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

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;
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.