AGC: f32 image stores into 16-bit and small float formats are rounded by the host; RDNA 2 rounds toward zero and saturates #8282

Closed
opened 2026-10-20 08:31:55 +00:00 by thuanquang · 9 comments
thuanquang commented 2026-10-20 08:31:55 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-20T08:31:55Z.


What

An f32 image_store into 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) and 10_11_11_FLOAT (36) through B10G11R11_UFLOAT — go to OpImageWrite as f32, and the host picks the rounding and the overflow. Formatted buffer stores of the same formats, and 11_11_10_FLOAT (43) image stores, already convert in the shader toward zero (#330, the 11_11_10 entry in libSceAgcDriver.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 glc through 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 and FP16_OVFL 1. Both gave the same results.

format rows round toward zero, finite overflow → largest finite, ±inf and NaN kept round to nearest even, overflow → inf
16_FLOAT (13) 38 38 29
16_16_FLOAT (29) 76 76 58
16_16_16_16_FLOAT (71) 152 152 116
10_11_11_FLOAT (36) 114 114 83
11_11_10_FLOAT (43) 114 114 83

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_10 image 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 - inf or inf * 0 then 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's F32BitsToSmallFloatRtz, which #330 measured) and store through a UINT view, as 11_11_10 already 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5938544398 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8282). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-20T08:31:55Z. --- ### What An f32 `image_store` into 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) and `10_11_11_FLOAT` (36) through `B10G11R11_UFLOAT` — go to `OpImageWrite` as f32, and the host picks the rounding and the overflow. Formatted buffer stores of the same formats, and `11_11_10_FLOAT` (43) image stores, already convert in the shader toward zero (#330, the 11_11_10 entry in `libSceAgcDriver.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 glc` through 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 and `FP16_OVFL` 1. Both gave the same results. | format | rows | round toward zero, finite overflow → largest finite, ±inf and NaN kept | round to nearest even, overflow → inf | |---|---|---|---| | `16_FLOAT` (13) | 38 | 38 | 29 | | `16_16_FLOAT` (29) | 76 | 76 | 58 | | `16_16_16_16_FLOAT` (71) | 152 | 152 | 116 | | `10_11_11_FLOAT` (36) | 114 | 114 | 83 | | `11_11_10_FLOAT` (43) | 114 | 114 | 83 | 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_10` image 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 - inf` or `inf * 0` then 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`'s `F32BitsToSmallFloatRtz`, which #330 measured) and store through a UINT view, as `11_11_10` already 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.
ryanc2112 commented 2026-10-20 09:07:51 +00:00 (Migrated from github.com)
Author
Contributor

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6287493484 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8282#issuecomment-6287493484). Originally posted by [ryanc2112](https://github.com/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.
yangxianshuo666 commented 2026-10-20 09:28:09 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by yangxianshuo666 on 2026-10-20T09:28:09Z.


Could you please adapt it for GTA 6? (LOL)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6287849998 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8282#issuecomment-6287849998). Originally posted by [yangxianshuo666](https://github.com/yangxianshuo666) on 2026-10-20T09:28:09Z. --- Could you please adapt it for GTA 6? (LOL)
MarcZX10 commented 2026-10-20 20:45:12 +00:00 (Migrated from github.com)
Author
Contributor

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6301087059 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8282#issuecomment-6301087059). Originally posted by [MarcZX10](https://github.com/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.
MarcZX10 commented 2026-10-20 21:54:58 +00:00 (Migrated from github.com)
Author
Contributor

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 through UINT) from 11_11_10_FLOAT (format 43, whose image-store conversion is already in shader). Your comment says you will leave 11_11_10_FLOAT (36) for follow-up; could you confirm whether you meant 10_11_11_FLOAT (36)? I have not started implementation, so your proposed 16-bit work remains unblocked.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6302542195 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8282#issuecomment-6302542195). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T21:54:58Z. --- Small scope clarification before a patch: the issue distinguishes `10_11_11_FLOAT` (format 36, currently remapped through `UINT`) from `11_11_10_FLOAT` (format 43, whose image-store conversion is already in shader). Your comment says you will leave `11_11_10_FLOAT (36)` for follow-up; could you confirm whether you meant `10_11_11_FLOAT (36)`? I have not started implementation, so your proposed 16-bit work remains unblocked.
MarcZX10 commented 2026-10-21 01:31:18 +00:00 (Migrated from github.com)
Author
Contributor

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) returns Format32UInt, and inspectImageDescriptor() sets conversionFormat for storage images; the shader store path then reaches PackImageTexel() / EmitFormatStoreComponent(). Non-storage images can retain the native B10G11R11 view. Could you share which descriptor/resource class produced the measured native OpImageWrite path 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6305776519 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8282#issuecomment-6305776519). Originally posted by [MarcZX10](https://github.com/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)` returns `Format32UInt`, and `inspectImageDescriptor()` sets `conversionFormat` for storage images; the shader store path then reaches `PackImageTexel()` / `EmitFormatStoreComponent()`. Non-storage images can retain the native B10G11R11 view. Could you share which descriptor/resource class produced the measured native `OpImageWrite` path 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.
MarcZX10 commented 2026-10-21 04:54:21 +00:00 (Migrated from github.com)
Author
Contributor

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, and 16_16_16_16_FLOAT, keeping format 36 out of scope while its reported native OpImageWrite path 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6308371966 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8282#issuecomment-6308371966). Originally posted by [MarcZX10](https://github.com/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`, and `16_16_16_16_FLOAT`, keeping format 36 out of scope while its reported native `OpImageWrite` path 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.
ryanc2112 commented 2026-10-21 08:18:09 +00:00 (Migrated from github.com)
Author
Contributor

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_10Float is 36 and Format10_11_11Float is 43 (BufferFormat.hpp:45,52). 36 is not remapped and still writes through the native B10G11R11_UFLOAT_PACK32 view, so the issue's report holds; #8898 now covers it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6311384305 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8282#issuecomment-6311384305). Originally posted by [ryanc2112](https://github.com/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_10Float` is 36 and `Format10_11_11Float` is 43 (`BufferFormat.hpp:45,52`). 36 is not remapped and still writes through the native `B10G11R11_UFLOAT_PACK32` view, so the issue's report holds; #8898 now covers it.
MarcZX10 commented 2026-10-21 09:16:49 +00:00 (Migrated from github.com)
Author
Contributor

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6312443352 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8282#issuecomment-6312443352). Originally posted by [MarcZX10](https://github.com/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.
SirDarky commented 2026-10-21 14:05:05 +00:00 (Migrated from github.com)
Author
Contributor

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.py isn't posted: raw ISA through the HIP runtime of AMD's Windows driver with tools/hw-oracle/template.s. image_store v[4:7], v[30:31], s[24:31] dmask:0xf dim:SQ_RSRC_IMG_2D unorm glc writes through a linear one-row 2D T# (SW_MODE 0, DST_SEL X,Y,Z,W) of each format. The same lane then reads the texel's raw bytes back with a glc dlc global load after s_waitcnt_vscnt and buffer_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 and FP16_OVFL 1. Every stored word is identical between them.

