Skip to content

Shader reflection API issues #4259

@Lumengine

Description

@Lumengine

Hi,

I don't know if it's the right place to ask questions but I will post it here and if it is not appropriate, I can move the discussion elsewhere.
I am using slang reflection API to feed my engine but I have some troubles.

For some UTs, I have this shader in slang:


struct Stuff
{
    int a;
    float b;
};

struct Things
{
    Texture2D t;
    ParameterBlock<Stuff> stuff;
};

ParameterBlock<Stuff> gStuff;
Texture2D gTex;
ConstantBuffer<Things> gThings;
SamplerState s;

RWStructuredBuffer<float> result;

[shader("compute")]
[numthreads(16, 16, 1)]
void main(uint3 threadId: SV_DispatchThreadID)
{
    result[0] = (float)gStuff.a + gStuff.b + gTex.SampleLevel(s, float2(0, 0), 0).x + (float)gThings.stuff.a+ gThings.stuff.b + gThings.t.SampleLevel(s, float2(0, 0), 0).x;
}

This is just for unit testing so don't look at the stuff in main.
That will compil into this : (with latest branch 2024.1.18

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

#line 18 0
layout(std430, binding = 3) buffer StructuredBuffer_float_t_0 {
    float _data[];
} result_0;

#line 4
struct Stuff_std140_0
{
    int a_0;
    float b_0;
};




layout(binding = 0, set = 1)
layout(std140) uniform _S1
{
    int a_0;
    float b_0;
}gStuff_0;

#line 14
layout(binding = 0)
uniform texture2D gTex_0;


#line 16
layout(binding = 2)
uniform sampler s_0;


#line 16
layout(binding = 1)
uniform texture2D gThings_t_0;


#line 16
layout(binding = 0, set = 2)
layout(std140) uniform _S2
{
    int a_0;
    float b_0;
}gThings_stuff_0;
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
void main()
{

#line 24
    const vec2 _S3 = vec2(0.0, 0.0);

#line 24
    result_0._data[0U] = float(gStuff_0.a_0) + gStuff_0.b_0 + (textureLod(sampler2D(gTex_0,s_0), (_S3), (0.0))).x + float(gThings_stuff_0.a_0) + gThings_stuff_0.b_0 + (textureLod(sampler2D(gThings_t_0,s_0), (_S3), (0.0))).x;
    return;
}

What I am trying to achieve is to get the correct binding and set for Vulkan for each variable. This shader is basded on an old comment I found in your repo when you were still using childSet in SimpleBindingOffset.

I am using this to compute the relative binding and set of variable


        /// Create an offset based on offset information in the given Slang `varLayout`
        SimpleBindingOffset(slang::VariableLayoutReflection* varLayout)
        {
            if (varLayout)
            {
                bindingSet = varLayout->getBindingSpace() + (Uint32)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_SUB_ELEMENT_REGISTER_SPACE);
                binding = (Uint32)(varLayout->getOffset(SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT));
                pushConstantRange =
                    (uint32_t)varLayout->getOffset(SLANG_PARAMETER_CATEGORY_PUSH_CONSTANT_BUFFER);
            }
        }

And I am adding recursively the offset with the parent. THe thing is that I get binding = 1 and set = 2 for gThings. But the gThings.t is in set 0 as the GLSL is showing (and binding 1). How am I supposed to get the right result ?

I read the documentation but I still have trouble understanding everything.

You can see part of my code here! I modified it a bit since last time but nothing fancy. #3318

Thanks,

Baptiste

Metadata

Metadata

Assignees

Labels

Needs reporter feedbackBugs awaiting more information from the reporterclient supportFeature or fix needed for a current slang user.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions