Skip to content

The water's frame cost: profiling, geometric level of detail, packed samplers, and O21 adaptive quality - #1321

Closed
transfix wants to merge 17 commits into
masterfrom
feat/water-lod
Closed

transfix wants to merge 17 commits into
masterfrom
feat/water-lod

Conversation

@transfix

@transfix transfix commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

The water's frame cost (OCEAN-AND-WEATHER-ROADMAP.md §10.10, §10.11, D9): the water node profiled, its geometric level of detail, fewer samplers, and O21's adaptive quality.

This PR carries #1314 (the persistent foam and the A4 shading, O5) and lands it. Since #1313 (WebGL2's 16 texture units, f128352) is on master, cvcgl_ariadne_realize checks that no water draw runs out of 16 units with the browser's low-memory mapper. #1314 alone fails it: its foam atlas is one sampler more than master's water, so 60 out-of-units warnings, the flood that locked up the deployed terrain_lab. This PR packs the cascades into one sampler (uDisp) and the coast with the wind's fetch maps into another (uCoast), which brings the water back under: the same check here gives 0 warnings at 16 units. So #1314 lands through this PR, with its base now master.

Merges in: feat/ocean-foam 7cb0ce1 (#1314, with master f128352 merged in by the coordinator) as 3686724, and earlier abf41d6 (#1314 with master's O13 wind) as e749578, which moved O13's uWindFetch into the coast atlas (OceanWind::glsl(true)) and reads the middle cascade's persistent foam through the current's flow map.

What changed

Profiling. water.profile (0): 1 times the node's work each frame, section by section, into water.stats.<section>_ms; 2 also waits for the GPU after each section. What it found on terrain_lab (1280 x 720 offscreen, the laptop's Intel Arc iGPU):

  • The largest cost is the physics step's CPU, about 16 ms a frame, most of it the water's fluid field sampling the sea for every immersed cell. Adaptive quality may not touch the physics sea, so this is left as a follow-up.
  • On the GPU, with fences: the three cascades took about 5 ms, the wake's window 2.4 ms and the persistent foam 0.9 ms. The water's own CPU work was under 1 ms.
  • Of the draw, the wake's per-pixel reads were the largest piece.

The cascades in one set of passes (src/cvcGL/ocean/OceanCascades.{h,cpp}, OceanButterfly over tiles).

  • The three cascades' textures are atlases and every pass does all of them: 18 passes a frame instead of 105.
  • The output is texel for texel three OceanFFTs' (worst difference 0).
  • setActive(k) drops the short cascade's passes at the low tiers.
  • The persistent foam reads its Jacobians from the displacement atlas.

Geometric level of detail (D9 (b)'s near part, §10.11).

  • The near grid is three rings: 2, 4 and 8 m at the defaults, about 2.9 times fewer vertices. They snap by the coarsest spacing, so nothing swims.
  • The far grid's vertex shader reads nothing.
  • The short cascade fades out by water.lod_waves (150 m) and is not read past it. A cascade with no weight at a point is never read.
  • The wake is read only inside its window. Its slope reads 12 cells, not 20. A vertex outside the window takes no taps.

Samplers (WebGL2's 16 a draw, shared with the low-memory mapper's arrays).

  • The cascades are one sampler (uDisp).
  • The coast is one (uCoast): the shore distance and depth, then the shore layer's two planes. It replaces the shore grid, the two shore-layer planes and the bed's height field.
  • Per stage, before → after:
    • vertex: 8 → 3 (the cascades, the coast, the wake);
    • fragment: 9 → 4, or 11 → 6 with a cloud_sky's shade;
    • the foam pass: 3 → 2.
  • No sampler added. The cloud shade's previous map is still bound outside a crossfade: at 6 there is no need.

O21 adaptive quality (inc/cvc/ariadne/scene_quality.h, ABYSSAL's Quality.tick at 849ff7f4, MIT notice in the header and THIRD_PARTY_NOTICES.md).

  • AdaptiveQuality is the loop. AriRuntime::frame ticks it on the wall time between frames, and only off the fixed clock, so arigl snapshot and the tests stay at tier 0 and reproducible.
  • Keys under the scene's prefix: quality.adaptive (1) and quality.target_fps (30). The loop writes quality.tier (0–4), quality.scale (0.5–1) and quality.frame_ms.
  • It is ABYSSAL's window, median panic, mean bands, scale steps and cooldowns, with three deviations:
    • No render scale: the scale moves the tiers' distances.
    • So the panic is at 2x target, not 4x. At 4x, the 15 fps model took 29 s to a playable frame.
    • Tiers come back after a 5 s calm spell. That spell doubles each time a tier is lost again within 10 s of returning, so a slow start does not cost the session its quality and an edge machine does not swing.
  • The water's tiers (water_quality; the node's water.quality key, -1 by default, pins one). Drawing only: the physics sea reads none of it.
    • 1: the A4 shading and the persistent foam to half their distance; the wake's window 128² (64 m).
    • 2: the shading to a quarter, the short cascade and the far normal to half, no persistent foam. The whitecaps take the bias that covers Monahan's share alone; the calibration finds it with the other two, off the frame.
    • 3: the plain Fresnel sea, no wake, two cascades (the short one neither transformed nor read).
    • 4: the far normal to a quarter.
  • Not stepped:
    • the near grid's density: its vertices are about 3 % of the water's reads after the rings, by count, and 4 m spacing aliases the middle cascade's 7 m waves;
    • the FFT resolution: it needs bilinear reads and a recalibrated foam.

Docs.

  • The roadmap: "As built (O21)" under §10.10; the water's level of detail under §10.11; D9's row. The Status line is untouched.
  • O5's notes: their GPU was the Intel Arc iGPU, not the RTX 4070. cvcGL's offscreen contexts run there (arigl info), and the same slip is in water: persistent foam, the A4 shading, level of detail and packed samplers (O5, O21) #1314's PR text.
  • docs/ARIADNE.md: the new keys and an adaptive-quality paragraph.
  • water_controls.ari: sliders for lod_waves and quality.

How it was checked

  • ariadne_scene_quality_test (new; 11 cases):
    • ABYSSAL's quality-sim cases: machines at 1, 4 and 15 fps reach a playable frame within 12 s on its cost model.
    • On a model where the scale buys a fifth, the hopeless machines reach the last tier in 12 s.
    • A healthy 60 fps is left alone, and a 2 s hitch drops nothing.
    • Windows close at 24 frames or 400 ms, and the start's cooldown holds.
    • A tier comes back after a calm spell, and an edge machine changes tier at most 20 times in 10 minutes.
    • The same frames give the same moves, and the tier table only takes away.
  • cvcgl_ari_switch:
    • On the fixed clock the loop does not run.
    • 150 ms frames drop to tier 2 at half scale within 3.2 s, and quality.frame_ms reads 156 ms.
    • quality.adaptive 0 holds a hand-set tier.
  • cvcgl_ariadne_realize:
    • The cascades are one 768 x 256 atlas, and the coast is one atlas; no per-cascade, shore-grid or bed sampler is bound.
    • water.quality is seeded at -1.
    • Tier 1 at half scale gives the expected uniforms.
    • water.quality 3 gives the simple shading, no short cascade and no persistent foam, and the whitecaps' threshold alone (higher than with persistence).
    • Tier 0 restores every uniform exactly.
  • cvcgl_ocean_fft:
    • OceanCascades against three OceanFFTs: worst difference 0, 14 passes at N = 64.
    • The foam stepped from the atlas matches the per-texture step.
    • With two cascades active, the first two step and the third is untouched.
  • ctest over the ocean, ewave, AdaptiveQuality/WaterQuality, Ariadne loader/components/scene-world, world-water and cvcgl ocean/ewave/ariadne/ari_/lowmem suites: 172 run, 171 passed, 1 skipped (AriadneLoader.ComboOptionsMayBeAReactiveExpression, as on master). The whole tree builds.
  • With water: persistent foam, the A4 shading, level of detail and packed samplers (O5, O21) #1314 and master f128352 merged in (3686724): cvcgl_ariadne_realize (all of it, including the WebGL2 16-unit section: 0 warnings), cvcgl_ocean_fft, cvcgl_ari_switch, cvcgl_ariadne_physics, ariadne_scene_quality_test (11) and ariadne_scene_world_test (36) pass on Windows Release.

Frame cost. Measured in one process: terrain_lab at 1280 x 720 offscreen on the laptop's Intel Arc iGPU (arigl info; the RTX 4070 sits idle), with other agents' builds and snapshots on the machine. Configurations alternated round by round, 16 frames each after 8 dropped. GPU time is from timestamp queries.

lake view (the water fills the frame) GPU: tick + draw frame, paired vs tier 0
tier 0 5.58 + 18.46 = 24.0 ms (41.8 ms median)
tier 1 3.21 + 17.70 = 20.9 ms within noise (+0.7)
tier 2 3.14 + 17.46 = 20.6 ms within noise (-0.6)
tier 3 1.71 + 15.97 = 17.7 ms -4.7 ms
tier 4 1.74 + 15.97 = 17.7 ms -6.1 ms
  • The default view (the whole world from high up, where the water is a small part of the frame): the tick's GPU work drops 3.4 → 1.7 ms at tier 3, and the frame drops 2.5–3.3 ms at tiers 3–4.
  • The cascades' atlas in one process, three runs of 360 paired steps, each fenced: three OceanFFTs 3.8–4.3 ms against OceanCascades 3.6–3.8 ms, a paired saving of 0.1–0.7 ms. On this iGPU the passes cost their pixels more than their count.
  • Before/after across processes (water: persistent foam, the A4 shading, level of detail and packed samplers (O5, O21) #1314's head against this branch, alternated, 3 rounds, tier 0): the numbers moved with the machine's load by more than the change, so no frame-level before/after is claimed. The lake view's GPU draw, round by round, was 15.6 / 18.9 / 40.0 ms before against 18.6 / 17.7 / 31.6 ms after.
  • The largest cost is the physics step's CPU, about 16 ms a frame (the water's fluid field sampling the sea), which no tier may touch. It is a follow-up for the physics.

Texture units. Now in-tree: cvcgl_ariadne_realize's WebGL2 section (#1313's: the water, the swash and the shade with the low-memory mapper at 16 units, a three-point rig's shadow map) passes with 0 out-of-units warnings on this branch (#1314 alone: 60). Also native, with CVCGL_LOWMEM_MAPPER=force CVCGL_TEXTURE_UNITS=16 arigl snapshot of terrain_lab at e749578 with #1313's commit cherry-picked: no "no texture unit left" line; at 10 units the far grid runs out (control).

Earlier, before #1311 and #1313 were on master, on a local branch with #1313's ba9f40b cherry-picked and #1311's uWindFetch stood in:

  • terrain_lab's opening view and the crate lake: 0 "no texture unit left" lines and 0 "Hardware does not support the number of textures defined" lines.
  • At 10 units the far grid runs out: "10 in all, 5 kept for the mapper's vertex data, 7 shader textures". So the water's draws take 12 of 16 units: 7 shader textures (the cascades, the coast, the wake, the foam, the fetch map and the two cloud-shade maps) plus 5 for the mapper's arrays.
  • Before this PR the same draw would have bound 12 shader textures with water: fetch and lee, gusts, the sea lagging the wind, and currents, in both seas (O13) #1311, 17 units with the arrays.

Frames looked at. Offscreen frames of terrain_lab and the crate lake (arigl snapshot, 1280 x 720), looked at by eye:

  • tiers 0–4 forced with --set water.quality=N: tier 1 keeps the rings and the near foam; tier 2 keeps the whitecaps; tier 3 is the plain sea without wakes;
  • the coast atlas's shoreline and shallows against the pre-packing frame;
  • the 16-unit low-memory-mapper runs.

Not checked

  • The browser (WebGL2): not run. The GLSL keeps to ES 3.0 (texelFetch, no float filtering), but no browser has compiled it.
  • The loop in a real interactive session: only the tests' wall-time frames and the modelled machines were run.
  • Linux and macOS: CI only.

…nahan's share (O5)

foam_step is the turbulence update the GPU runs (foam builds while a
texel folds, decays as exp(-t / decay) after; bubbles, crest, spray),
foam_look the windrow carve the shader draws it with. foam_history
evolves the cascades' h0 over a few seconds, integrates the long
cascades' foam texel by texel, and finds two biases: the aging foam's
alone covers 0.6 of Monahan's share, the whitecaps' the rest. A unit
of work is one cascade's Jacobian, so a caller can slice it.
…ter shading

The long and middle cascades' turbulence lies side by side in one
512 x 256 RGBA32F atlas, ping-ponged: one pass a frame, one sampler for
the water. OceanFoamCalibration runs foam_history as a sliced task.
The GLSL it hands the water: the atlas read bilinear, the windrows, and
the shading (GGX with Smith visibility and the sun's disc, footprint
roughness from Cox-Munk's slopes, short ripples for the glitter, light
through crests, the bubbles), ported from ABYSSAL (MIT, 849ff7f4).
GeometryNode can report the uniforms and textures it was given.
…eir level of detail (O5)

Both draw the long waves' foam from OceanFoam's atlas, carved into
windrows, with the whitecaps on top, and shade with OceanFoam's GLSL.
The thresholds are found off the frame. New keys: foam_decay (0: the
whitecaps alone, as before), lod_foam (the foam's detail ends there; the
mean cover beyond and on the far grid) and lod_shade (the O15 water
beyond), on water_controls.ari; coast.water.* in lsystem_coast.
… 105)

The cascades' textures are atlases of tiles side by side and every pass
does all of them: one time pass, 2 log2 n butterfly passes (OceanButterfly
over tiles) and one assemble, texel for texel three OceanFFTs (the test's
worst difference is 0). Each cascade's two work tiles sit together, so
setActive(k) transforms only the first k. OceanFoam steps from the
displacement atlas, and its calibration also finds the whitecaps' bias
for Monahan's share with no persistent foam beside them.
- water.profile times the node's work into water.stats.<section>_ms
  (2 also fences each section on the GPU).
- The cascades come from OceanCascades: one displacement atlas (uDisp).
- The coast is one atlas (uCoast): the shore distance and the still
  water's depth, then the shore layer's two planes. The bed's height
  field is no longer bound.
- The near grid is three rings (2, 4 and 8 m at the defaults). The far
  grid's vertex shader reads nothing. The short cascade fades out by
  water.lod_waves (150 m). The wake is read only inside its window, its
  slope from 12 cells instead of 20.
- Samplers: vertex 8 -> 3, fragment 9 -> 4 (11 -> 6 with a cloud_sky's
  shade).
- cvc::ariadne::AdaptiveQuality ports ABYSSAL's Quality.tick. AriRuntime
  ticks it on the wall time between frames, never on the fixed clock, and
  publishes quality.tier, quality.scale and quality.frame_ms.
  water_quality maps a tier to the water's distances and switches:
  the shading, the persistent foam, the wake's window, the short cascade
  and the far normal. water.quality pins a tier. Drawing only: the
  physics sea is the same at every tier.
The roadmap's "As built (O21)" under §10.10, the water's frame cost and
level of detail under §10.11, and D9's row. O5's frame-cost note names
the GPU it was measured on: the laptop's Intel Arc iGPU, where cvcGL's
contexts run, not the RTX 4070. docs/ARIADNE.md: water.lod_waves,
water.quality and water.profile, and the quality.* keys.
…the calibration

package-windows failed the O5 block three times: the thresholds' sliced task had finished within
the block's first seven frames, so the value read as the guess was already the calibration's
(0.7697) and never changed again. The check now waits on and compares against the guess itself
(0.75), so it passes whether the calibration lands before or during the wait.
The water node keeps both: #1311's lagged sea (keyframes, crossfade, fetch
maps), gusts, cat's paws and current, and the persistent foam, A4 shading
and level of detail. The far grid's cascade weights carry the lee, computed
once a fragment and shared by its normal and the shading's unresolved
slopes; the cat's paws darken the shaded colour as before. The foam's mean
cover, roughness wind and windrow direction follow the sea's wind (its
newest keyframe), as the whitecaps' thresholds already do.
…d; the fetch maps into the coast atlas

Conflicts:
- water_node.cpp: the level of detail's shaders and OceanCascades kept, with O13 in them:
  - the atlas read (wTexel) gets O13's flow map (wDisp(c, w, tile, adv)) for the cascades the
    current carries; wSum and wHt pass uAdvect per cascade;
  - the near grid's vertex weights are depth x edge x owWindW(w, gust); the gust and the current
    are computed for both grids' vertices (the far grid's fragments read through the current);
  - start_ocean takes h0 from the sea's keyframes into OceanCascades; sync_sea uploads per
    cascade through OceanCascades::setH0; the tick keeps adaptive quality's tier with
    follow_sea / sync_sea in place of the wind rebuild; fadeSpec drives the fades, the cover and
    uWindU beside the tier's uniforms.
