Skip to content

asahi: share negative-zero operands for G16 uniform clamps - #48

Open
IronsideXXVI wants to merge 4 commits into
omacom:integration/aurorafrom
IronsideXXVI:fix/g16-shared-negative-zero
Open

IronsideXXVI wants to merge 4 commits into
omacom:integration/aurorafrom
IronsideXXVI:fix/g16-shared-negative-zero

Conversation

@IronsideXXVI

@IronsideXXVI IronsideXXVI commented Nov 17, 2026 •

Copy link
Copy Markdown

G16 uniform clamps currently copy each uniform into a GPR before a saturated float32 add. Reuse one negative-zero GPR per block instead, retaining the same add, operand order, saturation and precision. This is restricted to eligible G16G operands. ASAHI_G16_SHARED_NZ=0 restores the previous path; the compiler-cache key includes the choice.

On an M4 MacBook Pro, a balanced same-boot old/off/on/on/off/old test of 1080p RGBA8 blended fill (depth 64, three samples per window) measured 371.494 → 348.73585 µs per submit, a 6.126% latency reduction. Every enabled sample was below every disabled sample. The selected shader changed from 178 bytes/25 compiler instructions to 170 bytes/22, with GPR/spill counts unchanged. Across all three arms, a finite 64-frame, 16-layer blend readback matched byte-for-byte and each arm had zero GPU faults. Diagnostic timings were excluded.

Validation: the experimental compiler suite passed 977 tests in both modes (one skipped and one disabled). Added tests cover materialization, captured blend expression compilation, signed zero, finite clamp boundaries and host bit-pattern cases. Production Mesa/Vulkan 1.8145 packages have now passed the official 188 Meson tests with zero failures; default and explicit opt-out compiler cases pass 3/3 each. The integration/aurora port also builds and passes those cases in both modes. Gallium and Vulkan cache keys both separate the opt-out. These are finite differential correctness results, not a full graphics conformance or macOS-parity claim; no constant-program protocol is changed.

Hardware testing used the installed 8f013bf-based Mesa plus three distribution patches. This PR ports only the optimization and its tests onto integration/aurora; it does not import that entire source branch. No Apple binaries or captures are included.

Preserve f32 saturated-add semantics while materializing one negative-zero GPR per block rather than copying every uniform source. Qualified on an M4 with matching finite blend readbacks and 6.126% lower fill submission time. Retain ASAHI_G16_SHARED_NZ=0 opt-out and include the choice in the Vulkan compiler cache key.

Assisted-by: LLM
Retain a reliable opt-out for OpenGL as well as Vulkan when process flags change.

Assisted-by: LLM
@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge because they only clarify comments.

Summary

The PR shares one negative-zero register per block for eligible G16G uniform clamps, while keeping the same float32 add and saturation.

  • G16G clamps share one negative-zero register per block.

Reviews (3) · Last reviewed commit: "asahi: name the sources of the G16 share..." · Reviewed by Greptile

@IronsideXXVI

Copy link
Copy Markdown
Author

Thanks. The review found nothing to change, so this stays as it is.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks Dylan. Sharing one -0.0 GPR per block for the saturated uniform adds meets the mixed uniform/GPR operand rule without a copy per clamp, and the old/off/on ordering with a byte-for-byte readback makes the 6 % easy to trust.

What blocks a merge:

  1. ASAHI_G16_SHARED_NZ (agx_g16_shared_nz_enabled() in src/asahi/compiler/agx_compile.c) is a runtime switch. Merged code here can't carry runtime switches or A/B parameters. Please drop it so the shared operand is the only path, along with the Gallium disk-cache change in b0b3902, which exists only to keep the two settings apart. G16SharedNegativeZero can then assert the shared form unconditionally.
  2. The value >= 256 and value & 1 checks need a stated source. Name them, or say in the comment which encoding limit each one comes from.
  3. Hardware conformance, which this tree's policy requires before a merge: a G16G vk-default subset run with 0 new Fail/Crash against the integration/aurora base, plus a GL smoke run, because the change reaches Gallium as well. The description is clear that the pixel checks so far are differential, not CTS.

A question, not a blocker: every G16 part executes AGX3b (src/asahi/lib/agx_chip.h), but the pass runs on G16G only. If G16S/G16C are left out only because they weren't measured, please say so in the commit message. If something about them rules the pass out, say what.

Mesa CI on b0b3902 is approved and running.

Merged code cannot carry runtime switches. Remove ASAHI_G16_SHARED_NZ
and agx_g16_shared_nz_enabled(): on G16G the saturated uniform add now
always shares one -0.0 register per block. The Vulkan compiler-flag bit
and the Gallium disk-cache bit only kept the two settings apart, so they
go too. G16SharedNegativeZero and the capture test assert the shared
form unconditionally.

The pass stays limited to G16G because that is the only AGX3b part it
was measured on. G16S and G16C were not measured; nothing known rules
them out.

Assisted-by: LLM
@IronsideXXVI

Copy link
Copy Markdown
Author

Thanks. I'll drop ASAHI_G16_SHARED_NZ and the disk-cache change that only kept the two settings apart, so the shared operand is the only path, and name the source of the value >= 256 and value & 1 checks in the comment. Before asking again I'll run the G16G vk-default subset plus a GL smoke run against the integration/aurora base.

On G16S/G16C: they're left out only because I haven't measured them. The only G16 part I have is the G16G in my M4 MacBook Pro. I'll say so in the commit message.

@IronsideXXVI

Copy link
Copy Markdown
Author

Pushed 3b5308b ("asahi: drop the G16 shared negative-zero switch"):

  • ASAHI_G16_SHARED_NZ and agx_g16_shared_nz_enabled() are gone, along with the Vulkan compiler-flag bit and the Gallium disk-cache bit from b0b3902. On G16G the shared -0.0 operand is now the only path.
  • G16SharedNegativeZero, the capture test and the boundary test assert the shared form unconditionally.
  • The commit message says G16S/G16C are left out only because they weren't measured. Nothing I know of rules them out.

The repo's CI build.sh passes locally on this head (meson test: 156 ok, 0 fail).

Still open: naming the encoding limit behind the value >= 256 and value & 1 checks (a separate commit), and the G16G vk-default subset plus a GL smoke run against the integration/aurora base. I'll post that run when it's done.

The odd-index check is an encoding limit: an f32 uniform operand starts
on an even 16-bit half, as agx_instr_accepts_uniform() and
agx3_uniform_float_encode() require. The 256 bound is not one: the
encoder takes uniform sources up to half 511, and the pass keeps the
low-half bound it was measured with. Comment only, no change in code
generation.

Assisted-by: LLM
@IronsideXXVI

Copy link
Copy Markdown
Author

Pushed 948be88 for point 2: the sources are named in the comment above the pass.

  • value & 1 is an encoding limit. Uniform indices count 16-bit halves, and an f32 uniform operand has to start on an even half: agx_instr_accepts_uniform() applies it to FADD on AGX3B, and agx3_uniform_float_encode() to an AGX3_FLOAT_UNIFORM source.
  • value >= 256 is not an encoding limit. The encoder takes uniform sources up to half 511. The pass keeps the low-half bound it was measured with (the high split in agx_instr_accepts_uniform()), so a high-half uniform keeps the existing copy. Widening it would need its own measurement.

Comment only, no change in generated code. meson test: 156 ok, 0 fail.

@IronsideXXVI

Copy link
Copy Markdown
Author

Retargeted to aurora-silicon#604

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.

2 participants