fix(shader): convert formatted buffer stores to the element format #330
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/330"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T06:31:13Z.
What
Bug: formatted buffer stores (
buffer_store_format_*with the descriptor's format,tbuffer_store_format_*with the instruction's) did not convert anything:8_UNORMstore of1.0fwrote0x00, the low byte of0x3f800000. The hardware writes0xff.2_10_10_10,10_11_11) wrote the full register into the word, once per component.store_format_xon8_8_8_8writes0x000000ff, and on32_32it zeroes the second dword.Only 32-bit FLOAT/UINT/SINT stores were right, which is likely why nothing noticed.
Semantics measured on an RDNA2 GPU (ROCm HSA, raw kernels; 2048 vectors per format, all matched by a Python model):
0xffin8_USCALED, 2048/2048)Implementation:
EmitFormatStoreComponentencodes one component. Exact x·M usesOpUMulExtendedof the mantissa and M, held as 16.16 fixed point plus a sticky bit, so it is 32-bit integer ops only. Going through an f32 multiply would round twice.StoreFormattedElementwrites every component of the element (missing ones as 0). Packed formats are composed into a single word store. The single-component and wide store paths both use it.Test
agc_driver_formatted_store: 16 results × 32 lanes captured on the RDNA2 GPU. It covers every component type, NaN/inf/−0/denormal inputs,x/xy/xyz/xyzwstores into packed (2_10_10_10UNORM/SNORM,10_11_11) and plain (8_8_8_8_SINT,16_16_FLOAT,32_32_UINT) formats, and checks the zero fill.Tested
Linux, full ctest (101) passes.
8unorm is 0xaaaaaa00, expected 0xaaaaaaff. Without the zero fill:uint32x2_y is 0xaaaaaaaa, expected 0x00000000.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T06:31:37Z.
Progress report (
d3ec1f1→4d90c0b)📈 GPU shader instructions: 74.96% (+3.95%, +46 implemented instructions)
✅ 46 implemented
DS_READ_I8_D16DS_READ_I8_D16_HIDS_READ_U8_D16DS_READ_U8_D16_HIDS_WRITE_B8_D16_HIFLAT_LOAD_SBYTE_D16FLAT_LOAD_SBYTE_D16_HIFLAT_LOAD_SHORT_D16FLAT_LOAD_SHORT_D16_HIFLAT_LOAD_UBYTE_D16FLAT_LOAD_UBYTE_D16_HIFLAT_STORE_BYTE_D16_HIFLAT_STORE_SHORT_D16_HIGLOBAL_LOAD_SBYTE_D16GLOBAL_LOAD_SBYTE_D16_HIGLOBAL_LOAD_SHORT_D16GLOBAL_LOAD_SHORT_D16_HIGLOBAL_LOAD_UBYTE_D16GLOBAL_LOAD_UBYTE_D16_HIGLOBAL_STORE_BYTE_D16_HIGLOBAL_STORE_SHORT_D16_HITBUFFER_LOAD_FORMAT_D16_XTBUFFER_LOAD_FORMAT_D16_XYTBUFFER_LOAD_FORMAT_D16_XYZTBUFFER_LOAD_FORMAT_D16_XYZWBUFFER_LOAD_FORMAT_D16_HI_XBUFFER_LOAD_FORMAT_D16_XBUFFER_LOAD_FORMAT_D16_XYBUFFER_LOAD_FORMAT_D16_XYZBUFFER_LOAD_FORMAT_D16_XYZWBUFFER_LOAD_SBYTE_D16BUFFER_LOAD_SBYTE_D16_HIBUFFER_LOAD_SHORT_D16BUFFER_LOAD_SHORT_D16_HIBUFFER_LOAD_UBYTE_D16BUFFER_LOAD_UBYTE_D16_HIBUFFER_STORE_BYTE_D16_HIBUFFER_STORE_SHORT_D16_HISCRATCH_LOAD_SBYTE_D16SCRATCH_LOAD_SBYTE_D16_HISCRATCH_LOAD_SHORT_D16SCRATCH_LOAD_SHORT_D16_HISCRATCH_LOAD_UBYTE_D16SCRATCH_LOAD_UBYTE_D16_HISCRATCH_STORE_BYTE_D16_HISCRATCH_STORE_SHORT_D16_HI