Skip to content

fix(shader): choose unary f32/f16 special results on the bits, as RDNA does - #537

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
adriadam10:test/vop1-float-unary
Oct 5, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
adriadam10:test/vop1-float-unary

Conversation

@adriadam10

@adriadam10 adriadam10 commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

What

The unary float ops v_ceil, v_floor, v_trunc, v_rndne, v_fract, v_sqrt, v_rsq, v_rcp, v_log, v_exp, v_sin, v_cos (f32 and f16), plus v_rcp_iflag_f32 and v_frexp_mant_f32, left their special results to the driver. Vulkan doesn't specify those results (NaN payloads, InverseSqrt/Log2 at 0, FDiv by 0 or inf), and on local drivers several were wrong:

  • A signaling NaN came back unquieted (RADV, every f32 op and v_frexp_mant_f32), and lavapipe dropped the NaN sign and payload on log/sin/cos, f32 and f16.
  • Invalid results (log/sqrt/rsq of a negative, fract/sin/cos of inf) were +NaN (0x7fc00000) on lavapipe. The hardware gives -NaN (0xffc00000, f16 0xfe00).
  • f32 sin at whole and half cycles and cos at quarter cycles returned values like -8.7e-8 where the hardware gives +0. The f16 path already had this rule.
  • v_fract_f16(-2^-14) rounded to 1.0. The hardware stops at 0x3bff, as f32 stops at 0x3f7fffff.

A shared helper now picks these results on the bits, from the source bits after neg/abs. Finite results still come from the driver's approximation. float16Trig is merged into float16Unary. f16 results go through applyF16ResultModifiers from #323, so clamp/omod behave as they do there.

