test(shader): execute flat and global loads against hardware results #547

Merged
adriadam10 merged 1 commit from upstream-pr/547 into main 2026-10-04 21:24:05 +00:00
adriadam10 commented 2026-10-04 17:10:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T17:10:20Z.


What

Test only, no recompiler change. Adds an execution test for the 8 flat_load_* and 8 global_load_* opcodes (ubyte, sbyte, ushort, sshort, dword, dwordx2, dwordx3, dwordx4). No execution test covered them on main: D16Memory covers only the D16 forms, and the cache-bit forms are in #495. The test found no bug.

It runs two compute shaders on 32 lanes over a guest block. Each lane loads from its own address, and checks 16 result dwords against values measured on hardware. The rows cover:

  • global with an SGPR base (v32, s[8:9]) and with a 64-bit VGPR address (v[34:35], off)
  • global offsets at both ends of the signed 12-bit range (-2048, 2047) and small negative ones (-1, -3, -6)
  • flat offsets up to the 11-bit unsigned maximum (2047)
  • addresses not aligned to the access size (odd ushort, unaligned dword to dwordx4)
  • sign and zero extension of bytes and shorts with the top bit set
  • lanes with EXEC off, which must keep their old VGPR values

Encodings come from llvm-mc -mcpu=gfx1013 -show-encoding.

Behaviour measured on HW

The same two kernels ran on a Radeon 660M (gfx1035, same FLAT encoding as gfx1013). All 64 rows (32 global, 32 flat) match a byte-level model:

  • the address is base + offset, with the global offset sign-extended
  • unaligned accesses read the bytes at that address
  • sbyte/sshort sign-extend, ubyte/ushort zero-extend
  • inactive lanes are not written

The expected values in the test are the hardware outputs.

The HW ran under amdgpu's default unaligned access mode. The test therefore pins unaligned reads as byte-exact, which is what EmitBdaDwordReads already does through its byte path.

Tested

Arch Linux: RADV (Radeon 660M), lavapipe with local Mesa, and lavapipe with CI's version (Ubuntu Mesa 25.2.8). New test agc_driver_flat_global_loads_tests passes on all three.

Negative checks: the test fails if

  • the flat offset loses bit 10
  • the global offset is not sign-extended
  • sbyte/sshort are zero-extended
  • dwordx3 drops its last dword
  • a 64-bit VGPR global address is treated as an SGPR-base offset

Mapping an unaligned span through the aligned dword path is not caught, because RADV and lavapipe both handle a misaligned dword OpLoad.

The test runs wave32 only. Each lane's load depends only on its own address, so wave64 adds no case. On CI's lavapipe the two dispatches take ~70 s with a cold shader cache, which is how CI runs: almost all of it is LLVM compiling the BDA lookups. With a warm cache it takes a few seconds, and under a second on RADV. Wave64 would double the time.

Full Release build (GCC) plus ctest: 183/184. The one failure, agc_driver_pixel_helper_lanes, also fails on main on local RADV since #305.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4736136007 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/547). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T17:10:20Z. --- ### What Test only, no recompiler change. Adds an execution test for the 8 `flat_load_*` and 8 `global_load_*` opcodes (`ubyte`, `sbyte`, `ushort`, `sshort`, `dword`, `dwordx2`, `dwordx3`, `dwordx4`). No execution test covered them on `main`: `D16Memory` covers only the D16 forms, and the cache-bit forms are in #495. The test found no bug. It runs two compute shaders on 32 lanes over a guest block. Each lane loads from its own address, and checks 16 result dwords against values measured on hardware. The rows cover: - global with an SGPR base (`v32, s[8:9]`) and with a 64-bit VGPR address (`v[34:35], off`) - global offsets at both ends of the signed 12-bit range (`-2048`, `2047`) and small negative ones (`-1`, `-3`, `-6`) - flat offsets up to the 11-bit unsigned maximum (`2047`) - addresses not aligned to the access size (odd `ushort`, unaligned `dword` to `dwordx4`) - sign and zero extension of bytes and shorts with the top bit set - lanes with EXEC off, which must keep their old VGPR values Encodings come from `llvm-mc -mcpu=gfx1013 -show-encoding`. ### Behaviour measured on HW The same two kernels ran on a Radeon 660M (gfx1035, same FLAT encoding as gfx1013). All 64 rows (32 global, 32 flat) match a byte-level model: - the address is `base + offset`, with the global offset sign-extended - unaligned accesses read the bytes at that address - `sbyte`/`sshort` sign-extend, `ubyte`/`ushort` zero-extend - inactive lanes are not written The expected values in the test are the hardware outputs. The HW ran under amdgpu's default unaligned access mode. The test therefore pins unaligned reads as byte-exact, which is what `EmitBdaDwordReads` already does through its byte path. ### Tested Arch Linux: RADV (Radeon 660M), lavapipe with local Mesa, and lavapipe with CI's version (Ubuntu Mesa 25.2.8). New test `agc_driver_flat_global_loads_tests` passes on all three. Negative checks: the test fails if - the flat offset loses bit 10 - the global offset is not sign-extended - `sbyte`/`sshort` are zero-extended - `dwordx3` drops its last dword - a 64-bit VGPR global address is treated as an SGPR-base offset Mapping an unaligned span through the aligned dword path is not caught, because RADV and lavapipe both handle a misaligned dword `OpLoad`. The test runs wave32 only. Each lane's load depends only on its own address, so wave64 adds no case. On CI's lavapipe the two dispatches take ~70 s with a cold shader cache, which is how CI runs: almost all of it is LLVM compiling the BDA lookups. With a warm cache it takes a few seconds, and under a second on RADV. Wave64 would double the time. Full Release build (GCC) plus `ctest`: 183/184. The one failure, `agc_driver_pixel_helper_lanes`, also fails on `main` on local RADV since #305. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
oneandonlydean commented 2026-10-04 21:19:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:19:29Z.


Thanks. I checked all 64 rows against a byte-level model of the two kernels (llvm-mc gfx1013 disassembly) and every value matches. The model uses base + offset with the global offset sign-extended, byte-exact unaligned reads, sign extension for sbyte/sshort, and the sentinels kept on EXEC-off lanes. Both the SADDR and the 64-bit VADDR global forms are covered, and the flat offsets go up to 2047.

One note: the test runs with the shader cache off, so on CI's lavapipe it pays the roughly 70 s compile every time. That's fine under the default timeout, so I'm not asking for a change.

Test only, no change to the translation. Ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984496126 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/547#issuecomment-5984496126). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T21:19:29Z. --- Thanks. I checked all 64 rows against a byte-level model of the two kernels (llvm-mc gfx1013 disassembly) and every value matches. The model uses `base + offset` with the global offset sign-extended, byte-exact unaligned reads, sign extension for sbyte/sshort, and the sentinels kept on EXEC-off lanes. Both the SADDR and the 64-bit VADDR global forms are covered, and the flat offsets go up to 2047. One note: the test runs with the shader cache off, so on CI's lavapipe it pays the roughly 70 s compile every time. That's fine under the default timeout, so I'm not asking for a change. Test only, no change to the translation. Ready to merge from my side.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!547
No description provided.