Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Nawid3333:docs/sdwa-f16-clamp-rdna2
Nov 13, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Nawid3333:docs/sdwa-f16-clamp-rdna2

Conversation

@Nawid3333

Copy link
Copy Markdown
Contributor

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the docs label Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5371 docs/dev/debt/shader.md
PR 6235 docs/dev/debt/shader.md
PR 6280 docs/dev/debt/shader.md
PR 6412 docs/dev/debt/shader.md
PR 6488 docs/dev/debt/shader.md
PR 6924 docs/dev/debt/shader.md
PR 7684 docs/dev/debt/shader.md
PR 8004 docs/dev/debt/shader.md
PR 9335 docs/dev/debt/shader.md
PR 9387 docs/dev/debt/shader.md
PR 9748 docs/dev/debt/shader.md
PR 9889 docs/dev/debt/shader.md
PR 10652 docs/dev/debt/shader.md
PR 11483 docs/dev/debt/shader.md
PR 14217 docs/dev/debt/shader.md
PR 14218 docs/dev/debt/shader.md
PR 14853 docs/dev/debt/shader.md
PR 15548 docs/dev/debt/shader.md
PR 17611 docs/dev/debt/shader.md
PR 17623 docs/dev/debt/shader.md
PR 17701 docs/dev/debt/shader.md

@Nawid3333

Copy link
Copy Markdown
Contributor Author

The overlap with #16899 is textual. #16899 adds its "SDWA unary-f16 byte selectors" entry directly above the entry this pull request edits in docs/dev/debt/shader.md. The resolution keeps both: the new entry, then the cut entry from here. Neither pull request needs the other. If #16899 is merged first, I'll rebase this one.

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

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.

@oneandonlydean
oneandonlydean merged commit ddd8c8c into boykopovar:main Nov 13, 2026
3 checks passed
@Nawid3333
Nawid3333 deleted the docs/sdwa-f16-clamp-rdna2 branch November 13, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants