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

Open
github-bot wants to merge 1 commit from github-bot/gh-2027 into main AGit
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-25 18:30 UTC · original
abnalstlll-byte:feat/rt-xs-alloc-size-guards-and-tests → main · +278 −0 · 3 files · 1 commits · open

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)

**@⁠abnalstlll-byte** on GitHub · 2026-11-25 18:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2027) `abnalstlll-byte:feat/rt-xs-alloc-size-guards-and-tests` → `main` · +278 −0 · 3 files · 1 commits · open Claimed in the coordination issue as: RT-XS-ALLOC-SIZE-GUARDS-AND-TESTS ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608)) ### 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)
Guard align_up_saturating against zero alignment (to == 0) in runtime/shims/d3d12_xs_alloc_size.h, avoiding division by zero and underflow.

Add standalone CPU-only unit test runtime/test/d3d12_xs_alloc_size_test.cpp covering align_up_saturating, render_target_element_bytes, console_depth_planes, console_render_target_size, console_depth_stencil_size, and console_placement.

Register test executable and CTest in runtime/CMakeLists.txt.

AI-assisted (Claude Code)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:15:11 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2027/head:github-bot/gh-2027'
git switch 'github-bot/gh-2027'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2027'
git switch 'github-bot/gh-2027'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2027'
git switch 'github-bot/gh-2027'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2027'
git switch 'main'
git merge --squash 'github-bot/gh-2027'
git switch 'main'
git merge --ff-only 'github-bot/gh-2027'
git switch 'main'
git merge 'github-bot/gh-2027'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.