Skip to content

feat(shader): implement the D16 format buffer stores - #331

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
adriadam10:feat/format-d16-stores
Oct 4, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
adriadam10:feat/format-d16-stores

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

What

This adds the store half of the D16 formats. The loads were #329.

  • MUBUF: buffer_store_format_d16_{x,xy,xyz,xyzw} (0x84-0x87) and buffer_store_format_d16_hi_x (0x27).
  • MTBUF: tbuffer_store_format_d16_{x,xy,xyz,xyzw} (0x0c-0x0f).

Each component is a 16-bit half: two per VGPR, low half first, and _hi_x takes the high half.

Semantics measured on an RDNA2 GPU (2048 vectors × 15 stores, all matched by a Python model):

Component type Stored value
UNORM / SNORM / USCALED / SSCALED, 32-bit and 11/10-bit FLOAT the half as f16, widened exactly to f32, then encoded like a 32-bit formatted store (#330)
16-bit FLOAT the half, unchanged
UINT the half zero-extended, then saturated (0x3c00 → 0xff in 8_UINT, 0x00003c00 in 32_UINT)
SINT the half sign-extended, then saturated (0xbc00 → 0x80 in 8_SINT, 0xffffbc00 in 32_SINT)

The whole element is written with missing components as 0, as in #330.

The f16 → f32 widening is done with integer ops: subnormals are normalized with FindUMsb and NaN payloads are kept. unpackHalf2x16 may flush f16 denormals or quiet NaNs, depending on the driver, and both are visible in the 11/10-bit float formats.

Test agc_driver_format_d16_store: 16 results × 32 lanes captured on the RDNA2 GPU. It covers every component type above, f16 specials (±inf, NaN 0x7e00/0x7c01, subnormals 0x0001/0x8001, 65504) in both halves, the xy/xyz/xyzw packing with zero fill, and _hi_x through the descriptor's format.

Tested

Linux, full ctest (102) passes.

  • RADV (Radeon 660M) and lavapipe: the test passes.
  • Treating the half as f32 bits instead of converting it: 8unorm is 0xaaaaaa00, expected 0xaaaaaaff.

Checklist

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Progress report (d3ec1f1 → b29fe00)

📈 GPU shader instructions: 75.73% (+4.72%, +55 implemented instructions)

✅ 55 implemented
Encoding Name
DS DS_READ_I8_D16
DS DS_READ_I8_D16_HI
DS DS_READ_U8_D16
DS DS_READ_U8_D16_HI
DS DS_WRITE_B8_D16_HI
FLAT FLAT_LOAD_SBYTE_D16
FLAT FLAT_LOAD_SBYTE_D16_HI
FLAT FLAT_LOAD_SHORT_D16
FLAT FLAT_LOAD_SHORT_D16_HI
FLAT FLAT_LOAD_UBYTE_D16
FLAT FLAT_LOAD_UBYTE_D16_HI
FLAT FLAT_STORE_BYTE_D16_HI
FLAT FLAT_STORE_SHORT_D16_HI
GLOBAL GLOBAL_LOAD_SBYTE_D16
GLOBAL GLOBAL_LOAD_SBYTE_D16_HI
GLOBAL GLOBAL_LOAD_SHORT_D16
GLOBAL GLOBAL_LOAD_SHORT_D16_HI
GLOBAL GLOBAL_LOAD_UBYTE_D16
GLOBAL GLOBAL_LOAD_UBYTE_D16_HI
GLOBAL GLOBAL_STORE_BYTE_D16_HI
GLOBAL GLOBAL_STORE_SHORT_D16_HI
MTBUF TBUFFER_LOAD_FORMAT_D16_X
MTBUF TBUFFER_LOAD_FORMAT_D16_XY
MTBUF TBUFFER_LOAD_FORMAT_D16_XYZ
MTBUF TBUFFER_LOAD_FORMAT_D16_XYZW
MTBUF TBUFFER_STORE_FORMAT_D16_X
MTBUF TBUFFER_STORE_FORMAT_D16_XY
MTBUF TBUFFER_STORE_FORMAT_D16_XYZ
MTBUF TBUFFER_STORE_FORMAT_D16_XYZW
MUBUF BUFFER_LOAD_FORMAT_D16_HI_X
MUBUF BUFFER_LOAD_FORMAT_D16_X
MUBUF BUFFER_LOAD_FORMAT_D16_XY
MUBUF BUFFER_LOAD_FORMAT_D16_XYZ
MUBUF BUFFER_LOAD_FORMAT_D16_XYZW
MUBUF BUFFER_LOAD_SBYTE_D16
MUBUF BUFFER_LOAD_SBYTE_D16_HI
MUBUF BUFFER_LOAD_SHORT_D16
MUBUF BUFFER_LOAD_SHORT_D16_HI
MUBUF BUFFER_LOAD_UBYTE_D16
MUBUF BUFFER_LOAD_UBYTE_D16_HI
MUBUF BUFFER_STORE_BYTE_D16_HI
MUBUF BUFFER_STORE_FORMAT_D16_HI_X
MUBUF BUFFER_STORE_FORMAT_D16_X
MUBUF BUFFER_STORE_FORMAT_D16_XY
MUBUF BUFFER_STORE_FORMAT_D16_XYZ
MUBUF BUFFER_STORE_FORMAT_D16_XYZW
MUBUF BUFFER_STORE_SHORT_D16_HI
SCRATCH SCRATCH_LOAD_SBYTE_D16
SCRATCH SCRATCH_LOAD_SBYTE_D16_HI
SCRATCH SCRATCH_LOAD_SHORT_D16
SCRATCH SCRATCH_LOAD_SHORT_D16_HI
SCRATCH SCRATCH_LOAD_UBYTE_D16
SCRATCH SCRATCH_LOAD_UBYTE_D16_HI
SCRATCH SCRATCH_STORE_BYTE_D16_HI
SCRATCH SCRATCH_STORE_SHORT_D16_HI

This was referenced Oct 2, 2026
@github-actions github-actions Bot added build shader core/shader agc libSceAgc* ci .github needs rebase Conflicts with main, rebase needed labels Oct 2, 2026
adriadam10 and others added 4 commits October 3, 2026 11:37
buffer/flat/global/scratch_load_{ubyte,sbyte,short}_d16(_hi),
buffer/flat/global/scratch_store_{byte,short}_d16_hi and
ds_read_{u8,i8}_d16(_hi), ds_write_b8_d16_hi threw in the decoder. They use
the same 16-bit destination/source select as the existing ds_read_u16_d16
and ds_write_b16_d16_hi: a load writes one half and keeps the other, a
_d16_hi store takes its data from the high half.

Co-Authored-By: Claude <noreply@anthropic.com>
buffer_load_format_d16_{x,xy,xyz,xyzw}, buffer_load_format_d16_hi_x and
tbuffer_load_format_d16_{x,xy,xyz,xyzw} convert each component to 16
bits and pack two per VGPR. The conversions follow the hardware:
unorm/snorm round the exact value to nearest even, scaled integers
round to nearest even and saturate at 65504, 32-bit floats truncate
toward zero (saturating at 65504), and 32-bit integers saturate to 16
bits. All of it is done with integer ops so it does not depend on the
driver's f16 rounding. _x and _hi_x keep the other half, xyz keeps the
upper half of its second register, and a descriptor constant one is
f16 1.0 for non-integer formats.

Co-Authored-By: Claude <noreply@anthropic.com>
buffer_store_format_* and tbuffer_store_format_* wrote the register
bits as they were: an 8_UNORM store of 1.0f wrote 0x00 (the low byte of
0x3f800000), packed formats such as 2_10_10_10 overwrote the whole word
with each component, and the components the instruction does not
provide were left untouched. Each component is now encoded as the
hardware does: unorm/snorm (and uscaled/sscaled, which store the same
way) round x*M exactly to nearest even after clamping, with NaN as 0;
uint/sint saturate; f16 and the 11/10-bit floats truncate toward zero
and saturate. The whole element is written, with the missing components
as 0, and packed formats are composed into one word.

Co-Authored-By: Claude <noreply@anthropic.com>
buffer_store_format_d16_{x,xy,xyz,xyzw}, buffer_store_format_d16_hi_x
and tbuffer_store_format_d16_{x,xy,xyz,xyzw} take one 16-bit half per
component (two per VGPR; hi_x takes the high half). As on hardware,
float, norm and scaled formats read the half as f16, widen it exactly
to f32 and then encode it like a 32-bit formatted store; uint formats
zero-extend it and sint formats sign-extend it before saturating, and
16-bit float components store it unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the feat/format-d16-stores branch from 6f4b044 to b29fe00 Compare October 3, 2026 09:44
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 3, 2026
@oneandonlydean
oneandonlydean merged commit f4071f2 into boykopovar:main Oct 4, 2026
3 checks passed
@adriadam10
adriadam10 deleted the feat/format-d16-stores branch October 5, 2026 06:47
SP4C3B4R-8 pushed a commit to SP4C3B4R-8/AnyPS5 that referenced this pull request Oct 6, 2026
Takes the 13 gate-batch PRs that merged upstream (boykopovar#319 boykopovar#329 boykopovar#330 boykopovar#331 boykopovar#325
boykopovar#435 boykopovar#471 boykopovar#294 boykopovar#376 boykopovar#404 boykopovar#394 boykopovar#401 boykopovar#446) in place of astrobot's local
versions, as integ/gate-batch cab0eab had them: boykopovar#294 and boykopovar#376 in
astrobot's depth model (DepthTarget, state.depth), boykopovar#394 with the thick mip
tails, boykopovar#401 over astrobot's slab pool, boykopovar#471 keeping the settled single-lane
path. Also takes the rest of main since a818bee (boykopovar#532 boykopovar#340 boykopovar#486 boykopovar#484 boykopovar#316
boykopovar#243 boykopovar#334 boykopovar#434 boykopovar#437 boykopovar#470 boykopovar#373 boykopovar#452 boykopovar#455 and our upstreamed PRs, where
astrobot keeps its later revisions and env switches).

Resolution notes: relinker converter/matcher/tests are upstream's (boykopovar#432
decoder covers VEX RIP-relative followers); RecompileResult gains boykopovar#316's
hostSubgroupSize (set from request.target.subgroupSize); shader disk cache
format 9; boykopovar#452's scissor message; upstream's later live-stack and
memory-copy decode tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mgp3oZvembQziVNE2xARQK
ps54all pushed a commit to ps54all/AnyPS5 that referenced this pull request Oct 14, 2026
image_store with D16 data to a storage image of a SINT format threw
"stores 16-bit data to an image of a SINT format", both when the
descriptor is decoded and in the SPIR-V image emitter, and the runtime
image modes left out the SINT conversions for such images. God of War
Ragnarok (PPSA08330) stops on it in compute shader 0x1052a17900 right
after its MFSR setup.

Each 16-bit half is now converted like the D16 format buffer stores
(EmitD16StoreComponent): sign-extended, then saturated to the
component width as for 32-bit data. The buffer form was measured on
RDNA2 in boykopovar#331; the image form is not measured (TechnicalDebt).

agc_driver_image_store_sint now stores D16 data with DMASK 0xf and 0x5
to all eight SINT formats and after an image_atomic_add on 32_SINT,
instead of expecting the refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adriadam10 pushed a commit to ps54all/AnyPS5 that referenced this pull request Oct 16, 2026
image_store with D16 data to a storage image of a SINT format threw
"stores 16-bit data to an image of a SINT format", both when the
descriptor is decoded and in the SPIR-V image emitter, and the runtime
image modes left out the SINT conversions for such images. God of War
Ragnarok (PPSA08330) stops on it in compute shader 0x1052a17900 right
after its MFSR setup.

Each 16-bit half is now converted like the D16 format buffer stores
(EmitD16StoreComponent): sign-extended, then saturated to the
component width as for 32-bit data. The buffer form was measured on
RDNA2 in boykopovar#331; the image form is not measured (TechnicalDebt).

agc_driver_image_store_sint now stores D16 data with DMASK 0xf and 0x5
to all eight SINT formats and after an image_atomic_add on 32_SINT,
instead of expecting the refusal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build ci .github shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants