Skip to content

agx: require tied min/max before decoding AGX3 FCMPSEL select immediates as minifloats - #677

Merged
DjDeveloperr merged 4 commits into
aurora-wipfrom
fix/agx3-fcmpsel-untied-immediate
Nov 24, 2026
Merged

DjDeveloperr merged 4 commits into
aurora-wipfrom
fix/agx3-fcmpsel-untied-immediate

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 22, 2026 •

Copy link
Copy Markdown

Summary

  • AGX3 FCMPSEL legalization checked only whether a single compare/select immediate slot held the same raw value rather than verifying a full tied LTN/GTN min/max where both operand pairs match.
  • On 8x MSAA sample-shading discard shaders, comparing against 0.5f (minifloat 0x20) while selecting integer bitmask 1 << 5 = 0x20 caused 0x20 to be decoded as FP16 0x3800, leaving sample 5 undiscardable.
  • Require the full tied min/max predicate before decoding select immediates as minifloats, and add compiler regression test NativeForms.Agx3HalfFcmpselUntiedImmediateNotDecodedAsMinifloat.

Verification (Apple M5 Pro / G17S B1, Borealis+Zink, MESA_SHADER_CACHE_DISABLE=1)

  • dEQP-GL45-ES31.functional.sample_shading.min_sample_shading.multisample_*_samples_8_discard: 2/2 Pass
  • dEQP-GLES31.functional.sample_shading.min_sample_shading.multisample_*_samples_8_discard: 2/2 Pass
  • dEQP-{GL45-ES31,GLES31}.functional.sample_shading.*: 44/44 supported Pass (0 fails)
  • agx_tests: 1222/1222 Pass (including NativeForms.Agx3HalfFcmpselUntiedImmediateNotDecodedAsMinifloat)
  • Zero GPU faults in dmesg.

@RyanTheTide

Copy link
Copy Markdown

The fix for the reported 8x discard case is right, but the new predicate still works from raw immediates, so it narrows the ambiguity without removing it.

  • agx_compile.c:6963-6975: a full tie is necessary for a minifloat select but not sufficient. (x < 0.5) ? x : uint16(0x20) ties src0/src2 (x), and once inlined src1/src3 are both immediate 0x20 (minifloat compare, integer select), so it would still be decoded as 0.5. The robust form is to record at fold time that the optimizer put a minifloat into the select slot, as fcmpsel_minifloat_select already does for the 32-bit fself case (agx_optimizer.c:355-385), and decode only when that is set.
  • Behaviour change: the old per-slot check decoded a select immediate whose own compare slot matched even when the other pair was untied, e.g. (0.5 < x) ? 0.5 : y. Now that is taken as raw bits. If that shape cannot reach this pass (tie preservation in the optimizer, compact constants), please say so in the comment. Otherwise add a test showing it still selects 0.5.
  • The test compares two binaries for inequality, which passes even if both are wrong. Please check the materialized mov_imm values instead: 0x0020 for the untied select, and 0x3800 for a tied max(h, 0.5) as a positive control.
  • The 16-bit hunk runs on every AGX3 chip except G17P, so it also changes M3 (G15G) and M4 (G16G) codegen. Please add the sample_shading 8x discard rows on one of those. The 12-term tie predicate now appears twice here and again as agx_g17p_tied_minmax() in agx_optimizer.c; a shared helper would keep the three in sync.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Author

Updated in 8d9276330937:

  • Explicit minifloat tracking: extracted a shared agx_fcmpsel_is_tied_minmax() helper in agx_compiler.h (used by agx_g17p_tied_minmax() and agx_materialize_agx3_alu_constants()), recorded I->fcmpsel_minifloat_select = true at fold time when agx_optimizer_inline_imm() copies a minifloat into a tied select slot, and gated 16-bit (and 32-bit non-zero) select immediate minifloat decoding strictly on I->fcmpsel_minifloat_select — removing the (h < 0.5h) ? h : uint16(0x0020) ambiguity.
  • Half-tied behavior comment: documented in agx_compile.c why half-tied shapes such as (0.5 < x) ? 0.5 : y cannot reach this pass with a minifloat in a select slot (agx_is_float_src() is false for s >= 2, and agx_optimizer_inline_imm() only folds select minifloats on full AGX3B tied min/max).
  • Direct MOV_IMM unit tests: rewrote NativeForms.Agx3HalfFcmpselUntiedImmediateNotDecodedAsMinifloat to assert materialized MOV_IMM values directly across G15G, G16G, and G17S for untied select (0x0020), adversarial (h < 0.5h) ? h : uint16(0x0020) (0x0020, fcmpsel_minifloat_select == false), and tied max(h, 0.5h) positive control (0x3800), and updated the two Optimizer.G17PFoldsBothHalvesOfATiedConstantFmax* expected-IR checks in test-optimizer.cpp.
  • M5 Pro (G17S B1) verification: agx_tests 1,218/1,218 passed (0 failed), Zink dEQP-GLES31.functional.sample_shading.min_sample_shading.multisample_renderbuffer_samples_8_discard passed, 0 GPU faults. M3/M4 live hardware rows are pending M3/M4 hardware access.

Assisted-by: LLM (Google:Gemini 4 Neon)

@DjDeveloperr
DjDeveloperr force-pushed the fix/agx3-fcmpsel-untied-immediate branch from 933d7ea to 8d92763 Compare November 22, 2026 12:21
@DjDeveloperr

Copy link
Copy Markdown
Author

Cross-chip verification on MacBook Neo (Apple A18 Pro / G17P B1, 0x8140) at exact head 8d92763309375947c6ea85ace350edf642ab6128:

  • Environment: Linux aurora 7.3.0-41.fc44.aurora.aarch64, MESA_SHADER_CACHE_DISABLE=true, Wayland session (pbuffer rgba8888d24s8ms0)
  • Staged binaries:
    • libvulkan_asahi.so (Borealis): 3ac0fe34e5064fba91bc929f60cf3f24cacf90610ef180a5dd655e35fb4315fd
    • libgallium-*.so (Gallium Asahi): 6b401b723110ddb30115dc8d56146f46d980f7be781c2ea4770c48553841c3c3
  • Targeted CTS results (428 cases: 174 Pass, 254 NotSupported, 0 Fail):
    • Native Gallium Asahi deqp-gles31 (dEQP-GLES31.functional.sample_shading.*): 18 Pass, 10 NotSupported, 0 Fail (28 cases)
    • Borealis Vulkan deqp-vk (sample_shading.*, first 400 mustpass cases): 156 Pass, 244 NotSupported, 0 Fail (400 cases)
  • Hardware health: PMU=30 00, kfault_delta=0, avc_delta=0

Assisted-by: LLM (Antigravity:Gemini 4 Neon)

@DjDeveloperr
DjDeveloperr force-pushed the fix/agx3-fcmpsel-untied-immediate branch from 8d92763 to 4e01913 Compare November 22, 2026 14:18
@DjDeveloperr

Copy link
Copy Markdown
Author

