Physical Device Pointers #466
Replies: 1 comment 1 reply
-
|
We currently don't support PhysicalStorageBuffer / BufferDeviceAddress (BDA), which is probably the single biggest limitation of rust-gpu. There is an old PR, so feel free to try that one. While there are a lot of people asking for it, it may still take a little longer until we implement it ourselves since there's a few dependent things that need cleaning first. The primary issue is that SPIR-V doesn't have pointers (apart from BDA, but those can only point to "global" buffers), so there's an entire emulation system to make expressions like these work: let a = 42u32;
let b = &a;This is especially important to have in rust since traits like However, the current implementation is quite limited, in that it doesn't support any offsets to the base pointer. So you can't do any of: // reference a field at a non-zero offset
let a = Vec3::ZERO;
let b = &a.y;
// slice a slice, whether it's a buffer or a local array
let buffer: &[u32] = ...;
let offset = buffer[42...];
// pointers from dynamic sources
let ptr = if a {
&buffer
} else {
&constant
}
// tagged unions that don't get "null pointer optimization" (see Option docs)
enum Option<T> {
None,
Some(T)
}
// the T in Some is at a non-zero offset, since the tag goes first
if let Some(t) = my_enum { ... }There is ongoing work called qptr or quasi-ptr to emulate pointers better and be able to do these things, and is the main thing eddyb has been working on for it feels like 2-3 years by now. We have a new impressive internal demos already, but it's still not yet ready to be merged. We could hackily implement BDA right now, we may be better off waiting for qptr to be in and implement it then, when all the pointers work as expected. (I'm so gonna reuse what I wrote here in the new docs) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
My current engine doesn't use descriptors, instead it passes raw device addresses of buffers into a push constant. The struct on the GPU side uses a Ptr wrapper struct, with only one field (ptr: *const T) and some utility methods. However when I tried to implement pointer arithmetic I got an error that you can't offset a pointer to an arbitrary element. I tried to get around this using inline spirv, however the pointer was of type _ptr_Function_T and to load an arbitrary element I need a pointer of type _ptr_PhysicalStorageBuffer_T. Is there an attribute or anything I could do to fix this?
Beta Was this translation helpful? Give feedback.
All reactions