feat(shader): translate the 64-bit and f32/f64 min/max DS src2 forms #5474

Closed
billythemenace2 wants to merge 1 commit from upstream-pr/5474 into main
billythemenace2 commented 2026-10-13 20:44:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-13T20:44:22Z.


What

Before: the GFX10.1-only ds_*_src2_* 64-bit forms (ds_{add,sub,rsub,inc,dec}_src2_u64, ds_{min,max}_src2_{i64,u64}, ds_{and,or,xor}_src2_b64, ds_write_src2_b64, ds_{min,max}_src2_f64) were not decoded and threw "DS opcode is not supported". ds_min_src2_f32 and ds_max_src2_f32 threw because the f32 denormal mode was not modelled.

After: all of these are translated. ds_add_src2_f32 still throws, with a message that names the actual gap.

  • 64-bit forms: they read DS[B] with the same dword offset as the 32-bit forms (B = A + 4 * sext(offset1[6:0]:offset0)) and update DS[A] with the matching 64-bit LDS atomic, or a 64-bit write. A B that is not 8-byte aligned reads as 0, and an A that is not 8-byte aligned writes nothing.
  • Float min/max forms: they use the existing LDS float atomics, which already model the measured flush and NaN rule, with DS[B] as the data operand.

Hardware semantics, measured on RDNA1 (gfx1010, AMD Radeon RX 5700 XT), which has the src2 opcodes. The kernels used the tools/hw-oracle template, assembled with the Windows driver's amd_comgr_2.dll and launched with its HIP runtime. One wave32 workgroup filled 2 KiB of LDS, ran the instruction on the selected lanes, and dumped the LDS.

  • 32-bit integer forms: all 13 ops in 78 single-lane cases equal DS[A] = op(DS[A], DS[B]) with the offset above. This confirms the existing translation.
  • 64-bit integer forms: all 13 ops in 624 cases (random, equal and adjacent operands) equal the 64-bit op. An offset of +2 or -4 dwords reads A+8 or A-16, so the scale is 4, not 8. An odd dword offset reads B as 0. An A of 404 (4 mod 8) writes nothing.
  • Float forms: every ds_{min,max}_src2_{f32,f64} equals plain ds_{min,max}_{f32,f64} with DS[B] as data. That holds on all 196 operand pairs (zeros, denormals, ±1, infinities, quiet and signalling NaNs with payloads, max normal) in IEEE 0 and 1 with denormals flushed and kept: 1,568 rows. The plain f32 and f64 results also match the existing "LDS float atomics" debt entry, which was measured on RDNA2, on every row.
  • ds_add_src2_f32: it equals ds_add_f32 on all 784 rows. That instruction flushes both operands when the f32 denormal field flushes, which the translation does not model yet, so the src2 form keeps throwing.

The measurement write-up is attached.
measurement-results-ds-src2-gfx1010.md

Known gap, recorded in technical debt and not changed here: on hardware, the active lanes run in lane order, and a lane's read of B sees the writes of lower lanes. The translation reads B for every lane first, for the 32-bit forms too.

