runtime: guard align_up_saturating against zero alignment and add unit tests (RT-XS-ALLOC-SIZE-GUARDS-AND-TESTS) #2027

Merged
abnalstlll-byte merged 1 commit from upstream-pr/2027 into main 2026-11-29 18:28:54 +00:00
abnalstlll-byte commented 2026-11-25 18:30:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-25T18:30:04Z.


Claimed in the coordination issue as: RT-XS-ALLOC-SIZE-GUARDS-AND-TESTS (claim)

What and why

  1. Guard align_up_saturating against zero alignment:

    • In runtime/shims/d3d12_xs_alloc_size.h:204, align_up_saturating(value, to) did not guard against to == 0, leading to integer division by zero and underflow in (to - 1).
    • Added if (to == 0) return value; to safely return value unmodified when alignment is 0.
  2. Add comprehensive standalone CPU-only unit test d3d12_xs_alloc_size_test:

    • runtime/shims/d3d12_xs_alloc_size.h computes critical console render target and depth-stencil allocation sizing rules (SW_64KB tile padding, mip tail tile sharing, and multi-slice scaling) but had no direct unit test.
    • Added runtime/test/d3d12_xs_alloc_size_test.cpp exercising:
      • align_up_saturating: zero alignment guard, standard rounding, power-of-two alignments, and saturation without wrapping near UINT64_MAX.
      • render_target_element_bytes: 1, 2, 4, 8, and 16-byte formats, plus 0 for non-RT formats.
      • console_depth_planes: depth/stencil plane separation for D32S8, D24S8, console D16S8 (DXGI 118), D32, D16, and non-depth formats.
      • console_render_target_size: dimension, flag, sample count, format, and extent validation; 1920x1080 4-byte target exact 135-tile computation (8,847,360 bytes); multi-slice arrays and full mip chains.
      • console_depth_stencil_size: plane addition, flags/dimension validation, and sample count checks.
      • console_placement: rejection of null descs and non-targets; placement calculations and offset/size reporting in each array for growing console render targets.
    • Registered d3d12_xs_alloc_size_test and d3d12_xs_alloc_size CTest in runtime/CMakeLists.txt.

