KhronosGroup / SPIRV-Reflect

SPIRV-Reflect is a lightweight library that provides a C/C++ reflection API for SPIR-V shader bytecode in Vulkan applications.
Apache License 2.0
672 stars 147 forks source link

Add ByteAddressBuffer support #248

Closed spencer-lunarg closed 7 months ago

spencer-lunarg commented 7 months ago

attempt 2 of https://github.com/KhronosGroup/SPIRV-Reflect/pull/236 (closes https://github.com/KhronosGroup/SPIRV-Reflect/issues/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
danginsburg commented 7 months ago

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.