Skip to content

rtx: move geometry preprocessing to the GPU and reuse prepared data - #387

Merged
jeffamstutz merged 20 commits into
NVIDIA:next_releasefrom
tarcila:gpu-preprocessing
Nov 25, 2026
Merged

jeffamstutz merged 20 commits into
NVIDIA:next_releasefrom
tarcila:gpu-preprocessing

Conversation

@tarcila

@tarcila tarcila commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

VisRTX accepts host-backed and device-backed arrays. Host accessibility is not guaranteed: after required uploads and stream dependencies, the device is the common location where preprocessing can consume either source. Move geometry
preprocessing there without requiring device-backed inputs to return to the host.

committed geometry inputs
  batch input uploads on the preparation stream
  compute derived geometry data on the GPU
  collect summaries through pooled pinned readbacks
  build BVHs and publish render-ready state

geometry-wide attribute updates
  reuse preparation when its inputs are unchanged

Batch small preparation jobs, instance/registry uploads and readbacks; reuse retired input allocations and completed retirement waits. Retain input owners and drain outstanding work on preparation failures.

Evidence

Matched builds on an RTX 5880 Ada, upstream next_release 4ce0fee3 → candidate 2d71888a.

Before → after, milliseconds to completed bounds/BVH readiness. Host-backed,
emissive, 64 geometries × 32 primitives:

Geometry Geometry-wide attribute recommit Input replacement
Triangle 0.743 → 0.063 1.568 → 0.849
Quad 0.804 → 0.051 1.265 → 1.192
Sphere 1.607 → 0.054 2.902 → 0.914
Curve 8.311 → 0.047 8.748 → 8.373
Cone 0.973 → 0.059 2.184 → 0.926
Cylinder 0.971 → 0.058 2.188 → 0.919
SDF 0.676 → 0.049 1.100 → 0.624

Non-emissive input replacement → readiness, host-backed, milliseconds
before → after. Small = 64 geometries × 32 primitives; large = one geometry ×
262,144 primitives:

Geometry Small replacement Large replacement
Sphere 2.727 → 0.901 2.049 → 1.836
Cone 1.908 → 0.911 5.257 → 3.286
Cylinder 1.895 → 0.925 4.891 → 3.035
Triangle 1.276 → 0.819 4.764 → 4.731

These cases demonstrate benefits outside emissive area-CDF preparation, which was the primary driver for this PR (crashing with device-backed geometry). Large triangle replacement is near-neutral.

Trade-offs: medians for unchanged host-backed sphere, curve and quad frames can be up to 10% slower, worst case in the above tests. This is sub-milliseconds processing, mostly negligible, possibly increasing latency up to 65µs.

tarcila and others added 20 commits November 17, 2026 19:20
Keep derived data device-resident and reject failed preparation before
tracing. Preserve curve connectivity.
Use a nonblocking preparation stream with explicit producer dependencies.
Replace device-wide BVH barriers with stream-local completion, and block
publication after failed builds while allowing retry.

Retain render-consumer retirement waits until storage generations can
be tracked independently.
Batch declared host inputs before geometry finalization, preserving source
lifetimes and marking uploads complete only after the batch succeeds.
Remove default-stream dependencies from checked preprocessing kernels.

Cover allocation, copy, completion and partial-batch failures plus retry
and coalesced host-array updates.
Upload OptiX instances and finalized world tables on the preparation
stream, and publish dirty registries as one checked batch before tracing.

Keep stable registry snapshots across host-vector growth and preserve
newer edits or failed batches for retry. Retain render-consumer ordering
and legacy fences for producers not migrated yet.
Submit checked bounds and area readbacks into owned pinned storage, then
collect and validate before BVH builds and geometry-light publication.
Retain queued geometries and drain before storage reuse or retirement.

