Repository navigation
cvcGL: sync-to-vblank off for every cvcgl_* / pycvc GL ctest, not per test - #583
Merged
Merged
Conversation
… test NVIDIA's GLX driver throttles buffer swaps of an unmapped (offscreen) window to about one per second while sync-to-vblank is on, so an offscreen GL test spends minutes of wall time on seconds of CPU (#512: cvcgl_streaming_overlays took 4m15s wall for 1.7 s CPU, 4.7 s with __GL_SYNC_TO_VBLANK=0). #512 and later tests worked around it one test at a time, with setenv before the first GL context. Every other offscreen GL test was still throttled. - src/cvcGL/CMakeLists.txt: append __GL_SYNC_TO_VBLANK=0 and vblank_mode=0 to the ENVIRONMENT of every test in the directory. It uses the same DIRECTORY TESTS sweep as the cvcgl_gl_context resource lock, so a new test gets it without asking. APPEND keeps any per-test ENVIRONMENT. - bindings/pycvc/CMakeLists.txt: the twelve GL-block tests (pycvc_gl_*, pycvc_ari, pycvc_vtk, pycvc_texture) each repeated the same PYTHONPATH/LD_LIBRARY_PATH string. They now share _PYCVC_GL_TEST_ENV, which also carries the two variables. - Drop the per-test workarounds: streaming_test_util.h's disableSwapThrottle() and its four callers (cvcgl_streaming_geometry, cvcgl_streaming_overlays, cvcgl_clip_children, cvcgl_clip_planes), the vblank lines in cvcgl_lowmem_fastdraw, and os.environ.setdefault in test_pycvc_gl_streaming.py and test_pycvc_gl_clip.py. cvcgl_lowmem_bench keeps its own: it is not a ctest, so the ENVIRONMENT never reaches it. No setenv is needed, so Windows and wasm build as before. ctest's ENVIRONMENT overrides the caller's environment; to time a test with vsync on, run its binary directly. Why not disable buffer swaps on cvcGL's offscreen windows instead (vtkRenderWindow::SetSwapBuffers(false))? In VTK 9.5, SwapBuffers off also skips the render-to-display framebuffer resolve in vtkOpenGLRenderWindow::Frame(). writePNG/frameRGB read the back buffer and would be fine. A front-buffer read through renderWindow(), for example a default vtkWindowToImageFilter, would return a stale frame. vtkHardwareSelector also calls SwapBuffersOn() unconditionally after every selection (cvcgl_lowmem_fastdraw picks on a SceneRenderer window). The DoubleBuffer variant collides with FrameYield, which owns DoubleBuffer, and with cvcgl_frame_yield's check that DoubleBuffer stays 1 natively.
transfix
marked this pull request as ready for review
October 19, 2026 20:42
…nc-off # Conflicts: # bindings/pycvc/CMakeLists.txt
transfix
enabled auto-merge (squash)
October 19, 2026 21:09
transfix
added a commit
that referenced
this pull request
Oct 20, 2026
…every cvcgl_* ctest) Master's #583 removed cvcgl_test::disableSwapThrottle() and sets __GL_SYNC_TO_VBLANK=0 / vblank_mode=0 on every test in src/cvcGL through ctest's ENVIRONMENT, which covers cvcgl_ari_golden too; the merge left the call behind and package-linux / libcvc-debug failed to compile it.
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.
Problem
NVIDIA's GLX driver throttles buffer swaps of an unmapped (offscreen) window to about one per second while sync-to-vblank is on. VTK's offscreen X window calls
glXSwapBuffersonce perRender(), so an offscreen cvcGL test spends minutes of wall time on seconds of CPU. #512 found this:cvcgl_streaming_overlaystook 4m15s wall for 1.7 s CPU, and 4.7 s with__GL_SYNC_TO_VBLANK=0 vblank_mode=0. #512 and two later PRs worked around it one test at a time, withsetenvbefore the first GL context. Every other offscreen GL test (cvcgl_renderer,cvcgl_viewport,cvcgl_lighting, the shadow tests, …) is still throttled.Change
src/cvcGL/CMakeLists.txt: appends__GL_SYNC_TO_VBLANK=0andvblank_mode=0to theENVIRONMENTof every test in the directory. It uses the sameDIRECTORY PROPERTY TESTSsweep as thecvcgl_gl_contextresource lock just above it, so a new test gets it without asking.APPENDkeeps any per-testENVIRONMENT. The headless and node tests ignore it.bindings/pycvc/CMakeLists.txt: the thirteen tests in the GL block (pycvc_gl_*,pycvc_ari,pycvc_vtk,pycvc_texture) each repeated the samePYTHONPATH/LD_LIBRARY_PATHstring. They now share one_PYCVC_GL_TEST_ENV, which also carries the two variables, and a new test copying the pattern picks it up.streaming_test_util.h'sdisableSwapThrottle()and its four callers (cvcgl_streaming_geometry,cvcgl_streaming_overlaysfrom cvcGL: streaming overlay geometry with partial uploads (StreamingGeometryNode, RibbonNode, terrain-hugging links) #512;cvcgl_clip_children,cvcgl_clip_planes).cvcgl_lowmem_fastdraw.os.environ.setdefaultintest_pycvc_gl_streaming.pyandtest_pycvc_gl_clip.py.cvcgl_lowmem_benchkeeps its own because it is not a ctest, so theENVIRONMENTproperty never reaches it.There is no
setenvand no source change to the library, so Windows and wasm build exactly as before.One behaviour change: ctest's
ENVIRONMENToverrides the caller's environment, whereas the oldsetenv(…, 0)let an explicit setting win. To time a test with vsync on, run its binary directly. The CMake comment says so.Why not stop offscreen windows swapping (option a)
vtkRenderWindow::SetSwapBuffers(false)on cvcGL's offscreenViewportManagerwindow was the first choice. It isn't clean in VTK 9.5:vtkOpenGLRenderWindow::Frame()gates the whole render-to-display framebuffer resolve onSwapBuffers, not only the platform swap. cvcGL's ownwritePNG/frameRGBread the back buffer and would be fine. Any front-buffer read throughrenderWindow(), for example avtkWindowToImageFilterleft at its defaultReadFrontBuffer=1, would silently return a stale frame.vtkHardwareSelector::EndSelection()callsSwapBuffersOn()unconditionally, without restoring the previous value.cvcgl_lowmem_fastdrawpicks on aSceneRendererwindow, so the throttle would come back mid-test.SetDoubleBuffer(0)variant is taken. It would skip only the platform swap, butDoubleBufferis FrameYield's lever on wasm, andcvcgl_frame_yieldasserts that it stays 1 natively.Production offscreen renders on NVIDIA (outside ctest) are therefore still throttled unless the process sets
__GL_SYNC_TO_VBLANK=0. That would be a separate change in the library.Measurement: 5.1x less wall time on NVIDIA
Measured 2026-10-19 on an NVIDIA GeForce GTX 1650 (driver 595.99.02, Ubuntu 24.04), through the X server of the box's own GNOME session (
glxinfo -B: NVIDIA, GL 4.6).nvidia-settings -q SyncToVBlankreads 1, and neither variable was set in the caller. Release, gcc 13.3, deps from cvcpkg (install-deps cvcpkg/recipes/libcvcplus vtk 9.5.0, imgui, sdl3).beforeis master9f4587b3;afteris this branch's mergeb8f89a6f, the same master plus this PR. Both have the same 69cvcgl_*tests;ctest --show-only=json-v1shows the variable on 0 of them before and on 69 after.ctest -R cvcgl_(NVIDIA, Release)9f4587b3)b8f89a6f)The CPU time is the same on both sides; the 430 s difference was all spent waiting on the swap throttle. The biggest drops per test:
cvcgl_shadow_casterscvcgl_volren_nodecvcgl_volslice_nodecvcgl_shadow_caster_growthcvcgl_shadow_pass_reusecvcgl_renderercvcgl_camera_idlecvcgl_lod_nodecvcgl_viewportAs predicted, the five tests that already had their own workaround read the same on both sides (each within 0.11 s:
cvcgl_streaming_overlays2.15 / 2.26 s,cvcgl_lowmem_fastdraw2.56 / 2.58 s).A pre-existing race surfaced. In the first
afterrun,cvcgl_stage_caster_truthsegfaulted; the second run passed 69/69. It is not caused by this PR. Running the binary directly 20 times per case:__GL_SYNC_TO_VBLANK=09f4587b3A gdb backtrace catches two threads in the scene graph at once:
state_publisher::worker → flush → cvc::state::value → GraphicsNode::handleStateChanged → SceneNode::runOnMainThread, which runs the lambda inline there and crashes inGraphicsNode::updateOwnClipWorld.StageLighting::apply → SceneGraph::addLight → NullGraphicNode::syncBoundsToChildren → updateBoundingBoxNode → BBoxNode::createCoordinateLabels, creating VTK objects.runOnMainThreadruns work inline whenever the node has no scene event sink yet (!events), so a node still being added can take VTK work on the publisher's thread. With vsync on it never crashed in 40 runs, so the throttle's timing hides it (the exact mechanism is not traced). Any run without the throttle can hit it, whether this PR on NVIDIA or another fast driver. It is a separate fix.To reproduce, use a box with an NVIDIA GPU and an X server (VTK's offscreen GLX path), with the driver's sync-to-vblank at its default (on):
beforeis master, which already has the five per-test workarounds. The delta is therefore the rest of the suite. If the X server belongs to a desktop session, also export itsDISPLAYandXAUTHORITY.What ran locally
__GL_SYNC_TO_VBLANK=1:APPENDadds both variables to every test;ENVIRONMENTis kept;$<TARGET_FILE_DIR:…>generator expression;__GL_SYNC_TO_VBLANK=0, which is where the override note above comes from.vtkOpenGLRenderWindow::Frame/ReadPixels,vtkXOpenGLRenderWindow::Frame,vtkHardwareSelectorandvtkWindowToImageFilteratv9.5.0.<cstdlib>stays instreaming_test_util.hbecauseCVC_REQUIRE_RENDERstill uses it, andosstays imported in both Python tests.Merge with master (2026-10-19)
bindings/pycvc/CMakeLists.txt: master addedpycvc_gl_world_geometrywith the old inlinePYTHONPATH/LD_LIBRARY_PATHstring. It now uses_PYCVC_GL_TEST_ENVlike the rest of the block.disableSwapThrottle()caller and no new per-test vblanksetenv. The only one left iscvcgl_lowmem_bench's, on purpose (above).-DCVC_BUILD_TESTS=ON -DCVC_BUILD_CVCGL=ON -DCVC_BUILD_PYCVC_GL=ON):ctest --show-only=json-v1: all 68cvcgl_*tests and all 13 pycvc GL tests carry__GL_SYNC_TO_VBLANK=0andvblank_mode=0, and the pycvc ones keep theirPYTHONPATH/LD_LIBRARY_PATH.cvcgl_streaming_geometry,cvcgl_streaming_overlays,cvcgl_clip_children,cvcgl_clip_planesandcvcgl_lowmem_fastdraw(the five that lost their own workaround) pass with real offscreen renders and pixel checks;ctest -Vshows both variables in their environment. Windows renders through WGL, not GLX, so this checks correctness, not the speedup.