AGC: f32 image stores into 16-bit and small float formats are rounded by the host; RDNA 2 rounds toward zero and saturates #8282
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 thuanquang on 2026-10-20T08:31:55Z.
What
An f32
image_storeinto a 16-bit or packed small-float format is converted by the host Vulkan driver, and on RDNA 2 hardware the conversion is different from what NVIDIA-style hosts usually do.PackImageTexel(SpirvImageEmitter.cpp:703) returns the texel unchanged when the image has no conversion format, so formats with a native view —16_FLOAT(13),16_16_FLOAT(29),16_16_16_16_FLOAT(71) and10_11_11_FLOAT(36) throughB10G11R11_UFLOAT— go toOpImageWriteas f32, and the host picks the rounding and the overflow. Formatted buffer stores of the same formats, and11_11_10_FLOAT(43) image stores, already convert in the shader toward zero (#330, the 11_11_10 entry inlibSceAgcDriver.md).Measured
RX 6700 XT (gfx1031), raw ISA through the HIP runtime of AMD's Windows driver 32.0.21045.5002, so the conversion is the hardware's.
image_store v[4:7] ... dmask:0xf dim:SQ_RSRC_IMG_2D unorm glcthrough a linear 2D T# of each format, read back through a UINT T# (16_UINT,16_16_UINT,16_16_16_16_UINT,32_UINT) over the same memory. 38 values per channel, every channel of each format: signed zeros, ±1, f16 ties and near-ties (1 + 2^-11, 1 + 3·2^-11 and neighbours), values around 65504 / 65520 / 65536, 1e6, ±inf, quiet and signalling NaNs with payloads, values in and below the f16 denormal range, the smallest f32 denormal, π, and 1/3. Two mode sets: IEEE 0 with denormals kept, and IEEE 1 with denormals flushed andFP16_OVFL1. Both gave the same results.16_FLOAT(13)16_16_FLOAT(29)16_16_16_16_FLOAT(71)10_11_11_FLOAT(36)11_11_10_FLOAT(43)For example, 65520.0 stores 0x7bff (65504), not 0x7c00, and 1 + 3·2^-11 stores 0x3c01, not 0x3c02. Negative values in the unsigned 10- and 11-bit fields store 0. The 43 row confirms the existing in-shader rule for
11_11_10image stores.Why it matters
A host that rounds to nearest and overflows to infinity stores +inf where the console stores 65504, for HDR values at or above 65520. A later
inf - inforinf * 0then makes NaN, and other values come out one f16 ulp away. On AMD's Windows driver the host conversion may already be the hardware's, but I haven't checked that through the emulator. NVIDIA and Intel aren't measured here.Possible fix
Convert these formats in the shader with the buffer-store rule (
EmitFormatStoreComponent'sF32BitsToSmallFloatRtz, which #330 measured) and store through a UINT view, as11_11_10already does. I can do it, but it needs NVIDIA and Intel runs I can't make here.Data and script:
float_store.py(hardware oracle), results on request.Imported from boykopovar/AnyPS5. Originally posted by ryanc2112 on 2026-10-20T09:07:51Z.
I'd like to pick this up. I'll do the in-shader RTZ conversion through a UINT view for write-only storage of 16_FLOAT, 16_16_FLOAT and 16_16_16_16_FLOAT first, and leave 11_11_10_FLOAT (36) for a follow-up. I can test on RADV (Polaris, Linux). Happy to hand over if you've already started.
Imported from boykopovar/AnyPS5. Originally posted by yangxianshuo666 on 2026-10-20T09:28:09Z.
Could you please adapt it for GTA 6? (LOL)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T20:45:12Z.
I checked current main and found no linked PR yet. I saw your note that you plan to implement the 16-bit float image-store conversion and can test it on RADV. I have not started a patch; are you already preparing a branch/PR? If you are, I will avoid duplicating it and can review the diff or help with validation.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T21:54:58Z.
Small scope clarification before a patch: the issue distinguishes
10_11_11_FLOAT(format 36, currently remapped throughUINT) from11_11_10_FLOAT(format 43, whose image-store conversion is already in shader). Your comment says you will leave11_11_10_FLOAT (36)for follow-up; could you confirm whether you meant10_11_11_FLOAT (36)? I have not started implementation, so your proposed 16-bit work remains unblocked.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T01:31:18Z.
I traced the current source path for format 36 before starting a separate change.
RemapTextureFormat(Format10_11_11Float)returnsFormat32UInt, andinspectImageDescriptor()setsconversionFormatfor storage images; the shader store path then reachesPackImageTexel()/EmitFormatStoreComponent(). Non-storage images can retain the native B10G11R11 view. Could you share which descriptor/resource class produced the measured nativeOpImageWritepath for format 36? That will show whether the gap is specifically in a storage mode not covered by this conversion or in a different write path. I have not started a patch, to avoid overlapping the planned 16-bit change.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T04:54:21Z.
No PR has appeared for the 16-bit storage-image subset, and I have not seen a reply to my earlier coordination questions. I am starting a focused implementation for
16_FLOAT,16_16_FLOAT, and16_16_16_16_FLOAT, keeping format 36 out of scope while its reported nativeOpImageWritepath remains unclear. If you already have a branch for the 16-bit work, please link it so we can coordinate or use the stronger patch.Imported from boykopovar/AnyPS5. Originally posted by ryanc2112 on 2026-10-21T08:18:09Z.
Thanks @MarcZX10 — I haven't started a branch, so go ahead with the 16-bit subset and I'll drop my claim. Once your PR is up I'll run the focused tests on main and the PR on RADV (RX 570, Polaris, Linux) under Khronos validation and post the results. On format 36: in the code
Format11_11_10Floatis 36 andFormat10_11_11Floatis 43 (BufferFormat.hpp:45,52). 36 is not remapped and still writes through the nativeB10G11R11_UFLOAT_PACK32view, so the issue's report holds; #8898 now covers it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T09:16:49Z.
The 16-bit storage-image subset is now up as PR #8998: https://github.com/boykopovar/AnyPS5/pull/8998. It covers 16_FLOAT, 16_16_FLOAT and 16_16_16_16_FLOAT; format 36/43 remains out of this change as discussed. The focused Linux target builds here, but this host lacks BMI1/BMI2, LZCNT, MOVBE, AVX2 and FMA, so the execution test aborts at CPU validation before Vulkan. Your offered RADV/Polaris run would provide the missing GPU validation if you still have time.
Imported from boykopovar/AnyPS5. Originally posted by SirDarky on 2026-10-21T14:05:05Z.
Measured on RDNA1 (gfx1010, AMD Radeon RX 5700 XT), the PS5's gfx10.1 family: the same rule as on your gfx1031, round toward zero with a finite overflow to the largest finite value, in all five formats.
Method. My own probe, since
float_store.pyisn't posted: raw ISA through the HIP runtime of AMD's Windows driver withtools/hw-oracle/template.s.image_store v[4:7], v[30:31], s[24:31] dmask:0xf dim:SQ_RSRC_IMG_2D unorm glcwrites through a linear one-row 2D T# (SW_MODE0,DST_SELX,Y,Z,W) of each format. The same lane then reads the texel's raw bytes back with aglc dlcglobal load afters_waitcnt_vscntandbuffer_gl0_inv/buffer_gl1_inv. That's 48 f32 values with every channel of a texel set to the same value: signed zeros, ±1, f16 ties and near-ties around 1 + 2^-11 and 1 + 3·2^-11, 65504 / 65519.99 / 65520 / 65520.01 / 65535 / 65536 and their negatives, ±1e6, ±inf, the largest finite f32, quiet and signaling NaNs with payloads, values at and below the f16 normal and denormal limits, the smallest f32 denormal, π and ±1/3. I ran two mode sets, as you did: IEEE 0 with denormals kept, and IEEE 1 with denormals flushed andFP16_OVFL1. Every stored word is identical between them.16_FLOAT(13)16_16_FLOAT(29)16_16_16_16_FLOAT(71)B10G11R11_UFLOAT_PACK32layout, and format 43 is R10 G11 B11. Negative values store 0 in both.StoreTexelentry. WithDST_SELX,Y,Z,W,16_16_FLOATwrites channel 1 from the W slot (4.0), and with X,Y,0,1 from the Y slot. That is adriadam10's gfx1035 result from #944, now on gfx1010 too.So the rule #8998 implements for the 16-bit formats, and the one #8898 covers for format 36, also hold on gfx10.1. gfx1013 itself is still not measured.
Probe, Windows runner and raw results: https://gist.github.com/SirDarky/69f5c4e1bf7962885b776f39f9ebfe40 (the runner expects
tools/hw-oracle/template.sone directory up, as in a checkout).AI-assisted: yes (Claude Code). I ran the probe on my machine.