Skip to content

Add support for PhysicalStorageBuffer #237

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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

jwollen
Copy link
Contributor

@jwollen jwollen commented Apr 19, 2025

Summary

This adds support for SPV_KHR_physical_storage_buffer and the PhysicalStorageBuffer64 addressing 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:

struct Node {
    next: PhysicalPtr<T>,
    payload: f32,
}

#[spirv(fragment)]
fn main(
    #[push_constant] root_node: &PhysicalPtr<Node>,
    out: &mut f32,
) {
    unsafe {
        let mut next_node = *root_node;
        while let Some(node) = next_node.as_ref() {
            *out = *out + node.payload;
            next_node = node.next.as_ref();
        }
    }
}

Implementation steps

  • Allow expressing explicit storage classes
  • Enable PhysicalStorageBuffer64 when PhysicalStorageBufferAddresses is supported
  • Support pointer casts
    • Enable u64 as *mut T and vice versa
    • Defer pointer-cast errors until after storage class inferrnce
  • Aligned
    • Generate Aligned operands for all memory operations
    • Add a SPIR-T pass to strip alignment from non-physical operations
    • Allow memory operands in qptr store/load lowering/lifting
  • Add RestrictedPointer if/where necessary
  • Ensure raw pointer ops are correct or disallowed
  • Add spirv_std utilities for working with physical pointers
    • Add a PhysicalPtr<T> type that wraps physical addresses. /bikeshed
    • Parity with *mut

Prior work

  • [Migrated] OpConvertUToPtr support #119: As noted the qptr route is the most flexible and custom constraints for each instruction don't scale. For example supporting OpBitcast would be hard to model with custom constraints.

Open questions

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.

1 participant