Tested

  • Windows 11, AMD Radeon RX 5700 XT, Adrenalin 32.0.21045.5002, MinGW GCC 15.2.0. The full build is clean.
  • New test agc_driver_lds_src2_wide covers the 15 64-bit forms and the f32 min/max forms on 32 lanes (integer edge cases, f64 and f32 specials), plus a misaligned B and a misaligned A. Before adding the expected values to the test, I ran the same kernel on the RX 5700 XT through the oracle and checked them against it: 0 mismatches. The test passes.
  • agc_driver_lds_src2 is updated: it now expects only ds_add_src2_f32 to be refused, and it passes.
  • ctest -R "lds_|shader_memory|decoder": everything passes except agc_driver_lds_mixed_width_atomics, which also fails on unchanged main (dacd78525) on this machine.
  • python3 tools/check_conventions.py --base origin/main passes.

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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 5700 XT (gfx1010), Adrenalin 32.0.21045.5002, Windows 11
  • AI-assisted: yes. Claude wrote the change, the test and the measurement kernels; I reviewed it and ran the measurements and tests on my machine.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4849240458 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5474). Originally posted by [billythemenace2](https://github.com/billythemenace2) on 2026-10-13T20:44:22Z. --- ### What Before: the GFX10.1-only `ds_*_src2_*` 64-bit forms (`ds_{add,sub,rsub,inc,dec}_src2_u64`, `ds_{min,max}_src2_{i64,u64}`, `ds_{and,or,xor}_src2_b64`, `ds_write_src2_b64`, `ds_{min,max}_src2_f64`) were not decoded and threw "DS opcode is not supported". `ds_min_src2_f32` and `ds_max_src2_f32` threw because the f32 denormal mode was not modelled. After: all of these are translated. `ds_add_src2_f32` still throws, with a message that names the actual gap. - **64-bit forms:** they read `DS[B]` with the same dword offset as the 32-bit forms (`B = A + 4 * sext(offset1[6:0]:offset0)`) and update `DS[A]` with the matching 64-bit LDS atomic, or a 64-bit write. A `B` that is not 8-byte aligned reads as 0, and an `A` that is not 8-byte aligned writes nothing. - **Float min/max forms:** they use the existing LDS float atomics, which already model the measured flush and NaN rule, with `DS[B]` as the data operand. Hardware semantics, measured on RDNA1 (gfx1010, AMD Radeon RX 5700 XT), which has the src2 opcodes. The kernels used the `tools/hw-oracle` template, assembled with the Windows driver's `amd_comgr_2.dll` and launched with its HIP runtime. One wave32 workgroup filled 2 KiB of LDS, ran the instruction on the selected lanes, and dumped the LDS. - **32-bit integer forms:** all 13 ops in 78 single-lane cases equal `DS[A] = op(DS[A], DS[B])` with the offset above. This confirms the existing translation. - **64-bit integer forms:** all 13 ops in 624 cases (random, equal and adjacent operands) equal the 64-bit op. An offset of +2 or -4 dwords reads A+8 or A-16, so the scale is 4, not 8. An odd dword offset reads `B` as 0. An `A` of 404 (4 mod 8) writes nothing. - **Float forms:** every `ds_{min,max}_src2_{f32,f64}` equals plain `ds_{min,max}_{f32,f64}` with `DS[B]` as data. That holds on all 196 operand pairs (zeros, denormals, ±1, infinities, quiet and signalling NaNs with payloads, max normal) in IEEE 0 and 1 with denormals flushed and kept: 1,568 rows. The plain f32 and f64 results also match the existing "LDS float atomics" debt entry, which was measured on RDNA2, on every row. - **`ds_add_src2_f32`:** it equals `ds_add_f32` on all 784 rows. That instruction flushes both operands when the f32 denormal field flushes, which the translation does not model yet, so the src2 form keeps throwing. The measurement write-up is attached. [measurement-results-ds-src2-gfx1010.md](https://github.com/user-attachments/files/33405724/measurement-results-ds-src2-gfx1010.md) Known gap, recorded in technical debt and not changed here: on hardware, the active lanes run in lane order, and a lane's read of `B` sees the writes of lower lanes. The translation reads `B` for every lane first, for the 32-bit forms too. ### Tested - Windows 11, AMD Radeon RX 5700 XT, Adrenalin 32.0.21045.5002, MinGW GCC 15.2.0. The full build is clean. - New test `agc_driver_lds_src2_wide` covers the 15 64-bit forms and the f32 min/max forms on 32 lanes (integer edge cases, f64 and f32 specials), plus a misaligned `B` and a misaligned `A`. Before adding the expected values to the test, I ran the same kernel on the RX 5700 XT through the oracle and checked them against it: 0 mismatches. The test passes. - `agc_driver_lds_src2` is updated: it now expects only `ds_add_src2_f32` to be refused, and it passes. - `ctest -R "lds_|shader_memory|decoder"`: everything passes except `agc_driver_lds_mixed_width_atomics`, which also fails on unchanged `main` (dacd78525) on this machine. - `python3 tools/check_conventions.py --base origin/main` passes. ### Checklist - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Unblocks: none - [x] GPUs tested: AMD Radeon RX 5700 XT (gfx1010), Adrenalin 32.0.21045.5002, Windows 11 - [x] AI-assisted: yes. Claude wrote the change, the test and the measurement kernels; I reviewed it and ran the measurements and tests on my machine.
github-actions[bot] commented 2026-10-13 21:29:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T21:29:02Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4706 docs/dev/debt/shader.md L106-107
#5176 docs/dev/debt/shader.md L106
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6155594076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5474#issuecomment-6155594076). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T21:29:02Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4706 | `docs/dev/debt/shader.md` [L106-107](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/docs/dev/debt/shader.md#L106-L107) | | | | #5176 | `docs/dev/debt/shader.md` [L106](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/docs/dev/debt/shader.md#L106) | | |
xXPBSXx commented 2026-10-14 00:37:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T00:37:58Z.


Windows test of #5474: Windows 10 (19045), MinGW-w64 GCC 15.2, Release, ninja -j 4, ctest called directly, GPU selected by the execution tests: NVIDIA GeForce RTX 4080 SUPER (Selected GPU log line; an AMD Radeon RX 6400 is present and was not selected). Tree: main feddf7f4c + merge of PR head b6ecd7527e8150290139f30f42f49728f56efebc (local merge ecde0711f).
agc_driver_lds_src2 and agc_driver_lds_src2_wide: exit code 0 in 3 of 3 runs each (6 of 6). Logs: rtx5474_*_N.log.
Not tested: that the new/changed test fails without the change (no baseline run for this PR), the AMD GPU, other ctest targets, Linux, a title run. (For comparison, the same-named tests with the head of #5498 crashed in the NVIDIA driver in 9 of 9 runs; see the separate report on #5498.)

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158230318 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5474#issuecomment-6158230318). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-14T00:37:58Z. --- Windows test of #5474: Windows 10 (19045), MinGW-w64 GCC 15.2, Release, `ninja -j 4`, ctest called directly, GPU selected by the execution tests: NVIDIA GeForce RTX 4080 SUPER (`Selected GPU` log line; an AMD Radeon RX 6400 is present and was not selected). Tree: `main` `feddf7f4c` + merge of PR head `b6ecd7527e8150290139f30f42f49728f56efebc` (local merge `ecde0711f`). `agc_driver_lds_src2` and `agc_driver_lds_src2_wide`: exit code 0 in 3 of 3 runs each (6 of 6). Logs: `rtx5474_*_N.log`. Not tested: that the new/changed test fails without the change (no baseline run for this PR), the AMD GPU, other ctest targets, Linux, a title run. (For comparison, the same-named tests with the head of #5498 crashed in the NVIDIA driver in 9 of 9 runs; see the separate report on #5498.) AI-assisted (Claude Code).
tibzejoker commented 2026-10-14 01:17:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tibzejoker on 2026-10-14T01:17:27Z.


Intel run for this PR: Intel UHD Graphics 770 (Raptor Lake iGPU of an i9-13900K), driver 32.0.101.6129, Windows 11, MinGW-w64 GCC 15.2.0 Release, device picked with ANYPS5_GPU=Intel, at head b6ecd7527.

  • agc_driver_lds_src2_wide and agc_driver_lds_src2 pass.
  • ctest -R "agc_driver|agc_masked|agc_shader" -j4: no failures out of 387 (359 pass, 28 skipped). These are the same 28 skips as main has on this GPU (f64, 64-bit and float atomics, fp16 interpolation and dot, mesh, shader clock and the like, which it does not support), and no new ones.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158703188 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5474#issuecomment-6158703188). Originally posted by [tibzejoker](https://github.com/tibzejoker) on 2026-10-14T01:17:27Z. --- Intel run for this PR: Intel UHD Graphics 770 (Raptor Lake iGPU of an i9-13900K), driver 32.0.101.6129, Windows 11, MinGW-w64 GCC 15.2.0 Release, device picked with `ANYPS5_GPU=Intel`, at head `b6ecd7527`. - `agc_driver_lds_src2_wide` and `agc_driver_lds_src2` pass. - `ctest -R "agc_driver|agc_masked|agc_shader" -j4`: no failures out of 387 (359 pass, 28 skipped). These are the same 28 skips as `main` has on this GPU (f64, 64-bit and float atomics, fp16 interpolation and dot, mesh, shader clock and the like, which it does not support), and no new ones. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-14 01:50:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T01:50:09Z.


Correction to my Windows test above: I wrote that the GPU was shown by a Selected GPU log line, but that line was not in the ctest logs of those runs (ctest without -V does not print the output of passing tests). Re-run with ctest -V on main 5a81f6085b0c18efed2125d857836c73acd129c6 + this PR's head b6ecd7527e8150290139f30f42f49728f56efebc: the log shows Selected GPU name=NVIDIA GeForce RTX 4080 SUPER, and agc_driver_lds_src2 exits with code 0 (1 run). agc_driver_lds_src2_wide was not re-run with -V.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159088368 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5474#issuecomment-6159088368). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-14T01:50:09Z. --- Correction to my Windows test above: I wrote that the GPU was shown by a `Selected GPU` log line, but that line was not in the ctest logs of those runs (ctest without `-V` does not print the output of passing tests). Re-run with `ctest -V` on `main` `5a81f6085b0c18efed2125d857836c73acd129c6` + this PR's head `b6ecd7527e8150290139f30f42f49728f56efebc`: the log shows `Selected GPU name=NVIDIA GeForce RTX 4080 SUPER`, and `agc_driver_lds_src2` exits with code 0 (1 run). `agc_driver_lds_src2_wide` was not re-run with `-V`. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-14 02:29:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:29:03Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159542557 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5474#issuecomment-6159542557). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:29:03Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Pull request closed

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!5474
No description provided.