Skip to content

hk: improve G17P shaders, submission and AS correctness - #62

Merged
DjDeveloperr merged 18 commits into
aurora-wipfrom
perf/g17-finalized-submit-20261024
Oct 26, 2026
Merged

DjDeveloperr merged 18 commits into
aurora-wipfrom
perf/g17-finalized-submit-20261024

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Oct 24, 2026 •

Copy link
Copy Markdown

G17P compute kernels repeatedly load uniform data per thread, uniform-colour blends recompute source terms per pixel, and command recording cleans entire reserved control-stream regions. Large buffer fills use global shader stores. Application signals also require a separate syncobj transfer after submission, and timestamp-only compute scopes unnecessarily wait for CPU query publication between otherwise independent timed dispatches. This series reduces those costs while preserving independent queue and engine execution. It also fixes AS relocation recording and TLAS serialization with inactive instances.

Added 2026-10-25 (rebased onto aurora-wip 28f65a6)

The series is rebased onto the current aurora-wip. That base includes #63, #64, and #70 (uniform-address atomics on AGX3, which these acceleration-structure gains build on). Five commits are new.

  • Refit without re-planning. A native G17P update keeps the topology of its source, so it restores the source's saved plan instead of re-running the five planning phases. Compacted and deserialized sources carry the plan inside their retained bytes.
  • No scene-bound atomics in update leaf generation. Only Morton code generation reads those bounds, and an update never runs it.
  • Four native nodes encoded per 32-lane workgroup instead of one per 8-lane workgroup. Node encoding was most of every build and refit, and three quarters of each SIMD group sat idle.
  • Occlusion availability carried by the render (2 commits). A render that ends an occlusion query writes availability through its own retirement timestamps. This removes the extra post-render compute command per submission. Leftover writes are merged into one per command buffer.

Measurements on Neo

Workload before now macOS
BLAS build, 64k triangles (Mtri/s) 11.9 26.6 26.3
BLAS build, 1M triangles (Mtri/s) 12.4 29.3 23.1
Fast-build BLAS, 1M triangles (Mtri/s) 12.4 28.3 27.2
Refit, 1M triangles (Mtri/s) 12.6 51.8 152.7
TLAS build, 64k instances (Minst/s) 14.4 27.0 29.6
Occlusion query overhead, depth 1 (µs per submit) ~20 ~1.8 −1.2

Ray traversal throughput is unchanged.

Correctness

  • RT oracles: 68 BLAS/AABB phases (544 ray comparisons) and 11 TLAS phases (88 ray/transform comparisons) pass.
  • Focused occlusion/query/conditional-rendering CTS: 4,097 pass, 0 fail.
  • Scissor, geometry and tessellation groups: 1,132 pass, 0 fail.
  • Full CTS on this head is running at 6 workers.

Changes

  • Enable uniform DMA for application and ordinary internal compute pipelines, sharing the existing validated launch-range publisher. Graphics compute-stage programs and separately precompiled helpers retain their separate paths.
  • Use existing linear PBE writes for eligible aligned, nonsparse G17P buffer fills of at least 64 MiB. Keep bounds checks, command-buffer-owned views and the original fallback for unsupported ranges. The cutoff avoids a measured small-fill regression.
  • Give uniform-colour inline blends their own constant program and launch layout, retaining the previous compile path when the backend or native protocol refuses it.
  • Publish application outputs in the submit ioctl when the kernel advertises cumulative signals. Older kernels and empty submissions retain the syncobj-transfer fallback. Completion scopes add no GPU execution dependencies.
  • Clean written extents of dedicated, unlinked command-stream BOs, including terminators and prefetch padding. Linked streams and invalid extents retain full-range cleaning; completion fences remain in place.
  • On native G17P with exact-prior barriers, omit only the freshly computed same-CDM timestamp execution prefix. Mandatory compute kick parents retain GPU order. Existing stream requirements, query copy/reset dependencies, cross-engine scope and the legacy path remain unchanged.
  • Build the existing G17P AS rebase and instance-record restoration helpers, fixing clone/compact recording failures caused by missing target-map entries.
  • Keep null-reference TLAS instances inactive, fully initialize nonnull masked/empty-BLAS leaves for legal updates, and initialize/relocate empty native AS identity. This fixes the serialized header claiming three BLAS references when only two were emitted.

Kernel companion: aurora-silicon/linux#423, targeting integration/aurora. Cumulative publication uses feature bit 17 and output sync type 2.

