Commit Graph
17 Commits
Author SHA1 Message Date
西风逍遥游 fb42efcc5f fix(thread): close JobSystem releaseDependents use-after-free
ASan (Linux CI) caught a heap-use-after-free in
JobSystemThreadPool::releaseDependents (voxel.world.cross_chunk_seam_culled):
completeJob set completionDone=true and released the mutex, then iterated
job->dependents. A waiter could acquire the mutex in between, see
completionDone, return from wait() and delete the heap job (owned by the
caller), freeing the dependents vector mid-iteration.

Move releaseDependents inside the same critical section and set
completionDone last, so no waiter can observe completion before the
dependents are released. Add a stress regression test that waits on a
completed child and deletes it immediately, 200 iterations.
2026-08-22 12:25:25 +08:00
西风逍遥游 811eff1c3a ci(quality): warnings-as-errors gate, sanitizers, smoke, Python lint/tests
- EVENGINE_ENABLE_STRICT_WARNINGS option: MSVC /W4 /WX, GCC/Clang
  -Wall -Wextra -Werror, with documented noise suppressions and
  -isystem/-external:I for third-party headers; enabled on the
  Windows/Linux debug CI jobs.
- Fix warnings across engine, modules and tests exposed by the gate,
  including real bugs (incomplete-type deletes, Timespan microsecond
  overflow, overload hiding, enum switch gaps, dead code).
- Add Linux ASan+UBSan job, example smoke step, python-tools test
  job, ruff config (scripts+tools), weekly Linux coverage job and a
  CodeQL workflow.
2026-08-22 02:27:37 +08:00
西风逍遥游 c40a60496e fix(thread): JobSystem frame-arena use-after-free under concurrency
Reproduced the intermittent CI segfault (different voxel.render tests each
run, ~1/80 processes under concurrent load) locally and traced it to a null
std::function call in JobSystemThreadPool::fireCompletion.

Root cause: completeJob released dependents (making a parallelFor join
runnable) before the child decremented its own counters and finished
touching its memory. The join could then complete on another thread and,
for heap jobs, be deleted by the caller — freeing the child while its
worker was still inside completeJob's tail; for frame jobs the same gap
let waitFrameJobs observe outstandingFrame == 0 and reset the arena early.
Both paths read freed memory, which manifested as the empty function call.

Fix:
- Add a per-State 'completing' count pinned around the whole completeJob
  tail; waitFrameJobs refuses to reset the arena while it is > 0.
- Mark each job completionDone under the mutex before releasing
  dependents, and waitJob()/isDone() now wait on completionDone rather
  than the status flag, so callers deleting a join never free a child
  still being completed.

Verified: pre-fix build crashed within ~25 rounds of a 4-way concurrent
voxel.render loop; post-fix survived 195 rounds (~780 process runs) with
zero crashes, and the full Linux ctest suite passes 1654/1654.
2026-08-22 00:21:12 +08:00
西风逍遥游 b684bf713d feat(render): move the 3 CSM shadow cascades into the deferred FrameGraph
Stage D (shadow part): each in-flight slot's FrameGraph now owns both the
shadow and G-buffer passes as declarative, dependency-free passes in one
layer. The CSM array is imported per cascade via its layer view with
arrayLayers=3 so barriers cover the whole array; every cascade ends in
DepthStencilReadOnlyOptimal for the engine-side forward pass to sample.

- recordPendingShadowPasses / recordPendingGBufferPass are gone, merged
  into recordDeferredFrameGraph(): graph record + submit before the
  swapchain pass, with a once-per-slot-per-frame guard so repeated
  render3D() calls in one script frame never re-record the same command
  buffers (resetting in-flight CBs hung the driver).
- buildDeferredFrameGraphs() rebuilds one graph per slot from the current
  shadow array + G-buffer targets; shadows can be enabled without a
  G-buffer pass and vice versa (graphs are built on demand).
- JobSystem fix (PR #134 scheduler bug): completeJob now decrements
  outstanding/outstandingFrame only after fireCompletion +
  releaseDependents have finished using the job. Previously a waiter
  (beginFrame/endFrame) could observe outstandingFrame == 0 and reset the
  per-frame arena while a worker still touched the job (use-after-free:
  lost forked job -> hang, or crash). Two stress tests
  (render_graph.jobSystemGroupStress, render_graph.jobSystemEngineFramePattern)
  cover the engine's exact beginFrame/parallel_for/task-group frame
  pattern.
- Recording stays serial (graph->record()) for now: the JobSystem
  help-execution path still has a residual timing-sensitive race that can
  leave a worker stuck in a pass callback. The parallel executor
  (jobSystemPassExecutor) is ready and CPU-tested; enable it once that
  race is root-caused upstream (documented in FrameGraphJobs.h).

Verified locally (win32-debug, full clean rebuild): render_graph.*,
thread.*, Shadow3D.*, RenderSystem3D.*, Lighting3D.*, Mesh.* and
AO/AA/Outline/GI — 77 cases pass.
2026-08-20 23:11:38 +08:00
西风逍遥游 0b04930496 feat(thread): add JobSystem with parallel_for, task_group, dependencies and frame arena
- JobSystem abstraction over the existing ThreadPool worker pool; the
  factory in JobSystem.cpp is the single backend switch point (TBB later).
- Job carries a dependency count and completion callback so a render graph
  can be wired on top without rewriting the scheduler.
- parallel_for(first, last, body, chunk) with static partitioning, auto
  chunk sizing, and a join handle; task_group provides fork/join with
  help-execution so workers can wait without deadlocking.
- Per-frame arena (beginFrame/endFrame) for frame-scoped jobs: no per-frame
  new/delete; frame jobs are recycled by the arena.
- Thread module exposes a shared engine JobSystem (getJobSystem).
- VoxelWorld::remeshDirty now uses parallel_for instead of raw std::thread.
- 24 new zeroerr tests in test/thread.cpp; verified with a standalone MSVC
  harness (24 cases x 30 runs, no flakes).
2026-08-19 22:33:11 +08:00
西风逍遥游 4377e062dd feat: zeroerr parameter validation + Doxygen API documentation
Squashed onto current main. Adds src/engine/common/Assert.h (EV_PARAM_CHECK / EV_ASSERT backed by zeroerr), an EVENGINE_ENABLE_ASSERTS option (non-Debug builds strip ZEROERR_NO_ASSERT unless enabled), parameter checks at key entry points, Doxygen comments across headers, Doxyfile + make docs / CMake docs targets, and Windows setup + code conventions in AGENTS.md.
2026-08-19 09:01:12 +08:00
西风逍遥游 50a230f5a3 Revert "feat: zeroerr parameter validation + Doxygen API documentation (#113)"
This reverts commit 3f3e41990b, reversing
changes made to 7d6375bc95.
2026-08-19 08:36:18 +08:00
西风逍遥游 af0cae4e49 Merge branch 'main' into codex/asserts-and-api-docs
# Conflicts:
#	src/engine/cmdline/cmdline.h
#	src/modules/building/BuildingTypes.h
#	src/modules/building/Ghost.h
#	src/modules/building/JsonHelpers.h
#	src/modules/building/PlacementSystem.h
#	src/modules/building/PlacementWorld.h
#	src/modules/dialogue/Dialogue.h
#	src/modules/filesystem/HotReload.h
#	src/modules/gpgpu/Gpgpu.h
#	src/modules/graphics/Graphics.h
#	src/modules/inventory/JsonHelpers.h
#	src/modules/model3d/ModelData.h
#	src/modules/network/Network.h
#	src/modules/network/TcpSocket.h
#	src/modules/rpg/JsonHelpers.h
#	src/modules/scene/SceneHost.h
#	src/modules/tensor/GpuBackend.h
#	src/modules/tensor/Graph.h
#	src/modules/tensor/Tensor.h
#	src/modules/voxel/Chunk.h
#	src/modules/voxel/GreedyMesher.h
#	src/modules/voxel/VoxelWorld.h
2026-08-19 08:20:18 +08:00
西风逍遥游 228b5a0f15 docs: add Doxygen API comments, docs target, and Windows AGENTS.md
Normalize all header comments to Doxygen @brief form and fill in missing class/method docs across engine common, cmdline, and module headers (~2368 @brief entries). Add root Doxyfile, 'make docs' target, CMake docs target, .gitignore for docs/api, README/docs/dev updates, and a Windows (native) + code-conventions section in AGENTS.md.
2026-08-19 00:13:35 +08:00
Cursor Agentand西风逍遥游 08679654e0 feat(common): add the capability registry, use it for GPU info and main-thread posts
Introduces eve::cap in common/Capability.h: a name-keyed registry where the
consumer owns the interface, the provider registers an implementation, and
neither includes the other. It generalises what common/RenderTrace.h already
does for the render tracer, and supports both a single provider (provide/query)
and many ordered ones (addListener/forEach), keyed by string so a provider
compiled into a plugin lands in the same slot as the host.

Two upward dependencies go away:

  system -> graphics   IGpuInfo. The Vulkan physical-device fields move into
                       graphics/vulkan/GpuInfoProvider.cpp, with a WebGPU
                       counterpart, so System.cpp loses both the graphics
                       include and its EVENGINE_WEBGPU branches.

  thread -> event      IMainThreadPost. postMain and submitPost now enqueue
                       through the capability. The interface makes explicit
                       what was previously only a comment in submitPost: the
                       submitting thread calls prepare() so the worker never
                       reaches the module registry.

Both now report an error when no provider is linked, rather than lazily
creating a module the build may not contain.

Step S3 of docs/dev/模块编排与裁剪架构.md; back-edge whitelist 16 -> 14.

Co-authored-by: 西风逍遥游 <sunxfancy@gmail.com>
2026-08-18 13:46:04 +00:00
西风逍遥游 4842b1e623 Merge remote-tracking branch 'origin/main' 2026-08-15 11:25:08 +08:00
西风逍遥游 0b06713d13 Harden thread pool task lifetime and event wakeups 2026-08-14 22:40:52 +08:00
西风逍遥游 6c73264707 fix(threadpool): enhance thread safety during destruction and stopping
- Updated ThreadPool destructor to handle exceptions during stop() gracefully, ensuring no unhandled exceptions disrupt the program.
- Improved stop() method to detach threads that are currently executing, preventing potential deadlocks when stopping the thread pool.
- Adjusted worker thread joining logic to ensure proper cleanup and resource management.

Additionally, modified occupancy threshold in RenderImageAudit to improve detection of incomplete frames, ensuring better handling of sparse frames.
2026-08-13 10:09:50 +08:00
sunxfancyandCursor d1034c4c2b feat: enhance math and tensor modules with new functionalities and documentation updates
- Updated the math module to include vector and matrix operations, noise generation, Bezier curves, and random number utilities.
- Introduced the tensor module, providing TensorFlow 2-style eager execution and graph building capabilities.
- Enhanced documentation to reflect the new features in the math and tensor modules, including usage examples and API references.
- Modified CMakeLists.txt to include the new math and tensor modules, ensuring proper build configurations.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 15:50:02 +08:00
sunxfancyandCursor 87145e5ce2 feat: enhance system and thread modules with new functionalities and documentation updates
- Added the system module to provide OS, CPU, RAM, wall clock, sleep, clipboard, battery, and GPU information.
- Enhanced the thread module to support thread pools, tasks, and named channels for inter-thread communication.
- Updated documentation to reflect the new features in the system and thread modules, including usage examples and API references.
- Modified CMakeLists.txt to include the new system and thread modules, ensuring proper build configurations.
- Updated load.nut script to initialize the new system and thread functionalities.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 00:06:25 +08:00
sunxfancy 1a8434fb02 update 2024-06-12 14:59:31 -07:00
西风逍遥游 412ec4ddcb update 2022-07-16 22:00:44 -07:00