Skip to content

cs_pk_mul_lo_const: keep lanes 0..15 inside vk_compute_test's 256-byte buffer (GPU-AV: 6 out-of-bounds writes) - #7965

Open
marso006 wants to merge 1 commit into
ItsNotRexed:mainfrom
marso006:fix/pk-mul-lo-const-oob
Open

marso006 wants to merge 1 commit into
ItsNotRexed:mainfrom
marso006:fix/pk-mul-lo-const-oob

Conversation

@marso006

Copy link
Copy Markdown

Claim: #7804 (comment) (no item ID yet).

What and why

runtime/test/shaders/cs_pk_mul_lo_const.asm (from #6836) has every lane load and store 16 bytes at lane * 16, so its 32 lanes cover 512 B. vk_compute_test gives a one-group dispatch groups * 64 words, i.e. 256 B (runtime/test/vk_compute_test.cpp, "Output buffer = heap"). Lanes 16..31 therefore read and wrote past the end of the buffer through its device address.

The test still passed because the dump only checks out[0..7], lanes 0 and 1. Under GPU-assisted validation it fails:

LEONIDA_VK_VALIDATION=1 VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 python -I scripts/run_gpu_tests.py --filter cs_pk_mul
validation: vkCmdDispatch(): Out of bounds: trying to write 4 bytes at [...] but this range does not belong to any buffer.   (x6)
6 validation errors
  FAIL  cs_pk_mul_lo_const

It is the only compute fixture that stores 16 bytes per lane from every lane without first masking EXEC to the lanes it checks (the 4-word LDS fixtures, for example, use v_cmpx_eq_u32 0, v0 first).

Change

  • v_cmpx_gt_u32_e32 16, v20 right after the lane index is taken, so lanes 0..15 run (16 * 16 B = the 256 B buffer). The packed multiplies are per-lane, so nothing the test measures changes, and the expected words (PK_MUL_LO_WORDS) stay the same. The header explains why.
  • tests/semantic/fixtures/disasm/cs_pk_mul_lo_const.s regenerated with tests/semantic/regen_fixtures.py (--check is clean).

No docs change, no game files.

Tested

Windows 11, NVIDIA GeForce RTX 5060 Ti (Blackwell, subgroup 32), driver 617.42, Vulkan SDK 1.4.363.0, runtime built from main with scripts/build_runtime.ps1 (VS 2026), llvm-mc 23.1.6 (conda-forge llvm-tools):

main dde82f27e this branch
run_gpu_tests.py --filter cs_pk_mul PASS PASS (same 8 words)
same, with LEONIDA_VK_VALIDATION=1 VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 FAIL, 6 OOB writes PASS, 0 validation errors
  • python -m unittest discover -s tests/semantic -p test_pk_mul_lo_const.py: OK
  • python -m unittest discover -s tests/semantic -p test_fixtures.py, python -I tests/test_regen_fixtures.py, python -I tests/semantic/regen_fixtures.py --check: OK
  • python -I scripts/run_semantic_tests.py tests/semantic: 5956 tests; the same 2 files fail with and without this change (test_image_atomics_guard, test_image_store_d16), unrelated.
  • python -I tests/test_shader_checks.py: the same 15 errors with and without this change (the table_fetch_test harness issue that tests/test_shader_checks: stub table_fetch_test in the Wave64Checks harness (15 errors on main) #7433 fixes).

AI-assisted (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code

…e buffer

Every lane loaded and stored 16 bytes at lane * 16, so 32 lanes covered 512 B,
but vk_compute_test gives one group 64 words (256 B). Lanes 16..31 read and
wrote past the buffer through its device address: GPU-AV reports 6
out-of-bounds writes and the test fails under validation. The dump checks only
lanes 0 and 1, so the test passed without it.

v_cmpx_gt_u32 16, v20 keeps lanes 0..15 before the first load; the expected
words are unchanged. The translator fixture is regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Joaco9020

Copy link
Copy Markdown

Tested 507d9e2eb on NVIDIA GeForce RTX 3070 (Ampere), driver 621.01, Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.1 (its Khronos validation layer), llvm-mc 23.1.6: pass, with the before/after under GPU-AV.

LEONIDA_VK_VALIDATION=1 VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 python -I scripts/run_gpu_tests.py --filter cs_pk_mul_lo_const:

fixture result words
HEAD~1 (.asm + .s from before this PR) FAIL 0/1 0x9e88 0x3675433 0x230000 0x77f6c ×2
this PR PASS 1/1 same eight words

The words are identical, so the old failure is the validation error alone, as described. Without validation the PR's fixture passes too. Synthetic fixture only, no game files. AI-assisted (Claude).

@kamilolejnik

Copy link
Copy Markdown

Tested 507d9e2 on Intel Iris Xe Graphics (TGL GT2, Xe-LP, subgroup 8..32), Mesa ANV 26.3.1, Vulkan 1.4.363, Khronos validation layers (Arch vulkan-validation-layers), Linux 6.12 (Arch container on Debian 13), llvm-mc 23.1.5: pass. The first non-NVIDIA run. Programs built once from the merge-base dde82f27e.

run_gpu_tests.py --filter cs_pk_mul merge-base this PR
plain PASS (0x9e88 0x3675433 0x230000 0x77f6c ×2) PASS (same 8 words)
LEONIDA_VK_VALIDATION=1 VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1 FAIL PASS

Running vk_compute_test on the same module under GPU-AV shows why the merge-base fails here too. There are 6 errors, each an OpStore through a PhysicalStorageBuffer pointer outside any buffer ("Nearest below committed device address range is [0x742000000, 0x742000100)", the 256-byte output buffer), and the exit status is 1. On this branch there are no errors and the exit status is 0. So the six out-of-bounds lane stores show up the same way on ANV, and the v_cmpx_gt_u32 16 fix removes them.

Synthetic fixtures only, no game files. AI-assisted (Claude Code).

@Cryptoteep Cryptoteep 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.

Tested 507d9e2 on NVIDIA GeForce RTX 5060 (driver 616.56, Windows 11): pass.

  • python -m unittest discover -s tests/semantic -p test_pk_mul_lo_const.py: OK (1/1).
  • python -I tests/semantic/regen_fixtures.py --check: clean (0 differences).
  • python -I scripts/check_no_game_data.py runtime/test/shaders/cs_pk_mul_lo_const.asm tests/semantic/fixtures/disasm/cs_pk_mul_lo_const.s: pass.

The v_cmpx_gt_u32_e32 16, v20 properly bounds active lanes to 0..15, restricting total stores to 256 bytes and eliminating the buffer overrun. Code looks good.

@tiagonogueiraa-bit

Copy link
Copy Markdown

Tested 507d9e2 (PR head; it fast-forwards from main dde82f2, no conflicts) on Apple M4 (10-core GPU, MacBook Air), MoltenVK 1.4.2 and KosmicKrisp (Mesa 26.3.1), macOS 27.2.1: pass. GPU-AV was not available here: the Khronos validation layer is not installed, only the Mesa layers. Instead, a larger buffer shows the out-of-bounds stores directly.

PR-specific:

  • cs_pk_mul_lo_const, 3 direct runs per driver of vk_compute_test cs_pk_mul_lo_const.spv 1 dump (subgroup 32). Main's module and this PR's both give 0x9e88 0x3675433 0x230000 0x77f6c ×2, 0 mismatches, on MoltenVK and on KosmicKrisp. Both runners pass it on both sides.

  • The stores past the buffer, without GPU-AV. The same dispatch with VKC_OUT_WORDS=128 VKC_DUMP=<file> (a 512 B buffer filled with 0xeeeeeeee, read back whole):

    module words 0..63 (the default 256 B buffer) words 64..127
    main dde82f2 all 64 written all 64 written: lanes 16..31 store the same four words (0x9e88 0x3675433 0x230000 0x77f6c) at bytes 256..511
    this PR all 64 written (lanes 0..15) all 64 still 0xeeeeeeee

    The two drivers give the same result. In the default 64-word buffer, main's lanes 16..31 therefore address bytes 256..511, past the end. The PR's v_cmpx_gt_u32 16, v20 stops them, and the eight dumped words are unchanged. This agrees with the earlier GPU-AV before/after on an RTX 3070.

  • CPU: regen_fixtures.py --check clean. test_pk_mul_lo_const passes. tests/test_shader_checks.py gives 84 tests with the same 15 cwd errors as main.

Against main dde82f2 (full suite, fresh RelWithDebInfo build, 0 warnings on both). Every test gives the same result as on main, with the same failure details:

  • ctest (MoltenVK): 62 passed, 2 skipped, 0 failed.
  • run_gpu_tests.py: MoltenVK 179/241 passed, 60 skipped (known cs_fma_fused, ps_ssharp). KosmicKrisp 174/241 passed, 63 skipped (known cs_bvh, cs_bvh32, ps_cndmask_sign_mods, ps_valu16_mad_sel).
  • check.py: MoltenVK 170 of 211 pass, 39 skipped. KosmicKrisp 163 of 211 pass, 43 skipped.
  • build.py: 269 / 270 translated, all pass spirv-val.

Synthetic fixtures only, no game files.

AI-assisted (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.

5 participants