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

Open
opened 2026-11-26 21:19:48 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2027
Author: @abnalstlll-byte
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: feat/rt-xs-alloc-size-guards-and-tests


📝 Commits (1)

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

📊 Changes

3 files changed (+278 additions, -0 deletions)

View changed files

📝 runtime/CMakeLists.txt (+12 -0)
📝 runtime/shims/d3d12_xs_alloc_size.h (+1 -0)
➕ runtime/test/d3d12_xs_alloc_size_test.cpp (+265 -0)

📄 Description

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)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2027 **Author:** [@abnalstlll-byte](https://github.com/abnalstlll-byte) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/rt-xs-alloc-size-guards-and-tests` --- ### 📝 Commits (1) - [`065df3d`](https://github.com/ubiquitarianism/leonida/commit/065df3d8b2468fb27cd4f388232bff19d8803b7d) runtime: guard align_up_saturating against zero alignment and add unit tests (RT-XS-ALLOC-SIZE-GUARDS-AND-TESTS) ### 📊 Changes **3 files changed** (+278 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+12 -0) 📝 `runtime/shims/d3d12_xs_alloc_size.h` (+1 -0) ➕ `runtime/test/d3d12_xs_alloc_size_test.cpp` (+265 -0) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2031
No description provided.