Final artifact validation

Clean Mesa commit 7c68adfc257201dcd5f7308fa2f0395fe4734fc0 was rebuilt with the qualified shader compiler. Vulkan library build ID: 53a9fb9740865d0f8426fc5f40d38a2b67f237d0; SHA256: 0a2c688bbc98650e6c7771602599abdb1aea8bff91ddfa35fa55a3bc574409ee.

That exact artifact passed on Neo with kernel source 5b25f951ab88f24fec3fe2f06020b4cf0f70c49a, Asahi build ID d1b39857cb8e51b1f5249d3f1c11af3fa3205f43 and retained core aa79324715fb0973934ebc4c1a6aa2ed2bf02de4:

  • All 24 query and injected-error cases, 49 repeated core rows and 28 rotating fill/copy rows.
  • All 15 whole-buffer readback/canary cases, including an aligned 64 MiB + 16-byte fill with a partial workgroup, and copy/fill/copy within one command buffer.
  • Eight fill-canary clients, concurrent two: 120 cases and 2,013,511,680 checked words. Each client had an observed mapping of the exact selected library.
  • 10,000-iteration cross-queue order and data checks, 35-second 18-client compute/render pressure, and 20-second mixed compute/render device churn.
  • Actual emitted fill shader inspection confirms image writes through the existing native PBE encoder, retained element bounds and uniform-DMA parameters.

No data errors or new GPU faults were observed, and the desktop remained alive. These are bounded development checks, not sustained qualification. All generated precompiled helper C remains byte-identical to preceding clean d6d814afdb8.

Prior-head AS correctness evidence belongs to d6d814afdb8, library 0866e00bc281d0696f636b8feb058c644387a35afc0ecd06ee7a5d673b269b54, build ID 3981e3acc2000f44a89dd983499988634df6a951: all 17 TLAS phases / 136 ray and transform comparisons, all 68 BLAS/AABB phases / 544 ray comparisons, and 16 RT churn clients / 680 phases / 5,440 comparisons passed. Those AS fixtures have not been rerun on this latest head. No RT throughput improvement is claimed.

Large buffer measurements

Seven rotating repetitions of each workload on the clean artifact measured 64 MiB fill medians of 1,602.56 us at depth 1 and 1,326.26 us at depth 4, versus a fresh baseline return of 1,650.17 and 1,381.22 us: 2.9% and 4.0% lower time. Earlier before/candidate/return comparisons corroborate the fill improvement. Copy controls on the clean artifact were flat at depth 1 and 0.5% lower at depth 4; no broad copy improvement is claimed. The seven representative core workloads ranged from -1.44% to +0.54%, with no established core latency gain.

Separate size probes found gains at 96–256 MiB, but additional recording overhead of about 2.3 us and a one-time cold pipeline/view cost. The new path therefore starts at 64 MiB. One unpaired 4 MiB record-per-submit probe was 3.35% slower. A subsequent three-pair alternating baseline/candidate check completed 96 rows / 19,200 submissions: that row was 0.85% faster by the median of run medians, with two of three pairs faster. Other small sizes varied in both directions; the 32 MiB medians were about 1.9–2.0% slower, with individual pairs ranging from approximately -4.7% to +5.0%. This does not establish a stable small-fill regression or blanket absence of regressions. The same paired probe repeated the 64 MiB gain at 3.2–3.4%. These are measured development medians, not significance or sustained-qualification claims. The recorded macOS fill medians remain 1,243.78 and 1,033.06 us: Linux is still about 29% and 28% slower. This change does not satisfy the all-benchmark gate.

Retained query and performance evidence

Earlier heads passed 2,859 resolver checks and 132 barrier checks, including legacy controls, genuine query-memory dependencies and secondary replay. Ten standalone query cases and ten isolated injected-error cases passed on both timestamp-change heads: compute preserved exact inherited ECANCELED, and empty predecessors preserved raw EIO/ECANCELED scope. These check public aggregate errors and genuine query dependencies; they do not claim identical internal execution suppression after failure. Published software-fence ordering, 256-submit backlog, deadline forwarding and native fan-in results are also prior-head evidence.

Seven same-boot query pairs reduced depth 16 timed dispatch medians from 158.7932 to 20.2347 microseconds; signed timestamp-overhead median changed from 138.7787 to 0.1609 microseconds. All seven timed pairs improved. This remains behind the recorded macOS signed overhead of -0.465 microseconds; depth 1 did not establish a reliable throughput gain.

