Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
2261a38
File pages under a buffer joining the residency set are wired by mloc…
seedds Nov 9, 2026
bfa1214
Where Metal's working set is under 8 GB, textures in GPU-only memory …
seedds Nov 9, 2026
3db7eb5
The power line names the threads that make clock waits, with their pr…
seedds Nov 9, 2026
aa82d4c
Ocarina of Time's note: the M1 iPad holds 20 fps at the Great Deku Tr…
seedds Nov 9, 2026
e0209b5
The present takes the shape of the game's crop: a crop whose width / …
seedds Nov 9, 2026
cf623ee
screen_aspect any: a profile's stubs follow any window or screen shap…
seedds Nov 9, 2026
021300a
Probe diagnostics for values the game caches: float arguments, a scan…
seedds Nov 9, 2026
d97bed7
Ocarina of Time fills any window or screen shape, live while playing:…
seedds Nov 9, 2026
a8fe89b
Ocarina of Time's HUD takes the output's shape at its own pixel size …
seedds Nov 9, 2026
2f2c543
Docs for any screen shape: Ocarina of Time's Screen shape section, th…
seedds Nov 9, 2026
6f4c427
file_wire keeps its list when growing it fails: the range it cannot r…
seedds Nov 9, 2026
1c92e40
A shader-code pool's own address keeps it out of the raw pool table: …
seedds Nov 9, 2026
66867a7
OoT3 2b: the frame step calls the GPU slowed only against a reference…
seedds Nov 6, 2026
fb9f13b
OoT5 A-4: a movie the player reads one picture per game frame follows…
seedds Nov 7, 2026
c855a8c
The frame step's GPU reference also matches compute dispatches, so Oc…
seedds Nov 9, 2026
d845268
Docs: Ocarina of Time plays on an iPhone 17 (27-30 fps in Kokiri Fore…
seedds Nov 9, 2026
0e303a6
iOS: a Rotation setting (Automatic, Landscape, Portrait) on the setti…
seedds Nov 9, 2026
e5bc342
iOS: upright, a game that renders any shape fills the space above the…
seedds Nov 9, 2026
7bfa426
screen_aspect any: upright, the vertical angle is held to a square pi…
seedds Nov 9, 2026
c4aae7a
iOS: Portrait layout, Full screen by default: upright, a game that re…
seedds Nov 10, 2026
e0f33bd
screen_aspect any: the shape line no longer adds "screen shape 16:9" …
seedds Nov 10, 2026
2e35fa7
Docs: portrait play on the iPhone (Rotation, Portrait layout, the upr…
seedds Nov 10, 2026
adb6431
OoT-iPhone A-2: a submission's end hands its records to the encode th…
seedds Nov 9, 2026
e73aaac
Frame step: late frames with the GPU idle do not step up, and a longe…
uncraftablexd Nov 9, 2026
1a273e8
OoT-iPhone B-2: frames late at a 30 fps cap's hold 2 are shown at the…
seedds Nov 9, 2026
99a52c8
OoT-iPhone B-3: the frame step's log lines name the cap, the longest …
seedds Nov 9, 2026
4850da5
OoT-iPhone B-2: the 60 Hz link that shows a 30 fps cap's late frames …
seedds Nov 9, 2026
3a625e5
OoT-iPhone B-1: why a 30 fps cap's late frames left a 66.7 ms gap abo…
seedds Nov 9, 2026
47412a7
OoT-iPhone B-3: the game-time line counts the switches to the next vs…
seedds Nov 9, 2026
2fa00c2
OoT-iPhone A (merge): the 20 graphics tests that build nvn_mtl.m and …
seedds Nov 10, 2026
1d91b35
OoT-iPhone B-1: the iPhone's numbers with late frames at the next vsy…
seedds Nov 10, 2026
d17df17
OoT-iPhone A-2 docs: the iPhone 17 frame's profile, the fix's A/B, an…
seedds Nov 10, 2026
f0e390e
DM_NVN_GPUPROF_GEOM=1 stamps each render pass where its vertex and me…
seedds Nov 8, 2026
0ca0186
OoT-iPhone A-1: DM_NVN_GPUPROF logs the host's CPU timeline beside a …
seedds Nov 9, 2026
e66db18
OoT-iPhone A-1 docs: the game note's iPhone 17 table names DM_NVN_GPU…
seedds Nov 10, 2026
3a181b6
test_env_switches passes again: DM_NVN_SUB_DRAIN has its row, and thr…
seedds Nov 10, 2026
1eac389
OoT-iPhone: test_oot_aspect's camera and shape helpers take a float c…
seedds Nov 10, 2026
8a8fb0b
OoT-iPhone: the Python lint baseline drops test_gpuprof.py's unused o…
seedds Nov 10, 2026
ed769e9
OoT-iPhone B-4: Ocarina of Time's smoke route, so regress.py check bo…
seedds Nov 10, 2026
4283410
Ocarina of Time's output-size stub keeps the size it hands the setter…
seedds Nov 10, 2026
e26ff09
iPhone memory 1: large sampled textures leave out their largest level…
seedds Nov 10, 2026
d78ddfa
iPhone memory 1b: the image flag no longer keeps a large sampled text…
seedds Nov 10, 2026
f9f1aa9
Docs for smaller textures on small devices: a memory.md entry with th…
seedds Nov 10, 2026
c5a352e
MetalFX draws Ocarina of Time's upscaler: the shader map's agl_ndsr_v…
seedds Nov 10, 2026
9612bc4
Upload staging is released after each batch where Metal's working set…
seedds Nov 10, 2026
42279e5
DM_SCREEN_PIXELS holds a picture in another shape than 16:9 to a shar…
seedds Nov 10, 2026
5af0e6e
Ocarina of Time's note: the iPhone 17 played through the Great Deku T…
seedds Nov 10, 2026
dbe335e
iPhone memory 2a: a probe of what a shader gets through a pointer to …
seedds Nov 10, 2026
845fdb3
iPhone memory 2b: a read through a pointer to a buffer outside the re…
seedds Nov 10, 2026
5e5be14
iPhone memory: the census counts a heap once and says who holds the t…
seedds Nov 11, 2026
098362b
iPhone memory: memory pressure trims what no frame needs, and the mem…
seedds Nov 11, 2026
bbed3b3
iPhone memory: an upload batch's reads over guest memory have a budge…
seedds Nov 11, 2026
d07be66
iPhone memory docs: the system's memory and the pressure trim, the up…
seedds Nov 11, 2026
e3193df
iPhone memory docs: the iPhone 17 run with the trim lived through Hyr…
seedds Nov 11, 2026
23d12a5
iPhone memory docs: back on the field after the castle town the iPhon…
seedds Nov 11, 2026
93ff62f
iPhone memory docs: the iPhone 17 run with the trim ended for proc-th…
seedds Nov 11, 2026
cb57493
iPhone memory 2: the residency set is described at each memory pressu…
seedds Nov 11, 2026
29b351d
iPhone memory 2: the census says who holds every texture in the resid…
seedds Nov 11, 2026
28083ec
iPhone memory 2 docs: what the residency set holds across loads on th…
seedds Nov 11, 2026
0832d01
iPhone memory 2 docs: the iPhone 17 run with the measuring build live…
seedds Nov 11, 2026
1df6607
iPhone memory 3: a packaged texture's spare that no re-upload took wi…
seedds Nov 11, 2026
c680394
iPhone memory 3: no rule says beforehand which pools a raw-memory sha…
seedds Nov 11, 2026
d634521
iPhone memory 3: at memory pressure, the Metal copies of uploaded tex…
seedds Nov 11, 2026
7374881
iPhone memory 3 docs: the re-uploads' spares, the uploaded textures f…
seedds Nov 11, 2026
c7ebf30
iPhone memory 3 docs: the iPhone 17 lived through 120 loads with trim…
seedds Nov 12, 2026
408e1b4
iPhone memory: DM_NVN_MEM_PRESSURE and DM_NVN_UPLOAD_SRC_MB have thei…
seedds Nov 12, 2026
36e013e
Ocarina of Time: pso_mtl4 on, so the iPhone and the iPad take render …
seedds Nov 12, 2026
b8cb0bd
nvn: give the whole-again texture warning its own RED_ONCE key
seedds Nov 12, 2026
4fc17cb
OoT-night N-1: submissions that end while the GPU still runs an earli…
seedds Nov 14, 2026
52d5c6a
OoT-night N-1: held submissions keep their own command buffers, so an…
seedds Nov 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
iPhone memory 2a: a probe of what a shader gets through a pointer to …
…a buffer outside the residency set (t_res_absent, DM_RES_PROBE=1)

The raw pool table makes every pool it lists resident, because a shader reaches pools through
pointers loaded from memory, which Metal cannot see. Whether a pool could stay out of the set
until a shader needs it depends on what such an access does. nvn_res_probe.inc measures it: a
Metal 4 queue with the residency set on the queue, as the host has it; a no-copy shared buffer
(anonymous memory or a shared file mapping, as the game's memory is on iOS) read or written
through a pointer held in a resident argument buffer; never resident, evicted (at once, after 32
commits, after 2 s), another buffer over the same pages resident, made resident late, against
resident controls.

Apple M4, macOS 27.2: no case faults the command buffer. A read of a buffer that was never
resident returns zeros, and a write is dropped. A buffer removed from the set still reads
correctly after 32 commits but no longer after 2 s. A buffer added after a zero read reads
correctly from the next commit. A second buffer over the same pages does not help (each buffer
has its own GPU address).

dm/gfx/tests/t_res_absent runs it on the Mac. The host runs it once at start with DM_RES_PROBE=1
(mtl_init, its own queue and set, "[res-probe]" lines) to measure the iPhone. The probe keeps its
feedback dispatch queue for good, as the host does: freed with the probe's queue, it was released
once too often (SIGTRAP in _os_object_release).
  • Loading branch information
seedds committed Nov 12, 2026
commit dbe335e7a9b4bebc8d686ea91ce82eebb7254ef4
3 changes: 3 additions & 0 deletions dm/gfx/nvn/nvn_mtl.m
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ static void udc_selftest(void) {
MLOG("UDC self-check %s %s %lux%lu first value %08x, values differing from it %lu / %lu", g_dev.name.UTF8String, depth ? "Depth32F_S8" : "RGBA8", (unsigned long)w, (unsigned long)h, px[0], (unsigned long)bad, (unsigned long)(w * h));
}
}
#include "nvn_res_probe.inc" // DM_RES_PROBE=1: what an access through a pointer to a buffer outside the residency set gets, on this device (mtl_init)
static void res_probe_say(const char *s) { MLOG("[res-probe] %s", s); }
void mtl_init(void) {
if (g_dev) return;
const char *vbc = getenv("DM_NVN_VBUF_CACHE"); g_vbuf_cache = !(vbc && !strcmp(vbc, "0"));
Expand Down Expand Up @@ -804,6 +806,7 @@ void mtl_init(void) {
if (!g_dev.supportsBCTextureCompression) MDIE("the Metal device %s has no BC texture formats, which the games' textures use and the host does not decompress: an iPhone needs an A17 Pro or later, an iPad an M1 or later", g_dev.name.UTF8String);
[g_q addResidencySet:g_res];
[g_q4 addResidencySet:g_res];
if (getenv("DM_RES_PROBE") && atoi(getenv("DM_RES_PROBE")) > 0) res_probe(g_dev, 2, res_probe_say); // diagnostic, before the game: its own queue and residency set
{ void crash_set_wait_dump(void (*fn)(void)); void mtl_wait_state_dump(void); crash_set_wait_dump(mtl_wait_state_dump); }
g_alloc_n = 3;
for (int i = 0; i < 3; i++) {
Expand Down
137 changes: 137 additions & 0 deletions dm/gfx/nvn/nvn_res_probe.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// What an Apple GPU does when a shader reads or writes through a pointer to a buffer outside the residency set (docs/reference/memory.md, "A read through a pointer to a buffer outside
// the residency set returns zeros"). The raw pool table (nvn_mtl.m gmem_map) hands shaders the GPU addresses of memory pools, which they reach through pointers loaded from memory, out
// of Metal's sight; whether a pool could stay out of the residency set until a shader needs it depends on what such an access does. Each case: a no-copy shared buffer over page-aligned
// memory (as a pool wraps the game's pages), one word per 4 KiB page filled, its GPU address in a resident argument buffer; a kernel copies the words through that pointer into a
// resident output buffer (or writes through it). A Metal 4 queue with the residency set on the queue, as the host has it. Its own queue, set and allocator: it runs before the game, or
// alone (dm/gfx/tests/t_res_absent.m; the host with DM_RES_PROBE=1, mtl_init). say() gets one line per case; returns 0 when a resident control went wrong
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
static const char *const kResProbeSrc =
"#include <metal_stdlib>\n"
"using namespace metal;\n"
"struct P { device uint *p; };\n"
"kernel void rd(constant P &a [[buffer(0)]], device uint *out [[buffer(1)]], constant uint &n [[buffer(2)]], uint i [[thread_position_in_grid]]) {\n"
" if (i < n) out[i] = a.p[i * 1024u];\n"
"}\n"
"kernel void wr(constant P &a [[buffer(0)]], device uint *out [[buffer(1)]], constant uint &n [[buffer(2)]], uint i [[thread_position_in_grid]]) {\n"
" if (i < n) { a.p[i * 1024u] = 0xC0DE0000u | i; out[i] = 1u; }\n"
"}\n";
enum { RP_WORDS = 4096 }; // pages touched per case: 16 MiB of buffer
typedef struct { id<MTLDevice> dev; id<MTL4CommandQueue> q; id<MTLResidencySet> res; id<MTL4CommandAllocator> alloc; id<MTL4ArgumentTable> at; id<MTLComputePipelineState> rd, wr; } rp_ctx;
typedef struct { int faulted; char err[400]; } rp_run;
typedef enum { RP_ANON, RP_FILE, RP_FILE_CACHE } rp_mem;
static uint32_t rp_pat(uint32_t i) { return 0xA5000000u | i; }
static rp_run rp_dispatch(rp_ctx *c, id<MTLComputePipelineState> pso, id<MTLBuffer> target, id<MTLBuffer> out) {
rp_run r = {0};
id<MTLBuffer> args = [c->dev newBufferWithLength:16 options:MTLResourceStorageModeShared], nb = [c->dev newBufferWithLength:16 options:MTLResourceStorageModeShared];
*(uint64_t *)args.contents = target.gpuAddress; *(uint32_t *)nb.contents = RP_WORDS;
memset(out.contents, 0xEE, out.length);
[c->res addAllocation:args]; [c->res addAllocation:nb]; [c->res addAllocation:out]; [c->res commit];
[c->alloc reset];
id<MTL4CommandBuffer> cb = [c->dev newCommandBuffer];
[cb beginCommandBufferWithAllocator:c->alloc];
id<MTL4ComputeCommandEncoder> e = [cb computeCommandEncoder];
[c->at setAddress:args.gpuAddress atIndex:0]; [c->at setAddress:out.gpuAddress atIndex:1]; [c->at setAddress:nb.gpuAddress atIndex:2];
[e setArgumentTable:c->at]; [e setComputePipelineState:pso];
[e dispatchThreads:MTLSizeMake(RP_WORDS, 1, 1) threadsPerThreadgroup:MTLSizeMake(64, 1, 1)];
[e endEncoding]; [cb endCommandBuffer];
dispatch_semaphore_t done = dispatch_semaphore_create(0); rp_run *rp = &r;
MTL4CommitOptions *o = [MTL4CommitOptions new];
[o addFeedbackHandler:^(id<MTL4CommitFeedback> f) {
if (f.error) { NSError *u = f.error.userInfo[NSUnderlyingErrorKey]; rp->faulted = 1;
snprintf(rp->err, sizeof rp->err, "%s%s%s", f.error.description.UTF8String, u ? " | underlying: " : "", u ? u.description.UTF8String : ""); }
dispatch_semaphore_signal(done);
}];
const id<MTL4CommandBuffer> cbs[1] = {cb};
[c->q commit:cbs count:1 options:o];
if (dispatch_semaphore_wait(done, dispatch_time(DISPATCH_TIME_NOW, 10 * NSEC_PER_SEC))) { r.faulted = 2; snprintf(r.err, sizeof r.err, "no feedback within 10 s"); }
[c->res removeAllocation:args]; [c->res removeAllocation:nb]; [c->res removeAllocation:out]; [c->res commit];
return r;
}
static void *rp_mem_new(rp_mem k, size_t n, int *fd_out) {
*fd_out = -1;
if (k == RP_ANON) { void *p = mmap(NULL, n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); return p == MAP_FAILED ? NULL : p; }
char path[1024]; snprintf(path, sizeof path, "%s/dm_res_probe.XXXXXX", NSTemporaryDirectory().UTF8String); // 16 MiB, removed at once
int fd = mkstemp(path); if (fd < 0) return NULL;
unlink(path);
if (ftruncate(fd, (off_t)n)) { close(fd); return NULL; }
if (k == RP_FILE_CACHE) for (uint32_t i = 0; i < RP_WORDS; i++) { uint32_t v = rp_pat(i); if (pwrite(fd, &v, 4, (off_t)i * 4096) != 4) { close(fd); return NULL; } } // in the page cache only
void *p = mmap(NULL, n, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); // the game's memory is a shared file mapping too where it goes into files (iOS)
if (p == MAP_FAILED) { close(fd); return NULL; }
*fd_out = fd; return p;
}
// history: 0 never resident; 1 resident for a commit that read it, then removed; 2 resident (a control); 3 never resident, another buffer over the same pages resident;
// 4 as 1, then 32 other commits; 5 as 1, then 2 s; 6 read while not resident, then made resident and read again
static int rp_case(rp_ctx *c, const char *name, rp_mem k, int history, int write, void (*say)(const char *)) {
char line[700]; size_t n = (size_t)RP_WORDS * 4096; int fd; void *p = rp_mem_new(k, n, &fd);
if (!p) { snprintf(line, sizeof line, "%-34s could not map memory", name); say(line); return 1; }
if (k != RP_FILE_CACHE) for (uint32_t i = 0; i < RP_WORDS; i++) ((uint32_t *)p)[i * 1024u] = rp_pat(i);
id<MTLBuffer> b = [c->dev newBufferWithBytesNoCopy:p length:n options:MTLResourceStorageModeShared deallocator:nil];
id<MTLBuffer> out = [c->dev newBufferWithLength:RP_WORDS * 4 options:MTLResourceStorageModeShared], twin = nil;
char pre[160] = "";
if (history == 1 || history == 4 || history == 5) {
[c->res addAllocation:b]; [c->res commit]; rp_dispatch(c, c->rd, b, out); [c->res removeAllocation:b]; [c->res commit];
if (history == 4) { id<MTLBuffer> o2 = [c->dev newBufferWithLength:n options:MTLResourceStorageModeShared]; [c->res addAllocation:o2]; [c->res commit]; for (int j = 0; j < 32; j++) rp_dispatch(c, c->rd, o2, out); [c->res removeAllocation:o2]; [c->res commit]; }
if (history == 5) sleep(2);
} else if (history == 2) { [c->res addAllocation:b]; [c->res commit]; }
else if (history == 3) { twin = [c->dev newBufferWithBytesNoCopy:p length:n options:MTLResourceStorageModeShared deallocator:nil]; [c->res addAllocation:twin]; [c->res commit]; }
else if (history == 6) {
rp_run cold = rp_dispatch(c, c->rd, b, out); int got = 0; for (uint32_t i = 0; i < RP_WORDS; i++) got += ((uint32_t *)out.contents)[i] == rp_pat(i);
snprintf(pre, sizeof pre, " (before it was resident: %s, data %d)", cold.faulted ? "FAULT" : "ok", got);
[c->res addAllocation:b]; [c->res commit];
}
rp_run r = rp_dispatch(c, write ? c->wr : c->rd, b, out);
int good = 0, zero = 0, other = 0, untouched = 0;
for (uint32_t i = 0; i < RP_WORDS; i++) {
uint32_t v = ((uint32_t *)out.contents)[i];
if (write) { uint32_t m = ((uint32_t *)p)[i * 1024u]; if (m == (0xC0DE0000u | i)) good++; else if (m == 0) zero++; else other++; }
else if (v == 0xEEEEEEEEu) untouched++; else if (v == rp_pat(i)) good++; else if (v == 0) zero++; else other++;
}
snprintf(line, sizeof line, "%-34s %-5s %s %d/%d, zero %d, other %d, output unwritten %d%s%s%s", name, r.faulted == 1 ? "FAULT" : r.faulted == 2 ? "HANG" : "ok",
write ? "landed" : "data", good, RP_WORDS, zero, other, untouched, pre, r.faulted ? " | error: " : "", r.faulted ? r.err : "");
say(line);
if (history == 2 || history == 6) [c->res removeAllocation:b];
if (twin) [c->res removeAllocation:twin];
[c->res commit];
b = nil; twin = nil; out = nil; munmap(p, n); if (fd >= 0) close(fd);
return history != 2 || (!r.faulted && good == RP_WORDS);
}
static int res_probe(id<MTLDevice> dev, int rounds, void (*say)(const char *)) { @autoreleasepool {
char line[300];
if (!dev || ![dev supportsFamily:MTLGPUFamilyMetal4]) { say("no Metal 4 device: skipped"); return 1; }
rp_ctx c = {.dev = dev}; NSError *err = nil;
MTLResidencySetDescriptor *rd = [MTLResidencySetDescriptor new]; rd.initialCapacity = 64;
c.res = [dev newResidencySetWithDescriptor:rd error:&err];
MTL4CommandQueueDescriptor *qd = [MTL4CommandQueueDescriptor new]; static dispatch_queue_t fq; if (!fq) fq = dispatch_queue_create("dm.res-probe.feedback", DISPATCH_QUEUE_SERIAL); // kept for good, as the host keeps its own (g_feedback_q): freed with the probe's queue it was released once too often
qd.feedbackQueue = fq;
c.q = [dev newMTL4CommandQueueWithDescriptor:qd error:&err];
if (c.q && c.res) [c.q addResidencySet:c.res];
c.alloc = [dev newCommandAllocator];
MTL4ArgumentTableDescriptor *atd = [MTL4ArgumentTableDescriptor new]; atd.maxBufferBindCount = 4;
c.at = [dev newArgumentTableWithDescriptor:atd error:&err];
id<MTLLibrary> lib = [dev newLibraryWithSource:@(kResProbeSrc) options:nil error:&err];
if (lib) { c.rd = [dev newComputePipelineStateWithFunction:[lib newFunctionWithName:@"rd"] error:&err]; c.wr = [dev newComputePipelineStateWithFunction:[lib newFunctionWithName:@"wr"] error:&err]; }
if (!c.q || !c.res || !c.alloc || !c.at || !c.rd || !c.wr) { snprintf(line, sizeof line, "could not set up Metal 4: %s", err.localizedDescription.UTF8String); say(line); return 0; }
snprintf(line, sizeof line, "%s, working set %llu MB, %d pages touched per case", dev.name.UTF8String, (unsigned long long)(dev.recommendedMaxWorkingSetSize >> 20), RP_WORDS); say(line);
int ok = 1;
for (int round = 0; round < rounds; round++) {
snprintf(line, sizeof line, "round %d", round + 1); say(line);
ok &= rp_case(&c, "control: resident, read", RP_ANON, 2, 0, say);
ok &= rp_case(&c, "anon, never resident, read", RP_ANON, 0, 0, say);
ok &= rp_case(&c, "anon, evicted, read", RP_ANON, 1, 0, say);
ok &= rp_case(&c, "anon, twin resident, read", RP_ANON, 3, 0, say);
ok &= rp_case(&c, "anon, evicted + 32 commits, read", RP_ANON, 4, 0, say);
ok &= rp_case(&c, "anon, evicted + 2 s, read", RP_ANON, 5, 0, say);
ok &= rp_case(&c, "anon, made resident late, read", RP_ANON, 6, 0, say);
ok &= rp_case(&c, "file, never resident, read", RP_FILE, 0, 0, say);
ok &= rp_case(&c, "file via pwrite, never res., read", RP_FILE_CACHE, 0, 0, say);
ok &= rp_case(&c, "anon, never resident, write", RP_ANON, 0, 1, say);
ok &= rp_case(&c, "file, never resident, write", RP_FILE, 0, 1, say);
ok &= rp_case(&c, "control: resident, write", RP_ANON, 2, 1, say);
}
ok &= rp_case(&c, "control after the cases", RP_ANON, 2, 0, say); // does the queue still work (a fault may revoke the process's GPU access)
[c.q removeResidencySet:c.res]; // Metal traps when a set still attached to a queue is freed
say(ok ? "done: controls correct" : "FAIL: a resident control went wrong");
return ok;
} }
2 changes: 2 additions & 0 deletions dm/gfx/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -675,3 +675,5 @@ check_t_pool_standin: t_pool_standin
t_tex_drop_mip: t_tex_drop_mip.m $(MTL_T_DEP)
clang $(CFLAGS) -fobjc-arc -o $@ t_tex_drop_mip.m $(MTL_T_SRC) $(FW)
check_t_tex_drop_mip: RUN_ENV = MTL_DEBUG_LAYER=1
t_res_absent: t_res_absent.m ../nvn/nvn_res_probe.inc
clang -O1 -g -Wall -fobjc-arc -o $@ t_res_absent.m -framework Metal -framework Foundation
15 changes: 15 additions & 0 deletions dm/gfx/tests/t_res_absent.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// What a shader reading or writing through a pointer to a buffer outside the residency set gets (dm/gfx/nvn/nvn_res_probe.inc; docs/reference/memory.md, "A read through a pointer
// to a buffer outside the residency set returns zeros"). It reports; it fails only when a resident control is wrong, so the result is the log, not the exit code.
// ./t_res_absent [rounds]. On a device, the host runs the same probe at start with DM_RES_PROBE=1
#import <Metal/Metal.h>
#import <Foundation/Foundation.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../nvn/nvn_res_probe.inc"
static void say(const char *s) { printf("%s\n", s); fflush(stdout); }
int main(int argc, char **argv) { @autoreleasepool {
int ok = res_probe(MTLCreateSystemDefaultDevice(), argc > 1 ? atoi(argv[1]) : 2, say);
printf("t_res_absent: %s\n", ok ? "done" : "FAIL");
return !ok;
} }
1 change: 1 addition & 0 deletions docs/env_switches.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ DM_RESOURCE_SHADERS path iOS shader library folder or one file, written to `Gen/
DM_RESOURCE_TITLE switch Game profile title ID, written to `Gen/resources.env` by `gen_resources.py`; with `DM_COPY_ROMFS=NO` the copy phase puts it in the `title=` field of the app's `romfs.id`
DM_RESOURCE_VERSION switch Display version, written to `Gen/resources.env` by `gen_resources.py`; with `DM_COPY_ROMFS=NO` the copy phase puts it in the `version=` field of the app's `romfs.id`
DM_RES_CHECK diagnostic `=1` prints the first 40 textures or buffers a shader reaches through its argument block that are not in the residency set (textures attributed to their parent allocation)
DM_RES_PROBE diagnostic `=1` runs, once at start, the probe of what a shader gets reading or writing through a pointer to a buffer outside the residency set (`nvn_res_probe.inc`, `t_res_absent`), and logs a `[res-probe]` line per case
DM_REWRITE_J switch `=<positive integer>`: worker processes per module for `patch_nso.py`'s x18 scan and spin wait search; `=1` runs serially. Default: one per core directly, an automatic per-module budget in the NSP script. An explicit value overrides that budget
DM_ROMFS path The game's RomFS folder, mounted read-only as `rom` (default `$DM_ROOT/romfs`); the Mac launcher, the iOS app and the NSP script set it
DM_ROMFS_OVERLAY path `=<dir>[:<dir>…]`: RomFS reads look in these folders first, in order, and fall back to `DM_ROMFS` (for a modified copy of some files)
Expand Down