Repository navigation
physics: terrain_lab's field step, cheaper and on worker threads, with the same values - #1322
Merged
Merged
Conversation
…ith the same values terrain_lab's physics step cost about 16 ms of CPU a frame in arigl, all of it the water field reading the sea at every cell of every floating body (Jolt's own step: 0.01 ms). Nothing it computes changes: every pinned hash holds. - det::sin / det::cos take the quadrant from an integer remainder below 2^53 (fmod above); det::sincos shares one reduction. The sea's modes and the shore layer's trains use it. The sea's Catmull-Rom stencil wraps its index the same way. - fft_plan::run_2d transforms eight rows or columns abreast, run()'s butterflies operation for operation, and leaves blocks of +0 rows as they are (a +0 row transforms to itself bit for bit). - world_config::field_threads reads the cells on worker threads, each cell into its own slot, summed in the cells' order; the sea's per-time fields run as their tasks. The reads go through the sea held at the step's time (sea_surface::at, fluid_surface::at), without the cache's lock; the source lattice's corners are read under a shared lock. SceneWorld uses up to three workers. - step_report carries fields_ms and engine_ms.
Where terrain_lab's 16 ms of physics went (the sea's per-time fields and the cells' reads; Jolt's own step is 0.01 ms), what was cut without changing a value, and the before / after numbers.
transfix
enabled auto-merge (squash)
November 16, 2026 13:36
transfix
added a commit
that referenced
this pull request
Nov 16, 2026
Conflicts in sea_surface.h / sea_surface.cpp, both sides kept: - the frame stays sea_surface_frame (held by sea_surface::at_time) and gains O13's crossfade weight, gust frame and current frame; - compute() keeps the per-cascade tasks (modes, then each transform) and det::sincos, with O13's h0 crossfade inside each cascade's modes task; - at(), at_time's reads and O13's forcing_at / weight / taps all stay; height_from and velocity_from (the held reads) carry O13's fetch, gust and current terms. Tests for O13's paths through the held reads and the tasks: OceanSea.TheWindsSeaAtATimeReadsTheSameValues (a sea mid-crossfade with two fetch maps, gusts and a current, its tasks run last first, bit-identical to the plain reads), and windy runs in PhysicsOceanSurface.TheFieldThreadsChangeNoValue (0, 1, 3 workers and switching mid-run give one state hash).
…sics-step-cost # Conflicts: # src/cvc/physics/field_step.h
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.
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.
…st: master's arisrvx build
…t: realize's Debug timeout
transfix
added a commit
that referenced
this pull request
Nov 17, 2026
…ry change of step (#1324) * cvcGL: the volume's draw queued without VTK's glFinish on still renders vtkOpenGLGPUVolumeRayCastMapper::GPURender ends every draw with glFinish() so that its CPU timer measures the GPU's work, which only an auto-adjusting (interactive) draw uses. The CPU waited there for the whole frame queued so far: in terrain_lab, 45-48 % of the main thread's samples, about 25 ms of a 45 ms offscreen frame on the Intel Arc iGPU. OverlappingVolumeMapper is a vtkSmartVolumeMapper that swaps glad's glFinish pointer for an empty function for the length of its own Render, unless the draw is timed (the window's desired update rate at or above the interactive rate), the loader has not loaded it, or an enclosing draw swapped it already. VolumeNode and the scene views' twin volumes use it. WebAssembly keeps VTK's behaviour. cvcgl_volume_overlap: no glFinish on still renders and the pointer put back, VTK's kept on interactive ones, one per still draw with a plain vtkSmartVolumeMapper, and byte-identical pixels between the two mappers. * EWave: the step tables kept per step, not remade at every change of step The exact step's coefficients, the symmetric step's multipliers and the real-space factors are n^2 modes of det:: math each. EWave kept one of each, for the last step only. The world clock moves in whole 1/120 s quanta, so a window stepped by the frame's clock step takes only a few steps, but under arigl run's wall clock the step changed nearly every frame and the tables were remade each time: about 10 ms of terrain_lab's 22 ms AriRuntime::frame on the Intel Arc iGPU (12-13 ms now). Each table is now kept for the last six steps it was made for, dropped as before when the depth or the mask changes. Same functions, same inputs, so the same values. cvcgl_ewave 2b: twelve steps of 1/30 s and 1/40 s in turn work out four tables and follow the CPU's exact step; a new depth works the coefficients out again. Docs: the wake window in OCEAN-AND-WEATHER-ROADMAP.md, and the volume's wait and what is left of terrain_lab's frame under RENDER_PERF_ROADMAP.md's Phase 6. * docs: terrain_lab's frame, measured interleaved on a quiet machine (with and without #1322) * Revert "cvcGL: the volume's draw queued without VTK's glFinish on still renders" This reverts commit 8d5858d11d5bf6b84b9c78de79cf7cd79193d17d. The swap of glad's glFinish pointer is process-wide state. The wait is to be removed in VTK itself instead: an opt-in vtkGPUVolumeRayCastMapper::FinishEveryRender (a cvcpkg patch, written for upstream), which libcvc then turns off per mapper. * docs: the volume's GPU wait is fixed in VTK (an opt-in FinishEveryRender), and the step tables' own measurement * ariadne_python: the bridge ops pass self to server_link 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. * cvcGL: cvcgl_ariadne_realize gets its own ctest timeout (1200 s) 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
added a commit
that referenced
this pull request
Nov 17, 2026
…feat/scene-wind #1322 moved each cell's reads into read_cell() (and ahead of the loop, on the field workers, for a free surface's cells). The scene wind's per-cell work moves with it: body_wind holds a body's wind (its reference at the centre of mass and its height profile), made once per body and field as before, and read_cell takes it to clip the cell at the wind's base and to read its velocity. A wind is a flow's and a free surface a fluid's, so the workers' reads never need it. The arithmetic is the branch's, in the same order. world.cpp keeps #1322's timing and the branch's field_time() for the vehicles' pre_step; the tests are both sides'.
transfix
added a commit
that referenced
this pull request
Nov 17, 2026
… into feat/water-drift #1322 moved each cell's reads into read_cell(); the inertial fluid's setup (its free surface, the displaced mass and moment) now sits before that loop, and its displaced mass reads the cell's value from the cell_read (cr.value) as the rest of the loop does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
terrain_lab's physics step cost about 16 ms of CPU a frame in arigl: the largest cost #1321's profiling found. This PR profiles it and cuts it to about 6 ms without changing anything it computes. Every pinned hash is the same:
0xbe86208109133b1aand the swell scene's0xf0085b4212e1a8c0(CrossPlatformGoldenHash);IsTheSameOnEveryPlatformand the source lattice's digests;2501c4f54a7f5cab), with and without worker threads.Where the time went
A headless harness built terrain_lab's world with
SceneWorld::from_sceneand stepped it on the snapshot's fixed 1/30 s a frame. That is four physics steps of 1/120 s, with the three floating crates' 512 cells each.SceneWorld::syncThe water runtimes' own work and the wake's immersion are not in the step. The generated world's colliders cost nothing per step: their bodies are static and asleep.
step_reportnow carriesfields_msandengine_ms, so the split can be read anywhere.What changed (all bit-exact)
det_math.cpp):det::sinanddet::costake the quadrant from an integer remainder below 2⁵³ instead offmod. That is the same value, andfmodis slow. Above 2⁵³,fmodas before.det::sincosshares one reduction. The sea's modes and the shore layer's trains use it.fft_plan::run_2dtransforms eight rows or columns abreast. The butterflies arerun()'s, operation for operation, so the inner loop over the block vectorises. A block of +0 rows is left as it is: every butterfly on +0 gives +0, and the long cascades fill a few rows of 64.world_config::field_threads(new; default 0, changeable byreconfigure) reads the cells on worker threads beside the stepping thread.sea_surface::at,fluid_surface::at), without the frame cache's lock and reference count on every read. The source lattice's corners are read under a shared lock.SceneWorlduses up to three workers. A build without threads (single-threaded wasm) ignores it.water_node.cpp) is untouched.Before / after
field_threads0, the same-arithmetic changes alone) the frame is 7.2 ms.fmodreductions, separatesinandcos, the row-by-row transform) with no workers. It still read through this PR's held sea, so master's own figure is a little higher. It matches the 16 ms first measured.tick_scenefrom 25.8 to 16.9 ms.How it was checked
OceanFft.TheBlockedTransformIsRunsBitForBit:run_2dagainstrun()over the rows and then the columns. It compares bits for n = 1–128, both signs, with rows of +0 and -0 and lone zeros.OceanSea.TheSeaAtATimeReadsTheSameValues:sea_surface::atreads the sea's height and velocity bit for bit over the beach, the swash and the open sea, with and without the source lattice.AlgoDetMath.SinCosIsSinAndCos:sincosgivessin's andcos's bits over 20,000 points from 1e-3 to 1e9, at quadrant edges, at +-0, beyond 2⁵³ and at the non-finite.PhysicsOceanSurface.TheFieldThreadsChangeNoValue: four bodies on the sea at 0, 1 and 3 workers, and switched mid-run byreconfigure. All give the samestate_hash, with and without the lattice.field_threadsoutside 0–64 is refused.PhysicsOceanSurface.CrossPlatformGoldenHash(be86208109133b1a) andPhysicsFluidSurface.CrossPlatformGoldenHash(f0085b4212e1a8c0);OceanSea.IsTheSameOnEveryPlatformand the lattice's;AlgoDetMath.Bits.Not done