Behaviour measured on HW (RDNA2, gfx1035, IEEE=1, f32 denormals on)

  • NaN source: the result is the source with the quiet bit set (f32 | 0x400000, f16 | 0x200), sign kept, for every op here.
  • Invalid: 0xffc00000 / 0xfe00.
  • rcp(±0) = ±inf, rcp(±inf) = ±0; rsq(±0) = ±inf, rsq(+inf) = +0; sqrt(±0) = ±0, sqrt(+inf) = +inf; log(±0) = -inf, log(1) = +0, log(+inf) = +inf; exp(±0) = 1, exp(x ≥ 128) = +inf, exp(x < -126) = +0 (f32 denormal results are flushed, the same assumption as the existing denormal input flush of these ops); fract(-0) = +0; sin(±0) = ±0.
  • f32 denormal inputs of v_rcp, v_rcp_iflag, v_rsq, v_sqrt, v_log and v_exp count as zero with their sign, in every mode (IEEE 0/1, denormals on/off): rcp/rsq give ±inf, sqrt ±0, log -inf (also for a negative denormal), exp 1. f16 ops keep denormals.
  • With IEEE=0 everything above is the same except that a signaling NaN comes back unquieted (113 of the test's cells). The recompiler doesn't read the mode, and this keeps the IEEE=1 result, like the packed f16 ops on main.
  • f16 results keep the high 16 bits of the destination.
  • Finite results of the approximate ops are within ~1 ulp of the exact value (f32 2^-23, f16 2^-11). f32 sin/cos lose accuracy beyond about ±2^20 cycles (the input is converted with limited precision). This is recorded in TechnicalDebt, and the test keeps f32 trig inputs below 256 cycles.

Tested

New execution test agc_driver_vop1_float_unary_tests runs the 27 opcodes (15 f32, 12 f16) on two inputs per lane, 54 results × 32 rows. Rows were picked by class (sign, zero, inf, quiet/signaling NaN, invalid, magnitude bands, zero/inf results), plus fixed rows for sNaN, -inf/-0, fract(-2^-30) and f32 denormals (0x807fffff, 0x007fffff). Expected values are what the hardware returns, and a Python model matches all of them. Exact ops and special results are compared bit for bit. Finite results of the approximate ops are compared with tolerances based on the Vulkan precision table: rcp/rsq/sqrt 2^-20 relative, log 2^-21 absolute or 2^-20 relative, exp (4+2|x|) ulp, f32 sin/cos 2^-11 absolute, f16 2^-9 relative or 2^-10 absolute for sin/cos. Denormal results are excluded, and the denormal row is only checked on the six ops that flush (on the others the result depends on the denormal mode).
It passes on RADV, local lavapipe and CI's lavapipe (Mesa 25.2.8). The test fails with each of these changes: NaN not quieted or left to the driver (f32, f16), positive invalid NaN, fract reaching 1 (f32 on lavapipe, f16 on both), sin/cos cardinals off (lavapipe; RADV happens to return them exactly), sign of sin(-0), and v_frexp_mant_f32 NaN. The zero/inf pins for rcp/rsq/sqrt/log/exp already come out right on RADV and lavapipe, which is why they're picked on the bits for other drivers. Setting each pin to a wrong value fails the test, so every pin is covered (except exp(0), which falls inside the exp tolerance). Without the denormal flush the test fails (sqrt(-denormal) gives 0xffc00000, and 0x807fffff with the sign kept but not flushed); RADV and lavapipe already flush the FDiv input of rcp_iflag, and exp of a denormal rounds to 1 anyway, so those two can't fail locally.
agc_driver_float16_result_modifiers_tests (#323) still passes. The full Release ctest passes except agc_driver_pixel_helper_lanes, agc_driver_global_load_addtid and agc_driver_vop3_carry_out (wave32 lane 32 on RADV's 64-wide subgroup), which also fail on main on local RADV.

Checklist

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks, the NaN, invalid, zero and inf picks match the ISA functional examples, and reading the f32 source as bits (so neg on a NaN keeps its sign) is a nice fix. Two things before it can go in:

  1. f32 denormal inputs. The RDNA2 ISA says V_EXP_F32, V_LOG_F32, V_RCP_F32, V_RSQ_F32 and V_SQRT_F32 flush denormals, and main's emitters already flush their input to signed zero (EmitFlushF32DenormToSignedZero). unaryFloatSpecials takes zero and negative from the unflushed bits, though. So a negative denormal gives 0xffc00000 for log, rsq and sqrt, where the hardware gives -inf, -inf and -0 (for sqrt that is a change from main, which gives -0). A positive denormal skips the rcp/rsq/log pins, so the result comes from FDiv/InverseSqrt/Log2 of 0, which is the undefined case the pins are there for. Could you take zero/negative from the flushed value for those five ops (magnitude below 0x00800000 counts as zero, sign kept), and add a denormal row for them? The f16 path is fine, since the f16 ops keep denormals.
  2. agc_driver_float16_result_modifiers (from fix(shader): apply clamp but not omod to f16 results, as RDNA does #323) fails on my NVIDIA machine: "lane 7 sin_mul2 is 0x00000003, expected 0x00000006". Input 0x0001 gives sin(2pi * 2^-24), about 6 f16 denormal ulps. That value comes straight from the driver's sine, and NVIDIA's sine has an absolute error bound larger than the value itself (Vulkan only asks for 2^-11 absolute), so 0x0003 is a valid result there. Neither this commit nor fix(shader): choose packed f16 NaN results on the bits, as RDNA does #533 touches it. Earlier the test stopped at lane 4 (the NaN payload), which is why it didn't show up then. Could the sin columns use an input whose sine is well above that error (around 0.25 to 0.5, so mul:2 applied or ignored is still obvious) and compare with a tolerance like Vop1FloatUnary does? I'll leave the same note on fix(shader): apply clamp but not omod to f16 results, as RDNA does #323.

agc_driver_vop1_float_unary itself passes on NVIDIA and fails on main there. This changes every unary float op PPSA21564 uses, so once it's updated I'll run it through my PPSA21564 check before merging.

@adriadam10
adriadam10 force-pushed the test/vop1-float-unary branch from 04d8193 to dd9431a Compare October 4, 2026 21:42
@adriadam10

Copy link
Copy Markdown
Collaborator Author

Thanks, both done (rebased on current main, last commit amended):

  1. Denormal inputs: v_rcp, v_rcp_iflag, v_rsq, v_sqrt, v_log and v_exp now take zero/negative from the flushed value (magnitude below 0x00800000 counts as zero, sign kept), and sqrt of a zero returns the sign instead of the source bits. I measured it on the hardware first, in all four IEEE/denormal mode combinations: rcp/rsq ±inf, sqrt ±0, log -inf (also for a negative denormal), exp 1, the same in every mode. v_rcp_iflag_f32 flushes too, so it's included. New fixed row 0x807fffff / 0x007fffff, checked only on those six ops (on the others the result depends on the denormal mode). Without the fix the test fails on lane 0 (sqrt_f32 gives 0xffc00000; with the sign but not the flush, 0x807fffff). The rcp_iflag and exp parts can't fail locally: RADV and lavapipe already flush the FDiv input, and exp2 of a denormal rounds to 1 anyway.
  2. The sin columns: fixed in fix(shader): apply clamp but not omod to f16 results, as RDNA does #323 (now in this branch too). They're compared within 2^-10 absolute, while the ±0 the cardinal pins choose stays bit-exact.

While rerunning the oracle I also ran IEEE=0: everything matches except signaling NaNs, which come back unquieted there (113 cells). The PR keeps the IEEE=1 quieting, as main does for the packed f16 ops. Noted in the description.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks, both points are fixed. unaryFloatSpecials now takes zero from a magnitude below 0x00800000 for rcp, rcp_iflag, rsq, sqrt, log and exp, and negative excludes it, so a negative denormal gives -inf for rsq and log and -0 for sqrt, and a positive one hits the rcp/rsq/log/exp pins instead of reaching the driver's undefined case. The f16 path is unaffected, since a widened f16 value is never an f32 denormal. The new 0x807fffff / 0x007fffff row is checked only on those six ops (bits 14 to 25 of Checked), which is the right scope, and #323's sine change comes through unchanged.

agc_driver_vop1_float_unary and agc_driver_float16_result_modifiers both pass on my NVIDIA machine on current main, and agc_driver_vop1_float_unary fails on main's code (lane 1 ceil_f32 gives 0x7fffffff where 0x7fc00001 is expected).

One small request, not blocking: the description says the sNaN quieting is the IEEE=1 result and that IEEE=0 leaves 113 cells unquieted. Could that go into TechnicalDebt as a line like the one on #501? Main's unary f32 ops currently pass a signalling NaN through unquieted on RADV, so this is a change in behaviour that the recompiler can't check against the mode, and #508 went the other way (NaN unchanged, IEEE=0). A line makes the split visible until MODE is read.

This lands after #323. Since it changes every unary float op PPSA21564 uses, I'll run it through my PPSA21564 check together with #323 and merge both if it's clean.

adriadam10 and others added 4 commits October 5, 2026 03:38
writeF16 dropped the clamp bit, so VOP3/SDWA f16 results with clamp
(v_rcp_f16, v_fma_f16, v_cvt_f16_f32, v_add_f16_sdwa, ...) were not
saturated. Clamp now limits to [0, 1] with NaN and -0 going to +0.
The f16 sqrt/rsq/log and sin/cos paths applied omod, which the
hardware ignores on f16 results in the default float mode, and
v_cvt_pkrtz_f16_f32 applied clamp and omod to its inputs, which the
hardware ignores as well.

Co-Authored-By: Claude <noreply@anthropic.com>
…yload

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…A does

v_ceil/floor/trunc/rndne/fract/sqrt/rsq/rcp/rcp_iflag/log/exp/sin/cos
(f32 and f16) and v_frexp_mant_f32 left NaN, invalid, zero and infinite
results to the driver: signalling NaNs came back unquieted, lavapipe lost
the NaN sign and payload, invalid results were +NaN instead of -NaN, f32
sin/cos at whole and half cycles returned tiny values instead of +0, and
v_fract_f16 of a tiny negative rounded up to 1.0.

Adds an execution test for the 27 opcodes with expected values from
hardware; approximate ops are compared with tolerances from the Vulkan
precision table.

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the test/vop1-float-unary branch from dd9431a to f3b74e2 Compare October 5, 2026 01:38
@adriadam10

Copy link
Copy Markdown
Collaborator Author

Rebased on current main: the only conflict was the neighbouring TechnicalDebt line (--to-intel RDPRU/MCOMMIT, now main's wording); the unary-ops line is unchanged. #323's three commits are patch-identical to #323's head. agc_driver_vop1_float_unary_tests passes on RADV and lavapipe, full ctest green on RADV apart from the known agc_driver_pixel_helper_lanes.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 5, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for the rebase. #323's three commits are patch-identical, the unary commit only changed in context, and the TechnicalDebt line is unchanged next to main's new --to-intel wording.

One merge-order detail: #323's own branch is still at cc69286 (the old base), while this branch carries rebased copies of those commits. If #323 is merged first as it stands, this PR then conflicts in FloatInstructions.cpp. Could you push the rebased commits to #323's branch too (6686bff is the one this branch carries)? Then #323 followed by this one merges cleanly. I checked that order locally.

agc_driver_vop1_float_unary passes here on the merged branch. These special results apply to v_rcp_f32, v_rsq_f32, v_sqrt_f32 and friends, which PPSA21564 uses in nearly all of its shaders, so #323 and this one go through my PPSA21564 check before merging.

@adriadam10

Copy link
Copy Markdown
Collaborator Author

Done: #323's branch is now at 6686bff, the same three commits this branch carries, so #323 followed by this one merges cleanly.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks. #323's branch is at 6686bff now, so this branch is #323 plus one commit, and #323, then this one, then #567 merges cleanly at every step. The full ctest passes here with the three merged.

These go through my PPSA21564 check before merging (v_rcp_f32, v_rsq_f32, v_sqrt_f32 and friends are in 5,470 of the 5,688 shaders I have dumped). Ready to merge from my side once that's done.

Gated on PPSA21564 on top of #323, with #567: no visual or FPS change.

@oneandonlydean
oneandonlydean merged commit dbfdcb1 into boykopovar:main Oct 5, 2026
3 checks passed
@adriadam10
adriadam10 deleted the test/vop1-float-unary branch October 5, 2026 06:47
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 5, 2026
The unary f32/f16 ops pick their special results on the source bits since
boykopovar#537. The emitted checks cost about 39 KB of NVIDIA code in PPSA21564's
compute program 0x555f41f00. This keeps every result and does less work:

- The IR now pins every result the backend's denormal flush could change
  (rcp, rsq, sqrt, log and exp of an f32 denormal), so the flush in front
  of FDiv, InverseSqrt, Sqrt, Exp2 and Log2 is dropped. The FragCoord.w
  reciprocal, the only other FPRecip32 user, flushes in the IR instead.
- f32 NaN sources are found with FPIsNan32. Vulkan gives OpFUnordNotEqual
  a correct result and the module declares SignedZeroInfNanPreserve.
- The invalid result and the NaN result are two plain selects in a row,
  with no LogicalOr and no extra select between the two specials.
- negative and nonzero is one compare (bits > 0x807fffff); exp overflow
  is one signed compare and exp underflow one unsigned compare.
- fract's clamp is UMin32.
- sin no longer keeps the signed zero in the backend (the IR pins it),
  and sin/cos reduce with Fract alone: Fract is correctly rounded, so it
  is already 0 for |x| >= 2^23, and inf and NaN are pinned in the IR.
adriadam10 pushed a commit that referenced this pull request Oct 13, 2026
…esults never use

The SPIR-V emitters of FPRecip32, FPRecipSqrt32, FPSqrt, FPExp2 and FPLog2
flushed a denormal input to its signed zero before the host operation.
Since #537, unaryFloatSpecials replaces the host result for every input
below 2^-126 with the hardware's result for a zero of the same sign: rcp
and rsq give a signed infinity, sqrt the signed zero, log -inf and exp 1.0.
floatUnary and float16Unary both go through it, so the flushed input could
only change a value that is then discarded. v_rcp_iflag_f32 gets the same
special values and already went without the flush.

The pixel prologue computes PositionW as FPRecip32 of FragCoord.w without
those special values, so it now flushes FragCoord.w in the IR first and
gives the same result as before.
RINNECODER referenced this pull request in RINNECODER/AnyPS5 Oct 13, 2026
…esults never use

The SPIR-V emitters of FPRecip32, FPRecipSqrt32, FPSqrt, FPExp2 and FPLog2
flushed a denormal input to its signed zero before the host operation.
Since #537, unaryFloatSpecials replaces the host result for every input
below 2^-126 with the hardware's result for a zero of the same sign: rcp
and rsq give a signed infinity, sqrt the signed zero, log -inf and exp 1.0.
floatUnary and float16Unary both go through it, so the flushed input could
only change a value that is then discarded. v_rcp_iflag_f32 gets the same
special values and already went without the flush.

The pixel prologue computes PositionW as FPRecip32 of FragCoord.w without
those special values, so it now flushes FragCoord.w in the IR first and
gives the same result as before.

(cherry picked from commit 1dc99ba)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RINNECODER referenced this pull request in RINNECODER/AnyPS5 Oct 13, 2026
* perf(shader): search a bindless image table once per access

EmitImage selects the table slot of a bindless image before it branches over
the image's runtime modes, and EmitImageMode then searched the table again in
every mode arm. Each search is a binary search of dependent flattened_srt
loads, so every bindless sample ran two. The mode arms now take the selection
EmitImage already made; the modes copy the base image, so the mapping offset,
root and iteration count the search reads are the same.

(cherry picked from commit d759a43)

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

* fix(agc,shader): prime the two host shared mutexes added after 48dcaac

Commit 48dcaac introduced PrimedSharedMutex and converted every host std::shared_mutex that existed at the time, because winpthreads initializes a static rwlock on first use and a concurrent first lock returns EINVAL, which std::shared_mutex ignores (docs/dev/TechnicalDebt.md:10).

Two host mutexes were added afterward and missed the conversion:
- Recompiler.cpp registrationModule() static mutex (added by baf3437)
- MultisampleTarget.cpp guardedMutex() static mutex (added by d109f39)

Apply the same priming. Recompiler.cpp reuses the PrimedSharedMutex already defined in that translation unit; MultisampleTarget.cpp gets the identical local helper to match the existing inline precedent.

Tested: Windows 11 x64, WinLibs GCC 15.2.0 (matches CI). Compiled Recompiler.cpp.obj and all three MultisampleTarget.cpp.obj targets with the project build flags; check_conventions.py passes.

(cherry picked from commit 4d37c93)

Fork: MultisampleTarget.cpp hunk left to the AGC slice.

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

* perf(shader): drop the input flush that rcp, rsq, sqrt, exp and log results never use

The SPIR-V emitters of FPRecip32, FPRecipSqrt32, FPSqrt, FPExp2 and FPLog2
flushed a denormal input to its signed zero before the host operation.
Since #537, unaryFloatSpecials replaces the host result for every input
below 2^-126 with the hardware's result for a zero of the same sign: rcp
and rsq give a signed infinity, sqrt the signed zero, log -inf and exp 1.0.
floatUnary and float16Unary both go through it, so the flushed input could
only change a value that is then discarded. v_rcp_iflag_f32 gets the same
special values and already went without the flush.

The pixel prologue computes PositionW as FPRecip32 of FragCoord.w without
those special values, so it now flushes FragCoord.w in the IR first and
gives the same result as before.

(cherry picked from commit 1dc99ba)

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

* fix(shader): split a BDA span read's in-place loads from its fallback

On an RTX 3060 (Windows, driver 591.86) a dispatch never finishes when
the lanes of read_bda_span split between its in-place dword loads and
its per-dword byte fallback, which calls read_bda_dword_bytes: Windows
resets the GPU and the device is lost. The two were the arms of one
selection in the DontInline function. They are now two selections, the
loads under the span's condition and the fallback under its negation,
joined after both. Loads, lookups, faults and stops are unchanged for
every lane; only the SPIR-V control-flow shape changes (SPIR-V
specification 2.11, structured control flow). Every stage except mesh
shaders is emitted as SPIR-V 1.3, and OpSelect chooses between
composites with a scalar condition only from 1.4 on, so the join stays
a selection.

The same hang and fix were reported in boykopovar#3291 on an RTX 4060 Laptop GPU
(Windows, driver 591.86) and an RTX 5060 (Linux, driver 590.48.01). An
RTX 4070 Laptop GPU on driver 616.92 does not hang with either shape.
The driver-side cause is unknown, so the shape is recorded in
docs/dev/debt/shader.md.

On main the hang fails nine tests on the RTX 3060, in two ways.
agc_driver_{flat,global}_loads{,_x2_x3,_x4} and
agc_driver_flat_apertures_{2,5} abort after 64 to 71 s: the lost batch
keeps its lease, so teardown waits 60 s for the pinned guest allocation.
agc_driver_pixel_interlock fails after about 4 to 7 s with
vkDeviceWaitIdle returning VK_ERROR_DEVICE_LOST (-4) and never reaches
the pin wait. All nine pass with the change.

Fixes boykopovar#3291

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

(cherry picked from commit f1b2e60)

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

* fix(shader): load a BDA span in place from its own function

read_bda_span chooses between the span's in-place dword loads and its
per-dword byte fallback, which calls read_bda_dword_bytes. Each shape of
that choice so far hangs a group of NVIDIA drivers: a dispatch never
finishes and the device is lost.

As the two arms of one selection, with the loads emitted in the arm,
it hung drivers 591.86 and 590.48.01 when lanes took both arms (boykopovar#3291).
As two selections, the loads under the span's condition and the fallback
under its negation (boykopovar#4759), it hangs 595.97, 596.36, 610.62, 610.74 and
610.57.04 (boykopovar#4975).

The loads now live in load_bda_span, a DontInline function that calls
nothing, and read_bda_span is one selection again: one arm calls
load_bda_span, the other is the fallback as before. Probe, loads,
lookups, faults and stops are unchanged for every lane.

On an RTX 4090 (Linux, driver 610.57.04) the two-selection shape hangs
agc_driver_scalar_wide_loads and agc_driver_flat_apertures_0..13 in a
build with SPIRV-Tools, and agc_driver_bda_span_reads and
agc_driver_pixel_interlock in a build without. All pass with this
change in both builds. Drivers 591.86, 590.48.01, 595.97, 596.36,
610.62 and 610.74 are not tested; a shape with the loads in their own
DontInline function was reported passing on 591.86 in boykopovar#3291.

agc_shader_memory now requires that a span read function holds no load
and calls its load function once, and that the load function holds the
four loads and no call.

Refs boykopovar#4975

(cherry picked from commit 8c04efc)

Fork: libSceAgc* and docs/dev/debt hunks dropped (AGC slice / file absent).

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

* perf(shader): convert f16 operands with UnpackHalf2x16 where f16 denormals are kept

Since boykopovar#1463, every f16 operand read decodes sign, exponent and mantissa
with integer operations, 8 to 12 instructions more per read than
UnpackHalf2x16 on NVIDIA. The decode works around an AMD Windows driver
that folds the mask of a byte-selected half into UnpackHalf2x16.

A new target flag, float16DenormPreserve, is set when the device reports
shaderDenormPreserveFloat16 and denormBehaviorIndependence ALL, the same
rule as float64DenormPreserve. With it, EmitF16BitsToF32 uses
UnpackHalf2x16 and declares DenormPreserve for 16-bit floats, under
which SPV_KHR_float_controls keeps unpacked subnormal halves. NVIDIA
returns the default NaN for every NaN half, so the NaN bits are rebuilt
from the half: its sign at bit 31, its payload at bits 22:13. The
DenormPreserve 16 mode is declared once, shared with the native f32 to
f16 conversion. Without the flag (lavapipe; RADV reports 32_BIT_ONLY)
the integer decode stays. Halves of fields narrower than 16 bits, such
as SDWA byte selects, keep the integer decode on every device.

The flag is serialized (request version 17) and part of the cache key.

New test agc_driver_f16_to_f32_unpack converts all 65,536 halves, with
nonzero high bits, through v_cvt_f32_f16, and byte-selected halves
through v_add_f16 SDWA, with each decode the device supports, and
compares the bits with an exact decode. agc_driver_f16_to_f32_unpack_spirv
checks which decode the SPIR-V uses with and without the flag.

(cherry picked from commit e4f212b)

Fork: request version 21 kept from upstream, on top of version 20 (paClVsOutCntl) from the AGC slice. The Vulkan device half (VulkanDevice.cpp) and the libSceAgcDriver tests are dropped; on Metal float16DenormPreserve stays false, so the integer f16 decode is kept.

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

* perf(shader): skip the f16 NaN rebuild for operands that are only compared

With float16DenormPreserve, EmitF16BitsToF32 rebuilds the bits of a NaN
half after UnpackHalf2x16, because NVIDIA returns the default NaN and
Intel quiets it. When every use of the converted operand is an f32
comparison or a NaN test, directly or through abs and neg, only whether
it is NaN matters, so the conversion returns UnpackHalf2x16's result as
is. v_cmp_*_f16 goes from 11.5 to 4 SASS on an RTX 4060.

agc_driver_f16_to_f32_unpack adds v_cmp_u_f16 and v_cmp_lt_f16 over all
65,536 halves with each decode the device supports. Its SPIR-V check
requires the v_cvt_f32_f16 conversion to rebuild the NaN bits and the
compared conversions not to.

(cherry picked from commit 352bf30)

Fork: libSceAgc* and docs/dev/debt hunks dropped (AGC slice / file absent).

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

* fix(shader): keep cube image gradients out of the face coordinate bias

image_sample_d and image_sample_cd on a cube pass their gradients through the
same conversion as the face coordinates, which subtracts 1.0 to move AMD's
[1, 2] face range to [0, 1]. A gradient is a difference of coordinates, so the
bias turned a one-texel gradient into one of about -1 and the sample read the
smallest mip. Gradients now skip the bias.

agc_driver_image_sample_cube_derivatives samples every face of a 16x16 cube at
five levels through image_sample_d and checks the level and face it read.

TechnicalDebt records that the gradient handling follows Mesa and was not
measured on hardware.

(cherry picked from commit 73eaa1f)

Fork: libSceAgc* and docs/dev/debt hunks dropped (AGC slice / file absent).

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

* fix(shader): declare the GDS buffer coherent

GDS is one memory for the whole GPU on AMD hardware: every work-group's
ds_read and ds_write with gds see the others' writes, with no cache in
between. The recompiler keeps it in a storage buffer that was not decorated
Coherent, so on a GPU whose L1 caches storage buffer loads, NVIDIA's from
Turing on among them, a plain GDS read could return a value cached before
another work-group's GDS write. Atomics were not affected. The gds buffer is
now declared Coherent.

verifyCoherentGds in agc_shader_memory compiles a ds_read_b32 and a
ds_write_b32 on GDS and checks that the gds buffer is Coherent.

(cherry picked from commit 0998eb4)

Fork: libSceAgc* and docs/dev/debt hunks dropped (AGC slice / file absent).

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

* perf(shader): reclaim unreachable cached source IR values

(cherry picked from commit 57b2dc8)

Fork: libSceAgc* and docs/dev/debt hunks dropped (AGC slice / file absent).

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

* fix(shader): read the ancillary render target index from Layer when the draw exports it

(cherry picked from commit 7015c04)

Fork: the DrawDecode.cpp line that sets layerExported is in libSceAgcDriver and left to the AGC slice; until it lands layerExported stays false and the ancillary render target index reads as 0, as before. Fork ShaderDiskCache format kept (bumped once at the end of the slice); libSceAgcDriver tests and docs/dev/debt dropped.

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

* fix(shader): serialize the pixel layer export flag from request version 23

main allocates request version 22 to the tessellation patches per group, so a version 22 request has no layer export byte.

(cherry picked from commit de5279b)

Fork: request version 23 kept to match upstream; version 22 (patchesPerGroup, from AGC commit 25a8372) is not in this tree yet, so the fork writes no version 22 field. libSceAgcDriver test hunk dropped.

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

* fix(shader): bump the shader disk cache format for the sync-8 shader slice

The ported recompiler changes add layerExported to the cached pixel info
and change generated shader output, so cached entries from format 31 are
not reused.

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

---------

Co-authored-by: Karan Vora <52519664+karanvora2599@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Mohamed Aziz Hadjkacem <mohamedaziz.hadjkacem21@gmail.com>
Co-authored-by: fdfawef324 <287205748+fdfawef324@users.noreply.github.com>
Co-authored-by: Dean Galvin <dean.galvin@live.com>
Co-authored-by: eljackjoestar-cmd <eljackjoestar@gmail.com>
Co-authored-by: TideOPL <obinewman101@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants