Skip to content

rdna2spirv: translate FLAT loads and stores as global accesses - #9790

Open
tiagonogueiraa-bit wants to merge 2 commits into
ProjectLeonida:mainfrom
tiagonogueiraa-bit:shader-flat-load-store
Open

tiagonogueiraa-bit wants to merge 2 commits into
ProjectLeonida:mainfrom
tiagonogueiraa-bit:shader-flat-load-store

Conversation

@tiagonogueiraa-bit

Copy link
Copy Markdown
Contributor

Resubmission of #8823, unchanged (head fbe718a46). #8823 was closed at 22:39 UTC during the move to ProjectLeonida, with no comment and no triage: line, and the API refuses to reopen it. It had about ten independent passes (CPU and GPU on Linux, Windows and macOS; see #8823's comments). On today's main 2d53a8055 the branch merges without conflicts, and its 12 test_flat_mem tests pass. Originally claimed in #8683: #8683 (comment)

What

flat_load_* and flat_store_* used to reach the translator's final Unsupported(op). tools/isa_coverage.py listed all 54 FLAT opcodes as unknown, and no open PR translates them. Gen.flat_mem now emits the same code as the GLOBAL access with off, through Gen.global_mem / Gen.global_sub. That covers:

  • every dword width (dword, x2, x3, x4);
  • the 8/16-bit loads and stores;
  • the d16 / d16_hi forms.

Inactive lanes don't access memory, as with global_*.

Why global

  • RDNA2 rule: a FLAT address outside the LDS and private apertures reads and writes global memory, and that is the GLOBAL access with off.
  • Aperture addresses: a program reads the aperture bases as src_shared_base / src_private_base. The translator refuses those operands, so a program that builds an aperture address from them is refused as a whole. A test covers this.
  • Unchecked case: an aperture address loaded from memory or a constant would be treated as global memory. I haven't seen one, and the translator can't detect it. The docs/design.md row says so.

Refused (Unsupported)

  • A non-zero instruction offset. Its behaviour on the console GPU isn't measured. LLVM marks GFX10.1 with FeatureFlatSegmentOffsetBug ("inst_offset is ignored when flat instructions access global memory") and folds no offset into a FLAT access there.
  • flat_atomic_*.
  • A 32-bit address.

Also changed

  • First-read analysis (read_before_write_vgprs): it counts the vdst of a FLAT d16 load as read, the same as for global_load_*_d16.
  • Interp copy analysis: it skips flat_store like the other stores.
  • tools/ab_control_flow.py: it lists flat_store among the memory writes the harness can't set up, next to global_store.
  • Contract row: a new "Flat memory" row in docs/design.md.

Tests

tests/semantic/test_flat_mem.py is new. Each program is translated, run with spirv_mini_interp, checked against words worked out by hand, and checked to leave the same memory as its global_* ..., off spelling. It covers:

  • loads and stores of every width;
  • byte offsets 0 to 11, including a 16-bit access that crosses a dword;
  • d16 loads keeping the other half;
  • a non-zero high address dword;
  • 32 lanes with 8 active through v_cmpx;
  • the refused forms (offset, atomics, 32-bit address) and both aperture operands;
  • the first-read analysis.

What I ran, on macOS 26 with an Apple M4 (CPU only) and Python 3.12.13:

  • python -I scripts/run_semantic_tests.py -j 4 tests/semantic: 448 files, 5,969 tests; 446 files pass. The two that fail, test_image_atomics_guard (47) and test_image_store_d16 (1), fail the same way on main 867d922f.
  • tests/test_isa_coverage.py, tests/test_semantic_translator_use.py, tests/test_ab_control_flow.py, tests/test_design_contract_rows.py, tests/test_docs_repo_paths.py: all pass.
  • tests/test_docs_design_rows.py and tests/test_docs_links.py fail the same way on main (on docs/README.md and docs/dev-tools.md, which this PR doesn't touch).
  • scripts/check_no_game_data.py passes on the changed files.

Not GPU-verified. No game files were used.

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

🤖 Generated with Claude Code

tiagonogueiraa-bit and others added 2 commits November 23, 2026 16:32
flat_load_* / flat_store_* with a 64-bit VGPR address emit the global_*
code with `off` (Gen.global_mem / Gen.global_sub). An address outside the
LDS and private apertures is a global access on RDNA2; the aperture bases
(src_shared_base / src_private_base) are refused, so no translated program
builds an aperture address from them. A non-zero instruction offset, the
FLAT atomics and a 32-bit address stay Unsupported. The first-read analysis
counts a FLAT d16 load's vdst, the interp copy analysis and ab_control_flow
treat flat_store like global_store.

CPU-checked by tests/semantic/test_flat_mem.py; contract row in
docs/design.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review on ItsNotRexed#8823 (wavehs): NEEDS listed flat_store but not flat_atomic, which
writes memory as well.

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

Copy link
Copy Markdown

Tested fbe718a46 (base 2d53a8055) on AMD Radeon RX 9060 XT (RDNA4, gfx1200), RADV Mesa 26.3.1, Vulkan 1.4.363, Linux 7.3.5, llvm-mc 23.1.5: pass.

  • tests/semantic/test_flat_mem.py: 33 tests OK. With 2d53a8055's tools/, the same file gives 2 failures and 36 errors, so the FLAT-as-global cases exercise the change.
  • Full translator suite: 448 files, 5,969 tests, 2 files failed (test_image_atomics_guard, test_image_store_d16), the same two red files as on the base here.
  • GPU suite: 224/241 passed, 16 skipped in both native and LEONIDA_W64_EMULATE=1; the one failure in each is the known ms_wave_info_s3 flake.

Exercised on hardware: 55 translated modules differ from the base build (the FLAT rename reaches the buffer/image fixtures) and all pass.

Counts and pass/fail only; no game files. AI-assisted (DeepSeek V4.1 Flash coding agent).

@pablo-biasco-411953

Copy link
Copy Markdown

checked: #9790fbe718a | with: PR diff applied on main 7e39a81, python -m pytest -q tests/semantic/test_flat_mem.py | on: Windows 11, CPython 3.11.9, pytest 9.2.0, CPU only, no game files | result: pass, 12 passed, 37 subtests passed; no new failures against the same tests on main | agent: yes

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