Range cleaning reduced API recording elapsed medians (microseconds): compute depth 1 3.375→1.125 (21 pairs), compute depth 64 2.625→0.875, render depth 1 2.916→1.875, and render depth 32 3.310→2.458 (7 pairs each). These CLOCK_MONOTONIC measurements include descheduling. The 21-pair compute depth 1 wall-time comparison remained inconclusive: median paired difference +1.5797 microseconds, 10 faster/11 slower pairs. Queue-hop median paired difference was -0.2867 microseconds. No depth 1 throughput win or macOS parity is claimed.

Earlier individual shader changes measured compute ALU 1527→1418 microseconds and 1080p blended fill 1005→737 (depth 1), 789→553 (depth 4). Cumulative publication reduced measured submission API elapsed from about 14 to 10 microseconds. These are workload-specific historical measurements. Historical shader gates passed 1,885 compute/binding cases, 23,145 wider compute cases, 7,458 fragment cases and 378 CPU blend comparisons; they do not qualify this final head.

Complete benchmark scope and merge order

The complete 209-configuration record belongs to preceding Mesa 5623937852679bc099bc753ff6c5a2c347d2dbad, library f4998b2ee9c1c997dc99b8bbe7db42da123b1d641edfaf5a37ed67747f1d53ae, on the identified 5b/AA kernel pair. Against the recorded macOS run, 207 comparable primary medians produced 55 strict wins, 143 slower and 9 ties; two reference skips remain noncomparable. This is historical evidence: no complete 209-configuration run is claimed for the latest head. Representative/repeated development rows cannot establish that full gate, and measured medians are not statistical significance.

All CTS work, including preparation and small slices, remains stopped until Linux strictly exceeds macOS in every comparable benchmark. Then the final pair must pass proper sustained stress and full applicable Vulkan CTS before merge. Both companion PRs remain draft and unmerged. Earlier CTS evidence does not satisfy the final gate. Diagnostic batching/queue-count controls, failed count estimates, scheduler experiments and other unqualified work are excluded.

Error reporting under memory pressure (89bb9b9)

Transform-feedback draws build an internal passthrough geometry shader on first use. When that build failed, the command buffer recorded VK_ERROR_FEATURE_NOT_PRESENT whatever the cause, so an out-of-memory upload under a cgroup memory limit showed up as a CTS failure. The compile result now propagates. Under the same pressure (neo/mempressure-repro.sh, 2800 MiB hog in a 3000 MiB cgroup) the case reports VK_ERROR_OUT_OF_DEVICE_MEMORY, a ResourceError. Without pressure, dEQP-VK.transform_feedback.simple.* gives 4983 pass, 0 fail and 2908 not supported.

Pair triangles in G17P leaf records (30c14dc, e1e3c6d)

A G17P triangle record holds two triangles that share an edge, but we stored one per record. BLAS builds now pair sibling triangles that share an edge, in plan phase 0 with no extra pass. The generated intersector applies our edge and vertex ownership rules to the second triangle too, with an exact sign for the shared edge when it rounds to zero. Pairing is limited to non-updatable, non-fast-build triangle BLAS. Every other build runs byte-identical shaders.

On Neo, against the same Mesa without these commits:

before after
compacted BLAS, 65k / 1M triangles 95.9 / 95.5 B/tri 52.5 / 52.1 B/tri
rt.rays coherent d1 / d4 +6.7% / +7.2%
rt.rays incoherent d1 / d4 +2.3% / +3.1%
rt.scene light d1 / d2, medium d2 +1.8% / +2.2%, +1.9%
BLAS build 65k / 1M +5.2% / +4.8%
fast build, refit, TLAS unchanged

Watertightness: 0 new holes on 57 ray grids (both windings, every vertex rotation, opaque and non-opaque), and 114 of base's own holes on mixed-winding meshes are filled. Targeted ray-query + ray-tracing-pipeline CTS: 5615 cases, 5343 pass, 257 not supported. ray_query has 0 non-pass. The 15 remaining non-pass cases are all host-built 1M / 4×65536 acceleration structures that exhaust the 6 GiB test cgroup. That is the host build path, which these commits do not change, and the smaller ones among them pass when rerun alone.

Cumulative signals are feature bit 29 (309c3fe)

Follows aurora-silicon/linux#423, which moves cumulative signals off bit 17, the bit the M5 line uses for render resources. A kernel that still reports bit 17 is treated as lacking the feature and gets per-point signals; a kprobe on the new kernel counted 74,260 cumulative outputs with this Mesa and 0 with the previous one. Gate PASS and targeted CTS 0 fail on the pair.

