Repository navigation
cvcGL shadows: an idle conference room bakes none, and a bake keeps its shaders and skips the framebuffer status wait - #996
Merged
Conversation
… shader per render pass The browser conference spent most of its render time on shadows: the shadow maps were re-baked with nobody moving, and every bake rebuilt every caster's shader source twice. - room_view: a marker is re-posed only once its pose has moved 1e-4 (0.1 mm, or under a hundredth of a degree) from the one it shows. A standing avatar's shown pose changes by rounding from frame to frame (measured natively under mouse look: rotation 2e-16, position up to 3e-8 m), and every pose applied moves a shadow caster: 170 bakes in 35 s standing still, natively; 0 now. The visor and parts move with the marker or not at all. - LowMemoryPolyDataMapper (the WebGL mapper) keeps a shader per set of render passes. Under shadows each caster is drawn by the bake and by the shadow pass, and VTK rebuilt its shader (a dozen-odd Substitute calls over ~16 KB, then the cache's copy and MD5) at every switch. The shader kept for a set is put back with its sources, GLSL mods and build stamp, so VTK's own up-to-date test judges it; it is dropped when a pass it was built for is gone, when the actor's property or textures changed since, or with the rest when the color or normal source or the array declarations change. CVCGL_LOWMEM_PASS_PROGRAMS=0 turns it off for A/B runs. - FilteredShadowMapPass reports a shader-stage MTime: its shader follows which lights cast, and only the alternation used to rebuild for that. - SceneGraph::shadowBakes(), for the tests and for telling a frame's cost apart. Tests: cvcgl_shadow_pass_programs (new: no shader builds while a caster moves, against two a caster a frame without; frames equal to pass programs off across a change of casting light, a shader-changing property and shadows off and on), and cvcgl_room_view's idle room (no bake while the facing wanders by rounding; turning and walking bake).
With pass programs a bake's draws re-bind the shader kept for their pass set: no build and no lookup, where the check pinned the full lookup every render-pass switch used to cost (still pinned with CVCGL_LOWMEM_PASS_PROGRAMS=0). The scene's stats sum the two new counters.
… every bake vtkOpenGLFramebufferObject::StartNonOrtho asks glCheckFramebufferStatus on every call, so once per casting light in every bake. On WebGL that waits on the GPU process: in the browser conference, walking, it was 8% of all CPU, all of it inside the bake. The bake's framebuffer is now a ShadowBakeFramebuffer whose startBake asks once per (map, size); the answer cannot change while those stay. cvcgl_shadow_pass_programs section F counts the calls at the driver (so the test is desktop GL only now): 0 in 8 frames that bake, against 8 with VTK's StartNonOrtho.
… per program Each kept pass program held its own copy of the vertex and fragment sources (~16 KB each), so a scene of thousands of shadow casters kept tens of MB of identical text on WebGL. The shader cache has one program per distinct source, so the sources are now shared by program (weakly registered, kept alive by the holders, which keep the program alive too), and a pass switch no longer copies them out of the mapper.
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.
The browser conference spent most of its render time on shadows, and motion juddered on a 144 Hz screen ("the camera jumps around" under mouse look). There were three causes:
Substitutecalls over ~16 KB, then the shader cache's copy and MD5, only to find the program it had two draws before. In an earlier browser profile,vtkOpenGLLowMemoryPolyDataMapper::UpdateShaderswas about 19% of all CPU time.vtkOpenGLFramebufferObject::StartNonOrthocallsglCheckFramebufferStatuson every call, which is once per casting light per bake, and on WebGL that call is synchronous. Profiled while walking with 2 fixed, it was 7.9% of all CPU time, inside a bake that took 17.8%.Changes
CVCGL_LOWMEM_PASS_PROGRAMS=0turns it off, for A/B runs.glCheckFramebufferStatusonce per (shadow map, size). The answer can't change while those stay the same, because the depth buffer belongs to the FBO and is resized with it.SceneGraph::shadowBakes(): bakes since shadows were turned on, for tests and frame-cost diagnosis.Who gets what:
Measured
Headless Chrome (D3D11 ANGLE), 1600x900, against a local relay, in mouse look. One round is idle 6 s, turning 4 s, walking 4 s, walking while turning 4 s, then 2 s stopped. The times are arigl's
AriRuntime::renderper frame (ms, median), from a temporary frame timer.Not done: a shadow update interval above 1 while only avatars move. It would save about another millisecond on every other frame, at the price of an avatar's shadow trailing it by a frame.
Tests
cvcgl_shadow_pass_programs, with the low-memory mapper forced (desktop GL only, for the driver call counts):glCheckFramebufferStatusthan frames that don't: 0 extra in 8 bakes, against 8 with VTK'sStartNonOrtho.cvcgl_room_view: an idle room, the facing flipping by one ULP each frame, makes 0 bakes in 60 frames (59 with the threshold at 0). A turn and a walk still bake.cvcgl_lowmem_fastdraw: the check that pinned "a shadow bake takes the full lookup" now expects the kept shader back (no build, no lookup). The old behaviour is still checked withCVCGL_LOWMEM_PASS_PROGRAMS=0. Both pass all 288 checks.ctest -R ^cvcglpasses all 88 tests on the final head.CVCGL_LOWMEM_MAPPER=force(not run in CI),cvcgl_shadow_castersfails one byte-exact footprint check. It fails the same way with every shadow change here reverted.No test pins the browser timings above. They were measured by hand in headless Chrome.