Skip to content

cvcGL: a shader-input texture holds its unit only for its own draw (terrain_lab's browser lock-up) - #1304

Merged
transfix merged 1 commit into
masterfrom
fix/cvcgl-texture-units
Nov 16, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/cvcgl-texture-units

Conversation

@transfix

Copy link
Copy Markdown
Owner

The deployed terrain_lab locks up the browser (and anything capturing it) since the water stack landed. This fixes the cause.

What was wrong. GeometryNode::bindShaderTextures (src/cvcGL/GeometryNode.cpp) activated each shader-input texture and never deactivated it, so every such texture a node had ever drawn kept a texture unit for good.

  • VTK hands out at most 32 units. Native GL never got close.
  • In the browser, the wasm low-memory mapper also takes units for its emulated vertex buffers on every draw, and bindShaderTextures reserves 8 more while it binds.
  • terrain_lab with the water (three cascades, three coast grids, the wake, the bed), the swash and the cloud shade ran out. Every draw after that failed and logged "Hardware does not support the number of textures defined" (vtkOpenGLState.cxx:1796) and "glUniform1i: Sampler uniform value out of range".
  • Headless Chrome on the deployed page logged 89,998 console messages in 75 s, 59,826 of them the texture-unit warning. That flood is what froze the page.

The fix.

  • GeometryActor, every GeometryNode's actor, overrides Render(ren, mapper). After the mapper's draw, it deactivates what bindShaderTextures activated for that draw. This covers every layer and pass that draws the actor: opaque, translucent, the shadow bake, picking, and the volumes' layer.
  • bindShaderTextures becomes a member so it can record on the node's actor. Its three callers are unchanged except onUpdateShader, which now calls self->. A texture that was already active (someone else's) is left as it was.

Checked (MSVC Release, Windows):

  • cvcgl_ariadne_realize gets a check: after the water + cloud_sky scene's frames, with the swash on 21 ground meshes, the context holds no texture unit between frames. With this change it holds 0 of 32; with master's GeometryNode it held 10 of 32, and the check fails.
  • 35 related cvcGL ctests pass: ocean, ewave and wake; lighting and shadows; textures and streaming; volren and volslice (volslice draws a volume mapper with a node's shader inputs); ribbons; low-memory fastdraw; and every ariadne suite.

Not checked here: Linux, macOS and the wasm CI lanes. The browser gets checked after the Pages redeploy: the same headless probe, then terrain_lab in a browser.

GeometryNode::bindShaderTextures activated each shader-input texture
and never deactivated it, so every such texture a node had ever drawn
kept a texture unit. VTK hands out at most 32. In the browser the wasm
low-memory mapper also takes units for its emulated vertex buffers each
draw, and bindShaderTextures reserves 8 more while it binds. terrain_lab
with the water (cascades, coast, wake, bed), the swash and the cloud
shade ran out: every later draw failed, and logged "Hardware does not
support the number of textures defined" and "Sampler uniform value out
of range" (about 90,000 console messages in 75 s, headless Chrome on
the deployed page), which locked the page up.

- GeometryActor (every GeometryNode's actor) overrides Render(ren,
  mapper): after the mapper's draw it deactivates what
  bindShaderTextures activated for that draw. That covers every layer
  and pass (the shadow bake, picking, the volumes' layer).
- bindShaderTextures is now a member, so it can record on the node's
  actor. A texture that was already active (someone else's) is left as
  it was.
- cvcgl_ariadne_realize: after the water + cloud_sky scene's frames,
  with the swash on 21 ground meshes, the context holds no texture
  unit between frames. Master's code held 10 of 32 there.
@transfix
transfix enabled auto-merge (squash) November 16, 2026 07:05
@transfix
transfix merged commit 3976ae2 into master Nov 16, 2026
2 of 29 checks passed
@transfix
transfix deleted the fix/cvcgl-texture-units branch November 16, 2026 07:15
transfix added a commit that referenced this pull request Nov 16, 2026
…#1307)

One conflict, in ariadne_runtime_test.cpp's ActionCapsAreTreeSettingsAndChargeAsyncCalls: this
branch cut its loop to 20 rounds so it fit the 0.1 s time cap on Linux debug CI, and master
(#1282) rewrote the test, raising the time cap to 30 s wherever the loop must finish.
Master's fix covers the same flake, so the test is master's as it stands, 200 rounds again.

tools/singleton_scan is master's (#1276); the auto-merged net, CI, test and doc files keep both
sides.
transfix added a commit that referenced this pull request Nov 17, 2026
…er's arrays (#1313)

#1304 stopped shader-input textures holding their units between draws.
The redeployed terrain_lab still ran out in every water draw: headless
Chrome logged 2,318 out-of-units warnings in 75 s once the water came
up. VTK sizes its texture-unit table from GL_MAX_TEXTURE_IMAGE_UNITS,
which is 32 on a desktop GL but 16 in WebGL2. bindShaderTextures first
reserved a fixed 8 units for the low-memory mapper's emulated vertex
arrays, which left a draw 8 for its own textures, and the water binds
10 (three cascades, three coast grids, the wake, the bed, two
cloud-shade textures).

- LowMemoryPolyDataMapper::arrayTextureUnits(): the arrays the draw
  under way takes, vtkDrawTexturedElements::Arrays (bound in
  RenderPieceStart, before UpdateShaderEvent fires). bindShaderTextures
  reserves that many when the drawing mapper (the event's caller, or
  the node's own) is one of ours, else 8 as before.
- A texture that still finds no unit is left unbound, so it no longer
  sets a -1 sampler, which was a second GL error every draw. cvcGL
  names the node and texture once.
- ViewportManager::limitTextureUnits(n) and $CVCGL_TEXTURE_UNITS cap
  VTK's table, put back at the start of each render after a GL state
  reset. With CVCGL_LOWMEM_MAPPER=force, a native run draws within the
  browser's budget. Native terrain_lab that way logged 1,440 warnings
  with the fixed reserve ("far" and "near" out of units for uWake: 16
  in all, 8 kept, 10 shader textures), and 0 with this change.
- cvcgl_ariadne_realize: the water (with a swell, so the swash and coast
  grids are on), cloud_sky's shade and a shadow-casting sun, drawn with
  the low-memory mapper at 16 units, log no out-of-units warning. The
  count is checked to hear VTK's warning.
- ARIADNE.md: the browser's texture units, natively.
- The comment #1304 added said WebGL2 gives VTK 32 units; it gives 16.
transfix added a commit that referenced this pull request Nov 17, 2026
…1315)

* world: the weather model, storm cells on a schedule and authored events (O18)

cvc::world::weather is a pure function of its parameters, the world time and
authored events (storm, steer, rate, calm): storms on hashed slots run clear,
building, storm, clearing and clear, born upwind and timed to cross the area in
their prime, riding the steering wind. It publishes the cells, the storm field
and a rain rate for O19 and O20. A weather stream is appended to lsys::stream.

* cloud_layer: storms close the deck; live base/top with cumulonimbus maps built off the frame

set_storms gives each cell a storm share that feeds it, holds it besides the
fair-weather coverage and deepens its shade and far opacity. set_deck makes the
maps again for new heights; a deck deeper than its cumulus grows cumulonimbus
(ABYSSAL's height profile) whose self-shade marches the sun through the tower.
prepare_deck / run / adopt_deck build it on another thread, and the cumulus the
maps grow from is kept, so a storm deck comes in in about 150 ms. cell_up_tau is
the optical depth straight up, for dark bases.

* cloud_sky: live base/top, darkness and storms; the weather node in terrain_lab

cloud_sky reads sky.base, sky.top, sky.darkness and sky.storms live: a storm deck
is built off the frame and swapped into the same near volumes and far shells, the
ramp darkens toward a storm's, a darkened cloud's light dims as the cloud above
hides the sky, and the storms reach the far shells and the receivers as uniforms
(no new sampler). The weather node owns the model over its ground, drives the sky
and publishes weather.*; its steering wind is the sky's until O14's scene wind.
weather_controls.ari, terrain_lab's weather node, docs and the roadmap's as built.

* cloud_sky: build a storm deck as a sliced task, a share a frame where there are no threads

std::async cannot start a thread in single-threaded wasm (the Pages gallery,
arigl-web), so a storm coming into reach would have aborted the page. The deck's
build is now a cvc::sliced_job on the app's scheduler, as generated_world's
rebuilds are (#984): on the background pool natively, a few milliseconds a frame
on the scheduler thread where there are no threads. cloud_layer::step builds a
deck a unit at a time (a variant's map, one layer of its self-shade, one row of
its shade), bit-identical to building it at once. deck_threading: cooperative
forces the sliced path natively; cvcgl_ariadne_realize runs the storm both ways.

* cvcGL: shader textures fit WebGL2's 16 units: the reserve is the mapper's arrays

The redeployed terrain_lab still ran out in every water draw: headless
Chrome logged 2,318 out-of-units warnings in 75 s once the water came
up. VTK sizes its texture-unit table from GL_MAX_TEXTURE_IMAGE_UNITS,
which is 32 on a desktop GL but 16 in WebGL2. bindShaderTextures first
reserved a fixed 8 units for the low-memory mapper's emulated vertex
arrays, which left a draw 8 for its own textures, and the water binds
10 (three cascades, three coast grids, the wake, the bed, two
cloud-shade textures).

- LowMemoryPolyDataMapper::arrayTextureUnits(): the arrays the draw
  under way takes, vtkDrawTexturedElements::Arrays (bound in
  RenderPieceStart, before UpdateShaderEvent fires). bindShaderTextures
  reserves that many when the drawing mapper (the event's caller, or
  the node's own) is one of ours, else 8 as before.
- A texture that still finds no unit is left unbound, so it no longer
  sets a -1 sampler, which was a second GL error every draw. cvcGL
  names the node and texture once.
- ViewportManager::limitTextureUnits(n) and $CVCGL_TEXTURE_UNITS cap
  VTK's table, put back at the start of each render after a GL state
  reset. With CVCGL_LOWMEM_MAPPER=force, a native run draws within the
  browser's budget. Native terrain_lab that way logged 1,440 warnings
  with the fixed reserve ("far" and "near" out of units for uWake: 16
  in all, 8 kept, 10 shader textures), and 0 with this change.
- cvcgl_ariadne_realize: the water (with a swell, so the swash and coast
  grids are on), cloud_sky's shade and a shadow-casting sun, drawn with
  the low-memory mapper at 16 units, log no out-of-units warning. The
  count is checked to hear VTK's warning.
- ARIADNE.md: the browser's texture units, natively.
- The comment #1304 added said WebGL2 gives VTK 32 units; it gives 16.

* world: the weather's recent storms, their rain radius and the ground's wetness (O19)

weather::recent gives the cells whose life reached into a window, alive or gone;
rain_radius is where a cell's field passes the rain onset; wetness is how long a
recent storm's rain lay over a point over a soak time, times its drying since,
the CPU twin of the wet ground the sky draws and the friction O20 will read.

* rain: streaks near the camera, shafts, wet ground, rings on the water and fog (O19)

The weather node hands cloud_sky the recent storms' tracks and the rain's
constants (sky.rain, sky.rain_k) and draws the streaks near the camera: a port of
ABYSSAL's Rain, drops placed and moved in the vertex shader as a closed form of
time, slanted by the scene wind's one accessor. cloud_sky draws rain shafts below
the cloud base in its far shells, wets and darkens its receivers along the tracks
and dries them after, puts procedural raindrop rings into the water's normal, and
thickens a distance fog with the rain at the camera, all as uniforms: no sampler
joins the ground, the buildings, the roads, the trees or the water. terrain_lab's
sky lists the streaks; the Weather panel has the rain's keys.

* rain: the sky finds the streaks inside the weather's node; the ground off the terrain

cloud_sky looked its receivers up among the scene's top-level names, so the
weather's streak mesh (weather_rain, a child of the weather's node) was never
wired: it drew without the deck's shade and fog, and in the volume layer
before the clouds instead of after them. A receiver is now found anywhere in
the scene. The streaks' ground under a camera off the terrain is the height at
the terrain's edge, not NaN. cvcgl_ariadne_realize checks that the sky wired
the streaks.

* 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
* world: the weather model, storm cells on a schedule and authored events (O18)

cvc::world::weather is a pure function of its parameters, the world time and
authored events (storm, steer, rate, calm): storms on hashed slots run clear,
building, storm, clearing and clear, born upwind and timed to cross the area in
their prime, riding the steering wind. It publishes the cells, the storm field
and a rain rate for O19 and O20. A weather stream is appended to lsys::stream.

* cloud_layer: storms close the deck; live base/top with cumulonimbus maps built off the frame

set_storms gives each cell a storm share that feeds it, holds it besides the
fair-weather coverage and deepens its shade and far opacity. set_deck makes the
maps again for new heights; a deck deeper than its cumulus grows cumulonimbus
(ABYSSAL's height profile) whose self-shade marches the sun through the tower.
prepare_deck / run / adopt_deck build it on another thread, and the cumulus the
maps grow from is kept, so a storm deck comes in in about 150 ms. cell_up_tau is
the optical depth straight up, for dark bases.

* cloud_sky: live base/top, darkness and storms; the weather node in terrain_lab

cloud_sky reads sky.base, sky.top, sky.darkness and sky.storms live: a storm deck
is built off the frame and swapped into the same near volumes and far shells, the
ramp darkens toward a storm's, a darkened cloud's light dims as the cloud above
hides the sky, and the storms reach the far shells and the receivers as uniforms
(no new sampler). The weather node owns the model over its ground, drives the sky
and publishes weather.*; its steering wind is the sky's until O14's scene wind.
weather_controls.ari, terrain_lab's weather node, docs and the roadmap's as built.

* cloud_sky: build a storm deck as a sliced task, a share a frame where there are no threads

std::async cannot start a thread in single-threaded wasm (the Pages gallery,
arigl-web), so a storm coming into reach would have aborted the page. The deck's
build is now a cvc::sliced_job on the app's scheduler, as generated_world's
rebuilds are (#984): on the background pool natively, a few milliseconds a frame
on the scheduler thread where there are no threads. cloud_layer::step builds a
deck a unit at a time (a variant's map, one layer of its self-shade, one row of
its shade), bit-identical to building it at once. deck_threading: cooperative
forces the sliced path natively; cvcgl_ariadne_realize runs the storm both ways.

* cvcGL: shader textures fit WebGL2's 16 units: the reserve is the mapper's arrays

The redeployed terrain_lab still ran out in every water draw: headless
Chrome logged 2,318 out-of-units warnings in 75 s once the water came
up. VTK sizes its texture-unit table from GL_MAX_TEXTURE_IMAGE_UNITS,
which is 32 on a desktop GL but 16 in WebGL2. bindShaderTextures first
reserved a fixed 8 units for the low-memory mapper's emulated vertex
arrays, which left a draw 8 for its own textures, and the water binds
10 (three cascades, three coast grids, the wake, the bed, two
cloud-shade textures).

- LowMemoryPolyDataMapper::arrayTextureUnits(): the arrays the draw
  under way takes, vtkDrawTexturedElements::Arrays (bound in
  RenderPieceStart, before UpdateShaderEvent fires). bindShaderTextures
  reserves that many when the drawing mapper (the event's caller, or
  the node's own) is one of ours, else 8 as before.
- A texture that still finds no unit is left unbound, so it no longer
  sets a -1 sampler, which was a second GL error every draw. cvcGL
  names the node and texture once.
- ViewportManager::limitTextureUnits(n) and $CVCGL_TEXTURE_UNITS cap
  VTK's table, put back at the start of each render after a GL state
  reset. With CVCGL_LOWMEM_MAPPER=force, a native run draws within the
  browser's budget. Native terrain_lab that way logged 1,440 warnings
  with the fixed reserve ("far" and "near" out of units for uWake: 16
  in all, 8 kept, 10 shader textures), and 0 with this change.
- cvcgl_ariadne_realize: the water (with a swell, so the swash and coast
  grids are on), cloud_sky's shade and a shadow-casting sun, drawn with
  the low-memory mapper at 16 units, log no out-of-units warning. The
  count is checked to hear VTK's warning.
- ARIADNE.md: the browser's texture units, natively.
- The comment #1304 added said WebGL2 gives VTK 32 units; it gives 16.

* world: the weather's recent storms, their rain radius and the ground's wetness (O19)

weather::recent gives the cells whose life reached into a window, alive or gone;
rain_radius is where a cell's field passes the rain onset; wetness is how long a
recent storm's rain lay over a point over a soak time, times its drying since,
the CPU twin of the wet ground the sky draws and the friction O20 will read.

* rain: streaks near the camera, shafts, wet ground, rings on the water and fog (O19)

The weather node hands cloud_sky the recent storms' tracks and the rain's
constants (sky.rain, sky.rain_k) and draws the streaks near the camera: a port of
ABYSSAL's Rain, drops placed and moved in the vertex shader as a closed form of
time, slanted by the scene wind's one accessor. cloud_sky draws rain shafts below
the cloud base in its far shells, wets and darkens its receivers along the tracks
and dries them after, puts procedural raindrop rings into the water's normal, and
thickens a distance fog with the rain at the camera, all as uniforms: no sampler
joins the ground, the buildings, the roads, the trees or the water. terrain_lab's
sky lists the streaks; the Weather panel has the rain's keys.

* rain: the sky finds the streaks inside the weather's node; the ground off the terrain

cloud_sky looked its receivers up among the scene's top-level names, so the
weather's streak mesh (weather_rain, a child of the weather's node) was never
wired: it drew without the deck's shade and fog, and in the volume layer
before the clouds instead of after them. A receiver is now found anywhere in
the scene. The streaks' ground under a camera off the terrain is the height at
the terrain's edge, not NaN. cvcgl_ariadne_realize checks that the sky wired
the streaks.

* world: the weather schedules lightning strikes (O20)

weather::strikes(t, window) lists the strikes of the last window weather
seconds: each recent cell's life in 1 s slots, a slot holding a strike with
probability flash_rate times a smoothstep of the cell's intensity from
flash_onset, a hashed draw of the seed, the cell and the slot, at a hashed
point within its rain radius; ground_share of them reach the ground. A
lightning_strike carries its id (the seed of its bolt), its time, its point
and one to four strokes, and intensity(age) gives its light. A pure function
of the seed, the time and the events, so every client sees the same strike.
Test: WorldWeather.LightningStrikesOnSchedule.

* physics: rain lowers the surfaces' friction through the material table (O20)

surface_class::mu_wet is each class's friction soaked (wet asphalt and
concrete 0.55, dirt 0.35, gravel and sand 0.45, grass 0.3; indoor floors keep
theirs). cvc::physics::wet_friction(class, w) runs mu toward it by the
wetness, and apply_wetness(world, w) sets every material named after a
surface class (as add_world_geometry names them) through world::set_material.
Test: PhysicsVehicle.RainLowersTheRoadsTractionAndItComesBackAsItDries, a
storm crossing the road: braking from 20 m/s the vehicle stops in 25.2 m dry,
37.8 m soaked and 25.2 m three dry times later.

* lightning: bolts and their flash; the rain into the scene's friction (O20)

The weather node draws the brightest strike of the moment as a bolt, a port
of ABYSSAL's Lightning (Lightning.js at 849ff7f4, MIT; notice in the header
and THIRD_PARTY_NOTICES.md): a channel from the cloud base to the ground by
midpoint displacement, fading forks and in-cloud crawlers, grown from the
strike's id, drawn as camera-facing ribbons (a hot core and a blue-white
glow, tapering past their ends) in the mesh <id>_bolt, rebuilt once a strike
and drawn after the deck as a sky receiver. Its ground point is the ground's
height, at the terrain's edge past it.

The flash goes to the sky as sky.flash, a frame step ahead since the sky
ticks first, and from there as one vec4 uniform, cloudFlash: the receivers
add their albedo times it, the water its lit term, the far shells glow round
the strike and the background whitens. No sampler is added.

In a scene with a physics world the node sets the surface materials'
friction from weather::wetness at the vehicles (apply_wetness), at most twice
a world second and only when the wetness moves by 1/64; weather.friction off
restores the dry friction. Keys weather.lightning, .flash, .friction and
.wetness, on the Weather panel; props flash_rate, flash_onset, ground_share,
lightning and friction. terrain_lab lists weather_bolt among the receivers.
cvcgl_ariadne_realize covers the lightning, the bolt's wiring and the
friction. Docs: ARIADNE.md, and "As built (O20, part 1)" in the roadmap,
with what F4 needs from O14.

* 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.

* Ariadne weather: the rain's friction is the scene world's, set in the physics step on the clock

The wet friction (O20, F6) was set by cvcGL's weather node from its frame tick: at most twice a world
second, into the physics world's materials from the next step on. The wetness is a function of the
seed, the time and the events, but the step at which the friction changed depended on when a frame
came (30 fps, 60 fps or an offscreen capture changed it at different steps), and a host without a
renderer (ari, arisrv, a headless test) never applied it, so one document's physics differed by host
and frame rate.

The friction is physics, so the scene's world now sets it. scene_weather.h:
- scene_weather_params / _ground / _soak / _dry read a weather node's props; the drawn node and the
  world both use them, so the friction follows the storms the node draws.
- WeatherFriction (one per weather node, SceneWorld::bind_weather; from_scene and scene_realize both
  bind it) reads weather.events and weather.friction at sync, and sets the friction in follow()
  before the physics step: on the first step of each half second of world time, counted in the
  world clock's ticks (each step's tick from the clock follower), when the wetness at the vehicles
  (their mean; the weather's centre with none) has moved by 1/64. weather.friction 0 dries the
  surfaces at the next step. It publishes weather.wetness. A restart sets it again at the next step.

The weather node no longer touches the friction (its frame tick is gone) and takes its params and
soak/dry from scene_weather.

Test: AriadneSceneWeather.TheRainsFrictionIsSetInTheStepOnTheClocksTicks. A headless world lowers
asphalt's friction to its soaked value; it first changes on a half-second boundary; a run with uneven
0.137 s frames has the same friction as one with a frame per clock quantum at every tick both see;
weather.friction 0 dries it at the next step.

* AriadneSceneWeather test: the friction is the wet ground's at the wetness applied (the storm moves on and the ground begins to dry), not a full soak
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