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

Add ByteAddressBuffer support #248

Conversation

spencer-lunarg
Copy link
Contributor

attempt 2 of #236 (closes #234)

When ByteAddressBuffer are collapsed they start to look like

OpDecorateString %var UserTypeGOOGLE "byteaddressbuffer"
%var = OpVariable %22 StorageBuffer

%a = OpLoad %type %input
%b = OpIAdd %type %a %uint_16
%c = OpShiftRightLogical %type %b uint_2
%_ = OpAccessChain %e %var 0 %c

using the UserType we can detect which variable is used, from here we can build up an offset by working out the math

// offset + 16
%b = OpIAdd %type %a %uint_16
// offset >> 2
%c = OpShiftRightLogical %type %b uint_2
// offset == 4

@spencer-lunarg spencer-lunarg force-pushed the spencer-lunarg-byteAddressBuffer2 branch 2 times, most recently from ca8e5d0 to 30efe84 Compare January 12, 2024 06:10
spirv_reflect.c Outdated Show resolved Hide resolved
@spencer-lunarg spencer-lunarg force-pushed the spencer-lunarg-byteAddressBuffer2 branch from 30efe84 to 7ebf3ad Compare January 19, 2024 07:01
@spencer-lunarg spencer-lunarg force-pushed the spencer-lunarg-byteAddressBuffer2 branch from 7ebf3ad to 0217071 Compare January 19, 2024 07:02
break; // arithmetic starts here
}
arithmetic_node_stack[arithmetic_count++] = p_next_node;
if (arithmetic_count >= 8) {
Copy link
Contributor

@danginsburg danginsburg Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check be above this? Otherwise it will return if you have 8 operations when it could have succeeded (if you have exactly 8). I also don't understand why there is such a low cap on this, it seems rather inflexible. Would it be better to scan for how many first then allocate an array with a cap of like the size of the spir-v or something?

The problem is that SPIR-V reflection will completely fail in this case, not just that you won't get the offsets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so before it failed because I returned an error, not I return the same as "could not find" it it hits the cap

I guess there is no reason for a hard limit, it just I have yet to find a case where it is more then 2 here

Would it be better to scan for how many first

So the other issue is I do need "a cap" when doing this search anyways, there is no "correct" way for HLSL/Slang to flatten the ByteAddressBuffer so in the future, if some strange pattern arises, I still need some arbitrary number to stop at incase I get in some strange situation and don't want to crash

spirv_reflect.c Outdated Show resolved Hide resolved
@danginsburg
Copy link
Contributor

I've tested the latest PR with our full shader corpus and can confirm it's working properly and producing proper ByteAddressBuffer offsets. Looks good to merge to me.

Copy link
Contributor

@chaoticbob chaoticbob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@spencer-lunarg spencer-lunarg merged commit 82ac7e5 into KhronosGroup:main Jan 26, 2024
5 checks passed
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

Successfully merging this pull request may close these issues.

Feature request: reflect referenced members of a ByteAddressBuffer
3 participants