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

Combined texture+sampler ignores register spaces #6471

Open
TheSpydog opened this issue Feb 26, 2025 · 3 comments
Open

Combined texture+sampler ignores register spaces #6471

TheSpydog opened this issue Feb 26, 2025 · 3 comments
Assignees
Labels
goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang

Comments

@TheSpydog
Copy link

For a shader that uses a combined texture-sampler with register syntax, like so:

Sampler2D Sampler : register(t0, space2) : register(s0, space2);

struct Input
{
    float2 TexCoord : TEXCOORD0;
    float4 Color : TEXCOORD1;
};

float4 main(Input input) : SV_Target0
{
    return input.Color * Sampler.Sample(input.TexCoord);
}

The register space seems to be ignored when compiling for SPIR-V and WGSL, as seen below:

// HLSL (correct)
Texture2D<float4 > Texture_0 : register(t0, space2);
SamplerState Sampler_0 : register(s0, space2);

// WGSL
@binding(0) @group(0) var Sampler_texture_0 : texture_2d<f32>;
@binding(1) @group(0) var Sampler_sampler_0 : sampler;

// SPIR-V, examined via spirv-cross --hlsl --shader-model 60
Texture2D<float4> Sampler : register(t0, space0);
SamplerState _Sampler_sampler : register(s0, space0);

If the texture and sampler are split, then the generated shaders have the expected set/group values, so I would expect that to work in this scenario too.

@csyonghe
Copy link
Collaborator

register is used specifically for specifying HLSL bindings. While Slang is trying to guess what it means when producing SPIRV, there will be gaps where it does not work as expected.

You can use [vk::binding(0, 1)] to explicitly specify the binding for Vulkan and WGSL. See it here: https://shader-slang.org/slang-playground/?target=SPIRV&code=eJxNjkELgkAQhe_7KwZPa4SodNKjdugkpEQgEVuuuqS7Mq4RRP-9rVVqDjMD7735przfougiZCVkQ4O1755Izvqh4ximMG8xIaPG6aphJ4dJkycBU3WnmA6h4I9EKawggmJ7TLJsn_rxz7CBRHUK_9QgJi9zsRxbVnGkTo2s6bnUjkHPkZ4JSb8sEJ_umnh-OBcMG679mY9cTyitwbOQ1fKxZye14vKia8hvawBMxA

@TheSpydog
Copy link
Author

Thanks for the reply!

register is used specifically for specifying HLSL bindings. While Slang is trying to guess what it means when producing SPIRV, there will be gaps where it does not work as expected.

Just to make sure I understand, does this mean that the gap here for SPIRV is not necessarily by design, and the register syntax for this could be supported in the future?

You can use [vk::binding(0, 1)] to explicitly specify the binding for Vulkan and WGSL.

Makes sense, but then that doesn't work for HLSL. :) It would be ideal if either the register or vk::binding syntax could be used across all of SPIRV/HLSL/WGSL so we don't end up having to use both to get consistent set/space semantics, like so:

[[vk::binding(0, 2)]] Sampler2D Sampler : register(t0, space2) : register(s0, space2);

@csyonghe
Copy link
Collaborator

Yes, this is something we need to fix. I am providing the workaround in case it is helpful to get you unblocked.

@bmillsNV bmillsNV added this to the Q2 2025 (Spring) milestone Feb 27, 2025
@bmillsNV bmillsNV added the goal:quality & productivity Quality issues and issues that impact our productivity coding day to day inside slang label Feb 27, 2025
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
Projects
None yet
Development

No branches or pull requests

4 participants