Repository navigation
Add M5 series GPU userspace support - #47
Conversation
The M5 series was written against a kernel that numbers its features in the old order and puts the M5-only ones at bits 8-14 and 23-26. This header uses the merged numbering, where bits 0-16 are taken. Add the M5 items after them: - features: RENDER_RESOURCES 17, RENDER_RESOURCES_V2 18, SPARSE_TILES 19, COMPUTE_MATRIX 20, TASK_MESH_STORAGE 21, RENDER_SHADER_WRITES 22 (the values of the earlier merged-numbering M5 kernel), M5_DEPTH_MSAA_COMPRESSION 23, COMPUTE_STAGE_BARRIERS 24, M5_STENCIL_MSAA_COMPRESSION 26 (their M5 values, free here) and COMPUTE_RESOURCES 28 (bit 16 is now BOUNDED_AS_BUILD; 25 and 27 stay reserved for the M5 runtime); - compute flag USES_MATRIX at bit 16 (bit 1 is WIDE_VISIBILITY in the merged kernel, bit 2 AS_BUILD); - render flags SHADER_WRITES 21 and COMPUTE_STAGE_BARRIERS 22, bind flag SPARSE_TILE 4 and command types 5-7, which collide with nothing; - the render/compute storage declarations and the render command with a tiling-half compute prefix. That one extends drm_asahi_cmd_render_with_prior, so its tail starts at byte 336, where the ray-query stage state would be; M5 sends no ray-query stage state. The M5 kernel must use the same numbering. Signed-off-by: Diljit Singh <hey@djdev.me>
Add the M5 compiler, library and Honeykrisp support as one snapshot of the hardware-qualified M5 tree, consolidated for rebasing onto agx3b. The M5 changes made after it follow as individual commits. On aurora-wip, every native-path test that the snapshot widened from `chip == G17P` to `G17P || M5` takes aurora-wip's predicate (agx_chip_native_agx3(), agx_native_graphics(), ...) `|| agx_chip_g17_m5()`, so G15S/G15C and G17P keep aurora-wip's behaviour. Snapshot changes made for M5 that would also reach other chips are scoped to M5: ray-tracing pipelines keep the single megakernel off M5 (one kernel per raygen group on M5 only), the Gen1 ray-query range bound stays at 8, the BVH planner's single-leaf phase stays out of the Gen1 variant, cumulative API signals stay with G17P plus M5 with independent queues, relative queue priorities and the HIGH/REALTIME classes apply to M5 only, and the acceleration structure and mesh-query features the snapshot turns off are turned off on M5 only. The M5 UAPI names come from the merged-numbering header. Signed-off-by: Diljit Singh <hey@djdev.me>
The classic AGX2 restorations select the upstream behaviour for every chip that is not native AGX3, which includes M5. M5 records its barriers and render passes with the native dependency tracker, folds the API sample mask into its forced-early coverage word like native AGX3, and exposes the same extension profile as before the restorations. Exclude M5 from the classic pipeline-barrier boundary, from the graphics dependency published at the end of each classic render pass and from the classic API sample mask with forced early tests. Keep VK_KHR_unified_image_layouts, VK_EXT_conditional_rendering, VK_EXT_memory_budget and VK_KHR_shader_fma on M5. G13-G15 and G17P are unchanged. Signed-off-by: Diljit Singh <hey@djdev.me>
Preserve the qualified M5 mesh and AS layouts alongside the Gen1 paths. Select BVH generation at shader compilation and retain chip-specific resource, SCS and descriptor contracts. Update shared interface checks. Validation: all 36 Asahi host test suites pass. Hardware qualification is pending; the installed M5 driver is unchanged. Signed-off-by: Diljit Singh <hey@djdev.me>
The rebase duplicated task-payload layout lowering and inflated a four-byte payload to eight bytes, rejecting the existing M5 payload contract. Keep one lowering pass. The resulting mesh and fragment shader bytes match the snapshot. Validation: all 36 Asahi host test suites pass; the original CTS pipeline compiles through the DRM shim. Hardware execution qualification follows. Signed-off-by: Diljit Singh <hey@djdev.me>
Lower TCS ray queries through the native compute traversal path and bind its SCS resources for internal tessellation-control dispatches. Reserve the native query uniform prefix even though lowered TCS retains its API stage, so descriptor roots cannot overlap the traversal state. Keep geometry and hardware graphics stages outside this path. Add compiler coverage for the TCS candidate protocol and transactional stage rejection. M5 qualification: 298 TCS cases pass, 249 are unsupported, and the single-hit watertightness case still fails. RT, matrix, mesh, and derivative regression results remain unchanged; no GPU fault occurred in the 5,025-case gate. Signed-off-by: Diljit Singh <hey@djdev.me>
Drive the AGX3C tile-store lifetime hint from the payload last-use flags. Multisample epilogs can share a packed color across samples; releasing it on the first store zeroed later samples. Keep the existing AGX3B policy. Add a compiler regression for repeated tile payloads. The test fails on the previous compiler and passes with this change. M5 hardware: all four image.general_layout.msaa failures now pass, with no other changes in the paired image and rasterization regression sets. The failing epilog retains its instruction count, size and GPR allocation; only three lifetime bits change. The tile-data-copy probe remains disabled. Signed-off-by: Diljit Singh <hey@djdev.me>
Allow graphics-pipeline triangle mesh shaders to discard unused point-size writes before validating the native output layout. Keep shader-object compilation on its existing path and distinguish the pipeline context in M5 mesh shader cache keys. Encode the M5 output limits from the declared vertex/primitive counts and UVS words instead of the fixed small-mesh values. Cover the native packet values captured for mesh-cell, primitive-ID and overlap draws. Validation: 36 host suites passed. A 28,012-case mesh comparison gained three depth-only triangle passes with no other status changes or GPU faults. Cold-cache, warm-cache and cache-disabled mixed checks passed 69/69, followed by 23/23 checks of the system-installed driver on M5 Pro. Signed-off-by: Diljit Singh <hey@djdev.me>
Keep oversized eight-sample fragment bodies as NIR until their draw epilog can be inlined. Resolve color exports to SSA before expanding the complete sample body so all samples do not occupy the fixed export register file. Use the reserved low uniform gap for the native spilled-target heap and fold sample masks before lowering them to live coverage operands. Refuse any failed mandatory inline link and invalidate older shader binaries. M5 Pro hardware: 17,140 graphics and multisample cases; 4,796 Pass, 12,344 NotSupported, no Fail or GPU fault. Exactly two rasterization-order cases changed Fail to Pass. Cache checks passed 105/105, installed-driver checks 35/35. Clean build and all 36 Asahi host suites passed. Signed-off-by: Diljit Singh <hey@djdev.me>
Canonicalize the output topology only when a mesh shader has no output reads or writes and one constant-zero vertex/primitive count dominates its exit. This retains its buffer work and uses the existing native M5 triangle path for the empty geometry. Keep nonempty and conditional output paths unchanged. M5 Pro: 2,026 Fail-to-Pass changes in a paired 32,248-case mesh/subgroup run, with no other status changes or GPU faults. The candidate has 2,434 Pass, 29,215 NotSupported and 599 remaining Fail. All 36 host suites passed, including the new guard and compile checks; cache repeats passed 114/114 and installed-driver checks passed 38/38. Signed-off-by: Diljit Singh <hey@djdev.me>
Admit the existing AGX3C SR34 encoding for mesh-stage active invocation indices. The stage whitelist previously rejected elect, broadcast-first and vote operations after their NIR lowering. Add a packer regression covering low, odd and high half-register outputs. All 327 compiler tests pass. On M5 Pro, a paired 76,633-case mesh/subgroup comparison produces 99 additional subgroup passes without Pass-to-Fail changes or GPU faults. A separate intermittent invocation-ID output result is retained independently and is not counted as a fix. Signed-off-by: Diljit Singh <hey@djdev.me>
Lower M5 mesh image descriptors to native heap indices, stage read coordinates, and publish the indexed texture/sampler heaps at launch. The previous path left a software descriptor operand at the packer and then rejected the mesh stage when collecting the native uniform ranges. Admit mesh workgroups through the advertised 1024 invocations. Linearize the 1024-wide Z dimension for the native threadgroup field while preserving the API local and global IDs and retaining all invocations. Add regression coverage for image lowering, staged reads and workgroup bounds. All 330 compiler tests pass. Four targeted Vulkan CTS cases and 489312 CPU-reference values pass on M5 Pro, including 1024-thread X/Y/Z groups and shared-memory rendezvous across multiple workgroups. The 76633-case mesh/subgroup comparison confirms these four gains, with only the separately tracked intermittent invocation-ID result changing otherwise. All 408 cold/warm/disabled-cache checks pass. Signed-off-by: Diljit Singh <hey@djdev.me>
Serialize RT stage NIR, group metadata, and compiled ray-generation kernels without treating the custom pipeline as a common vk_rt_pipeline. Restore them for binary imports, including pipeline libraries, and generate keys for imported libraries using their actual representation. Four pipeline-binary crash cases pass on M5. The matched 16,561-case pipeline sweep has no other status changes; cache round trips and existing RT/mesh/compute smoke gates pass with the known closed-fan failures retained. Signed-off-by: Diljit Singh <hey@djdev.me>
…arate banks Hardware-qualified and installed on M5 before this commit; see M5_CTS_HANDOFF.md (R224/R235/R237/R245/R252). Signed-off-by: Diljit Singh <hey@djdev.me>
Hardware-qualified and installed on M5 before this commit; see M5_CTS_HANDOFF.md (R224/R235/R237/R245/R252). Signed-off-by: Diljit Singh <hey@djdev.me>
Hardware-qualified and installed on M5 before this commit; see M5_CTS_HANDOFF.md (R224/R235/R237/R245/R252). Signed-off-by: Diljit Singh <hey@djdev.me>
Hardware-qualified and installed on M5 before this commit; see M5_CTS_HANDOFF.md (R224/R235/R237/R245/R252). Signed-off-by: Diljit Singh <hey@djdev.me>
agx_nir_opt_preamble gained an agx3c argument on the M5 branch, and agx3b's min/max lowering now proves canonical select/phi inputs before the M5 provenance pass runs. Keep the final-flush expectations exact. Signed-off-by: Diljit Singh <hey@djdev.me>
AGX3C has no witnessed native float atomic, but agx_nir_lower_atomics already lowers fp32 add/min/max on buffers, shared memory and lowered images to compare-and-swap loops. Advertise EXT_shader_atomic_float and EXT_shader_atomic_float2 with the same fp32 feature set as G17P. Signed-off-by: Diljit Singh <hey@djdev.me>
EXT_shader_atomic_float's image features require the matching R32_SFLOAT storage-atomic format bits, as on G17P. Image atomics are lowered to the same global compare-and-swap loops on M5. Signed-off-by: Diljit Singh <hey@djdev.me>
…cquire Port of the private R278 candidate (R257 per-stage SCS/IFT state, R265 VS/FS queries, R278 colorless fragment acquire 0x270000050000 and release 0x270000040000 from the native Metal witness R277) onto agx3b 161e29e. Unqualified: a mixed compute/graphics run lost the device. Signed-off-by: Diljit Singh <hey@djdev.me>
Compute derivatives are lowered in NIR to quad swaps and implicit-LOD samples to explicit gradients; M5 supports both. Enable the quad ID shuffle and lowering for M5 and advertise KHR_compute_shader_derivatives with the same features as G17P (quad control stays off). Signed-off-by: Diljit Singh <hey@djdev.me>
OpImageQueryLod in a derivative-group compute shader reached the AGX3 packer as an implicit-LOD query, which it refuses in compute (the six compute_shader_derivatives lod_op.query cases failed pipeline creation). Extend G17P's software lowering -- quad-derivative lambda, texture size and level count, sampler min/max LOD, mip filter and API bias -- to the Gen10 descriptor layout. A Gen10 sampled descriptor carries its plane's Gen5 sampler word itself (the heap entry's packed key), so the clamp, mip-filter and signed 5:6 LOD-bias fields (bits 43..53) are read from the descriptor instead of the sampler heap. Signed-off-by: Diljit Singh <hey@djdev.me>
On the native M5 RT path an intersection shader runs inside the generated TraceRay query's candidate loop, so its ray query is a second live native query. The pipeline was refused outright because the first such CTS case once timed out the compute scheduler, before the M5 lowering gained its multiple-owner protocol: a query whose shared payload was taken by another owner now re-activates through intersect_ray and replays its processed candidate prefix (agx_nir_lower_m5_ray_query), the same path a ray query nested in an any-hit shader already uses. Drop the refusal. The lowering still enforces its live-query limit, so a shader that would need more native query slots than are witnessed keeps failing pipeline creation instead of compiling. Signed-off-by: Diljit Singh <hey@djdev.me>
The Gen10 compute textureQueryLod lowering reads min/max LOD, mip filter and the signed LOD bias straight out of the descriptor's copy of the Gen5 sampler word. Assert those bit positions against the packer for the existing pinned words (bias 0, 1.5, -2.25, max LOD 14) and the base state (min LOD 1, clamped max 15, linear mip filter, bias -1.015625). Signed-off-by: Diljit Singh <hey@djdev.me>
A static-vertex-input VS containing an M5 native ray query reserves uniform halves 0..167 for query state, and the prolog key and bound uniform ranges place vertex buffer bases at 168. The no-prolog path only applied that offset for Gen1 queries, so M5 query vertex shaders read their attributes from query slots and traced rays from garbage origins. Signed-off-by: Diljit Singh <hey@djdev.me>
M5 refused every mesh shader that writes a per-primitive user output,
gl_Layer or gl_ViewportIndex ("native mesh layout outside captured
triangle contract"), which covered ~600 EXT_mesh_shader, pipeline EDS,
library and shader-object CTS cases.
Give each primitive three private vertices instead: the API body writes
vertex words and per-primitive words to separate shared regions, then
SIMD group 0 copies, between two threadgroup barriers, the referenced
vertex words and the primitive's words to vertices 3p..3p+2 and rewrites
the index list to the identity. Per-primitive words are therefore flat
on every corner, so any provoking vertex selects them; positions,
winding, primitive order and interpolated values are unchanged. Layer
and viewport also fill the packed layer/viewport UVS word and, like the
M5 vertex stage (layer_as_varying), flat user words for fragment reads.
The fragment side reads per-primitive user/layer/viewport inputs as flat
32-bit inputs. Shaders are admitted while 3 * max_primitives <= 256 (the
native output-vertex limit); mesh-written primitive IDs and primitive
culling stay refused. The exported vertex count is reported as the mesh
max_vertices for the native output limits.
This is an emulation, not Apple's per-primitive record path (whose
storage/lifetime contract is still unproven on M5, R175); it costs at
most 3 * max_primitives exported vertices and only applies to shaders
that were refused before. Meshes without per-primitive outputs compile
byte-identically (host drm-shim: every R314 binary of all 6,056 mesh CTS
cases is reproduced).
Hardware (boot 2e8881b2, R239 kernel): a SIMD-group barrier between the
copy and the UVB stores exported stale words (api.draw_count_64 wrong
colours/missing triangles); a copy loop over all threads lost workgroup 2
of builtin.layer deterministically (cause not established); the SIMD 0
copy between threadgroup barriers passes both.
Signed-off-by: Diljit Singh <hey@djdev.me>
M5 vertex-stage draws select the provoking vertex through the VDM vertex program template; native mesh draws have no such template and always used the first vertex, so last-vertex mesh draws read flat inputs from the wrong vertex (pipeline.*.extended_dynamic_state. mesh_shader.*.provoking_vertex_first_to_last_*, mesh_shader.ext.misc. clip_*_provoking_last). For mesh draws, program the HAL300 PPP cull word's flat-shading vertex ((vertex + 1) << 7) instead, and recompute the selector when binding or unbinding a mesh shader changes the topology. Vertex-stage draws keep 0 in the PPP word. On hardware the PPP selector makes the EDS last-vertex mesh draws pass; putting the selector in the VDM mesh-state word 1 (bits 0..1, the vertex-outputs word-1 analogue) had no effect. Signed-off-by: Diljit Singh <hey@djdev.me>
Lower M5 native ray queries in tessellation-evaluation shaders. The hardware evaluation variant becomes a vertex program in poly_nir_lower_tes() after the per-stage query scan, so flag it from the API stage, giving it the vertex query state (uniform halves 0..167, SCS/IFT render program). An evaluation variant run as a kernel before a geometry shader uses the compute query ABI; admit its internal dispatch like the control and geometry kernels. Also stop the M5 indexed-read vertex shift from moving query helper loads: with a native query the vertex ABI starts at half 168 and only loads above it belong to the vertex ABI. Hardware (R320a on the 329 previously refused evaluation cases): 274 Pass, 54 Fail with wrong results, 1 DeviceLost during a recovery shared with concurrent geometry runs. Host: agx_tests 428/428, agx_scs_query adds the evaluation stage. Signed-off-by: Diljit Singh <hey@djdev.me>
…eries opt-in poly_nir_lower_gs clones the (already lowered) geometry shader into the main and count kernels and the raster vertex program. The main kernel has the API stores stripped, so a native query whose results only fed them was dead work that still ran on CDM ahead of the raster draw. agx_nir_m5_remove_dead_ray_queries marks every value data- or control-dependent on a native query operation (SCS loads/stores, enter/intersect/continue) and removes the query only when no remaining side effect depends on it; otherwise only trivial phis are folded. Host compile of 308 geometry ray-query CTS pipelines: no main or count kernel keeps a query (e.g. builtin.flow.geom main 4994 -> 120 bytes); the raster vertex program keeps it. Geometry ray queries nevertheless stay refused by default: hardware runs of GS query draws (before this removal) requested GPU recovery twice and the cause is not isolated. ASAHI_M5_GS_RAY_QUERY_DIAGNOSTIC=1 enables them for diagnosis; ASAHI_M5_RQ_DEAD_DIAG=1 reports a query kept live. Host: agx_tests 428/428; agx_scs_query adds the geometry stage and a dead/live removal regression. Signed-off-by: Diljit Singh <hey@djdev.me>
Uniform source lowering copies a uniform into a GPR for every M5 operation that cannot read it in place, after the last CSE pass, and constant materialization likewise emits one move per use. A uniform condition selecting among many values is then copied once per select: one uniform boolean of Counter-Strike 2's largest fragment shader is copied 60 times. AGX3B merges such repeats only while the earlier copy is still live, which never happens for a copy read right after it is made. Add a CSE mode that may also extend the earlier result's range, as long as the register pressure at every instruction it newly spans stays within the peak the shader already has, and run it on M5 main programs that had no CSE at this point. The pressure is counted in the halves RA's demand charges, per instruction from the block's liveness. On top of the previous changes this removes 68 and 120 instructions from Counter-Strike 2's two largest fragment shaders, mostly uniform copies and constant moves, and 16 from its main-pass shader, and 1675 from the fragment shaders of its 205-pipeline corpus: 116 shaders improve, none regresses, six use fewer registers, and no spill or occupancy changes. The bounded CSE mode and its host test already exist for G17P, which runs it on its AGX3B main programs. This change runs the same mode on M5 main programs that had no CSE at this point. Signed-off-by: Diljit Singh <hey@djdev.me>
M5 texture coordinates, sin/cos operands and the other bank-constrained values must live in halves 0..127, the reach of their seven-bit fields. RA assigns every value the lowest free registers, so at the limit of the register file the low bank is full of unconstrained values, and each constrained definition evicts one of them with a live range split. The moved values then sit in different registers on the two sides of the next merge, which costs a copy per value at the join. Once a shader spills, every register up to the bound is in use somewhere, and where a value goes no longer changes the register count. There, place unconstrained values above the low bank first, within the registers already in use, unless they feed a collect that has to sit in the low bank. On top of the previous changes this removes 253 and 245 instructions from Counter-Strike 2's two largest fragment shaders, whose 32-bit register moves drop from 1177 to 920 and from 1189 to 935, and 24 from the only other spilling shader of its 205-pipeline corpus. No other shader changes, and no register count, spill or occupancy changes. The placement already exists for G17P, where it also skips values with a G17P bank constraint. This change applies it on M5 as well. Signed-off-by: Diljit Singh <hey@djdev.me>
A draw that changes any part of the HAL300 graphics core re-emitted all nine of its PPP records. The PPP keeps each record until the next one of its kind, and every record it processes stalls tiling for about 50 ns, so a front-face, blend-constant or pipeline change cost close to half a microsecond of tiling time per draw. Keep the packed core the stream latched and emit only the records whose bytes differ. On a 1000-draw pass at 3024x1964 4x MSAA, toggling the front face per draw drops from 567 to 133 us of tiling time and a per-draw blend constant from 582 to 162 us; a pass with no state changes stays at 119 us. Signed-off-by: Diljit Singh <hey@djdev.me>
Each render record now notes, as st=r:v:n:p, how many draws republished render state, how many vertex-program state updates were emitted and how many of those named a program other than the stream's previous one, and how many PPP state records were emitted. Signed-off-by: Diljit Singh <hey@djdev.me>
…mats D3D translation layers create typeless render targets that shaders also write as storage images: mutable images of RGBA16, RG16 or RGBA8 that list the UNORM, SNORM, UINT, SINT and FLOAT views of one channel layout. The M5 storage compression admitted mutable images only for RGBA8 UNORM and otherwise only the float formats, so these stayed uncompressed. SCP: Secret Laboratory's HDRP reads and writes several full-screen RGBA16 targets of this kind about fourteen times a frame. None of the 8- and 16-bit-channel formats has image atomics, and the format list check keeps every view to the image's channel layout, so admit the integer and normalized RGBA16, RG16 and RGBA8 formats and mutable images whose only extension is that list. Signed-off-by: Diljit Singh <hey@djdev.me>
D3D translation layers load every render target they were not told to clear or discard, so the full-screen post-processing passes of a D3D game read each target into the tilebuffer only to overwrite it. SCP: Secret Laboratory's HDRP runs about fourteen such single-triangle passes over full-resolution RGBA16 targets a frame. Prove the overwrite instead of guessing it. At compile time, a vertex shader whose positions for vertices 0, 1 and 2 fold to constants once the vertex index is known (instance, base vertex and draw index 0), and form a triangle containing the whole clip-space square inside the depth range, is marked as covering; a shader writing clip or cull distances never is. A fragment shader that discards, demotes, terminates or writes the sample mask is marked as able to leave pixels unwritten. When the first command of a render pass's only control stream is a direct, non-indexed, single-instance draw of vertices 0..2 by such a vertex shader, under one viewport and scissor covering the render area, with culling, depth, stencil and depth-bounds tests, alpha to coverage, logic ops and partial sample masks all unable to drop a sample, every colour attachment the fragment shader writes without blending and with its whole write mask is overwritten before anything reads it. At the end of the pass the main background program clears those attachments instead of loading them; stores and the partial render's reload are unchanged. A check program (LOAD over a buffer-copied red image, one triangle of green) gives all green for the full-screen triangle with the load skipped, and keeps the red where it must: half-screen triangle, blending, and a discarding fragment shader all keep the load. The shader facts, the first-draw proof and the background program rebuild already exist for G17P, including the later requirement that the attachment's colour write is enabled. This change takes them on M5 as well and records the covered attachments in the frame anatomy. Signed-off-by: Diljit Singh <hey@djdev.me>
The compression decision of a mutable image depends on the view formats it lists, so print them next to it. D3D translation layers give their 32-bit typeless targets R32 views besides the RGBA8 or RG16 ones, which keeps those uncompressed. Signed-off-by: Diljit Singh <hey@djdev.me>
With soft faults, an out-of-range read returns without faulting, so a bounded load can read unconditionally and select zero for an access outside the descriptor, as constant-buffer loads already do. Storage buffers instead redirected every load through the zero page: a saturating end offset, a compare and selects of both base halves and of the offset, all before the load could issue. Now the load issues at once, and a saturating end offset and one compare-and-select follow it. SCP: Secret Laboratory's pipelines (Fossilize replay, robustness enabled as DXVK enables it): 6.81M -> 6.08M instructions (-10.8%), spills and fills -4.5%. Comparing against a per-descriptor limit instead saves more instructions (-14.8%) but raises spills by 60%, and runs slower in game at 3024x1964 (panned): 53.1 and 51.6 FPS against 53.7 and 55.9 here. The storage-buffer result select already exists for G17P. This change selects it on M5 as well. Signed-off-by: Diljit Singh <hey@djdev.me>
D3D11 translation layers also create single-channel 16-bit typeless storage targets, and Unity's HDRP keeps its colour pyramid in a 12-level RGBA16 storage image: a 2x downsample and a shared-memory blur per level, each reading the level above it, plus a full-screen pass rendering level 0. All of it ran uncompressed because storage compression admitted only single-level images. A mipmapped storage image compresses its levels exactly as a colour attachment's do; each level's descriptor carries its own compression state. SCP: Secret Laboratory at 3024x1964 (panned, palindromic): 51.3 and 55.6 FPS against 50.0 and 53.3. Signed-off-by: Diljit Singh <hey@djdev.me>
fmin and fmax are compare-and-select on AGX, so a denormal operand passes through unflushed, and agx_nir_lower_fminmax adds an fadd of -0.0 after every min/max whose operands might be denormal. Vulkan only requires that flush when the shader declares DenormFlushToZero for 32-bit floats. Without a denormal execution mode, any denormal an instruction produces may or may not be flushed, and the driver does not offer DenormPreserve for fp32. Skip the canonicalization unless the shader declares flush-to-zero; the existing tests now declare it. Counter-Strike 2's depth pyramid kernel drops from 984 to 920 instructions and its MSAA resolve from 213 to 201. SCP: Secret Laboratory's pipeline cache (fossilize replay, robustness enabled): Instructions 6834940 -> 6825892 (-0.13%), helped 920, hurt 9 Spills 39515 -> 39525 (+0.03%) Fills 39496 -> 39498 (+0.01%) The flush-to-zero-only mode and its host test already exist for G17P, with other chips keeping the flush after every min/max. This change selects that mode on M5 as well. Signed-off-by: Diljit Singh <hey@djdev.me>
AGX3 threadgroup loads and stores index scalar elements, so the shared lowering turns each NIR byte offset into an element index. It did that with a right shift per access, because the exact division it already has for the backstop pass did not run here and did not understand the address multiply (amul) or multiply-add (imadshl_agx) that offsets are built from. A depth pyramid that addresses tile[y * 18 + x] then pays an add and a shift before every one of its 47 accesses. Divide the byte arithmetic itself where that is exact in the 16-bit index, including amul and imadshl_agx/imsubshl_agx, and fall back to the shift otherwise. The constant addends that remain inside the element sum move to the LDTG/STTG byte offset when range analysis proves neither the remaining sum nor the 16-bit narrowing can wrap; the variable terms are summed in a fixed order so accesses that differ only in the constant share an index. Counter-Strike 2's depth pyramid kernels drop from 920 to 843, 174 to 150 and 139 to 122 instructions (shifts 44 -> 6). SCP: Secret Laboratory's pipeline cache (fossilize replay, robustness enabled): Instructions 6825892 -> 6823515 (-0.03%), helped 32, hurt 0 Compute 374417 -> 372040 (-0.63%) GPRs, spills and fills unchanged. Signed-off-by: Diljit Singh <hey@djdev.me>
An M5 texel fetch stages its coordinates into the sampler operand file with one COPY per component, and a multisampled read publishes its sample index with PACK_SMPIR, so the read never needs its coordinates as a contiguous GPR vector. Collecting one anyway costs a GPR move for every component that lives elsewhere: Counter-Strike 2's depth pyramid reads four samples at each of sixteen texels and moved three words before each of its 64 reads. Before register allocation, give a 2D or 2D multisampled TEXTURE_LOAD whose coordinates are a collect of scalars those scalars directly (src[0] x, src[6] y, src[7] sample index, flag agx3_split_coords). The packer stages x and y with the wide scalar COPY that scalar publications already use, so they may live anywhere in the register file; the sample index keeps PACK_SMPIR's seven-bit source. The collect remains as an RA affinity hint, so allocation keeps the vector's placement where the components fit together. Split coordinates in the registers a vector would occupy stage byte for byte like the vector. Counter-Strike 2: the depth pyramid kernel drops from 843 to 654 instructions, its post-process fragment shader from 618 to 559 and the MSAA resolve from 200 to 188; 421 fewer instructions over 28 of the 1475 binaries of its 205 hot pipelines. SCP: Secret Laboratory's pipeline cache (fossilize replay, robustness enabled): Instructions 6823515 -> 6819343 (-0.06%), helped 2019, hurt 150 GPRs 552655 -> 552615 (-0.01%), helped 8, hurt 1 Spills 39525 -> 39252 (-0.69%) Fills 39498 -> 39173 (-0.82%) Signed-off-by: Diljit Singh <hey@djdev.me>
Each render record now carries pt=o:t:p:tp:nm:zw:lz, the draws by the fragment pass type latched in the M5 PPP state (opaque, translucent, punch-through, translucent punch-through), and how many of them had triangle merging disabled, depth writes, or a depth mode other than UNCHANGED. A pass whose render area does not cover its framebuffer prints it as area=WxH+X+Y. Profiler-only; nothing changes unless HK_FRAME_ANATOMY is set. Signed-off-by: Diljit Singh <hey@djdev.me>
An M5 filtered 2D sample stages x and y with one COPY each into its sampler operand bank, like a texel fetch; its level, bias, gradient, offset and comparison operands stage on their own. Collecting the coordinates into a contiguous vector first costs a GPR move for every component that lives elsewhere, and the vector must sit below half 128 for the seven-bit COPY source. A percentage-closer shadow filter pairs each x with several y values, so it moved coordinates before nearly every tap. Give a 2D TEXTURE_SAMPLE whose coordinates are a collect of scalars those scalars directly (src[0] x, src[6] y, agx3_split_coords), as texel fetches already are, and stage them with the wide scalar COPY, which reads the whole register file. A component that is also another operand of the sample keeps the vector, so no other staging read can discard a coordinate register around its COPY; the packer refuses that shape. When x and y share a register, only the second COPY discards it. Unlike fetches, samples take no RA affinity hint from the removed collect: taps combine coordinates in other pairs, and on the pipeline caches below the hint cost 0.1% instructions and 1% GPRs. Counter-Strike 2's 205 hot pipelines (1475 binaries, host compile) drop from 718384 to 707058 instructions; 242 binaries change, one gains an instruction. Its largest fragment shaders lose 56 to 84 instructions each (78842: 4302 -> 4246), and pipeline 78891 drops from 208 to 195 spills. Pipeline caches (fossilize replay, robustness enabled): SCP: Secret Laboratory Instructions 6819343 -> 6757493 (-0.91%), helped 1816, hurt 166 GPRs 552615 -> 549431 (-0.58%), helped 503, hurt 108 Spills 39252 -> 35591 (-9.33%), helped 299, hurt 0 Fills 39173 -> 38863 (-0.79%), helped 188, hurt 0 Counter-Strike 2 Instructions 6516946 -> 6470447 (-0.71%), helped 7220, hurt 335 GPRs 1255931 -> 1242669 (-1.06%), helped 1758, hurt 106 Spills and fills unchanged. Signed-off-by: DjDeveloperr <hey@djdev.me>
An M5 fragment 3D sample publishes its coordinates with a scalar publication that stages x, y and z through the wide scalar COPY, which reads the whole register file. The lowering still copied each coordinate into a fresh register first, for the seven-bit form whose operands must sit in the low source bank: three moves per publication that the wide form does not need. Publish the coordinates from their own registers when the wide form is in use (ASAHI_M5_WIDE_SCALAR_SOURCES, on by default), and keep the copies for the seven-bit form. Coordinates may now share a register, which the publication's discard handling already covers, and may live above half 192, which the word identity that carries the publication's wait cannot name. Carry that wait with agx3_retire_wait_on(), as fetch coordinates do: the same word identity below half 192 and the halfword identity above it, where the packer refused the shader before. Two binaries of Counter-Strike 2's pipeline 78891 need it. Counter-Strike 2's 205 hot pipelines (1475 binaries, host compile) drop from 707058 to 706234 instructions over 89 binaries: 826 moves fewer, two halfword wait carriers more. Pipeline caches (fossilize replay, robustness enabled): SCP: Secret Laboratory Instructions 6757493 -> 6695827 (-0.91%), helped 1752, hurt 0 GPRs, spills and fills unchanged. Counter-Strike 2 Instructions 6470447 -> 6466149 (-0.07%), helped 811, hurt 0 GPRs, spills and fills unchanged. Signed-off-by: DjDeveloperr <hey@djdev.me>
An M5 2D-array texel fetch stages x and y with one COPY each and packs its layer with PACK_SMPIR, beside a register level when it has one, so like 2D and multisampled fetches it never needs its coordinates as a contiguous vector. Split its coordinate collect as well: src[7] carries the layer, which keeps PACK_SMPIR's seven-bit source, and x and y stage through the wide scalar COPY. The layer is packed before the x/y COPYs, so it discards its register only when neither coordinate reads it. SCP: Secret Laboratory's pipeline cache (fossilize replay, robustness enabled): Instructions 6695827 -> 6685057 (-0.16%), helped 1443, hurt 53 GPRs 549431 -> 549533 (+0.02%), helped 9, hurt 17 Spills 35591 -> 35591, unchanged Fills 38863 -> 38861 (-0.01%), helped 2, hurt 0 Threads unchanged. Counter-Strike 2's cache loses 3 instructions; its 205 hot pipelines do not change. Signed-off-by: DjDeveloperr <hey@djdev.me>
An M5 uniform export is one 32-bit copy per word, so a 64-bit constant-program result costs two copies however it is stored. Most 64-bit fragment exports are texture and sampler handles built as pack_64_2x32_split(word, 0). Storing the packed value made the backend collect both words into an aligned register pair first, a move for the word and one for the zero, ahead of the two copies. Export the two words of such a pack directly from their own registers, into the same uniform halves at the same program point. The uniform file ends up with the same contents; only the register moves go. Shader-db, host replay through the M5 shim, machine instructions in the constant programs (disassembled): CS2 fragment 1557055 -> 1438823 (-7.6%), mean 100.4 -> 92.8 SCP:SL fragment 1186444 -> 1142219 (-3.7%), mean 334.1 -> 321.2 CS2 compute 423643 -> 415085 (-2.0%) Main programs, GPRs, spills and uniform counts are unchanged.
A constant-program result narrower than a word is exported with a 32-bit copy, so a lone 16-bit result is widened to a word first. The widening cleared the neighbouring half, which costs a move of zero per export, and tying the result to a fixed word with a cleared neighbour also forced a move of the result in many programs. The neighbour is proven unoccupied: no constant-program access, no reserved or input uniform and no promoted constant uses it, and the preamble layout gives each lone half a word of its own. Nothing reads it, so leave it undefined. Every live half keeps its value and address. Shader-db, host replay through the M5 shim, machine instructions in the fragment constant programs (disassembled), on top of the previous change: CS2 1438823 -> 1380640 (-4.0%), mean 92.8 -> 88.9 SCP:SL 1142219 -> 1107437 (-3.0%), mean 321.2 -> 311.8 No executable gets a longer constant program; main programs, GPRs, spills and uniform counts are unchanged.
A robust read at a constant offset keeps its value only when its end lies within the descriptor's byte size, one compare-select taking the end as an 8-bit immediate. Every check ending past 255 bytes first loads its end with a constant move. The large constant buffers of D3D titles (a 2 KiB G-buffer constant buffer) pay that move for most of their reads, in a constant program that reruns for every tile its draw touches. For a word-aligned end, end <= size exactly when end/4 <= size/4 rounded down, and subtracting a common base from both sides of a signed comparison stays exact (size/4 < 2^30, end/4 < 2^14). Check a descriptor's reads against size/4, less a base per 256-word window, so each end is an 8-bit immediate again: one shift per descriptor and one subtraction per further window replace a constant move per check. Each check keeps its own exact predicate, so no value is read, kept or zeroed differently. Rewrite a descriptor only when that is cheaper, and only in the constant program: in main programs the extra live word sizes would compete for registers. Programs with uniform DMA launches keep the byte form they match. Shader-db, host replay through the M5 shim, machine instructions in the fragment constant programs (disassembled), on top of the previous change: SCP:SL 1107437 -> 1011818 (-8.6%), mean 311.8 -> 284.8 CS2 1380640 -> 1364962 (-1.1%), mean 88.9 -> 88.0 Main programs, GPRs, spills and uniform counts are unchanged.
When a render pass instance clears an attachment with its load op but
the clear cannot be the background program's (an incomplete render
area, a spilled colour target), BeginRendering draws the clear over the
render area. Every tile that clear has to reach then holds a draw, but
the stored clear still set process_empty_tiles, so the hardware loaded
and stored back every tile of the framebuffer outside the render area
as well, unchanged.
Counter-Strike 2 clears small HUD rectangles (around 300x300) of
3024x1964 RGBA8 targets like that four or five times per frame. Each
of those passes took 49-57 us of fragment time; with only the render
area processed they take 5 us, 204 -> 20 us of fragment time per frame
(frame anatomy, ts=all). Counter-Strike 2 High, 3024x1964, 4x MSAA
(palindromic A/B, render depth 32 kernel): 71.60/71.76 -> 72.64/72.29 FPS.
SCP: Secret Laboratory gameplay at 3024x1964 (panned camera,
palindromic A/B): 51.8/52.1 -> 53.5/55.3 FPS.
On M5, keep process_empty_tiles only for a resolve of loaded samples
when the clear is drawn.
dEQP-VK renderpasses, api.image_clearing, pipeline.monolithic.{multisample,
stencil,depth,depth_range_unrestricted,render_to_image}, draw.renderpass,
draw.dynamic_rendering and texture.mipmap (235,635 cases): no failures.
Signed-off-by: Diljit Singh <hey@djdev.me>
A compute stream that already holds dispatches takes on the requirement of every later dispatch recorded into it. When a barrier between two dispatches names a render the stream does not wait for yet, the earlier dispatches, which are outside that barrier's second scope, end up waiting for the render as well. Counter-Strike 2 records its occlusion culling dispatch right after a 4x MSAA render with no barrier in between, and barriers whose first scope covers all graphics stages between the following dispatches; the whole culling stream then waits for that render's fragment work before it starts. On M5, end the stream instead when the requirement of the work entering it names a render the stream does not already wait for, directly or through the compute prefix it waits on. The new work goes into a stream created under the whole requirement, and a first scope that covers compute work names the ended stream, so the dispatches stay ordered as recorded. For the same reason, adjacent compute streams are no longer merged at the end of the command buffer when the later one waits for a render the earlier one does not. No dependency is dropped: every command still waits for everything the barriers before it name; only the extension of a later barrier to dispatches recorded before it is gone. Counter-Strike 2's first culling dispatch after a render that only writes attachments now overlaps that render's fragment work. CS2 High, 3024x1964, 4x MSAA: 73.15 -> 73.99 FPS. dEQP-VK synchronization, synchronization2, memory.pipeline_barrier, compute.pipeline, indirect draws, conditional_rendering, query_pool, timestamps, api command buffer and copy, image.load_store (32,507 cases): no failures. Signed-off-by: Diljit Singh <hey@djdev.me>
An empty render pass that only clears its attachments is replaced by image clears, which on M5 are compute jobs. A later render's vertex half has to wait for compute work, but not for a render that writes only its attachments, so a compute clear between two renders keeps the next render from tiling until the clear finishes. Counter-Strike 2 records several clear-only passes of its 4x depth, stencil and colour targets per frame, right before its depth prepass. On M5, keep a multisample clear-only pass as a render: its background program clears and its end-of-tile program stores the attachments, as for the other clear-only renders this path already keeps. CS2 High, 3024x1964, 4x MSAA: 73.30/73.42 -> 74.26/74.00 FPS. dEQP-VK api.image_clearing, renderpasses and pipeline.monolithic.multisample (135,360 cases): no failures. Signed-off-by: Diljit Singh <hey@djdev.me>
The reads of one structure in a loop (a light record, a constant buffer row) differ only by a constant field offset, and each robust read computed its own end, uadd_sat(iadd(X, c), n), before its compare-select. For the reads of one block with the same X and size, compute R = usub_sat(size, X + c_min) once and check each read's immediate c - c_min + n against R. The predicate is exact, except that a read whose 32-bit offset wraps is now zeroed, as its real offset lies past the end. SCP: Secret Laboratory compute shaders (DXVK, 80 shaders): 164,407 -> 150,364 instructions (-8.5%), none worse; the heaviest deferred lighting variant 6661 -> 5996. dEQP-VK robustness, ubo, ssbo, spirv_assembly, compute, glsl and binding_model (418,194 cases): no failures. Gameplay FPS unchanged (56.6/56.0 vs 56.7/56.1). Signed-off-by: Diljit Singh <hey@djdev.me>
A structure read field by field (a light record in a loop) issues one 32-bit load per field. NIR's vectorizer merges such loads only where it can prove the 32-bit offset X + c does not wrap before the zero extension to the 64-bit address, which fails for every field past the first 16 bytes of a record with a non-power-of-two stride (240 bytes here). Each field then pays its own load and index computation. Before the global loads are lowered, group the 32-bit reads of one block by base, descriptor size and offset term, and merge up to four consecutive words into one vector load. The words differ from their separate reads only where X + c wraps 2^32, which lies past the end of any buffer: undefined without robustness, and zeroed for robust reads, which keep each word's own bounds check against the soft-fault load. SCP: Secret Laboratory's Unity Vulkan compute shaders (85, robustness off as the game runs them): 110,679 -> 106,128 instructions (-4.1%); the heaviest in-game deferred lighting variant 4328 -> 4094. Its DXVK pipelines (10,903 executables, robustness on): -3.9% instructions (fragment -4.2%), fills +2.3%. Counter-Strike 2 (30,026 executables): -0.34%, spills unchanged. Gameplay FPS unchanged (63.3 vs 62.9). dEQP-VK robustness, ubo, ssbo, spirv_assembly, compute, glsl and binding_model (418,194 cases): no failures, statuses identical. Signed-off-by: Diljit Singh <hey@djdev.me>
M5 compresses storage images of the formats without image atomics, which may also be colour attachments, sampled and transfer images: every write goes through compressed PBE descriptors. An input attachment reads the image as a sampled colour attachment does, and M5 colour attachments already compress with that usage, but the storage policy did not admit it. Engines that create their render targets with every usage they may need (Unity: TRANSFER | SAMPLED | STORAGE | COLOR | INPUT_ATTACHMENT) therefore kept their full-screen RGBA16F, RG16 and RGBA8 targets uncompressed: each clear wrote the whole image (236 us per 3024x1964 RGBA16F clear, against 26 us for a fast clear) and every pass read and wrote them at full bandwidth. SCP: Secret Laboratory (Unity Vulkan, 3024x1964): 63.3 -> 73.3 FPS (previous legs 62.6, 63.4, 62.9; a frame-anatomy leg 76.0), its 3024x1964 RGBA16F, RG16 and RGBA8 targets now compressed. dEQP-VK image, image_clearing, renderpasses, input attachment, local read and storage-image descriptor cases (275,898): no failures, statuses identical to the parent. Signed-off-by: Diljit Singh <hey@djdev.me>
RyanTheTide
left a comment
There was a problem hiding this comment.
I rechecked bd4290a. The port documents its kernel contract and distinguishes the rebased host results from the older M5 GPU measurements. Keeping existing-chip predicates explicit also helps review the shared paths.
The UAPI collision is still present at include/drm-uapi/asahi_drm.h:315. RENDER_RESOURCES uses bit 17, while Linux #423 and its Mesa #62 companion use that bit for cumulative signals. Userspace can interpret the same advertised capability as two different contracts. Please allocate distinct bits in one shared mapping and update the matching kernel and both Mesa lines together, including capability/fallback tests.
After that, build this exact rebased head with warnings as errors and rerun its host suites against the matching M5 kernel backend. The quoted older-tree M5 CTS and performance numbers do not qualify this port. We still need exact-head M5 CTS and sustained runs, plus G13/G14/G17P regression coverage of the shared compiler and Honeykrisp changes before merging.
Adds Honeykrisp and compiler support for the M5 family (G17G/G17S, AGX3C/HAL300) on top of
aurora-wip. This is the full M5 userspace line, rebased onto currentaurora-wipas 232 commits.What the series adds
drm-uapi/asahi: the M5 extensions in the merged numbering (one commit, mapping below).HK_FRAME_ANATOMY).aurora-wipalready has a G17P port of an M5 commit, that commit only widens the existing gate to M5, and its message says so. This covers about 20 commits, including deferred clears, continuation, ZLS, shared compression, image barriers, divmod64, phi/spill/CSE/low-bank RA, fminmax and the stencil plane.<aurora-wip predicate> || agx_chip_g17_m5(), so G13–G15 and G17P keepaurora-wipbehaviour.hk: keep M5 off the classic AGX2 barrier and capability pathskeeps M5 out of the AGX2-restoration gates (!agx_native_graphics). Without it, M5 would take the classic pipeline-barrier boundary, the classic end-of-pass graphics dependency and the classic API sample mask, and would loseKHR_unified_image_layouts,EXT_conditional_rendering,EXT_memory_budgetandKHR_shader_fma.Validation
libvulkan_asahi.so, the compiler, the libraries, drm-shim and all tests build.meson test --suite asahi: 70/70.Kernel UAPI dependency
M5 needs a kernel that implements the merged asahi UAPI with the M5 extensions:
DRM_ASAHI_SET_RENDER_RESOURCES/_COMPUTE_RESOURCES/_RENDER_RESOURCES_V2= 5/6/7;DRM_ASAHI_BIND_SPARSE_TILE(bit 4);SHADER_WRITES(21) andCOMPUTE_STAGE_BARRIERS(22);drm_asahi_cmd_render_with_stage_prior(352 bytes).Other chips do not use them.
UAPI mapping (old M5 line → this series)
Supersedes #26.
🤖 Generated with Claude Code