Skip to content

fix(subgroup_size): guard 64-bit invocation product overflow and zero local_size_x - #1939

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
totonicpu:pr/fix-subgroup-size-overflow
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
totonicpu:pr/fix-subgroup-size-overflow

Conversation

@totonicpu

Copy link
Copy Markdown
Contributor

Summary

Fixes two edge-case bugs in decide_subgroup_size() (runtime/src/subgroup_size.h):

  1. 64-bit multiplication overflow in invocations: std::uint64_t(entry.local_size[0]) * entry.local_size[1] * entry.local_size[2] can wrap modulo 2^64 (e.g. {0x1000000, 0x1000000, 0x10000} wraps to 0), bypassing the maxComputeWorkgroupSubgroups limit (VUID-VkPipelineShaderStageCreateInfo-pNext-02756). Replaced with subgroup_workgroup_fits(), which checks xy <= max_invocations / local_size[2] without overflow.
  2. Zero local_size[0] falsely enabling REQUIRE_FULL_SUBGROUPS_BIT: When a malformed/unknown local_size entry yields entry.local_size[0] == 0, 0 % r.wanted == 0 evaluated true and set VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT. Guarded with entry.local_size[0] != 0.

Regression Test (Fail-First)

Added two cases to runtime/test/subgroup_size_test.cpp:

  • Before fix (Debug): failed on {0x1000000u, 0x1000000u, 0x10000u} (line 176: r.outcome == SubgroupOutcome::device_default && r.size == 0 && r.flags == 0, EXIT=1).
  • After fix (Debug + RelWithDebInfo): subgroup_size and d3d12_vulkan_device (RTX 4070 Ti with LEONIDA_VK_VALIDATION=1) pass 2/2 in both configs with zero warnings and zero Vulkan validation errors.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): no regression from this PR. RTX 4080 SUPER: 111/113 pass. On current main three tests fail the same way on every PR I built, so they're not from this PR: d3d12_draw (bundle blend, bisected to #1660's merge, see #1902), d3d12_compute on both GPUs (line 515: device_proxy_ref_count(device.p) == 1), and d3d12_subgroup on the Intel UHD 770 (line 611: fragment_default). I'm bisecting the last two. Other Intel failures are the known d3d12_present and d3d12_m3_frame.

@ItsNotRexed
ItsNotRexed merged commit 68cee18 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
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.

3 participants