From 64dfdbda7185cdc54523e038d2f52a6530bacd1e Mon Sep 17 00:00:00 2001 From: Mukund Keshava Date: Tue, 18 Feb 2025 17:31:52 +0530 Subject: Add warning for ignored binding attributes on uniforms (#6373) Fixes #4251 When binding attributes (like [[vk::binding]]) are specified on uniforms that get packed into the default constant buffer, these binding attributes are effectively ignored since the uniform will always be placed at descriptor set 0, binding 0. This can be confusing for users who expect their explicit bindings to take effect. This change adds a new warning (71) that informs users when their binding attributes on uniforms will be ignored, and suggests declaring the uniform inside a constant buffer to preserve the explicit binding. The warning helps users understand: 1. Why their binding attribute isn't having the expected effect 2. That the uniform is being packed into the default constant buffer 3. How to fix it by using a constant buffer declaration Added test case in tests/bugs/binding-attribute-ignored.slang to verify the warning behavior. Co-authored-by: Ellie Hermaszewska --- tests/bugs/binding-attribute-ignored.slang | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/bugs/binding-attribute-ignored.slang (limited to 'tests/bugs') diff --git a/tests/bugs/binding-attribute-ignored.slang b/tests/bugs/binding-attribute-ignored.slang new file mode 100644 index 000000000..9025489ec --- /dev/null +++ b/tests/bugs/binding-attribute-ignored.slang @@ -0,0 +1,22 @@ +// binding-attribute-ignored.slang +// Test that binding attributes on uniforms that get packed into the default uniform buffer trigger a warning + +//TEST:SIMPLE(filecheck=CHECK):-target spirv + +//CHECK: ([[# @LINE+2]]): warning 39071 +[[vk::binding(1, 2)]] +uniform float4 g_position; + +//CHECK: ([[# @LINE+2]]): warning 39071 +[[vk::binding(3, 1)]] +uniform float4x4 g_transform; + +// This won't trigger a warning because it's a texture (not packed into default uniform buffer) +[[vk::binding(0, 0)]] +Texture2D g_texture; + +[shader("vertex")] +float4 main(float4 pos : POSITION) : SV_POSITION +{ + return g_position; +} \ No newline at end of file -- cgit v1.2.3