fixtures: ab_tier2, our MSL for argument buffers tier 2's GPU-written, Private and pointer-indexed argument buffers

Three kernels for the runtime's device test of what tier 2 adds beside writable textures
(a8r_buffers' a8r_held holds those): ab_copy copies a texture member device to device, ab_read
reads texel (0, 0) through an argument buffer's member, and ab_indexed reads through element g
of an array of argument buffers that a pointer member reaches. The companions follow from
scripts/regen-air-fixtures on the M3.
This commit is contained in:
Anees Iqbal committed 2026-11-19 06:34:26 -08:00
1 parent c1bd06c085
commit 0dc0ccfa95
1 file changed
+33
@@ -0,0 +1,33 @@
// Owned fixture: what Metal's argument buffers tier 2 adds over tier 1 beside writable textures
// (a8r_buffers' a8r_held holds those), one kernel a piece, for the runtime's device test
// tests/argument_tier.rs:
// - ab_copy: the GPU writes an argument buffer, copying a texture member from one argument buffer
// to another, device to device, as tier 2's mutable argument buffers allow;
// - ab_read: reads texel (0, 0) through an argument buffer's texture member, whether the CPU wrote
// the buffer, the GPU wrote it (ab_copy) or it is a Private buffer a blit filled;
// - ab_indexed: thread g reads texel (0, 0) of the texture member of element g of an array of
// argument buffers that a pointer member of the bound one reaches (pointer indexing, and an
// argument buffer that points at others).
#include <metal_stdlib>
using namespace metal;
struct Held {
texture2d<float> t [[id(0)]];
};
kernel void ab_copy(device const Held *from [[buffer(0)]], device Held *to [[buffer(1)]]) {
to->t = from->t;
}
kernel void ab_read(device const Held &held [[buffer(0)]], device float4 *out [[buffer(1)]]) {
out[0] = held.t.read(uint2(0));
}
struct Table {
device const Held *held [[id(0)]];
};
kernel void ab_indexed(device const Table &table [[buffer(0)]], device float4 *out [[buffer(1)]],
uint g [[thread_position_in_grid]]) {
out[g] = table.held[g].t.read(uint2(0));
}