A zero-byte memory pool initialises as an empty pool in the Vulkan back end

vk_pool_init gave a size-0 pool with storage a record: the host import of 0 bytes failed (the driver refuses the
memory, VK_ERROR_INVALID_EXTERNAL_HANDLE) and the record went into the pool index as the empty range [mem, mem]. A
lookup at that address then found the empty pool before the pool that starts there and reported it unbacked. TotK
makes such pools now and then (MacNativeGames d3407e29, 1.2.1). Such a pool now gets no record, as a GPU_NO_ACCESS
pool; vk_pool_fini finds none and does nothing. Removal by key already kept a neighbour's range safe at Finalize.

--probe-vkexec gains an empty pool part: a zero-byte pool at the start of another, lookups there before and after
its Finalize. It failed before ("a lookup at the start of a pool finds the empty pool there").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-02 09:14:10 +03:00
1 parent d554165cf0
commit b6ab660b00
2 files changed
+33

No files matched your search

+28
View File
@@ -845,6 +845,31 @@ static int test_mirror(const GfxBackend *b, uint8_t *guest, int *bytes) {
return 0;
}
// A pool of zero bytes (TotK makes some now and then; MacNativeGames hit one on 1.2.1) initialises as an empty pool: no
// Vulkan buffer or memory (a buffer or import of 0 bytes is invalid usage) and no pool index entry, so a lookup at its
// address still finds the pool that starts there, before and after the empty pool's Finalize.
static int test_empty_pool(const GfxBackend *b, uint8_t *guest) {
pool_t pool = {.magic = NVN_POOL_MAGIC, .flags = 0x22, .mem = guest + 0xE00000, .size = 0x100000,
.game_mem = guest + 0xE00000};
pool_t empty = {.magic = NVN_POOL_MAGIC, .flags = 0x22, .mem = guest + 0xE00000, .size = 0,
.game_mem = guest + 0xE00000};
CHECK(b->pool_init(&pool), "pool_init of a CPU-visible pool for the empty-pool part");
long errors = vk_validation_errors_total();
CHECK(b->pool_init(&empty), "pool_init of a zero-byte pool");
uint64_t a = (uint64_t)(uintptr_t)pool.mem;
VkMemSpan whole, at, after;
CHECK(vk_mem_resolve(a + 16, 16, &whole) && whole.buffer, "the pool beside an empty pool is not resolved");
CHECK(vk_mem_resolve(a, 0, &at) && at.buffer == whole.buffer && at.offset == whole.offset - 16,
"a lookup at the start of a pool finds the empty pool there");
CHECK(vk_validation_errors_total() == errors, "the zero-byte pool raised %ld validation errors",
vk_validation_errors_total() - errors);
b->pool_fini(&empty);
CHECK(vk_mem_resolve(a + 16, 16, &after) && after.buffer == whole.buffer,
"the empty pool's Finalize took the pool beside it out of the index");
b->pool_fini(&pool);
return 0;
}
int probe_vkexec(void) {
vk_hdr_off(); // the present checks read 8-bit swapchain pixels
layouts_equal = 0;
@@ -866,6 +891,7 @@ int probe_vkexec(void) {
int nvnx_bytes = 0, mirror_bytes = 0;
if (!bad) bad = test_nvnx(b, guest, &nvnx_bytes);
if (!bad) bad = test_mirror(b, guest, &mirror_bytes);
if (!bad) bad = test_empty_pool(b, guest);
b->finish();
vk_pipeline_shutdown(); // the pipelines and the draw part's stand-ins go before the device
vk_exec_draw_shutdown();
@@ -910,5 +936,7 @@ int probe_vkexec(void) {
"between submissions mirrored, CPU bytes beside a fill kept, %d bytes compared)\n", mirror_bytes);
else
printf("probe-vkexec: mirror part skipped (memory mode import)\n");
printf("probe-vkexec: empty pool part passed (a zero-byte pool at the start of another: no Vulkan objects, lookups "
"there find the other pool before and after its Finalize)\n");
return 0;
}
+5
View File
@@ -245,6 +245,11 @@ int vk_pool_init(pool_t *p) {
// virtual pools that map it. Either gets device-local memory: 1.4.3's CPU never writes its 0x18c pool's storage
// (unchanged over 3600 frames of the intro), so the guest storage and the GPU copy need no sync.
if ((p->flags & NVN_MEMORY_POOL_FLAGS_GPU_NO_ACCESS) && !(p->flags & NVN_MEMORY_POOL_FLAGS_PHYSICAL)) return 1;
// A pool of zero bytes (TotK makes some now and then) holds no address the GPU can use: it gets no record. A record
// would import 0 bytes (invalid usage; the driver refuses the memory) and put an empty range into the index at the
// pool's address, where a lookup of the pool that starts there found the empty one first. vk_pool_fini finds no
// record for it and does nothing.
if (!p->size) return 1;
PoolRec *r = calloc(1, sizeof *r);
if (!r) rt_fatal("vk: out of memory for a pool record");
r->key = p;