- ARIADNE.md and water_controls.ari: both sides' keys and wording.

uWindFetch onto the coast atlas: OceanWind::glsl(true) leaves the fetch read to its caller. The
water node packs OceanWind::fetch's texels into uCoast past its planes (upload_atlas; uCoastRows,
uCoastFetch, uWindFetchGrid) and reads them with the same bilinear arithmetic, so the water takes
no sampler for the lee. upload_shore keeps the planes on the CPU; a keyframe's new maps rebuild
the atlas from them. lsystem_coast keeps uWindFetch.

Under a current the middle cascade's persistent foam is read through the same flow map as its
waves (oFoamAt: two reads, weights normalised), so it stays on their folds.

cvcgl_ariadne_realize checks no uWindFetch on either grid and the coast atlas past its planes.
master fails to build arisrvx's python_engine.cpp: #1302 (bridged users)
added room(), bridge_presence(), bridge_absent(), bridge_post() and
listen_chat() calling server_link() with no argument, written against the
process-wide server link that the P0a cleanup replaced with the module's
own state, server_link(PyObject *self). Each of the five now names its
module argument self and passes it, as the other server ops (lent(),
publish(), ...) already do.

Found in #1324's pycvc-linux / cp312 job (run 43956686020),
which builds the PR merged with master.
# Conflicts:
#	src/cvcGL/test/cvcgl_ariadne_realize.cpp
…o feat/water-lod

#1313 made shader textures fit WebGL2's 16 units, and its realize test checks that no draw runs
out with the low-memory mapper at 16. #1314 alone fails that check (its foam atlas is one sampler
more than master's water); this branch's packing (the cascades in uDisp, the coast and the wind's
fetch maps in uCoast) brings the water back under. No conflicts.

cvcgl_ariadne_realize: the WebGL2 section passes (16 texture units, 0 out-of-units warnings).
@transfix
transfix changed the base branch from feat/ocean-foam to master November 17, 2026 00:37
@transfix
transfix enabled auto-merge (squash) November 17, 2026 00:39
The realize suite runs every node type's checks in one process. In a
Linux Debug job (Xvfb, llvmpipe) it took 250.6 s, 50 s under the 300 s a
test without a TIMEOUT gets; on a slower runner (#1309's Debug job, where
PhConvoy and Ewave also ran about 1.3x longer) it timed out on all three
attempts. As cvcgl_ewave, cvcgl_wake and cvcgl_volren_node have, it gets
a budget of its own with headroom, so only a real hang fails it.
@transfix

Copy link
Copy Markdown
Owner Author

Folded into #1314: feat/ocean-foam was fast-forwarded to this branch's head (0b3c5e2), so #1314 now carries this PR's packed samplers, level of detail, profiling and adaptive quality, and passes #1313's 16-unit check on its own. #1314's description includes this one's.

@transfix transfix closed this Nov 17, 2026
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