Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
21bbb4a
fix(rtx): preprocess geometry on the GPU
tarcila Oct 16, 2026
c00aa31
perf(rtx): reuse preparation for geometry-wide attribute updates
tarcila Oct 20, 2026
49d1a6d
perf(rtx): add local preprocessing comparisons
tarcila Oct 20, 2026
9f9f130
perf(rtx): skip retirement waits for preparation-preserving updates
tarcila Oct 29, 2026
3f6b423
perf(rtx): isolate geometry and BVH preparation
tarcila Oct 29, 2026
d60ca4d
perf(rtx): upload geometry arrays on preparation stream
tarcila Oct 29, 2026
62422dc
perf(rtx): batch instance and registry uploads
tarcila Oct 29, 2026
e5dfc0c
perf(rtx): batch geometry preparation readbacks
tarcila Oct 29, 2026
cf9eb36
perf(rtx): pool pinned geometry readbacks
tarcila Oct 29, 2026
7e8d39f
perf(rtx): batch committed geometry input uploads
tarcila Oct 29, 2026
234236c
perf(rtx): batch small geometry preprocessing
tarcila Nov 3, 2026
d54a6b5
perf(rtx): consolidate small geometry summary readbacks
tarcila Nov 3, 2026
02fb3f2
perf(rtx): reuse completed render-stream retirement waits
tarcila Nov 3, 2026
865f748
perf(rtx): cache retired geometry input allocations
tarcila Nov 4, 2026
ddf212a
fix(rtx): retain preparation owners across collection exceptions
tarcila Nov 4, 2026
a7f64b4
test(rtx): verify weighted geometry CDFs at batch boundaries
tarcila Nov 4, 2026
867e28c
perf(rtx): pool pinned BVH readbacks
tarcila Nov 7, 2026
f6201fd
refactor(rtx): gate disabled-device API calls in one place
jeffamstutz Nov 25, 2026
a7a9f6d
refactor(rtx): simplify geometry preprocessing state, readbacks and k…
jeffamstutz Nov 25, 2026
4773aff
refactor(rtx): extract GeometryPreparation and run the lifecycle once
jeffamstutz Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .agents/skills/benchmark-geometry-preprocessing/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
name: benchmark-geometry-preprocessing
description: Compare local before/after performance for RTX geometry preparation, preprocessing, BVH readiness or preparation-preserving updates. Use when assessing whether a development change improves end-to-end latency.
---

# Local geometry-preprocessing comparison

Produce a terminal before/after comparison and a short assessment of whether the
change helps its intended workload. Results are local development feedback;
historical performance tracking is a separate CI concern. Run affected correctness
tests independently of timing.

Repository paths below are relative to the checkout root. Timing definitions,
custom workload examples and optional profiling commands live in
`devices/rtx/docs/geometry-preprocessing-performance.md`; read it before choosing
workloads or interpreting numbers.

## 1. Identify before and after

Use the user's control revision; ask if unspecified. Keep the candidate intact
and create a separate control workspace using the checkout's VCS (`jj workspace
add` in a jj workspace, otherwise `git worktree add`). Record the control revision
and candidate revision/working-copy state in the local report.

## 2. Build matched libraries

Use identical compiler, CUDA, OptiX, architecture, build configuration, optional
components and library suffix on both sides. Prefer the host's existing build
recipe. A minimal single-configuration starting point, with dependencies already
available, is:

```bash
cmake -S SOURCE -B BUILD -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DVISRTX_BUILD_GL_DEVICE=OFF -DVISRTX_ENABLE_MDL_SUPPORT=OFF \
-DVISRTX_ENABLE_MATERIALX_SUPPORT=OFF -DCMAKE_CUDA_RUNTIME_LIBRARY=Shared
```

Enable `VISRTX_BUILD_TESTS` in the candidate and build
`BenchmarkGeometryPreprocessing`; build `anari_library_visrtx` in the control.
One candidate executable runs against either ABI-compatible library, so the
control need not contain benchmark sources. If their ABIs differ, establish a
compatible harness/build pair before comparing.

Locate the executable and directories containing the built shared libraries.
For multi-configuration builds include the configuration directory. Check both
loader resolutions, substituting each library directory:

```bash
LD_LIBRARY_PATH=LIBRARY_DIR ldd BENCHMARK
```

Proceed only when each resolves the intended device library and a real CUDA
driver, not a toolkit link-time stub. Keep the remaining runtime environment the
same on both sides.

## 3. Compare

Start with the default cases, or a focused case when the user requests one:

```bash
python3 devices/rtx/apps/tests/api/benchmark_preprocessing.py \
BENCHMARK CONTROL_LIBRARY_DIR CANDIDATE_LIBRARY_DIR
```

Use `--help` for workload selection, geometry, device inputs and run budget.
The tool prints warm medians, trial ranges and candidate/control ratios.
A trailing JSON path before the options retains raw results in local scratch;
no output file is required. A nonzero exit or incomplete run is a failed
comparison. Resolve the failure rather than reporting its partial timing.

## 4. Assess and stop

Report the selected workloads, before/after medians, trial ranges and ratios.
Describe what improved, regressed or remains inconclusive, and the geometry/input
and rendering paths actually measured. Overlapping ranges warrant a focused
rerun with more trials if the distinction matters; they neither prove equality
nor establish a statistically significant effect. Avoid universal percentage
thresholds for noise on an uncontrolled host.

For an apparent regression, rerun that case before drawing a conclusion. For a
claimed work-elimination speedup, use the optional trace recipe to check work
counts. Pair synchronization or memory-lifetime changes with relevant failure
and retirement tests; use Compute Sanitizer when those risks warrant it.

Finish with a concise local assessment and any remaining uncertainty. Keep raw
results and captures outside the repository; this workflow does not create
versioned baselines, performance-history tables or CI acceptance thresholds.
7 changes: 7 additions & 0 deletions devices/rtx/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ The `devices/rtx/` subdirectory contains the OptiX-based GPU ray-tracing ANARI d
- [`CONTEXT-MAP.md`](./CONTEXT-MAP.md) — bounded contexts and how they relate; each context has its own `CONTEXT.md` glossary ([Frontend](./device/CONTEXT.md), [Render Pipeline](./device/renderer/CONTEXT.md), [World](./device/world/CONTEXT.md), [MDL](./libmdl/CONTEXT.md)). Use these terms in code and docs.
- [`docs/adr/`](./docs/adr/) — architecture decision records. Scan the directory and read the relevant one before "fixing" a design it locks in.

## Measuring geometry preparation

Use the [`benchmark-geometry-preprocessing`](../../.agents/skills/benchmark-geometry-preprocessing/SKILL.md) skill for local before/after checks of geometry preparation or preparation-reuse performance. Timing contracts: [`docs/geometry-preprocessing-performance.md`](./docs/geometry-preprocessing-performance.md). Keep one-off results in local scratch; historical tracking belongs in a separate CI workflow.

## Build

Built as part of the repository build — see the repo-root [AGENTS.md](../../AGENTS.md). `CMAKE_PREFIX_PATH` must locate the ANARI-SDK and OptiX.
Expand Down Expand Up @@ -53,6 +57,8 @@ Test sources: `apps/tests/api/` (e.g. `ctest -C Release -R TestSpheres`). Run vi
- OptiX device context
- All precompiled PTX modules (one per renderer type, one per material/sampler type)
- `DeviceObjectArray` registries for materials, geometries, samplers, spatial fields
- `preparationStream`, the `PreparationStream` that geometry preparation, BVH builds, registry uploads and world-table uploads submit to
- `preparation`, the one `GeometryPreparation` that owns GPU geometry preparation (its queues, batch, results and input allocation cache); read `device/geometry/GeometryPreparation.h` for the lifecycle

**Frame::renderFrame()** orchestrates each frame:

Expand Down Expand Up @@ -117,6 +123,7 @@ After rebuild, `OptixTraversableHandle`s are stored in `WorldGPUData` and passed
| `device/renderer/Renderer.h` | Base renderer: pipeline init, SBT construction |
| `device/world/World.h/.cpp` | BVH (TLAS/BLAS) management |
| `device/utility/DeviceObjectArray.h` | Thread-safe GPU slot allocator / registry |
| `device/geometry/GeometryPreparation.h` | Owner of GPU geometry preparation: one scene update as one commit/upload/submit/collect transaction |

### Renderer Types

Expand Down
90 changes: 90 additions & 0 deletions devices/rtx/apps/tests/api/BenchmarkCudaOrdering.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2019-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

// Manual semantics probe, not a timing assertion. Uses the same legacy-default
// stream compilation mode as the device. Never change production ordering based
// only on this probe: pageable copies and readbacks impose additional edges.
#include <cuda_runtime.h>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <initializer_list>

static void check(cudaError_t error)
{
if (error != cudaSuccess) {
fprintf(stderr, "%s\n", cudaGetErrorString(error));
std::exit(1);
}
}

__global__ void delay(unsigned long long cycles)
{
const auto start = clock64();
while (clock64() - start < cycles) {
}
}

int main()
{
int clockRate = 0;
check(cudaDeviceGetAttribute(&clockRate, cudaDevAttrClockRate, 0));
// clockRate is kHz: about 30 ms, not a precision timing source.
const auto cycles = 30ull * clockRate;
check(cudaFree(nullptr));
for (unsigned flags :
{unsigned(cudaStreamDefault), unsigned(cudaStreamNonBlocking)}) {
cudaStream_t stream;
cudaEvent_t done;
check(cudaStreamCreateWithFlags(&stream, flags));
check(cudaEventCreateWithFlags(&done, cudaEventDisableTiming));
for (bool producerDefault : {true, false}) {
delay<<<1, 1, 0, producerDefault ? nullptr : stream>>>(cycles);
check(cudaGetLastError());
// Record completion of an otherwise empty consumer stream. With legacy
// NULL-stream ordering this event cannot pass the blocking producer.
check(cudaEventRecord(done, producerDefault ? stream : nullptr));
const auto start = std::chrono::steady_clock::now();
check(cudaEventSynchronize(done));
const double ms = std::chrono::duration<double, std::milli>(
std::chrono::steady_clock::now() - start)
.count();
printf("flags=%s producer=%s consumer=%s consumer_wait_ms=%.3f\n",
flags == cudaStreamDefault ? "blocking" : "nonblocking",
producerDefault ? "default" : "work",
producerDefault ? "work" : "default",
ms);
check(cudaDeviceSynchronize());
}
check(cudaEventDestroy(done));
check(cudaStreamDestroy(stream));
}
}
Loading
Loading