NVNcommandBuffer fields, from disassembly of the two SDKs:
| Field | Game A | Game 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, +0x6c | not 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:
BeginRecording writes {0xffffffffffffff01, 0}.{u64 gpu_va, u64 cpu_va, u32 nwords, u8 flags}, with flags 1 for mergeable and 3 for normal. A range contiguous
with the previous one merges by adding to its nwords.EndRecording writes a type-2 terminator and returns control start + 0x10 as the command handle.AddCommandMemory, EndRecording) and compute-stage
binds (16-byte control items) do. A compute-stage (stage 5) BindTexture writes a control item instead of methods.| Function | Game A | Game B |
|---|---|---|
nvnCommandBufferInitialize | 0xd141860 | 0xd15a0a0 |
nvnCommandBufferAddCommandMemory | 0xd141920 | 0xd15a140 |
nvnCommandBufferAddControlMemory | 0xd141af0 | 0xd15a320 |
nvnCommandBufferBeginRecording | 0xd141c40 | 0xd15a480 |
nvnCommandBufferEndRecording | 0xd141cf0 | 0xd15a530 |
nvnCommandBufferDrawArrays | 0xd163b00 | 0xd183880 |
nvnCommandBufferDrawElements | 0xd163b80 | 0xd1838f0 |
nvnCommandBufferBindTexture | 0xd1627c0 | 0xd181680 |
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.