Repository navigation
cvcGL: frame-cost fixes (idle camera, caster-aware bakes, partial texture uploads, metadata mirror, bounds walk) + reship cvc.15 - #521
Merged
Conversation
GraphicsNode::setMetadata mirrors each key into "<node>.metadata.<key>" and marks it read-only, so a state browser shows it but a dashboard or script cannot edit it (the node never reads the mirror back; VolRover3's state tree shows such keys as locked). The lock also stopped the node itself: every write after the first threw read_only_error, which was swallowed. The mirror kept the first value forever, and each setGeometry paid for ~17 exceptions -- about 40% of a wall re-mesh spike in the demo3 wasm profile (JS-emulated EH). - An unchanged value returns before touching state (updateMetadata re-sends every key on each setGeometry; a mesh rebuilt in place keeps most of them). - The owner lifts the lock for its own write and restores it, the idiom VolRover3's AppState uses for world_bounds. Others still get read_only_error. - One state path lookup per write instead of two. - long / long long / unsigned / float are mirrored too: a Python int reaches setMetadata as a long and was never mirrored. - A metadata change (this node's or a descendant's) no longer marshals a handler or requests a redraw; it changes nothing drawn. Test: cvcgl_metadata_mirror (headless); pycvc_gl coverage in test_pycvc_gl.py.
update() called applyToCamera() every frame. Re-setting an unchanged pose is a no-op for vtkCamera, but the ResetCameraClippingRange() that comes with it re-derives every visible prop's bounds (a mapper Update and a cell-bounds pass per rewritten mesh): 1-1.5 ms a frame in the demo3 wasm profile with the camera standing still. The throttled pose mirror added 14 state writes, each a path lookup (~2 ms there at frame rates under its 15 Hz). update() now re-applies only when something applyToCamera() derives from has moved: the pose (eye, focal, up, mode, field of view), the camera itself (an outside change is overridden, as before), the renderer's prop list (a prop added or removed), or the new SceneGraph::contentVersion(). That counter moves when the scene's extent may have: - a graphics node registered or removed, a registered node moved, the world box grown; - a mesh or volume replaced (setGeometry / setVolume); - a node shown or hidden (SceneNode::setVisible) or an LOD rung switched -- these change a prop's VTK visibility, which the prop list does not show; - a streaming node's reserved box grown, re-laid out or re-derived (StreamingGeometryNode::applyPending / setDerivedBoundsNow), which is what VTK clips a RibbonNode or DrapedLinkNode by and changes no MTime. markContentChanged() bumps it for changes the scene cannot see (vertices pushed far out in place, a host's own prop toggled with SetVisibility, an unregistered node moved). A controller without a scene keeps the old every-frame behaviour. The pose mirror skips writes while the pose equals the one last mirrored. ABI break: SceneGraph grows a member (sizeof changes) with the SOVERSION unchanged -- rebuild everything that links cvcGL. Test: cvcgl_camera_idle (headless: idle frames, adds/moves/re-meshes/shows, a RibbonNode driving away from a still camera, an LOD node shown/hidden/ switched; plus a rendered section with shadows on that pins the camera's MTime as stable across frames); pycvc_gl coverage.
texture_modified() marks the vtkTexture and the actor modified. The next frame re-uploads the whole texture (vtkOpenGLTexture::Load), and since vtkActor::GetMTime() includes the texture's, vtkShadowMapBakerPass re-renders the scene into its shadow maps. demo3's 1024^2 fog layer repaints ~1% of its texels per update and paid a 4 MiB upload plus a bake each time. GeometryNode::texture_modified_rows(row0, row1) and texture_modified_rect(x0, y0, x1, y1) copy just that part of the aliased RGBA8 buffer into the live vtkTextureObject with glTexSubImage2D (GL_UNPACK_ROW_LENGTH for a rectangle; GLES3/WebGL2 and desktop GL alike) and mark nothing modified. Owner thread, marshalled from others; the range is clamped. Before the texture's first draw there is nothing to patch (that draw uploads every pixel); a copy-path texture falls back to texture_modified(). Test: cvcgl_texture_rows (desktop GL, reads the texture back): only the named rows/rectangle reach the GPU, MTimes stay put, no re-bake follows, and texture_modified() still re-uploads everything. pycvc_gl coverage.
vtkShadowMapBakerPass re-bakes whenever ANY view prop's MTime moved, hidden or not, casting or not. In the demo3 wasm profile every due frame re-baked (30-37 ms each), triggered by vehicle poses, the fog texture and overlay restyles -- none of which change a building's shadow. - GraphicsNode::setCastsShadow(bool) (default true: every node casts, as before) marks a node, its descendants and those added later; the flag lives on the vtkProp (an information key in its PropertyKeys), and setPropCastsShadow / propCastsShadow do the same for a host's raw prop. Any thread: applied on the owner thread, where addGraphicsChild reads the flag. - The scene's baker decides a due frame from what the maps depend on: a light (as VTK checks them) or a CASTING prop that changed since the last bake, joined or left. For a caster that means its own MTime and, since vtkActor::GetMTime() leaves them out, its mapper's and the mapper input's -- so a caster deformed in place (updateVertices / updateNormals / updateColors) still re-bakes. A non-caster is ignored. When it decides to bake it makes VTK bake (a prop that only started or stopped casting has not itself changed). - The bake draws casters only: a filter pass wraps the baker's opaque sequence, so a non-caster is left out of the maps rather than frozen into them at its last-baked pose. - Streaming nodes (#512): RibbonNode and DrapedLinkNode are flat overlays and no longer cast by default. A casting StreamingGeometryNode marks its actor modified when an apply changes what it draws (streamed writes bump no MTime by design), so its shadow follows at the bake interval instead of freezing. ABI break: GraphicsNode gains a member (layout changes) with the SOVERSION unchanged -- rebuild everything that links cvcGL. Test: cvcgl_shadow_casters: moving or restyling a non-caster never bakes; moving a caster, restyling one, deforming one in place, a node starting/ stopping casting and a light change do; a non-casting slab throws no shadow (same pixels as no slab); RibbonNode appends do not bake, a casting streaming node's write does; the update interval still strides a moving caster's bakes. cvcgl_streaming_overlays' one-upload-for-two-passes check now opts its overlays into casting (they would otherwise not be drawn by the bake). pycvc_gl coverage.
SceneGraph::computeGraphicsBounds, run after registered nodes move, did per root child a dynamic_pointer_cast<LightNode>, a dynamic_cast<NullGraphicNode> inside getCombinedBoundingBox, and a vtkMatrix4x4 New + DeepCopy (getWorldTransform) to push 8 corners through. In node-wasm about half of a walk was those copies and casts. - Lights and include-own-bounds groups are plain flags on GraphicsNode (contributesToSceneBounds(), set by LightNode; NullGraphicNode keeps its include-own-bounds setting there), not casts per node per walk. - Each child goes through its cached world matrix (getCombinedWorldBoundingBox): the same 8-corner re-fit, bit-identical for affine transforms, without the allocation. - The grow-only walk after moves only sizes the grid, the axis and the graphics root's own box (shown by default), so it is skipped while all three are hidden. It runs once when any is shown again: at once from setGridVisible / setAxisVisible, and otherwise at the end of the next processEvents() -- the grid/axis node's own setVisible or "visible" state key, setBBoxesVisible, the root's setShowBBox. While deferred the root's bounds and its "<prefix>.graphics.root.bounds" state key do not grow over moves; computeGraphicsBounds() stays the live answer. Adds and removes still refresh at once. ABI break: GraphicsNode gains members and NullGraphicNode loses one (layouts change), SceneGraph grows, with the SOVERSION unchanged -- rebuild everything that links cvcGL. Test: cvcgl_bounds_walk: bit-identical bounds against the old walk (replicated) over 40 random hierarchies with rotations, scales, nesting, groups and lights; no walk under hidden chrome, a catch-up however the box is shown again (SceneGraph setters, the grid node itself, the root's setShowBBox), the root box and its state key following moves while it alone is shown; one walk per pump with the grid shown. Native: 36 -> 21 us per walk over 110 nodes. pycvc_gl coverage.
Ships everything merged since 3.4.0+cvc.14 to every platform: the stream/ image zero-copy family (#516, #517), cvcGL's L3 streaming overlay geometry (#512) and StreamTextureBinding (#518), the pycvc stream bindings (#519), and the cvcGL frame-cost fixes on this branch (metadata mirror, idle-camera skip, texture_modified_rows, caster-aware shadow baking, cheaper bounds walk). ABI: SceneGraph, GraphicsNode and NullGraphicNode layouts changed with the SOVERSION unchanged, so dependents must rebuild against +cvc.15; cvcgl bumps in lockstep and re-pins it.
applyPending bumped SceneGraph::contentVersion() whenever a box was staged, and setReservedBounds / commitDerivedBounds stage whatever they are given. So DrapedLinkNode::setStyle -- documented as a per-frame call (signal quality, jamming) and re-deriving the same box for a colour-only restyle -- or a host re-pinning the same box every frame made a still CameraController run ResetCameraClippingRange every frame (60/60 frames, ~1.5 ms each in the review probe), the cost the idle-camera skip removed. The node now keeps the box it last handed to the mapper. An apply (or setDerivedBoundsNow) of that same box changes nothing: no mapper call, no bbox-node refresh, no content-version bump. Test: cvcgl_camera_idle section F: 20 frames recolouring and moving a draped link give no re-fit, a wider style (bigger box) gives one; a new pinned box re-fits once and re-pinning it every frame does not.
vtkRenderer::ComputeVisiblePropBounds skips a prop with UseBounds or Visibility off, so a box change on such a streaming node cannot change the clipping range -- yet it bumped SceneGraph::contentVersion() and made a still CameraController re-fit anyway. Hosts turn UseBounds off on exactly the overlays that grow every tick (demo3's dynamic tracks), so a RibbonNode track would have paid ~1 ms of ResetCameraClippingRange per frame for nothing. The streaming node now bumps only when its actor takes part in the fit. A host that turns UseBounds back on calls SceneGraph::markContentChanged() (now documented, there and on the node). Test: cvcgl_camera_idle section F: a UseBounds-off ribbon growing away from a still camera re-fits nothing; turned back on with markContentChanged(), once.
A DrapedLinkNode is placed by uniforms -- setEndpoints, setStyle's half width and lift -- and by its height field, none of which bumps an MTime. Once opted into casting, its shadow therefore froze at the first bake: the caster-aware baker (rightly) no longer re-bakes for moving non-casters, which used to refresh it along the way. StreamingGeometryNode gains markShapeChanged() / stageShapeChanged(): "what I draw changed without a point write". The apply treats it like a new draw range -- an actor Modified() when the node casts, nothing uploaded. A casting DrapedLinkNode marks it on setEndpoints, on a setStyle or refreshReservedBounds that changes width, lift or sees new heights, and on new heights found as VTK asks for its bounds (an actor Modified() right there, on the render thread). A non-casting link (the default) stages nothing, so moving one per frame costs what it did. Test: cvcgl_shadow_casters section F: a casting link's setEndpoints bakes once and uploads nothing; a colour-only restyle does not bake, a new width and new heights do; a non-casting link's move does not. Also pins the two other no-write triggers of a casting streaming node -- a draw range alone and a relayout alone each bake once, neither does on a non-caster.
…anges casterGeometryChanged called vtkAlgorithm::GetInputDataObject for every visible caster on every due frame -- an executive lookup (port checks and two information-key reads), several times the cost of the rest of the check (~0.45 us of the ~0.6 us per caster in the review probe; 2 ms a due frame at 2000 casters). The baker now caches, per mapper, the input it found and the mapper MTime it found it at, and looks the input up again only when that MTime moves -- SetInputData / SetInputConnection mark the mapper modified -- or the input it named is gone (a weak pointer). A due frame reads the mapper's and the input's MTime, as before. The cache is dropped when it grows well past the casters drawn. Test: cvcgl_shadow_casters section F: a caster re-wired to a new input object bakes; the new input deformed in place bakes; the old, replaced input changing does not. The existing deform-in-place cases are unchanged.
Review of the round-2 visibility hooks found that no test failed without SceneNode::setVisible's content-version bump: every attached cvcGL node also adds or removes a prop (GridNode and AxisNode included), which the camera sees on its own. The bump is for nodes that show and hide in place with SetVisibility. One such path was still blind: a single grid plane toggled through its "<plane>_plane.visible" state key (GridNode::setXYPlaneVisible and friends) only calls SetVisibility, so a still camera never re-fitted to it. GridNode now bumps SceneGraph::contentVersion() there. Test: cvcgl_camera_idle section G (chrome shown and attached): the grid and axis hidden/shown through their own nodes (getGridNode()/getAxisNode(), as pycvc_gl does), one grid plane hidden/shown, and a test node that toggles its actor in place -- one re-fit each, idle in between, and the in-place node inside [near, far] once shown. Mutation-checked: without GridNode's bump the plane cases fail, without SceneNode::setVisible's the in-place cases fail; the grid/axis node cases pass either way (their prop list changes), so they pin behaviour, not that hook.
transfix
added a commit
that referenced
this pull request
Oct 2, 2026
…ext) Every cvcGL test that renders through a GL context now takes the CTest resource lock cvcgl_gl_context, so ctest never runs two of them at once; the 23 headless tests (listed by name) keep running in parallel. The lock is assigned by exclusion -- every test in the directory minus the headless list -- so a GL test added later is locked unless someone lists it as headless. Why: on the macOS runners every failed attempt of cvcgl_shadow_casters (4 of the 12 attempts across the 8 package-macos jobs of #521-#523) ran alongside cvcgl_shadow_caster_growth and other GL tests under ctest --parallel; no passing attempt overlapped growth, and each retry passed. That is a correlation, not a reproduction -- no Mac reproduced the flake. On every platform, on purpose: the cost is wall time only. On macOS Debug the GL tests' own times summed to ~370 s (cvcgl_volren_node 230 s of it) where they overlapped into ~250 s, so that ctest step can grow by up to ~2 minutes of ~9.
transfix
added a commit
that referenced
this pull request
Oct 2, 2026
…ext) Every cvcGL test that renders through a GL context now takes the CTest resource lock cvcgl_gl_context, so ctest never runs two of them at once; the 23 headless tests (listed by name) keep running in parallel. The lock is assigned by exclusion -- every test in the directory minus the headless list -- so a GL test added later is locked unless someone lists it as headless. Why: on the macOS runners every failed attempt of cvcgl_shadow_casters (4 of the 12 attempts across the 8 package-macos jobs of #521-#523) ran alongside cvcgl_shadow_caster_growth and other GL tests under ctest --parallel; no passing attempt overlapped growth, and each retry passed. That is a correlation, not a reproduction -- no Mac reproduced the flake. On every platform, on purpose: the cost is wall time only. On macOS Debug the GL tests' own times summed to ~370 s (cvcgl_volren_node 230 s of it) where they overlapped into ~250 s, so that ctest step can grow by up to ~2 minutes of ~9.
transfix
added a commit
that referenced
this pull request
Oct 8, 2026
…584) getPose() had no Map branch, so applyToCamera() -- which update() runs whenever the pose, the camera or the scene moved, and every frame without a scene -- pushed the ORBIT pose onto the map camera. frameMap(100, 200, ...) put the eye at (100, 200, 1000); one update() later it sat at the default orbit eye, (4.33, -7.5, 5.0), still in parallel projection. Pans and zooms wrote the vtkCamera directly and were undone the same way, so the 2-D map in the nav demos (navdemo::set_ortho_topdown, demo3's 2-D toggle) never held. Map now has its own pose, like orbit and fly: map.center.{x,y} and map.scale (the parallel scale), in the state tree and the pose mirror. getPose() returns it (eye straight above the centre, north up), applyToCamera() applies it with the parallel projection and scale, and frameMap(), drag-pan, wheel/pinch zoom and the resize re-fit all move that pose rather than the camera, so update()'s pose/version change detection from #521 covers Map unchanged (plus the scale). Mode switches keep each mode's pose: setMode() no longer seeds Orbit/Fly from a straight-down map camera, so Orbit -> Map -> Orbit returns to the same orbit and Map -> Orbit -> Map to the same map; leaving Map turns the parallel projection Map turned on back off (what demo3's setMode(Orbit) "ensure perspective" assumed); Track entered from Map eases in from the orbit view. Also fixed on the way: * readAllFromState() read mode 3 back as Orbit, so any outside state write while in Map -- a Camera-menu slider -- dropped out of the map; * the Map drag panned the view WITH the pointer vertically (only x was negated; VTK display y grows upward), so the grabbed point did not stay under it as documented; * frameBounds() in Map re-applied the orbit pose; it now also seeds the map pose with the box's x/y footprint. Tests: cvcgl_camera_map (new) pins frameMap + update(), pan/zoom, the Orbit/Fly/Track <-> Map switches, the state round-trip, the Map idle path with a scene, and the resize re-fit (skipped when the renderer reports no size). test_pycvc_gl_camera gains a headless Map section.
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.
cvcGL main-thread costs measured in a downstream wasm app (Firefox) and verified against the code. One commit per item, each with its own test; the last commit reships libcvc + cvcgl at cvc_revision 15.
GraphicsNodemetadata mirrorread_only_errorthrows per geometry re-mesh (a large share of a re-mesh's cost on wasm, where exceptions are JS-emulated) and the mirror no longer goes stale.CameraController::updateSceneGraph::contentVersion()changed. The version bumps on register/remove, registered moves, world-box growth,setGeometry/setVolume,SceneNode::setVisible, LOD rung visibility changes and streaming nodes' reserved-bounds/layout changes;markContentChanged()for anything else. A controller without a scene keeps the old every-frame behaviour.vtkProp::SetVisibility, is not watched.GeometryNode::texture_modified_rows/_rectglTexSubImage2Dof the edited part of a zero-copy texture into the existing texture object (GL_UNPACK_ROW_LENGTH for rects), no texture/actor MTime bump, marshalled to the owner thread; desktop GL + GLES3/WebGL2.GraphicsNode::setCastsShadow(bool)(default true; inherited by descendants; any thread, applied on the owner) +setPropCastsShadow. On a due frame the baker re-bakes only if a light or a caster changed (incl. a caster's mapper/input data — in-place deformation), joined or left; a filter pass draws only casters into the maps.RibbonNode/DrapedLinkNode(#512) default to non-casters; a castingStreamingGeometryNoderequests a bake on writes.dynamic_casts per node, the cached world matrix instead ofvtkMatrix4x4New+DeepCopy, and the grow-only walk deferred only while the grid, axis AND root bounding box are all hidden (caught up at the next pump however one is shown).cvc_revision14 → 15ABI:
SceneGraph,GraphicsNodeandNullGraphicNodelayouts change with the SOVERSION unchanged — dependents must rebuild (noted in the commits; the cvc.15 reship covers the published packages).Tests: new
cvcgl_metadata_mirror,cvcgl_camera_idle(incl. a RibbonNode growing away from a still camera and LOD show/hide/rung switches),cvcgl_texture_rows(GPU read-back: only the named rows/rect change),cvcgl_shadow_casters(bake counts for casters vs non-casters, in-place deformation, streaming nodes; pixel checks),cvcgl_bounds_walk(bit-identical vs the old walk over 40 random hierarchies; deferral + catch-up incl. the root bbox and its state key);cvcgl_streaming_overlaysopts its overlays into casting to keep its bake-pass upload check. All 55cvcgl_*,pycvc_gl*,pycvc_proxy_hookspass locally;em++ -fsyntax-onlyclean for every changed source against the wasm-mt deps.Review: an adversarial three-lens review (semantics, GL/threading, portability + merge with #512) of the first round found 8 issues (streaming/LOD changes invisible to the idle camera, in-place caster deformation not re-baking, streaming overlays' frozen shadows, catch-up only from two setters, the root bbox not following, an unmarshalled
setCastsShadow, the undocumented ABI break); all are fixed and folded into their commits.Also found while doing this (filed separately, not fixed here): changing the shadow interval/resolution with shadows on leaks the old baker's GL resources; Map-mode
CameraController::update()re-applies the orbit pose afterframeMap.