Skip to content

fix(translator): query image_store bounds from typed views - #5385

Open
Flyander wants to merge 3 commits into
ItsNotRexed:mainfrom
Flyander:codex/fix-image-store-typed-bounds
Open

Flyander wants to merge 3 commits into
ItsNotRexed:mainfrom
Flyander:codex/fix-image-store-typed-bounds

Conversation

@Flyander

@Flyander Flyander commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What changed

The float, unsigned and signed storage images use separate descriptor arrays. The old bounds check always queried the float array before choosing the typed write, so a smaller float fallback could suppress valid integer writes. Each typed branch now queries the dimensions of the same view it writes through.

The change adds translator coverage for 1D, 2D, 2D-array and 3D stores, a Vulkan regression fixture with unequal typed-view extents, and a design-contract update.

Claim: #5256 claim
Depends on: #5250

This branch is based on the current head of #5250 and should merge after that dependency.

Validation

  • python -I tests/semantic/test_image_store_bounds.py -v — PASS, 1 test.
  • python -I tests/test_design_contract_rows.py — PASS, 4 tests.
  • python -I tests/test_docs_design_rows.py — PASS, 4 tests.
  • python -I tests/test_docs_table_rows.py — PASS, 2 tests.
  • python -I -m compileall -q tools tests — PASS.
  • Generated cs_imgstore with runtime/test/shaders/build.py — 1 shader translated; spirv-val passed.
  • Recompiled vk_store_test.cpp and ran cs_imgstore — PASS, zero bad texels in float, uint and sint views.
  • Negative control: the fix(translator): drop image_store writes outside the image (EGEN-IMGSTORE-OOB) #5250 translator at 5dd8051 with the same fixture reported 63 bad texels in each integer view; the regression is detected.
  • GPU used: NVIDIA GeForce RTX 5070 Ti, driver 621.14.
  • Generated 1D, 2D, 2D-array and 3D store modules — all assembled and passed spirv-val.
  • git diff --check — PASS.
  • Broader semantic suite: 6,246 tests ran; the run reported 3 failures, 3 errors, 16 skips and 1 expected failure. The visible failures were wave64 control-flow classification assertions outside this change. One SPIR-V validator test from that run passed when rerun with the locally available SPIR-V tools on PATH.

AI-assisted.

evilclanker9000 and others added 2 commits November 23, 2026 10:47
…TORE-OOB)

RDNA2 (gfx1036, tools/hw_oracle) leaves memory unchanged for an image_store at x/y past the edge, at -1 or at the row pitch. OpImageWrite out of range is undefined in Vulkan, so every write is now behind an unsigned coordinate < OpImageQuerySize test per axis (1D, 2D, 2D array, 3D).
@CharlyRien

Copy link
Copy Markdown

