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

Conflicting interface variables emitted when multiple variables have same set/binding #3472

Open
Rua opened this issue Jan 6, 2024 · 0 comments

Comments

@Rua
Copy link

Rua commented Jan 6, 2024

The following vertex shader declares two different variables with the same descriptor set and binding number, but only one of them is statically used:

#version 450

layout(set = 0, binding = 0) uniform Data {
    vec4 pos;
};
layout(set = 0, binding = 0) uniform texture2D dummy;

void main() {
    gl_Position = pos;
}

Compiling with glslc -S --target-env=vulkan1.3 gives the following result (showing only relevant parts):

OpEntryPoint Vertex %main "main" %_ %__0 %dummy
OpDecorate %__0 DescriptorSet 0
OpDecorate %__0 Binding 0
OpDecorate %dummy DescriptorSet 0
OpDecorate %dummy Binding 0

Both variables are included in the interface of the OpEntryPoint, which according to the Vulkan spec means that they are considered "statically used":

9.24. Static Use

A SPIR-V module declares a global object in memory using the OpVariable instruction, which results in a pointer x to that object. A specific entry point in a SPIR-V module is said to statically use that object if that entry point’s call tree contains a function containing a instruction with x as an id operand. A shader entry point also statically uses any variables explicitly declared in its interface.

But the spec section "15.8.3. DescriptorSet and Binding Assignment" contains a note stating that this is disallowed:

If multiple shader variables with the same set and binding values are declared in a single shader, but with different declared types, where any of those are not supported by the relevant bound descriptor, that shader can only be executed if the variables with the unsupported type are not statically used.

This issue only exists when optimizations are disabled. With the -O option, the unused variable is eliminated and no longer appears in the interface. It doesn't happen with SPIR-V versions below 1.4, because descriptor binding variables are not allowed/included in interfaces in older versions.

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

No branches or pull requests

1 participant