Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
castano opened this issue Feb 12, 2024 · 2 comments
Closed

Comments

@castano
Copy link

castano commented Feb 12, 2024

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 KhronosGroup/glslang#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
@cassiebeckley
Copy link
Contributor

The SPIR-V spec does state that OpUConvert for OpSpecConstantOp is missing before version 1.4: https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpSpecConstantOp.

It looks like you can tell glslangValidator to generate SPIR-V 1.4 using the --target-env argument:

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

As mentioned in KhronosGroup/glslang#3506, this likely is a glslangValidator bug, since it is generating invalid code for SPIR-V 1.0.

@cassiebeckley cassiebeckley closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2024
@castano
Copy link
Author

castano commented Feb 13, 2024

Thanks for the clarification. I don't think we can target spir-v versions greater than 1.3 yet, so it would be great to have this fixed in the glslang compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants