Skip to content

compute: lower the d16 descriptor-format buffer loads - #2165

Merged
tedin7 merged 3 commits into
R0Y00:mainfrom
archielcqp-a11y:compute/load-descriptor-format-d16
Nov 26, 2026
Merged

tedin7 merged 3 commits into
R0Y00:mainfrom
archielcqp-a11y:compute/load-descriptor-format-d16

Conversation

@archielcqp-a11y

Copy link
Copy Markdown
Contributor

Refs #2022 (item A). This follows #2150 (merged), which added the descriptor-format decoder.

Summary

R0Y00 asked on #2022 for d16 to follow the first slice, with integer versus float handling and a format-specific rounding or conversion control. This PR adds that.

buffer_load_format_d16_{x,xy,xyz,xyzw} now use the descriptor-format decoder from #2150. The format word, the exact-width validity rule and the refusal (no store when any load is invalid) are unchanged. Two 16-bit channels pack per result word, x in the low half.

The format's type decides the 16-bit value:

  • FLOAT16 formats: the stored halves, unchanged.
  • UNORM and SNORM16: binary16 of x / (2^n - 1) or max(x / 32767, -1), rounded to nearest even by integer long division (descriptor_ratio16). Binary16 denormals are kept, so 1/65535 is 0x0100.
  • 16-bit UINT and SINT: the 16-bit integer, not converted to a float.
  • 32-bit formats: no d16 rule is established here (for example, the overflow and rounding of 32_FLOAT to binary16). So 32_UINT and 32_FLOAT, in one to four channels, are invalid under d16 and publish nothing.

Whether the RDNA format unit rounds the same way, or keeps binary16 denormals, is not verified.

Odd channel counts: d16_x and d16_xyz leave the high half of the last word undefined. That word is now an alu_low16 value. It reaches a whole-word store or an ALU operand only through v_and_b32 0xffff, the same rule the existing caller-format D16 reads (source_low16) follow.

Fixture

compute_store_aot_descriptor_load_format_d16_{warp,hardware} (tests/compute_load_format_check.py draw-d16).

The fixture makes ten d16 loads over the same t0 words as the binary32 fixture, one per format with a d16 rule, into a 64-byte u0 record. The edge values exercise round-up, binary16 denormals, -32768 and -32767, and the sign of 16-bit SINT.

  • Readback: all 320 words for one group and for two.
  • Invalid formats: three runs each make one load invalid (32_32_FLOAT under d16_xy, 16_16_UNORM under d16_x, and 8_SNORM). Each must leave u0 unwritten, and a zero-filled reference must fail.
  • Wrong references: seven must fail on the two-group run, at their first differing word:
    • truncated binary16, and flushed binary16 denormals;
    • 16-bit UINT converted like 16-bit UNORM, and 16-bit SINT converted like 16-bit SNORM;
    • halves packed high first;
    • the legacy word ignored;
    • the neighbouring thread's element.
  • Mutated HLSL: nine sources must fail:
    • a binary16 ratio that never rounds up, and flushed denormals;
    • each integer format converted, halves packed high first, and the SNORM16 half sign dropped;
    • the binary32 conversion used under d16;
    • on the invalid runs, a 32-bit format accepted under d16, and the refusal removed.
  • Translation controls:
    • They reject the odd half stored without the mask, used by an ALU operation, or loaded into a destination range that is too wide.
    • They fail when the d16 flag is dropped, the low-half marking is removed, or 32-bit formats get a d16 arm.
    • The existing gfx1030 D16 readback (draw-mubuf-load-format-d16), which shares the mask rule, still passes on WARP.
  • LLVM 15: assembles both fixtures, and the round trip matches.

Results

Run at 340c608 (on #2150's head f3a6819), Windows 10 build 19045, debug layer enabled, 0 debug errors and 0 debug warnings on every dispatch. The pull-request CI runs the pr smoke preset, which does not include these tests, so here is the local CTest output:

1/5 Test  #462: compute_load_format_controls ............................   Passed    2.95 sec
2/5 Test  #991: compute_store_aot_descriptor_load_format_hardware .......   Passed   11.61 sec
3/5 Test  #992: compute_store_aot_descriptor_load_format_d16_hardware ...   Passed    9.25 sec
4/5 Test #1180: compute_store_aot_descriptor_load_format_warp ...........   Passed   27.70 sec
5/5 Test #1181: compute_store_aot_descriptor_load_format_d16_warp .......   Passed   10.67 sec
100% tests passed, 0 tests failed out of 5

The hardware adapter is an NVIDIA GeForce RTX 3080 (driver 32.0.15.9174), and WARP is 1.0.22 (app-local).

Other checks:

  • tests/compute_load_format_check.py binary with LLVM 15: pass, both fixtures.
  • tests/compute_store_check.py binary with LLVM 15: pass.
  • tests/compute_store_check.py draw-mubuf-load-format-d16 on WARP: pass.
  • form_coverage_check, docs_links_check, bidi_controls_check and shader_census_check: pass.

No capability skips.

cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R '^compute_(store_aot_descriptor_load_format_|load_format_controls$)' -V

🤖 Generated with Claude Code

buffer_load_format_d16_{x,xy,xyz,xyzw} now use the descriptor-format
decoder, with the same validity rule and refusal. Two 16-bit channels
pack per word, x low. The format's type decides the value. FLOAT16
formats give their stored halves. UNORM and SNORM16 give binary16, rounded
to nearest even by long division with denormals kept. 16-bit UINT and
SINT give the 16-bit integer, not a float. 32-bit formats have no d16
rule here and are invalid. An odd count leaves the last word low-16 only:
it reaches a store or an ALU operand through v_and_b32 0xffff, as for
the caller-format D16 reads.

A second fixture makes ten d16 loads over the same t0 words. It compares
all 320 words for one and two groups on WARP and hardware. Three
invalid-format runs must leave u0 unwritten. Seven wrong references and
nine mutated sources must fail, among them integer-as-float, truncated
or flushed binary16, and swapped packing. LLVM 15 assembles both
fixtures and the round trip matches.

Refs R0Y00#2022 (item A, d16 follow-up to the format decoder)

AI-assisted (Claude Code); reviewed and run locally.

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

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head 340c608.

P1: 0. P2: 0.

Logic: the binary16 long division in descriptor_ratio16 is correct. Normal results keep 11 bits, and denormals count units of 2^-24. Rounding is nearest-even with a sticky bit, and a carry into the exponent is fine. SNORM16 clamps -32767 and below to -1.0. 16-bit UINT and SINT stay integer, and 32-bit formats have no d16 arm. The odd last half is tracked as alu_low16, so it must be masked before a whole-word store.

Linux, run locally:

  • python3 tests/compute_load_format_check.py passed.
  • python3 tests/docs_links_check.py passed.
  • python3 tests/bidi_controls_check.py passed.
  • git diff --check origin/main...HEAD was clean.

Mutations in tools/compute_store_aot.py:

  • Dropping the odd-half low16 condition made the test fail (rc=1).
  • Passing 0u instead of the packed flag made the test fail (rc=1).
  • Changing the SNORM clamp constant from 0xbc00 to 0xbc01 is not caught by the Linux controls, which only check strings. The Win2025 WARP readback test covers the real values.

Win2025 (x2w_pipe.py win2025 2165 --wait 3600): Debug 60/60 passed and Release /O2 60/60 passed. This includes compute_store_aot_descriptor_load_format_d16_warp, a GPU readback test against a CPU reference. GitHub CI Build and test on Windows = SUCCESS.

Competing PRs: no other open PR covers d16 descriptor-format buffer loads. #2139 is D16 image_load, a different opcode.

AI-assisted; commands listed were executed locally.

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

Verified head 340c6085 on Windows x64 (dev preset, MSVC 19.44.35228.0, SDK/DXC 10.0.26100.0):

  • python -B tests/compute_load_format_check.py -> passed
  • ctest --preset dev --no-tests=error -R '^compute_store_aot_descriptor_load_format_' -V -> 4/4 passed (compute_store_aot_descriptor_load_format_{hardware,warp} and compute_store_aot_descriptor_load_format_d16_{hardware,warp})
    • descriptor_load_format: 6 dispatches, 13 wrong references, 11 mutated sources checked; descriptor_load_format_d16: 5 dispatches, 10 wrong references, 9 mutated sources checked (debug_errors=0 debug_warnings=0).
    • Hardware: AMD Radeon RX 7900 XTX (vendor=1002 device=744c, driver 32.0.32029.2010)
    • WARP: Microsoft Basic Render Driver (vendor=1414 device=008c, driver 10.0.26100.9818)

Verdict: Approved at 340c6085.

@legacy-code-archaeologist

Copy link
Copy Markdown
Contributor

Ran head 340c6085 on three adapters. All pass. Windows 11 build 26100, debug layer unavailable.

Test Adapter Driver Result
compute_store_aot_descriptor_load_format_d16_warp Microsoft Basic Render Driver 10.0.26100.8972 pass, 5/5 dispatches with compared_words=320 mismatches=0
compute_store_aot_descriptor_load_format_d16_hardware (XBOX2WINDOWS_ADAPTER=Quadro) NVIDIA Quadro M1000M (Maxwell) 32.0.15.7371 pass, same
compute_store_aot_descriptor_load_format_d16_hardware (XBOX2WINDOWS_ADAPTER=Intel) Intel HD Graphics 530 (Gen9) 31.0.101.2111 pass, same

AI-assisted.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@archielcqp-a11y could you rebase this branch onto current main and force-push?

GitHub reports head 340c6085 as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (b1a644ae):

  • CMakeLists.txt
  • README.md
  • tools/compute_store_aot.py

Commands run locally:

git fetch origin main pull/2165/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 2165 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

Keeps main's batched references, heap-view loads and 2_10_10_10 format (code 50, 10_10_10_2 invalid) together with the d16 opcodes. A d16 load through a heap view is refused: the heap-view helper has no d16 rule. The d16 fixture's 10-bit row now uses 2_10_10_10_UNORM (50).
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Pushed 6ceb259: a merge of main into this branch (no force, no rebase) so the PR is mergeable again. The d16 lowering itself is unchanged.

Main had changed the same areas, so the merge needed a few decisions. Both sides are kept where they do not clash:

  • tools/compute_store_aot.py: main's call string for descriptor-format and heap-view loads, with the d16 flag passed to load_descriptor_format.
  • tests/compute_load_format_check.py: your suite-parameterised draw() now uses main's batched references (--compute-store-batch) and parallel mutations.
  • CMakeLists.txt, README.md, docs/experiments.md: both sides kept; the README row names the d16 forms.

Two behaviours to review:

  • Refused: a d16 load through a heap view. The heap-view helper has no d16 rule, so the translator now raises "D16 descriptor-format loads are not lowered through a heap view" and the helper calls load_descriptor_format with d16 off. Refuse rather than guess.
  • Fixture change: main now treats 10_10_10_2_UNORM (44) as invalid and handles 2_10_10_10_UNORM (50). The d16 fixture's 10-bit row (a 44) moved to 50, so it still exercises a valid format.

Commands executed locally:

  • python3 tests/compute_load_format_check.py, tests/compute_heap_view_check.py, tests/compute_heap_store_check.py: pass
  • python3 x2w_pipe.py win2025 2165 --patch <merge diff> --regex 'compute_store_aot_descriptor_load_format|compute_store_aot_heap_view|compute_heap|compute_load_format' (default slots, dev and release): 11/11 passed each, including the d16 and heap-view WARP and hardware draws

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 enabled auto-merge (squash) November 26, 2026 02:18
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Pushed 3d84b65: a second merge of main into this branch (no force, no rebase) so the PR is mergeable again. The d16 lowering is unchanged.

One real conflict, in tools/compute_store_aot.py next to the v_and_b32 0xffff rule. Both sides are kept: your source_low16/alu_low16 handling stays, and main's new _e64 float add/sub/mul rule with source modifiers follows it. CMakeLists.txt and the docs merged cleanly, and the foreach/endforeach counts match (368/368).

Commands executed locally:

  • python3 -m py_compile tools/compute_store_aot.py
  • python3 -B tests/compute_load_format_check.py controls (pass)
  • python3 -B tests/rdna2_tools_check.py (OK)

The Windows WARP pass on the d16 content was recorded earlier in this thread; it was not re-run because the conflict was a keep-both merge of two independent rules.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit fa189d2 into R0Y00:main Nov 26, 2026
5 checks passed
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.

4 participants