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

For GLSL targets, uniform struct fields if unused will optimize out but still appear in function calls #3929

Open
ArielG-NV opened this issue Apr 11, 2024 · 0 comments
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang kind:bug something doesn't work like it should

Comments

@ArielG-NV
Copy link
Collaborator

ArielG-NV commented Apr 11, 2024

For GLSL targets, uniform struct fields if unused will optimize out but still appear in function calls.

repro of issue:

//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain

//TEST_INPUT:ubuffer(data=[0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;

struct DefaultData
{
    static const int2 val = int2(0, 1);
    Texture2D texture;
    SamplerState samplerState1;
    SamplerState samplerState2;
    float2 size;
    float scale;
    float bias;
};

extension DefaultData
{
    int someGet()
    {
        return val.x;
    }
}

int loadDefaultData(inout DefaultData noInit)
{
    outputBuffer[1] = 1;
    return noInit.someGet();
}

[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
    DefaultData noInit;
    outputBuffer[0] = true
        && loadDefaultData(noInit) == 0;
        ;
    // BUF: 1
    // BUF-NEXT: 1
}

compiles into:

###
#version 450
layout(row_major) uniform;
layout(row_major) buffer;

#line 7 0
layout(std430, binding = 0) buffer StructuredBuffer_int_t_0 {
    int _data[];
} outputBuffer_0;

#line 9
struct DefaultData_0
{
    vec2 size_0;
    float scale_0;
    float bias_0;
};


#line 22
int someGet_0(DefaultData_0 this_0, texture2D this_texture_0, sampler this_samplerState1_0, sampler this_samplerState2_0)
{
    return 0;
}


#line 38
int loadDefaultData_0(inout DefaultData_0 noInit_0, texture2D noInit_texture_0, sampler noInit_samplerState1_0, sampler noInit_samplerState2_0)
{

#line 30
    outputBuffer_0._data[1U] = 1;
    return someGet_0(noInit_0, noInit_texture_0, noInit_samplerState1_0, noInit_samplerState2_0);
}


layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main()
{

#line 35
    DefaultData_0 noInit_1;

#line 35
    int _S1 = loadDefaultData_0(noInit_1, noInit_texture_1, noInit_samplerState1_1, noInit_samplerState2_1);


    outputBuffer_0._data[0U] = int(_S1 == 0);

#line 43
    return;
}

Notice as issue specifically: int _S1 = loadDefaultData_0(noInit_1, noInit_texture_1, noInit_samplerState1_1, noInit_samplerState2_1); despite the uniforms noInit_texture_1, noInit_samplerState1_1, and noInit_samplerState2_1 missing

HLSL/SPIR-V both work in this scenario through not optimizing out the variables. Slang->GLSL should not optimize out any struct members

@ArielG-NV ArielG-NV added kind:bug something doesn't work like it should goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang labels Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang kind:bug something doesn't work like it should
Projects
None yet
Development

No branches or pull requests

1 participant