runtime: guard DescriptorTable 9-way collision, read_slots width, and change-tracking OOM #1739

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

@⁠IlyassRS3 on GitHub · 2026-11-25 10:37 UTC · original
IlyassRS3:fix/descriptor-table-guards → main · +187 −12 · 2 files · 1 commits · open

Item ID: RT-DESCRIPTOR-TABLE-GUARDS
Claim: #1608

Summary

Hardens runtime/src/descriptor_table.h (the bindless set 0, binding 2 T#/S# hash table) against three edge-case bugs:

  1. Unresolvable 9-way full-hash collision checked before load-factor growth (insert_locked()): previously, (occupied_count_ + 1) * 2 > entries_.size() called grow_locked() before checking whether all 8 probe slots already held keys with full hash h. Inserting a 9th colliding key into a 16-slot table needlessly doubled capacity (16 -> 32) and set all_changed_ = true before throwing std::length_error. Checking the 8-slot full-hash collision first refuses immediately without mutating capacity or dirty state.
  2. 64-bit slot offset arithmetic in read_slots(): widened dest + std::size_t(i) * 10 and entries_[std::size_t(first) + i] so large counts cannot wrap 32-bit uint32_t arithmetic.
  3. Strong exception safety for dirty-slot tracking & skip redundant tracking under all_changed_:
    • Previously mark(slot) pushed to changed_slots_ after mutating entries_ and occupied_count_ (and before --occupied_count_ in erase_locked()). A std::bad_alloc inside changed_slots_.push_back left CPU entries mutated (and occupied_count_ stale on erase) while dropping the dirty slot from take_changes(), desynchronizing the GPU descriptor table from the CPU table.
    • reserve_marks(count) now reserves changed_slots_ capacity before mutating entries_/occupied_count_ (and before make_probe_slot() relocates a resident), and both reserve_marks() and mark() are no-ops when all_changed_ is already set (since the next BindlessSet upload writes the full table).

Verification

  • AI-assisted: yes
  • GPUs tested: none (portable CPU-only C++20 header and unit test)
  • Commands run (macOS, Apple Clang, C++20):
    • clang++ -std=c++20 -Wall -Wextra -Werror -O1 -g -fsanitize=undefined runtime/test/descriptor_table_test.cpp -pthread: PASS (0 failures).
    • clang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/descriptor_table_test.cpp -pthread: PASS (0 failures).
    • Mutation test running the updated descriptor_table_test.cpp against unpatched main:runtime/src/descriptor_table.h: FAILS as expected (exit 1 on test_unresolvable_collision_does_not_grow_at_load_threshold).
    • python3 -I scripts/check_no_game_data.py runtime/src/descriptor_table.h runtime/test/descriptor_table_test.cpp: PASS.
    • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.
**@⁠IlyassRS3** on GitHub · 2026-11-25 10:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1739) `IlyassRS3:fix/descriptor-table-guards` → `main` · +187 −12 · 2 files · 1 commits · open Item ID: `RT-DESCRIPTOR-TABLE-GUARDS` Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ## Summary Hardens `runtime/src/descriptor_table.h` (the bindless set 0, binding 2 T#/S# hash table) against three edge-case bugs: 1. **Unresolvable 9-way full-hash collision checked before load-factor growth** (`insert_locked()`): previously, `(occupied_count_ + 1) * 2 > entries_.size()` called `grow_locked()` before checking whether all 8 probe slots already held keys with full hash `h`. Inserting a 9th colliding key into a 16-slot table needlessly doubled capacity (`16 -> 32`) and set `all_changed_ = true` before throwing `std::length_error`. Checking the 8-slot full-hash collision first refuses immediately without mutating capacity or dirty state. 2. **64-bit slot offset arithmetic in `read_slots()`**: widened `dest + std::size_t(i) * 10` and `entries_[std::size_t(first) + i]` so large counts cannot wrap 32-bit `uint32_t` arithmetic. 3. **Strong exception safety for dirty-slot tracking & skip redundant tracking under `all_changed_`**: - Previously `mark(slot)` pushed to `changed_slots_` *after* mutating `entries_` and `occupied_count_` (and before `--occupied_count_` in `erase_locked()`). A `std::bad_alloc` inside `changed_slots_.push_back` left CPU entries mutated (and `occupied_count_` stale on erase) while dropping the dirty slot from `take_changes()`, desynchronizing the GPU descriptor table from the CPU table. - `reserve_marks(count)` now reserves `changed_slots_` capacity before mutating `entries_`/`occupied_count_` (and before `make_probe_slot()` relocates a resident), and both `reserve_marks()` and `mark()` are no-ops when `all_changed_` is already set (since the next `BindlessSet` upload writes the full table). ## Verification - **AI-assisted**: yes - **GPUs tested**: none (portable CPU-only C++20 header and unit test) - **Commands run** (macOS, Apple Clang, C++20): - `clang++ -std=c++20 -Wall -Wextra -Werror -O1 -g -fsanitize=undefined runtime/test/descriptor_table_test.cpp -pthread`: **PASS** (`0 failures`). - `clang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/descriptor_table_test.cpp -pthread`: **PASS** (`0 failures`). - Mutation test running the updated `descriptor_table_test.cpp` against unpatched `main:runtime/src/descriptor_table.h`: **FAILS as expected** (`exit 1` on `test_unresolvable_collision_does_not_grow_at_load_threshold`). - `python3 -I scripts/check_no_game_data.py runtime/src/descriptor_table.h runtime/test/descriptor_table_test.cpp`: **PASS**. - `python3 -I tests/test_text_write_line_endings.py`: **3/3 OK**.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:03:13 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 10:37 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 10:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1739#pullrequestreview-6055994886) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠potatoe0100 on GitHub · 2026-11-25 10:57 UTC · original

Windows/MSVC check: f41be1995 merged onto main bcaa13dad (clean), native Windows 11 Pro 26H2 (build 26300), MSVC 19.44 (VS 2022) RelWithDebInfo + Ninja, NVIDIA GeForce RTX 4060, driver 621.14.

  • Builds cleanly; descriptor_table passes.
  • Full ctest -j 6: 409 of 409 passed, same as main.
  • run_gpu_tests.py: 209/263 passed, 53 skipped, identical to main (the one failure, cs_imgatomic_ext, is on main too).

AI-assisted testing (non-developer tester).

**@⁠potatoe0100** on GitHub · 2026-11-25 10:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1739#issuecomment-7160394543) Windows/MSVC check: `f41be1995` merged onto `main` `bcaa13dad` (clean), native Windows 11 Pro 26H2 (build 26300), MSVC 19.44 (VS 2022) RelWithDebInfo + Ninja, NVIDIA GeForce RTX 4060, driver 621.14. - Builds cleanly; `descriptor_table` passes. - Full `ctest -j 6`: 409 of 409 passed, same as `main`. - `run_gpu_tests.py`: 209/263 passed, 53 skipped, identical to `main` (the one failure, `cs_imgatomic_ext`, is on `main` too). AI-assisted testing (non-developer tester).
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-25 10:58 UTC · original · approved these changes

### Clean-Room & Technical Verification

  • Mergeability: 3-way merge against upstream main (bcaa13dad) is 100% clean with zero merge conflicts.
  • Clean-Room Compliance: 100% clean-room. Descriptor table data structures and unit tests only; zero retail binaries, game data, or keys (check_no_game_data.py clean).
  • Technical Rigor & Edge-Case Hardening:
    • Checks for 9-way unresolvable full-hash collisions before evaluating load-factor growth, preventing spurious table growth (16 -> 32) and unnecessary all_changed_ dirty flags prior to throwing std::length_error.
    • Widens slot offset arithmetic in read_slots() to 64-bit (std::size_t), safeguarding against 32-bit integer overflow.
    • Guarantees strong exception safety in dirty-slot tracking by reserving capacity via reserve_marks() before modifying entries_ or occupied_count_, eliminating CPU/GPU state desynchronization under OOM.
    • Skips redundant individual slot tracking when all_changed_ is already active.
    • Comprehensive unit test coverage added in runtime/test/descriptor_table_test.cpp with OOM fault injection testing.

LGTM! Approved.

**@⁠abnalstlll-byte** on GitHub · 2026-11-25 10:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1739#pullrequestreview-6056317627) · **approved these changes** ### Clean-Room & Technical Verification - **Mergeability**: 3-way merge against upstream `main` (`bcaa13dad`) is 100% clean with zero merge conflicts. - **Clean-Room Compliance**: 100% clean-room. Descriptor table data structures and unit tests only; zero retail binaries, game data, or keys (`check_no_game_data.py` clean). - **Technical Rigor & Edge-Case Hardening**: - Checks for 9-way unresolvable full-hash collisions *before* evaluating load-factor growth, preventing spurious table growth (`16 -> 32`) and unnecessary `all_changed_` dirty flags prior to throwing `std::length_error`. - Widens slot offset arithmetic in `read_slots()` to 64-bit (`std::size_t`), safeguarding against 32-bit integer overflow. - Guarantees strong exception safety in dirty-slot tracking by reserving capacity via `reserve_marks()` before modifying `entries_` or `occupied_count_`, eliminating CPU/GPU state desynchronization under OOM. - Skips redundant individual slot tracking when `all_changed_` is already active. - Comprehensive unit test coverage added in `runtime/test/descriptor_table_test.cpp` with OOM fault injection testing. LGTM! Approved.
This pull request has changes conflicting with the target branch.
  • runtime/src/descriptor_table.h
  • runtime/test/descriptor_table_test.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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