Skip to content

gallium/tc: run a frontend flush inline when the driver thread is idle - #981

Merged
RyanTheTide merged 2 commits into
aurora-wipfrom
perf/tc-idle-inline-flush
Nov 25, 2026
Merged

RyanTheTide merged 2 commits into
aurora-wipfrom
perf/tc-idle-inline-flush

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

When gallium/tc has no pending driver-thread batches, execute a frontend PIPE_FLUSH_ASYNC flush inline on the calling thread instead of waking the idle driver thread — gated behind a new threaded_context_options::inline_idle_flush driver option enabled only on asahi (ea44b8564f4e).

  • Commit 1 (3422dea7ee93): gallium/tc: run a frontend flush inline when the driver thread is idle
  • Commit 2 (ea44b8564f4e): gallium/tc: make the inline idle flush a driver option, enable it on asahi — leaves zink (which already submits inline via merged #982) and other Gallium drivers on async flush so Zink GPU-bound throughput at depth 4 is completely unaffected.

Note on the earlier 3422dea7ee93 numbers: the previously reported native transfer.ops mipchain d1 (62.7 -> 73.9) and copy_b2i d1 (37.3 -> 40.7) figures were GB/s (higher is better) mislabeled as µs. In µs/submit, both are large wins (-15.62% and -8.63%).

Verification at exact head ea44b8564f4eb59ad3ec9aeb432f14af776897e7

  • Host CI / Policy: Fedora warm --suite asahi 194/0, drm-shim asahi-{g13g,g16g,g17p}-threaded-context PASS; agent-policy.sh clean; clean merge tree against aurora-wip 00a73680e009 (#982 merged).
  • Hardware: MacBook Neo (J700, G17P B1), kernel 7.3.0-41, release build (-Db_ndebug=true, empty BUILD-DIFF.patch), private ICD prefix, shader cache disabled.
    • B (ea44b8564f4e): libgallium sha256 9834dcf1ebcc8337e36d4c66d878a6856b9c90bda3ef978ac21a6e2feae52, libvulkan_asahi.so sha256 1b0e4bafe16916e2bd01807faa234d250f46dbec84ccc14360306f1303d1a7ef.
    • D (1107a4201c37, ea44b8564f4e + merged #982 6493d421d0ed): libgallium sha256 ca8210d073f6deaa9eaf5e76d3adf4da34f7d9c496e89eb0ab10d4bae4cbdd1f, libvulkan_asahi.so sha256 17df42969e1f614547e67d513cfd1e92d3dca558217e29269853ab90e98015b7.

Balanced ABBA + BAAB (explicit discarded warm-up per build/workload, 216 records across 27 rows; 0 regressions — worst pooled delta +0.65%)

Native Asahi GL (A cedf24806bc vs B ea44b8564f4e)

Workload Depth A (µs) B (µs) Δ ABBA / BAAB
compute.light 1 152.49 103.51 -32.12% -32.08% / -32.16%
compute.light 4 22.06 20.32 -7.87% -9.09% / -6.61%
render.light tri 1 192.28 130.55 -32.10% -32.06% / -32.14%
render.light tri 4 35.16 34.73 -1.22% -0.86% / -1.59%
transfer.ops clear_16m 1 168.05 122.85 -26.90% -27.15% / -26.64%
transfer.ops clear_16m 4 26.80 24.93 -6.99% -7.13% / -6.85%
transfer.ops mipchain 1 387.87 327.27 -15.62% -15.40% / -15.84%
transfer.ops mipchain 2 217.98 204.24 -6.31% -7.39% / -5.23%
compress.bw rgba32f 1440p 1 589.23 534.56 -9.28% -9.31% / -9.24%
compress.bw rgba32f 1440p 4 401.48 403.64 +0.54% +0.85% / +0.24%
transfer.ops copy_b2i 1 452.92 413.86 -8.63% -9.51% / -7.71%
transfer.ops copy_b2i 4 347.79 349.18 +0.40% -0.00% / +0.78%
compress.bw storage 1440p 1 515.11 501.96 -2.55% -3.81% / -1.31%
compress.bw storage 1440p 4 439.25 442.11 +0.65% +1.95% / -0.62%
render.draws 1024 direct 1 1328.35 1324.54 -0.29% -0.76% / +0.18%
render.draws 1024 direct 4 557.37 541.64 -2.82% -2.77% / -2.88%
render.draws 4096 mdi 1 820.23 819.20 -0.13% +0.58% / -0.83%
render.draws 4096 mdi 4 627.57 625.28 -0.37% +0.18% / -0.90%

Zink GL (C #982 6493d421d0ed vs D #981+#982 1107a4201c37)

Workload Depth C (µs) D (µs) Δ ABBA / BAAB
compute.light 1 155.02 155.04 +0.01% +0.11% / -0.09%
compute.light 4 21.51 21.63 +0.54% +1.57% / -0.47%
render.draws 4096 mdi 1 1044.93 1048.02 +0.30% +0.89% / -0.29%
render.draws 4096 mdi 4 814.23 803.91 -1.27% +0.62% / -3.04%
render.light tri 1 198.95 198.67 -0.14% -0.43% / +0.14%
transfer.ops copy_b2i 1 442.52 439.17 -0.76% -2.06% / +0.57%
transfer.ops copy_b2i 4 357.96 357.71 -0.07% +0.19% / -0.32%
transfer.ops mipchain 1 338.82 339.48 +0.19% +0.19% / +0.19%
transfer.ops mipchain 2 175.93 176.89 +0.55% +0.94% / +0.15%

Conformance & Health (ea44b8564f4e)

  • dEQP-GLES3: 5,150 Pass / 69 NotSupported / 1 QualityWarning / 0 Fail.
  • dEQP-GLES31: 1,356 Pass / 15 NotSupported / 0 Fail (6,591 total cases, 0 Fail).
  • gpubench-gl --verify: 9/9 status=ok, check.valid=true on all 3 transfer readbacks.
  • Health: 0 GPU faults/timeouts/recoveries, 0 AVCs, 0 failed units.

glFlush and glFinish reach tc_flush() as PIPE_FLUSH_ASYNC flushes. With
a driver that provides create_fence, tc queues them to the driver
thread even when that thread has nothing left to do, so the submission
waits for the thread to wake up first. A caller that waits on the work
next (glFenceSync + glFlush + glClientWaitSync, glFinish) pays that
wakeup on every round trip.

When every flushed batch has already executed, take the synchronous
path instead: run the unflushed calls and the driver flush on the
calling thread, as tc already does for a synchronous flush. A busy
driver thread still gets the batch queued behind its own work, and the
memory-limit flushes issued while recording stay asynchronous.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 24, 2026 22:43
@DjDeveloperr
DjDeveloperr marked this pull request as draft November 24, 2026 22:50
…asahi

Running an idle frontend flush on the calling thread removes the driver
thread's wakeup from every glFlush/glFinish round trip, but its effect
on throughput depends on what the driver does after tc. zink hands the
batch to its own submit thread. With several frames in flight on
Borealis, executing those flushes on the application thread cost zink
GPU-bound throughput (transfer.ops copy_b2i and multi-draw indirect at
four frames in flight) even though its single-frame round trips got
much faster.

Add threaded_context_options::inline_idle_flush and enable it only for
asahi, where the inline flush is a gain at every depth measured. Other
drivers keep the asynchronous flush.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr marked this pull request as ready for review November 24, 2026 23:44

@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 ea44b8564f4e

APPROVED — clean opt-in threaded_context_options::inline_idle_flush path scoped to asahi, full release+assert Meson suite green, and live Apple M5 Max native Asahi GL + Zink GLES3/GLES31 conformance verified at exact head.

Blockers

None.

Checked

  • Full diff audit of all 4 changed files (src/gallium/auxiliary/util/u_threaded_context.c, src/gallium/auxiliary/util/u_threaded_context.h, src/gallium/drivers/asahi/agx_pipe.c, src/gallium/drivers/asahi/tests/test-agx-threaded-context.c; +48/-7) across both commits (3422dea7ee93, ea44b8564f4e, both signed off with Signed-off-by:).
  • Verified internal memory-limit flushes (tc_invalidate_buffer, tc_buffer_unmap, tc_texture_unmap) pass frontend = false so they stay asynchronous; deferred flushes (PIPE_FLUSH_DEFERRED) stay untouched; non-asahi drivers (including zink) keep inline_idle_flush = false.
  • Merged ea44b8564f4e cleanly onto origin/aurora-wip (5e183ceaeb2c), built aarch64 release with assertions (-Dbuildtype=release -Db_ndebug=false), and ran meson test --suite asahi --suite poly: 199/199 PASS (0 failed), including test-agx-threaded-context covering the inline idle async flush path.
  • Live Apple M5 Max (G17C B1) verification against private prefix (MESA_SHADER_CACHE_DISABLE=true, 0 GPU faults/timeouts):
    • Native Asahi GL: dEQP-GLES3.functional.fence_sync.* 11/11, dEQP-GLES3.functional.flush_finish.* 5/5, dEQP-GLES3.functional.buffer.write.basic.* 72/72, dEQP-GLES31.functional.synchronization.in_invocation.* 20/20 (108/108 PASS, 0 fail).
    • Zink GL (MESA_LOADER_DRIVER_OVERRIDE=zink): dEQP-GLES3.functional.fence_sync.* 11/11, dEQP-GLES3.functional.flush_finish.* 5/5 (16/16 PASS, 0 fail).
  • Untested scope: Did not re-run gpubench-gl latency benchmarks locally (exact-head ABBA/BAAB tables for native Asahi GL and Zink GL are already reported in the PR description).
Evidence
  • Merge base: origin/aurora-wip 5e183ceaeb2c + ea44b8564f4e → clean ort merge (fd801ee21ea).
  • meson test -C /tmp/b64-bld981 --suite asahi --suite poly: Ok: 199, Fail: 0.
  • Renderer strings verified from private prefix: Apple M5 Max (G17C B1) / OpenGL ES 3.2 Mesa 26.3.0-devel (git-fd801ee21e) and zink Vulkan 1.4(Apple M5 Max (G17C B1) (AURORA_BOREALIS)).
  • Combined live M5 Max GLES3/GLES31 + Zink conformance: 124/124 Pass, 0 Fail.

Copy link
Copy Markdown
Author

Second-generation J773g (Apple M4, G16G B0) hardware row: PASS at ea44b8564f4eb59ad3ec9aeb432f14af776897e7.

Ran on the booted 7.3.0-ARCH-m4prod25d kernel. Native Asahi GL, Zink GL, and the Vulkan ICD reported git-ea44b8564f from the private release kit. GL ran with GALLIUM_THREAD=1 and MESA_SHADER_CACHE_DISABLE=1.

Path gpubench-gl --verify dEQP-GLES3 dEQP-GLES31
Native Asahi GL 23/23 OK 758 Pass, 6 NotSupported, 1 QualityWarning 327 Pass, 18 NotSupported
Zink GL 23/23 OK 758 Pass, 6 NotSupported, 1 QualityWarning 345 Pass

Both paths passed the 1080p postfx readbacks at 1× and 4× MSAA and the clear_16m, mipchain, and copy_b2i readbacks. The CTS samples included all five GLES3 flush_finish cases. All 2,220 selected CTS cases finished with zero failures or hangs. The GLES3 QualityWarning on both paths was functional.fbo.completeness.samples.rbo1_rbo2_rbo4.

Zero GPU faults, timeouts, or recoveries during the row. The boot ID stayed the same, display-manager stayed active, and systemd reported zero failed units after the private kit was removed.

@RyanTheTide
RyanTheTide merged commit 0beca10 into aurora-wip Nov 25, 2026
@RyanTheTide
RyanTheTide deleted the perf/tc-idle-inline-flush branch November 27, 2026 13:21
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