Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ API between minor releases.
- Export explicitly placed source models together in one standalone HTML viewer with independent visibility.
- Import BCF 2.1 topics and open their cameras, clipping and matched components in the offline viewer.
- Preview distance measurement points and snap to visible vertices, edge midpoints and edges near the pointer.
- Use each instance's projected size for orbit detail when the measured frame budget has room.

### Fixed

Expand Down
52 changes: 49 additions & 3 deletions docs/viewer-performance-baseline.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ for ($trial = 1; $trial -le 3; $trial++) {
Each `ladder-<label>.json` contains both workloads, with separate `perf-<label>-<model>.json` files for each page.
Use `readyMs` for navigation to first frame submission, `orbit.p95Ms` and `orbitFull.p95Ms` for the p95 interval
between animation frames, and `pickMs` for the median pick at the fitted scale. The adaptive orbit reports
the median share of in-view instances drawn in `orbit.drawnMedian`. `memory.gpuBytes` counts the scene's GPU buffers
the median share of submitted triangles relative to the full spans of cells and chunks in view in `orbit.drawnMedian`.
`memory.gpuBytes` counts the scene's GPU buffers
and slot textures, and `heapMB` samples Chromium's JavaScript heap just after load. Divide byte counts by 1,048,576
for MiB. The harness's `htmlMB` and `heapMB` fields already use MiB.

Expand Down Expand Up @@ -134,5 +135,50 @@ Export Synthetic-1M the same way with `--elements 1000000` to reproduce the mill

The median triangle count for Synthetic-400k hits fell from 4,046,612 to 62,948. On Synthetic-1M, with 96 million
triangles in the model, it fell from 10,339,788 to 159,872. All sample pairs matched.
Schependomlaan draws only merged chunks, so both runs submitted 247,472 triangles. This change applies to picking.
Adaptive orbit continues to use its existing detail cut. [Instancing and picking issue](https://github.com/IOExtend/IOViewer/issues/12)
Schependomlaan draws only merged chunks, so both runs submitted 247,472 triangles. [Instancing and picking issue](https://github.com/IOExtend/IOViewer/issues/12)

## Per-instance orbit detail

Set `PERF_ORBIT_DETAIL_ONLY=1` and run the harness on the current Synthetic-400k, Synthetic-1M and Schependomlaan
exports. The fixed-budget comparison completes 72 identical camera poses per mode using an offscreen render and a
one-pixel readback. Both modes get the same budget of up to 20 million weighted triangles. The adaptive comparison
uses the normal controller and reports animation-frame intervals from the same starting view.

The following results are from the initial experiment with per-instance selection enabled throughout motion
(`f0c1918`).

| Workload | GPU | Fixed frame p95, ms, cell / instance | Fixed median triangles, cell / instance | Adaptive frame p95, ms, cell / instance | Adaptive median drawn share, cell / instance |
| --- | --- | ---: | ---: | ---: | ---: |
| Synthetic-400k | Radeon | 34.7 / 35.2 | 12.36 M / 12.28 M | 33.5 / 50.3 | 25.5% / 32.0% |
| Synthetic-1M | Radeon | 26.1 / 24.1 | 7.60 M / 5.27 M | 50.0 / 50.0 | 8.0% / 5.6% |
| Synthetic-400k | RTX 4080 | 14.0 / 14.2 | 12.36 M / 12.28 M | 16.8 / 33.4 | 100% / 100% |
| Synthetic-1M | RTX 4080 | 9.2 / 10.9 | 7.60 M / 5.27 M | 33.4 / 33.4 | 56.1% / 100% |
| Schependomlaan | Radeon | 2.2 / 1.9 | 247,472 / 247,472 | 16.8 / 16.8 | 100% / 100% |
| Schependomlaan | RTX 4080 | 33.2 / 0.7 | 247,472 / 247,472 | 16.8 / 16.8 | 100% / 100% |

These are single runs per GPU. Both paths submit identical geometry in the merged control, which shows the
variance in the timed frames. On Synthetic-1M, CPU preparation at fixed budget took 4.7 / 8.7 ms p95 on Radeon
and 4.3 / 7.1 ms on RTX 4080. More precise selection trades CPU preparation for fewer submitted triangles.

Instance detail keeps 48 bytes of CPU transform data per instanced slot and allocates reusable CPU/GPU draw buffers
as needed. The Radeon run on Synthetic-1M retained 45.8 MiB of source transforms and allocated 18.8 MiB of compact
draw data on each side. Read `memory.detailSourceBytes` and `memory.detailBytes` for these totals.

### Adaptive frame budget with refinement

Motion starts with cell detail. After 20 consecutive moving frames with detail cut and measured cost below
the controller's existing growth threshold, the next frame may use per-instance detail. A slow frame
returns to cell detail immediately. This keeps the original detail budget and lets the viewer refine selection
when rendering and frame preparation leave enough headroom.

For the 400,000-element check, export the same model with the viewer at `4288013` and with the updated bundle.
Set `PERF_ADAPTIVE_ORBIT_ONLY=1` and pass the two exports to `PERF_MODELS`. Run four trials per GPU with the two
files in alternating order. Each trial times the default adaptive orbit after the first full frame settles.

| GPU | Main p95 median (range), ms | Refined policy p95 median (range), ms | Main median submitted triangles | Refined policy median submitted triangles |
| --- | ---: | ---: | ---: | ---: |
| Radeon | 33.5 (33.4–33.5) | 33.5 (33.5–33.5) | 11.11 M | 12.36 M |
| RTX 4080 | 33.3 (33.2–33.4) | 25.1 (16.8–33.4) | 38.40 M | 38.40 M |

The Radeon trial view stayed on cell detail. On the RTX 4080, two trials used one refined frame each, and
the other two stayed on cell detail. The report's `refinedFrames` field records this choice.
372 changes: 186 additions & 186 deletions src/IOViewer/Viewer/dist/viewer.js

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions src/IOViewer/Viewer/src/engine/culling.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as THREE from 'three';

const matrix = new THREE.Matrix4();
const frustum = new THREE.Frustum();
const BINS = 32; // half-octave bins of the on-screen radius, from 1/16 px up
export const BINS = 32; // half-octave bins of the on-screen radius, from 1/16 px up

// The camera's six frustum planes as [nx, ny, nz, d] x 6 in `out`; a point p is inside a plane when n·p + d >= 0.
export function frustumPlanes(camera, out = new Float64Array(24)) {
Expand All @@ -18,6 +18,12 @@ export function outsideFrustum(p, x, y, z, r) {
return false;
}

// A containing sphere inside all six planes lets its instances skip their own frustum tests.
export function insideFrustum(p, x, y, z, r) {
for (let k = 0; k < 24; k += 4) if (p[k] * x + p[k + 1] * y + p[k + 2] * z + p[k + 3] < r) return false;
return true;
}

/**
* How to get a sphere's depth and on-screen radius for a camera drawn `viewHeight` CSS pixels high, in `out`:
* [eye x, y, z, forward x, y, z, scale, perspective (1|0)]. Depth = (centre - eye)·forward; the radius in pixels is
Expand Down Expand Up @@ -50,8 +56,16 @@ export function detailThreshold(pixels, cost, budget) {
const p = pixels[i];
if (p < 0) continue;
total += cost[i];
bins[31 - Math.clz32(Math.max(1, Math.min(p * p * 256, 0x7fffffff)))] += cost[i]; // octave of (16 p)^2
bins[detailBin(p)] += cost[i];
}
return thresholdFromBins(bins, total, budget);
}

export function detailBin(pixels) {
return 31 - Math.clz32(Math.max(1, Math.min(pixels * pixels * 256, 0x7fffffff))); // octave of (16 p)^2
}

export function thresholdFromBins(bins, total, budget) {
if (total <= budget) return 0;
let sum = 0;
let top = true;
Expand Down
Loading
Loading