Skip to content

feat(core): support building custom geometry BLAS#9290

Merged
Vecvec merged 15 commits intogfx-rs:trunkfrom
dylanblokhuis:trunk
Apr 1, 2026
Merged

feat(core): support building custom geometry BLAS#9290
Vecvec merged 15 commits intogfx-rs:trunkfrom
dylanblokhuis:trunk

Conversation

@dylanblokhuis
Copy link
Copy Markdown
Contributor

@dylanblokhuis dylanblokhuis commented Mar 23, 2026

Connections
#6762 #7701

Description
wgpu-hal supports building AABB BLASes but wgpu-core does not. This PR adds this functionality to wgpu-core. This PR also includes a rewrite for the naga MSL writer to emit "correct" MSL for ray queries. (this part was heavily written by AI as I do not understand the naga internals at this time)

Testing
I added a new example ray_aabb_compute to test the custom geometry on macOS (metal) and Windows (dx12, vulkan). Raytracing tests don't work for macOS at the moment, so cargo xtask text doesn't validate the MSL changes to be working properly. Tests do pass on Windows.

Squash or Rebase?

Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@dylanblokhuis dylanblokhuis marked this pull request as ready for review March 24, 2026 08:26
@inner-daemons
Copy link
Copy Markdown
Collaborator

We appreciate the effort here! I can't speak to the usefulness of the changes myself but I'm sure @Vecvec will have thoughts.

This PR also includes a rewrite for the naga MSL writer to emit "correct" MSL for ray queries. (this part was heavily written by AI as I do not understand the naga internals at this time)

This kind of approach is unlikely to result in a merge unfortunately. We want contributors to know exactly what the code is doing, and be able to explain and defend the choices made. "Oh, AI did it" isn't a valid excuse for poor or unnecessary code.

In particular, I doubt the MSL writer is really that broken. If it was, you would be better off first filing an issue explaining that and then making a separate PR once its been confirmed that major changes are required (or waiting for someone who is better versed handle the issue if they desire).

@Vecvec
Copy link
Copy Markdown
Contributor

Vecvec commented Mar 24, 2026

@inner-daemons, from reading over the previously generated code, the previous method does not support AABB intersections (and probably non-opaque intersections too).

Interestingly, yesterday I was actually re-writing the metal ray tracing backend to use intersection queries to try and isolate #9100 (though my initial draft did not help it at all, so its probably not that). It would probably need some polishing up before opening a PR, but if @dylanblokhuis would prefer it, I can do some more work on it.

@inner-daemons
Copy link
Copy Markdown
Collaborator

@Vecvec Looks like I misinterpreted this, and the MSL writer changes are needed and relevant, so you can ignore those doubts. Thanks for following up so quickly.

@dylanblokhuis
Copy link
Copy Markdown
Contributor Author

@inner-daemons, from reading over the previously generated code, the previous method does not support AABB intersections (and probably non-opaque intersections too).

Interestingly, yesterday I was actually re-writing the metal ray tracing backend to use intersection queries to try and isolate #9100 (though my initial draft did not help it at all, so its probably not that). It would probably need some polishing up before opening a PR, but if @dylanblokhuis would prefer it, I can do some more work on it.

Whatever you prefer! Perhaps the Naga MSL output from the ray_aabb_compute example can help you write the custom intersector part. Since it is actually working currently.

Would be great to have ray queries working on the big three, then all the voxel game dev enthusiasts can use hardware ray tracing in their projects.

@Vecvec
Copy link
Copy Markdown
Contributor

Vecvec commented Mar 25, 2026

@dylanblokhuis I've opened the patch for msl-out in #9304

@Vecvec
Copy link
Copy Markdown
Contributor

Vecvec commented Mar 25, 2026

Also, this will need some tests. You can find the ray tracing ones under tests/tests/wgpu-gpu/ray_tracing.

@dylanblokhuis
Copy link
Copy Markdown
Contributor Author

@Vecvec I added tests

@dylanblokhuis
Copy link
Copy Markdown
Contributor Author

I reverted the naga changes so the PR is only focused on wgpu-core now

@dylanblokhuis dylanblokhuis changed the title feat(core, naga): support building custom geometry BLAS and fix metal rayQuery codegen feat(core): support building custom geometry BLAS Mar 26, 2026
Copy link
Copy Markdown
Contributor

@Vecvec Vecvec left a comment

Choose a reason for hiding this comment

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

Nothing major from a first read-through. Very excited to have this!

@Vecvec Vecvec linked an issue Mar 27, 2026 that may be closed by this pull request
@Vecvec Vecvec self-requested a review March 29, 2026 18:17
Copy link
Copy Markdown
Contributor

@Vecvec Vecvec left a comment

Choose a reason for hiding this comment

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

A few places where stride validation should be changed since stride doesn't affect initial size. Somewhere in build acceleration structures there should be stride validation which is now in create_blas. Otherwise seems good!

@Vecvec
Copy link
Copy Markdown
Contributor

Vecvec commented Mar 30, 2026

I didn't notice this earlier, but the example probably should have a readme in it.

@dylanblokhuis
Copy link
Copy Markdown
Contributor Author

I didn't notice this earlier, but the example probably should have a readme in it.

Added the README and changed up the stride location.

Copy link
Copy Markdown
Contributor

@Vecvec Vecvec left a comment

Choose a reason for hiding this comment

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

I'm afraid I was unclear about where to put the validation. Once this is changed, I think everything should be good to merge.

I'm assuming you don't want to wait on #9304 because you have not rebased on it. If that is so, could you add a second line to aabb compute (either in the readme or on the expected fail) that explains that metal does not support aabb intersections yet so this example may not work on it.

@dylanblokhuis
Copy link
Copy Markdown
Contributor Author

I'm afraid I was unclear about where to put the validation. Once this is changed, I think everything should be good to merge.

I'm assuming you don't want to wait on #9304 because you have not rebased on it. If that is so, could you add a second line to aabb compute (either in the readme or on the expected fail) that explains that metal does not support aabb intersections yet so this example may not work on it.

I added this!

Copy link
Copy Markdown
Contributor

@Vecvec Vecvec left a comment

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: Vecvec <vectorsofvectors@gmail.com>
@Vecvec Vecvec merged commit 438ed2a into gfx-rs:trunk Apr 1, 2026
59 checks passed
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.

Custom geometry for acceleration structures

3 participants