Skip to content

WebGPU RayQuery Support #369

Open
Open

Description

@ahmedtd

I've been working on RayQuery support for the past few days, based entirely on copying the design of the current feature in gfx-rs/wgpu.

To get an interactive demo working required changes across gogpu/gputypes, gogpu/naga, gogpu/wgpu, and gogpu/gogpu. It also only supports the Vulkan backend.

You can see the branches across the various repositories:

Based on these branches I was able to get a minimal interactive demo working (http://github.com/ahmedtd/gogames/blob/master/games/wgputest/cmd/windowtest/main.go)

Are you interested in merging this? If so, I will work on cleaning it up and moving my real-time interactive example into gogpu.

The current state of the branches are heavily vibecoded, but the overall guidance was to explicitly copy the interface and implementation choices from gfx-rs/wgpu.

Activity

  1. kolkov commented on Nov 3, 2026

    @kolkov
    Contributor

    Sorry for the slow answer. Yes, we want this.

    Ray queries have been in the HAL since v0.32 (ADR-062), but the public API never got them. Your branches also show the Vulkan path could never have run: the RT procs weren't loaded, the extensions and features were never enabled, the geometry union had the wrong alignment and vk-gen ignored extnumber. So this is exactly the missing piece, ported from the right reference.

    Part of it is already in:

    • The pass usage-scope tracking from your d9e2c1b shipped in wgpu v0.34.7, credited in the changelog.
    • Both of your naga fixes are in naga v0.21.0 (current v0.21.2): compaction keeps and renumbers the special types, and the SPIR-V ray query helpers match Rust (barycentrics and front face for every hit, no OpRayQueryProceedKHR after traversal has finished). You had both fixed in your branch two weeks before we landed the same ports from Rust, thank you. gfx-rs/wgpu's seven ray query examples are now vendored in naga's tests, so your naga commit can be dropped. If you want a naga piece, acceleration_structure<vertex_return> isn't parsed yet (needed for ray_cube_normals), and a PR for it is welcome.
    • wgpu v0.34.7 refuses a device request the adapter can't satisfy, which your gogpu change relied on.
    • Since your base, @stubbedev's vk-gen fixes landed (extnumber, the missing instance and device commands), so some of your Phase 2 should fall away on a rebase.

    How I'd like it to land:

    1. One PR per repo, in dependency order: gputypes (the acceleration structure BindingResource and the minimum AS limits), then wgpu. wgpu's CI builds without a workspace, so it can only bump to a released gputypes. In wgpu itself, two PRs would review better: Vulkan HAL enablement first, then core, the public API and the examples. gogpu needs no PR from you: feat(config): let an app name the device features it requires gogpu#497 covers requesting features at app creation, and FeatureRayQuery goes through it. gogpu requests the adapter's own limits by default, so a ray query device gets the acceleration structure limits the adapter reports. Your Vulkan enablement fills those in for Vulkan.
    2. One implementation of the build and submit logic. You ported wgpu-core into core/ray_tracing_*.go and left internal/raytracing's BuildContext unused because its semantics differ from wgpu-core. I agree wgpu-core's semantics should win, but the port should replace that code in internal/raytracing instead of living next to it. architecture: move ALL implementation to internal/ (ADR-070) #329 will also move core/ and hal/ under internal/. If you take this on, we'll agree on the order first so you don't have to rebase twice.
    3. Public API: following Rust's Blas, Tlas with instance slots, BuildAccelerationStructures and BindGroupEntry.AccelerationStructure is the right call. Compaction can come in a follow-up. We're reviewing the whole public API before 1.0, and these types will go through that review. The Vulkan HAL enablement doesn't depend on it and can land earlier, as its own PR.
    4. Tests and data: CI has no ray tracing hardware, so the GPU tests are local-only runs, and the headless tests on the software HAL are what CI checks. The models and images taken from wgpu's examples need the upstream license and a provenance note next to them.
    5. Backends: starting with Vulkan only is fine. DX12, Metal and the software backend have HAL code for this, but none of it has run through this path. We'll check those ourselves, and the release notes will only claim the backends we've verified.

    You have a choice here, and either answer is fine:

    • You bring it to PRs, and we help. We review, push fixes to your branches if you allow maintainer edits, run Windows and validation-layer checks, and take the gputypes part through its release.
    • You hand it over. If you'd rather not spend more time on it, say so, and we'll integrate your branches ourselves. Your authorship stays in the commits (Co-authored-by) and you're credited in the changelog.

    Which would you prefer?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions