nvn: publish buffer flushes and preserve API contracts (PR #1285)

BufferFlushMappedRange now publishes buffer-relative writes through the
existing pool flush tracking, including both offsets. Unified CPU memory
still has separate Metal texture mirrors that need this publication.

Retain nine missing builder queries, correct pointer-return signatures,
restore NVN defaults, and respect CPU mapping and physical-pool contracts.
Preserve main's existing getters, pool lifetime and texture retirement code.
Adapt the GPU regression to current command-list handles and keep its
negative control independent of automatic dirty-upload inference.

Checked: 460 API checks, 132 Metal texture/lifetime checks, docs/usage tests,
and C lint at its baseline. Restoring only the flush no-op fails exactly the
buffer-flush GPU readback. Full Cuphead and Breath of the Wild comparisons
against 2925d7af pass on M4 Pro, macOS 27.2.1, Xcode 27.2, with no changed
shaders, new diagnostics, interface failures or screenshot regressions.
No shader-chain change. No iOS device run.

Co-authored-by: Michael Straßburger <[email protected]>
This commit is contained in:
seeddsandMichael Straßburger committed 2026-11-17 23:47:29 +08:00
1 parent 1af88aad6f
commit fa2ed14d70
9 files changed
+305 -30

No files matched your search

+4
View File
@@ -179,6 +179,10 @@ On this Mac the background prewarm also ends before the save loads, so the step
`smoke.tsv` takes the outdoors save (`saves/outdoors` in the NSP folder) with frame-numbered presses, `f300:A` to `f1700:A`; the Zora's Domain save it used before is no longer on the test Mac. Link stands in a field from about 50 s; with the window on screen (M4 Pro) frame 3,000 comes at 57 s and 6,000 at 107 s, while a covered window runs at 20 fps ([covered windows](../../../docs/reference/frame-rate.md)). `regress.py capture` records frame 5000 for `regress.py replay`: noise up to about 150 pixels with 5d2bf73f; one capture at chain `a31235713eee` differed from every replay in 1,603 pixels, a rare live outcome of the depth-EQUAL variation (Frame capture and replay, under Open); later captures replay within 0 to 246 pixels. The current one (chain `f3ceca86cac5`, 2026-10-30): no replay of 8 equals the live frame, noise 122 pixels; 4 of 8 and 113 pixels in the one before. In 2 of 6 `regress.py check` runs on 2026-10-29 the game stayed at 20 fps from the start (frame 2500 not reached by 60 s: NEW-FAIL): the frame step went from 1 to 3 vsyncs at presents 12–15 on three late frames costing 0.02 vsyncs and never came back. Resolved (2026-10-30): the window was behind another one in those runs ([a game window another process starts opens behind other windows](../../../docs/reference/frame-rate.md#a-game-window-another-process-starts-opens-behind-other-windows)); every 20 fps run of 2026-10-28 and 29 had 21 to 115 display link stalls, the 60 fps runs 0 to 7. With `DM_WINDOW_TOP` the window stays in front.
### NVN contract validation (2026-11-17)
The general NVN builder, mapping and [buffer-flush contracts](../../../docs/reference/nvn-objects.md#buffer-flushes-publish-the-corresponding-pool-range) from PR #1285 passed the full 110-second outdoors route against main `2925d7af`. This game covers frequent pool/buffer mappings and explicit texture-storage flushes; the missing buffer-flush publication itself is isolated by synthetic GPU readback. All 19,592 shaders were unchanged, with no new interface failures, red diagnostics or screenshot regression. On an M4 Pro, macOS 27.2.1: 58.6 → 59.1 fps, frame p99 33.33 → 33.21 ms, peak footprint 3,179 → 3,218 MB. Both runs built all 15,767 pipeline pairs without failures (172.1 → 183.7 seconds). These results establish no regression, not a measured speedup. iOS was not rerun.
### Buffer-copy upload ordering validation (2026-11-17)
The general [buffer-copy storage visibility correction](../../../docs/reference/nvn-objects.md#buffer-copies-over-the-storage-of-textures-uploaded-from-it) (PR #2919) passed the full 110-second outdoors route against `9bd8bb38`: 19,592 shaders on both revisions, no new shader or interface failures, screenshots within the comparison tolerances (grass and trees move), and no new red diagnostics. On an M4 Pro, macOS 27.2.1, baseline → candidate: 57.4 → 58.6 fps, frame p99 33.50 → 33.34 ms, peak footprint 3,226 → 3,164 MB. After integrating main `3fe574df`, the 70-second quick comparison also passed: 55.5 → 56.4 fps, p99 33.44 → 33.46 ms, peak 3,187 → 3,203 MB. These pairs establish no regression, not a measured speedup. iOS was not rerun.
+1
View File
@@ -34,6 +34,7 @@ Update 1.3.7 (v655360) over the base game; its DLC (The Delicious Last Course) i
## Mac routes
- **NVN contract validation (2026-11-17, PR #1285):** the full 85-second map route passed against main `2925d7af`, covering Unity's pool/buffer access, builder state and texture uploads. Both revisions used the local build's derived profile; 3,131 shaders were unchanged, with no new red diagnostics or screenshot regression. On an M4 Pro, macOS 27.2.1: 59.6 → 59.7 fps, frame p99 17.19 → 17.16 ms, peak footprint 2,374 → 2,361 MB. This establishes no regression; the [buffer-flush defect](../../../docs/reference/nvn-objects.md#buffer-flushes-publish-the-corresponding-pool-range) is reproduced independently by GPU readback. iOS was not rerun.
- **Current host buffer-copy validation (2026-11-17, PR #2919):** [`smoke.tsv`](smoke.tsv) loads slot 1 from the existing map save and stands on Inkwell Isle One. The full 85-second comparison against `9bd8bb38` passed with 3,131 shaders on both revisions, no new red diagnostics or screenshot regression, and over 53,000 buffer-copy groups committed before later commands (none uncommittable). On an M4 Pro, macOS 27.2.1, baseline → candidate: 59.7 → 59.7 fps, frame p99 17.45 → 17.22 ms, peak footprint 2,354 → 2,359 MB. After integrating main `3fe574df`, the 60-second quick comparison also passed: 59.6 fps on both, p99 17.23 → 17.20 ms, peak 2,343 → 2,345 MB. These pairs establish no regression, not a measured speedup. Both revisions used the local build's derived profile, so this does not stamp the repository profile's `validated.tsv`; iOS was not rerun. The general mechanism and synthetic regressions are in [buffer copies over uploaded texture storage](../../../docs/reference/nvn-objects.md#buffer-copies-over-the-storage-of-textures-uploaded-from-it).
- A fresh save through the title (L+R), a new slot, the storybook and the house to the map (at about 160 s): `DM_KEYS="20:L+R,26:A,32:A,38:A,44:A,50:A,56:A*20/3,120:LRight~4,125:A,127:LRight~3,131:A*10/2,152:LLeft~3,155.5:A"`.
- From that save, across the bridge (its entry is narrow between the posts) into Forest Follies (play from about 68 s; Y shoots): `DM_KEYS="20:L+R,26:A,32:A,35:A,40:LRight~1.5,42:LDown~1.5,45:LRight~3,49:LUp~1,51:LRight~3,54.5:LLeft~0.5,55.2:LUp~0.25,55.6:LRight~2,58:LUp~0.2,58.4:LRight~0.25,58.8:LUp~0.2,59.2:LRight~0.25,59.6:LUp~0.2,60:LRight~0.25,60.4:LUp~0.2,61:A,63:A"`.
+37 -12
View File
@@ -131,6 +131,7 @@ HLE_FORCE("nvnBootstrapLoader", "the NVN graphics API is replaced wholesale with
// ---------- Device ----------
NVN(nvnDeviceBuilderSetDefaults, void, NVNdeviceBuilder *b) { memset(b, 0, sizeof(dev_builder_t)); }
NVN(nvnDeviceBuilderSetFlags, void, NVNdeviceBuilder *b, int f) { ((dev_builder_t *)b)->flags = f; }
NVN(nvnDeviceBuilderGetFlags, int, const NVNdeviceBuilder *b) { return (int)((const dev_builder_t *)b)->flags; }
NVN(nvnDeviceInitialize, NVNboolean, NVNdevice *d, const NVNdeviceBuilder *b) {
dev_t_ *o = (dev_t_ *)d; memset(o, 0, sizeof *o);
o->magic = MAGIC('D', 'E', 'V', 0); o->flags = ((const dev_builder_t *)b)->flags;
@@ -264,10 +265,23 @@ NVN(nvnDeviceFinalizeCommandHandle, void, NVNdevice *d, NVNcommandHandle h) { (v
NVN(nvnDeviceGenerateDebugDomainId, NVNdebugDomainId, const NVNdevice *d, const char *name) { static atomic_int next; (void)d; (void)name; return atomic_fetch_add(&next, 1) + 1; }
// ---------- Memory pools ----------
NVN(nvnMemoryPoolBuilderSetDefaults, void, NVNmemoryPoolBuilder *b) { memset(b, 0, sizeof(pool_builder_t)); }
NVN(nvnMemoryPoolBuilderSetDefaults, void, NVNmemoryPoolBuilder *b) {
// SetDefaults preserves SetDevice; NVN defaults to CPU_NO_ACCESS | GPU_CACHED.
pool_builder_t *o = (pool_builder_t *)b; o->mem = NULL; o->size = 0;
o->flags = NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS | NVN_MEMORY_POOL_FLAGS_GPU_CACHED;
}
NVN(nvnMemoryPoolBuilderSetDevice, void, NVNmemoryPoolBuilder *b, NVNdevice *d) { ((pool_builder_t *)b)->dev = d; }
NVN(nvnMemoryPoolBuilderSetStorage, void, NVNmemoryPoolBuilder *b, void *m, size_t n) { ((pool_builder_t *)b)->mem = m; ((pool_builder_t *)b)->size = n; }
NVN(nvnMemoryPoolBuilderSetFlags, void, NVNmemoryPoolBuilder *b, int f) { ((pool_builder_t *)b)->flags = f; }
NVN(nvnMemoryPoolBuilderGetDevice, NVNdevice *, const NVNmemoryPoolBuilder *b) { return ((const pool_builder_t *)b)->dev; }
NVN(nvnMemoryPoolBuilderGetMemory, void *, const NVNmemoryPoolBuilder *b) { return ((const pool_builder_t *)b)->mem; }
NVN(nvnMemoryPoolBuilderGetSize, size_t, const NVNmemoryPoolBuilder *b) { return (size_t)((const pool_builder_t *)b)->size; }
NVN(nvnMemoryPoolBuilderGetFlags, NVNmemoryPoolFlags, const NVNmemoryPoolBuilder *b) { return (NVNmemoryPoolFlags)((const pool_builder_t *)b)->flags; }
static uint8_t *pool_cpu_map(const pool_t *p) {
// A host address also represents GPU-only storage and virtual GPU ranges.
// Neither is a CPU mapping in NVN, even after a virtual pool aliases physical pages.
return (p->flags & (NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS | NVN_MEMORY_POOL_FLAGS_VIRTUAL)) ? NULL : p->mem;
}
static uint8_t *vpool_reserve(pool_t *o); static void vpool_release(pool_t *o); static void vpool_taken(const pool_t *o); // sparse virtual pools, see MapVirtual
NVN(nvnMemoryPoolInitialize, NVNboolean, NVNmemoryPool *p, const NVNmemoryPoolBuilder *b) {
const pool_builder_t *s = (const pool_builder_t *)b; pool_t *o = (pool_t *)p;
@@ -358,9 +372,10 @@ NVN(nvnSamplerPoolGetSize, int, const NVNsamplerPool *sp) { return ((const dpool
#define TB(b) ((tex_builder_t *)(b))
NVN(nvnTextureBuilderSetDefaults, void, NVNtextureBuilder *b) {
NVNdevice *dev = TB(b)->dev; memset(b, 0, sizeof(tex_builder_t)); TB(b)->dev = dev;
TB(b)->d.target = NVN_TEXTURE_TARGET_2D; TB(b)->d.width = TB(b)->d.height = TB(b)->d.depth = TB(b)->d.levels = 1;
TB(b)->d.target = NVN_TEXTURE_TARGET_2D; TB(b)->d.levels = 1; // dimensions remain unset (zero)
}
NVN(nvnTextureBuilderSetDevice, void, NVNtextureBuilder *b, NVNdevice *d) { TB(b)->dev = d; }
NVN(nvnTextureBuilderGetDevice, NVNdevice *, const NVNtextureBuilder *b) { return ((const tex_builder_t *)b)->dev; }
NVN(nvnTextureBuilderSetFlags, void, NVNtextureBuilder *b, int f) { TB(b)->d.flags = f; }
NVN(nvnTextureBuilderSetTarget, void, NVNtextureBuilder *b, NVNtextureTarget t) { TB(b)->d.target = t; }
NVN(nvnTextureBuilderSetWidth, void, NVNtextureBuilder *b, int v) { TB(b)->d.width = v; }
@@ -716,11 +731,12 @@ NVN(nvnTextureInvalidateTexels, void, const NVNtexture *t, const NVNtextureView
NVN(nvnSamplerBuilderSetDefaults, void, NVNsamplerBuilder *b) {
NVNdevice *dev = ((samp_builder_t *)b)->dev; memset(b, 0, sizeof(samp_builder_t)); ((samp_builder_t *)b)->dev = dev;
samp_par *o = SB(b);
o->minf = NVN_MIN_FILTER_NEAREST_MIPMAP_LINEAR; o->magf = NVN_MAG_FILTER_LINEAR; // GL defaults
o->minf = NVN_MIN_FILTER_LINEAR; o->magf = NVN_MAG_FILTER_LINEAR; // NVN defaults: no mip filtering
o->ws = o->wt = o->wr = NVN_WRAP_MODE_REPEAT; o->cmp_func = NVN_COMPARE_FUNC_LESS;
o->lod_min = -1000.f; o->lod_max = 1000.f; o->aniso = 1.f;
o->lod_min = 0.f; o->lod_max = 1000.f; o->aniso = 1.f;
}
NVN(nvnSamplerBuilderSetDevice, void, NVNsamplerBuilder *b, NVNdevice *d) { ((samp_builder_t *)b)->dev = d; }
NVN(nvnSamplerBuilderGetDevice, NVNdevice *, const NVNsamplerBuilder *b) { return ((const samp_builder_t *)b)->dev; }
NVN(nvnSamplerBuilderSetMinMagFilter, void, NVNsamplerBuilder *b, NVNminFilter mi, NVNmagFilter ma) { SB(b)->minf = mi; SB(b)->magf = ma; }
NVN(nvnSamplerBuilderSetWrapMode, void, NVNsamplerBuilder *b, NVNwrapMode s, NVNwrapMode t, NVNwrapMode r) { SB(b)->ws = s; SB(b)->wt = t; SB(b)->wr = r; }
NVN(nvnSamplerBuilderSetLodClamp, void, NVNsamplerBuilder *b, float lo, float hi) { SB(b)->lod_min = lo; SB(b)->lod_max = hi; }
@@ -1735,7 +1751,7 @@ NVN(nvnChannelMaskStateSetChannelMask, void, NVNchannelMaskState *s, int i, uint
uint32_t m = (B(r) ? 1 : 0) | (B(g) ? 2 : 0) | (B(b) ? 4 : 0) | (B(a) ? 8 : 0);
chmask_st *o = ST(chmask_st, s); o->mask = (o->mask & ~(0xfu << (4 * i))) | m << (4 * i);
}
NVN(nvnMultisampleStateSetDefaults, void, NVNmultisampleState *s) { memset(s, 0, sizeof(ms_st)); ST(ms_st, s)->enable = 1; }
NVN(nvnMultisampleStateSetDefaults, void, NVNmultisampleState *s) { memset(s, 0, sizeof(ms_st)); ST(ms_st, s)->enable = ST(ms_st, s)->a2c_dither = 1; }
NVN(nvnMultisampleStateSetMultisampleEnable, void, NVNmultisampleState *s, uint32_t e) { ST(ms_st, s)->enable = B(e) != 0; }
NVN(nvnMultisampleStateSetSamples, void, NVNmultisampleState *s, int n) { ST(ms_st, s)->samples = (uint8_t)n; }
NVN(nvnMultisampleStateSetAlphaToCoverageEnable, void, NVNmultisampleState *s, uint32_t e) { ST(ms_st, s)->a2c = B(e) != 0; }
@@ -2796,7 +2812,7 @@ NVN(nvnQueuePresentTexture, void, NVNqueue *q, NVNwindow *w, int idx) {
// They only read and write the object itself and record no commands. Where the host has no matching capability (texture channel swizzle, depth / stencil sampling mode, sampler reduction, virtual mapping) the first occurrence logs one line and the call returns normally.
#define ONCE_LOG(...) do { static int once_; if (!once_++) LOG("[nvn] " __VA_ARGS__); } while (0)
// Buffer object = pool + offset + size; the GPU address and the CPU mapping are both the pool's host pointer + offset (same convention as MemoryPoolGetBufferAddress)
// Buffer object = pool + offset + size; GPU addresses use the host pointer, while CPU mappings also require a CPU-accessible pool.
typedef struct { NVNdevice *dev; const pool_t *pool; int64_t off; uint64_t size; } buf_builder_t; FITS(buf_builder_t, NVNbufferBuilder);
// Guest ring allocators write offset/size directly at +0x18/+0x20 (issue #723).
// The intervening driver bytes have no host meaning; keep them reserved.
@@ -2807,9 +2823,13 @@ _Static_assert(offsetof(buf_t, size) == 0x20, "NVNbuffer guest size");
#define BF(b) ((const buf_t *)(b))
NVN(nvnBufferBuilderSetDefaults, void, NVNbufferBuilder *b) { NVNdevice *d = BB(b)->dev; memset(b, 0, sizeof(buf_builder_t)); BB(b)->dev = d; }
NVN(nvnBufferBuilderSetDevice, void, NVNbufferBuilder *b, NVNdevice *d) { BB(b)->dev = d; }
NVN(nvnBufferBuilderGetDevice, NVNdevice *, const NVNbufferBuilder *b) { return ((const buf_builder_t *)b)->dev; }
NVN(nvnBufferBuilderSetStorage, void, NVNbufferBuilder *b, NVNmemoryPool *p, ptrdiff_t off, size_t n) { BB(b)->pool = (const pool_t *)p; BB(b)->off = off; BB(b)->size = n; }
NVN(nvnBufferInitialize, NVNboolean, NVNbuffer *buf, const NVNbufferBuilder *b) {
const buf_builder_t *bb = (const buf_builder_t *)b;
memset(buf, 0, sizeof(buf_t));
// Physical pools supply pages to virtual pools; buffers must refer to ordinary or virtual pools.
if (bb->pool && (bb->pool->flags & NVN_MEMORY_POOL_FLAGS_PHYSICAL)) return 0;
if (!bb->pool || !bb->pool->mem) { LOG("[RED] BufferInitialize: pool has no storage (pool %p flags %#x offset %#llx size %#llx)", (const void *)bb->pool, bb->pool ? bb->pool->flags : 0, (unsigned long long)bb->off, (unsigned long long)bb->size); return 0; }
// The NVN driver does not check a buffer's range against its pool, and the host's own GPU access never goes by the buffer: it takes an address and a length from the command (mtl_addr resolves it
// in the pool's memory and reports a range that leaves the pool as its own red line). Breath of the Wild creates a 256 KB buffer over a 144 KB pool for a screen readback that feeds a
@@ -2826,16 +2846,20 @@ NVN(nvnBufferGetAddress, NVNbufferAddress, const NVNbuffer *buf) { vpool_taken(B
// A buffer or pool the CPU has no access to (NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS) maps to NULL, as in NVN, though the host's storage is CPU memory: EA SPORTS FC 27's Frostbite
// renderer takes a buffer's GPU address as GetAddress + (its data pointer − Map), with a null data pointer for such a buffer (OpcodeCopySubresource), so a real pointer made the
// copy's destination address 0 (FATAL buffer copy address is in no memory pool)
NVN(nvnBufferMap, void *, const NVNbuffer *buf) { if (BF(buf)->pool->flags & NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS) return NULL; vpool_taken(BF(buf)->pool); return BF(buf)->pool->mem + BF(buf)->off; }
NVN(nvnBufferMap, void *, const NVNbuffer *buf) { uint8_t *base = pool_cpu_map(BF(buf)->pool); return base ? base + BF(buf)->off : NULL; }
NVN(nvnBufferGetSize, size_t, const NVNbuffer *buf) { return (size_t)BF(buf)->size; }
NVN(nvnBufferGetMemoryPool, NVNmemoryPool *, const NVNbuffer *buf) { return (NVNmemoryPool *)BF(buf)->pool; }
NVN(nvnBufferGetMemoryOffset, ptrdiff_t, const NVNbuffer *buf) { return (ptrdiff_t)BF(buf)->off; }
NVN(nvnBufferFlushMappedRange, void, const NVNbuffer *buf, ptrdiff_t off, size_t n) { (void)buf; (void)off; (void)n; } // unified memory: nothing to flush
NVN(nvnBufferFlushMappedRange, void, const NVNbuffer *buf, ptrdiff_t off, size_t n) {
// Forward to the pool flush with both offsets. Unified memory still
// needs the host's flush tracking when a Metal texture mirrors this storage.
h_nvnMemoryPoolFlushMappedRange((const NVNmemoryPool *)BF(buf)->pool, BF(buf)->off + off, n);
}
NVN(nvnBufferInvalidateMappedRange, void, const NVNbuffer *buf, ptrdiff_t off, size_t n) { (void)buf; (void)off; (void)n; }
// Memory pool queries
NVN(nvnMemoryPoolGetFlags, NVNmemoryPoolFlags, const NVNmemoryPool *p) { return (NVNmemoryPoolFlags)((const pool_t *)p)->flags; }
NVN(nvnMemoryPoolMap, void *, const NVNmemoryPool *p) { if (((const pool_t *)p)->flags & NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS) return NULL; vpool_taken((const pool_t *)p); return ((const pool_t *)p)->mem; } // NULL without CPU access (nvnBufferMap)
NVN(nvnMemoryPoolMap, void *, const NVNmemoryPool *p) { return pool_cpu_map((const pool_t *)p); }
NVN(nvnMemoryPoolGetSize, size_t, const NVNmemoryPool *p) { return (size_t)((const pool_t *)p)->size; }
NVN(nvnMemoryPoolInvalidateMappedRange, void, const NVNmemoryPool *p, ptrdiff_t off, size_t n) { (void)p; (void)off; (void)n; }
NVN(nvnMemoryPoolSetDebugLabel, void, NVNmemoryPool *p, const char *s) { (void)p; (void)s; }
@@ -3198,9 +3222,9 @@ NVN(nvnMultisampleStateGetSampleLocationsGridEnable, NVNboolean, const NVNmultis
NVN(nvnBufferBuilderGetSize, size_t, const NVNbufferBuilder *b) { return (size_t)((const buf_builder_t *)b)->size; }
NVN(nvnBufferBuilderGetMemoryOffset, ptrdiff_t, const NVNbufferBuilder *b) { return (ptrdiff_t)((const buf_builder_t *)b)->off; }
// The storage set with SetStorage (EA SPORTS FC 27's Frostbite renderer reads it back from its texture builders before it initializes the textures). The pool getters return the
// pool's address, as nvnTextureGetMemoryPool does; the header the prototypes come from declares the builders' by value, so they get no signature check
NVN_NOPROTO(nvnBufferBuilderGetMemoryPool, NVNmemoryPool *, const NVNbufferBuilder *b) { return (NVNmemoryPool *)((const buf_builder_t *)b)->pool; }
NVN_NOPROTO(nvnTextureBuilderGetMemoryPool, NVNmemoryPool *, const NVNtextureBuilder *b) { return (NVNmemoryPool *)((const tex_builder_t *)b)->pool; }
// pool's address, as nvnTextureGetMemoryPool does. The texture/buffer queries return pool pointers.
NVN(nvnBufferBuilderGetMemoryPool, NVNmemoryPool *, const NVNbufferBuilder *b) { return (NVNmemoryPool *)((const buf_builder_t *)b)->pool; }
NVN(nvnTextureBuilderGetMemoryPool, NVNmemoryPool *, const NVNtextureBuilder *b) { return (NVNmemoryPool *)((const tex_builder_t *)b)->pool; }
NVN(nvnTextureBuilderGetMemoryOffset, ptrdiff_t, const NVNtextureBuilder *b) { return (ptrdiff_t)((const tex_builder_t *)b)->off; }
NVN_NOPROTO(nvnEventBuilderGetMemoryPool, NVNmemoryPool *, const NVNeventBuilder *b) { return (NVNmemoryPool *)((const ev_builder_t *)b)->pool; }
NVN_NOPROTO(nvnEventBuilderGetMemoryOffset, int64_t, const NVNeventBuilder *b) { return ((const ev_builder_t *)b)->off; }
@@ -3212,6 +3236,7 @@ NVN(nvnTextureBuilderGetLevels, int, const NVNtextureBuilder *b) { return (int)(
NVN(nvnTextureBuilderGetFormat, NVNformat, const NVNtextureBuilder *b) { return (NVNformat)((const tex_builder_t *)b)->d.format; }
NVN(nvnTextureBuilderGetSamples, int, const NVNtextureBuilder *b) { return ((const tex_builder_t *)b)->d.samples; }
NVN(nvnTextureBuilderGetStride, ptrdiff_t, const NVNtextureBuilder *b) { return (ptrdiff_t)((const tex_builder_t *)b)->d.stride; }
NVN(nvnTextureBuilderGetPackagedTextureData, const void *, const NVNtextureBuilder *b) { return ((const tex_builder_t *)b)->pkg_data; }
NVN(nvnTextureViewGetFormat, NVNboolean, const NVNtextureView *v, NVNformat *f) { const view_t *w = (const view_t *)v; if (f) *f = (NVNformat)w->format; return w->set_format; }
NVN(nvnTextureViewGetDepthStencilMode, NVNboolean, const NVNtextureView *v, NVNtextureDepthStencilMode *m) { const view_t *w = (const view_t *)v; if (m) *m = (NVNtextureDepthStencilMode)w->dsmode; return w->set_dsmode; }
NVN(nvnTextureViewGetSwizzle, NVNboolean, const NVNtextureView *v, NVNtextureSwizzle *r, NVNtextureSwizzle *g, NVNtextureSwizzle *b, NVNtextureSwizzle *a) {
+9 -3
View File
@@ -1119,6 +1119,8 @@ typedef void (*PFNNVNDEBUGCALLBACKPROC)(NVNdebugCallbackSource source, NVNdebugC
typedef void (*PFNNVNWALKDEBUGDATABASECALLBACKPROC)(void*, void*);
typedef void (*PFNNVNDEVICEBUILDERSETDEFAULTSPROC)(NVNdeviceBuilder*);
// Builder queries return storage and object pointers; see docs/reference/nvn-objects.md.
typedef int (*PFNNVNDEVICEBUILDERGETFLAGSPROC)(const NVNdeviceBuilder*);
typedef void (*PFNNVNDEVICEBUILDERSETFLAGSPROC)(NVNdeviceBuilder*, int);
typedef NVNboolean (*PFNNVNDEVICEINITIALIZEPROC)(NVNdevice*, const NVNdeviceBuilder*);
typedef void (*PFNNVNDEVICEFINALIZEPROC)(NVNdevice*);
@@ -1198,7 +1200,8 @@ typedef void (*PFNNVNMEMORYPOOLBUILDERSETDEVICEPROC)(NVNmemoryPoolBuilder*, NVNd
typedef void (*PFNNVNMEMORYPOOLBUILDERSETDEFAULTSPROC)(NVNmemoryPoolBuilder*);
typedef void (*PFNNVNMEMORYPOOLBUILDERSETSTORAGEPROC)(NVNmemoryPoolBuilder*, void*, size_t);
typedef void (*PFNNVNMEMORYPOOLBUILDERSETFLAGSPROC)(NVNmemoryPoolBuilder*, int);
typedef void (*PFNNVNMEMORYPOOLBUILDERGETMEMORYPROC)(const NVNmemoryPoolBuilder*);
typedef NVNdevice* (*PFNNVNMEMORYPOOLBUILDERGETDEVICEPROC)(const NVNmemoryPoolBuilder*);
typedef void* (*PFNNVNMEMORYPOOLBUILDERGETMEMORYPROC)(const NVNmemoryPoolBuilder*);
typedef size_t (*PFNNVNMEMORYPOOLBUILDERGETSIZEPROC)(const NVNmemoryPoolBuilder*);
typedef NVNmemoryPoolFlags (*PFNNVNMEMORYPOOLBUILDERGETFLAGSPROC)(const NVNmemoryPoolBuilder*);
typedef NVNboolean (*PFNNVNMEMORYPOOLINITIALIZEPROC)(NVNmemoryPool*, const NVNmemoryPoolBuilder*);
@@ -1236,7 +1239,8 @@ typedef void (*PFNNVNBUFFERBUILDERSETDEVICEPROC)(NVNbufferBuilder*, NVNdevice*);
typedef void (*PFNNVNBUFFERBUILDERSETDEFAULTSPROC)(NVNbufferBuilder*);
typedef void (*PFNNVNBUFFERBUILDERSETSTORAGEPROC)(NVNbufferBuilder*, NVNmemoryPool*, ptrdiff_t,
size_t);
typedef NVNmemoryPool (*PFNNVNBUFFERBUILDERGETMEMORYPOOLPROC)(const NVNbufferBuilder*);
typedef NVNdevice* (*PFNNVNBUFFERBUILDERGETDEVICEPROC)(const NVNbufferBuilder*);
typedef NVNmemoryPool* (*PFNNVNBUFFERBUILDERGETMEMORYPOOLPROC)(const NVNbufferBuilder*);
typedef ptrdiff_t (*PFNNVNBUFFERBUILDERGETMEMORYOFFSETPROC)(const NVNbufferBuilder*);
typedef size_t (*PFNNVNBUFFERBUILDERGETSIZEPROC)(const NVNbufferBuilder*);
typedef NVNboolean (*PFNNVNBUFFERINITIALIZEPROC)(NVNbuffer*, const NVNbufferBuilder*);
@@ -1296,7 +1300,8 @@ typedef void (*PFNNVNTEXTUREBUILDERGETSPARSETILELAYOUTPROC)(const NVNtextureBuil
NVNtextureSparseTileLayout*);
typedef uint32_t (*PFNNVNTEXTUREBUILDERGETGLTEXTURENAMEPROC)(const NVNtextureBuilder*);
typedef size_t (*PFNNVNTEXTUREBUILDERGETZCULLSTORAGESIZEPROC)(const NVNtextureBuilder*);
typedef NVNmemoryPool (*PFNNVNTEXTUREBUILDERGETMEMORYPOOLPROC)(const NVNtextureBuilder*);
typedef NVNdevice* (*PFNNVNTEXTUREBUILDERGETDEVICEPROC)(const NVNtextureBuilder*);
typedef NVNmemoryPool* (*PFNNVNTEXTUREBUILDERGETMEMORYPOOLPROC)(const NVNtextureBuilder*);
typedef ptrdiff_t (*PFNNVNTEXTUREBUILDERGETMEMORYOFFSETPROC)(const NVNtextureBuilder*);
typedef void (*PFNNVNTEXTUREVIEWSETDEFAULTSPROC)(NVNtextureView*);
typedef void (*PFNNVNTEXTUREVIEWSETLEVELSPROC)(NVNtextureView*, int, int);
@@ -1360,6 +1365,7 @@ typedef int (*PFNNVNTEXTUREGETSTORAGESIZEPROC)(const NVNtexture*);
typedef NVNboolean (*PFNNVNTEXTURECOMPAREPROC)(const NVNtexture*, const NVNtexture*);
typedef uint64_t (*PFNNVNTEXTUREGETDEBUGIDPROC)(const NVNtexture*);
typedef void (*PFNNVNSAMPLERBUILDERSETDEVICEPROC)(NVNsamplerBuilder*, NVNdevice*);
typedef NVNdevice* (*PFNNVNSAMPLERBUILDERGETDEVICEPROC)(const NVNsamplerBuilder*);
typedef void (*PFNNVNSAMPLERBUILDERSETDEFAULTSPROC)(NVNsamplerBuilder*);
typedef void (*PFNNVNSAMPLERBUILDERSETMINMAGFILTERPROC)(NVNsamplerBuilder*, NVNminFilter,
NVNmagFilter);
+8 -8
View File
@@ -4,6 +4,7 @@
typedef void (*NVNT_nvnDeviceBuilderSetDefaults)(NVNdeviceBuilder*);
typedef void (*NVNT_nvnDeviceBuilderSetFlags)(NVNdeviceBuilder*, int);
typedef int (*NVNT_nvnDeviceBuilderGetFlags)(const NVNdeviceBuilder*);
typedef NVNboolean (*NVNT_nvnDeviceInitialize)(NVNdevice*, const NVNdeviceBuilder*);
typedef void (*NVNT_nvnDeviceFinalize)(NVNdevice*);
typedef void (*NVNT_nvnDeviceSetDebugLabel)(NVNdevice*, const char*);
@@ -77,7 +78,8 @@ typedef void (*NVNT_nvnMemoryPoolBuilderSetDevice)(NVNmemoryPoolBuilder*, NVNdev
typedef void (*NVNT_nvnMemoryPoolBuilderSetDefaults)(NVNmemoryPoolBuilder*);
typedef void (*NVNT_nvnMemoryPoolBuilderSetStorage)(NVNmemoryPoolBuilder*, void*, size_t);
typedef void (*NVNT_nvnMemoryPoolBuilderSetFlags)(NVNmemoryPoolBuilder*, int);
typedef void (*NVNT_nvnMemoryPoolBuilderGetMemory)(const NVNmemoryPoolBuilder*);
typedef NVNdevice* (*NVNT_nvnMemoryPoolBuilderGetDevice)(const NVNmemoryPoolBuilder*);
typedef void* (*NVNT_nvnMemoryPoolBuilderGetMemory)(const NVNmemoryPoolBuilder*);
typedef size_t (*NVNT_nvnMemoryPoolBuilderGetSize)(const NVNmemoryPoolBuilder*);
typedef NVNmemoryPoolFlags (*NVNT_nvnMemoryPoolBuilderGetFlags)(const NVNmemoryPoolBuilder*);
typedef NVNboolean (*NVNT_nvnMemoryPoolInitialize)(NVNmemoryPool*, const NVNmemoryPoolBuilder*);
@@ -109,7 +111,8 @@ typedef int (*NVNT_nvnSamplerPoolGetSize)(const NVNsamplerPool*);
typedef void (*NVNT_nvnBufferBuilderSetDevice)(NVNbufferBuilder*, NVNdevice*);
typedef void (*NVNT_nvnBufferBuilderSetDefaults)(NVNbufferBuilder*);
typedef void (*NVNT_nvnBufferBuilderSetStorage)(NVNbufferBuilder*, NVNmemoryPool*, ptrdiff_t, size_t);
typedef NVNmemoryPool (*NVNT_nvnBufferBuilderGetMemoryPool)(const NVNbufferBuilder*);
typedef NVNdevice* (*NVNT_nvnBufferBuilderGetDevice)(const NVNbufferBuilder*);
typedef NVNmemoryPool* (*NVNT_nvnBufferBuilderGetMemoryPool)(const NVNbufferBuilder*);
typedef ptrdiff_t (*NVNT_nvnBufferBuilderGetMemoryOffset)(const NVNbufferBuilder*);
typedef size_t (*NVNT_nvnBufferBuilderGetSize)(const NVNbufferBuilder*);
typedef NVNboolean (*NVNT_nvnBufferInitialize)(NVNbuffer*, const NVNbufferBuilder*);
@@ -146,6 +149,7 @@ typedef void (*NVNT_nvnTextureBuilderSetPackagedTextureLayout)(NVNtextureBuilder
typedef void (*NVNT_nvnTextureBuilderSetStride)(NVNtextureBuilder*, ptrdiff_t);
typedef void (*NVNT_nvnTextureBuilderSetGLTextureName)(NVNtextureBuilder*, uint32_t);
typedef NVNstorageClass (*NVNT_nvnTextureBuilderGetStorageClass)(const NVNtextureBuilder*);
typedef NVNdevice* (*NVNT_nvnTextureBuilderGetDevice)(const NVNtextureBuilder*);
typedef NVNtextureFlags (*NVNT_nvnTextureBuilderGetFlags)(const NVNtextureBuilder*);
typedef NVNtextureTarget (*NVNT_nvnTextureBuilderGetTarget)(const NVNtextureBuilder*);
typedef int (*NVNT_nvnTextureBuilderGetWidth)(const NVNtextureBuilder*);
@@ -161,7 +165,7 @@ typedef ptrdiff_t (*NVNT_nvnTextureBuilderGetStride)(const NVNtextureBuilder*);
typedef void (*NVNT_nvnTextureBuilderGetSparseTileLayout)(const NVNtextureBuilder*, NVNtextureSparseTileLayout*);
typedef uint32_t (*NVNT_nvnTextureBuilderGetGLTextureName)(const NVNtextureBuilder*);
typedef size_t (*NVNT_nvnTextureBuilderGetZCullStorageSize)(const NVNtextureBuilder*);
typedef NVNmemoryPool (*NVNT_nvnTextureBuilderGetMemoryPool)(const NVNtextureBuilder*);
typedef NVNmemoryPool* (*NVNT_nvnTextureBuilderGetMemoryPool)(const NVNtextureBuilder*);
typedef ptrdiff_t (*NVNT_nvnTextureBuilderGetMemoryOffset)(const NVNtextureBuilder*);
typedef void (*NVNT_nvnTextureViewSetDefaults)(NVNtextureView*);
typedef void (*NVNT_nvnTextureViewSetLevels)(NVNtextureView*, int, int);
@@ -220,6 +224,7 @@ typedef void (*NVNT_nvnSamplerBuilderSetBorderColorui)(NVNsamplerBuilder*, const
typedef void (*NVNT_nvnSamplerBuilderSetMaxAnisotropy)(NVNsamplerBuilder*, float);
typedef void (*NVNT_nvnSamplerBuilderSetReductionFilter)(NVNsamplerBuilder*, NVNsamplerReduction);
typedef void (*NVNT_nvnSamplerBuilderSetLodSnap)(NVNsamplerBuilder*, float);
typedef NVNdevice* (*NVNT_nvnSamplerBuilderGetDevice)(const NVNsamplerBuilder*);
typedef void (*NVNT_nvnSamplerBuilderGetMinMagFilter)(const NVNsamplerBuilder*, NVNminFilter*, NVNmagFilter*);
typedef void (*NVNT_nvnSamplerBuilderGetWrapMode)(const NVNsamplerBuilder*, NVNwrapMode*, NVNwrapMode*, NVNwrapMode*);
typedef void (*NVNT_nvnSamplerBuilderGetLodClamp)(const NVNsamplerBuilder*, float*, float*);
@@ -482,7 +487,6 @@ typedef void (*NVNT_nvnCommandBufferSignalEvent)(NVNcommandBuffer*, const NVNeve
typedef NVNboolean (*NVNT_nvnDeviceRegisterFastClearStencil)(NVNdevice*, int);
// Names without a prototype in the header (newer interfaces): they can only get named stubs
// nvnDeviceBuilderGetFlags
// nvnQueueBuilderSetQueuePriority
// nvnQueueBuilderGetQueuePriority
// nvnQueueBuilderGetDevice
@@ -503,13 +507,9 @@ typedef NVNboolean (*NVNT_nvnDeviceRegisterFastClearStencil)(NVNdevice*, int);
// nvnWindowGetNumTextures
// nvnProgramSetShadersExt
// nvnProgramSetSampleShading
// nvnMemoryPoolBuilderGetDevice
// nvnBufferBuilderGetDevice
// nvnTextureBuilderGetDevice
// nvnTextureBuilderGetPackagedTextureLayout
// nvnTextureBuilderGetRawStorageClass
// nvnTextureGetRawStorageClass
// nvnSamplerBuilderGetDevice
// nvnCommandBufferSetCommandMemoryCallbackEnabled
// nvnCommandBufferSetColorReductionEnable
// nvnCommandBufferSetColorReductionThresholds
+44 -1
View File
@@ -326,6 +326,49 @@ static void retire_across_threads(void) {
g_churn_x = nil;
}
}
// A CPU write published through a buffer must be visible to a texture sharing its
// storage. Compare no flush, a direct pool flush, and a buffer-relative flush.
static void flushed_buffer_upload(int flush_kind) {
const size_t len = 262144, buffer_off = 65536, flush_off = 4096, output_off = 131072;
uint8_t *mem = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (mem == MAP_FAILED) abort();
NVNmemoryPool pool = {0}; NVNmemoryPoolBuilder pb = {0};
h_nvnMemoryPoolBuilderSetDefaults(&pb); h_nvnMemoryPoolBuilderSetStorage(&pb, mem, len);
h_nvnMemoryPoolBuilderSetFlags(&pb, NVN_MEMORY_POOL_FLAGS_CPU_CACHED | NVN_MEMORY_POOL_FLAGS_GPU_CACHED);
CHECK(h_nvnMemoryPoolInitialize(&pool, &pb), "flush test pool initialized");
NVNbufferBuilder bb = {0}; NVNbuffer buffer = {0};
h_nvnBufferBuilderSetDefaults(&bb); h_nvnBufferBuilderSetStorage(&bb, &pool, buffer_off, 32768);
CHECK(h_nvnBufferInitialize(&buffer, &bb), "flush test buffer initialized at nonzero pool offset");
NVNtextureBuilder tb = {0}; NVNtexture tex = {0};
h_nvnTextureBuilderSetDefaults(&tb); h_nvnTextureBuilderSetWidth(&tb, 4); h_nvnTextureBuilderSetHeight(&tb, 4);
// Storage images may be GPU-written, so their contents are not inferred from
// CPU storage at first use. Only an explicit flush publishes this upload.
h_nvnTextureBuilderSetFlags(&tb, NVN_TEXTURE_FLAGS_IMAGE);
h_nvnTextureBuilderSetFormat(&tb, NVN_FORMAT_RGBA8); h_nvnTextureBuilderSetStorage(&tb, &pool, buffer_off + flush_off);
uint8_t pixels[64], zeros[64] = {0}; for (int i=0;i<64;i++) pixels[i]=(uint8_t)(i+32);
// Fill before registration so a dirty-upload profile cannot infer publication
// from a later write. TextureWriteTexels would bypass the flush path as well.
CHECK(nvn_swizzle(&((const tex_builder_t *)&tb)->d, 0, 0, pixels, 16, mem + buffer_off + flush_off) == 0, "CPU pixels swizzled into buffer storage");
CHECK(h_nvnTextureInitialize(&tex, &tb), "flush test texture initialized without packaged layout");
const tex_t *t = (const tex_t *)&tex;
if (flush_kind == 1) h_nvnMemoryPoolFlushMappedRange(&pool, buffer_off + flush_off, t->L.size);
if (flush_kind == 2) h_nvnBufferFlushMappedRange(&buffer, flush_off, t->L.size);
NVNcommandBuffer cmd; CHECK(h_nvnCommandBufferInitialize(&cmd, NULL), "flush test command buffer initialized");
h_nvnCommandBufferAddCommandMemory(&cmd, &pool, 0, buffer_off); h_nvnCommandBufferBeginRecording(&cmd);
NVNcopyRegion region = {0,0,0,4,4,1};
h_nvnCommandBufferCopyTextureToBuffer(&cmd, &tex, NULL, &region, (uint64_t)mem + output_off, 0);
NVNcommandHandle handle = h_nvnCommandBufferEndRecording(&cmd);
state_reset(); memset(&R,0,sizeof R); mtl_sub_begin();
uint8_t *records = nvn_rec_linear(handle, NULL); mtl_exec(records); free(records);
CHECK(mtl_wait(mtl_sub_commit(),5000000000ull), "flushed storage GPU readback completed");
CHECK(!mtl_last_commit_error(), "flushed storage readback has no GPU error");
CHECK(!memcmp(mem + output_off, flush_kind ? pixels : zeros, sizeof pixels),
flush_kind == 2 ? "buffer flush publishes texture pixels to Metal" :
flush_kind == 1 ? "pool flush publishes texture pixels to Metal" : "unflushed cached storage does not trigger first-use upload");
h_nvnCommandBufferFinalize(&cmd); h_nvnTextureFinalize(&tex); h_nvnBufferFinalize(&buffer); h_nvnMemoryPoolFinalize(&pool);
CHECK(!nvn_flushed(mem + buffer_off + flush_off, 1), "pool finalization retires buffer flush ranges");
defer_drain(); munmap(mem,len);
}
int main(int argc, const char **argv) { @autoreleasepool {
enum { N = 6442, BASE = 1000 };
static tex_t t[N];
@@ -360,6 +403,6 @@ int main(int argc, const char **argv) { @autoreleasepool {
own.serial = 900002; mtl_tex_init(&own); moved = own; own.magic = 0; mtl_tex_release(&moved);
CHECK(!own_tex_live(moved.serial), "a copy outliving the object it was initialized in ends the texture");
retired_classification(); descriptor_replacement();
if (argc > 1 && !strcmp(argv[1], "--metal")) { mtl_init(); finalized_upload(0); finalized_upload(1); finalize_during_walk(); poll_asks_again(); poll_beside(); handover_holders(); retire_after_completion(); retire_across_threads(); }
if (argc > 1 && !strcmp(argv[1], "--metal")) { mtl_init(); finalized_upload(0); finalized_upload(1); for (int i=0;i<3;i++) flushed_buffer_upload(i); finalize_during_walk(); poll_asks_again(); poll_beside(); handover_holders(); retire_after_completion(); retire_across_threads(); }
printf("t_cpu_tex: %d checks, %d failed\n", checks, failed); return failed != 0;
} }
+163 -5
View File
@@ -122,6 +122,143 @@ static void *cmdsize_recorder(void *a) {
}
return NULL;
}
// NVN defaults are checked through public setters and getters, including reset
// of previously assigned state; see docs/reference/nvn-objects.md.
static void native_defaults(void) {
NVNmemoryPoolBuilder pb = {0}; uint8_t storage[16];
P(nvnMemoryPoolBuilderSetDevice)(&pb, &dev);
P(nvnMemoryPoolBuilderSetStorage)(&pb, storage, sizeof storage);
P(nvnMemoryPoolBuilderSetFlags)(&pb, NVN_MEMORY_POOL_FLAGS_CPU_CACHED | NVN_MEMORY_POOL_FLAGS_GPU_UNCACHED);
P(nvnMemoryPoolBuilderSetDefaults)(&pb);
EXPECT("pool defaults retain device", 1, P(nvnMemoryPoolBuilderGetDevice)(&pb) == &dev);
EXPECT("pool defaults clear storage", 1, P(nvnMemoryPoolBuilderGetMemory)(&pb) == NULL && P(nvnMemoryPoolBuilderGetSize)(&pb) == 0);
EXPECT("pool default flags CPU_NO_ACCESS/GPU_CACHED", 0x21, P(nvnMemoryPoolBuilderGetFlags)(&pb));
NVNsamplerBuilder sb = {0}; NVNsampler sampler = {0};
P(nvnSamplerBuilderSetDevice)(&sb, &dev);
P(nvnSamplerBuilderSetMinMagFilter)(&sb, NVN_MIN_FILTER_NEAREST_MIPMAP_LINEAR, NVN_MAG_FILTER_NEAREST);
P(nvnSamplerBuilderSetLodClamp)(&sb, -4.f, 8.f);
P(nvnSamplerBuilderSetDefaults)(&sb);
NVNminFilter min; NVNmagFilter mag; float lo, hi;
P(nvnSamplerBuilderGetMinMagFilter)(&sb, &min, &mag);
EXPECT("sampler default minification is linear", NVN_MIN_FILTER_LINEAR, min);
EXPECT("sampler default magnification is linear", NVN_MAG_FILTER_LINEAR, mag);
P(nvnSamplerBuilderGetLodClamp)(&sb, &lo, &hi);
EXPECT("sampler default LOD clamp is [0,1000]", 1, lo == 0.f && hi == 1000.f);
EXPECT("default sampler initializes", 1, P(nvnSamplerInitialize)(&sampler, &sb));
P(nvnSamplerGetMinMagFilter)(&sampler, &min, &mag);
P(nvnSamplerGetLodClamp)(&sampler, &lo, &hi);
EXPECT("sampler keeps default filtering and LOD", 1,
min == NVN_MIN_FILTER_LINEAR && mag == NVN_MAG_FILTER_LINEAR && lo == 0.f && hi == 1000.f);
P(nvnSamplerFinalize)(&sampler);
NVNtextureBuilder tb = {0};
P(nvnTextureBuilderSetDevice)(&tb, &dev);
P(nvnTextureBuilderSetSize3D)(&tb, 7, 9, 11); P(nvnTextureBuilderSetLevels)(&tb, 4);
P(nvnTextureBuilderSetDefaults)(&tb);
EXPECT("texture default width is unset", 0, P(nvnTextureBuilderGetWidth)(&tb));
EXPECT("texture default height is unset", 0, P(nvnTextureBuilderGetHeight)(&tb));
EXPECT("texture default depth is unset", 0, P(nvnTextureBuilderGetDepth)(&tb));
EXPECT("texture default has one level", 1, P(nvnTextureBuilderGetLevels)(&tb));
NVNmultisampleState ms = {0};
P(nvnMultisampleStateSetAlphaToCoverageDither)(&ms, 0);
P(nvnMultisampleStateSetDefaults)(&ms);
EXPECT("default alpha-to-coverage dither enabled", 1, P(nvnMultisampleStateGetAlphaToCoverageDither)(&ms));
}
static void builder_queries(void) {
// Builder setters/getters retain full pointer, size and offset values. No allocation
// or Initialize is needed to inspect a builder's proposed storage.
NVNdeviceBuilder db = {0}; NVNmemoryPool pool = {0}; uint8_t storage[16];
const size_t size = 0x200000080ull; const ptrdiff_t offset = 0x100000028ll;
P(nvnDeviceBuilderSetFlags)(&db, 0x40000002);
EXPECT("device builder flags round trip", 0x40000002, P(nvnDeviceBuilderGetFlags)(&db));
P(nvnDeviceBuilderSetDefaults)(&db);
EXPECT("device builder reset clears flags", 0, P(nvnDeviceBuilderGetFlags)(&db));
NVNmemoryPoolBuilder pb = {0};
P(nvnMemoryPoolBuilderSetDevice)(&pb, &dev); P(nvnMemoryPoolBuilderSetDefaults)(&pb);
P(nvnMemoryPoolBuilderSetStorage)(&pb, storage, size); P(nvnMemoryPoolBuilderSetFlags)(&pb, 0x24);
EXPECT("pool builder storage pointer round trip", 1, P(nvnMemoryPoolBuilderGetMemory)(&pb) == storage);
EXPECT("pool builder full 64-bit size", size, P(nvnMemoryPoolBuilderGetSize)(&pb));
EXPECT("pool builder flags round trip", 0x24, P(nvnMemoryPoolBuilderGetFlags)(&pb));
NVNbufferBuilder bb = {0};
P(nvnBufferBuilderSetDevice)(&bb, &dev); P(nvnBufferBuilderSetDefaults)(&bb);
P(nvnBufferBuilderSetStorage)(&bb, &pool, offset, size);
EXPECT("buffer builder retains device", 1, P(nvnBufferBuilderGetDevice)(&bb) == &dev);
EXPECT("buffer builder returns pool pointer", 1, P(nvnBufferBuilderGetMemoryPool)(&bb) == &pool);
EXPECT("buffer builder full 64-bit offset", offset, P(nvnBufferBuilderGetMemoryOffset)(&bb));
EXPECT("buffer builder full 64-bit size", size, P(nvnBufferBuilderGetSize)(&bb));
P(nvnBufferBuilderSetDefaults)(&bb);
EXPECT("buffer builder reset retains device", 1, P(nvnBufferBuilderGetDevice)(&bb) == &dev);
EXPECT("buffer builder reset clears storage", 1, P(nvnBufferBuilderGetMemoryPool)(&bb) == NULL &&
P(nvnBufferBuilderGetMemoryOffset)(&bb) == 0 && P(nvnBufferBuilderGetSize)(&bb) == 0);
NVNtextureBuilder tb = {0};
P(nvnTextureBuilderSetDevice)(&tb, &dev); P(nvnTextureBuilderSetDefaults)(&tb);
P(nvnTextureBuilderSetStorage)(&tb, &pool, offset); P(nvnTextureBuilderSetPackagedTextureData)(&tb, storage);
EXPECT("texture builder returns pool pointer", 1, P(nvnTextureBuilderGetMemoryPool)(&tb) == &pool);
EXPECT("texture builder full 64-bit offset", offset, P(nvnTextureBuilderGetMemoryOffset)(&tb));
EXPECT("texture builder packaged-data pointer", 1, P(nvnTextureBuilderGetPackagedTextureData)(&tb) == storage);
P(nvnTextureBuilderSetDepthStencilMode)(&tb, NVN_TEXTURE_DEPTH_STENCIL_MODE_STENCIL);
EXPECT("texture builder stencil mode", NVN_TEXTURE_DEPTH_STENCIL_MODE_STENCIL, P(nvnTextureBuilderGetDepthStencilMode)(&tb));
const int channels[][4] = {{1,0,5,2}, {0,0,0,0}};
for (unsigned i=0;i<2;i++) {
const int *c=channels[i]; NVNtextureSwizzle r=-1,g=-1,b=-1,a=-1;
P(nvnTextureBuilderSetSwizzle)(&tb,c[0],c[1],c[2],c[3]); P(nvnTextureBuilderGetSwizzle)(&tb,&r,&g,&b,&a);
EXPECT("texture builder swizzle round trip", 1, r==c[0] && g==c[1] && b==c[2] && a==c[3]);
}
P(nvnTextureBuilderSetDefaults)(&tb);
EXPECT("texture builder reset retains device", 1, P(nvnTextureBuilderGetDevice)(&tb) == &dev);
EXPECT("texture builder reset clears storage", 1, P(nvnTextureBuilderGetMemoryPool)(&tb) == NULL && P(nvnTextureBuilderGetMemoryOffset)(&tb) == 0);
EXPECT("texture builder reset clears packaged data", 1, P(nvnTextureBuilderGetPackagedTextureData)(&tb) == NULL);
EXPECT("texture builder reset selects depth", NVN_TEXTURE_DEPTH_STENCIL_MODE_DEPTH, P(nvnTextureBuilderGetDepthStencilMode)(&tb));
NVNtextureSwizzle r=-1,g=-1,b=-1,a=-1; P(nvnTextureBuilderGetSwizzle)(&tb,&r,&g,&b,&a);
EXPECT("texture builder reset restores RGBA", 1, r==2 && g==3 && b==4 && a==5);
NVNsamplerBuilder sb = {0}; P(nvnSamplerBuilderSetDevice)(&sb, &dev); P(nvnSamplerBuilderSetDefaults)(&sb);
EXPECT("sampler builder reset retains device", 1, P(nvnSamplerBuilderGetDevice)(&sb) == &dev);
}
static void pool_access(void) {
const size_t size=65536; const ptrdiff_t offset=4096;
uint8_t *mem=mmap(NULL,size,PROT_READ|PROT_WRITE,MAP_ANON|MAP_PRIVATE,-1,0);
if (mem==MAP_FAILED) abort();
const int flags[]={NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS, NVN_MEMORY_POOL_FLAGS_CPU_UNCACHED, NVN_MEMORY_POOL_FLAGS_CPU_CACHED};
NVNmemoryPoolBuilder pb={0}; P(nvnMemoryPoolBuilderSetDevice)(&pb,&dev); P(nvnMemoryPoolBuilderSetDefaults)(&pb);
P(nvnMemoryPoolBuilderSetStorage)(&pb,mem,size);
NVNbufferBuilder bb={0}; P(nvnBufferBuilderSetDevice)(&bb,&dev); P(nvnBufferBuilderSetDefaults)(&bb);
for (unsigned i=0;i<3;i++) {
NVNmemoryPool pool={0}; NVNbuffer buf={0};
P(nvnMemoryPoolBuilderSetFlags)(&pb,flags[i]|NVN_MEMORY_POOL_FLAGS_GPU_CACHED);
EXPECT("mapping test pool initializes",1,P(nvnMemoryPoolInitialize)(&pool,&pb));
P(nvnBufferBuilderSetStorage)(&bb,&pool,offset,512);
EXPECT("mapping test buffer initializes",1,P(nvnBufferInitialize)(&buf,&bb));
EXPECT("pool map respects CPU access",1,P(nvnMemoryPoolMap)(&pool)==(i ? mem : NULL));
EXPECT("buffer map respects CPU access and offset",1,P(nvnBufferMap)(&buf)==(i ? mem+offset : NULL));
EXPECT("GPU address survives CPU_NO_ACCESS",(uintptr_t)mem+offset,P(nvnBufferGetAddress)(&buf));
P(nvnBufferFinalize)(&buf); P(nvnMemoryPoolFinalize)(&pool);
}
NVNmemoryPool physical={0}, virtual_pool={0}; NVNbuffer buf;
P(nvnMemoryPoolBuilderSetFlags)(&pb,NVN_MEMORY_POOL_FLAGS_PHYSICAL|NVN_MEMORY_POOL_FLAGS_CPU_CACHED|NVN_MEMORY_POOL_FLAGS_GPU_NO_ACCESS);
EXPECT("physical backing pool initializes",1,P(nvnMemoryPoolInitialize)(&physical,&pb));
EXPECT("physical backing remains CPU-mappable",1,P(nvnMemoryPoolMap)(&physical)==mem);
P(nvnBufferBuilderSetStorage)(&bb,&physical,offset,512); memset(&buf,0xa5,sizeof buf);
EXPECT("physical pool cannot directly back a buffer",0,P(nvnBufferInitialize)(&buf,&bb));
EXPECT("failed physical-buffer init clears object",0,((const buf_t *)&buf)->magic);
P(nvnMemoryPoolBuilderSetFlags)(&pb,NVN_MEMORY_POOL_FLAGS_VIRTUAL|NVN_MEMORY_POOL_FLAGS_CPU_NO_ACCESS|NVN_MEMORY_POOL_FLAGS_GPU_CACHED);
P(nvnMemoryPoolBuilderSetStorage)(&pb,NULL,size);
EXPECT("virtual address pool initializes",1,P(nvnMemoryPoolInitialize)(&virtual_pool,&pb));
EXPECT("virtual address range is not a CPU mapping",1,P(nvnMemoryPoolMap)(&virtual_pool)==NULL);
P(nvnBufferBuilderSetStorage)(&bb,&virtual_pool,offset,512);
EXPECT("virtual pool can back a buffer",1,P(nvnBufferInitialize)(&buf,&bb));
EXPECT("unmapped virtual buffer has no CPU mapping",1,P(nvnBufferMap)(&buf)==NULL);
map_req map={&physical,0,0,size,0,0};
EXPECT("virtual pool maps physical backing",1,P(nvnMemoryPoolMapVirtual)(&virtual_pool,1,(const NVNmappingRequest *)&map));
EXPECT("mapped virtual pool still has no CPU mapping",1,P(nvnMemoryPoolMap)(&virtual_pool)==NULL);
EXPECT("mapped virtual buffer still has no CPU mapping",1,P(nvnBufferMap)(&buf)==NULL);
EXPECT("virtual mapping does not hide physical CPU mapping",1,P(nvnMemoryPoolMap)(&physical)==mem);
P(nvnBufferFinalize)(&buf); P(nvnMemoryPoolFinalize)(&virtual_pool); P(nvnMemoryPoolFinalize)(&physical); munmap(mem,size);
}
int main(void) {
setenv("DM_NVN_COUNT", "1", 1); // the call-count checks below need the counting trampolines (off by default)
{ // A missing control section must not publish uninitialized bytes or poison a serial's key cache.
@@ -234,6 +371,7 @@ int main(void) {
P(nvnDeviceGetInteger)(&dev, (NVNdeviceInfo)0x68, &v); EXPECT("X1 item 0x68 (16383, the driver's last)", 16383, v);
P(nvnDeviceGetInteger)(&dev, (NVNdeviceInfo)0x62, &v); EXPECT("X1 item 0x62 (32: the driver's table, the device's value read at init)", 32, v);
v = -1; P(nvnDeviceGetInteger)(&dev, (NVNdeviceInfo)0x69, &v); EXPECT("X1 items past 0x68 answer 0", 0, v);
native_defaults(); builder_queries(); pool_access();
// The Switch 2 table (NVN2's own constants: the newest seen, SDK 21.4.4's, as an older sdk's own switch answers its older versions through dm_sdk_nvn2_item): its GPU code range and Ampere's limits, the host's 16 vertex slots, and the run-time items
EXPECT("NVN2: API 231.39", 231 * 100 + 39, g_devinfo2[0] * 100 + g_devinfo2[1]);
EXPECT("NVN2: GPU code 201.0 to 201.20", 1, g_devinfo2[0x2E] == 201 && g_devinfo2[0x30] == 20 && g_devinfo2[0x2F] == 201 && g_devinfo2[0x31] == 0);
@@ -442,6 +580,22 @@ int main(void) {
P(nvnMemoryPoolBuilderSetStorage)(&pb, poolmem, sizeof poolmem);
}
// Buffer flushes name a subrange relative to the buffer, not to its memory pool.
{
NVNbufferBuilder bb = {0}; NVNbuffer buffer = {0};
P(nvnBufferBuilderSetDevice)(&bb, &dev); P(nvnBufferBuilderSetDefaults)(&bb);
P(nvnBufferBuilderSetStorage)(&bb, &pool, 0x4000, 0x400);
EXPECT("flush buffer initializes", 1, P(nvnBufferInitialize)(&buffer, &bb));
P(nvnBufferFlushMappedRange)(&buffer, 0x80, 0x40);
EXPECT("buffer flush includes both offsets", 1, nvn_flushed(poolmem + 0x4080, 0x40));
EXPECT("buffer flush excludes preceding byte", 0, nvn_flushed(poolmem + 0x407f, 1));
EXPECT("buffer flush excludes following byte", 0, nvn_flushed(poolmem + 0x40c0, 1));
EXPECT("buffer flush excludes unadjusted offset", 0, nvn_flushed(poolmem + 0x80, 0x40));
P(nvnBufferFlushMappedRange)(&buffer, 0x200, 0);
EXPECT("zero-length buffer flush adds no span", 0, nvn_flushed(poolmem + 0x4200, 1));
P(nvnBufferFinalize)(&buffer); fl_drop(poolmem, sizeof poolmem);
}
// 5. Command buffer: record uniform updates / events / counters / buffer copies / nested calls, with memory in 256 B segments to force multi-segment linking
NVNcommandBuffer cb; P(nvnCommandBufferInitialize)(&cb, &dev);
NVNmemoryPoolBuilder cpb; P(nvnMemoryPoolBuilderSetDefaults)(&cpb); P(nvnMemoryPoolBuilderSetStorage)(&cpb, g_cmdmem, sizeof g_cmdmem);
@@ -1602,14 +1756,18 @@ int main(void) {
}
// 7. Unimplemented functions: return 0, report a failure, report only once
// Use a function that is still unimplemented (nvnBufferBuilderSetDefaults, used before, was implemented later and crashes on NULL)
// Exercise a real thunk while installing a stub only for this test.
unsigned ui = 0; while (strcmp(nvn_names[ui], "nvnBufferBuilderGetDevice")) ui++;
((void (*)(void *))proc("nvnBufferBuilderGetDevice"))(NULL); ((void (*)(void *))proc("nvnBufferBuilderGetDevice"))(NULL);
void *saved_fn = nvn_slot[ui].fn; uint64_t before = nvn_slot[ui].cnt;
nvn_slot[ui].fn = (void *)nvn_unimpl_entry;
EXPECT("unimplemented function returns zero", 1, P(nvnBufferBuilderGetDevice)(NULL) == NULL);
P(nvnBufferBuilderGetDevice)(NULL);
EXPECT("unimplemented function marked as reported ([RED]) after a call", 1, g_unimpl_seen[ui] > 0);
EXPECT("unimplemented function count 2", 2, nvn_slot[ui].cnt);
for (int i = 0; i < 254; i++) ((void (*)(void *))proc("nvnBufferBuilderGetDevice"))(NULL); // the 256th call is where a one-byte count wrapped to 0, and the next call reported again
EXPECT("unimplemented function count 256", 256, nvn_slot[ui].cnt);
EXPECT("unimplemented function counted twice", 2, nvn_slot[ui].cnt - before);
for (int i = 0; i < 254; i++) P(nvnBufferBuilderGetDevice)(NULL); // a one-byte count used to wrap on the 256th call
EXPECT("unimplemented function counted 256 times", 256, nvn_slot[ui].cnt - before);
EXPECT("unimplemented function stays reported past 256 calls", 1, g_unimpl_seen[ui]);
nvn_slot[ui].fn = saved_fn;
// 8. A texture buffer as 2D rows for wrapped 1D fetches (x & 0x3FFF, x >> 14; nvn_mtl.m tbuf_as_2d): full rows back to back, one short row rounded to the alignment
{
+4
View File
@@ -702,6 +702,8 @@ One line per symptom in the [subsystem references](../reference/): what you see
- a running game with sound draws a black screen; every uniform buffer returns the same initialized address, with its allocation offset reported as its size. → [Guest ring allocators write `NVNbuffer` offset and size directly](../reference/nvn-objects.md#guest-ring-allocators-write-nvnbuffer-offset-and-size-directly)
- a game registers the same few sampler states into its sampler pool again and again: Super Mario Odyssey made 3,368 to 5,737 `nvnSamplerPoolRegisterSampler` calls for 168 distinct states in two runs of about 110 s from the regress route's save, against 168 for 168 after the fix. Each re-registration rewrites a pool ID that recorded draws may still use. Its picture on that route (frames 4,500 to 6,300) was the same either way, apart from the hint video's corner, which also varies between runs of one host. → [Games hash a sampler's bytes from 8 on](../reference/nvn-objects.md#games-hash-a-samplers-bytes-from-8-on)
- sprites broke apart in some runs only, depending on the allocation order; buffers overlapped. → [Sizes the hardware never reports as 0 (ZCull save area)](../reference/nvn-objects.md#sizes-the-hardware-never-reports-as-0-zcull-save-area)
- a default sampler selects mipmaps unexpectedly; builder reset loses the assigned device or reports different initial state from native NVN. → [Native NVN defaults](../reference/nvn-objects.md#native-nvn-defaults)
- `MemoryPoolMap` or `BufferMap` returns a writable pointer for a CPU-inaccessible or virtual GPU range; a buffer initializes directly on a physical backing pool. → [CPU mappings and physical backing pools](../reference/nvn-objects.md#cpu-mappings-and-physical-backing-pools)
- a null write as soon as the main thread starts recording a command buffer (13 Sentinels: a constructor at `main+0x2fa9a0` runs on `this = 0` when the prologue enters its first battle). → [Heaps cut from a pool at alignment relative to its GPU address](../reference/nvn-objects.md#heaps-cut-from-a-pool-at-alignment-relative-to-its-gpu-address)
- `[RED] memory pool … created at retry N`. → [`newBufferWithBytesNoCopy` retried under memory pressure](../reference/nvn-objects.md#newbufferwithbytesnocopy-retried-under-memory-pressure)
- a buffer is created with a null pool right after a scene change. → [Virtual memory pools mapped onto one physical pool](../reference/nvn-objects.md#virtual-memory-pools-mapped-onto-one-physical-pool)
@@ -781,6 +783,7 @@ One line per symptom in the [subsystem references](../reference/): what you see
- black screen with every geometry right (`DM_NVN_HILITE` shows each sprite and glyph in place); the uniform buffer right (a `CBDUMP`), so every texture read 0. → [A pool's storage at creation is its textures' content](../reference/nvn-objects.md#a-pools-storage-at-creation-is-its-textures-content)
- a game draws its UI and text but every image is black; `packaged textures: first uploads 0` while `TextureInitialize` counts the textures the game created (SD GUNDAM G GENERATION CROSS RAYS: 74, of which the 10 BC3 ones hold data and none is uploaded). After the fill works, one overlay still comes up with its text over nothing: the panel's background is missing and the text of the next block sits on top of it. → [`COMPRESSIBLE` in a pool the CPU writes is only a hint](../reference/nvn-objects.md#compressible-in-a-pool-the-cpu-writes-is-only-a-hint)
- a texture the game filled with `memcpy` and flushed reads as zeros (BotW's sky brownish grey, the distant haze brown). → [First-use fill of storage the game flushed](../reference/nvn-objects.md#first-use-fill-of-storage-the-game-flushed)
- a CPU-cached buffer holds texture pixels, but a texture sharing its storage reads back as zeros after `nvnBufferFlushMappedRange`. → [Buffer flushes publish the corresponding pool range](../reference/nvn-objects.md#buffer-flushes-publish-the-corresponding-pool-range)
- magenta (ASTC's error colour) where UI images belong: a title logo and menu panels, while the 3D scene and the text draw; `DM_NVN_ZBLOCK=1` reports nothing (the textures are not uploaded on the CPU at all); `DM_NVN_TEXINFO=WxH` shows storage holding data at first use (`non-zero …`) in a pool with flags 0x22 (`CPU_UNCACHED | GPU_CACHED`). → [Storage of a CPU-uncached pool at first use](../reference/nvn-objects.md#storage-of-a-cpu-uncached-pool-at-first-use)
- a picture that should change with a selection is black, or shows the previous item's picture while the item's name and description are right. `DM_NVN_TEXINFO=WxH` shows `swizzled=0` at first use with storage holding data, no packaged layout, in a `CPU_CACHED` or `CPU_UNCACHED` pool, and `DM_NVN_DIRTYCHECK=1` reports no missed write. → [Block-compressed storage the CPU wrote before first use](../reference/nvn-objects.md#block-compressed-storage-the-cpu-wrote-before-first-use)
- a movie plays black (Age of Calamity: its intro movie under the "+ Skip" prompt). → [Mapped-range flushes taken as uploads (`tex_flush_upload`)](../reference/nvn-objects.md#mapped-range-flushes-taken-as-uploads-tex_flush_upload)
@@ -821,6 +824,7 @@ One line per symptom in the [subsystem references](../reference/): what you see
- a jump to pc=0 right after the NVN bootstrap loader (`lr=main+0x37fe930`, `[RED] NVN address lookup of an unknown name: nvnSetExternalDebuggerEnabledNVX`). → [Extensions fetched by name and called unchecked](../reference/nvn-objects.md#extensions-fetched-by-name-and-called-unchecked)
- SIGBUS in `AGCDeserializedReply`, address in the guest stack region. → [NVN entry points on the big host stack](../reference/nvn-objects.md#nvn-entry-points-on-the-big-host-stack)
- red `NVN unimplemented function called` lines for `nvnColorStateGetBlendEnable`, `nvnBlendStateGetBlendFunc`, `nvnPolygonStateGetCullFace`, `nvnDepthStencilStateGetDepthTestEnable`, `nvnBufferBuilderGetSize`, `nvnTextureBuilderGetWidth`, …. → [State read back through NVN getters](../reference/nvn-objects.md#state-read-back-through-nvn-getters)
- querying a configured builder logs `[RED] NVN unimplemented function called`, returns a null storage/device pointer, or reports the wrong size, flags or sampling mode. → [Builder queries return pointers and retained state](../reference/nvn-objects.md#builder-queries-return-pointers-and-retained-state)
- an abort in device setup when `nvnTexturePoolGetSize` / `nvnSamplerPoolGetSize` returned 0. → [Pool size getters, texture address and command memory size](../reference/nvn-objects.md#pool-size-getters-texture-address-and-command-memory-size)
- `[RED] NVN unimplemented function called: nvnTextureBuilderGetMemoryOffset`, then `nvnTextureBuilderGetRawStorageClass`. → [Builder storage getters](../reference/nvn-objects.md#builder-storage-getters)
- `[nvn-mtl] FATAL buffer copy address is in no memory pool src=0x70d08a8b00 dst=0 n=0x29a00` as a match loads: a recorded `CopyBufferToBuffer` whose destination is 0. → [`Map` of a pool without CPU access returns NULL](../reference/nvn-objects.md#map-of-a-pool-without-cpu-access-returns-null)
+35 -1
View File
@@ -52,8 +52,26 @@ A game may tell NVN objects apart by their bytes, without an NVN call. A host re
- **Fix:** the host never reports a ZCull storage size of 0 (`hle_nvn.c` `zcull_size`).
- **Found on:** [Cuphead](../../dm/games/0100A5C00D162000/README.md). Found by tracking the allocator from observation gates (`OBS` in its `patches.py`) on its free-list push and after its map insert, checking at every event that each block allocated so far was still in the game's map.
## Builder and state defaults
### Native NVN defaults
- **Symptom:** a default sampler selects mipmaps unexpectedly; builder reset loses the assigned device or reports different initial state from native NVN.
- **Cause:** `SamplerBuilderSetDefaults` used OpenGL's minification filter and minimum LOD. Pool defaults cleared the device and left flags zero; texture dimensions started at one; alpha-to-coverage dithering started disabled.
- **Fix:** use NVN's defaults in `hle_nvn.c`: linear minification and magnification without mip filtering, LOD clamp `[0, 1000]`; pool flags `CPU_NO_ACCESS | GPU_CACHED` (`0x21`), cleared storage and size, preserved device; unset texture dimensions (`0`) with one mip level; alpha-to-coverage dither enabled. The dither change fixes state readback; it does not add a Metal dithering implementation.
- **Found on:** synthetic public-entry-point tests in `t_nvn.c`; no game-specific visual result is claimed.
- **Check:** `t_nvn.c` resets previously assigned state, preserves the pool's device, and checks sampler initialization and public state getters against explicit expected defaults.
## Memory pools
### CPU mappings and physical backing pools
- **Symptom:** `MemoryPoolMap` or `BufferMap` returns a writable pointer for a CPU-inaccessible or virtual GPU range; a buffer initializes directly on a physical backing pool.
- **Cause:** the host used the same address for CPU access, GPU storage and virtual aliases. The existing [CPU-inaccessible pool check](#map-of-a-pool-without-cpu-access-returns-null) did not separately exclude virtual ranges, and buffer initialization accepted physical backing pools directly. A virtual pool keeps a GPU address but no CPU mapping; its physical backing can have a CPU mapping of its own.
- **Fix:** a shared `pool_cpu_map` excludes `CPU_NO_ACCESS` and `VIRTUAL` pools. `BufferMap` adds the buffer offset only to a non-null CPU mapping. `BufferInitialize` rejects `PHYSICAL` pools and clears the host object on failure, matching native initialization. The backing pointers used internally by Metal and virtual mapping remain available.
- **Found on:** synthetic mapping and initialization tests in `t_nvn.c`; no game-specific crash is claimed.
- **Check:** `t_nvn.c` covers both mapping entry points with a nonzero buffer offset, GPU addressing of CPU-inaccessible storage, physical backing's CPU mapping, and virtual pools before and after mapping physical pages.
### Heaps cut from a pool at alignment relative to its GPU address
- **Symptom:** a null write as soon as the main thread starts recording a command buffer (13 Sentinels: a constructor at `main+0x2fa9a0` runs on `this = 0` when the prologue enters its first battle).
@@ -732,6 +750,14 @@ Games read this count as a position in their own command memory and size their h
- **Found on:** [The Legend of Zelda: Breath of the Wild](../../dm/games/01007EF00011E000/README.md), GitHub issue #52 (Mac and iPhone). The sky is precomputed atmospheric scattering: each frame a pass (`08fe25061d583637`, `uking_pass_shader.sharcb`) turns a 256×32×16 RGBA16F 3D table of in-scattered light into a 256×256 sky map, which the sky draw (`8110c74078548172`) and the materials' aerial perspective sample. The table and two 2D ones (transmittance 256×64, irradiance 64×64) come from `System/KSys/sky.skybin` in `Pack/Bootup_Graphics.pack` (1,212,416 bytes, the three textures' storage back to back). The game makes a `CPU_CACHED | GPU_CACHED` pool for each texture, creates the textures, copies the file's data in with `memcpy` and flushes (`main+0x1257d50`, once, at the sky's setup; the flush goes through `main+0xebf4c4`, which flushes only CPU-cached pools). With zeros the sky had no scattered light: only the clouds and the sun's colour were left. In the Great Plateau save the fill covers that one texture; the flushes (about 15 a frame) merge into about 530 ranges, and frame times did not change. DRAGON QUEST XI S (title, free play, menus; 300 s) filled none.
- **Note:** `DM_NVN_TEXRAW=212,214` (all zero) and `DM_NVN_TEXINFO=256x32` (`storage 1048576 bytes non-zero 781567` at first use, `swizzled=0`) showed it.
### Buffer flushes publish the corresponding pool range
- **Symptom:** a CPU-cached buffer holds texture pixels, but a texture sharing its storage reads back as zeros after `nvnBufferFlushMappedRange`.
- **Cause:** the host treated the buffer flush as a no-op because memory is unified. Metal textures can be separate copies of that memory, and the no-op bypassed both first-use flush tracking and the existing texture-upload tracking. A buffer flush names a subrange relative to its buffer, so it must add the buffer offset before forwarding the range to the pool.
- **Fix:** forward buffer flushes to the pool flush with `buffer.poolOffset + requestedOffset` and the original size. This uses the existing pool lifetime, virtual-pool and upload rules.
- **Found on:** the ABI audit's synthetic Metal readback, with nonzero buffer and flush offsets. Before the fix, the pool-flush control uploaded the pixels and the buffer-flush case returned zeros; after the fix both return the CPU-written pixels.
- **Check:** `t_nvn.c` checks the exact range boundaries and a zero-length flush. `t_cpu_tex --metal` compares an unflushed cached storage image, a pool flush and a buffer flush through a GPU texture-to-buffer copy, then checks pool finalization retires the flush range. The test writes block-linear storage before texture registration, without `TextureWriteTexels` or a packaged layout that would bypass the failure. This avoids dirty-upload inference, and its `IMAGE` flag excludes automatic first-use CPU-content inference. On current main's command-list API the test flattens the handle with `nvn_rec_linear`; restoring only the buffer-flush no-op fails exactly its buffer-flush readback, while the pool-flush control passes. The dirty-upload profile also runs the existing rewrite and lifetime cases (132 checks, none failed).
### Storage of a CPU-uncached pool at first use
- **Symptom:** magenta (ASTC's error colour) where UI images belong: a title logo and menu panels, while the 3D scene and the text draw; `DM_NVN_ZBLOCK=1` reports nothing (the textures are not uploaded on the CPU at all); `DM_NVN_TEXINFO=WxH` shows storage holding data at first use (`non-zero …`) in a pool with flags 0x22 (`CPU_UNCACHED | GPU_CACHED`).
@@ -1070,6 +1096,14 @@ Games read this count as a position in their own command memory and size their h
- **Fix:** the getters read the packed state objects (`hle_nvn.c`); the multisample setters the host lacked (alpha-to-coverage dither, raster samples, coverage modulation and coverage-to-colour) are recorded in fields `ms_st` already had.
- **Found on:** [Pokémon Legends: Z-A](../../dm/games/0100F43008C44000/README.md) (19.3.11, Game Freak's Trinity engine; one boot).
### Builder queries return pointers and retained state
- **Symptom:** querying a configured builder logs `[RED] NVN unimplemented function called`, returns a null storage/device pointer, or reports the wrong size, flags or sampling mode.
- **Cause:** nine pure queries were still stubs; the pool/offset and texture-swizzle getters already worked. The header also declared `MemoryPoolBuilderGetMemory` as returning `void`, and the buffer/texture builder `GetMemoryPool` queries as returning an entire `NVNmemoryPool`. Those declarations do not describe native NVN's single-register pointer returns.
- **Fix:** correct the declarations in `include/nvn.h` and regenerate `nvn_protos.h`. Implement device-builder flags; memory-pool builder device, memory, size and flags; buffer-builder device; texture-builder device and packaged-data pointer; sampler-builder device. Each reads the existing state, including device preservation and cleared storage after `SetDefaults`. Existing pool/offset, depth/stencil and texture-swizzle queries are retained. All-zero explicit channels remain distinct from the default RGBA mapping.
- **Found on:** synthetic public-entry-point tests in `t_nvn.c`; no game-specific validation is claimed.
- **Check:** `t_nvn.c` invokes the generated, signature-checked API types through the public procedure lookup. Its unimplemented-entry test temporarily installs the stub in a real dispatch slot and restores it, so adding a real implementation no longer breaks that test.
### Device getters that were red stubs
- **Fix:** `nvnDeviceGetWindowOriginMode` and `nvnDeviceGetDepthMode` were red stubs: the game sets neither mode and reads both. `nvnDeviceGetTexelFetchHandle` returns the texture ID with sampler 0.
@@ -1085,7 +1119,7 @@ Games read this count as a position in their own command memory and size their h
- **Symptom:** `[RED] NVN unimplemented function called: nvnTextureBuilderGetMemoryOffset`, then `nvnTextureBuilderGetRawStorageClass`.
- **Cause:** the renderer reads a texture builder's storage back before it initializes the texture; the host had the texture's getters (`nvnTextureGetMemoryPool` / `Offset` / `RawStorageClass`) but not the builders'.
- **Fix:** the texture, buffer and event builders return the pool and offset `SetStorage` stored (the pool getters return its address, as `nvnTextureGetMemoryPool` does; the header the prototypes come from declares the builders' by value, so they are `NVN_NOPROTO`), and the texture builder's raw storage class is the texture's (1): it only names the page kind a virtual pool maps (`NVNmappingRequest.storageClass`), which the host's virtual pools do not distinguish.
- **Fix:** the texture, buffer and event builders return the pool and offset `SetStorage` stored (the pool getters return its address, as `nvnTextureGetMemoryPool` does; the [buffer and texture query declarations are now corrected](#builder-queries-return-pointers-and-retained-state); event queries still use `NVN_NOPROTO`), and the texture builder's raw storage class is the texture's (1): it only names the page kind a virtual pool maps (`NVNmappingRequest.storageClass`), which the host's virtual pools do not distinguish.
- **Found on:** [EA SPORTS FC 27](../../dm/games/0100C49025D3E000/README.md) (SDK 22, Frostbite's NVN renderer NRO).
### `Map` of a pool without CPU access returns NULL