@DjDeveloperr DjDeveloperr changed the title hk: improve G17P compute, uniform blends and completion publication hk: reduce G17P compute, blending and command submission costs Oct 24, 2026
@DjDeveloperr DjDeveloperr changed the title hk: reduce G17P compute, blending and command submission costs hk: improve G17P shaders, submission and AS correctness Oct 24, 2026
@DjDeveloperr
DjDeveloperr force-pushed the perf/g17-finalized-submit-20261024 branch from 7c68adf to 4a85090 Compare October 25, 2026 05:26
An application compute kernel on G17P forms no preamble, so every thread
loaded its push constants, dispatch base and buffer descriptors from the
root table and its descriptor sets, and the scheduler serialised those
loads: compute.light paid three dependent memory latencies per command,
and compute.heavy alu read its FMA operands a and b from GPRs.

Key application compute kernels for uniform DMA like vertex and fragment
programs, and publish their spans from the compute descriptor state in
the launch's uniform ranges. The span publishing is shared with the
graphics stages (hk_g17p_dma_ranges()). Driver-internal kernels and the
compute-stage programs of graphics keep their loads.

Measured on Neo (int5 module, gpubench):
  compute.heavy alu d1: 1527 -> 1418 us/submit (GPU 1287 -> 1183 us)
  compute.light:        GPU timestamps 2.92 -> 1.92 us,
                        firmware run per command 2.8 -> 2.3 us (d1),
                        2.5 -> 2.1 us (d64)
SCP:SL pipeline cache (G17P shim): compute instructions -2.9%, GPRs -0.4%.
CTS compute/push-constant/binding/robustness2/descriptor-indexing gate:
1885 pass, 0 fail. Stress gate passes.
When a fragment main exports only uniform values, such as a colour from
push constants, every source term of its blend is the same for every
pixel. The inline-blend program still recomputed them per pixel: four
clamps (after copying the uniforms to GPRs), 1 - alpha and the source
factor products, 20 ALU instructions per pixel for an alpha-blended
RGBA8 fill. Compute the uniform source terms once in a constant program
and blend with one FMA per channel.

A push-constant-only fragment forms no constant program, and the
inline-blend program had to reuse the API shader's uniform layout, so it
could not form one either. Now such a program is compiled with its own
constant program (falling back to the old compile when the backend or the
native constant-program protocol refuses it). It is linked as the main of
a layout shader that describes its uniforms, constant program and code,
owned by the linked shader, and the draw launches from that layout
instead of the API shader's. The blend becomes wait, tile load, two
unpacks, four FMAs with uniform operands, two packs, wait, tile store.

Measured on Neo (int5 module, gpubench render.heavy fill 1080p, 16
alpha-blended full-screen layers):
  d1: 1005 -> 737 us/submit, GPU 818 -> 561 us (macOS 552 us)
  d4:  789 -> 553 us/submit (macOS 653)
render.light (no blend) is unchanged. A push-constant/uniform-math/
flat-varying blend check over seven blend states and three formats
matches a CPU model; a fragment CTS gate (11128 blend, draw, dynamic
state, render pass, shader object and glsl cases) has no failures; the
stress gate passes.
Use the advertised cumulative-signal capability to include earlier queue completion in application outputs without adding GPU execution dependencies. Retain syncobj-transfer fallback on older kernels and for empty submissions.

Validated with the matching G17 kernel on Neo: full stress, mixed-engine and empty-wait scopes, binary and timeline outputs, a 256-submit backlog, deadline hints and error propagation.
Dedicated stream uploads reserve 64 KiB roots but often write only a small prefix. Mark BOs allocated exclusively by the stream uploader and clean each live unlinked stream through its current pointer plus the existing prefetch padding, bounded by its reserved end. Keep the conservative whole-BO path for linked streams and invalid extents, and preserve all cache-clean completion fences.

The exact helper passes host coverage and overflow checks. Hardware validation and before/after timing remain pending.
Logical compute kick parents already preserve GPU execution order. A timestamp-only same-engine prefix additionally waits for CPU result publication, serializing independent timed dispatches across submissions.

Omit only the freshly computed CDM timestamp dependency on native G17P with exact-prior barriers. Preserve existing stream requirements, query-memory dependencies, other engines and legacy kernels. Add resolver coverage for those boundaries and secondary replay.

