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

Merged
abnalstlll-byte merged 1 commit from upstream-pr/2057 into main 2026-11-29 01:05:25 +00:00
abnalstlll-byte commented 2026-11-25 19:09:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-25T19:09:57Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5497498652 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2057). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-25T19:09:57Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:35:33Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238653649 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2057#issuecomment-7238653649). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T11:35:33Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T00:45:34Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248331340 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2057#issuecomment-7248331340). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T00:45:34Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T01:05:28Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248552585 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2057#issuecomment-7248552585). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T01:05:28Z. --- 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 reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2057
No description provided.