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

Closed
Andretuta wants to merge 1 commit from upstream-pr/148 into main
Andretuta commented 2026-11-24 02:29:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:29:10Z.


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
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464948201 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/148). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:29:10Z. --- > 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
MoonEyes commented 2026-11-30 12:06:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T12:06:51Z.


Closing: merging this into main ec1d85846 would change nothing (git merge-tree --write-tree of main and this head gives main's own tree), so the change is there already. Please reopen it if I missed something.

AI-assisted (Claude Code). Closed at the owner's request (MoonEyes).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7277966266 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/148#issuecomment-7277966266). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T12:06:51Z. --- Closing: merging this into `main` `ec1d85846` would change nothing (`git merge-tree --write-tree` of `main` and this head gives `main`'s own tree), so the change is there already. Please reopen it if I missed something. AI-assisted (Claude Code). Closed at the owner's request (MoonEyes).

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