On Neo, seven alternating pairs reduce depth-16 timed-dispatch medians from 158.79 to 20.23 us. Both stacks pass ten standalone query correctness cases and ten exact injected-error cases; the candidate also passes all 19 development rows and concurrent data/order/churn pressure without new GPU faults. This does not establish full-suite macOS parity or final CTS qualification.
Native AS copy dispatches rebase and instance-record restoration, but the target helper allowlist omitted both programs. Cloning could therefore fail command recording with FEATURE_NOT_PRESENT before submission.

Compile these existing helpers for G17P while retaining the other targets unchanged. Their native metadata and argument packing pass stream validation. Neo passes 68 BLAS/AABB update and copy phases, concurrent RT churn and the short pressure gate. Separate TLAS copy/compaction/update checks verify both transforms across different slot biases. A pre-existing TLAS serialization handle-count mismatch remains under investigation; this change does not claim full RT or CTS qualification.
Keep null-reference instances inactive when retaining updateable topology.
Initialize nonnull masked and empty-BLAS instances so legal mask and
reference updates retain valid bounds and metadata.

Initialize the complete native empty image, including its owned base and
resource ID, and relocate that identity when copying an empty structure.
This fixes poisoned TLAS leaves and an extra serialized BLAS reference.

Validated on G17P with 17 TLAS phases and 136 ray/transform comparisons,
including masked and degenerate updates, and 68 BLAS update/copy phases
with 544 ray comparisons. Host checks and native command validation pass.
Ordinary meta compute pipelines use the same launch range publisher as application compute. Include them in the existing lowering while retaining both compute-stage checks; graphics emulation and precompiled helpers keep their separate launch contracts.
Route eligible aligned, nonsparse fills of at least 64 MiB through a command-buffer-owned RGBA32_UINT texel view. Preflight the existing native descriptor codec and verify the created view, retain the element guard, and keep the original algorithm for unsupported ranges.

Rotating 64 MiB measurements improve fill time by approximately 3-4 percent. Query/error, boundary readback, cross-queue order/data and bounded concurrent pressure checks pass. The cutoff avoids a measured small-fill regression.
An update of a native G17P acceleration structure refitted the retained
binary IR, then ran all five planning phases again before encoding the
nodes: initialisation, the leaf-count pass, a walk from every node to
the root to classify it, and the atomic job and slot allocation. An
update has the topology of its source, so that work rebuilt the same
plan every time.

Keep the plan of a full build after the retained IR: the plan state and,
per encoding job, its IR node, root slot and child slot (12 bytes). The
leaf counts the plan walks need go into the retained internal nodes'
bvh_offset field, which nothing reads after the common build. An update
copies the plan back to scratch after leaf generation (refit phase 5, or
phase 6 when the update writes another structure, which also receives
the plan), and plan phase 4 rebuilds each job from its record with
emit's bounded walk before it finishes the envelope. The update then
encodes the nodes over the existing layout with the refitted bounds: no
classification walks, no allocation, the same slots.

The source plan is found through the source's metadata, so compacted
and deserialised copies update in place as before, and copies carry the
plan inside the retained bytes.

G17P native path only. An update records 9 compute launches instead of
12 (6 strong barriers instead of 10); a full build of an updatable
structure records one more, which saves the plan. The size bound of an
updatable structure grows by 32 bytes plus 24 bytes per primitive (12
bytes per job in use). Plan shader 1023 -> 1544 instructions, refit
343 -> 547, envelope 830 -> 866, with unchanged register counts and
occupancy.

Checked on lavapipe by running these shaders over generated binary IR:
in-place, src != dst, chained and compacted-source updates encode native
images byte-identical to a full build of the same topology, for
triangles and AABBs from 1 to 65536 primitives.
Leaf generation adds every active primitive to the header's scene bounds
with six uniform-address atomics. Only Morton code generation reads those
bounds, and an update keeps its retained topology, so it never runs.

Add a leaf build flag that omits the scene-bound atomics and set it in
vk_cmd_build_as_leaves, which only the honeykrisp update path calls. The
active-leaf count, which the native plan still needs, is unchanged.

Those atomics all target one cache line; an update now issues none.
Native node encoding ran one job per eight-lane workgroup, so the SIMD
group running it was three-quarters idle, and inside a job lane zero
quantized all eight child boxes into the root node while two lanes wrote
every QTB vertex byte, 48 quantizations each, one after another.

Encode HK_AGX3_NODE_JOBS_PER_GROUP (four) jobs per 32-lane workgroup.
Each child's lane now also computes its own root word (header bits and
quantized bounds) and its triangle's QTB vertex bytes, which are
combined in shared memory and written by the block's lane as before;
lane zero still fits the root bounds and the first lanes the QTB
headers. Every lane reaches every barrier: a slot without a valid job
only stops working. Plan phase 4 writes the encoding dispatch, whole
workgroups of jobs, after the plan state, and the encoder reads the job
count it rounds up from the state.

The encoded structures are byte-identical to the previous encoder's:
checked on lavapipe with the AS shader harness for triangles and AABBs
from 1 to 65536 primitives, including mixed opacity, in full builds,
updates and compacted-source updates.

G17P native path only. The encoder shader goes from 1994 to 1834
instructions and from 127 to 111 registers (832 to 896 threads), for
four nodes per workgroup instead of one.
Every occlusion query that ended in a render made the availability word
available from an extra post-graphics compute command. With one render
per submission that is a second firmware command, ordered after the
render, on every submission.

A render's retirement record has four timestamp slots. The kernel writes
each requested slot when it retires the render, after the end-of-render
cache maintenance that makes the occlusion counts visible and before it
signals the submission. Native occlusion pools now keep 64-bit
availability slots in a buffer bound for timestamps, so a nonzero slot
written that way means available. The reset and range-copy kernels take
the slot width.

Only a query that began in the render that ends it qualifies: renders
of one queue may finish out of order, and the store waits on every
earlier render. The queued store is still recorded, but its stream stays
empty until the end of the command buffer. When no later compute work in the command
buffer, and no carried requirement, waits on the render (such work would
otherwise wait for host retirement instead of firmware), no API timestamp
rides on the stream, and the render has free slots, the render carries
the availability and the stream is dropped. Otherwise the store is
emitted exactly as before. A slot holding a retirement timestamp also
lets a CPU read skip the submission wait, which only guards the queued
store against early counts.

gpubench query occlusion overhead on A18 Pro, alternating with the
previous build: d1 19.4-24.1 us -> 1.7-7.3 us, d16 14.8-19.7 us ->
-4.9-5.6 us; readback 1.4 us -> 0.08 us. Timestamp queries unchanged.
A render has four retirement timestamp slots, so a render that ends more
occlusion queries than it has free slots still needed its queued
availability store, one compute command per such render.

When no later work in the command buffer waits on such a store or, from
compute, on its render, move it into the latest such store instead. That
stream waits on a later render, and a render wait covers every render
before it, so the queries become available no earlier than their own
renders finish. A command buffer with any number of these renders then
emits a single compute command.

Host query tests and an availability test with three renders of six
queries each, read on the CPU and copied from a later submission, pass on
A18 Pro.
@DjDeveloperr
DjDeveloperr force-pushed the perf/g17-finalized-submit-20261024 branch from 4a85090 to 360a1c9 Compare October 25, 2026 05:29
Binding the passthrough geometry shader for transform feedback compiles
it on first use. When that compile failed, the command buffer recorded
VK_ERROR_FEATURE_NOT_PRESENT whatever the cause. Under memory pressure
the cause is an out-of-memory upload, and vkEndCommandBuffer then
reported a missing feature instead of VK_ERROR_OUT_OF_DEVICE_MEMORY.

Return the compile result from hk_meta_shader() and record it.
A G17P triangle record holds a second triangle B = (v2, v1, v3) beside
A = (v0, v1, v2), sharing A's edge v1-v2. The generated intersector
applies our edge and vertex ownership rules to A only. That is all a
record with a degenerate B needs. A real B was decided by the native
rule instead, which disagrees with ours on the edges B shares with other
records. And when the shared edge function rounds to zero, B's exact
path takes its sign from products that do not form that edge. Both left
holes exactly on edges.

Apply the ownership rules to B as well, with its edges in its own
direction. Form the products of the shared edge in registers the body
never reads otherwise, and when that edge function rounds to zero but is
not exactly zero, take its sign from their residuals. A record without a
second triangle keeps its current results.

With records holding two triangles, ray grids over meshes on A18 Pro,
including non-planar quads and both assignments of a quad's triangles to
A and B, hit everywhere single-triangle records do, from both sides. The
ray-query and ray-tracing-pipeline watertightness tests pass.
A G17P triangle record holds four vertices and two primitive words. The
hardware tests A = (v0, v1, v2) and B = (v2, v1, v3), B sharing A's edge
v1-v2 in the opposite direction. Bits 30-31 of each primitive word,
above its 30-bit index, give the rotation of that triangle's vertex order
against the stored one, which the hardware applies to the barycentrics it
reports. We stored one triangle per record, repeating v2 as v3, so a
BLAS took twice the records and quantized-triangle entries it needs.

When a binary IR node's two children are triangles of one geometry and
opacity that share an edge, plan phase 0 marks the node a pair and counts
it as one leaf. Its leaf job then names the node, and node encoding
stores both triangles in one record: triangle 0 rotated so the shared
edge becomes v1-v2, triangle 1 given by its opposite vertex, and both
rotation codes. Pairing reads the IR the build already has, needs no
extra pass, and keeps the common builder's partition.

Only triangle structures that cannot be updated and do not prefer a fast
build are paired. An update refits the build's plan one triangle per
record, and on a fast build of a million triangles finding pairs cost
more than it saved. The plan and node encoding that pair are separate
builds of their shaders, so every other build runs the shaders as before.

On A18 Pro, against the same Mesa without this change:
  compacted BLAS, 65k triangles:  6.23 -> 3.41 MB (95.9 -> 52.5 B/tri)
  compacted BLAS, 1M triangles:   99.9 -> 54.6 MB (95.5 -> 52.1 B/tri)
  rt.rays coherent d1/d4:         +6.7% / +7.2%
  rt.rays incoherent d1/d4:       +2.3% / +3.1%
  rt.scene light d1/d2, medium:   +1.8% / +2.2%, +1.9%
  rt.scene light, trace pipeline: +2.7%
  BLAS build 65k / 1M:            +5.2% / +4.8%
  fast build, refit, TLAS build:  unchanged

Hits, primitive IDs, facing and barycentrics match single-triangle
records on ray grids over meshes using every rotation and both windings.
Targeted ray-query and ray-tracing-pipeline CTS (5615 cases) pass but for
host-built structures that exhaust memory under the test's 6 GiB limit.
Follow the kernel, which moves cumulative signals off bit 17, the bit the
M5 userspace line uses for render resources. A kernel that still reports
bit 17 is treated as lacking the feature and gets per-point signals.
astaff pushed a commit to astaff/mesa that referenced this pull request Oct 28, 2026
…) into the consolidation

Merge aurora-wip at f2c9dc3 (acb2189 plus aurora-silicon#62, 309c3fe, 18
commits) into the consolidated tree da770a4. aurora-silicon#62 branched at 28f65a6,
before the consolidation's M5 (G17G/G17S) snapshot made several G17P-only
paths shared with M5, so both sides rewrote the same native AGX3 code.
Each conflict is resolved by chip, keeping both designs: G17P and the other
native AGX3 chips take aurora-silicon#62's, M5 keeps the consolidation's. Nothing new is
configurable.

Native AS encoder (agx3_leaf.comp, hk_build_interface.h, bvh/meson.build):
- The two encoders are separate sources selected by the device's chip
  (hk_agx3_as_format_for_chip(), new hk_agx3_as_format.h). bvh/agx3_*.comp
  are the consolidation's M5 encoders, unchanged but for one field name
  (m5_aabb_stride, below) (8-lane node workgroups
  through the batch job map, 48-byte bounding-box records, 1 KiB images).
  bvh/agx3_gen1_*.comp are aurora-silicon#62's G17P encoders, unchanged (four node jobs
  per 32-lane workgroup with a GPU-written indirect dispatch, triangle-pair
  records, 64-byte records, 16 KiB images), built as the hk_agx3_gen1_*
  programs hk_acceleration_structure.c already used.
- The consolidation's -DHK_AGX3_GEN1 builds of agx3_*.comp were G17P's
  previous encoder; preprocessed with HK_AGX3_GEN1=1 they match the merge
  base 28f65a6 (only redundant zero stores, reordered exclusive stores and
  a refactored helper differ), which aurora-silicon#62 builds on. aurora-silicon#62 supersedes them for
  G17P, so they are no longer built. M5 never used them.
- Without the split the auto-merge combined the consolidation's G17P
  shaders (one node per workgroup) with aurora-silicon#62's G17P dispatch (four per
  workgroup, indirect counts), and put aurora-silicon#62's plan-state tail into M5's
  scratch layout too.
