Skip to content

zink, asahi/apple9: fixes for Firefox and Signal on Zink-on-Honeykrisp (M4) - #2

Open
audreyt wants to merge 171 commits into
GravityLinux:mainfrom
audreyt:zink-honeykrisp-apple9-int16
Open

audreyt wants to merge 171 commits into
GravityLinux:mainfrom
audreyt:zink-honeykrisp-apple9-int16

Conversation

@audreyt

@audreyt audreyt commented Oct 27, 2026 •

Copy link
Copy Markdown

Five commits on main that apply and build (the CPU tests were run for commits 1-4) without the rest of the Apple9
graphics work. They come from a longer series (#3, draft) that runs a
Zink-on-Honeykrisp desktop on an Apple M4 (G16G, J715 MacBook Air): Firefox with WebRender,
Signal with GPU rasterization.

Commits

  1. zink: don't track render passes on Honeykrisp. Honeykrisp has no
    VK_KHR_unified_image_layouts, so general_layout is false while TC render-pass tracking is
    on. Firefox hit both asserts that live under that combination:
    !ctx->track_renderpasses || screen->driver_workarounds.general_layout in zink_clear and
    !check_rp || check_rp == ctx->in_rp in zink_update_barriers. Same effect as
    ZINK_DEBUG=norp; the cost is a full attachment load/store per pass.

  2. zink: don't share pipelines across topologies without dynamic topology.
    dynamicPrimitiveTopologyUnrestricted lets one pipeline serve every topology only when
    VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY is dynamic, which zink enables only with
    EXT_extended_dynamic_state. Without it the topology is baked into each pipeline, yet every
    topology still used pipeline slot 0, so Signal drew 4-vertex triangle strips with a cached
    triangle-list pipeline and only half of its logo appeared. Not Honeykrisp-specific.

  3. zink: skip draws whose graphics pipeline could not be created. Report the failure once and
    drop the draw instead of assert(pipeline) and binding VK_NULL_HANDLE. By then
    zink_get_gfx_pipeline has consumed the dirty state, so a context flag sends every following
    draw back through the pipeline lookup (past the vertex-input fast path) and drops it until a
    lookup succeeds. A failed creation stays cached without a pipeline; a hit on it is reported as
    a failure instead of becoming the tracked pipeline, and the state hashes are folded out of
    final_hash unconditionally, since a context can now have hashed state without a pipeline.
    The previously bound pipeline stays bound and tracked. Not Honeykrisp-specific either.
    A dropped draw may also have consumed state changes that zink_draw emits only after the
    pipeline update, such as a dynamic primitive topology, so the graphics state is marked
    changed (as after a mesh draw) and the next draw takes the batch-changed path and re-emits
    all of it. Honeykrisp has no EXT_extended_dynamic_state, so topology is baked into each
    pipeline there and the dynamic-topology case cannot be exercised on this hardware.

  4. asahi/apple9: evaluate narrow integer math at 32 bits. A narrow integer keeps only its low
    bits in a 32-bit GPR, and narrowing conversions leave the upper bits as they were, so
    integer comparisons, right shifts, imin/imax/umin/umax and imul_high/umul_high
    (which nir_opt_idiv_const emits for a division by a constant) read garbage. Narrow integer
    comparisons and every other narrow integer ALU op except conversions, moves and selects are
    now evaluated at 32 bits. The algebraic passes after the width lowering can fold a widened
    comparison back to 16 bits (a clamp becomes a 16-bit imin), so the lowering runs again
    after the last of them, and a narrow integer ALU op that still reaches instruction selection
    is rejected instead of being miscompiled. GLES contexts get mediump fragment
    ints lowered to 16 bits (Zink on Honeykrisp reports shaderInt16), so this hit WebRender: its
    multi-stop gradient lookup divides by 5 and clamps an index, and gradients with more than two
    stops drew bands, flat discs and stray colours past their last stop. The change is in the
    shared Apple9 compiler, so gallium asahi shaders are affected too; I only tested through Zink.

  5. zink: select the pipeline again when topology changes without dynamic topology.
    Without dynamic topology each pipeline has its topology baked in, but zink_draw looked the
    pipeline up again only when other state was dirty, the rasterization primitive class changed
    or the batch changed. A change between two topologies of the same class, such as a triangle
    list followed by a triangle strip, kept the previous pipeline, so a strip drawn after a list
    lost the second triangle of every four-vertex quad: Signal drew half of each message bubble
    and of its composer bar. Commit 2 fixed the pipeline slot but not this lookup. Not
    Honeykrisp-specific; it applies whenever topology is not dynamic.

Testing

  • Each commit built on its own on top of main (aarch64, debugoptimized,
    -Dgallium-drivers=asahi,zink -Dvulkan-drivers=asahi -Dbuild-tests=true): agx_tests
    366/366 on commits 1-3 and 368/368 on commit 4 (two new tests), libasahi_tests 5/5,
    zink_format_test pass; git diff --check is clean.
    git merge-tree with asahi: fixes enabling sway, zathura and mpv on Apple M4 mini #1 is clean.
  • On hardware (J715, kernel 7.1.9-m4-gpu-backport) these commits were tested inside the longer
    series, not on main alone, because main has no Apple9 Vulkan graphics path:
    • A GLES 3.0 probe running Firefox's dumped multi-stop gradient source (10, 32 and 130 stops)
      failed every mediump case before commit 4 and passes after; the same source with
      precision highp int passed before. A second probe checks 15 mediump integer expressions
      from that lookup and passes after commit 4; before it, the index clamp and the highp address
      arithmetic were wrong.
    • Firefox Developer Edition 160 on https://audreyt.org with hardware WebRender: the gradient
      sections now match software WebRender, and the page stays responsive.
    • Signal (Chromium, Wayland, GPU rasterization): full logo after commit 2, no GPU-process
      crashes.
    • Firefox no longer hits the two render-pass asserts (commit 1) or assert(pipeline)
      (commit 3).
    • Commit 5, a GL 4.6 probe with one program and one VAO that alternates triangle-strip, triangle-list
      and restart-index strip draws without changing any other state: draws after a list lost half of each
      quad (15300 pixels missing) before commit 5 and none are missing after. Signal, with one avatar clicked
      repeatedly, no longer clips its message bubbles or composer bar. Commit 5 was built on top of
      commit 4 (libgallium only); agx_tests and the other unit tests were not rerun for it, and the
      hardware run was on the longer series with this commit, not on main alone.
    • Commit 3, a GL 3.3 probe on one render target: a valid draw, then two identical draws whose
      fragment shader writes gl_FragDepth (rejected by the Apple9 graphics path, so no pipeline can be
      created), then valid draws again. With the previous version of commit 3 the second failed draw
      was rendered with the previously bound pipeline (2 of 9 probe columns wrong); now every failed
      draw is dropped and the following draws render correctly. The same sequence with only
      GL_COLOR_LOGIC_OP toggled (a pure pipeline-state change) passes before and after.
  • Commit 4 adds two tests. NarrowIntegerMathIsEvaluatedAt32Bits checks which operations the
    width callback widens. NarrowIntegerShadersReachSelectionWidened compiles 16-bit comparison,
    clamp, min/max, shift, add and multiply shaders through the Apple9 compiler; with the second
    widening removed, the comparison and clamp shaders are rejected, so it fails. On this tree a
    16-bit division by a constant is still rejected by the Apple9 compute compiler
    ("unsupported NIR"), with or without this change.
  • CTS 1.4.3.3, dEQP-VK.spirv_assembly.type.*.{i16,u16}.*_{comp,frag} (1100 cases), on the longer series with and without this change: 456 pass before, 552 after, no case regressed. The 96 newly passing cases are all compute and all gave wrong output before. The 548 remaining failures are all fragment cases that fail identically on both builds in vkCreateGraphicsPipelines (VK_ERROR_FEATURE_NOT_PRESENT), unrelated to this change. Not run on main alone, which has no Apple9 Vulkan graphics path.

Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Assisted-By: OpenAI Codex (GPT-5.6 Sol)
Use a depth of one for each 1D array image during texture finalization instead of the resource layer count, matching its image dimensions.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
…hader

Admit triangles, triangle strips and triangle fans for triangle transform feedback without a geometry shader. Preserve quad and polygon modes only in desktop compatibility profiles; exclude adjacency modes requiring a geometry stage.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Normalize passthrough geometry primitive-ID inputs before creating compute and raster variants. Retain each stream's transform-feedback count and suppress captures for dummy culled primitives when an invocation emitted no primitives.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Cache device debug and direct-submit settings during initialization and share compiler tracing through a single helper.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Expose common compiler lowering helpers, move MSAA lowering into the compiler, and serialize portable library NIR for Apple9 linking. Share sample-position and printf support between compiler paths.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Track loop break predicate banks through lowering and encoding, with focused compiler coverage.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Model integer unary and binary16 operations in Apple9 IR, optimization and machine encoding. Lower narrow conversions through the native operation model and add compiler and Piglit regression coverage.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Add IR and encoding support for memory, scans, fences and indirect atomic operations, and account for their operand constraints during register allocation.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Integrate Apple9 compute, geometry and raster shader lowering with descriptor, varying and launch interfaces. Extend resource addressing, texture and sample operations, scratch limits and compiler regression coverage through the normal shader pipeline.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Update blit and resolve paths for layered resources and tile helper preparation. Keep helper dispatch state and render synchronization consistent with the shader launch interfaces.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Track resource access by render stage, synchronize cross-context CPU access with pending writers, and retire completed batches when finishing contexts.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Provide native M4 test profiles and runner tooling using upstream expectations, with documented deployment and result provenance.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Update compiler and driver documentation with the captured implementation state and existing hardware results, and point DRM shim users to current launcher documentation.

Validation: Asahi compiler, layout, geometry, launcher and GLSL function-scope tests. Gallium, EGL, DRM shim, GLSL compiler and compute runner builds; GLES fixture compiled with -Werror. No hardware run for this snapshot split.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Enable the Apple9 graphics path for G16G and G17P without requiring AGX_APPLE9_DIRECT_RENDER. Keep the existing hardware guard and remove obsolete launcher exports and documentation.

Validation: git diff --check, shell syntax checks, and Python AST parsing. No hardware run for this change.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Signed-off-by: Niklas Sheth <[email protected]>
Accept VARYING_SLOT_CLIP_VERTEX in the shared varying predicate so
compatibility shaders writing gl_ClipVertex pass signature validation and
use the existing export path, including when user clipping is disabled.
No special cleanup pass or new instruction encoding is needed.

Add regressions for ordinary export with clip distances, reads of the
output variable, transform-feedback compilation, and the publication
capacity boundary. Clip vertex consumes four of the current 96 export
components. Report the rejected vertex output or missing position when
signature validation fails.

Validation: isolated Asahi compiler test suite and Gallium driver build.
Native M4 regression probes previously passed rendering, clipping toggles,
output reads, and capture with clipping disabled, plus GL 3.3/GLES 3.0
smoke tests. The existing combined clipping/capture failure remains.

Assisted-By: OpenAI Codex (GPT-6 Astra)
Signed-off-by: Niklas Sheth <[email protected]>
@audreyt

audreyt commented Oct 27, 2026

Copy link
Copy Markdown
Author

Correction pushed (tip 9c8bfc8). The first version of commit 4 only widened shifts, min/max and the high-multiply, and its message said integer comparisons were already widened. That is true of the longer series (#3) but not of main, so on main the index > count - 1 clamp in the gradient lookup was still evaluated at 16 bits. Commit 4 now also widens 8/16-bit integer comparisons, exports the callback as agx_apple9_alu_width, and adds a unit test; the message is rewritten to match main. agx_tests: 367/367. The earlier hardware results came from the longer series, not from main alone; I have not run main alone on hardware.

@audreyt
audreyt force-pushed the zink-honeykrisp-apple9-int16 branch from 9c8bfc8 to 833eb5a Compare October 27, 2026 22:30
@audreyt

audreyt commented Oct 27, 2026

Copy link
Copy Markdown
Author

Pushed a fix to commit 4 (tip 833eb5a). A review found that on main the width lowering ran only once, and the algebraic passes after it folded widened comparisons back to 16 bits: a 16-bit ilt/ieq, and the clamp, which becomes a 16-bit imin, still reached Apple9 instruction selection and compiled with undefined upper bits. Commit 4 now runs the lowering again after the last algebraic passes (as #3 already did), rejects any narrow integer ALU op that still reaches selection, and adds NarrowIntegerShadersReachSelectionWidened, which fails on exactly those shaders when the second lowering is removed. agx_tests 368/368. The message no longer claims that main already widened comparisons. Separately, on main a 16-bit division by a constant is still rejected by the Apple9 compute compiler (unsupported NIR), unchanged by this PR.

@audreyt
audreyt force-pushed the zink-honeykrisp-apple9-int16 branch from 833eb5a to 97700ee Compare October 28, 2026 01:32
@audreyt

audreyt commented Oct 28, 2026

Copy link
Copy Markdown
Author

Pushed 97700ee after another review round. Commit 3 (zink: skip draws whose graphics pipeline could not be created) only dropped the first draw: zink_get_gfx_pipeline had already consumed the dirty state, so an identical next draw skipped the pipeline update and was rendered with the previously bound pipeline, and a cache hit on the failed creation set the tracked pipeline to VK_NULL_HANDLE. It now keeps a failure flag on the context that sends every following draw back through the lookup (past the vertex-input fast path) and drops it until a lookup succeeds, reports a cached failed creation as a failure without tracking it, and folds the state hashes out of final_hash unconditionally. A GL probe on the Apple9 series reproduced the stale-pipeline draw before and passes after. Commit 1's message is rewrapped; commits 2 and 4 are unchanged apart from their parents.

Honeykrisp has no VK_KHR_unified_image_layouts, so general_layout is
false. Enabling render-pass tracking violates the !track_renderpasses ||
general_layout assertion in zink_clear.c and also triggers the
render-pass consistency assertion in zink_update_barriers. Leave
tracking disabled instead of forcing depth stores.
dynamicPrimitiveTopologyUnrestricted lets one pipeline be drawn with any
topology, but only when VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY is dynamic,
and zink makes it dynamic only with EXT_extended_dynamic_state. Without
that, the topology is baked into each pipeline, yet the property still
put every topology in pipeline slot 0, so a pipeline created for one
topology was reused for draws with another.

The in-progress Apple9 graphics path for Honeykrisp does not expose
extendedDynamicState but keeps the property. Chromium (Signal) drew
4-vertex triangle strips with a cached triangle-list pipeline, so only
the first triangle of its logo quad reached the screen; with back-face
culling, a 6-vertex list drawn with a cached strip pipeline lost its
second triangle.

Only use the shared slot when topology is dynamic.
update_gfx_pipeline asserted that a pipeline was returned and otherwise
bound VK_NULL_HANDLE. Pipeline creation can fail: out of memory, or a
driver that cannot express the state (the in-progress Apple9 graphics
path for Honeykrisp rejected vertex shaders that write gl_PointSize
with VK_ERROR_FEATURE_NOT_PRESENT). Firefox then aborted as soon as
audreyt.org created its WebGL2 point sprites.

Report the failure once and drop the draw. By then zink_get_gfx_pipeline
has consumed the dirty state, so an identical next draw would skip the
pipeline update and draw with the previously bound pipeline. Keep a
failure flag on the context instead: it sends every following draw
through the pipeline lookup, past the vertex-input fast path, and drops
it until a lookup succeeds.

A dropped draw may also have consumed state changes that zink_draw
emits only after the pipeline update, such as a dynamic primitive
topology. Mark the graphics state as changed, as after a mesh draw, so
the next draw takes the batch-changed path and re-emits all of it.

A failed creation stays in the pipeline cache without a pipeline. Treat
a cache hit on it as a failure rather than tracking a null pipeline, so
the previously bound pipeline stays bound and tracked. The state and
vertex hashes start at zero and stay folded into final_hash when
creation fails, so fold the old value out unconditionally instead of
only once a pipeline exists.
A narrow (8- or 16-bit) integer keeps only its low bits in a 32-bit GPR;
narrowing conversions leave the upper bits as they were. Operations that
read past the low bits then give wrong results: integer comparisons,
right shifts, imin/imax/umin/umax, and imul_high/umul_high, which
nir_opt_idiv_const emits for a division by a constant and which were
lowered as the high word of a 32x32 product.

Zink on Honeykrisp reports shaderInt16, so GLES contexts get mediump ints
in fragment shaders lowered to 16 bits and this hits real content.
WebRender's multi-stop gradient lookup walks a tree with
"index_stride /= 5" and clamps the stop index with "index > count - 1";
on the in-progress Apple9 graphics path the division returned 0 and the
clamp was lost, so gradients with more than two stops drew bands, flat
discs and stray colours past the last stop in Firefox.

Evaluate narrow integer comparisons and every other narrow integer ALU
op except conversions, moves and selects at 32 bits. nir_lower_bit_size
extends the sources explicitly and takes the high half of the 32-bit
product for imul_high/umul_high. The algebraic passes that follow can fold
a widened comparison back to its narrow form (a clamp becomes a 16-bit
imin), so widen again after the last of them, and reject a narrow integer
ALU op that still reaches instruction selection instead of miscompiling
it.

Export the width callback as agx_apple9_alu_width, and add tests for which
operations it widens and that narrow integer shaders compile.
@audreyt
audreyt force-pushed the zink-honeykrisp-apple9-int16 branch from 97700ee to dcf6d0d Compare October 28, 2026 04:42
@audreyt

audreyt commented Oct 28, 2026

Copy link
Copy Markdown
Author

Pushed dcf6d0d. Commit 3 now also marks the graphics state as changed when it drops a draw (what zink already does after a mesh draw), so the next draw takes the batch-changed path and re-emits all dynamic state. Without it, a dropped draw could consume a topology change before vkCmdSetPrimitiveTopology was emitted, and on a driver with dynamic topology the recovery draw would run with the previous topology. Honeykrisp bakes topology into each pipeline, so that case cannot be exercised here; the GL failure probe and the rest of the hardware validation pass on the Apple9 series with this change. Commits 1, 2 and 4 are unchanged apart from their parents.

… topology

Without dynamic primitive topology the topology is baked into each
pipeline, and zink keeps one pipeline slot per topology. zink_draw only
looked the pipeline up again when other state was dirty, when the
rasterization primitive class changed, or when the batch changed. A pure
change between two topologies of the same class, such as a triangle list
followed by a triangle strip, therefore kept the previously bound
pipeline.

A strip drawn after a list used the list pipeline and lost the second
triangle of every four-vertex quad. Chromium (Signal) then drew half of
each message bubble and of the composer bar.

Also look the pipeline up again when the topology changes and topology is
not dynamic.
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