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

error when creating a const vector with specialization constants #2025

Closed
DadSchoorse opened this issue Dec 17, 2019 · 5 comments · Fixed by #2662
Closed

error when creating a const vector with specialization constants #2025

DadSchoorse opened this issue Dec 17, 2019 · 5 comments · Fixed by #2662

Comments

@DadSchoorse
Copy link
Contributor

DadSchoorse commented Dec 17, 2019

My shader looks like that:

#version 450

layout(constant_id = 0) const float _3 = 0.1500000059604644775390625;
layout(constant_id = 1) const float _4 = 1.0;
layout(constant_id = 2) const float _5 = 1.0;
layout(constant_id = 3) const float _6 = 1.0;
const vec3 _8 = vec3(_4, _5, _6);

layout(set = 1, binding = 0) uniform sampler2D _11;
layout(set = 1, binding = 1) uniform sampler2D _15;

layout(location = 0) in vec2 _172;
layout(location = 0) out vec3 _176;

vec3 _83(vec4 _85, vec2 _86)
{
    vec3 _92 = texture(_11, _86).xyz;
    vec3 _98 = vec3(0.21265600621700286865234375, 0.715157985687255859375, 0.072186000645160675048828125);
    float _102 = dot(_98, _92);
    float _114 = max(_92.x, max(_92.y, _92.z));
    float _126 = min(_92.x, min(_92.y, _92.z));
    float _130 = _114 - _126;
    vec3 _133 = _8 * vec3(_3);
    _92 = mix(vec3(_102), _92, vec3(1.0) + (_133 * (vec3(1.0) - (sign(_133) * vec3(_130)))));
    return _92;
}

void main()
{
    vec4 _167 = gl_FragCoord;
    vec2 _171 = _172;
    _176 = _83(_167, _171);
}

If I try to compile that to Vulkan spir-v, the following error occurs:

ERROR: vibrance.frag.glsl:7: '=' : global const initializers must be constant ' const highp 3-component vector of float'

This usage should be valid and is even mentioned in the spec:
https://github.com/KhronosGroup/GLSL/blob/6c0a07d45d45c42e6fbe441e5199fe8497d085d7/extensions/khr/GL_KHR_vulkan_glsl.txt#L181
I have tried Version 7.13.3381 and latest master.

@DadSchoorse
Copy link
Contributor Author

DadSchoorse commented Dec 31, 2019

a simpler example:

#version 450

layout(constant_id = 1) const float _4 = 1.0;
const vec4 _8 = vec4(_4, _4,_4,_4);

layout(location = 0) out vec4 fragColor;

void main()
{
    fragColor = _8;
}

Expected output:

; SPIR-V
; Version: 1.0
; Generator: Khronos SPIR-V Tools Assembler; 0
; Bound: 12
; Schema: 0
               OpCapability Shader
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %main "main" %fragColor
               OpExecutionMode %main OriginUpperLeft
               OpSource GLSL 450
               OpName %main "main"
               OpName %fragColor "fragColor"
               OpDecorate %4 SpecId 1
               OpDecorate %fragColor Location 0
       %void = OpTypeVoid
          %6 = OpTypeFunction %void
      %float = OpTypeFloat 32
    %v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
  %fragColor = OpVariable %_ptr_Output_v4float Output
          %4 = OpSpecConstant %float 1
         %10 = OpSpecConstantComposite %v4float %4 %4 %4 %4
       %main = OpFunction %void None %6
         %11 = OpLabel
               OpStore %fragColor %10
               OpReturn
               OpFunctionEnd

That spirv works, it gets validated and changing the spec constant works, too.

@godlikepanos
Copy link
Contributor

I'm also hitting this issue. If _8 is ivec or uvec it compiles just fine but it failes with plain vec types.

@haasn
Copy link
Contributor

haasn commented May 31, 2021

I'm also hitting this bug. Working around it using #define foo vec4(_1, _2, _3, _4) instead of const vec4 foo = vec4(_1, _2, _3, _4);, but it's annoying and I shouldn't have to do this.

Also, I think this is a bug, not missing functionality, and should be reclassified as such.

@greg-lunarg
Copy link
Contributor

glslang has commented code and a commented test which holds to the policy that constant float vectors containing specialization constants are not allowed, although I can find no such policy in the Vulkan, SPIR-V or GLSL specs. The aforementioned test's file name seems to imply that the policy comes from Vulkan.

I will check with the SPIR-V WG to see if they know more about this policy. Once I have a go-ahead from them I should be posting a fix shortly after.

@greg-lunarg
Copy link
Contributor

According to the SPIR-V WG, the construct const vec4 foo = vec4(_1, _2, _3, _4); is legal in SPIR-V, GLSL and Vulkan. It is only generating an error because support has not yet been implemented in glslang.

I will add support shortly.

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

Successfully merging a pull request may close this issue.

5 participants