runtime: guard mesh_limit_refusal workgroup invocation product against uint64 overflow (RT-VULKAN-MESH-LIMITS-OVERFLOW) #1991

Closed
IlyassRS3 wants to merge 1 commit from upstream-pr/1991 into main
IlyassRS3 commented 2026-11-25 17:34:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T17:34:47Z.


Item ID: RT-VULKAN-MESH-LIMITS-OVERFLOW (claimed in #1608)

Summary

In mesh_limit_refusal() (runtime/src/vulkan_mesh_limits.h), the workgroup invocation check computed std::uint64_t(n[0]) * n[1] * n[2] > limits.maxMeshWorkGroupInvocations. Because n[0], n[1], and n[2] are 32-bit integers, their 3-way product can exceed 64 bits and wrap around in uint64_t (for example {1<<24, 1<<24, 1<<16} wraps to 0), allowing an oversized mesh workgroup to bypass the maxMeshWorkGroupInvocations refusal check.

  • Replace the 3-way multiplication with an overflow-free check (xy = uint64_t(n[0]) * n[1], then n[2] != 0 && (xy > limit || (xy != 0 && n[2] > limit / xy))), matching the division pattern used in subgroup_workgroup_fits() (runtime/src/subgroup_size.h).
  • Expand runtime/test/vulkan_mesh_limits_test.cpp with exact 3D invocation boundary, 2⁶⁴/2⁶⁶ wrap-around, UINT32_MAX boundary, and zero-limit tests.

Testing & Disclosure

  • AI-assisted: yes
  • GPUs tested: none (macOS host, CPU-only portable unit test)
  • clang++ -std=c++20 -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp: PASS
  • clang++ -std=c++20 -g -O1 -fsanitize=thread -fno-omit-frame-pointer -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp: PASS
  • clang++ -std=c++20 -O2 -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp: PASS
  • python3 -I scripts/check_no_game_data.py runtime/src/vulkan_mesh_limits.h runtime/test/vulkan_mesh_limits_test.cpp: PASS
  • python3 -I tests/test_text_write_line_endings.py: PASS (3/3)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5496119887 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1991). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T17:34:47Z. --- Item ID: `RT-VULKAN-MESH-LIMITS-OVERFLOW` (claimed in #1608) ## Summary In `mesh_limit_refusal()` (`runtime/src/vulkan_mesh_limits.h`), the workgroup invocation check computed `std::uint64_t(n[0]) * n[1] * n[2] > limits.maxMeshWorkGroupInvocations`. Because `n[0]`, `n[1]`, and `n[2]` are 32-bit integers, their 3-way product can exceed 64 bits and wrap around in `uint64_t` (for example `{1<<24, 1<<24, 1<<16}` wraps to `0`), allowing an oversized mesh workgroup to bypass the `maxMeshWorkGroupInvocations` refusal check. - Replace the 3-way multiplication with an overflow-free check (`xy = uint64_t(n[0]) * n[1]`, then `n[2] != 0 && (xy > limit || (xy != 0 && n[2] > limit / xy))`), matching the division pattern used in `subgroup_workgroup_fits()` (`runtime/src/subgroup_size.h`). - Expand `runtime/test/vulkan_mesh_limits_test.cpp` with exact 3D invocation boundary, 2⁶⁴/2⁶⁶ wrap-around, `UINT32_MAX` boundary, and zero-limit tests. ## Testing & Disclosure - AI-assisted: yes - GPUs tested: none (macOS host, CPU-only portable unit test) - `clang++ -std=c++20 -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp`: PASS - `clang++ -std=c++20 -g -O1 -fsanitize=thread -fno-omit-frame-pointer -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp`: PASS - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp`: PASS - `python3 -I scripts/check_no_game_data.py runtime/src/vulkan_mesh_limits.h runtime/test/vulkan_mesh_limits_test.cpp`: PASS - `python3 -I tests/test_text_write_line_endings.py`: PASS (3/3)
copilot-pull-request-reviewer[bot] commented 2026-11-25 17:34:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T17:34:55Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6062158518 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1991#pullrequestreview-6062158518). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T17:34:55Z. **Review:** COMMENTED --- 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.
zmasi commented 2026-11-28 11:58:01 +00:00 (Migrated from github.com)

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


#1991 | head 7bfc32c0a7 (merged cleanly with main 4150b1a1cd) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(vulkan_mesh_limits|d3d12_mesh)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: vulkan_mesh_limits fails (exit 8 at line 89: !mesh_limit_refusal(many, wide).empty() when {1u << 24, 1u << 24, 1u << 16} wraps uint64_t to 0) | green on PR+main: 2/2 CTests pass (vulkan_mesh_limits + d3d12_mesh with 4096/4096 pixels matched) on RTX 3090 with 0 Khronos validation errors; check_no_game_data.py 0 violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238900299 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1991#issuecomment-7238900299). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T11:58:01Z. --- #1991 | head 7bfc32c0a77c94b0350a32461941539e832f378e (merged cleanly with main 4150b1a1cd9de753749e0417ff71a450b6ce92cc) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(vulkan_mesh_limits|d3d12_mesh)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red on main: `vulkan_mesh_limits` fails (exit 8 at `line 89: !mesh_limit_refusal(many, wide).empty()` when `{1u << 24, 1u << 24, 1u << 16}` wraps `uint64_t` to `0`) | green on PR+main: 2/2 CTests pass (`vulkan_mesh_limits` + `d3d12_mesh` with 4096/4096 pixels matched) on RTX 3090 with `0` Khronos validation errors; `check_no_game_data.py` `0` violations | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
enlight3d commented 2026-11-29 15:18:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T15:18:19Z.


RUN #1991 (mesh_limit_refusal workgroup invocation product, uint64 overflow)

  • Heads: PR head 7bfc32c0a77c94b0350a32461941539e832f378e, main bd643e46e784daf6bf3a45d09f0ec20e669c4ddb.
  • Merged locally with main (git merge --no-ff), no conflicts, nothing pushed.
  • Commands:
    • cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON
    • cmake --build runtime/build -j 6 --target vulkan_mesh_limits_test d3d12_mesh_test gta6rt
    • ctest --test-dir runtime/build -C RelWithDebInfo -R "^(vulkan_mesh_limits|d3d12_mesh)$" --output-on-failure -j1 (once as is, once with LEONIDA_VK_VALIDATION=1)
  • Red (behavioural): the PR's vulkan_mesh_limits_test.cpp kept, runtime/src/vulkan_mesh_limits.h reverted to main's version. vulkan_mesh_limits fails with exit 8: line 89: !mesh_limit_refusal(many, wide).empty(). d3d12_mesh (which includes the header) still passes.
  • Green (PR merged into main): 2 of 2 pass (vulkan_mesh_limits is CPU-only; d3d12_mesh ran on the GPU, not skipped), both without and with LEONIDA_VK_VALIDATION=1.
  • Link: gta6rt.exe built from the merged tree has no new imports vs main (693 DLL!symbol entries, identical list, from dumpbin /imports).
  • Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44.
  • Prep notes by TheGeogeo's review session.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7257983194 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1991#issuecomment-7257983194). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T15:18:19Z. --- RUN #1991 (mesh_limit_refusal workgroup invocation product, uint64 overflow) - Heads: PR head `7bfc32c0a77c94b0350a32461941539e832f378e`, main `bd643e46e784daf6bf3a45d09f0ec20e669c4ddb`. - Merged locally with main (`git merge --no-ff`), no conflicts, nothing pushed. - Commands: - `cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON` - `cmake --build runtime/build -j 6 --target vulkan_mesh_limits_test d3d12_mesh_test gta6rt` - `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(vulkan_mesh_limits|d3d12_mesh)$" --output-on-failure -j1` (once as is, once with `LEONIDA_VK_VALIDATION=1`) - Red (behavioural): the PR's `vulkan_mesh_limits_test.cpp` kept, `runtime/src/vulkan_mesh_limits.h` reverted to main's version. `vulkan_mesh_limits` fails with exit 8: `line 89: !mesh_limit_refusal(many, wide).empty()`. `d3d12_mesh` (which includes the header) still passes. - Green (PR merged into main): 2 of 2 pass (`vulkan_mesh_limits` is CPU-only; `d3d12_mesh` ran on the GPU, not skipped), both without and with `LEONIDA_VK_VALIDATION=1`. - Link: gta6rt.exe built from the merged tree has no new imports vs main (693 DLL!symbol entries, identical list, from `dumpbin /imports`). - Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44. - Prep notes by TheGeogeo's review session.
aslan2142 commented 2026-12-01 16:40:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:40:52Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318023364 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1991#issuecomment-7318023364). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:40:52Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

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!1991
No description provided.