Add support for PhysicalStorageBuffer - #237
Conversation
|
Turns out I am porting a shader that needs this too! |
Are physical pointers more performant than using descriptor indexing? Are they similar to 32-bit handles used for bindless in DirectX? Sorry for asking here, but I haven't found documentation on them. |
Will pick it up again soon!
There is no direct equivalent in DX (yet?). Buffer device addresses/physical storage buffer pointers are literally 64-bit pointers to GPU memory. That means, compared to descriptors
They behave a little different and might take different data paths, so the question performance is not trivial. But in general they should be superior. |
|
I'd love if this was implemented, one of the few things that are blocking me from transitioning fully to rust GPU. I'm not really willing to sacrifice the ergonomics of pointers for descriptor indexed buffers |
|
While waiting for this to be resolved by someone who actually knows something I sent my silicon servant to rebase and hack something up based on the PR description here and the other PR. Just switched my lightmap baker to using it and it seems to work for me. Hopefully @jwollen revisits this and solves it properly. If there's anything of use in my branch, feel free to grab. I didn't write any of it, just steered it with what taste I had to offer without knowing the domain. main...dsvensson:rust-gpu:physical_storage The code in the PR description is added pretty much verbatim to an executable example. #[repr(C)]
#[derive(Copy, Clone, Pod, Zeroable)]
pub struct Node {
pub next: PhysicalPtr<Node>,
pub payload: f32,
}
#[spirv(compute(threads(1)))]
pub fn main(
#[spirv(push_constant)] root_node: &PhysicalPtr<Node>,
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] output: &mut f32,
) {
let mut current = *root_node;
*output = 0.0;
unsafe {
while let Some(node) = current.as_ref() {
*output += node.payload;
current = node.next;
}
}
} |
|
Rebased my fork of this PR after f16 and "rm cap checks" by @Firestar99 in main as a new branch: main...dsvensson:rust-gpu:physical_storage_2026_07_22 Been using this feature with great success since May for my above mentioned lightmap baker. Hopefully it gets proper attention from someone who knows what they're doing some day. The updated example now accumulates f16 node payloads to a f16 storage buffer output at a >4GB offset. |
|
Feel free to actually open a PR so we can properly review it, and not have to manually copy in stuff. Some things I've noticed while scrolling through;
You know you can just change the pointer width to 64? Also widening random u32 values to u64 can have significant knock-on effects, like can you lift all possible operations to u64? Also what would that do to Your RestrictedPhysicalPtr docs say: So, this type does absolutely nothing today? |
|
Yep, it's entirely claude mangled of the original PR as I just needed the feature now and never intended to have it upstreamed, instead waiting for the original author to come back. The current state is not mergable, lots of vomit'y slop crap all over the place - potentially breaking stuff I don't use myself. I mentioned this in my earlier comment. I'm ok just having claude rebase it for myself from time to time as it does so effortless and pointing my cargo.toml at a git fork works fine. But as it works so well, and it looked like it had been forgotten in the GH issues, I just wish the feature to be adopted by someone who is invested into the project, such as the original PR author. The ray_query is not gated correctly which makes RustRover cry. As I'm using this branch in my project, it has to contain any fixes needed for my project to behave correctly. A separate fix ofc. As for f16 in the example, the example serves as a rebase-verification for me and I experimented with using that f16 type in my lightmap baker, again, tailored to my usecase. Don't see that example being part of any real PR, and it's not a PR, so it's fine. Not requiring or requesting anything, just hoping with fingers crossed. |
|
All good, at first this sounded like you wanting to actually upstream your branch, so I thought I'd have a quick look only to notice the sloppyness |
Summary
This adds support for
SPV_KHR_physical_storage_bufferand thePhysicalStorageBuffer64addressing model and expands support for physical pointers.Includes
Motivation
Allow taking advantage of physical buffer addresses (
VK_KHR_buffer_device_address) for more flexible bindless storage buffer access.While physical pointers are largely optional with increasing support for bindless storage buffers,
fully descriptor-less storage buffers remain very ergonomic, especially in pure compute and ray-tracing shaders.
This allows, for example:
Implementation steps
PhysicalStorageBuffer64whenPhysicalStorageBufferAddressesis supportedu64 as *mut Tand vice versaAlignedAlignedoperands for all memory operationsqptrstore/loadlowering/liftingRestrictedPointerif/where necessaryspirv_stdutilities for working with physical pointersPhysicalPtr<T>type that wraps physical addresses. /bikeshed*mutPrior work
OpConvertUToPtrsupport #119: As noted theqptrroute is the most flexible and custom constraints for each instruction don't scale. For example supportingOpBitcastwould be hard to model with custom constraints.Open questions