Skip to content

Conversation

@LegNeato
Copy link
Collaborator

@LegNeato LegNeato commented Jan 9, 2026

Disclosure: I had AI write this and I only superficially understand the code.

Replace OpLoad from Private/Function
storage class variables with their constant initializers. This eliminates pointer-to-pointer patterns like &&123 which would otherwise generate invalid SPIR-V in Logical addressing mode (pointer-to-pointer is only allowed for StorageBuffer/Workgroup, not Private).

The optimization runs after inlining (which may expose such patterns) and before DCE (so the now-unused variables can be removed).

Also extend DCE to treat Private storage class variables as pure, allowing them to be removed when unused.

Newer versions of spirv-val catch this, causing our compiletests to fail.

Disclosure: I had AI write this and I only superficially understand the code.

Replace OpLoad from Private/Function
storage class variables with their constant initializers. This eliminates
pointer-to-pointer patterns like `&&123` which would otherwise generate
invalid SPIR-V in Logical addressing mode (pointer-to-pointer is only
allowed for StorageBuffer/Workgroup, not Private).

The optimization runs after inlining (which may expose such patterns)
and before DCE (so the now-unused variables can be removed).

Also extend DCE to treat Private storage class variables as pure,
allowing them to be removed when unused.

Newer versions of spirv-val catch this, acusing compiletests to fail.
Copy link
Member

@Firestar99 Firestar99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good!

And indeed spirv-tools v2025.5 (pulled from nix unstable) introduces a new validation rule that is failing nested-ref:

error: error:0:0 - In Logical addressing, variables can only allocate a pointer to the StorageBuffer or Workgroup storage classes
         %3 = OpVariable %_ptr_Private__ptr_Private_uint Private %4
   |
   = note: spirv-val failed
   = note: module `$TEST_BUILD_DIR/lang/consts/nested-ref.vulkan1.2`

@LegNeato LegNeato added this pull request to the merge queue Jan 13, 2026
Merged via the queue into Rust-GPU:main with commit beb7391 Jan 13, 2026
13 checks passed
@LegNeato LegNeato deleted the opload branch January 13, 2026 15:52
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.

2 participants