Skip to content

cvcGL: shader textures fit WebGL2's 16 units: the reserve is the mapper's arrays (terrain_lab's water in the browser) - #1313

Merged
transfix merged 2 commits into
masterfrom
fix/webgl-texture-budget
Nov 17, 2026
Merged

transfix merged 2 commits into
masterfrom
fix/webgl-texture-budget

Conversation

@transfix

Copy link
Copy Markdown
Owner

Second half of terrain_lab's browser lock-up, after #1304.

What the redeploy showed. With #1304 deployed, headless Chrome on terrain_lab logged 3,736 console messages in 75 s, down from 89,998. But 2,318 of them were still "Hardware does not support the number of textures defined", starting when the water's cascades came up.

Why.

  • VTK 9.5 sizes its texture-unit table from GL_MAX_TEXTURE_IMAGE_UNITS (vtkTextureUnitManager::Initialize). That is 32 on this NVIDIA GL, but 16 in WebGL2: headless Chrome on ANGLE/D3D11 reports frag 16, vert 16, combined 32.
  • GeometryNode::bindShaderTextures first reserved a fixed 8 units for the low-memory mapper's emulated vertex arrays. That left a draw 8 for its own textures.
  • The water binds 10: three cascades, three coast grids, the wake, the bed, and two cloud-shade textures.

The fix.

  • LowMemoryPolyDataMapper::arrayTextureUnits() returns the arrays the draw under way will take: vtkDrawTexturedElements::Arrays, bound in RenderPieceStart before UpdateShaderEvent fires and activated after it.
    • bindShaderTextures reserves exactly that many when the drawing mapper is one of ours. The drawing mapper is the event's caller, or the node's own mapper for the streaming hooks.
    • Any other mapper keeps the 8-unit reserve.
  • A texture that still finds no unit is left unbound, so its sampler is no longer set to -1. That was the "Sampler uniform value out of range" error on every draw.
  • cvcGL names the node and the texture once, e.g. cvcGL: near: no texture unit left for uWake (16 in all, 8 kept for the mapper's vertex data, 10 shader textures).
  • ViewportManager::limitTextureUnits(n) and $CVCGL_TEXTURE_UNITS cap VTK's table. The cap is put back at the start of each render, since VTK recreates its GL state on a reset. With CVCGL_LOWMEM_MAPPER=force, a native run draws within the browser's budget.

Checked (MSVC Release, Windows).

  • Native arigl snapshot of terrain_lab with CVCGL_LOWMEM_MAPPER=force CVCGL_TEXTURE_UNITS=16, 120 frames: 1,440 out-of-units warnings with the fixed reserve (the water's far and near grids out of units for uWake), and 0 with this change.
  • cvcgl_ariadne_realize gets a WebGL2 block. It draws the water (with a swell, so the swash and coast grids are on), cloud_sky's shade and a shadow-casting sun with the low-memory mapper at 16 units, and expects no out-of-units warning. It also checks that the counter hears VTK's warning.
    • This smaller scene stays within 16 units even with the fixed reserve, so the block guards against regressions. It is not the reproduction; the terrain_lab run above is.
  • 35 related cvcGL ctests pass: ocean/ewave/wake, lighting and shadows, textures and streaming, volren/volslice, ribbons, low-memory fastdraw and every ariadne suite.

Not checked: Linux, macOS, and the browser itself. After this deploys: rerun the headless probe, then look at terrain_lab in a browser.

Budget note for open PRs: #1311 (O13) adds a ninth water sampler, so the water binds 11 with the shade. With the arrays taking about 4–5 units, that still fits in 16. The knob above checks it natively.

…er's arrays

#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.
The one conflict, docs/ARIADNE.md, keeps both: #1310's 'Recording a video'
section, then the browser's texture units. cvcgl_ariadne_realize's 16-unit
block still passes with #1311's uWindFetch in the water: no draw runs out.
@transfix
transfix merged commit f128352 into master Nov 17, 2026
29 checks passed
@transfix
transfix deleted the fix/webgl-texture-budget branch November 17, 2026 00:16
transfix added a commit that referenced this pull request Nov 17, 2026
…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 added a commit that referenced this pull request Nov 17, 2026
One conflict, in ci.yml's SAN_CXX_TESTS: this branch added stream_test, net_ws_client_test and
ariadne_host_test to the sanitizer legs' list, and #1292 added gradient_vector_diffusion_test,
critical_points_test and seed_generators_test (reflowing the lines). Kept both.

ci.yml's line 1271 (the arigl-web path filter's files.h/files.cpp line) also goes back to master's
bytes: master stores ci.yml with CRLF but that one line LF-only, and an earlier merge here had
given it a CR, a whitespace-only change in this PR's diff.
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