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

HLSL: binding start offset feature #2340

Open
TheArheus opened this issue Jun 12, 2024 · 4 comments
Open

HLSL: binding start offset feature #2340

TheArheus opened this issue Jun 12, 2024 · 4 comments
Labels
question Further progress depends on answer from issue creator.

Comments

@TheArheus
Copy link

TheArheus commented Jun 12, 2024

Hi, I have small user experience issue, not really bug or anything. I am interested if spirv-cross have a feature so that when it cross compile from spv to hlsl, it would start, for example, CBVs not from 0, but from another user specified value.
For example, right now, I have this cbuffer, generated from spirv:

cbuffer pushConstant
{
    row_major float4x4 _75_ShadowMatrix : packoffset(c0);
};

And I want to know if it spirv-cross could generate the bindings for specific resource type to be started from another value(for example, starting from 1) and not from zero

@TheArheus TheArheus changed the title HLSL: binding start offset HLSL: binding start offset feature Jun 12, 2024
@HansKristian-Work HansKristian-Work added the question Further progress depends on answer from issue creator. label Jun 17, 2024
@HansKristian-Work
Copy link
Contributor

What do you mean here, do you want to offset packoffset() (c0), or register(b#)? Of the latter, you can use the resource binding APIs to achieve that. Random resource shifts is jarring and not supported. You can override the bindings in many different ways.

@TheArheus
Copy link
Author

Yeah, I was about packoffset(c#) starts from some arbitrary value and register(b#, space#) to start from some value and was thinking about this feature or how to do this if already implemed features

@HansKristian-Work
Copy link
Contributor

HansKristian-Work commented Jun 19, 2024

You want to look at CompilerHLSL::add_hlsl_resource_binding. It can override register/space as needed.
packoffset is really something you don't want to mess with. If you really want to do you overwrite the decorations with set_member_decoration(type.self, DecorationOffset, offset) on the type.

@TheArheus
Copy link
Author

TheArheus commented Jun 28, 2024

@HansKristian-Work there is another thing with generating actual hlsl code. It is similar to my initial issue, but different, and I think this should be a bug. For example, I have this piece of glsl shader bindings defines:

layout(set = 0, binding = 8)  uniform sampler2D GBuffer[GBUFFER_COUNT]; // << Based on error, this one is the issue, GBUFFER_COUNT is equal to 5
layout(set = 0, binding = 9)  uniform writeonly image2D ColorTarget;
layout(set = 0, binding = 10) uniform writeonly image2D BrightTarget;
layout(set = 0, binding = 11) uniform sampler2D AmbientOcclusionBuffer;
layout(set = 0, binding = 12) uniform sampler2D ShadowMap[DEPTH_CASCADES_COUNT];

And the issue is that it will translate to something like this:

Texture2D<float4> GBuffer[GBUFFER_COUNT] : register(t8, space0); // <-- The issue will be after this
SamplerState _GBuffer_sampler[GBUFFER_COUNT] : register(s8, space0); // <-- The issue will be after this
RWTexture2D<float4> ColorTarget : register(u9, space0);
RWTexture2D<float4> BrightTarget : register(u10, space0);
Texture2D<float4> AmbientOcclusionBuffer : register(t11, space0);
SamplerState _AmbientOcclusionBuffer_sampler : register(s11, space0);
Texture2D<float4> ShadowMap[DEPTH_CASCADES_COUNT] : register(t12, space0);
SamplerState _ShadowMap_sampler[DEPTH_CASCADES_COUNT] : register(s12, space0);

The issue is that after translating glsl to hlsl, there will be overlapping registers and I wont be able to create a pipeline state. If I have a register, which is actually an array of samplers (like GBuffer in my code), then, the bindings after that should come like this:

Texture2D<float4> GBuffer[GBUFFER_COUNT] : register(t8, space0); // <-- Now there shouldn't be an issue after that
SamplerState _GBuffer_sampler[GBUFFER_COUNT] : register(s8, space0); // <-- Now there shouldn't be an issue after that
RWTexture2D<float4> ColorTarget : register(u13, space0);
RWTexture2D<float4> BrightTarget : register(u14, space0);
Texture2D<float4> AmbientOcclusionBuffer : register(t15, space0);
SamplerState _AmbientOcclusionBuffer_sampler : register(s15, space0);
Texture2D<float4> ShadowMap[DEPTH_CASCADES_COUNT] : register(t16, space0);
SamplerState _ShadowMap_sampler[DEPTH_CASCADES_COUNT] : register(s16, space0);

Or it shpuld just generate Texture2DArray, but then without binding offset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further progress depends on answer from issue creator.
Projects
None yet
Development

No branches or pull requests

2 participants