Skip to content

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

Closed
ChalanaGimhanaX wants to merge 1 commit into
ProjectLeonida:mainfrom
ChalanaGimhanaX:fix/subgroup-size-zero-min-range
Closed

ChalanaGimhanaX wants to merge 1 commit into
ProjectLeonida:mainfrom
ChalanaGimhanaX:fix/subgroup-size-zero-min-range

Conversation

@ChalanaGimhanaX

Copy link
Copy Markdown

Claimed in the coordination issue as: #9065 (comment)

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.

This is the C++ runtime companion to #9154 (which fixed the same half-zero range gap in tools/wave64_pipeline_audit.py). It is scoped strictly to decide_subgroup_size() with no hunk overlap against #8762 (subgroup_workgroup_fits) or #5282 (subgroup_refused).

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

  • 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 origin/main 867d922):
    • ctest --test-dir runtime/build -C Release -R ^subgroup_size$ --output-on-failure -V -> FAILED at line 218: r.outcome == SubgroupOutcome::device_default && r.size == 0 && r.flags == 0 (returned required with size = 64 and REQUIRE_FULL_SUBGROUPS_BIT for min_size = 0, max_size = 64).
  • After fix:
    • 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 (subgroup size decision: AMD-like, NVIDIA-like, old RADV, limits, create-info chain and query OK).
    • cl /nologo /std:c++20 /W4 /WX /permissive- /utf-8 /EHsc ... /Zs runtime/test/subgroup_size_test.cpp -> 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 --check -> exit 0; 0 CR (\r) bytes in both modified files.

Clean-room & disclosure

  • Synthetic inputs only; no game data, keys, decryption, or online endpoints.
  • AI-assisted: yes

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Windows review (commit 0c2f0a718c41639df9285b6b02635d6de800ef4a)

What changed:

  • runtime/src/subgroup_size.h:
    • decide_subgroup_size() now validates power-of-two subgroup bounds (subgroup_is_power_of_two(caps.min_size) && subgroup_is_power_of_two(caps.max_size) && caps.min_size <= caps.max_size).
    • Rejects half-zero ranges (e.g. min_size == 0, max_size == 64), preventing illegal chaining of VkPipelineShaderStageRequiredSubgroupSizeCreateInfo when minSubgroupSize was not reported (VUID-02761).
    • Handles asymmetric unknown_device conditions and invalid non-power-of-two bounds cleanly.
  • runtime/test/subgroup_size_test.cpp:
    • Comprehensive unit tests covering half-zero, mirror, inverted, and non-power-of-two bounds.

Verification on Windows 11 host with MSVC:

  • Checked compilation with MSVC 19.44: clean build, 0 warnings.
  • Clean diff: pure standard library / C++20, zero game files.

LGTM!

@Grimkaaah Grimkaaah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Linux CPU review

Checked: decide_subgroup_size requires a power-of-two min/max with min<=max before treating the range as valid; half-zero / inverted / non-PoT fall back to default or unknown_device. New cases in subgroup_size_test.cpp. Header-only review — standalone g++ of the test pulls broader runtime headers and did not build in this agent env.

Looks correct from review; no game files.

@smowlyy

smowlyy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Verified on native Windows 11 (10.0.26300.9974, MSVC 19.44, RelWithDebInfo), PR head 0c2f0a718 merged onto main (6312c057f):

  • python -I scripts/check_no_game_data.py runtime/src/subgroup_size.h runtime/test/subgroup_size_test.cpp: clean (exit 0).
  • cmake --build runtime/build --target subgroup_size_test --parallel: built cleanly.
  • ctest --test-dir runtime/build -R ^subgroup_size --output-on-failure -V: 1/1 passed (subgroup size decision: AMD-like, NVIDIA-like, old RADV, limits, create-info chain and query OK).

AI-assisted.

@GeremC

GeremC commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 0c2f0a7 (already contains main 867d922) under Wine: pass

On: Linux, Ubuntu 24.04, cross-built with clang-cl 19.1.1 + xwin SDK (RelWithDebInfo), run by ctest through Wine 9.0; CPU only, no game files.

  • ctest -R ^subgroup_size$: passed.
  • Negative control, runtime/src/subgroup_size.h from main with the PR's test kept: subgroup_size fails.

AI-assisted (Claude Code).

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 0c2f0a71 on Linux, GCC, CPU only (no GPU, no Windows API), merged onto main 6312c057: pass

  • Built only the subgroup_size test target from the merged tree and ran it through CTest: 100% tests passed out of 1.
  • With the PR's runtime/src files reverted to main and rebuilt: 0% tests passed, 1 tests failed out of 1a failing check at :218 r.outcome == SubgroupOutcome::device_default && r.size == 0 && r.flags == 0.

So the new test depends on the change.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) with the agent's recheck.sh before posting.

@sayak-brm sayak-brm left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the full diff and all of subgroup_size.h on main, and checked the other users of SubgroupSizeCaps (d3d12_vulkan_device.cpp, d3d12_subgroup_test.cpp, vk_pipeline_check.cpp, vk_test_device.h). I found no problems.

The valid_range logic matches the description: min/max both 0 (feature not reported) behaves as before, valid power-of-two ranges behave as before, and half-zero, inverted or non-power-of-two bounds no longer reach required or device_fixed. I traced each new CHECK in the test by hand against the new code and every expected outcome matches.

Ran on Windows (merged onto a recent main): a clean build of the Vulkan runtime on an RTX 3090 succeeds and ctest -R ^subgroup_size$ passes. check_no_game_data.py on both files exits 0, git diff --check is clean, no CR bytes. I did not run the negative control from the description (the test against the old subgroup_size.h), so that part is not reproduced by me.

Two small notes, neither blocking: the comment above decide_subgroup_size still describes only "a power of two in [min, max]" for the wanted size, and the odd entry in the malformed-range block is reused in the control section. Also, with #5282 merged, a malformed-range device with default_size 32 would turn a wave64 shader into unavailable and so be refused, which looks right.

Review prepared with Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants