Skip to content

[PR2] Implemented a set of methods for directly populating ray buffers on device with GPRT#196

Open
Waqar-ukaea wants to merge 65 commits intoxdg-org:mainfrom
Waqar-ukaea:PR2-Prepared-Queries
Open

[PR2] Implemented a set of methods for directly populating ray buffers on device with GPRT#196
Waqar-ukaea wants to merge 65 commits intoxdg-org:mainfrom
Waqar-ukaea:PR2-Prepared-Queries

Conversation

@Waqar-ukaea
Copy link
Collaborator

@Waqar-ukaea Waqar-ukaea commented Feb 3, 2026

Summary

This PR adds additional methods for GPU based ray queries. Specifically, an API for filling ray buffers from an external application and launching against those pre-populated rays:

  • Prepared / device-only queries — allows external applications to populate XDG’s device ray buffers via a callback, then launch the RT pipeline without host staging.

To support the prepared workflow, this PR also adds a ray/hit buffer abstraction and the callback plumbing required for external ray population. The required stubs for Embree are in place for compilation but the majority of these functions will only ever work with a GPU capable RT backend.

The expected workflow here is something like:

  • XDG allocates device memory for rays (if not already large enough)
  • XDG passes device pointers to the callback
  • User's callback populates the buffers using their preferred compute kernel/shader
  • User's callback returns (XDG assumes buffers are now populated)

This avoids unnecessary host-device transfers by allowing users to write directly to XDG's device buffers without any host-side transfers. An example of how the ray buffers can be populated via slang shader can be found in :

[shader("compute")]
[numthreads(256, 1, 1)]
void pack_external_rays(uint3 DispatchThreadID: SV_DispatchThreadID,
                        uniform ExternalRayParams extParams)
{
    uint globalThreadID = DispatchThreadID.x;
    uint stride = extParams.total_threads; // Groups * 256

    // Grid-stride loop: each thread handles ray idx, idx+stride, idx+2*stride, ...
    for (uint idx = globalThreadID; idx < extParams.num_rays; idx += stride)
    {
        xdg::dblRay r;
        r.origin = extParams.origins[idx];
        r.direction = extParams.directions[idx];
        r.exclude_primitives = nullptr;
        r.exclude_count = 0;
        r.volume_mesh_id = extParams.volume_mesh_ids[idx]; // Set volume mesh ID per ray
        r.enabled = extParams.enabled;

        extParams.xdgRays[idx] = r; // Write to device ray buffer
    }
}

Another important aspect of this code path is the ability to specify a different volume to trace against per ray.


Public API Changes

GPRTRayTracer (new / overridden)

Point-in-volume

  • point_in_volume_prepared(...) — run PIV using pre-populated device buffers.

Ray fire

  • ray_fire_prepared(...) — run ray fire using pre-populated device buffers.

Buffer / workflow plumbing

  • check_rayhit_buffer_capacity(...) — ensure device buffers can accommodate N rays.
  • populate_rays_external(...) — callback-based external ray population (device-only path).
  • get_device_rayhit_buffers(...) — return opaque device rayhit buffers struct

GPRT backend accessors

  • context() — access the underlying GPRT context. Currently required since GPRT does not implement VK_EXTERNAL_MEMORY as of yet. So to mock an external application, I use "external" compute shaders attached to the same underlying GPRTContext.
  • download_hits(...) — download hits into host-side storage (utility).

RayTracer interface (new virtuals)

Adds virtual entry points for batched and prepared workflows:

  • point_in_volume_prepared(...)
  • ray_fire_prepared(...)
  • check_rayhit_buffer_capacity(...)
  • populate_rays_external(...)

XDG API (new overloads / helpers)

Prepared / device-only workflow

  • ray_fire_prepared(...)
  • point_in_volume_prepared(...)
  • populate_rays_external(...)

Waqar-ukaea and others added 25 commits January 19, 2026 16:25
Added a code path that involves populating GPRT rays via a callback and firing against these pre-populated rays with `xdg::ray_fire_prepared()`
@Waqar-ukaea Waqar-ukaea changed the title Implemented a set of methods for directly populating ray buffers on device with GPRT [PR2] Implemented a set of methods for directly populating ray buffers on device with GPRT Feb 4, 2026
@Waqar-ukaea Waqar-ukaea requested a review from pshriwise February 4, 2026 12:14
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