subgroup_size: reject half-zero and invalid subgroup size ranges in decide_subgroup_size #148

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

@⁠Andretuta on GitHub · 2026-11-24 02:29 UTC · original
ubiquitarianism:old-pr/9881 → main · +75 −4 · 2 files · 1 commits · draft

Carried over from old PR 9881 by ChalanaGimhanaX in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9881, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
ChalanaGimhanaX: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claimed in the coordination issue as: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116742311

(Resubmission of #9245, which was previously approved by @abnalstlll-byte with 4 additional cross-platform passes on MSVC, Linux GCC, and clang-cl/Wine before being closed during the repo transfer cleanup; cleanly rebased onto ProjectLeonida/Leonida main 7e39a81ea and re-verified.)

Summary

decide_subgroup_size() in runtime/src/subgroup_size.h checks caps.min_size && before treating [min_size, max_size] as device_fixed, but omits a validity check on [min_size, max_size] for requirable and unknown_device:

  1. Half-zero range (min_size == 0, max_size > 0): r.wanted >= caps.min_size && r.wanted <= caps.max_size evaluates 32 >= 0 && 32 <= 64 (and 64 >= 0 && 64 <= 64) as true, returning SubgroupOutcome::required and chaining VkPipelineShaderStageRequiredSubgroupSizeCreateInfo (plus VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT for compute) even though minSubgroupSize was not reported (VUID-VkPipelineShaderStageRequiredSubgroupSizeCreateInfo-requiredSubgroupSize-02761).
  2. Asymmetric unknown_device check: (default_size == 0, min_size == 32, max_size == 0) returns SubgroupOutcome::unknown_device, whereas (default_size == 0, min_size == 0, max_size == 64) bypassed !caps.default_size && !caps.max_size and returned SubgroupOutcome::required.
  3. Non-power-of-two / inverted bounds: VkPhysicalDeviceSubgroupSizeControlProperties requires power-of-two bounds with 1 <= minSubgroupSize <= maxSubgroupSize; malformed bounds such as min_size = 24, max_size = 64 or min_size = max_size = 48 could previously satisfy requirable or device_fixed.

Changes

  • runtime/src/subgroup_size.h:
    • Compute valid_range = subgroup_is_power_of_two(caps.min_size) && subgroup_is_power_of_two(caps.max_size) && caps.min_size <= caps.max_size.
    • Gate unknown_device on !caps.default_size && !valid_range, and require valid_range for both fixed and requirable.
    • Valid power-of-two ranges (including with default_size == 0) behave identically to before; invalid/half-zero ranges with a non-zero default_size cleanly fall back to device_default or unavailable with size == 0 and flags == 0.
  • runtime/test/subgroup_size_test.cpp:
    • Add synthetic unit tests covering half-zero ranges (0..64 with default_size 64, 32, and 0), mirror half-zero (32..0), inverted ranges (64..32), non-power-of-two bounds (24..64, 48..48), and the valid-range default_size == 0 control.

Verification (rebased onto 7e39a81ea)

  • Environment: Windows 11 x64, MSVC 19.50.35721 (VS 18 Community), Windows SDK 10.0.26100.0, pinned Khronos Vulkan-Headers 6802bb47 (SHA256=9044fbb356160e43201dc2094acb44c8a906722a63a35f48fc0f051579db9bb6), CPU only (no GPU, no game files).
  • Negative control (new tests against unmodified main): subgroup_size_test failed at line 218: r.outcome == SubgroupOutcome::device_default && r.size == 0 && r.flags == 0.
  • With fix (rebased on 7e39a81ea):
    • cmake --build runtime/build --config Release --target subgroup_size_test -> clean build.
    • ctest --test-dir runtime/build -C Release -R ^subgroup_size$ --output-on-failure -V -> 1/1 passed (0.04 sec).
    • /std:c++20 /W4 /WX /permissive- /utf-8 -> 0 warnings, 0 errors.
    • python -I scripts/check_no_game_data.py runtime/src/subgroup_size.h runtime/test/subgroup_size_test.cpp -> exit 0.
    • git diff origin/main..HEAD --check -> exit 0; 0 CR (\r) bytes.

Clean-room & disclosure

  • Synthetic inputs only; no game data, keys, decryption, or online endpoints.
  • AI-assisted: yes
**@⁠Andretuta** on GitHub · 2026-11-24 02:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/148) `ubiquitarianism:old-pr/9881` → `main` · +75 −4 · 2 files · 1 commits · draft > Carried over from **old PR 9881** by `ChalanaGimhanaX` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9881`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `ChalanaGimhanaX`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claimed in the coordination issue as: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7116742311 *(Resubmission of `#9245`, which was previously approved by `@abnalstlll-byte` with 4 additional cross-platform passes on MSVC, Linux GCC, and clang-cl/Wine before being closed during the repo transfer cleanup; cleanly rebased onto `ProjectLeonida/Leonida` `main` `7e39a81ea` and re-verified.)* ## Summary `decide_subgroup_size()` in `runtime/src/subgroup_size.h` checks `caps.min_size &&` before treating `[min_size, max_size]` as `device_fixed`, but omits a validity check on `[min_size, max_size]` for `requirable` and `unknown_device`: 1. **Half-zero range (`min_size == 0, max_size > 0`)**: `r.wanted >= caps.min_size && r.wanted <= caps.max_size` evaluates `32 >= 0 && 32 <= 64` (and `64 >= 0 && 64 <= 64`) as `true`, returning `SubgroupOutcome::required` and chaining `VkPipelineShaderStageRequiredSubgroupSizeCreateInfo` (plus `VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT` for compute) even though `minSubgroupSize` was not reported (`VUID-VkPipelineShaderStageRequiredSubgroupSizeCreateInfo-requiredSubgroupSize-02761`). 2. **Asymmetric `unknown_device` check**: `(default_size == 0, min_size == 32, max_size == 0)` returns `SubgroupOutcome::unknown_device`, whereas `(default_size == 0, min_size == 0, max_size == 64)` bypassed `!caps.default_size && !caps.max_size` and returned `SubgroupOutcome::required`. 3. **Non-power-of-two / inverted bounds**: `VkPhysicalDeviceSubgroupSizeControlProperties` requires power-of-two bounds with `1 <= minSubgroupSize <= maxSubgroupSize`; malformed bounds such as `min_size = 24, max_size = 64` or `min_size = max_size = 48` could previously satisfy `requirable` or `device_fixed`. ## Changes - **`runtime/src/subgroup_size.h`**: - Compute `valid_range = subgroup_is_power_of_two(caps.min_size) && subgroup_is_power_of_two(caps.max_size) && caps.min_size <= caps.max_size`. - Gate `unknown_device` on `!caps.default_size && !valid_range`, and require `valid_range` for both `fixed` and `requirable`. - Valid power-of-two ranges (including with `default_size == 0`) behave identically to before; invalid/half-zero ranges with a non-zero `default_size` cleanly fall back to `device_default` or `unavailable` with `size == 0` and `flags == 0`. - **`runtime/test/subgroup_size_test.cpp`**: - Add synthetic unit tests covering half-zero ranges (`0..64` with `default_size` 64, 32, and 0), mirror half-zero (`32..0`), inverted ranges (`64..32`), non-power-of-two bounds (`24..64`, `48..48`), and the valid-range `default_size == 0` control. ## Verification (rebased onto `7e39a81ea`) - **Environment**: Windows 11 x64, MSVC 19.50.35721 (VS 18 Community), Windows SDK 10.0.26100.0, pinned Khronos `Vulkan-Headers` `6802bb47` (`SHA256=9044fbb356160e43201dc2094acb44c8a906722a63a35f48fc0f051579db9bb6`), CPU only (no GPU, no game files). - **Negative control** (new tests against unmodified `main`): `subgroup_size_test` failed at `line 218: r.outcome == SubgroupOutcome::device_default && r.size == 0 && r.flags == 0`. - **With fix (rebased on `7e39a81ea`)**: - `cmake --build runtime/build --config Release --target subgroup_size_test` -> clean build. - `ctest --test-dir runtime/build -C Release -R ^subgroup_size$ --output-on-failure -V` -> **1/1 passed** (`0.04 sec`). - `/std:c++20 /W4 /WX /permissive- /utf-8` -> **0 warnings, 0 errors**. - `python -I scripts/check_no_game_data.py runtime/src/subgroup_size.h runtime/test/subgroup_size_test.cpp` -> exit `0`. - `git diff origin/main..HEAD --check` -> exit `0`; `0` CR (`\r`) bytes. ## Clean-room & disclosure - Synthetic inputs only; no game data, keys, decryption, or online endpoints. - AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:46:25 +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/148/head:github-bot/gh-148'
git switch 'github-bot/gh-148'

Merge

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