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

Closed
leonida/mandy
quietfold wants to merge 0 commits from fix/rt-vulkan-mesh-limits-overflow into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

quietfold commented 2026-11-25 17:34:47 +00:00

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)
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] reviewed 2026-11-25 17:34:55 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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

#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

#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

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.
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

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.

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.
Sign in to join this conversation.
No description provided.