Skip to content

No singletons, cvcGL and pycvc: registries, settings and caches per app [4.0, breaking] - #1187

Closed
transfix wants to merge 1 commit into
p0a/no-singletons-ariadne-4from
p0a/no-singletons-cvcgl
Closed

transfix wants to merge 1 commit into
p0a/no-singletons-ariadne-4from
p0a/no-singletons-cvcgl

Conversation

@transfix

Copy link
Copy Markdown
Owner

No singletons, cvcGL and pycvc: registries, settings and caches per app. Stacked on #1176 (Ariadne part 3); a sibling of #1182, #1183 and #1184. Breaking (4.0).

All of cvcGL's and pycvc's own process-wide state is gone. What remains in their allowlist sections:

What moved

  • Onto the app (app.slot):
    • the scene node types and shader presets (register_scene_node_type, has_scene_node_type, register_shader_preset, has_shader_preset, register_default_shader_presets, verify_scene_customs, and the lsystem, mesh, world, vehicle-preview and stream node registrars);
    • the tf bindings and their owner-tag counter;
    • the UI font settings (ImGuiOverlay::setUiFontPath / setUiFontFallbacks / setUiFontMemory / loadUiFonts);
    • the low-memory mapper's policy, draw path, pass programs, stage observer and shared shader sources (LowMemoryPolyDataMapper::setApp: GeometryNode sets it; a mapper with no app uses its environment defaults; BBoxNode(app), RenderView(app, ...));
    • the X11 clipboard connection (clipboard::set / get, and the core's Backend::set_clipboard(app, text));
    • shadow non-caster marks (GraphicsNode::setPropCastsShadow / propCastsShadow: a table per app replaces the VTK information key);
    • the publisher flush stack (state_publisher::flushing / in_flush).
  • Into their objects:
    • g_glBackendFailed is per overlay. A failed ImGui_ImplOpenGL3_Init also calls imgl3wShutdown(), so a later overlay fails cleanly instead of crashing on a null GL_VERSION; that crash was why the flag had been process-wide.
    • VolumeNode's own-write records and first-call log.
    • The ImGui clipboard buffer.
    • The JPEG codec: jpeg_encoder / jpeg_decoder own their TurboJPEG handles.
  • Constants:
    • the computedKeys sets, the cursor, punctuation and SDL key-name tables, and the gizmo names are constexpr;
    • TouchScroll's ImGui ids are hashed per call, and tf_editor's default model is built per call.
  • SdlWindow:
    • the open-window count and window→interactor routes are SDL window properties;
    • a timer tick goes to the interactor whose timers_ holds its id;
    • the timer event type (SDL_RegisterEvents, a per-process SDL resource that is never returned) is registered once and kept in SDL's own global properties, not in a static of ours.
  • pycvc:
    • enum classes, exception types, the dsl_error factory and the kept names live on the _pycvc module object;
    • SWIG types come from the SWIGTYPE_p_* table;
    • capsule names are constexpr;
    • exec's running marker and pycvc_gl's deferred rung-style error use PyThreadState_GetDict instead of C++ thread_locals.

Allowlist: -103 lines (cvcGL 76, pycvc 26, pycvc_gl 1)

  • cvcGL: Clipboard, GeometryNode, GraphicsNode, ImGuiOverlay, LowMemoryPolyDataMapper, SdlInput, SdlWindow, StageLighting, TouchScroll, ViewportManager, VolumeNode, scene_realize, tf_binding, tf_editor_imgui, jpeg_codec, state_publisher, and the <header> tf_binding::impl::idle_status()::head and its guard.
  • pycvc: all of pycvcPYTHON_wrap.cxx's lines and pycvc_exec.cpp's t_running_exec.
  • pycvc_gl: gl_lod::style_error()::e.

Not removed

  • Dear ImGui's statics in its stock imgui_impl_opengl3.cpp (the GL function table imgl3wProcs, the loader handles, version) and imgui_freetype.cpp (allocator and loader hooks), 11 lines. They are compiled into cvcGL from the deps bundle, not from libcvc's sources. They are third-party; a follow-up adds a source-path rule to scan.py's third-party list for them.
  • X11 clipboard edge: each app now has its own X connection. One app pasting what another app in the same process copied works when the copying app pumps its connection, as for any outside client.

Tests

  • cvcgl_multi_app (new, headless). Each app registers its own node type and shader preset and realizes only its own: another app's type and preset only warn. It also covers the customs gate, mapper settings, shadow marks, publisher flushes and the JPEG codec. It runs alone, on threads at once and in reverse order; a later app starts clean, and UI fonts are per app.
  • Extended: cvcgl_state_publisher (flushing per app), cvcgl_lowmem_fastdraw (another app keeps its own policy and draw path), cvcgl_shadow_casters (a mark is its app's alone), and test_pycvc_app.py (module state for several apps, in either order and on threads).
  • Fixed (they passed only through shared registrations): cvcgl_ariadne_physics and the other cvcGL tests register on their own app; cvcgl_lowmem_fastdraw's probe mappers and cvcgl_lowmem_bench's TallyMapper call setApp.

Locally (Windows, MSVC Release; the whole tree builds):

  • ctest -R ^cvcgl_ 105/105, ctest -R pycvc 64/64, ctest -R ^arigl (10 pass, 5 skipped);
  • app_test 121, multi_app_integration_test 2;
  • ariadne_runtime_test, ariadne_requires_test, ariadne_media_test and job_intrinsics_test (because backend.h changed).

The X11 clipboard branch is not compiled on Windows; the Linux CI builds it.

CI

Full run: the push to ci/full/no-singletons-cvcgl, https://github.com/transfix/libcvc/actions/runs/43212922516.

cvcGL and the pycvc bindings kept process-wide state: scene node types and shader presets, the
transfer-function bindings, the UI font settings, the low-memory mapper's policy, draw path and
shared shader sources, the X11 clipboard connection, SDL's window and timer routes, the props
marked as casting no shadow, the flushing publisher, the JPEG handles and constant tables built
at first use. Each now lives on the cvc::app (app.slot<T>()), in the object that uses it, in the
SDL window it describes, or in read-only data.

cvcGL:
- Scene node types and shader presets are the app's (scene_realize.cpp): register_scene_node_type,
  has_scene_node_type, register_shader_preset, has_shader_preset, register_default_shader_presets
  and verify_scene_customs take the app, as do the registrars that call them
  (register_lsystem_node_types, register_mesh_node_types, register_world_node_types,
  register_vehicle_preview_node, register_stream_node_type). A scene realizes only its own app's
  types and presets.
- tf_binding: the live bindings, the seeds and the overlay_status owners, and the owner-tag
  counter, are the app's (they were keyed by app pointer in a process-wide map). idle_status's
  "unavailable: " is a constexpr string_view.
- tf_editor_imgui: the stand-in default model and overlays are built per call.
- ImGuiOverlay: the UI font settings are the app's (setUiFontPath / setUiFontFallbacks /
  setUiFontMemory / loadUiFonts take the app). The clipboard buffer handed to ImGui is the
  overlay's. A failed ImGui_ImplOpenGL3_Init is remembered per overlay, and clears imgui's GL
  loader table (imgl3wShutdown, as ImGui_ImplOpenGL3_Shutdown does) so a later overlay's Init
  fails cleanly instead of crashing on a null GL_VERSION: that was why g_glBackendFailed had to be
  process-wide.
- Clipboard: clipboard::set/get take the app; on X11 the app holds its own X connection (closed
  with the app). Backend::set_clipboard takes the document's app (the core passes the Runtime's).