Tested 33c80b5 (merged on main 3faac55, so with #5250 underneath) on RTX 3090 (NVIDIA 616.56, Windows 11 23H2): pass. AI-assisted.

This confirms the fix for the failure I reported on #5250. d3d12_m4_compute, which goes through the D3D12 layer with an R32_UINT RWTexture2D, failed there with image: 255 of 256 words differ. It passes here. run_gpu_tests cs_imgstore, with the new unequal-extent fixture, also passes. Everything else is the same as main on this host (ctest and run_gpu_tests 170/217).

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested 33c80b58 merged onto main 3faac557 on an Apple M4, macOS 27.2.1, MoltenVK 1.4.2 (Vulkan 1.4.357), AppleClang 21.0.0, LLVM 23.1.6. The head includes #5250 (5dd8051c), and the runtime was built from this head. Result: pass. This is also the first Apple run of #5250's change.

cs_imgstore on this head's vk_store_test:

translator float view uint view sint view
this head 0 bad 0 bad (texel(5,3) = 129) 0 bad (-29)
5dd8051c (#5250 alone) 0 bad 63 bad (0) 63 bad (0)
main 0 bad 0 bad 0 bad

So Apple reproduces the #5250 regression @CharlyRien saw on the RTX 3090: the float-view query suppresses valid integer writes. This head fixes it. main passes only because it has no store bounds check yet.

Other runs:

  • tests/semantic/test_image_store_bounds.py: OK on Python 3.15.2 and 3.12.16. With main's or 5dd8051c's translator, all four dims fail, so the test pins the change.
  • Full run_gpu_tests.py: 152/217 passed, 58 skipped, identical per test to main.
  • ctest: 49/50, the same as main. Only vk_overlapping_occlusion fails, a known test bug fixed by Tests: vk_overlapping_occlusion executes only the lists it closed; it failed without pipelineStatisticsQuery (TEST-859, MoltenVK) #3926.
  • Corpus slice (shard 0/64 of the 26k listings from my copy, 415 shaders): 415/415 translate and pass spirv-val on both main and this head. 37 modules change, exactly the 37 that contain OpImageWrite. The other 378 are byte-identical. The changed modules grow by 0.09% in bytes.
  • Docs and CPU checks: the design and docs row tests, compileall and git diff --check are clean.

AI-assisted.

@thehollowedone

Copy link
Copy Markdown

Windows GPU recheck of the revised cs_imgstore fixture at 1b7fc6c4. RTX 3080 Ti / 621.35, Windows 11, MSVC 19.44.35230, Vulkan SDK 1.4.363.0.

The stock fixture had 0/64 mismatches each for float, uint, and sint. Keeping the same harness and fixture and regenerating only the shader with the #5250 translator gave 0/64 float mismatches and 63/64 in each integer view. All stores target valid coordinates in their selected 8×8 views. This confirms the revised 1×1 float mip still catches querying the wrong view. Both modules passed spirv-val, and Vulkan validation reported no errors. Synthetic only. AI-assisted.

@kacper-serewis kacper-serewis 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.

AI-assisted independent review. At 1b7fc6c on Windows RTX 5070 driver 616.56, synthetic RGBA8, R32_UINT and R32_SINT targets of unequal extents preserved all 39 neighboring texels and matched all 33 valid writes. Parent 5dd8051 missed all 24 integer writes. Both modules validated.

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

Reviewed head 1b7fc6c495.

Commands:

  • python tests/semantic/test_image_store_bounds.py -> Ran 1 test, OK; python -I tests/test_semantic_translator_use.py -> OK; git diff --check -> clean.
  • GPU: $env:LLVM_MC='wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc'; $env:LEONIDA_VK_DEVICE='RTX 5070 Ti'; python -I scripts/run_gpu_tests.py --build build --filter cs_imgstore -> PASS (1/1).
  • Control with the dependency's translator 5dd8051cb + this fixture -> FAIL (0/1), so the 1x1 float view in slots 2/3 really catches a bounds query through the wrong class.
  • Control with main's translator -> PASS, expected: main has no store bounds guard at all, so nothing is dropped.

The semantic test shows 3 OpImageWrite and 3 OpImageQuerySize, one per typed view, each write inside its own bounds branch for 1D/2D/2D-array/3D.

Dependency: #5250 is still open and is the first commit here; merge it first or rebase. The CMake-listed GPU fixture is cs_imgstore, which is what I ran.

Verdict: LGTM after #5250.

@Kev-Ball

Copy link
Copy Markdown

Checked the emitted store guards across all 2,449 retail shader listings containing image_store in my Xbox 1.0.2.1 corpus. With wave64 emulation, all 2,449 translated and passed spirv-val. The merged index, module files and input listing set matched exactly. Tested translator 33c80b58; the only file changed through current head 1b7fc6c4 is the C++ GPU fixture.

The corpus exercised 7,611 stores: 6,658 2D, 181 2D-array, 765 3D and seven 1D. Across all 22,833 emitted float/uint/sint write branches, the size query used the exact image SSA value used by the write. In every branch, the conditional entering the write block included an unsigned bounds test for each coordinate axis against the corresponding component of that query. This covers the real 1D and layered cases alongside the unequal-view GPU fixture already reported here. CachyOS Linux, CPU translation and SPIR-V inspection. AI-assisted.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

#5385 (head 1b7fc6c, open)

Tested 1b7fc6c on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

  • python -I -m unittest discover -s tests/semantic -p "test_image_store*.py": 18 tests OK, including the new test_image_store_bounds.py.
  • Built vk_store_test from this head. LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py: 202/217 passed, 15 skipped, 0 failed. cs_imgstore PASS: float view 0 bad, uint view 0 bad (texel (5,3) = 129), sint view 0 bad (texel (5,3) = -29).
  • Negative control on the same new vk_store_test: the translator at 5dd8051 (fix(translator): drop image_store writes outside the image (EGEN-IMGSTORE-OOB) #5250 alone) gives float 0 bad, uint 63 bad, sint 63 bad, all zeros, and cs_imgstore FAILS. With main's translator the test passes (main has no bounds check), so main is not a control for this fixture; 5dd8051 is.
  • Rebuilt d3d12_m4_compute_test at this head and ran it: exit 0, "1924 words matched the CPU reference (error 0)", which includes the R32_UINT storage image.
  • Not done: the corpus count of guards (needs the game files); the whole ctest run.

AI-assisted (Claude Code).

@lunarminus

Copy link
Copy Markdown

Tested 1b7fc6c4 merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • The merge was a fast-forward. d0835dd9 is an ancestor of this branch's base 3faac557, so the tree tested is this head itself: main through 3faac557, plus fix(translator): drop image_store writes outside the image (EGEN-IMGSTORE-OOB) #5250 (5dd8051c), plus this PR.

  • Build: I built the runtime from this head (RelWithDebInfo), so vk_store_test includes this head's revised 1x1 float-view fixture.

  • CPU tests:

    • tests/semantic/test_image_store_bounds.py: 1 test OK.
    • unittest discover -s tests/semantic -p 'test_image_store*.py': 18 tests OK.
    • test_design_contract_rows (4), test_docs_design_rows (4) and test_docs_table_rows (2): all OK.
    • compileall of tools and tests: clean.
  • run_gpu_tests.py, with LEONIDA_W64_EMULATE unset and with it set to 1: 202/217 passed, 15 skipped, 0 failed in each mode.

    • I compared each test with d0835dd9 without the PR (196/210, 14 skipped). The 210 tests in both runs give the same result in both modes.
    • The other 7 come from newer main, not from this PR, and have no baseline here: cs_smem_sconst_off, ps_far_branch, ps_sample_c, ps_sample_c_b, ps_texture_b_cl and ps_texture_cl pass, and ps_m2_literal is skipped.
  • cs_imgstore on this head's vk_store_test, in both modes:

    translator float view uint view sint view result
    this head 0 bad 0 bad, texel(5,3) = 129 0 bad, -29 PASS
    5dd8051c (fix(translator): drop image_store writes outside the image (EGEN-IMGSTORE-OOB) #5250 alone) 0 bad 63 bad, 0 63 bad, 0 FAIL

    This matches the RTX 3080 Ti and RX 9070 XT reports above on this head, and the Apple M4 report on 33c80b58. With d0835dd9's own vk_store_test, all three views have 0 bad texels with either translator. That tree has no store bounds check, so it is not a control for this fixture.

  • Not run:

    • d3d12_m4_compute_test: it is not part of this Linux build.
    • ctest.
    • The corpus guard count, which needs 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.

10 participants