Tested

  • Unit test execution: 62/62 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:5496923487 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2027). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-25T18:30:04Z. --- Claimed in the coordination issue as: RT-XS-ALLOC-SIZE-GUARDS-AND-TESTS ([claim](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7170907254)) ### What and why 1. **Guard `align_up_saturating` against zero alignment**: - In `runtime/shims/d3d12_xs_alloc_size.h:204`, `align_up_saturating(value, to)` did not guard against `to == 0`, leading to integer division by zero and underflow in `(to - 1)`. - Added `if (to == 0) return value;` to safely return `value` unmodified when alignment is 0. 2. **Add comprehensive standalone CPU-only unit test `d3d12_xs_alloc_size_test`**: - `runtime/shims/d3d12_xs_alloc_size.h` computes critical console render target and depth-stencil allocation sizing rules (SW_64KB tile padding, mip tail tile sharing, and multi-slice scaling) but had no direct unit test. - Added `runtime/test/d3d12_xs_alloc_size_test.cpp` exercising: - `align_up_saturating`: zero alignment guard, standard rounding, power-of-two alignments, and saturation without wrapping near `UINT64_MAX`. - `render_target_element_bytes`: 1, 2, 4, 8, and 16-byte formats, plus 0 for non-RT formats. - `console_depth_planes`: depth/stencil plane separation for D32S8, D24S8, console D16S8 (DXGI 118), D32, D16, and non-depth formats. - `console_render_target_size`: dimension, flag, sample count, format, and extent validation; 1920x1080 4-byte target exact 135-tile computation (8,847,360 bytes); multi-slice arrays and full mip chains. - `console_depth_stencil_size`: plane addition, flags/dimension validation, and sample count checks. - `console_placement`: rejection of null descs and non-targets; placement calculations and offset/size reporting in `each` array for growing console render targets. - Registered `d3d12_xs_alloc_size_test` and `d3d12_xs_alloc_size` CTest in `runtime/CMakeLists.txt`. ### Tested - Unit test execution: `62/62 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:51:51 +00:00 (Migrated from github.com)

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


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 24549bdb1 + 065df3d8b (claim #2570#issuecomment-7238799031):

  • Line-by-line diff audit: Clean (runtime/CMakeLists.txt, runtime/shims/d3d12_xs_alloc_size.h, runtime/test/d3d12_xs_alloc_size_test.cpp); guards align_up_saturating(value, 0) against division by zero / wraparound and adds a 62-check unit test covering render-target/depth-stencil element sizes, planes, console tile padding, and placement. check_no_game_data.py clean.
  • Red (24549bdb1 + PR test): d3d12_xs_alloc_size_test.exe fails (rc=1, FAIL align_up_saturating with to=0 returns value, 61/62 checks passed).
  • Green (24549bdb1 + 065df3d8b merge): Auto-merges cleanly (rc=0), compiles with 0 warnings in d3d12_xs_alloc_size.h / d3d12_xs_alloc_size_test.cpp, and passes (62/62 checks passed, rc=0).

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238832367 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2027#issuecomment-7238832367). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T11:51:51Z. --- 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` `24549bdb1` + `065df3d8b` (claim `#2570#issuecomment-7238799031`): - **Line-by-line diff audit**: Clean (`runtime/CMakeLists.txt`, `runtime/shims/d3d12_xs_alloc_size.h`, `runtime/test/d3d12_xs_alloc_size_test.cpp`); guards `align_up_saturating(value, 0)` against division by zero / wraparound and adds a 62-check unit test covering render-target/depth-stencil element sizes, planes, console tile padding, and placement. `check_no_game_data.py` clean. - **Red (`24549bdb1` + PR test)**: `d3d12_xs_alloc_size_test.exe` fails (`rc=1`, `FAIL align_up_saturating with to=0 returns value`, `61/62 checks passed`). - **Green (`24549bdb1` + `065df3d8b` merge)**: Auto-merges cleanly (`rc=0`), compiles with `0` warnings in `d3d12_xs_alloc_size.h` / `d3d12_xs_alloc_size_test.cpp`, and passes (`62/62 checks passed`, `rc=0`). AI-assisted.
OreoFR commented 2026-11-28 21:58:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:58:18Z.


Verified by OreoFR

Run 1 (lot 4)

  • Base: main 09c153948 + PR head 065df3d8b; integration package 4 of 6 (2 PRs, merged without conflict)
  • Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; the PRs' Python tests
  • Red on main: n/a (integration test; main baseline: xbox_present and d3d12_set_descriptor_heaps)
  • Green with the PR: ctest: only xbox_present and d3d12_set_descriptor_heaps fail, as on main; the new d3d12_xs_alloc_size test passes
  • Verdict: CLEAN PACKAGE (no new failure vs main)

Run 2 (lot 4 bis)

  • Base: main 33db04a70 + PR head 065df3d8b; integration package of 15 PRs
  • Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; the PRs' Python tests; translator suite
  • Red on main: n/a (integration test; main baseline: xbox_present, and flaky xmem)
  • Green with the PR: ctest: only xbox_present fails as on main (xs_proxy_mock failed once, flaky: passes on rerun and 5/5 direct runs); Python: same failures as main, the PRs' tests pass; translator: 507 files, 6405 tests, 0 failures
  • Verdict: CLEAN PACKAGE (no new failure vs main)

All runs

  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246404244 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2027#issuecomment-7246404244). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:58:18Z. --- **Verified by OreoFR** **Run 1 (lot 4)** - Base: main `09c153948` + PR head `065df3d8b`; integration package 4 of 6 (2 PRs, merged without conflict) - Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; the PRs' Python tests - Red on main: n/a (integration test; main baseline: xbox_present and d3d12_set_descriptor_heaps) - Green with the PR: ctest: only xbox_present and d3d12_set_descriptor_heaps fail, as on main; the new d3d12_xs_alloc_size test passes - Verdict: CLEAN PACKAGE (no new failure vs main) **Run 2 (lot 4 bis)** - Base: main `33db04a70` + PR head `065df3d8b`; integration package of 15 PRs - Test: full runtime build; ctest -j 6 without the 28 tests that launch gta6rt; the PRs' Python tests; translator suite - Red on main: n/a (integration test; main baseline: xbox_present, and flaky xmem) - Green with the PR: ctest: only xbox_present fails as on main (xs_proxy_mock failed once, flaky: passes on rerun and 5/5 direct runs); Python: same failures as main, the PRs' tests pass; translator: 507 files, 6405 tests, 0 failures - Verdict: CLEAN PACKAGE (no new failure vs main) **All runs** - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
OreoFR commented 2026-11-29 12:56:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T12:56:39Z.


TAKEN by OreoFR (Windows, RTX 4070 8 GB)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7256174967 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2027#issuecomment-7256174967). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T12:56:39Z. --- TAKEN by OreoFR (Windows, RTX 4070 8 GB)
OreoFR commented 2026-11-29 15:31:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T15:31:27Z.


Verified by OreoFR — READY

  • Base: main 3535eb5c4 + this PR (head 065df3d8b) merged with --no-ff, no conflict (still none with main c22a0a732). Main has changed runtime/shims/d3d12_xs_alloc_size.h since the earlier runs (console_texture_layout takes the title's layout word, console_placement passes it), so this run checks the PR against that.
  • Red (main + this PR's test file and its CMake registration, test target only): d3d12_xs_alloc_size_test fails, rc=1, FAIL align_up_saturating with to=0 returns value, 61/62 checks.
  • Green (merge): 62/62 checks, rc=0. Full clean build OK.
  • ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded, -j 3): main 503 tests, 3 failures (display_white_cache, xs_proxy_mock, xbox_present); merge 504 tests, 11 failures, all in tests this PR cannot reach (a second agent was loading the CPU, and the run took twice as long, with 4 timeouts). I reran the 11 tests plus display_white_cache and d3d12_xs_alloc_size alone, --repeat until-fail:3. On the merge, 12/12 passed. On main, the 11 that exist there still had 4 failures (big_compile_gate and api_ref_state timed out, xs_proxy_mock and file_system failed). New failures vs main: none.
  • gta6rt.exe links without the XMA decoder (LEONIDA_CARGO=OFF, LEONIDA_XMA2_DECODER_LIB empty); dumpbin /imports identical to main (25 DLLs, no WS2_32).
  • Diff read: no issue. The one-line guard only changes to == 0, which used to divide by zero. Every call in the runtime passes a non-zero alignment, so runtime behaviour is unchanged. The new test uses console_placement through its current signature and builds against main's header.
  • Other runs: consistent with zmasi's red/green and our earlier package runs on this head, against older mains.
  • Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44 (no GPU needed)

AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.

Ready to merge per the maintainers' plan (green, no conflict, tested).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7258157002 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2027#issuecomment-7258157002). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T15:31:27Z. --- **Verified by OreoFR** — READY - Base: main 3535eb5c4 + this PR (head 065df3d8b) merged with --no-ff, no conflict (still none with main c22a0a732). Main has changed `runtime/shims/d3d12_xs_alloc_size.h` since the earlier runs (`console_texture_layout` takes the title's layout word, `console_placement` passes it), so this run checks the PR against that. - Red (main + this PR's test file and its CMake registration, test target only): `d3d12_xs_alloc_size_test` fails, rc=1, `FAIL align_up_saturating with to=0 returns value`, 61/62 checks. - Green (merge): 62/62 checks, rc=0. Full clean build OK. - ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded, -j 3): main 503 tests, 3 failures (display_white_cache, xs_proxy_mock, xbox_present); merge 504 tests, 11 failures, all in tests this PR cannot reach (a second agent was loading the CPU, and the run took twice as long, with 4 timeouts). I reran the 11 tests plus display_white_cache and d3d12_xs_alloc_size alone, `--repeat until-fail:3`. On the merge, 12/12 passed. On main, the 11 that exist there still had 4 failures (big_compile_gate and api_ref_state timed out, xs_proxy_mock and file_system failed). New failures vs main: none. - gta6rt.exe links without the XMA decoder (`LEONIDA_CARGO=OFF`, `LEONIDA_XMA2_DECODER_LIB` empty); `dumpbin /imports` identical to main (25 DLLs, no WS2_32). - Diff read: no issue. The one-line guard only changes `to == 0`, which used to divide by zero. Every call in the runtime passes a non-zero alignment, so runtime behaviour is unchanged. The new test uses `console_placement` through its current signature and builds against main's header. - Other runs: consistent with zmasi's red/green and our earlier package runs on this head, against older mains. - Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44 (no GPU needed) AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR. Ready to merge per the maintainers' plan (green, no conflict, tested).
DadaCap commented 2026-11-29 18:28:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-29T18:28:56Z.


Thank you! Merged into main with a merge commit. It was verified ready on its current head (065df3d8b) by OreoFR's Windows agent (RTX 4070, Windows 11: ctest and the gta6rt link without XMA); see the verification comment above. (AI-assisted, posted for DadaCap.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260517132 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2027#issuecomment-7260517132). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-29T18:28:56Z. --- Thank you! Merged into `main` with a merge commit. It was verified ready on its current head (065df3d8b) by OreoFR's Windows agent (RTX 4070, Windows 11: ctest and the gta6rt link without XMA); see the verification comment above. (AI-assisted, posted for DadaCap.)
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!2027
No description provided.