Code Reading Guide - limztudio/NWBLot GitHub Wiki
Code Reading Guide
This order starts at runtime ownership, follows data into the renderer, and enters Vulkan only after the engine-facing contracts are clear.
1. Loader And Project Boundary
Read:
loader/main.cpploader/project_entry.hloader/project_entry.cppglobal/terminal_entry.hcore/common/application_entry.hengine_namespace.hand the engine-domainglobal.humbrellasCoolStuff/Testbed/namespace.hCoolStuff/Testbed/entry.cppCoolStuff/Testbed/project.hCoolStuff/Testbed/runtime.cpp
Root engine_namespace.h owns the engine namespace wrappers; Testbed's independent local namespace header owns its application wrappers. The entry adapter supplies the required NWB loader functions while ordinary application code belongs to Testbed.
These files show crash/log setup, ConfigureProjectRuntime, graphics initialization, cooked-volume mounting through IFilesystem, asset registration, ProjectRuntimeContext, project callbacks, world creation, onUpdate, and shutdown.
2. Frame Ownership
Read:
core/frame/module.hcore/frame/module.cppcore/frame/win32.cppcore/frame/linux.cpp
Follow platform events into the project update callback and registered render passes. The project owns and ticks its ECS world; the frame owns the platform loop, graphics lifetime, the shared CPU and GPU task schedulers, timing, and presentation.
3. CPU And GPU Execution
Read:
core/task/README.mdcore/task/cpu/scheduler.hcore/task/cpu/types.hcore/task/gpu/scheduler.hplusscheduler_compilation.cpp(centralizedscheduleGraphadmission),compiler_internal.h, andpacket_runtime_internal.hdocs/cpu_task_scheduler.md
Frame owns both schedulers. GraphicsRuntime borrows them and attaches the GPU scheduler to the live device. ECS worlds and the loader own CpuTaskScope lifetimes. Tests live under tests/unit/task/cpu (nwb_cpu_task_tests) and tests/unit/task/gpu (nwb_gpu_task_tests).
4. Runtime Assets And Cooked Volumes
Read runtime loading first:
core/assets/manager.*core/assets/registry.*core/assets/ref.hcore/assets/auto_registration.*core/filesystem/filesystem.hcore/filesystem/factory.hcore/filesystem/volume_file_system.h
Then read cook and publication:
pipeline/readme.mdpipeline/launch.pypipeline/command_line.*pipeline/asset_builder/build.cpppipeline/asset_gatherer/gather.cppcore/assets/cook_entry_registry.*core/assets/volume/core/filesystem/volume_build.cppcore/filesystem/volume_staging.cpp
Concrete codecs and cookers live under impl/assets_shader, impl/assets_material, impl/assets_texture, impl/assets_mesh, impl/assets_skeleton, and impl/assets_model.
5. ECS And Project Systems
Read core/ecs/ for entity lifetime, component pools, systems, queries, message buffers, and scheduling. Then follow the content systems under:
impl/ecs_scene/impl/ecs_mesh/(skinning accepted-geometry reuse and current-pose local/optical bounds inskinning/deformation_state.*andskinning/local_bounds.*)impl/ecs_model/impl/ecs_model_renderer/impl/ecs_render/impl/ecs_ui/(input routing contracts inimpl/ecs_ui/toolkit/input/README.md: identified pointer/contact providers, command press-arm/release-submit, bindings, hover, gestures, and popup policy)
6. Renderer Entry And Frame Pipeline
Start with:
impl/ecs_render/module.himpl/ecs_render/module.cppimpl/ecs_render/renderer_frame_pipeline.himpl/ecs_render/renderer_frame_pipeline.cppimpl/ecs_render/renderer_frame_pipeline_resources.cpp(resetFrameTaskStatelives here)impl/ecs_render/renderer_frame_pipeline_graph.cpp(the declaration orchestrator; per-domain task bodies moved toimpl/ecs_render/graph/:frame_graph_avboit_occupancy.*,frame_graph_avboit_extinction.*,frame_graph_avboit_accumulation.*,frame_graph_reflection_resolve.*,frame_graph_software_bvh_build_state.*, andframe_graph_transparent_csg_tasks.*) plus the focused stage builders (impl/ecs_render/deferred/*_builder.*including the deferred frame-tail builder,impl/ecs_render/csg/transparent_csg_interval_builder.*,impl/ecs_render/avboit/clear_chain_builder.*,avboit_pass_upload_helper.*, material/geometry-preparation builders, and compute-emulation capture helper,impl/ecs_render/raytrace/hardware_caustics_stage_builder.*andtask_graph_optical_scene_upload.*), the scheduler-admission unitrenderer_frame_pipeline_graph_schedule.cpp(singlescheduleGraphcall withFrontierSafepacketization), the packet-metrics unitrenderer_frame_pipeline_graph_packet_metrics.cpp, and the execute-sideimpl/ecs_render/execute/frame_execute_lifecycle.*(12 prepare/accept methods) with per-domain merge validators (graphics_prefix_timing_resolver.*,opaque_emulation_merge_validator.*,shadow_prepare_packet_validator.*,shadow_visibility_merge_validator.*,surfel_caustics_merge_validator.*)impl/ecs_render/renderer_frame_pipeline_execute.cppplus the execute-side focused units (impl/ecs_render/execute/frame_execute_cpu_restore.*,frame_execute_history_copy.*, andframe_execute_surfel_readback.*)
RendererSystem is declared in impl/ecs_render/module.h. The frame-pipeline files show validation, immutable frame snapshots, graph declaration, native execution, and accepted-state updates.
Read feature domains next:
impl/ecs_render/material/: material assets, typed bytes, resource resolution, pipelines, and draws (persistent indexed raster and accepted object-space geometry cache inobject_geometry_pass.cpp/task_graph_object_geometry_cache.*)impl/ecs_render/mesh/: mesh resources and compute-emulated/native mesh workimpl/ecs_render/deferred/: G-buffer, lighting, composite, and presentationimpl/ecs_render/csg/: CSG resources and interval workimpl/ecs_render/avboit/: transparency targets and tasks (generated-geometry reuse across compatible passes ingenerated_geometry_reuse.*)impl/ecs_render/raytrace/: shadows, caustics, software BVHs, hardware RT, refraction resolve, and surfel GI (staged hardware transparent shadows inhardware_transparent_shadow.*, per-stage shadow resolve insoft_shadow_resolve_state.h, staged caustic resolve incaustic_resolve_state.h)impl/ecs_render/optics/: coincident refractive-volume resolution shared by render pathsimpl/ecs_render/reflection/: reflection settings, graph domain, postprocess, feedback, history, sampling, and statistics
impl/ecs_render/raytrace/raytracing_system.cpp coordinates ray-effect feature paths (frame CPU-state snapshots live on renderer_raytracing_state.*; shared snapshot/prepared-build ABIs live in raytrace/graph_snapshots.h and raytrace/prepared_builds.h; accepted optical metadata uploads and their residency live in raytrace/optical_scene_upload.* with graph wiring in raytrace/task_graph_optical_scene_upload.*); impl/ecs_render/reflection/reflection_system.cpp and task_graph_reflection.cpp own the reflection domain. Reflection snapshots expose hasHardwareWork() so zero-budget frames declare no hardware consumer. The shared shader-side contracts live beside the compute shaders under impl/assets/graphics/reflection/ and impl/assets/graphics/raytrace/.
7. GPU Task Graph
Read:
core/task/gpu/task_graph.hcore/task/gpu/task_desc.hcore/task/gpu/task_contract.hcore/task/gpu/compiler.cppcore/task/gpu/compiled_graph.hcore/task/gpu/packet_runtime.hcore/task/gpu/packet_runtime_internal.hcore/task/gpu/persistent_state.hcore/task/gpu/timing_feedback.hcore/task/gpu/scheduler.hplusscheduler_compilation.cpp(centralizedscheduleGraphadmission),compiler_internal.h, andpacket_runtime_internal.hcore/graphics/rhi/resource_state_selection.hcore/graphics/gpu_timing.h
Then follow the focused compiler and packet-runtime translation units for queue assignment, resource versions, packetization, recording frontiers, concurrent submission, and rejection. task_contract.h defines the typed payload Record/Accepted/Discarded shape. The GPU timing implementation is split among gpu_timing_accumulator.cpp, gpu_timing_listener.cpp, and gpu_timing_submission.cpp.
Renderer task definitions are named task_graph_*.cpp within their feature domains.
8. Graphics API, Backend Selection, And Vulkan
Read the engine-facing API before backend implementation:
core/graphics/api.hcore/graphics/runtime/runtime.hcore/graphics/backend_contract.hcore/graphics/rhi/core/graphics/backend_selection/configuration.hcore/graphics/backend_selection/backend.hand the narrow selected concern headerscore/graphics/backend_selection.hfor the full context
Consumer code and graphics tests reach public selected backend definitions through these headers; they do not include native Vulkan headers directly. Selection happens at compile time and adds no runtime dispatch. Vulkan is the default and only implemented provider; the future Metal branch is explicitly rejected until implemented. Tests, fixtures, and test-only helpers live under tests/. Graphics tests exercise existing public contracts after normal backend selection; Vulkan-, Metal-, and other provider-specific tests, private provider fixtures, native SDK assertions, and production test hooks are prohibited.
Then enter the current Vulkan provider:
core/graphics/vulkan/backend_context_instance.cppcore/graphics/vulkan/backend_context_adapter.cppcore/graphics/vulkan/backend_context_device.cppcore/graphics/vulkan/backend_context_presentation.cppcore/graphics/vulkan/device.cppcore/graphics/vulkan/device_submission_lifecycle.cppcore/graphics/vulkan/queue_submission.cppcore/graphics/vulkan/tracked_command_buffer.cppcore/graphics/vulkan/swap_chain_presentation.hcore/graphics/vulkan/gpu_descriptor_heap*.cppcore/graphics/vulkan/resource_bindings*.cppcore/graphics/vulkan/command_buffer_resource_references.h
Use Platform and GPU Support while reading adapter admission and Bindless Descriptor Heap while reading binding code. Follow the focused backend context, queue, submission, and command-buffer files before treating device.cpp as the only Vulkan lifetime owner.
9. Materials And Shader ABI
For material cooking, read:
impl/assets_material/material_parse.cppimpl/assets_material/bind_parse.cppimpl/assets_material/bind_typed_layout.cppimpl/assets_material/material_bind_codegen.cppimpl/assets_material/material_generated_shaders.cppimpl/assets_material/material_dispatch_codegen.cppimpl/assets_material/cook.cppimpl/assets_material/runtime.cpp
Read shared CPU/GPU ABI headers and Slang includes together under impl/assets/graphics/. Binding slots, resource layouts, and struct fields must match on both sides.
Project material interfaces, surfaces, and BXDFs are under project asset roots such as CoolStuff/Testbed/assets and tests/smoke/assets.
10. Tests As Contracts
Unit tests exercise concrete edge cases and regressions; routine success checks and source-text wiring assertions fall outside that scope. Integration/smoke suites retain actual CLI and runtime workflows, and standalone benchmark executables remain explicit performance workloads under tests/performance/ and tests/smoke/. .helper/standard.md section 20 defines the scope.
Useful entry points:
tests/unit/task/cpu/: CPU scheduler, scopes, ranges, waits, cancellation, MPMC submission, and profilingtests/unit/task/gpu/: GPU task graph, buffer ranges, packets, and compiler policytests/unit/graphics/: selected public presentation receipts, device-creation and cooperative-vector bounds, resource-sharing input validation, crash markers, and GPU timingtests/unit/ecs_graphics/: executable renderer ownership, stale-generation, aliasing, cancellation, and failure-recovery regressionstests/smoke/REFLECTION.mdandtests/smoke/reflection_smoke.py: reflection capture contracts, routes, filters, and optical fixture checkstests/smoke/renderer_ab_benchmark.pyandtests/integration/renderer_ab_benchmark_tests.py: frozen paired workloads, timing admission, completed-sample normalization, and control-equivalence checkstests/unit/filesystem/:IFilesystemand factory mountstests/integration/pipeline_cli_tests.py: pipeline launcher and tool CLItests/integration/assets_graphics/: material, texture, shader, model, and cook contractstests/smoke/: windowed renderer and capture paths.helper/standard.mdsection 18: source ownership and focused domain boundaries
First Complete Pass
loader/main.cppCoolStuff/Testbed/runtime.cppcore/frame/module.cppcore/assets/manager.cpppipeline/asset_builder/build.cppcore/ecs/world.cppcore/task/cpu/scheduler.himpl/ecs_render/module.himpl/ecs_render/renderer_frame_pipeline.cppcore/task/gpu/compiler.cppcore/graphics/vulkan/device.cpp