Rebased cleanly onto origin/aurora-wip (c90b9140c855, post-#702 / #601) at 4e01913b2aae (MERGEABLE).

  • Resolved end-of-file test conflict in src/asahi/compiler/test/test-native-form-regressions.cpp alongside agx: keep f16 GPR sources native in unmodified AGX3B F32 FFMA #702.
  • Exact-head M5 Pro (G17S B1, -Dbuildtype=release -Db_ndebug=true, MESA_SHADER_CACHE_DISABLE=1): meson test --suite asahi 155/155 PASS (agx_tests 1,222/1,222 passed, 1 skipped, 0 fail); Zink dEQP-GLES31.functional.sample_shading.min_sample_shading.multisample_renderbuffer_samples_8_discard 1/1 PASS; 0 new dmesg GPU faults; agent-policy.sh pr PASS.

@DjDeveloperr
DjDeveloperr force-pushed the fix/agx3-fcmpsel-untied-immediate branch from 4e01913 to 856ddfb Compare November 22, 2026 19:45
@DjDeveloperr

Copy link
Copy Markdown
Author

Rebased cleanly onto origin/aurora-wip (8b8db5b137c6) at 856ddfb7f5a0 (preserving merged agx3c_fsel16_imm_encodable() alongside explicit fcmpsel_minifloat_select tracking). Verified on M5 Pro (G17S): meson test --suite asahi 161/161 PASS, gb-gaussian (gaussian-horizontal-small + gaussian-horizontal-32x16) checked PASS, 0 GPU faults.

Decoding AGX3 FCMPSEL select immediates as minifloats from raw immediate
values is ambiguous even when both compare/select pairs appear tied (for
example `(h < 0.5h) ? h : uint16(0x0020)` leaves imm 0x20 in both src1 and
src3).

Extract a shared agx_fcmpsel_is_tied_minmax() helper in agx_compiler.h
used by both agx_g17p_tied_minmax() and agx_materialize_agx3_alu_constants(),
record I->fcmpsel_minifloat_select = true at fold time when
agx_optimizer_inline_imm() places a minifloat into a tied select slot, and
decode select immediates as minifloats only when fcmpsel_minifloat_select
is set. Update test-optimizer.cpp expectations and test materialized
MOV_IMM values directly across G15G, G16G, and G17S for untied select
(0x0020), adversarial `(h < 0.5h) ? h : 0x0020` (0x0020), and tied
`max(h, 0.5h)` (0x3800).

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr force-pushed the fix/agx3-fcmpsel-untied-immediate branch from 856ddfb to 3d1613b Compare November 23, 2026 03:47
@DjDeveloperr

Copy link
Copy Markdown
Author

Refreshed head pushed as 3d1613b9511a (b8b79e1fcff8 + pr677-rebased.patch), verified on Apple M5 Pro (G17S B1):

  • Environment: Linux 7.3.0-m5-n1keep-r3, MESA_SHADER_CACHE_DISABLE=1, no ASAHI_M5_BRINGUP.
  • Unit tests (meson test --suite asahi): 163/163 OK.
  • Vulkan CTS (exact head):
    • dEQP-VK.glsl.operator.selection.*: 56/56 Pass (100%) (0 Fail)
    • dEQP-VK.glsl.operator.binary_operator.less*: 24/24 Pass (100%) (0 Fail)
  • GPU faults: 0 new dmesg GPU faults.
  • Mirror asahi CI: 45096145786 (PASS).

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 24, 2026 19:13
@DjDeveloperr

Copy link
Copy Markdown
Author

Merged current aurora-wip cleanly at 80e53866a12 (fast-forward, no force-push; scrubbed AI attribution from description). Assert-ON unit CI: 188/188 PASS (0 fail); policy check clean. Ready for review.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Audited all 5 changed files and cross-checked every fcmpsel_minifloat_select use across src/asahi/compiler/:

  • agx_fcmpsel_is_tied_minmax() cleanly centralizes the tied min/max predicate and gates fcmpsel_minifloat_select in both agx_optimizer_inline_imm() and agx_compile.c (agx_nir_lower_minmax / immediate lowering).
  • Untied AGX3 16-bit and AGX3C 32-bit FCMPSEL select immediates are no longer decoded as minifloats, while tied constant fmin/fmax folding retains minifloat encoding.
  • The 3-case NativeForms.Agx3HalfFcmpselUntiedImmediateNotDecodedAsMinifloat regression test covers the untied immediate shapes cleanly.

Verification

  • Unmodified PR head 80e53866a120: agx_tests --gtest_filter="*Agx3HalfFcmpselUntiedImmediateNotDecodedAsMinifloat*:*G17PFoldsBothHalves*" 3/3 PASS.
  • Cleanly test-merged onto aurora-wip (a7920cea, which includes the #970 hk_sync.c revert; excluding unrelated asahi_layout_tests and hk-cpu-upload-bench): full non-layout asahi test suite 283/283 PASS.
  • Live Apple M5 Max (G17C B1, MESA_SHADER_CACHE_DISABLE=1): dEQP-VK.spirv_assembly.instruction.compute.float16.arithmetic.* 76/76 PASS, 0 GPU faults in dmesg.

Untested scope

  • Live hardware execution on G17P (AGX3B) was not run directly; AGX3B packing and optimizer behavior was verified via unit tests.

@DjDeveloperr

Copy link
Copy Markdown
Author

Verdict at 80e53866a120

Approve.

Blockers

None.

Checked

  • Audited all 4 changed files against origin/aurora-wip:
    • src/asahi/compiler/agx_compiler.h: adds agx_fcmpsel_is_tied_minmax() requiring identical sizes, modifiers (abs/neg), and memory flags on both compare/select pairs, and updates fcmpsel_minifloat_select documentation.
    • src/asahi/compiler/agx_optimizer.c: sets I->fcmpsel_minifloat_select = true in agx_optimizer_inline_imm() when folding a minifloat into src[s + 2] of an AGX3B tied min/max.
    • src/asahi/compiler/agx_compile.c: checks I->fcmpsel_minifloat_select (and clears it after materialization) in agx_materialize_agx3_alu_constants() instead of inferring from equal immediate bits, preventing raw 16-bit integer select payloads from being mis-decoded as minifloats.
    • src/asahi/compiler/test/test-native-form-regressions.cpp: covers untied, adversarial half-tied, and positive-control tied min/max cases across G15G, G16G, and G17S.
Evidence
  • Local agent-policy.sh pr: PASS.
  • Author M5 Pro (G17S B1) CTS and assert-ON unit suite (188/188 PASS) posted on PR; pre-merge mirror CI queued in Batch 5B.

Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict at 0fda13d52c53

Approved.

Blockers

None.

Checked

  • Audited all 5 changed files (agx_compile.c, agx_compiler.h, agx_optimizer.c, test-native-form-regressions.cpp, test-optimizer.cpp) at exact head 0fda13d52c53 (+155/-35, clean merge onto aurora-wip a65c0b99bb30 with no functional delta vs 80e53866a120).
  • Verified agx_fcmpsel_is_tied_minmax() requires exact source equivalence including size, abs, neg, and memory flags, agx_optimizer_inline_imm() sets fcmpsel_minifloat_select only when folding a minifloat into a tied min/max select slot, and agx_materialize_agx3_alu_constants() gates minifloat decoding on fcmpsel_minifloat_select before clearing it on both 32-bit and 16-bit paths.
  • Built isolated Borealis and compiler test targets cleanly (b_ndebug=false) and ran the full non-layout asahi unit suite (185/185 PASS, including the 3 new/updated FCMPSEL cases across AGX3B and AGX3C).
  • Verified on live Apple M5 Max (G17C B1, Linux 7.3, MESA_SHADER_CACHE_DISABLE=1): dEQP-VK.spirv_assembly.instruction.compute.float16.arithmetic.* 76/76 PASS, dEQP-VK.compute.pipeline.basic.* 80/80 executed PASS (1 unsupported, 0 failed), 0 GPU faults.
  • Untested scope: Live hardware execution on AGX3B (M3/M4) chips (covered only by compiler unit tests and IR/packing checks here) and asahi_layout_tests.
Evidence
  • Exact head verified: 0fda13d52c5330a453931c2099d207b940f8c9da (OPEN, non-draft, MERGEABLE)
  • agx_tests --gtest_filter="*Agx3HalfFcmpselUntiedImmediateNotDecodedAsMinifloat*:*G17PFoldsBothHalves*": 3/3 PASS
  • Full non-layout asahi suite (meson test --suite asahi): 185/185 PASS, 0 FAIL
  • Live Apple M5 Max (G17C B1, MESA_SHADER_CACHE_DISABLE=1):
    • dEQP-VK.spirv_assembly.instruction.compute.float16.arithmetic.*: 76/76 PASS
    • dEQP-VK.compute.pipeline.basic.*: 80/81 PASS (1 Not supported, 0 Failed)
    • GPU faults delta: 0

@DjDeveloperr
DjDeveloperr merged commit 7ed772c into aurora-wip Nov 24, 2026
@RyanTheTide
RyanTheTide deleted the fix/agx3-fcmpsel-untied-immediate branch November 27, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants