mirror of
https://github.com/seedds/nxnative.git
synced 2026-11-23 11:39:42 -10:00
nvn: decouple handle checks from unbind deferral
Keep the continued-pass fragment texture-handle proof enabled when
DM_NVN_UNBIND_DEFER=0 restores immediate empty-target unbinding. The two
mechanisms are independent, including same-target binds with no empty bind
between them. Retain the stage, feedback and attachment-alias guards.
Run the handle assertions with deferral disabled too, add real replay and
GPU readback for a nonattachment handle, and cover both encoding modes in
both configurations. Clarify the independent controls in the reference.
Validation on Apple M6:
- New coverage: two failures before the guard correction; 77 checks pass
afterward in each of the four encoding/deferral configurations.
- Graphics suite completes successfully; two external reflection-sample
checks are skipped because their fixtures are unavailable.
- LLVM 23.1.4 targeted C lint has no new findings; documentation tests and
diff checks pass. No game regression, gameplay or iOS run.
Follow-up to d6b5fc1b and issue #2806. Orbitals' remaining gameplay and
performance validation stays open. Retain the original reporter's general
continuation and handle-resolution design.
Co-authored-by: settobox-crypto <[email protected]>
This commit is contained in:
1 parent
6c079578f3
commit
87422462a4
4 files changed
+29
-7
No files matched your search
@@ -13255,7 +13255,7 @@ static int draw_samples_rt(NvProg *pr) { // Keep storage-alias guards for reso
|
||||
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;
|
||||
int handles = st == 1 && g_samples_fb_left && fb_mode() && unb_on();
|
||||
int handles = st == 1 && g_samples_fb_left && fb_mode(); // The handle proof does not depend on deferring empty target binds.
|
||||
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.
|
||||
|
||||
@@ -33,7 +33,8 @@ t_rt_unbind: t_rt_unbind.m $(MTL_T_DEP)
|
||||
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
|
||||
MTL_DEBUG_LAYER=1 DM_NVN_ENC_THREAD=0 DM_NVN_UNBIND_DEFER=0 ./t_rt_unbind
|
||||
MTL_DEBUG_LAYER=1 DM_NVN_ENC_THREAD=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),
|
||||
|
||||
@@ -83,6 +83,27 @@ static void replay(prog_t *pg, prog_t *green_pg, tex_t *t, tex_t *copy) {
|
||||
}
|
||||
mtl_pool_del(mem); free(mem);
|
||||
}
|
||||
static void replay_handles(prog_t *red_pg, prog_t *green_pg, id<MTLLibrary> lib, NvShader *vs, tex_t *t, tex_t *source) {
|
||||
void *mem=NULL; if (posix_memalign(&mem,getpagesize(),getpagesize())) abort(); memset(mem,0,getpagesize()); mtl_pool_add(mem,getpagesize());
|
||||
*(uint32_t *)mem=602; mtl_reg_tex(602,source,NULL);
|
||||
prog_t pg={.serial=882006}; NvProg *pr=[NvProg new]; pr->sh[0]=vs; pr->sh[1]=[NvShader new]; NvShader *fs=pr->sh[1];
|
||||
fs->stage=1; fs->fn=[lib newFunctionWithName:@"read_tex"]; strcpy(fs->key,"rt-unbind-handles");
|
||||
fs->ae=[fs->fn newArgumentEncoderWithBufferIndex:0]; fs->arg_len=fs->ae.encodedLength;
|
||||
fs->rf.bindless=1; fs->rf.nb=1; fs->rf.color_known=1; fs->rf.color_mask=1;
|
||||
fs->rf.b[0]=(nvn_rbind){.kind=NVN_RB_TEXU,.reg=2,.aid=0,.dtt=MTLTextureType2D}; serial_put(pg.serial,pr);
|
||||
p_set_rt rt={.n=1}; rt.color[0]=source; p_bind_program bind={green_pg,3};
|
||||
chain init={0}; emit(&init,OP_SET_RT,&rt,sizeof rt); emit(&init,OP_BIND_PROGRAM,&bind,sizeof bind); triangle(&init); run(&init);
|
||||
rt.color[0]=t; bind.prog=&pg;
|
||||
p_bind_buf ub={.stage=1,.index=2,.addr=(uint64_t)(uintptr_t)mem,.size=16};
|
||||
chain warm={0}; emit(&warm,OP_SET_RT,&rt,sizeof rt); emit(&warm,OP_BIND_PROGRAM,&bind,sizeof bind); emit(&warm,OP_BIND_UBO,&ub,sizeof ub); triangle(&warm); run(&warm);
|
||||
// No empty bind: disabling unbind deferral must leave this handle proof and same-target continuation enabled.
|
||||
chain c={0}; bind.prog=red_pg; emit(&c,OP_SET_RT,&rt,sizeof rt); emit(&c,OP_BIND_PROGRAM,&bind,sizeof bind); triangle(&c);
|
||||
bind.prog=&pg; emit(&c,OP_SET_RT,&rt,sizeof rt); emit(&c,OP_BIND_PROGRAM,&bind,sizeof bind); emit(&c,OP_BIND_UBO,&ub,sizeof ub); triangle(&c);
|
||||
uint64_t before=g_stat_pass; run(&c);
|
||||
CHECK(g_stat_pass-before==(rtc_on() ? 1 : 2),"nonattachment uniform handle continues the same-target pass independently of unbind deferral");
|
||||
pixels(t,0,255,"continued draw reads the green nonattachment texture through its uniform handle");
|
||||
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;
|
||||
@@ -116,7 +137,7 @@ static void handles(tex_t *t) {
|
||||
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];
|
||||
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); }\nstruct A { texture2d<float,access::read> source [[id(0)]]; };\nfragment float4 read_tex(float4 p [[position]], constant A &a [[buffer(0)]]) { return a.source.read(uint2(p.xy)); }\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;
|
||||
@@ -124,7 +145,7 @@ int main(void) { @autoreleasepool {
|
||||
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);
|
||||
replay_handles(&pg,&green_pg,lib,pr->sh[0],&t,&cp); handles(&t);
|
||||
mtl_tex_release(&t); mtl_tex_release(&cp);
|
||||
printf("render target unbind: %d checks, %d failed\n",checks,failed); return failed!=0;
|
||||
} }
|
||||
@@ -868,9 +868,9 @@ The replay on Metal (`dm/gfx/nvn/nvn_mtl.m`) and the Vulkan and OpenGL layers. E
|
||||
### 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.
|
||||
- **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. Its handle proof initially also depended on `DM_NVN_UNBIND_DEFER`, so disabling deferral split eligible same-target draws even without an empty bind.
|
||||
- **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; it leaves the handle proof enabled when feedback snapshots are enabled (`DM_NVN_FB_SNAP`). The proof applies independently to same-target binds with no empty bind between them. No cvar override or game-specific rule is involved.
|
||||
- **Check:** `check_t_rt_unbind` exercises real replay and GPU readback in both encoding modes with deferral enabled and 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. A draw sampling a nonattachment through a uniform handle continues a same-target pass with no intervening empty bind, including with deferral disabled; the handle assertions also run in every configuration. Existing `check_t_perf_order`, `check_t_feedback` and `check_t_lazy_clear_order` cover ordering, color/depth snapshots and lazy clears. The correction's graphics suite completed successfully on Apple M6 (2026-11-17), with two reflection-sample checks skipped because their external fixtures were unavailable. The original change's 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
|
||||
|
||||
Reference in new issue
Block a user