KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.9k stars 815 forks source link

OpUConvert for specialization constant should not generate spirv-opt error. #3506

Open castano opened 4 months ago

castano commented 4 months ago

When I compile the following program:

#version 450
#extension GL_EXT_shader_explicit_arithmetic_types_int16 : require

layout (constant_id = 0) const uint local_size_x = 8;
layout (constant_id = 1) const uint local_size_y = 8;
layout (local_size_x_id = 0, local_size_y_id = 1, local_size_z = 1) in;

void main() {
    u16vec2 tid = u16vec2(gl_LocalInvocationID.xy);
    uint16_t idx = tid.y * uint16_t(gl_WorkGroupSize.x) + tid.x;
}

As follows:

glslangValidator.exe -V100 -e main repro.comp.glsl -o spirv/repro.comp.spv
spirv-opt.exe -O spirv/repro.comp.spv -o spirv/repro.comp.opt.spv

spirv-opt produces the following error:

error: line 38: Prior to SPIR-V 1.4, specialization constant operation UConvert requires Kernel capability or extension SPV_AMD_gpu_shader_int16
  %28 = OpSpecConstantOp %ushort UConvert %27

According to https://github.com/KhronosGroup/glslang/issues/848 the spec has been updated to include OpUConvert in the list of permitted opcodes. Is this a spirv-opt error?

I'm using the most recent builds that are publicly available:

$ glslangValidator.exe --version
Glslang Version: 11:14.0.0
ESSL Version: OpenGL ES GLSL 3.20 glslang Khronos. 14.0.0
GLSL Version: 4.60 glslang Khronos. 14.0.0
SPIR-V Version 0x00010600, Revision 1
GLSL.std.450 Version 100, Revision 1
Khronos Tool ID 8
SPIR-V Generator Version 11
GL_KHR_vulkan_glsl version 100
ARB_GL_gl_spirv version 100

$ spirv-opt.exe --version
SPIRV-Tools v2023.6 v2023.6.rc1-0-gf0cc85ef
castano commented 4 months ago

Sorry, reported to wrong repository.

castano commented 4 months ago

Reposted here: https://github.com/KhronosGroup/SPIRV-Tools/issues/5571

arcady-lunarg commented 4 months ago

This is technically a glslang error I think, SPIR-V 1.0 does indeed have the restriction you mention and so glslang should not be generating this code because you explicitly requested SPIR-V 1.0.