Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions dm/games/0400486024DEC000/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ From an empty save: at about 45 s `A` (title), `A` (New Game), then the movie. F
- Resolved: dotted horizontal rows across the picture in play, in fog and light (GitHub issue 1537): the agl_ndsr_vr networks' HMMA calls outside a chain overwrote an accumulator a chain held ([An HMMA outside a chain overwrote the chain's accumulator](../../../docs/reference/shaders.md#an-hmma-outside-a-chain-overwrote-the-chains-accumulator)), since chain 23a1ea1db092; found by bisecting chains on the Kokiri Forest autosave (0f510fd5's chain clean, bd9f422d's not). Under the game's upscaler they had also grown into white blotches: [LDSM reads rows other lanes stored](../../../docs/reference/shaders.md#ldsm-reads-rows-other-lanes-stored).
- No iOS shader build or iPhone run has been done. Its memory use makes an iPhone unlikely as it stands.

## Unused border corrections

Specialize unused sampler border corrections away ([mechanism](../../../docs/reference/rendering.md#unused-border-corrections-retain-sample-registers)). No sampler of this game needs a twin (no "border colour … Metal lacks" line, the mask 0 in every draw of a profiled frame), so every draw takes the specialization and the picture does not change. Measured on a MacBook Air M4, docked at render scale 0.75 (1920×1080), whole GPU, a window, in the fixed view of Hyrule Field with the most grass (`still.sh`), with the 264 render-stage shaders of that scene that sample through the corrections rebuilt in the new form beside the chain `971e0669b443` image and a host of that chain:

- In-process A/B (`DM_AB DM_NVN_BORDER_KEEP=ab`, the same process, scene and temperature): GPU per frame 25.20 ms specialized against 26.69 and 26.79 ms with the corrections, about 1.5 ms, in the render stages; with the kernels too, a mean of 24.73 ms over five phases against 26.54 ms over four, 1.8 ms.
- Separate runs, interleaved: 26.48 and 27.10 ms with the corrections, 26.00 and 25.46 ms specialized (thermal drift between runs is about 0.6 ms).
- The earlier test-only experiment, every twin sample removed from all 301 shaders including 37 kernels, gave 24.97 ms against a four-run mean of 26.36 ms.

The prewarm built the 551 specialized bases of that scene in 11 s at the start, on background threads, before the measured frames. The offline archive of a full conversion holds them (`pso_offline.py`): a test archive of 24 scene pairs, 20 of them with a specialized pixel function, served all 24 to the host's descriptors.

Its 37 kernels that correct samples, NDSR's network among them, gave about 0.25 ms more (GPU per frame 25.09 and 25.24 ms with their corrections, 24.97 and 24.86 ms without, interleaved runs; their compute encoders 0.3 ms faster in the profiled frames). Chain `da29694f3f98` contains the change for every stage; a full shader conversion with it is pending, and so is the target of at least 55 fps at these settings.

## Found on this game

- [The 60 Hz link at 40 fps in fullscreen on a ProMotion screen](../../../docs/reference/frame-rate.md#the-60-hz-link-at-40-fps-in-fullscreen-on-a-promotion-screen): 40 fps in fullscreen on an M5 Pro MacBook Pro with the GPU at 10 ms of the 16.7, every present one 120 Hz refresh late and every other display-link tick skipped; the screen's fixed 60 Hz mode held 60.0 fps there and fullscreen now switches to it, with the 120 Hz link (59 fps) for screens with no such mode.
Expand All @@ -119,6 +131,7 @@ From an empty save: at about 45 s `A` (title), `A` (New Game), then the movie. F
- [Frame-step stubs placed by their function](../../../docs/reference/rewriter.md#frame-step-stubs-placed-by-their-function)
- [Repository patches missing under bracketed paths](../../../docs/reference/rewriter.md#repository-patches-missing-under-bracketed-paths): resolved, a build in a folder named with brackets lost this game's frame-step stubs and cuts without an error.
- [Retired pool buffers pile up while a game submits nothing](../../../docs/reference/memory.md#retired-pool-buffers-pile-up-while-a-game-submits-nothing): out of focus GPU allocated went from 11 to 20 GB in 12 s with swap following (PR #1392); the likely cause of a session that stayed frozen after a window switch. Not reproduced on the village-deck route (2026-11-09, M6): 40 s out of focus, during the load or standing on the deck, made no pool deletions at all, so the scene that remakes a virtual pool's runs out of focus is still to be found.
- [Unused border corrections retain sample registers](../../../docs/reference/rendering.md#unused-border-corrections-retain-sample-registers): about 1.5 ms of GPU a frame at 1080p ([measurements](#unused-border-corrections)).

- [Position invariance across shaders](../../../docs/reference/shaders.md#position-invariance-across-shaders): white shapes on plants and bushes for single frames in Kokiri Forest, from the foliage's mesh pre-pass and mesh colour pass rounding the position apart.
- [gl_FragCoord.z against the depth stored for its own surface](../../../docs/reference/shaders.md#gl_fragcoordz-against-the-depth-stored-for-its-own-surface): the dark specks flickering in the ground mist (long-standing). The mist's own depth test (`5ad65c0eefd09c7f`, against its depth-only pass `4757b5b373a5406e`) rejected its own surface where Apple's GPU stored the depth one ulp under the fragment's z. Bisected by dropping fragment shaders: after mesh draws took the drop too (`skip_fs_draw`), the specks went with the mist or its depth-only pass, and when that pass wrote `[[position]].z` as depth. Resolved by the rewrite: no specks in play with its 39 rewritten shaders as an overlay (the player's check, 2026-11-09); a full library build on the new chain has not been run.
Expand Down
3 changes: 3 additions & 0 deletions dm/gfx/nvn/dmsh_abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
#define DMSH_BORDER_K 0x10 // byte offset of sampler bit i's factors k (a float4) in the block: DMSH_BORDER_K + 16 i
#define DMSH_BORDER_TWIN "_w" // the suffix of a twin sampler member's name
#define DMSH_BORDER_MEMBER "dm_border" // the name of the block's member in the argument buffer
// The corrections' function constant (bool, every stage): true turns them off, for a pipeline whose draw or dispatch binds no sampler with a
// twin (nvn_mtl.m border_need, bd_off, cs_fn). The twin samples go, and the registers they kept: Ocarina of Time's 1080p material passes spilled 300-400 bytes a thread with them. Undefined, every sample corrects as its bit says
#define DMSH_BORDER_FC 216
// The logic operation's state (dm/gfx/tools/dmsh_logic.py, the _l entry points of the <key>_bx libraries): uint operation (NVN_LOGIC_OP_*), 12 bytes of padding, a uint4 channel mask per colour target, at this fragment buffer index (nvn_mtl.m lo_bind)
#define DMSH_LOGIC_BUFFER 29
// Its function constants: bool, colour target n is attached (the variant reads it only then), at this index + n (nvn_mtl.m lo_fn specializes the entry point per pass's targets)
Expand Down
2 changes: 1 addition & 1 deletion dm/gfx/nvn/dmsh_chain.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Generated file (dm/gfx/tools/dmsh_chain.py --header): the B shader library translation chain version this source tree expects (default options), one for every game;
// the host loads only <library dir>/b-<V>/. Run dmsh_chain.py --header after changing the chain's tools and commit this file with the change
#define DMSH_CHAIN "0c434f1b68df"
#define DMSH_CHAIN "884b3d7c2712"
28 changes: 17 additions & 11 deletions dm/gfx/nvn/nvn_geometry.inc
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static NvShader *geo_lean_pick(NvProg *pr, NvShader *gs, int topology, int insta
}
NvShader *lean = base->geo_lean_v[topology];
if (!lean || !lean->geo_slot || lean->geo_vertices != (uint32_t)nvn_geo_width(topology) || lean->geo_invocations != 1) return NULL;
if (!lean->geo_pso && !lean->geo_pso_failed) { NSError *e = nil; lean->geo_pso = [g_dev newComputePipelineStateWithFunction:lean->fn error:&e];
if (!lean->geo_pso && !lean->geo_pso_failed) { NSError *e = nil; lean->geo_pso = [g_dev newComputePipelineStateWithFunction:fn_dev(lean->fn) error:&e];
if (!lean->geo_pso || lean->geo_pso.maxTotalThreadsPerThreadgroup < 32) { lean->geo_pso = nil; lean->geo_pso_failed = 1; MLOG("[RED] lean geometry compute %s: %s; the full kernel draws", lean->key, e ? e.localizedDescription.UTF8String : "no 32-thread group"); } }
if (!lean->geo_pso) return NULL;
if (!g_geo_lean_k[2]) {
Expand Down Expand Up @@ -385,6 +385,11 @@ static uint32_t geo_mesh_prims(id<MTLFunction> f) {
}
static struct { NvShader *vs, *lean; id<MTLFunction> f; } g_geo_mesh_last;
static NSMutableDictionary *g_geo_mesh_runfn; // a mesh entry → its run twin (dm_mesh_run..., dmsh_mesh.py), or NSNull: none in the library, or its pipeline failed
// Generated mesh entries inherit the vertex library's constants. Keep their descriptors so fn_dev can materialize defaults or bd_off's specialization, as for shader_load.
static id<MTLFunction> geo_mesh_entry(id<MTLLibrary> lib, NSString *name) {
id<MTLFunction> f = [lib newFunctionWithName:name];
return f.functionConstantsDictionary.count ? fn_spec(lib, name, [MTLFunctionConstantValues new], NULL) : fn4_note(f, lib, name, nil);
}
// The mesh entry for this draw's program, or nil (the compute path draws it)
static id<MTLFunction> geo_mesh_fn(NvProg *pr, const p_draw *dw, const p_draw_idx *di) {
if (!geo_mesh_on()) return nil;
Expand All @@ -401,10 +406,10 @@ static id<MTLFunction> geo_mesh_fn(NvProg *pr, const p_draw *dw, const p_draw_id
NSString *path = [NSString stringWithFormat:@"%@/%.16s_%.16s_m3.metallib", g_msl_dir, vs->key, lean->key];
id<MTLLibrary> lib = lib_from_file(path, NULL);
NSString *want = [vs->fn.name isEqualToString:@"main0_z"] ? @"dm_mesh_z" : @"dm_mesh";
f = lib ? [lib newFunctionWithName:want] : nil;
if (lib && !f) for (NSString *nm in lib.functionNames) if ([nm hasPrefix:[want stringByAppendingString:@"_p"]]) { f = [lib newFunctionWithName:nm]; break; } // fewer triangles a group (dm_mesh_p16)
f = lib ? geo_mesh_entry(lib, want) : nil;
if (lib && !f) for (NSString *nm in lib.functionNames) if ([nm hasPrefix:[want stringByAppendingString:@"_p"]]) { f = geo_mesh_entry(lib, nm); break; } // fewer triangles a group (dm_mesh_p16)
if (f) { if (!g_geo_mesh_runfn) g_geo_mesh_runfn = [NSMutableDictionary dictionary]; // its run twin: dm_mesh_z_p16 → dm_mesh_run_z_p16
g_geo_mesh_runfn[[NSValue valueWithPointer:(__bridge const void *)f]] = [lib newFunctionWithName:[@"dm_mesh_run" stringByAppendingString:[((id<MTLFunction>)f).name substringFromIndex:7]]] ?: NSNull.null; }
g_geo_mesh_runfn[[NSValue valueWithPointer:(__bridge const void *)f]] = geo_mesh_entry(lib, [@"dm_mesh_run" stringByAppendingString:[((id<MTLFunction>)f).name substringFromIndex:7]]) ?: NSNull.null; }
static int n; if (f || n++ < 16) MLOG("geometry mesh: vertex %s kernel %s %s", vs->key, lean->key, f ? "has a mesh library" : "has no mesh library (geo_mesh.tsv): the compute path draws it");
vs->geo_mesh[k] = f = f ?: NSNull.null;
}
Expand All @@ -425,7 +430,7 @@ static id<MTLRenderPipelineState> geo_mesh_pso_for(NvProg *pr, id<MTLFunction> f
if (!ps) {
MTLRenderPipelineDescriptor *d = pso_desc(&k, vs, fs, nil, 0);
MTLMeshRenderPipelineDescriptor *m = [MTLMeshRenderPipelineDescriptor new];
m.meshFunction = fn; m.fragmentFunction = d.fragmentFunction;
m.meshFunction = fn_dev(k.border ? fn : bd_off(fn)); m.fragmentFunction = fn_dev(d.fragmentFunction);
m.rasterSampleCount = d.rasterSampleCount; m.alphaToCoverageEnabled = d.alphaToCoverageEnabled;
for (int i = 0; i < 8; i++) m.colorAttachments[i] = d.colorAttachments[i];
m.depthAttachmentPixelFormat = d.depthAttachmentPixelFormat; m.stencilAttachmentPixelFormat = d.stencilAttachmentPixelFormat;
Expand Down Expand Up @@ -569,8 +574,8 @@ static id<MTLFunction> mtk_nop_fragment(void) {
}
// The Metal 4 descriptor of a native mesh pipeline, whole: no base with open colour state, as a game has some hundred of them, each with functions of its own. Its depth / stencil
// formats are not named (Metal 4 pipelines serve any). nil when a function has no Metal 4 descriptor (fn4_of: the diagnostic fragment overrides)
static MTL4MeshRenderPipelineDescriptor *mtk_desc4(MTLRenderPipelineDescriptor *d, NvShader *ts, NvShader *ms, id<MTLFunction> ff) {
MTL4FunctionDescriptor *mf = fn4_of(ms->fn), *of = fn4_of(ts ? ts->fn : ms->mesh_obj), *f4 = fn4_of(ff);
static MTL4MeshRenderPipelineDescriptor *mtk_desc4(MTLRenderPipelineDescriptor *d, NvShader *ts, NvShader *ms, id<MTLFunction> ff, int border) {
MTL4FunctionDescriptor *mf = fn4_of(border ? ms->fn : bd_off(ms->fn)), *of = fn4_of(ts ? (border ? ts->fn : bd_off(ts->fn)) : ms->mesh_obj), *f4 = fn4_of(ff);
if (!mf || !of || !f4) return nil;
MTL4MeshRenderPipelineDescriptor *m = [MTL4MeshRenderPipelineDescriptor new];
m.meshFunctionDescriptor = mf; m.fragmentFunctionDescriptor = f4; m.maxTotalThreadsPerMeshThreadgroup = ms->mesh_threads;
Expand All @@ -592,7 +597,7 @@ static id<MTLRenderPipelineState> mtk_build(const pso_key *k, NvShader *ts, NvSh
if (!pso_ds_valid((uint32_t)d.depthAttachmentPixelFormat, (uint32_t)d.stencilAttachmentPixelFormat)) return nil;
id<MTLFunction> ff = d.fragmentFunction ?: mtk_nop_fragment();
pso4_init();
MTL4MeshRenderPipelineDescriptor *m4 = g_comp4 ? mtk_desc4(d, ts, ms, ff) : nil;
MTL4MeshRenderPipelineDescriptor *m4 = g_comp4 ? mtk_desc4(d, ts, ms, ff, k->border) : nil;
if (m4) {
id<MTLRenderPipelineState> ps = nil; int from_run = 0;
ps = arch_lookup(m4, 0, &from_run); // a period of mesh pipelines alone is a p file (no vertex layout)
Expand All @@ -603,8 +608,8 @@ static id<MTLRenderPipelineState> mtk_build(const pso_key *k, NvShader *ts, NvSh
}
}
MTLMeshRenderPipelineDescriptor *m = [MTLMeshRenderPipelineDescriptor new];
m.meshFunction = fn_dev(ms->fn); m.fragmentFunction = fn_dev(ff); m.maxTotalThreadsPerMeshThreadgroup = ms->mesh_threads;
m.objectFunction = fn_dev(ts ? ts->fn : ms->mesh_obj); m.payloadMemoryLength = ts ? (ts->mesh_payload + 15u) & ~15u : 16; m.maxTotalThreadsPerObjectThreadgroup = ts ? ts->mesh_threads : 1;
m.meshFunction = fn_dev(k->border ? ms->fn : bd_off(ms->fn)); m.fragmentFunction = fn_dev(ff); m.maxTotalThreadsPerMeshThreadgroup = ms->mesh_threads;
m.objectFunction = fn_dev(ts ? (k->border ? ts->fn : bd_off(ts->fn)) : ms->mesh_obj); m.payloadMemoryLength = ts ? (ts->mesh_payload + 15u) & ~15u : 16; m.maxTotalThreadsPerObjectThreadgroup = ts ? ts->mesh_threads : 1;
m.rasterSampleCount = d.rasterSampleCount; m.alphaToCoverageEnabled = d.alphaToCoverageEnabled;
for (int i = 0; i < 8; i++) m.colorAttachments[i] = d.colorAttachments[i];
m.depthAttachmentPixelFormat = d.depthAttachmentPixelFormat; m.stencilAttachmentPixelFormat = d.stencilAttachmentPixelFormat;
Expand All @@ -626,6 +631,7 @@ static id<MTLRenderPipelineState> mtk_pso(NvProg *raster) {
if (!raster || !g_mtk.ms || !g_mtk.ms->fn) return nil;
NvShader *ts = g_mtk.ts, *ms = g_mtk.ms, *fs = raster->sh[1];
pso_key k; pso_key_fill(&k, ms, fs, g_pass.cfmt, g_pass.dfmt, g_pass.sfmt, g_pass.samples, 0);
k.border |= border_need(ts, 3);
memset(k.attr, 0, sizeof k.attr); memset(k.attr_hi, 0, sizeof k.attr_hi); memset(k.stream, 0, sizeof k.stream);
mtk_bind_key(&k, ts, ms, fs);
id ps = hm_get_id(&g_pso_mtk, &k);
Expand Down Expand Up @@ -840,7 +846,7 @@ static int geo_prep(NvProg *pr, const p_draw *dw0, const p_draw_idx *di0, geo_jo
if (lean) gs = lean;
uint32_t record = lean ? gs->geo_words : GEO_CAPTURE_WORDS;
id<MTLRenderPipelineState> capture = geo_capture_pso(vs); if (!capture) return 0;
if (!gs->geo_pso) { NSError *e = nil; gs->geo_pso = [g_dev newComputePipelineStateWithFunction:gs->fn error:&e];
if (!gs->geo_pso) { NSError *e = nil; gs->geo_pso = [g_dev newComputePipelineStateWithFunction:fn_dev(gs->fn) error:&e]; // fn_dev: a kernel that samples has the border corrections' constant (kept)
if (!gs->geo_pso) { MLOG("[RED] geometry compute %s: %s", gs->key, e.localizedDescription.UTF8String); return 0; } }
if (gs->geo_pso.maxTotalThreadsPerThreadgroup < 32) { MLOG("[RED] geometry kernel cannot run a 32-thread group"); return 0; }

Expand Down
Loading
Loading