docs(shader): cut the f16 SDWA clamp entry to its NaN test gap #17974

Merged
Nawid3333 merged 1 commit from upstream-pr/17974 into main 2026-11-13 09:02:01 +00:00
Nawid3333 commented 2026-11-10 02:05:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nawid3333 on 2026-11-10T02:05:33Z.


What

Cuts the "f16 VOP2 SDWA clamp with byte selectors" entry in docs/dev/debt/shader.md to what is still open. It changes no code.

The entry said the order of clamp and destination select was not measured on hardware. The order is: the f16 result is clamped as without SDWA, then written into DST_SEL as DST_U says. The RDNA2 ISA doesn't state it; ACO and LLVM assume it.

The order is now measured on RDNA2 for every selector triple that has a byte selector, NaN results included. The entry's closing condition was "measured with clamp on RDNA2 or a PS5", so that part is closed.

What stays open is that the tests pin no NaN result. The entry now leads with that and closes when a measured NaN row is pinned in SdwaFloatSelectors.cpp.

Tested

All runs were on an AMD Ryzen 5 7600X iGPU (RDNA2, gfx1036), AMD Windows driver 32.0.21045.16010, Windows 11 Pro build 26200. They went through tools/hw-oracle with the HIP runtime, in wave32.

  1. The existing test's kernel on hardware. The 17 instruction words of ClampCode in SdwaFloatSelectors.cpp ran natively with the test's 32 Rows. All 183 checked values equal ClampExpected, under all four combinations of IEEE 0/1 and DX10_CLAMP 0/1.

  2. The order itself. Each kernel holds 8 cases. For each case it computes:

    • the SDWA instruction with clamp (destination preset to a third input for UNUSED_PRESERVE);
    • next to it, the same operation as VOP3 with clamp, on the operand fields extracted with v_bfe_u32 (v_mov_b32 for a DWORD selector).

    The VOP3 result, inserted into the DST_SEL field as DST_UNUSED says, is the expected value.

    • Ops: v_add_f16, v_sub_f16, v_subrev_f16, v_mul_f16, v_max_f16, v_min_f16 and v_ldexp_f16.
    • Selectors: every SRC0_SEL x SRC1_SEL x DST_SEL triple that holds a byte selector, 2,212 cases in all. Each case got one DST_UNUSED mode, chosen at random.
    • Inputs: 32 lanes of f16 edge values (NaN, ±inf, values above 1 and below 0, denormals, ±0) and random words.
    • Modes: IEEE 0 with DX10_CLAMP 1, and IEEE 1 with DX10_CLAMP 0.

    Result: 141,568 of 141,568 lane results match.

    • The inputs reach the clamp: in each mode about 12,300 references are 1.0 and over 30,000 are +0.
    • With DX10_CLAMP 0, 3,270 references are NaN: 2,280 written into a byte field, 660 into a word field and 330 into the full dword. The SDWA results equal them inserted as DST_SEL and DST_UNUSED say.

The scripts and per-lane results: anyps5-sdwa-f16-clamp-rdna2-evidence.zip.

python3 tools/check_conventions.py --base origin/main: all conventions checks passed.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5234510986 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17974). Originally posted by [Nawid3333](https://github.com/Nawid3333) on 2026-11-10T02:05:33Z. --- ### What Cuts the "f16 VOP2 SDWA clamp with byte selectors" entry in `docs/dev/debt/shader.md` to what is still open. It changes no code. The entry said the order of clamp and destination select was not measured on hardware. The order is: the f16 result is clamped as without SDWA, then written into `DST_SEL` as `DST_U` says. The RDNA2 ISA doesn't state it; ACO and LLVM assume it. The order is now measured on RDNA2 for every selector triple that has a byte selector, NaN results included. The entry's closing condition was "measured with clamp on RDNA2 or a PS5", so that part is closed. What stays open is that the tests pin no NaN result. The entry now leads with that and closes when a measured NaN row is pinned in `SdwaFloatSelectors.cpp`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> All runs were on an AMD Ryzen 5 7600X iGPU (RDNA2, gfx1036), AMD Windows driver 32.0.21045.16010, Windows 11 Pro build 26200. They went through `tools/hw-oracle` with the HIP runtime, in wave32. 1. **The existing test's kernel on hardware.** The 17 instruction words of `ClampCode` in `SdwaFloatSelectors.cpp` ran natively with the test's 32 `Rows`. All 183 checked values equal `ClampExpected`, under all four combinations of IEEE 0/1 and DX10_CLAMP 0/1. 2. **The order itself.** Each kernel holds 8 cases. For each case it computes: - the SDWA instruction with clamp (destination preset to a third input for `UNUSED_PRESERVE`); - next to it, the same operation as VOP3 with clamp, on the operand fields extracted with `v_bfe_u32` (`v_mov_b32` for a DWORD selector). The VOP3 result, inserted into the `DST_SEL` field as `DST_UNUSED` says, is the expected value. - **Ops:** `v_add_f16`, `v_sub_f16`, `v_subrev_f16`, `v_mul_f16`, `v_max_f16`, `v_min_f16` and `v_ldexp_f16`. - **Selectors:** every `SRC0_SEL` x `SRC1_SEL` x `DST_SEL` triple that holds a byte selector, 2,212 cases in all. Each case got one `DST_UNUSED` mode, chosen at random. - **Inputs:** 32 lanes of f16 edge values (NaN, ±inf, values above 1 and below 0, denormals, ±0) and random words. - **Modes:** IEEE 0 with DX10_CLAMP 1, and IEEE 1 with DX10_CLAMP 0. Result: 141,568 of 141,568 lane results match. - The inputs reach the clamp: in each mode about 12,300 references are 1.0 and over 30,000 are +0. - With DX10_CLAMP 0, 3,270 references are NaN: 2,280 written into a byte field, 660 into a word field and 330 into the full dword. The SDWA results equal them inserted as `DST_SEL` and `DST_UNUSED` say. The scripts and per-lane results: [anyps5-sdwa-f16-clamp-rdna2-evidence.zip](https://github.com/Nawid3333/AnyPS5/releases/download/evidence-sdwa-f16-clamp/anyps5-sdwa-f16-clamp-rdna2-evidence.zip). `python3 tools/check_conventions.py --base origin/main`: all conventions checks passed. ### 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 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
gabichuuuuu commented 2026-11-10 17:49:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-10T17:49:57Z.

Review: COMMENTED


Read 8d145ef744 against main.

Correctness. The entry on main says the clamp and DST_SEL order is "not measured on hardware" and closes "when measured with clamp on RDNA2 or a PS5"; the PR records the measurement on gfx1036 and narrows the open part to NaN results. docs/dev/HW_ORACLE.md and core/libs/prx/libSceAgcDriver/tests/execution/SdwaFloatSelectors.cpp exist on main, and the test pins its clamp results through ClampExpected with a per-row ClampChecked mask (SdwaFloatSelectors.cpp:131-175, :236-241), so "the tests pin no NaN result" is plausible; I did not decode every masked cell to prove it. The measurement itself cannot be checked from the code. The other shader.md PRs (#17807, #18026) edit different entries.

Not run here; this is from reading the code.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5846665510 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17974#pullrequestreview-5846665510). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-10T17:49:57Z. **Review:** COMMENTED --- Read `8d145ef744` against `main`. **Correctness.** The entry on main says the clamp and `DST_SEL` order is "not measured on hardware" and closes "when measured with clamp on RDNA2 or a PS5"; the PR records the measurement on gfx1036 and narrows the open part to NaN results. `docs/dev/HW_ORACLE.md` and `core/libs/prx/libSceAgcDriver/tests/execution/SdwaFloatSelectors.cpp` exist on main, and the test pins its clamp results through `ClampExpected` with a per-row `ClampChecked` mask (`SdwaFloatSelectors.cpp:131-175`, `:236-241`), so "the tests pin no NaN result" is plausible; I did not decode every masked cell to prove it. The measurement itself cannot be checked from the code. The other shader.md PRs (#17807, #18026) edit different entries. Not run here; this is from reading the code. AI-assisted: yes.
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!17974
No description provided.