Command buffer layout (two games' SDK observations)

NVNcommandBuffer fields, from disassembly of the two SDKs:

FieldGame AGame B
device+0x00+0x60
memory callback, userdata+0x08, +0x10+0x68, +0x70
command cursor+0x18+0x00
command limit+0x20+0x08
chunk start+0x28+0x40
control cursor+0x30+0x20
control limit+0x38+0x28
control stream start+0x40+0x48
current range-record header+0x48+0x50
chunk CPU base+0x50+0x30
chunk GPU base+0x60+0x58
recording flag (byte)+0x68+0x11
space check enabled, BindTexture's 0x68b word (bytes)+0x6d, +0x6cnot observed
reserve margin in words+0x70 (u32)+0x16 (u8)

The GPU address of a cursor is chunk GPU base + (cursor - chunk CPU base). Game B caps each range at 0x7ffffc bytes.

Command functions are all inlined copies with no shared reserve helper. Each checks whether cursor + n*4 exceeds the limit (game A checks only when the command buffer's byte +0x6d is set) and if so calls a slow path (game A 0xd141f20, game B 0xd15a754). The slow path calls the memory callback (event 0 for command memory, 1 for control memory), expects it to call AddCommandMemory or AddControlMemory, and asserts if the space is still short. Its third argument is the least the callback must add: the bytes the function checked for and never fewer than 0x200 for command memory, 0x100 for control memory (the drivers of NVN SDK 4.5, 9.3 and 16.2 alike). The bytes checked for are the most the function may write, not what it writes: every state bind (color, channel mask, depth-stencil, polygon, multisample, vertex attributes) checks for 0xc4 bytes and a vertex stream bind for 0x100, so on the console the callback runs while that many bytes are not free. The runtime asks only once the bytes a command writes do not fit, with the same third argument.

The control stream:

FunctionGame AGame B
nvnCommandBufferInitialize0xd1418600xd15a0a0
nvnCommandBufferAddCommandMemory0xd1419200xd15a140
nvnCommandBufferAddControlMemory0xd141af00xd15a320
nvnCommandBufferBeginRecording0xd141c400xd15a480
nvnCommandBufferEndRecording0xd141cf00xd15a530
nvnCommandBufferDrawArrays0xd163b000xd183880
nvnCommandBufferDrawElements0xd163b800xd1838f0
nvnCommandBufferBindTexture0xd1627c00xd181680

nvnDeviceGetTextureHandle is orr w8,w1,w2,lsl #20; sxtw x8,w8; orr x0,x8,#0x100000000; ret in both (game B 0xd165530): the texture ID in the low 20 bits, the sampler ID in the next 12, and bit 32 set.


Made from docs/layers/gpu/nvn.md at 69237645142c. GPL-3.0-or-later.