The argument encoders and the host-numbered samplers had unit tests on each side, but nothing ran an argument buffer through a guest's kernel. argbuf_probe writes two argument buffers through a function's encoder, each a texture, a sampler, a buffer at an offset, a constant and a nested argument buffer, reads them in a kernel, and checks the encoders' lengths and alignments and the eight values against Metal's on the M3 Max (macOS 27), within 1/64. The guest on the RTX 5080 answers the same lengths and the same values, bit for bit.
30 lines
973 B
Metal
30 lines
973 B
Metal
// argbuf_probe's kernel (argbuf_probe.m): two argument buffers of the same layout, each a texture,
|
|
// a sampler, a buffer, a constant and a nested argument buffer of a texture and a sampler.
|
|
#include <metal_stdlib>
|
|
using namespace metal;
|
|
|
|
struct Inner {
|
|
texture2d<float> t [[id(0)]];
|
|
sampler s [[id(1)]];
|
|
};
|
|
|
|
struct Args {
|
|
texture2d<float> tex [[id(0)]];
|
|
sampler smp [[id(1)]];
|
|
device const float4 *data [[id(2)]];
|
|
float4 k [[id(3)]];
|
|
constant Inner *inner [[id(4)]];
|
|
};
|
|
|
|
kernel void argbuf_probe(constant Args *args [[buffer(0)]], device float4 *out [[buffer(1)]],
|
|
uint i [[thread_position_in_grid]])
|
|
{
|
|
constant Args &a = args[i / 4];
|
|
switch (i % 4) {
|
|
case 0: out[i] = a.tex.sample(a.smp, float2(0.6, 0.25), level(0)); break;
|
|
case 1: out[i] = a.tex.sample(a.smp, float2(1.25, 0.25), level(0)); break;
|
|
case 2: out[i] = a.data[1] + a.k; break;
|
|
default: out[i] = a.inner->t.sample(a.inner->s, float2(0.25, 0.75), level(0)); break;
|
|
}
|
|
}
|