Cover deferred lifetime, callback reentry, pinned allocation failure,
batch completion errors, and pending shared-array retirement.
Lease result slots from device-local pinned pages instead of allocating
one pinned buffer per geometry. Cache pages for reuse and retain page
ownership independently of the pool until every lease is returned.

Cover page-growth failures, retry, move/reset, concurrent slot use,
asynchronous DMA, and pool-before-lease teardown.
Capture declared input arrays during commits and upload them together
before geometry finalization. Deduplicate shared array versions and
retain sources through checked completion.

Retire obsolete snapshots before allocating multi-geometry cohorts;
preserve single-geometry ordering and observer-only fallback. Cover
batch failure, observer recovery, host retirement, and in-place timing.
Avoid pageable readback staging while retaining completion waits and
failure drains. Reuse completed render retirement at input-batch and
BVH dependency points; retain geometry-level dependency handling.

Cover pinned allocation recovery and retirement certificate validity.
Report refused ANARI calls on a disabled device and route the gated
entry points through a single gate, separate from initDevice().

- report refused API calls and gate the disabled device apart from initDevice()
- reset the refusal-report guard on scope exit
- pass the gated device entry points through one gate
…ernels

Replace Geometry preparation flags with explicit state, let Preprocessing
own its published results through one pinned results buffer, write
bounds and area kernels per geometry type, and simplify allocation-cache
and failure handling.

- handle device allocation failure once, in DeviceBuffer
- make RegisteredObject::upload() virtual
- replace Geometry preparation flags with explicit state
- let Preprocessing own its published results
- collapse pinned readback machinery into one results buffer
- collect input uploads with the shared PreparationQueue
- write the bounds and area kernels per geometry type
- fail preparation directly where the failure is already known
- cover the general path's preparation-results reservation failure
- correct the SmallGeometryJob comment
- ask CUDA whether the render stream is idle
- guard the allocation cache's cohort with nonstd::scope_exit
- keep the allocation cache's blocks in one partitioned array
- cover a failed observer-only geometry input upload
- upload observer-only geometry inputs through the input batch
- drop the unread Preprocessing::Status::Failed
Move the preparation stream, storage, queues, render-stream waits and
failure API into a private GeometryPreparation, run the preparation
lifecycle once in Geometry::finalize(), and report every reason not
to upload (including World and Group build failures) by return value.

- add GeometryPreparation to hold the preparation stream and storage
- move the render-stream waits and upload-and-wait into GeometryPreparation
- move the geometry preparation queues into GeometryPreparation
- give Array::privatize() two waits on GeometryPreparation
- put the preparation failure API on GeometryPreparation
- make the geometry preparation protocol private
- describe the geometry preparation lifecycle in GeometryPreparation.h
- run the preparation lifecycle once, in Geometry::finalize()
- report every reason not to upload through prepare()'s result
- report rejected geometry input without the CUDA failure path
- reserve the bounds buffer once in Preprocessing::bounds()
- report World and Group build failures by return value
- keep the Geometry Light area data in the Geometry base
- narrow the Geometry preparation state to three values
- separate the scene-update stream from GeometryPreparation
- walk the Geometry preparation parameters in one place
- share the Array upload selection and privatization failure
@jeffamstutz

Copy link
Copy Markdown
Collaborator

Rebased this branch onto current next_release (previous head 2d71888a; the original 17 commits only changed in CMakeLists.txt context) and added three refactor commits on top:

  • f6201fd1 refactor(rtx): gate disabled-device API calls in one place
  • a7a9f6d0 refactor(rtx): simplify geometry preprocessing state, readbacks and kernels
  • 4773aff9 refactor(rtx): extract GeometryPreparation and run the lifecycle once

Each commit builds and passes the full RTX ctest suite (96/96). If you have local work on gpu-preprocessing, please git fetch and rebase onto the new head rather than pulling.

@jeffamstutz
jeffamstutz merged commit bb2b925 into NVIDIA:next_release Nov 25, 2026
8 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.

2 participants