- hk_agx3_as_layout.h derives image alignment and the plan tail from the
  format: GEN1 status follows the 48-byte plan state plus encode dispatch
  arguments (aurora-silicon#62), M5 keeps its 32-byte plan state.
- hk_build_interface.h stays shared, holding both sides' additions (aurora-silicon#62's
  leaf counts and plan pairs fields, the M5 batch job structures). M5's
  push and batch structures therefore grow by aurora-silicon#62's fields, which M5
  leaves zero and its encoders never read; its ABI asserts are updated
  (leaf args 32, plan args 120, batch job 152, first_job at 140). Separate
  per-chip structs of the same name would break hk_cmd_encode_agx3_nodes(),
  which forwards one struct to the M5 backend.
- aurora-silicon#62 renamed the hk_agx3_plan_args word that M5 uses for its diagnostic
  bounding-box record stride (reserved) to plan_restored, its G17P update
  flag. Each format keeps its meaning of that word: M5 code names it
  m5_aabb_stride, an alias defined and documented next to the field, so
  neither side's push layout changes.
- Build-time asserts pin each layout (plan tail, record and slot size,
  alignment, encoder workgroup) next to the backend that uses it.
- AS entry points dispatch on hk_agx3_as_format_for_chip(), which maps
  exactly what agx_chip_g17_m5() mapped. Each format's refit, traversal
  (compiler/agx3_rt_gen1_* for GEN1), serialization, relocation, copies and
  property queries (libagx_gen1_as_* vs libagx_agx3_as_*) were already per
  format and are unchanged.
- tests/test-hk-agx3-as-format.c checks for every chip the selected format,
  its scratch and image layout, and the encoder and refit SPIR-V its
  pipelines are created from (workgroup shape per format and variant).

Queue signals (hk_queue.c): the in-ioctl cumulative output
(DRM_ASAHI_SYNC_TIMELINE_SYNCOBJ_CUMULATIVE) is used exactly where aurora-silicon#62
enabled it: G17P with DRM_ASAHI_FEATURE_CUMULATIVE_SIGNALS. M5 keeps the
consolidation's signalling unchanged (cumulative transfer after the ioctl
with INDEPENDENT_QUEUES, chunked timelines); the two never combine because
chunked timelines are M5-only.

Occlusion availability (hk_query_pool.c, hk_cmd_buffer.h): native AGX3
pools take aurora-silicon#62's 64-bit availability slots in a bound timestamp buffer and
render-carried availability, chosen at pool creation by
agx_native_graphics(); M5 pools keep 32-bit slots, the queued 32-bit store
and lazy counter assignment. At query end M5 transform feedback queries
still publish after their pre-graphics helpers; only native occlusion pools
can take the stamped path. Both sides' state fields are kept.

Compute uniform DMA (hk_cmd_buffer.c, hk_cmd_dispatch.c, hk_shader.c):
aurora-silicon#62's shared hk_g17p_dma_ranges() serves graphics on every chip (the
consolidation's loop was the same code) and compute on native AGX3; M5
compute keeps hk_m5_compute_uniform_dma_ranges() appended by its caller.
hk_g17p_compute_uniform_ranges() takes both the chip (M5 root and texture
uniforms) and the command buffer (aurora-silicon#62, NULL when prewarming) and counts
spans only off M5, so no chip adds them twice. The compute DMA enable is
aurora-silicon#62's term on native AGX3 or the consolidation's on M5. The Gen1 ray-query
range limit becomes HK_G17P_COMPUTE_MAX_RANGES (aurora-silicon#62): the consolidation's
8-range limit assumed G17P compute had no spans.

Mechanical: asahi_drm.h keeps the M5 feature bits 17-28 and aurora-silicon#62's
CUMULATIVE_SIGNALS (bit 29) and cumulative sync type (2); no value
collides. hk_cmd_draw.c uses aurora-silicon#62's two-attempt monolithic compile with
the consolidation's inline-samples layout check inside it (inline samples
are M5-only, uniform exports G17P-only, so they never combine), and the
cached-program check passes own_layout=false.
test-hk-sync-prior.c's link stub from aurora-silicon#62 (0b03b01) defines
hk_flush_deferred_clears_why(), the function behind the consolidation's
hk_flush_deferred_clears() macro.

Not resolved by chip because they are chip-agnostic: aurora-silicon#62's common Vulkan
runtime update-path changes (leaf.h, vk_acceleration_structure.c,
vk_bvh_*) also apply to M5 builds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RyanTheTide
RyanTheTide deleted the perf/g17-finalized-submit-20261024 branch October 30, 2026 03:23
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.

1 participant