format channel values round toward zero, finite overflow → largest finite, ±inf and NaN kept round to nearest even, overflow → inf
16_FLOAT (13) 48 48 34
16_16_FLOAT (29) 96 96 68
16_16_16_16_FLOAT (71) 192 192 136
36 144 144 111
43 144 144 111
  • The same examples as on gfx1031: 65520.0 stores 0x7bff and 1 + 3·2^-11 stores 0x3c01. 65519.99 also stores 0x7bff, -65520 stores 0xfbff, and 1.5·2^-25 and the smallest f32 denormal store 0.
  • NaNs keep the sign and the top payload bits: 0x7fc12345 stores 0x7e09 and 0xffc00000 stores 0xfe00. A signaling 0x7f800001 stores 0x7c01, a NaN that is not quieted, rather than inf.
  • Bit layout, low to high: format 36 is R11 G11 B10, the B10G11R11_UFLOAT_PACK32 layout, and format 43 is R10 G11 B11. Negative values store 0 in both.
  • One extra row with different channels (1, 2, 3, 4) showed the two-channel case of the existing StoreTexel entry. With DST_SEL X,Y,Z,W, 16_16_FLOAT writes 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.s one directory up, as in a checkout).

AI-assisted: yes (Claude Code). I ran the probe on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6318055185 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8282#issuecomment-6318055185). Originally posted by [SirDarky](https://github.com/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.py` isn't posted: raw ISA through the HIP runtime of AMD's Windows driver with `tools/hw-oracle/template.s`. `image_store v[4:7], v[30:31], s[24:31] dmask:0xf dim:SQ_RSRC_IMG_2D unorm glc` writes through a linear one-row 2D T# (`SW_MODE` 0, `DST_SEL` X,Y,Z,W) of each format. The same lane then reads the texel's raw bytes back with a `glc dlc` global load after `s_waitcnt_vscnt` and `buffer_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 and `FP16_OVFL` 1. Every stored word is identical between them. | format | channel values | round toward zero, finite overflow → largest finite, ±inf and NaN kept | round to nearest even, overflow → inf | |---|---|---|---| | `16_FLOAT` (13) | 48 | 48 | 34 | | `16_16_FLOAT` (29) | 96 | 96 | 68 | | `16_16_16_16_FLOAT` (71) | 192 | 192 | 136 | | 36 | 144 | 144 | 111 | | 43 | 144 | 144 | 111 | - The same examples as on gfx1031: 65520.0 stores 0x7bff and 1 + 3·2^-11 stores 0x3c01. 65519.99 also stores 0x7bff, -65520 stores 0xfbff, and 1.5·2^-25 and the smallest f32 denormal store 0. - NaNs keep the sign and the top payload bits: 0x7fc12345 stores 0x7e09 and 0xffc00000 stores 0xfe00. A signaling 0x7f800001 stores 0x7c01, a NaN that is not quieted, rather than inf. - Bit layout, low to high: format 36 is R11 G11 B10, the `B10G11R11_UFLOAT_PACK32` layout, and format 43 is R10 G11 B11. Negative values store 0 in both. - One extra row with different channels (1, 2, 3, 4) showed the two-channel case of the existing `StoreTexel` entry. With `DST_SEL` X,Y,Z,W, `16_16_FLOAT` writes 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.s` one directory up, as in a checkout). AI-assisted: yes (Claude Code). I ran the probe on my machine.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#8282
No description provided.