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

Array with size using specialization constant passed as function parameter error #2188

Open
shizhy1986 opened this issue Aug 23, 2023 · 0 comments
Labels
needs triage Needs to be reproduced before it can become a different issue type.

Comments

@shizhy1986
Copy link

shizhy1986 commented Aug 23, 2023

origin glsl:

#version 460
#extension GL_EXT_shader_explicit_arithmetic_types : enable
layout(constant_id = 0) const uint32_t RANK_OUT = 4;
layout(local_size_x = 64) in;
void outputOffsetToIndex(uint[RANK_OUT] shape, uint offset, out uint[RANK_OUT] index) {
    for(uint32_t i = RANK_OUT - 1; i >= 0; i--) {
        index[i] = offset % shape[i];
        offset /= shape[i];
    }
}
void main() {
    uint offset = gl_GlobalInvocationID.x;
    uint[RANK_OUT] shape;
    if (RANK_OUT == 4)
    {
        shape[0] = 1;
        shape[1] = 4;
        shape[2] = 4;
        shape[3] = 1;
    }
    uint[RANK_OUT] index;
    outputOffsetToIndex(shape, offset, index);
}

compile with glslang and used SPIRV-Cross to get decompiled glsl again, get following code:

#version 460
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
layout(constant_id = 0) const uint RANK_OUT = 4u;
const uint _19 = (RANK_OUT - 1u);
const bool _53 = (RANK_OUT == 4u);
void outputOffsetToIndex(uint shape[RANK_OUT], inout uint offset, inout uint index[RANK_OUT])
{
    for (uint i = _19; i >= 0u; i--)
    {
        index[i] = offset % shape[i];
        offset /= shape[i];
    }
}
void main()
{
    uint offset = gl_GlobalInvocationID.x;
    uint shape[RANK_OUT];
    if (_53)
    {
        shape[0] = 1u;
        shape[1] = 4u;
        shape[2] = 4u;
        shape[3] = 1u;
    }
    uint param[RANK_OUT] = shape;
    uint param_1 = offset;
    uint param_2[RANK_OUT];
    outputOffsetToIndex(param, param_1, param_2);
    uint index[RANK_OUT] = param_2;
}

but this code got compile error: 'initializer' : can't use with types containing arrays sized with a specialization constant

@HansKristian-Work HansKristian-Work added the needs triage Needs to be reproduced before it can become a different issue type. label Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Needs to be reproduced before it can become a different issue type.
Projects
None yet
Development

No branches or pull requests

2 participants