- LowMemoryPolyDataMapper: the policy, draw path, pass-program switch and stage observer are the
  app's, read from the environment when the app's settings are first used; a mapper draws by the
  settings of the app newPolyDataMapper(app) (or a node's setApp) gave it, and shares its shader
  source copies with that app's mappers. newPolyDataMapper, setLowMemoryMapperPolicy,
  lowMemoryMapperPolicy, setDrawPath/drawPath, setPassProgramsEnabled/passProgramsEnabled and
  setStageObserver take the app. BBoxNode and RenderView take the app for it.
- SdlWindow: which SDL windows are cvcGL's (openWindows) and whose events each window's are are
  SDL window properties, not process-wide tables; a timer tick goes to the interactor whose timers
  have its id. The registered timer event type is an SDL resource of the process (SDL_RegisterEvents
  gives each type once and none back), so it is kept in SDL's own global properties. The cursor and
  punctuation tables are constexpr.
- GraphicsNode: the shadow non-caster mark is the app's (setPropCastsShadow / propCastsShadow take
  the app); it was a process-wide VTK information key. The shadow passes ask their scene's app.
- state_publisher: which publisher is flushing on a thread is kept by the app
  (flushing(app) / in_flush(app)), not in thread-locals.
- VolumeNode: its own transfer-function writes in progress are the node's (with the writing
  thread), not a thread-local; the first-call log is per node.
- jpeg_codec: jpeg_encoder / jpeg_decoder objects own their TurboJPEG handles (the encode source
  and the stream view's decoder keep theirs) instead of thread-local handles.
- GeometryNode / VolumeNode computed keys, SdlInput's key names, StageLighting's gizmo names: in
  constexpr tables. TouchScroll's ImGui ids are hashed per call. ViewportManager sets VTK's output
  window each time instead of once behind a static flag.

pycvc / pycvc_gl:
- The enum classes, exception types, dsl_error factory and the kept `who` names live on the
  _pycvc module object (found through the interpreter's dict), not in C statics.
- symbol_swig_type / value_swig_type / async_call_to_py use SWIG's own type-table entries.
- The capsule names are constexpr.
- Exec's "a run() is active on this thread" mark and pycvc_gl's deferred rung-style error are kept
  in Python's per-thread state (PyThreadState_GetDict), not in C++ thread-locals.

Tests:
- cvcgl_multi_app (new, headless): a workload of node types, shader presets, mapper settings,
  shadow marks, publisher flushes and JPEG codecs, alone, on threads at once and in reverse order,
  plus a later app starting clean and per-app UI fonts.
- cvcgl_state_publisher: flushing is per app (nested both ways, on threads at once, a later app).
- cvcgl_lowmem_fastdraw: another app keeps its own policy and draw path.
- cvcgl_shadow_casters: a non-caster mark is its app's alone.
- test_pycvc_app.py: two apps' module state (enums, exceptions, dsl_error, kept names, the
  running-Exec mark) alone, in either order and on threads.
- Tests that relied on process-wide registrations now register on their own app.

Allowlist: 103 lines removed (cvcGL 76, pycvc 26, pycvc_gl 1).
@transfix

Copy link
Copy Markdown
Owner Author

Replaced by #1203, which lands the whole no-singletons stack as one PR. This branch's head is an ancestor of #1203's branch, so its commits are all there; the branch is kept.

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