mirror of
https://github.com/seedds/nxnative.git
synced 2026-11-23 11:39:42 -10:00
nvn: continue passes across redundant target unbinds (#2806)
Keep an empty render-target binding pending across state records so a rebind
can use the existing same-target continuation. Work, barriers and submission
end first finalize the old pass and apply the empty binding. Compare views
by their active fields and ignore trailing empty color slots.
Resolve fragment uniform texture handles with the existing storage-alias
guards. Keep conservative boundaries for unknown bindings, tables, pools,
other shader stages and mixed bindless/raw-buffer access. Apply the pending
binding only after queued mesh work and attachment stores have finished.
The unrelated fixed-offset Unreal cvar forcing is excluded.
Validation on Apple M4 Pro, macOS 27.2.1, against ba9ce212:
- Replay/readback tests cover unbind/rebind, nested returns, unbound draws,
barriers, clears, copies, inline updates, view identity and feedback.
- Full graphics suite: an existing t_counter_clock precision flake also
reproduces on unchanged main; the remaining checks pass.
- NieR: full 220-second flight route and captured-frame replay pass within
measured baseline noise. Timed ocean shots vary on unchanged main too.
- Octopath II: full 440-second battle route and screenshots pass, with the
pre-existing profile gl/runtime zero depth mismatch recorded as known.
- Targeted C lint has no new findings; documentation checks pass.
This is a general host fix. Orbitals' reported M4 speedup is not remeasured
for the revised guards; its gameplay/performance retest and iOS remain open.
Co-authored-by: settobox-crypto <[email protected]>
This commit is contained in:
1 parent
5d54b885ec
commit
d6b5fc1b08
10 files changed
+266
-38
No files matched your search
@@ -29,6 +29,8 @@ Update 1.0.3 (v131072) over the base cartridge dump. PlatinumGames' engine, SDK
|
||||
|
||||
## Status on the Mac
|
||||
|
||||
- Shared host [render-pass continuity](../../../docs/reference/rendering.md#empty-target-bindings-between-draws-broke-continuation) validation (#2806, 2026-11-17, M4 Pro, macOS 27.2.1, baseline `ba9ce212`, chain `9eecb8412308`): both full 220-second opening-flight runs reached the route target, with all 1,225 shaders unchanged, no new red diagnostic, crash or hang. The timed ocean screenshot comparison flagged a difference (RGB 7.26); an unchanged-baseline control varied more (RGB 9.38). Frame 10,800 then passed three fresh replays per revision within the existing 2,094-pixel tolerance, derived from eight unchanged-baseline replays with at most 1,047 differing pixels. The candidate differed in at most 1,260 pixels, the comparison baseline in 885. The route now names that frame for repeatable capture/replay checks; captures and reports stay in the NSP work folder's `regress/` directory.
|
||||
- In those runs' 140–200 s window, GPU p50 was 8.363 / 8.761 ms in the two baseline controls and 6.837 ms in the candidate. Attachment traffic and pass counts were essentially unchanged, with no deferred-unbind event logged in this route, so these observations do not establish a speedup from the fix.
|
||||
- The title, menus, keyboard naming, a new Easy game with auto-chips, save creation and save loading pass. The opening formation cinematic and ocean combat render ships, clouds, lighting, exhaust, shots and HUD correctly. Left/right movement and firing respond to input (`snap01_control_*`, `fps60_opt_*`).
|
||||
- Both logo movies decode through NintendoSDK_movie. The final 300-second run exits cleanly after the test's SIGTERM; Wwise output has zero underruns through 28,000 device callbacks. Resident memory peaks around 2,811 MB and Metal allocations around 2,995 MB, then settle below those peaks while the route streams more objects; its last report is 2,794 / 2,933 MB at frame 17,700.
|
||||
- **Resolved: repeated geometry drains and sorting.** The original heavy flight route spent most sampled main-thread time waiting in `mdi_wait`, followed by sorting capture indices. The shared synchronization/bitset fix linked below removes those hotspots.
|
||||
|
||||
@@ -9,3 +9,5 @@ reach 3000@100
|
||||
window 140 60
|
||||
shots 100,180
|
||||
hang 20
|
||||
# Ocean flight: replay identical commands when timed wave highlights/ship motion differ between live runs.
|
||||
capture 10800
|
||||
|
@@ -47,6 +47,7 @@ Status: brought up on the Mac: the boot, the initial settings, the title, a new
|
||||
## Mac routes
|
||||
|
||||
- [`smoke.tsv`](smoke.tsv) loads a copy of `saves/hikari-settings` (the initial settings only), selects Hikari, closes the first battle tutorial and executes his first attack. That attack exercises the 129,032-triangle geometry split above and opens the boost tutorial shown by the comparison screenshots.
|
||||
- **Shared host render-pass continuity validation (#2806, M4 Pro, macOS 27.2.1, 2026-11-17, `ba9ce212` baseline, chain `9eecb8412308`, 440 seconds):** both runs reached the first attack and boost tutorial, with all 13,980 shaders unchanged, no new red diagnostic, crash, hang or interface failure, and matching screenshots (dHash 1 bit each, RGB differences 0.14 / 0.10). GPU p50 in the 400–425 s window was 6.786 / 7.000 ms; these unisolated runs do not establish a performance change. **Open, baseline too:** this profile defaults to `depth_mode gl`, while both runs select near-zero depth at boot; the harness reports that archive/profile mismatch as known. Correcting the metadata and rebuilding its archive is separate from the [general continuity fix](../../../docs/reference/rendering.md#empty-target-bindings-between-draws-broke-continuation).
|
||||
- **Geometry integration validation (M6 Mac, `e06adb2a` baseline, 440 seconds):** both revisions execute the 129,032-triangle split after the first attack; the corrected candidate completes without a crash, hang or red diagnostic. Baseline/candidate: 59.8/59.8 fps, frame p99 18.06/18.51 ms, peak footprint 3,609/3,762 MB; all 1,903 pipeline bases prebuild. Both comparison screenshots pass (RGB differences 0.32 and 0.36). After that measured window, closing the boost tutorial and taking a further candidate screenshot confirms the battle scene. The earlier failing run remains recorded as the descriptor-lifetime bug's reproduction.
|
||||
- **Compute primitive-ID follow-up (M6 Mac, `2c31212f` baseline, 440 seconds):** both revisions again execute the 129,032-triangle split; no new red diagnostic, crash, hang or shader-interface failure. Baseline/candidate: 59.8/59.6 fps, frame p99 17.63/17.39 ms, peak footprint 3,830/3,766 MB; all 1,903 pipeline bases prebuild. Both comparison screenshots pass (RGB differences 0.06 and 0.10). After the measured window, closing the boost tutorial in both runs confirms the battle geometry. The [general primitive-ID fix](../../../docs/reference/shaders.md#split-geometry-primitive-ids) is verified independently with a shader that reads the ID; this route checks the changed splitter in gameplay.
|
||||
- The work folder's `run/ctlrun.sh <run>` starts a run with `DM_CTL`, `run/see.sh <shot> <wait> <presses…>` presses and takes a screenshot, `run/mash.sh` presses through dialog. From `run/save_ref` (the initial settings only): `run/to_ship.sh <run>` goes through the title, New Game and Castti (R L L L L on the traveler selection) to her free play on the ship's deck, `run/to_hikari.sh` to Hikari's battlefield (R L L L), `run/to_battle.sh` on through his first battle and the scene after it, and `run/ab.sh <prefix> "<env>"…` drives several runs at once into Hikari's battlefield with shots along the way (how the scissor fix was found): [05, Scripted input](../../../docs/agents/05-debugging.md#scripted-input-and-thread-scheduling).
|
||||
|
||||
@@ -33,6 +33,8 @@ Orbitals cannot be played alone: Play Local waits for a second player to join, a
|
||||
|
||||
- Current: 30 fps, the game's own: it sets present interval 2 at the title (`the game sets present interval 1 → 2`). In the first area: frame time p50 33.3 ms, p95 34.2 ms, an occasional long frame of 200 ms; CPU 113% of one core, 4.7 W.
|
||||
- Not tried: 60 fps (`fps_target`).
|
||||
- Host pass-continuity fix (#2806): the reporter's M4 split-screen scene was GPU-bound, with about 550 passes and GPU p50 97 ms; the original general continuity patch reportedly reduced these to about 270 and 40 ms. See [empty target bindings](../../../docs/reference/rendering.md#empty-target-bindings-between-draws-broke-continuation). The revised patch excludes fixed-offset cvar forcing and preserves conservative alias/unknown-handle guards. Open: local Orbitals gameplay and a same-scene performance comparison (the title is unavailable in this machine's local regression set); the newer depth/stencil-plane and depth-only/vertex-handle proposals are not included.
|
||||
- Other-game validation: [NieR Automata](../010056B015FE8000/README.md#status-on-the-mac) (feedback/postprocessing, including a captured-frame comparison) and [Octopath Traveler II](../0100A3501946E000/README.md#mac-routes) (Unreal), the two lighter local games chosen for this uncertain shared NVN change. Their notes record the results and existing limitations; the [reference entry](../../../docs/reference/rendering.md#empty-target-bindings-between-draws-broke-continuation) records the graphics-suite checks.
|
||||
|
||||
## Memory
|
||||
|
||||
@@ -56,6 +58,7 @@ On a first start the language, gamma and terms screens come before the title: `A
|
||||
|
||||
## Found on this game
|
||||
|
||||
- [Empty target bindings between draws broke continuation](../../../docs/reference/rendering.md#empty-target-bindings-between-draws-broke-continuation): redundant unbind/rebind calls prevented the host from continuing its render pass ([#2806](https://github.com/seedds/nxnative/issues/2806)).
|
||||
- [Unreal Engine 5.6 IoStore shader libraries for the Switch 2](../../../docs/reference/shaders.md#unreal-engine-56-iostore-shader-libraries-for-the-switch-2): the split stopped at `shader 0 is not an LSLG record`.
|
||||
- [The SDK's address-region node area](../../../docs/reference/memory.md#the-sdks-address-region-node-area): the engine region started past a 1 GB node area and did not fit an iPhone's address space; the SDK-wide rule now has this SDK 21.4 build's constructor.
|
||||
- [Ampere forms with a handle in a register](../../../docs/reference/shaders.md#ampere-forms-with-a-handle-in-a-register-and-sureds-other-operations): 5 compute shaders stopped at `Ampere instruction 394`.
|
||||
|
||||
+88
-29
@@ -2578,7 +2578,8 @@ int mtl_gpu_span(uint64_t f, uint64_t *t0, uint64_t *t1) {
|
||||
*t0 = atomic_load(&g_gpu[k].t0); *t1 = atomic_load(&g_gpu[k].t1);
|
||||
return *t1 >= *t0 && *t1;
|
||||
}
|
||||
static void rp_flush(void);
|
||||
static void rp_flush_at(const char *fn, int line);
|
||||
#define rp_flush() rp_flush_at(__func__, __LINE__)
|
||||
static const char *cctx_snap(void); // What is in this submission (printed into the failure line on error; defined before mtl_exec)
|
||||
typedef struct cbs_list cbs_list; // The game's shaders one command buffer encoded (defined before encode_args)
|
||||
static cbs_list *cbs_take(void);
|
||||
@@ -5737,6 +5738,11 @@ static void rt_mirror_flush(void) {
|
||||
}
|
||||
static int g_nbcp; static void bcp_flush(void); static void bcp_wrote(const tex_t *t, id<MTLTexture> m); static void bcp_idx(int id_, const tex_t *t, int add);
|
||||
static int bcp_before(const tex_t *t, id<MTLTexture> m, tex_t *o); static void bcp_after(const tex_t *t, unsigned level, const NVNcopyRegion *r); static void bcp_after_to(const tex_t *t, const tex_t *op, unsigned level, const NVNcopyRegion *r); // compressed-alias pairs: sides written in this pass or dispatch (bcp_wrote)
|
||||
// Deferred unbind (DM_NVN_UNBIND_DEFER, on by default). An empty binding carries no GPU work: keep the open pass across state records so the next SET_RT can use same-target
|
||||
// continuation. An op outside unb_keeps ends the pass first. The old attachments and queued mesh draws are finalized before the empty binding takes effect, including when the pass ends
|
||||
// for a reason other than SET_RT
|
||||
static int g_unb; static p_set_rt g_unb_rt; static uint64_t g_unb_n;
|
||||
static int unb_on(void) { static int v = -1; if (v < 0) { const char *e = getenv("DM_NVN_UNBIND_DEFER"); v = !(e && !strcmp(e, "0")); if (!v) MLOG("DM_NVN_UNBIND_DEFER=0: unbinding the targets ends the pass"); } return v; }
|
||||
static void rp_end_at(const char *fn, int line) { if (g_enc) { AP_B; geo_mesh_flush_pass(); PD("E %llu pass ends in %s:%d", g_stat_pass, fn, line);
|
||||
if (enc_label_on()) { static uint64_t lf = ~0ull, base; uint64_t f = atomic_load(&g_cur_frame); if (f != lf) { lf = f; base = g_stat_pass - 1; } // Intra-frame serial: the same pass has the same name every frame, so the table can aggregate by name
|
||||
[(id)g_enc setLabel:[NSString stringWithFormat:@"p%02llu %dx%d %s d%d", (unsigned long long)(g_stat_pass - base), g_el_w, g_el_h, g_el_key[0] ? g_el_key : "-", g_el_draws]]; }
|
||||
@@ -5747,7 +5753,9 @@ static void rp_end_at(const char *fn, int line) { if (g_enc) { AP_B; geo_mesh_fl
|
||||
if (g_nrtm) rt_mirror_flush();
|
||||
if (g_nbcp) { bcp_flush(); if (g_blit) { enc_b_end(g_blit); g_blit = nil; } } // sides of compressed-alias pairs the pass wrote go into their other sides, after the shadows' blocks (bcrt_flush); the copy encoder is closed again, as rt_mirror_flush does
|
||||
AP_E(0);
|
||||
} }
|
||||
}
|
||||
if (g_unb) { g_unb = 0; R.rt = g_unb_rt; } // finalize the old attachments and queued mesh draws before applying the unbind
|
||||
}
|
||||
void pg_sub_begin_ext(uint64_t fence) { pg_sub_begin(fence); }
|
||||
void pg_commit_ext(id<MTLCommandBuffer> cb) { pg_commit(cb); }
|
||||
// The format an attachment is actually attached with: the view's format if the view changes the format and can be attached, otherwise the base texture's. Shared by attaching (attach) and pipeline prediction (pso_predict_rest) so both agree --
|
||||
@@ -6139,11 +6147,11 @@ static void rt_dims(NSUInteger *tw, NSUInteger *th) {
|
||||
*tw = t0 ? mip_extent(t0.width, level) : 16384; *th = t0 ? mip_extent(t0.height, level) : 16384; // no targets: an attachment-less pass can be up to 16384 (bare_dims)
|
||||
}
|
||||
// There are pending clears but no draw in the pass: open a pass once to land the clears
|
||||
static void rp_flush(void) {
|
||||
static void rp_flush_at(const char *fn, int line) { // fn:line is the caller (the pass dump's E line names it)
|
||||
int pend = R.clear_d || R.clear_s;
|
||||
for (int i = 0; i < 8; i++) pend |= R.clear_c[i];
|
||||
if (pend && !g_enc && g_cb) rp_begin_ex(1);
|
||||
rp_end();
|
||||
rp_end_at(fn, line);
|
||||
}
|
||||
static int scissor_full(const tex_t *t, const view_t *v, int has_v) {
|
||||
NSUInteger level = has_v && v->set_levels ? v->base_level : 0;
|
||||
@@ -13157,15 +13165,31 @@ static void pso_predict_rest_(void) {
|
||||
// its memory holds nothing of this pass until then; and a draw writing depth or stencil after a draw of the pass read that attachment ends it too (fb_prepare), since the GPU stores the pass tile by tile, so the earlier reads would see the later writes in the tiles already done.
|
||||
// Its water reads the scene's depth and the next draw writes the water's own: without that rule, grey blocks of tiles all over the sea. A pass with no colour attachment ends as before. DM_NVN_RT_CONTINUE=0 ends every pass as before
|
||||
static int rtc_on(void) { static int v = -1; if (v < 0) { const char *e = getenv("DM_NVN_RT_CONTINUE"); v = !(e && !strcmp(e, "0")); if (!v) MLOG("DM_NVN_RT_CONTINUE=0: setting the same render targets again ends the pass"); } return v; }
|
||||
static int rt_same(const p_set_rt *a, const p_set_rt *b) { // Same set of targets: compare by texture serial and view (not by object pointer: the game may copy texture objects by value)
|
||||
if (a->n != b->n || !a->depth != !b->depth || (a->depth && a->depth->serial != b->depth->serial) || a->has_dview != b->has_dview) return 0;
|
||||
if (a->has_dview && memcmp(&a->dview, &b->dview, sizeof a->dview)) return 0;
|
||||
for (int k = 0; k < a->n && k < 8; k++) {
|
||||
if (!a->color[k] != !b->color[k] || (a->color[k] && a->color[k]->serial != b->color[k]->serial) || a->has_cview[k] != b->has_cview[k]) return 0;
|
||||
if (a->has_cview[k] && memcmp(&a->cview[k], &b->cview[k], sizeof a->cview[k])) return 0;
|
||||
}
|
||||
// Two views select the same subresources and format: only the fields their flags set count (the rest, and _rsv, may hold anything the game left in its stack slot)
|
||||
static int view_same(const view_t *x, const view_t *y) {
|
||||
if (x->set_levels != y->set_levels || x->set_layers != y->set_layers || x->set_format != y->set_format || x->set_target != y->set_target || x->set_swizzle != y->set_swizzle || x->set_dsmode != y->set_dsmode) return 0;
|
||||
if (x->set_levels && (x->base_level != y->base_level || x->nlevels != y->nlevels)) return 0;
|
||||
if (x->set_layers && (x->min_layer != y->min_layer || x->nlayers != y->nlayers)) return 0;
|
||||
if (x->set_format && x->format != y->format) return 0;
|
||||
if (x->set_target && x->target != y->target) return 0;
|
||||
if (x->set_swizzle && memcmp(x->swz, y->swz, 4)) return 0;
|
||||
if (x->set_dsmode && x->dsmode != y->dsmode) return 0;
|
||||
return 1;
|
||||
}
|
||||
static const char *g_rt_diff; // why the last rt_same said no (the pass dump's M line)
|
||||
static int rt_same(const p_set_rt *a, const p_set_rt *b) { // Same set of targets: compare by texture serial and view (not by object pointer: the game may copy texture objects by value)
|
||||
int na = a->n, nb = b->n; // trailing empty colour slots do not change the set
|
||||
while (na > 0 && !a->color[na - 1]) na--;
|
||||
while (nb > 0 && !b->color[nb - 1]) nb--;
|
||||
if (na != nb) { g_rt_diff = "n"; return 0; }
|
||||
if (!a->depth != !b->depth || (a->depth && a->depth->serial != b->depth->serial)) { g_rt_diff = "depth"; return 0; }
|
||||
if (a->depth) { view_t z = {0}; if (!view_same(a->has_dview ? &a->dview : &z, b->has_dview ? &b->dview : &z)) { g_rt_diff = "dview"; return 0; } }
|
||||
for (int k = 0; k < na && k < 8; k++) {
|
||||
if (!a->color[k] != !b->color[k] || (a->color[k] && a->color[k]->serial != b->color[k]->serial)) { g_rt_diff = "color"; return 0; }
|
||||
if (a->color[k]) { view_t z = {0}; if (!view_same(a->has_cview[k] ? &a->cview[k] : &z, b->has_cview[k] ? &b->cview[k] : &z)) { g_rt_diff = "cview"; return 0; } }
|
||||
}
|
||||
g_rt_diff = NULL; return 1;
|
||||
}
|
||||
// Slice-merged passes (see g_sm_plan). sm_rt_slice: b names the same single colour target as a (one colour attachment in slot 0, no depth / stencil, the same texture and view)
|
||||
// except the view's first layer, which goes to *slice
|
||||
static int sm_on(void) { static int m = -1; if (m < 0) { const char *e = getenv("DM_NVN_SLICE_MERGE"); m = !(e && !strcmp(e, "0")); if (!m) MLOG("DM_NVN_SLICE_MERGE=0: passes into other layers of one texture level stay apart"); } return m; }
|
||||
@@ -13200,7 +13224,7 @@ static int sm_scan(const uint8_t *p, const p_set_rt *rt, int cur, int *lo, int *
|
||||
}
|
||||
// The draw about to open a pass: plan it as slice-merged when its target is one layer of an array or cube texture level and the next targets switch to other layers of that level
|
||||
// (every layer between the lowest and the highest drawn into), and the draw's amplified pipeline is built (else it is queued, and this pass stays as it is)
|
||||
static int draw_samples_rt(NvProg *pr);
|
||||
static int draw_samples_rt(NvProg *pr); static int fb_mode(void); static int fb_depth_on(void);
|
||||
static void sm_plan(NvProg *pr) {
|
||||
g_sm_plan.on = 0;
|
||||
if (!pr || !pr->sh[0] || pr->sh[0]->layer_out || R.clear_d || R.clear_s || draw_samples_rt(pr)) return;
|
||||
@@ -13225,25 +13249,43 @@ static int tex_storage_overlap(const tex_t *a, const tex_t *b) {
|
||||
return (x < y + b->L.size && y < x + a->L.size) || nvn_sparse_alias(x, x + a->L.size) || nvn_sparse_alias(y, y + b->L.size);
|
||||
}
|
||||
static int g_samples_fb_left; // draw_samples_rt: a fragment texture that is a colour attachment does not count: fb_prepare answers for it, as for any draw of a pass
|
||||
static int draw_samples_rt(NvProg *pr) { // Sampled attachments keep the original conservative ser-level guard, not split by level/layer
|
||||
uint64_t rs[9]; int nr = 0;
|
||||
for (int k = 0; k < R.rt.n && k < 8; k++) if (R.rt.color[k]) rs[nr++] = R.rt.color[k]->serial;
|
||||
if (R.rt.depth) rs[nr++] = R.rt.depth->serial;
|
||||
if (!pr) return 1;
|
||||
static const char *g_dsr_why; // what draw_samples_rt found (the pass dump's split line)
|
||||
#define DSR(w) do { g_dsr_why = (w); return 1; } while (0)
|
||||
static int draw_samples_rt(NvProg *pr) { // Keep storage-alias guards for resolved handles as well as ordinary slots
|
||||
g_dsr_why = NULL;
|
||||
if (!pr) DSR("noprog");
|
||||
for (int st = 0; st < 5; st++) { __unsafe_unretained NvShader *sh = pr->sh[st]; if (!sh) continue;
|
||||
if (sh->rf.bindless || sh->rf.dyn) return 1;
|
||||
for (int i = 0; i < sh->rf.nb; i++) { const nvn_rbind *b = &sh->rf.b[i]; uint64_t h;
|
||||
if (b->kind == NVN_RB_TEXU || b->kind == NVN_RB_TEXD || b->kind == NVN_RB_TEXA) return 1;
|
||||
if (b->kind == NVN_RB_IMG) h = b->reg < 32 && sh->stage < 6 ? bound_img(sh->stage, b->reg) : 0; else if (b->kind == NVN_RB_TEX || b->kind == NVN_RB_TBUF) h = sh->stage < 6 ? bound_tex(sh->stage, b->reg) : 0; else continue;
|
||||
int tid = (int)(h & 0xfffff); if (!tid) continue;
|
||||
os_unfair_lock_lock(&g_rmu); tex_t t = tid < g_ntreg && g_treg[tid].ok ? g_treg[tid].t : (tex_t){0}; os_unfair_lock_unlock(&g_rmu);
|
||||
if (!t.serial) return 1;
|
||||
if (g_samples_fb_left && st == 1 && b->kind == NVN_RB_TEX) { int col = 0; for (int j = 0; j < R.rt.n && j < 8; j++) col |= R.rt.color[j] && R.rt.color[j]->serial == t.serial; if (col) continue; }
|
||||
for (int j = 0; j < nr; j++) if (t.serial == rs[j]) return 1;
|
||||
for (int j = 0; j < R.rt.n && j < 8; j++) if (tex_storage_overlap(&t, R.rt.color[j])) return 1;
|
||||
if (tex_storage_overlap(&t, R.rt.depth)) return 1; } }
|
||||
int handles = st == 1 && g_samples_fb_left && fb_mode() && unb_on();
|
||||
if (sh->rf.dyn || sh->rf.pool || (sh->rf.bindless && !handles)) DSR("unknown-handles");
|
||||
for (int i = 0; i < sh->rf.nb; i++) { const nvn_rbind *b = &sh->rf.b[i];
|
||||
// A raw/storage buffer can read an attachment's pool bytes, including a mirror written only at pass end. Preserve the old bindless fallback without a disjoint-range proof.
|
||||
if (sh->rf.bindless && (b->kind == NVN_RB_GMEM || b->kind == NVN_RB_SBUFP || b->kind == NVN_RB_SBUFU || b->kind == NVN_RB_SBUFQ)) DSR("bindless-buffer");
|
||||
// Tables, pool reads and uniform image/buffer handles have no complete attachment proof here. Keep the original split.
|
||||
if (b->kind == NVN_RB_TEXD || b->kind == NVN_RB_TEXA || b->kind == NVN_RB_TEXH || b->kind == NVN_RB_TEXP || b->kind == NVN_RB_IMGU || b->kind == NVN_RB_TBUFU) DSR("unknown-binding");
|
||||
int texu = b->kind == NVN_RB_TEXU;
|
||||
if (texu && !handles) DSR("texu");
|
||||
if (!texu && b->kind != NVN_RB_IMG && b->kind != NVN_RB_TEX && b->kind != NVN_RB_TBUF) continue;
|
||||
for (int k = 0, n = texu && b->n ? b->n : 1; k < n; k++) {
|
||||
uint64_t h = texu ? 0 : b->kind == NVN_RB_IMG ? (b->reg < 32 && sh->stage < 6 ? bound_img(sh->stage, b->reg) : 0) : (sh->stage < 6 ? bound_tex(sh->stage, b->reg) : 0);
|
||||
int tid = texu ? ubo_tex_id(b->n ? ubo_handle(1, b->reg, b->off + 8 * k) : ubo_bind_handle(1, b)) : (int)(h & 0xfffff);
|
||||
if (!tid) continue; // an unbound handle reads the dummy, as in encode_args
|
||||
os_unfair_lock_lock(&g_rmu); tex_t t = tid < g_ntreg && g_treg[tid].ok ? g_treg[tid].t : (tex_t){0}; os_unfair_lock_unlock(&g_rmu);
|
||||
if (!t.serial) DSR("unreg");
|
||||
// Ordinary fragment slots' colour feedback uses fb_prepare. A uniform handle naming colour stays conservative.
|
||||
int colour_slot = 0;
|
||||
for (int j = 0; j < R.rt.n && j < 8; j++) if (R.rt.color[j]) {
|
||||
if (g_samples_fb_left && st == 1 && b->kind == NVN_RB_TEX && R.rt.color[j]->serial == t.serial) colour_slot = 1;
|
||||
else if (tex_storage_overlap(&t, R.rt.color[j])) DSR("color-alias");
|
||||
}
|
||||
if (colour_slot) continue;
|
||||
if (R.rt.depth && R.rt.depth->serial == t.serial && handles && fb_depth_on() && (texu || b->kind == NVN_RB_TEX)) continue; // fb_depth_rule orders the read against earlier/later writes
|
||||
if (tex_storage_overlap(&t, R.rt.depth)) DSR("depth-alias");
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#undef DSR
|
||||
// The whole render pass's need for depth / stencil (bits: 1 depth 2 stencil; 3 = both needed or cannot be proven). Starting from the draw that opens the render pass, scan in real replay order to the end of the render pass:
|
||||
// the attached clears and this draw's state are counted first; later draws accumulate by their depth-stencil state; anything unprovable such as a mid-pass clear or nesting too deep is treated as both needed
|
||||
// Pure-clear render pass hoisting: when a render pass is opened, scan forward, and if the shape is "several draws of this render pass -> several groups (SetRenderTargets + only clears) -> back to the same targets as this render pass",
|
||||
@@ -14616,7 +14658,7 @@ static void draw_(const p_draw *dw, const p_draw_idx *di) {
|
||||
g_samples_fb_left = 1;
|
||||
int rt_sampled = g_rt_merged && draw_samples_rt(pr); g_samples_fb_left = 0;
|
||||
if (rt_sampled) { static int once; if (!once++) MLOG("same-target continuation: a draw in the continued pass samples an attachment; split here (first case pass %llu)", g_stat_pass);
|
||||
PD("M %llu a draw in the continued pass samples an attachment; split here", g_stat_pass); rp_end(); }
|
||||
PD("M %llu a draw in the continued pass samples an attachment (%s); split here", g_stat_pass, g_dsr_why ?: "?"); { static int nw; if (nw++ < 6) MLOG("continued pass split: %s (pass %llu)", g_dsr_why ?: "?", g_stat_pass); } rp_end(); }
|
||||
order_draw(pr, g_sm_pass); // a write after an ordering barrier in the pass
|
||||
if (g_enc && g_vis_counting && g_vis_need && g_vis_n >= VIS_SLOTS) rp_end(); // this draw's query needs a slot and the buffer is bound for the whole pass: the next pass begins with a new one (rp_begin_ex)
|
||||
if (g_enc && g_rp_aw && (!R.has_sc || (long)R.sc.x + R.sc.w > (long)g_rp_aw || (long)R.sc.y + R.sc.h > (long)g_rp_ah)) rp_end(); // leaves the pass's render area
|
||||
@@ -16300,6 +16342,15 @@ static void clear_ds_tri(const p_clear_ds *c) {
|
||||
(unsigned long)sc.x, (unsigned long)sc.y, (unsigned long)sc.width, (unsigned long)sc.height);
|
||||
}
|
||||
|
||||
static int unb_keeps(uint32_t op) { // state an open pass carries over to the targets set again (see g_unb)
|
||||
switch (op) {
|
||||
case OP_SET_RT: case OP_VIEWPORTS: case OP_SCISSOR: case OP_DEPTH_RANGE: case OP_BIND_PROGRAM: case OP_BIND_STATE: case OP_BIND_VATTR: case OP_BIND_VSTREAM: case OP_BIND_VBUF: case OP_BIND_VBUF1:
|
||||
case OP_BIND_UBO: case OP_BIND_UBO_SMALL: case OP_BIND_SSBO: case OP_BIND_TEX: case OP_BIND_TEX1: case OP_BIND_SAMP: case OP_BIND_IMG: case OP_STENCIL: case OP_POLY_OFFSET: case OP_BLEND_COLOR:
|
||||
case OP_ALPHA_REF: case OP_PUSH_CONST: case OP_DEPTH_CLAMP: case OP_PATCH_SIZE: case OP_LINE_WIDTH: case OP_VP_SWIZZLE: case OP_PRIM_RESTART: case OP_RAST_DISCARD: case OP_SET_TEX_POOL:
|
||||
case OP_SET_SAMP_POOL: case OP_JUMP: case OP_CALL: return 1;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
void mtl_exec(const uint8_t *p) {
|
||||
if (!g_state_inited) state_reset();
|
||||
static int dump_all = -1; if (dump_all < 0) dump_all = getenv("DM_NVN_PASSDUMP_ALL") != NULL;
|
||||
@@ -16313,6 +16364,7 @@ void mtl_exec(const uint8_t *p) {
|
||||
if (g_allocprof == 2) { static int prev = -1; uint64_t now = g_alloc4[g_alloc_cur].allocatedSize; if (prev >= 0 && prev < 64 && now > g_cm_last) g_cm_op[prev] += now - g_cm_last; g_cm_last = now; prev = (int)h.op; if (h.op < 64) g_cm_opn[h.op]++; }
|
||||
if (g_allocprof) { static uint64_t last; static int prev = -1; uint64_t now = g_dev.currentAllocatedSize; if (prev >= 0 && prev < 64 && now > last) g_ap_bytes[prev] += now - last; last = now; prev = h.op; }
|
||||
const void *a = p + 8;
|
||||
if (g_unb && !unb_keeps(h.op) && !(h.op == OP_END && g_ret_n)) { PD("M %llu unbound targets land before op %u", g_stat_pass, (unsigned)h.op); rp_flush(); } // see g_unb
|
||||
if (g_nlc && !lc_keeps(h.op) && !(h.op == OP_END && g_ret_n)) lc_land(); // see lc_keeps (a sub-list's end returns to its caller)
|
||||
if (g_mrun.n && !geo_mesh_keeps(h.op) && !(h.op == OP_END && g_ret_n)) geo_mesh_flush(); // see geo_mesh_keeps
|
||||
switch (h.op) {
|
||||
@@ -16360,7 +16412,14 @@ void mtl_exec(const uint8_t *p) {
|
||||
case OP_SET_RT: {
|
||||
const p_set_rt *r = a; g_setrt_n++; g_split_resume = 0; // a split's resume is for its own pass only
|
||||
int pend = R.clear_d || R.clear_s; for (int i = 0; i < 8; i++) pend |= R.clear_c[i];
|
||||
{ int empty = !r->depth; for (int k = 0; k < r->n && k < 8; k++) if (r->color[k]) empty = 0;
|
||||
PD("M %llu set_rt n=%d depth=%d empty=%d enc=%d", g_stat_pass, r->n, !!r->depth, empty, !!g_enc);
|
||||
if (empty && g_enc && g_enc_mode != 1 && !pend && R.has_rt && rtc_on() && unb_on()) { if (!g_unb) { g_unb = 1; g_unb_rt = *r; } else g_unb_rt = *r;
|
||||
if (!g_unb_n++) MLOG("deferred unbind: first case pass %llu", g_stat_pass); break; }
|
||||
if (g_unb) g_unb = 0; } // targets again: compared with the open pass's below
|
||||
// Do not continue a render pass opened only for a clear; one with fewer depth / stencil attachments can be continued (check the planes before drawing)
|
||||
if (g_enc && g_enc_mode != 1 && !pend && R.has_rt && rtc_on() && r->n && !rt_same(&R.rt, r)) { static int nd; if (nd++ < 8) MLOG("same-target continuation refused (%s) pass %llu", g_rt_diff ?: "?", g_stat_pass); PD("M %llu new targets (%s)", g_stat_pass, g_rt_diff ?: "?"); }
|
||||
else if (g_enc && R.has_rt && r->n && (g_enc_mode == 1 || pend || !rtc_on()) && rt_same(&R.rt, r)) { static int nw; if (nw++ < 8) MLOG("same targets, no continuation: enc_mode=%d pend=%d rtc=%d pass %llu", g_enc_mode, pend, rtc_on(), g_stat_pass); }
|
||||
if (g_enc && g_enc_mode != 1 && !pend && R.has_rt && rtc_on() && r->n && rt_same(&R.rt, r)) { g_rt_merged = 1; if (!g_rt_merge_n++) MLOG("same-target continuation: first case pass %llu", g_stat_pass); PD("M %llu same-target continuation pass", g_stat_pass); R.rt = *r; break; }
|
||||
if (g_enc && g_sm_pass && !pend && !g_game_barrier) { int sl; // another layer of the slice-merged pass's level (sm_scan planned it)
|
||||
if (sm_rt_slice(&R.rt, r, &sl) && sl >= g_sm_lo && sl <= g_sm_hi) { R.rt = *r; g_sm_cur = sl; g_sm_ncont++;
|
||||
|
||||
@@ -27,6 +27,13 @@ FW=-framework Metal -framework MetalFX -framework Foundation -framework IOKit -f
|
||||
# Tests that #include nvn_mtl.m link the rest of the NVN layer beside it (hle_nvn.c: memory pools, sparse pools, serials) and the host's large stack, with weak stubs of what they need of the host (t_host_stubs.c)
|
||||
MTL_T_DEP=../nvn/hle_nvn.c ../../host/crash.c ../../host/hle_bigstack.c t_host_stubs.c $(GFX) $(GFX_H)
|
||||
MTL_T_SRC=../nvn/hle_nvn.c ../../host/crash.c ../../host/hle_bigstack.c t_host_stubs.c $(filter-out ../nvn/nvn_mtl.m,$(GFX))
|
||||
t_rt_unbind: t_rt_unbind.m $(MTL_T_DEP)
|
||||
clang $(CFLAGS) -fobjc-arc -o $@ t_rt_unbind.m $(MTL_T_SRC) $(FW)
|
||||
.PHONY: check_t_rt_unbind
|
||||
check_t_rt_unbind: t_rt_unbind
|
||||
MTL_DEBUG_LAYER=1 DM_NVN_ENC_THREAD=0 ./t_rt_unbind
|
||||
MTL_DEBUG_LAYER=1 DM_NVN_ENC_THREAD=1 ./t_rt_unbind
|
||||
MTL_DEBUG_LAYER=1 DM_NVN_UNBIND_DEFER=0 ./t_rt_unbind
|
||||
# The run list: every t_*.c and t_*.m but those in NOT_RUN. `make run` builds them all (in parallel with -j), then runs them one after another, each through its check_
|
||||
# target: ./t_x by default, with the environment its RUN_ENV gives it (check_t_x: RUN_ENV = MTL_DEBUG_LAYER=1, beside its build rule), or a check_t_x recipe of its own when it
|
||||
# runs several ways. A new test needs its source and its build rule; no list to add it to. NOT_RUN: helpers linked into other tests (t_host_stubs, t_present_rescue_focus, t_gpu_lost_front),
|
||||
|
||||
@@ -843,30 +843,44 @@ static void depth_snap_case(NvProg *pr) {
|
||||
}
|
||||
// A draw that samples the depth attachment after an earlier draw of its pass wrote depth, and writes none itself, ends the pass first (Red Dead Redemption's cloud fog); one that samples
|
||||
// it first in its pass leaves the pass open, and a later draw that writes depth then ends it (g_fb_dread)
|
||||
static void depth_after_write_case(NvProg *pr) {
|
||||
static void depth_rebind(NvProg *pr) {
|
||||
uint8_t ops[1024]={0}; size_t off=0; p_set_rt targets[2]={{0},R.rt};
|
||||
for (int i=0;i<2;i++) { op_hdr h={OP_SET_RT,8+sizeof(p_set_rt)}; memcpy(ops+off,&h,8); memcpy(ops+off+8,&targets[i],sizeof(p_set_rt)); off+=h.size; }
|
||||
op_hdr end={OP_END,8}; memcpy(ops+off,&end,8); mtl_exec(ops);
|
||||
CHECK(g_enc && g_rt_merged,"empty unbind/rebind preserves the open depth-feedback pass");
|
||||
g_samples_fb_left=1; CHECK(!draw_samples_rt(pr),"continued-pass guard hands exact depth reads to the depth feedback rule"); g_samples_fb_left=0;
|
||||
}
|
||||
static void depth_binding(int texu, int tid) { if (texu) g_ubo_words[0]=(uint32_t)tid; else S.tex[1][0]=(uint64_t)tid; }
|
||||
static void depth_after_write_case(NvProg *pr, int texu) {
|
||||
int before = failed; NvShader *fs = pr->sh[1]; fs->rf.b[0].reg = 0;
|
||||
tex_t output, depth; target(&output, 99940); target(&depth, 99941); mtl_reg_tex(654, &depth, NULL);
|
||||
state_reset(); memset(&R, 0, sizeof R); mtl_sub_begin();
|
||||
R.has_rt = 1; R.rt.n = 1; R.rt.color[0] = &output; S.chmask.mask = 0xffffffffu;
|
||||
clear(MTLClearColorMake(0, 0, 0, 1)); R.rt.depth = &depth;
|
||||
uint64_t splits = g_fb_dsplit;
|
||||
S.ds.dt = S.ds.dw = 1; S.tex[1][0] = 0;
|
||||
fs->rf.bindless=texu; fs->rf.b[0].kind=texu ? NVN_RB_TEXU : NVN_RB_TEX;
|
||||
if (texu) { fs->rf.b[0].reg=2; S.ubo[1][2]=(p_bind_buf){.addr=(uint64_t)(uintptr_t)g_ubo_words,.size=16}; }
|
||||
S.ds.dt = S.ds.dw = 1; depth_binding(texu,0);
|
||||
fb_prepare(pr);
|
||||
CHECK(g_enc && g_fb_dwrote && !g_fb_dread, "a draw that writes depth and samples nothing leaves the pass open");
|
||||
S.ds.dw = 0; S.tex[1][0] = 654;
|
||||
S.ds.dw = 0; depth_binding(texu,654); depth_rebind(pr);
|
||||
fb_prepare(pr);
|
||||
CHECK(!g_enc && g_fb_n == 0 && g_fb_dsplit == splits + 1, "a draw that samples the depth an earlier draw of its pass wrote ends the pass first");
|
||||
R.rt.depth = NULL; clear(MTLClearColorMake(0, 0, 0, 1)); R.rt.depth = &depth; // the pass that draw opens
|
||||
fb_prepare(pr);
|
||||
CHECK(g_enc && g_fb_dread && g_fb_dsplit == splits + 1, "one that samples it first in its pass reads it there");
|
||||
S.ds.dw = 1; S.tex[1][0] = 0;
|
||||
S.ds.dw = 1; depth_binding(texu,0); depth_rebind(pr);
|
||||
fb_prepare(pr);
|
||||
CHECK(!g_enc, "and a later draw that writes depth ends that pass");
|
||||
R.rt.depth = NULL; clear(MTLClearColorMake(0, 0, 0, 1)); R.rt.depth = &depth; g_fb_depth_m = 0;
|
||||
fb_prepare(pr); S.ds.dw = 0; S.tex[1][0] = 654;
|
||||
g_fb_pass=UINT64_MAX; R.rt.depth=NULL; clear(MTLClearColorMake(0,0,0,1)); R.rt.depth=&depth; S.ds.dw=0; depth_binding(texu,654); fb_prepare(pr);
|
||||
S.ds.st=1; S.ds.zpass_f=NVN_STENCIL_OP_REPLACE; S.st_wmask[0]=255; depth_binding(texu,0); depth_rebind(pr); fb_prepare(pr);
|
||||
CHECK(!g_enc,"a stencil writer after a depth read still ends the continued pass"); S.ds.st=0;
|
||||
g_fb_pass=UINT64_MAX; R.rt.depth = NULL; clear(MTLClearColorMake(0, 0, 0, 1)); R.rt.depth = &depth; g_fb_depth_m = 0;
|
||||
fb_prepare(pr); S.ds.dw = 0; depth_binding(texu,654);
|
||||
fb_prepare(pr);
|
||||
CHECK(g_enc && g_fb_dsplit == splits + 1, "with DM_NVN_FB_DEPTH=0 it reads it in the pass, as before");
|
||||
g_fb_depth_m = 1; R.rt.depth = NULL; S.ds.dt = S.ds.dw = 0; S.tex[1][0] = 0; rp_end();
|
||||
g_fb_depth_m = 1; R.rt.depth = NULL; S.ds.dt = S.ds.dw = 0; depth_binding(texu,0); rp_end();
|
||||
fs->rf.bindless=0; fs->rf.b[0].kind=NVN_RB_TEX; fs->rf.b[0].reg=0;
|
||||
CHECK(mtl_wait(mtl_sub_commit(), 5000000000ull) && !mtl_last_commit_error(), "that submission completed without error");
|
||||
mtl_tex_release(&output); mtl_tex_release(&depth);
|
||||
printf("depth after a write: %s\n", before == failed ? "PASS" : "FAIL");
|
||||
@@ -897,6 +911,7 @@ static void real_depth_snap_case(NvProg *pr, int colour_pass, int stencil, int p
|
||||
if (pending) CHECK(!g_enc, "no pass is open: the clear waits for the draw's pass");
|
||||
else if (colour_pass) clear(MTLClearColorMake(0, 0, 0, 1)); else CHECK(rp_begin() != nil, "production depth-only render pass opens");
|
||||
uint64_t copies = g_fb_dsnaps;
|
||||
if (colour_pass && !pending) depth_rebind(pr);
|
||||
fb_prepare(pr);
|
||||
id<MTLTexture> snap = g_fb_n == 1 ? g_fb_use[0] : nil;
|
||||
CHECK(!g_enc && snap && snap != dt && snap.pixelFormat == dt.pixelFormat && g_fb_dsnaps == copies + 1,
|
||||
@@ -964,11 +979,12 @@ int main(int argc, char **argv) { @autoreleasepool {
|
||||
id<MTLRenderPipelineState> pipeline = [g_dev newRenderPipelineStateWithDescriptor:d error:&error];
|
||||
CHECK(pipeline != nil, "synthetic render pipeline compiles");
|
||||
if (!pipeline) { fprintf(stderr, "%s\n", error.localizedDescription.UTF8String); return 1; }
|
||||
if (posix_memalign((void **)&g_ubo_words, getpagesize(), getpagesize())) abort(); memset(g_ubo_words, 0, getpagesize()); mtl_pool_add(g_ubo_words, getpagesize());
|
||||
const int slots[] = {0, 128, 255};
|
||||
for (int i = 0; i < 3; i++) slot_case(pr, pipeline, slots[i], i);
|
||||
reuse_case(pr);
|
||||
depth_snap_case(pr);
|
||||
depth_after_write_case(pr);
|
||||
depth_after_write_case(pr,0); depth_after_write_case(pr,1);
|
||||
for (int pending = 0; pending < 2; pending++) for (int stencil = 0; stencil < 2; stencil++) { real_depth_snap_case(pr, 1, stencil, pending); real_depth_snap_case(pr, 0, stencil, pending); }
|
||||
pending_clear_case(pr);
|
||||
shape_case();
|
||||
@@ -977,7 +993,6 @@ int main(int argc, char **argv) { @autoreleasepool {
|
||||
mip_pixels_case(lib);
|
||||
base_level_case(lib, 0, 1, 0, 0); base_level_case(lib, 1, 2, 1, 0); base_level_case(lib, 0, 2, 2, 1); base_level_case(lib, 0, 2, 3, 2);
|
||||
// A texture named by one handle in a uniform buffer (FINAL FANTASY XII THE ZODIAC AGE's limit-break echo): before fb_prepare took TEXU bindings, the draw read the attachment itself
|
||||
if (posix_memalign((void **)&g_ubo_words, getpagesize(), getpagesize())) abort(); memset(g_ubo_words, 0, getpagesize()); mtl_pool_add(g_ubo_words, getpagesize());
|
||||
fs->rf.b[0] = (nvn_rbind){.kind=NVN_RB_TEXU, .aid=0, .dtt=MTLTextureType2D}; slot_case(pr, pipeline, 2, 4);
|
||||
fs->rf.b[0] = (nvn_rbind){.kind=NVN_RB_TEX, .aid=0, .dtt=MTLTextureType2D};
|
||||
fs->fn = [lib newFunctionWithName:@"mask"];
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
// Empty target bindings are state, not work. Exercise real replay/pass stores and
|
||||
// pixel readback, plus the conservative attachment proof for uniform handles.
|
||||
#include "../nvn/nvn_mtl.m"
|
||||
void *front_metal_layer(void) { return NULL; }
|
||||
module_t *module_of(const void *p) { (void)p; return NULL; }
|
||||
module_t *g_mod; int g_nmod;
|
||||
void svc_thread_dump(void) {}
|
||||
uint64_t now_ns(void) { return bp_now(); }
|
||||
static int checks, failed;
|
||||
#define CHECK(c, label) do { checks++; if (!(c)) { failed++; fprintf(stderr, "FAIL: %s\n", label); } } while (0)
|
||||
typedef struct { uint8_t p[8192]; size_t n; } chain;
|
||||
static void emit(chain *c, unsigned op, const void *a, size_t n) {
|
||||
size_t size = (8 + n + 7) & ~7ull; if (c->n + size > sizeof c->p) abort();
|
||||
op_hdr h = {op, (uint32_t)size}; memcpy(c->p + c->n, &h, 8);
|
||||
if (n) memcpy(c->p + c->n + 8, a, n); c->n += size;
|
||||
}
|
||||
static tex_t texture(uint64_t serial) {
|
||||
tex_t t = {.magic=MAGIC('T','E','X',0), .serial=serial, .off=(int64_t)serial<<20};
|
||||
t.d = (nvn_texdesc){.target=NVN_TEXTURE_TARGET_2D, .format=NVN_FORMAT_RGBA8, .width=8, .height=8, .depth=1, .levels=1, .samples=1};
|
||||
nvn_tex_layout(&t.d, &t.L); return t;
|
||||
}
|
||||
static void triangle(chain *c) { p_draw d = {.prim=NVN_DRAW_PRIMITIVE_TRIANGLES, .count=3, .instances=1}; emit(c, OP_DRAW, &d, sizeof d); }
|
||||
static void run(chain *c) {
|
||||
emit(c, OP_END, NULL, 0); state_reset(); memset(&R, 0, sizeof R);
|
||||
mtl_sub_begin(); mtl_exec(c->p); mtl_sub_commit(); mtl_drain();
|
||||
CHECK(!mtl_last_commit_error(), "submission has no GPU error");
|
||||
CHECK(!g_unb, "submission leaves no deferred unbind");
|
||||
}
|
||||
static void pixels(tex_t *t, int red, int green, const char *label) {
|
||||
id<MTLTexture> mt = tex_mtl(t);
|
||||
id<MTLBuffer> b = [g_dev newBufferWithLength:2048 options:MTLResourceStorageModeShared];
|
||||
CHECK(mt && b, "readback resources allocate"); if (!mt || !b) return;
|
||||
id<MTLCommandQueue> q = [g_dev newCommandQueue]; id<MTLCommandBuffer> cb = [q commandBuffer];
|
||||
id<MTLBlitCommandEncoder> en = [cb blitCommandEncoder];
|
||||
[en copyFromTexture:mt sourceSlice:0 sourceLevel:0 sourceOrigin:MTLOriginMake(0,0,0) sourceSize:MTLSizeMake(8,8,1) toBuffer:b destinationOffset:0 destinationBytesPerRow:256 destinationBytesPerImage:2048];
|
||||
[en endEncoding]; [cb commit]; [cb waitUntilCompleted];
|
||||
int ok = cb.status == MTLCommandBufferStatusCompleted;
|
||||
for (int y=0; y<8; y++) for (int x=0; x<8; x++) { const uint8_t *p=(const uint8_t *)b.contents+y*256+x*4; ok &= p[0]==red && p[1]==green && p[2]==0 && p[3]==255; }
|
||||
CHECK(ok, label);
|
||||
}
|
||||
static void identity(tex_t *t) {
|
||||
p_set_rt a = {.n=1}, b; a.color[0]=t; b=a;
|
||||
b.n=8; b.has_cview[0]=1; b.cview[0]=(view_t){.base_level=7, .min_layer=9, .format=123, ._rsv=0xffff};
|
||||
CHECK(rt_same(&a,&b), "inactive view fields and trailing empty slots do not change the binding");
|
||||
b.cview[0].set_levels=1; b.cview[0].base_level=1;
|
||||
CHECK(!rt_same(&a,&b), "a different selected mip ends the pass");
|
||||
b=a; b.has_cview[0]=a.has_cview[0]=1;
|
||||
a.cview[0]=(view_t){.set_layers=1, .min_layer=0, .nlayers=1}; b.cview[0]=a.cview[0]; b.cview[0].min_layer=1;
|
||||
CHECK(!rt_same(&a,&b), "a different selected layer ends the pass");
|
||||
b=a; b.cview[0].set_format=1; b.cview[0].format=NVN_FORMAT_RGBA8_SRGB;
|
||||
CHECK(!rt_same(&a,&b), "a different selected format ends the pass");
|
||||
}
|
||||
static void replay(prog_t *pg, prog_t *green_pg, tex_t *t, tex_t *copy) {
|
||||
void *mem=NULL; if (posix_memalign(&mem,getpagesize(),getpagesize())) abort(); memset(mem,0,getpagesize()); mtl_pool_add(mem,getpagesize());
|
||||
p_set_rt rt={.n=1}, empty={0}; rt.color[0]=t;
|
||||
p_bind_program bind={pg,3}; p_clear_color green={0,0xf,{0,1,0,1}};
|
||||
// Warm the demanded pipeline before asserting the number of actual passes.
|
||||
chain warm={0}; emit(&warm,OP_SET_RT,&rt,sizeof rt); emit(&warm,OP_BIND_PROGRAM,&bind,sizeof bind); triangle(&warm); run(&warm);
|
||||
for (int kind=0; kind<8; kind++) {
|
||||
chain c={0}; emit(&c,OP_SET_RT,&rt,sizeof rt); emit(&c,OP_BIND_PROGRAM,&bind,sizeof bind); triangle(&c);
|
||||
emit(&c,OP_SET_RT,&empty,sizeof empty);
|
||||
// Repeated empty binds and sub-list returns may carry state to the rebind.
|
||||
if (kind==0) { chain sub={0}; emit(&sub,OP_SET_RT,&empty,sizeof empty); emit(&sub,OP_END,NULL,0); uint64_t ptr=(uint64_t)(uintptr_t)sub.p;
|
||||
emit(&c,OP_CALL,&ptr,8); emit(&c,OP_SET_RT,&rt,sizeof rt); triangle(&c);
|
||||
uint64_t before=g_stat_pass; run(&c);
|
||||
CHECK(g_stat_pass-before==(rtc_on() && unb_on() ? 1 : 2), "state-only unbind/rebind continues exactly one pass");
|
||||
pixels(t,255,0,"continued pass stores all red pixels"); continue; }
|
||||
if (kind==1) { uint32_t bits=~0u; emit(&c,OP_BARRIER,&bits,4); }
|
||||
if (kind==2) { p_copy_t2t cp={.src=t,.dst=copy,.sr={0,0,0,8,8,1},.dr={0,0,0,8,8,1}}; emit(&c,OP_COPY_T2T,&cp,sizeof cp); }
|
||||
if (kind==3) { run(&c); CHECK(!R.rt.n && !R.rt.depth,"end of submission applies empty binding"); pixels(t,255,0,"unbind at end stores old attachment"); continue; }
|
||||
if (kind==4) { p_set_rt other={.n=1}; other.color[0]=copy; emit(&c,OP_SET_RT,&other,sizeof other); emit(&c,OP_CLEAR_COLOR,&green,sizeof green); run(&c);
|
||||
pixels(t,255,0,"different target preserves the old pass"); pixels(copy,0,255,"different target receives its own clear"); continue; }
|
||||
if (kind==5) { p_bind_program gb={green_pg,3}; emit(&c,OP_BIND_PROGRAM,&gb,sizeof gb); triangle(&c); run(&c);
|
||||
CHECK(!R.rt.n && !R.rt.depth,"draw itself applies the empty binding"); pixels(t,255,0,"unbound green draw cannot change the previous red target"); continue; }
|
||||
if (kind==7) { uint64_t update[3]={(uint64_t)(uintptr_t)mem,8,73}; emit(&c,OP_UPDATE_UB,update,sizeof update); }
|
||||
emit(&c,OP_SET_RT,&rt,sizeof rt);
|
||||
if (kind==6) emit(&c,OP_CLEAR_COLOR,&green,sizeof green); else triangle(&c);
|
||||
uint64_t before=g_stat_pass; run(&c);
|
||||
CHECK(g_stat_pass-before>=2,"barrier/copy/clear or unbound draw prevents accidental continuation");
|
||||
pixels(t,kind==6?0:255,kind==6?255:0,"ordered clear/draw has the expected pixels");
|
||||
if (kind==2) pixels(copy,255,0,"copy after an empty binding sees the stored render target");
|
||||
if (kind==7) CHECK(*(uint64_t *)mem==73,"inline update after empty binding reaches memory in order");
|
||||
}
|
||||
mtl_pool_del(mem); free(mem);
|
||||
}
|
||||
static void handles(tex_t *t) {
|
||||
void *mem=NULL; if (posix_memalign(&mem,getpagesize(),getpagesize())) abort(); memset(mem,0,getpagesize()); mtl_pool_add(mem,getpagesize());
|
||||
state_reset(); memset(&R,0,sizeof R); R.rt.n=1; R.rt.color[0]=t;
|
||||
NvProg *pr=[NvProg new]; pr->sh[1]=[NvShader new]; NvShader *fs=pr->sh[1]; fs->stage=1; fs->rf.bindless=1; fs->rf.nb=1;
|
||||
fs->rf.b[0]=(nvn_rbind){.kind=NVN_RB_TEXU,.reg=2};
|
||||
S.ubo[1][2]=(p_bind_buf){.addr=(uint64_t)(uintptr_t)mem,.size=16};
|
||||
tex_t independent=texture(882002), alias=texture(882003); alias.mem=(uint8_t *)mem+128; alias.L.size=128; t->mem=mem; t->L.size=256;
|
||||
mtl_reg_tex(601,t,NULL); mtl_reg_tex(602,&independent,NULL); mtl_reg_tex(603,&alias,NULL);
|
||||
g_samples_fb_left=1;
|
||||
*(uint32_t *)mem=602;
|
||||
CHECK(!draw_samples_rt(pr),"resolved nonattachment fragment handle permits continuation");
|
||||
*(uint32_t *)mem=601;
|
||||
CHECK(draw_samples_rt(pr),"uniform handle naming colour attachment splits");
|
||||
*(uint32_t *)mem=603;
|
||||
CHECK(draw_samples_rt(pr),"uniform handle to another serial with overlapping storage splits");
|
||||
*(uint32_t *)mem=699;
|
||||
CHECK(draw_samples_rt(pr),"unregistered uniform texture handle splits");
|
||||
int unknown[]={NVN_RB_TEXA,NVN_RB_TEXH,NVN_RB_TEXP,NVN_RB_IMGU,NVN_RB_TBUFU,NVN_RB_TEXD};
|
||||
for (unsigned i=0;i<sizeof unknown/sizeof *unknown;i++) { fs->rf.b[0].kind=unknown[i]; CHECK(draw_samples_rt(pr),"unsupported handle/table binding stays conservative"); }
|
||||
fs->rf.b[0].kind=NVN_RB_TEXU; fs->rf.pool=1; CHECK(draw_samples_rt(pr),"pool reflection stays conservative"); fs->rf.pool=0;
|
||||
fs->rf.dyn=1; CHECK(draw_samples_rt(pr),"dynamic reflection stays conservative"); fs->rf.dyn=0;
|
||||
*(uint32_t *)mem=602; fs->rf.nb=2;
|
||||
int buffers[]={NVN_RB_GMEM,NVN_RB_SBUFP,NVN_RB_SBUFU,NVN_RB_SBUFQ};
|
||||
for (unsigned i=0;i<sizeof buffers/sizeof *buffers;i++) { fs->rf.b[1]=(nvn_rbind){.kind=buffers[i]}; CHECK(draw_samples_rt(pr),"mixed bindless/raw buffer reads keep the pass-end storage mirror boundary"); }
|
||||
fs->rf.nb=1;
|
||||
R.rt.depth=&alias; R.rt.n=0; *(uint32_t *)mem=601;
|
||||
CHECK(draw_samples_rt(pr),"uniform handle to overlapping depth storage splits");
|
||||
g_samples_fb_left=0; CHECK(draw_samples_rt(pr),"slice merge retains the conservative handle guard");
|
||||
t->mem=NULL; mtl_pool_del(mem); free(mem);
|
||||
}
|
||||
int main(void) { @autoreleasepool {
|
||||
alarm(60); setvbuf(stdout,NULL,_IONBF,0); mtl_init();
|
||||
NSError *error=nil;
|
||||
id<MTLLibrary> lib=[g_dev newLibraryWithSource:@"#include <metal_stdlib>\nusing namespace metal;\nvertex float4 v(uint i [[vertex_id]]) { float2 p[3]={float2(-1,-1),float2(3,-1),float2(-1,3)}; return float4(p[i],0,1); }\nfragment float4 red() { return float4(1,0,0,1); }\nfragment float4 green() { return float4(0,1,0,1); }\n" options:nil error:&error];
|
||||
if (!lib) { fprintf(stderr,"%s\n",error.localizedDescription.UTF8String); return 2; }
|
||||
prog_t pg={.serial=882000}; NvProg *pr=[NvProg new]; pr->sh[0]=[NvShader new]; pr->sh[1]=[NvShader new];
|
||||
pr->sh[0]->fn=[lib newFunctionWithName:@"v"]; pr->sh[0]->stage=0;
|
||||
pr->sh[1]->fn=[lib newFunctionWithName:@"red"]; pr->sh[1]->stage=1; pr->sh[1]->rf.color_known=1; pr->sh[1]->rf.color_mask=1; serial_put(pg.serial,pr);
|
||||
prog_t green_pg={.serial=882005}; NvProg *gp=[NvProg new]; gp->sh[0]=pr->sh[0]; gp->sh[1]=[NvShader new];
|
||||
gp->sh[1]->fn=[lib newFunctionWithName:@"green"]; gp->sh[1]->stage=1; gp->sh[1]->rf.color_known=1; gp->sh[1]->rf.color_mask=1; serial_put(green_pg.serial,gp);
|
||||
tex_t t=texture(882001), cp=texture(882004); identity(&t); replay(&pg,&green_pg,&t,&cp);
|
||||
if (unb_on()) handles(&t);
|
||||
mtl_tex_release(&t); mtl_tex_release(&cp);
|
||||
printf("render target unbind: %d checks, %d failed\n",checks,failed); return failed!=0;
|
||||
} }
|
||||
@@ -913,6 +913,7 @@ One line per symptom in the [subsystem references](../reference/): what you see
|
||||
- in handheld mode the picture fills only two thirds of the screen's width and height, in the bottom-left corner (the top-left with the upper-left origin), the rest black. → [The NVN present crops by the vi layer crop](../reference/rendering.md#the-nvn-present-crops-by-the-vi-layer-crop)
|
||||
- a scene turns narrow, with black bars at its sides, while the swapchain or window textures keep their size; circles come out as tall ovals. The log has `vi::SetLayerCrop 0,0 1200x960` and `present upscaling: ... 1200x960 → 1800x1440` in a 2560x1440 window. → [A crop only picks texels; the picture has the layer's shape](../reference/rendering.md#a-crop-only-picks-texels-the-picture-has-the-layers-shape)
|
||||
- one-draw passes on one target, hundreds of times a frame, with the same attachments each time (a `DM_NVN_GPUPROF` frame: `load` and `store` of the whole target in every line); a low frame rate that follows the target's size. → [Setting the same targets again continues the pass](../reference/rendering.md#setting-the-same-targets-again-continues-the-pass)
|
||||
- hundreds of one-draw passes loading and storing the same attachments; `same-target continuation: first case` never appears even though each draw uses the same targets. → [Empty target bindings between draws broke continuation](../reference/rendering.md#empty-target-bindings-between-draws-broke-continuation)
|
||||
- a pass on a very large target costs about the same however little it draws; `DM_NVN_GPUPROF` shows time proportional to the target's area. → [A render area for passes on very large targets](../reference/rendering.md#a-render-area-for-passes-on-very-large-targets)
|
||||
- `[RED] NVN unimplemented function called: nvnCommandBufferShadingRateImagePalette`, or `nvnCommandBufferBindShadingRateImage` or `nvnCommandBufferSetShadingRatePaletteMode`, every frame. → [Variable rate shading ignored](../reference/rendering.md#variable-rate-shading-ignored)
|
||||
- `regress.py` flagged Bastion as a REGRESSION on a screenshot (RGB difference about 30) whose game picture was the same on both sides: a strip beside the picture was black in some runs and purple (68, 34, 136) in others, on the baseline as well as the candidate. → [Screenshots of a cropped window held what lay outside the crop](../reference/rendering.md#screenshots-of-a-cropped-window-held-what-lay-outside-the-crop)
|
||||
|
||||
@@ -865,6 +865,14 @@ The replay on Metal (`dm/gfx/nvn/nvn_mtl.m`) and the Vulkan and OpenGL layers. E
|
||||
- **Found on:** [Splatoon Raiders](../../dm/games/0400380020056000/README.md): its ink map (6400x6400 RG8 with a Depth32F-S8) got about 150 one-draw occlusion queries a frame, each after setting the map again: 150 passes of about 1 ms, 42 GB of attachment loads a frame, about 6 fps. Without the depth rules its water came out in grey blocks of tiles: the water reads the scene's depth, then the next draw writes the water's own.
|
||||
- **Check:** `make -C dm/gfx/tests GAME=<id> check_t_feedback` (the depth attachment read, then written).
|
||||
|
||||
### Empty target bindings between draws broke continuation
|
||||
|
||||
- **Symptom:** hundreds of one-draw passes loading and storing the same attachments; `same-target continuation: first case` never appears even though each draw uses the same targets.
|
||||
- **Cause:** an empty `SetRenderTargets` ended the encoder before the next binding could match the open pass. View comparisons also counted reserved bytes, inactive fields and trailing empty color slots. The continued-pass sampling guard rejected every bindless shader, including handles that name no attachment.
|
||||
- **Fix:** general, `unb_keeps`, `rt_same` and `draw_samples_rt` in `nvn_mtl.m`. Defer an empty binding across state changes and sub-list calls/returns. A rebind compares against the open pass; work (including inline buffer updates), barriers and the submission's end first finalize the old pass and apply the empty binding. A different target bind ends the old pass normally. Compare only active view fields and ignore trailing empty color slots. Resolved fragment uniform texture handles retain serial, overlapping-storage and sparse-alias guards. Exact depth reads use the existing [depth feedback rule](#depth-sampled-in-the-pass-that-writes-it). Unknown handles, tables, pools, dynamic bindings, uniform image/buffer handles and other shader stages retain conservative splits. Mixed bindless shaders with raw/storage buffer access also split: attachment mirrors reach those pool bytes only at pass end, and their accesses have no disjoint-range proof here. `DM_NVN_UNBIND_DEFER=0` restores immediate empty-target unbinding. No cvar override or game-specific rule is involved.
|
||||
- **Check:** `check_t_rt_unbind` exercises real replay and GPU readback in both encoding modes and with deferral disabled: redundant/repeated empty bindings, sub-list return, changed targets, submission end, attachment-less draws, barriers, clears and texture copies, semantic view identity, resolved nonattachment handles, overlapping storage and unsupported handles. Existing `check_t_perf_order`, `check_t_feedback` and `check_t_lazy_clear_order` cover ordering, color/depth snapshots and lazy clears. The full graphics suite completed apart from an existing intermittent `t_counter_clock` precision assertion, reproduced on unchanged main. Two-game validation is recorded in [NieR Automata](../../dm/games/010056B015FE8000/README.md#status-on-the-mac) and [Octopath Traveler II](../../dm/games/0100A3501946E000/README.md#mac-routes); [Orbitals](../../dm/games/040032B023CA4000/README.md#frame-rate) records the remaining target-game validation.
|
||||
- **Found on:** [Orbitals](../../dm/games/040032B023CA4000/README.md#frame-rate), [issue #2806](https://github.com/seedds/nxnative/issues/2806). The game note records the reporter's measurements and the remaining validation. The issue's later depth/stencil-plane and vertex/depth-only extensions are separate, unvalidated proposals.
|
||||
|
||||
### A render area for passes on very large targets
|
||||
|
||||
- **Symptom:** a pass on a very large target costs about the same however little it draws; `DM_NVN_GPUPROF` shows time proportional to the target's area.
|
||||
|
||||
Reference in new issue
Block a user