Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow instructions to explicitly specify StorageClasses #236

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
jwollen wants to merge 4 commits into Rust-GPU:main
base: main
Choose a base branch
Loading
from jwollen:explicit-storage-class

Conversation

@jwollen
Copy link
Contributor

@jwollen jwollen commented Apr 19, 2025
edited
Loading

Summary

This adds an optional StorageClass to SpirvType::Pointer to allow instructions to explicitly specify it on their results.

Required for

Motivation

Currently storage classes are only inferred from interface variables. However, there is a number of instructions that have results with implicit storage classes (i.e. that "create provenance" on the fly).
These include

  • OpConvertUToPtr creates a PhysicalStorageBuffer pointer
  • OpBitcast can be used to create a PhysicalStorageBuffer pointer from u64 or uvec2 (if Int64 is not supported)
  • OpImageTexelPointer creates an Image pointer
  • future bindless extensions will need to create Uniform/StorageBuffer pointers

It should be possible to generate these both in the compiler (e.g. u64 as *const T) and through asm! for unknown instructions.

This is a requirement for the PhysicalStorageBuffer addressing model as well as upcoming more modern bindless extensions.

For example we can now write (or generate in inttoptr)

fn convert_u_to_ptr<T>(addr: u64) -> *const T {
 let result: *const T;
 unsafe {
 let dummy: T = core::mem::MaybeUninit::uninit().assume_init(); // :(
 asm!(
 "%ptr_type = OpTypePointer PhysicalStorageBuffer typeof*{dummy}",
 "{result} = OpConvertUToPtr %ptr_type {addr}",
 addr = in(reg) addr,
 dummy = in(reg) &dummy,
 result = out(reg) result,
 );
 }
 result
}

Implementation steps

  • Add an optional storage class to pointer types
  • Remove the Generic requirement in asm!. Generic is still used to indicate automatic inferrence.
  • Storage class inference
    • Initial hackish support
    • This works seemlessly qptr storage class inference.
    • Either generate InferVars for non-Generic storage classes or infer instances based on concrete types
  • Add API for OpImageTexelPointer
  • Add tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@eddyb eddyb Awaiting requested review from eddyb eddyb will be requested when the pull request is marked ready for review eddyb is a code owner

@LegNeato LegNeato Awaiting requested review from LegNeato LegNeato will be requested when the pull request is marked ready for review LegNeato is a code owner

@Firestar99 Firestar99 Awaiting requested review from Firestar99 Firestar99 will be requested when the pull request is marked ready for review Firestar99 is a code owner

@schell schell Awaiting requested review from schell schell will be requested when the pull request is marked ready for review schell is a code owner

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /