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

Bindings missing from reflection data if passed by parameter #102

Open
aclysma opened this issue Nov 16, 2020 · 2 comments
Open

Bindings missing from reflection data if passed by parameter #102

aclysma opened this issue Nov 16, 2020 · 2 comments
Assignees
Labels

Comments

@aclysma
Copy link

aclysma commented Nov 16, 2020

When I compile this shader and run it through spirv_reflect, I get reflection data as I expect

#version 450

layout (set = 0, binding = 1) uniform sampler smp;
layout (set = 1, binding = 3) uniform texture2D tex;

layout (location = 0) out vec4 out_color;

vec4 normal_map(
    texture2D t,
    sampler s,
    vec2 uv
) {
    // *** NOT using the parameters, just accessing tex/smp directly ***
    return texture(sampler2D(tex, smp), uv);
}

void main() {
    out_color = normal_map(tex, smp, vec2(1.0, 1.0));
}

If I use this code instead, the bindings are not in the reflection data.

#version 450

layout (set = 0, binding = 1) uniform sampler smp;
layout (set = 1, binding = 3) uniform texture2D tex;

layout (location = 0) out vec4 out_color;

vec4 normal_map(
    texture2D t,
    sampler s,
    vec2 uv
) {
    // *** Using parameters t and s instead of "global" tex/smp ***
    return texture(sampler2D(t, s), uv);
}

void main() {
    out_color = normal_map(tex, smp, vec2(1.0, 1.0));
}

I'm going through rust bindings, but this is the code I'm calling:

    let enumerated_entry_points = shader_module.enumerate_entry_points()?;
    for entry_point in enumerated_entry_points {
        for descriptor_set in &entry_point.descriptor_sets {
            for binding in &descriptor_set.bindings {
                println!("binding {} {} {}", binding.name, binding.set, binding.binding);
            }
        }
    }

Is this expected behavior? I expected that these shaders would produce identical reflection data.

@chaoticbob
Copy link
Contributor

You're right, it should produce the same reflection data. My initial guess on what's happening is that there's a case where the parser can't connect the passed arguments with the parameters being referenced. Most likely a pattern it hasn't seen before. I'll have a look.

Thank you for providing the shaders for repro.

@spencer-lunarg
Copy link
Contributor

moving the example from KhronosGroup/glslang#3468 here

#version 450

vec3 IBL(samplerCube env_map, sampler2D dfg_lut) {
  float r = 1;
  float lod = 1;
  vec4 env_map_sample = textureLod(env_map, vec3(r), lod);
  vec2 dfg = texture(dfg_lut, vec2(0, 0)).rg;
  return env_map_sample.xyz + vec3(dfg, 0.0);
}

layout(set = 0, binding = 0) uniform samplerCube u_ibl_view;
layout(set = 0, binding = 1) uniform sampler2D u_dfg_lut_view;
layout(location = 0) out vec4 o_color;

void main() {
  o_color = vec4(IBL(u_ibl_view, u_dfg_lut_view), 1);
}

also is not working as expected

@spencer-lunarg spencer-lunarg self-assigned this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants