[PR #148] subgroup_size: reject half-zero and invalid subgroup size ranges in decide_subgroup_size #201

Open
opened 2026-11-26 20:17:07 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/148
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9881


📝 Commits (1)

  • 136e1d1 subgroup_size: reject half-zero and invalid subgroup size ranges in decide_subgroup_size

📊 Changes

2 files changed (+75 additions, -4 deletions)

View changed files

📝 runtime/src/subgroup_size.h (+8 -4)
📝 runtime/test/subgroup_size_test.cpp (+67 -0)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/148 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9881` --- ### 📝 Commits (1) - [`136e1d1`](https://github.com/ubiquitarianism/leonida/commit/136e1d101e1802c9298293e36c504ef133b842cd) subgroup_size: reject half-zero and invalid subgroup size ranges in decide_subgroup_size ### 📊 Changes **2 files changed** (+75 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/subgroup_size.h` (+8 -4) 📝 `runtime/test/subgroup_size_test.cpp` (+67 -0) </details> ### 📄 Description > 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#201
No description provided.