runtime: guard null bind callbacks, add owner accessor and unit test suite for DeferredImageBinding (RT-DEFERRED-IMAGE-BINDING-GUARDS-AND-TESTS) #2057

Merged
leonida/mandy
abnalstlll-byte merged 1 commit from feat/rt-deferred-image-binding-guards-and-tests into main 2026-11-29 01:05:25 +00:00

Pull request successfully merged and closed

abnalstlll-byte commented 2026-11-25 19:09:57 +00:00

Claimed in the coordination issue as: RT-DEFERRED-IMAGE-BINDING-GUARDS-AND-TESTS (claim)

What and why

runtime/src/deferred_image_binding.h synchronizes deferred single-time image memory binding across concurrent calls (e.g. from command replay and descriptor table creation).

  1. Null callback guard:

    • ensure(): guards against null bind_ function pointer (if (!bind_ || !bind_(owner_)) return false;), returning false safely instead of crashing.
  2. Owner query helper:

    • Added owner() accessor returning owner_.
  3. Unit test suite (runtime/test/deferred_image_binding_test.cpp):

    • 28 assertions verifying:
      • Initial state (bound() == false, owner() == target).
      • Null callback handling (returns false, leaves bound() == false).
      • Failed bind retry semantics (retries on failure without latching bound_).
      • Latching on success (bound() == true).
      • Idempotency (subsequent calls return true immediately without re-invoking callback).
      • Null owner pointer handling.
      • Multithreaded race synchronization (16 concurrent threads calling ensure() simultaneously; callback executes exactly once, all threads succeed).
      • Independent instances isolation.

Registers deferred_image_binding_test and CTest in runtime/CMakeLists.txt.

Tested

  • Unit test execution: 28/28 checks passed (0 failures).
  • python -I tests/test_ci_registration.py: 16/16 pass.
  • python -I tests/test_text_write_line_endings.py: 3/3 pass.
  • python -I scripts/check_no_game_data.py: clean (0 violations, no game data).

AI-assisted (Claude Code)

Claimed in the coordination issue as: RT-DEFERRED-IMAGE-BINDING-GUARDS-AND-TESTS ([claim](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7171856623)) ### What and why `runtime/src/deferred_image_binding.h` synchronizes deferred single-time image memory binding across concurrent calls (e.g. from command replay and descriptor table creation). 1. **Null callback guard**: - `ensure()`: guards against null `bind_` function pointer (`if (!bind_ || !bind_(owner_)) return false;`), returning false safely instead of crashing. 2. **Owner query helper**: - Added `owner()` accessor returning `owner_`. 3. **Unit test suite (`runtime/test/deferred_image_binding_test.cpp`)**: - 28 assertions verifying: - Initial state (`bound() == false`, `owner() == target`). - Null callback handling (returns false, leaves `bound() == false`). - Failed bind retry semantics (retries on failure without latching `bound_`). - Latching on success (`bound() == true`). - Idempotency (subsequent calls return true immediately without re-invoking callback). - Null owner pointer handling. - Multithreaded race synchronization (16 concurrent threads calling `ensure()` simultaneously; callback executes exactly once, all threads succeed). - Independent instances isolation. Registers `deferred_image_binding_test` and CTest in `runtime/CMakeLists.txt`. ### Tested - Unit test execution: `28/28 checks passed` (0 failures). - `python -I tests/test_ci_registration.py`: 16/16 pass. - `python -I tests/test_text_write_line_endings.py`: 3/3 pass. - `python -I scripts/check_no_game_data.py`: clean (0 violations, no game data). AI-assisted (Claude Code)
zmasi commented 2026-11-28 11:35:33 +00:00

Verified on Windows 11 (10.0.26200.9974) with MSVC 19.44.35228 (x64, /std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) against main 4a54aedcb + 14e1a352c (claim #2570#issuecomment-7238618828):

  • Line-by-line diff audit: Clean (runtime/CMakeLists.txt, runtime/src/deferred_image_binding.h, runtime/test/deferred_image_binding_test.cpp); guards null bind_ callback in DeferredImageBinding::ensure(), adds owner() accessor, and adds a 28-check unit + 16-thread concurrency test target. check_no_game_data.py clean.
  • Red (4a54aedcb): Calling DeferredImageBinding(&x, nullptr).ensure() on main crashes with 0xc0000005 (STATUS_ACCESS_VIOLATION), and the PR test fails compilation (C2039: 'owner': is not a member of 'leonida::DeferredImageBinding').
  • Green (4a54aedcb + 14e1a352c merge): Auto-merges cleanly (rc=0), compiles with 0 /W4 warnings, and deferred_image_binding_test.exe passes (Summary: 28 checks, 0 failures, rc=0).

AI-assisted.

Verified on Windows 11 (`10.0.26200.9974`) with MSVC `19.44.35228` (`x64`, `/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2`) against `main` `4a54aedcb` + `14e1a352c` (claim `#2570#issuecomment-7238618828`): - **Line-by-line diff audit**: Clean (`runtime/CMakeLists.txt`, `runtime/src/deferred_image_binding.h`, `runtime/test/deferred_image_binding_test.cpp`); guards null `bind_` callback in `DeferredImageBinding::ensure()`, adds `owner()` accessor, and adds a 28-check unit + 16-thread concurrency test target. `check_no_game_data.py` clean. - **Red (`4a54aedcb`)**: Calling `DeferredImageBinding(&x, nullptr).ensure()` on `main` crashes with `0xc0000005` (`STATUS_ACCESS_VIOLATION`), and the PR test fails compilation (`C2039: 'owner': is not a member of 'leonida::DeferredImageBinding'`). - **Green (`4a54aedcb` + `14e1a352c` merge)**: Auto-merges cleanly (`rc=0`), compiles with `0` `/W4` warnings, and `deferred_image_binding_test.exe` passes (`Summary: 28 checks, 0 failures`, `rc=0`). AI-assisted.
enlight3d commented 2026-11-29 00:45:34 +00:00

Run of #2057 (ctest, red/green), by enlight3d. Nothing pushed.

Heads: PR 14e1a352c (base 490f5b9ec, older than main), main 1bc055e6c. git merge-tree --write-tree main <PR head> is clean (no conflicts).
The PR adds runtime/test/deferred_image_binding_test.cpp (28 checks, registered as ctest deferred_image_binding in runtime/CMakeLists.txt) and changes runtime/src/deferred_image_binding.h (a null-callback guard in ensure() and a new owner() accessor). Stdlib only, no GPU used.

Machine: NVIDIA GeForce RTX 3090 24 GB, driver 621.40, Windows 11 Pro (build 10.0.26300), MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo.

Commands (vcvars64 environment, only this target built):

cmake -S runtime -B bld -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
cmake --build bld --target deferred_image_binding_test -j 8
ctest --test-dir bld -R "^deferred_image_binding$" --output-on-failure
  • GREEN (PR head): deferred_image_binding Passed (1/1); the executable prints Summary: 28 checks, 0 failures.
  • RED 1 (PR head with the header taken from main, test kept): does not compile, error C2039: 'owner' is not a member of 'leonida::DeferredImageBinding' (test lines 50 and 94). This one is only "the new member is missing", not behavioural.
  • RED 2 (behavioural: keep owner(), revert only the null-callback guard to if (!bind_(owner_)) return false;): the test builds and ctest reports ***Exception: SegFault, which is the null callback being called.
  • Not exercised: I did not try removing the mutex to see whether the 16-thread case catches it.
    Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.
Run of #2057 (ctest, red/green), by enlight3d. Nothing pushed. Heads: PR `14e1a352c` (base `490f5b9ec`, older than main), main `1bc055e6c`. `git merge-tree --write-tree main <PR head>` is clean (no conflicts). The PR adds `runtime/test/deferred_image_binding_test.cpp` (28 checks, registered as ctest `deferred_image_binding` in `runtime/CMakeLists.txt`) and changes `runtime/src/deferred_image_binding.h` (a null-callback guard in `ensure()` and a new `owner()` accessor). Stdlib only, no GPU used. Machine: NVIDIA GeForce RTX 3090 24 GB, driver 621.40, Windows 11 Pro (build 10.0.26300), MSVC 19.44 (VS 2022 Build Tools), CMake + Ninja, RelWithDebInfo. Commands (vcvars64 environment, only this target built): ``` cmake -S runtime -B bld -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON cmake --build bld --target deferred_image_binding_test -j 8 ctest --test-dir bld -R "^deferred_image_binding$" --output-on-failure ``` - GREEN (PR head): `deferred_image_binding` Passed (1/1); the executable prints `Summary: 28 checks, 0 failures`. - RED 1 (PR head with the header taken from main, test kept): does not compile, `error C2039: 'owner' is not a member of 'leonida::DeferredImageBinding'` (test lines 50 and 94). This one is only "the new member is missing", not behavioural. - RED 2 (behavioural: keep `owner()`, revert only the null-callback guard to `if (!bind_(owner_)) return false;`): the test builds and ctest reports `***Exception: SegFault`, which is the null callback being called. - Not exercised: I did not try removing the mutex to see whether the 16-thread case catches it. Link check: merged into main 1bc055e6c, gta6rt.exe builds and links (RelWithDebInfo, MSVC 19.44); no new imports vs main.
MoonEyes commented 2026-11-29 01:05:28 +00:00

Merged after enlight3d (Thib)'s red/green run (RUN, RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and gta6rt.exe still links) and a re-check here: no conflict with main 818d881b1, same head as run, no-game-data green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on main or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ).

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

Merged after **enlight3d** (Thib)'s red/green run ([RUN](https://github.com/ProjectLeonida/mandy/pull/2057#issuecomment-7248331340), RTX 3090, driver 621.40, Windows 11: green with this PR, red without it, and `gta6rt.exe` still links) and a re-check here: no conflict with `main` 818d881b1, same head as run, `no-game-data` green, and the only ctest failures in the Windows/macOS CI jobs are tests this diff does not touch (known on `main` or Vulkan: vk_xdxr_postbuild_readback vk_bindless_dimensions d3d12_compile_pool xbox_present ). _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No description provided.