The NVN investigation

Snapshot: this page records what the investigation that led to the NVN loader found, as it was found. The code has changed since, and the page is not kept up to date. The current design is in NVN, which names the games A to D as this page does.

Why the first replay was abandoned

This section describes a replay that ran beside the Maxwell decoder, after the driver had written the command memory. The loader avoids its problems, because it takes each NVN function before the driver can write anything. The investigation built about 14,000 lines of opt-in probes: a recorder of NVN calls, a replay of those calls on the GPU thread, a second Vulkan renderer with its own image cache, and pixel comparisons against the Maxwell path. It reached byte-exact intermediate targets in all four titles, but the approach could not become a renderer:

What the first runs found (one game, SDK NVN 55.15)

With the driver beside nvn, the game ran through its title and save load. The results the driver answered otherwise, which the game sizes its memory by:

CallnvnDriver
nvnQueueBuilderGetQueueMemorySize (defaults, compute memory set)0x1000000x109000
nvnTextureBuilderGetStorageClass00x100, 0x1fe
nvnTextureBuilderGetStorageSize0x200, 0x180000x10000, 0x20000
nvnTextureBuilderGetStorageAlignment0x2000x10000
nvnTextureBuilderGetZCullStorageSize0x100, 0x200, 0x2c000x460, 0x860, 0xafe0
nvnDeviceGetTextureHandle0x103001070x110300107 (bit 32 set)
TIC word 6 of registered textures00x03000000

The texture rows are fixed (Texture storage answers). The queue memory size is fixed too (nvn_queue.c): the driver's QueueInitialize fails with less. Its rule (sdk's GetQueueMemorySize of NVN 55.15) adds to the command and control sizes (defaults 0x10000 and 0x4000) an area of its own, rounded up to 4 KiB:

The six device words the rule reads are nvdrv's answers, which the driver keeps in its device: 1 GPC (num_gpc), 2 SMs (NUM_VSMS), 0x80 warps (sm_arch_warp_count), the ZCULL context size 1 (ZCULL_GET_CTX_SIZE) and its 4 KiB alignment, and the device flags.

Emulator fixes kept from the investigation

FixWhere
A render-target alias of an 8×8 cubemap mip is padded to a 16×8 surface (64-byte GOB rows). The importer accepts that shape and copies the logical extentvk/texture.c tex_take_drawn
Depth-only D16 and D32F textures import from render targets through the depth aspectvk/texture.c
Four-byte packed depth/stencil uploads: G24R8 (0x0e) and Z24S8 (0x29) keep stencil in the low byte, X8Z24 (0x2a) and S8Z24 (0x2b) depth in the low 24 bitsvk/texture.c
A BRX resolves its jump table when the LDC is up to 64 instructions back, with only a short list of instructions that don't write the index register in between and no control flow before it. Game B has the LDC at instruction 93 and the BRX at 125shader/shader.c (brx_far_ldc then, shader_brx_targets now)
Compute code is bounded by the NVN header's declared size (magic 0x12345679 at code - 0x100), so an unresolved BRX cannot scan into neighboring programsvk/compute.c
Storage results are read back from host-cached memoryvk/buffer.c, vk/cmd.c

Made from docs/history/nvn-investigation.md at 69237645142c. GPL-3.0-or-later.