The game draws part of its frames with mesh shaders: about 14 nvnCommandBufferDrawMeshTasks calls a frame in the
screens after the title, all from the programs of Shader/Drive.Nin_Ounce_NVN2.release.sarc.zs
(DrivePassShaderDefault.sharcb, the 3D scene's passes). The renderer draws them with VK_EXT_mesh_shader where
the driver has it and no ban holds, which keeps them off on NVIDIA's driver (see Draws). No font or UI program
(Lib/sead/nvn2_font, the programs in main) is a mesh program, so the missing menu text has another cause. Of the
programs that the shipped pass translates, about 500 fragment and vertex programs are refused (most with "BRX with no
jump table"), which is a better lead for the text.
An Ounce control section names the program's stage in its halfword at 0x56: 0 vertex, 1 fragment, 5 compute, 6
task, 7 mesh (NVN_SHADER_STAGE_TASK and NVN_SHADER_STAGE_MESH). The SPH cannot tell them, as NVIDIA's hardware
runs a task program in the vertex slot and a mesh program in the tessellation slot when a task program launches it,
else in the vertex slot (Mesa's NAK, nak/sph.rs, and NVK's mesa_to_nv9097_shader_type):
| Program | SPH word 0 | Section 0x56 |
|---|---|---|
| vertex | 0x020c0481 (bit 25, ISBE space sharing, set) | 0 |
| task | 0x000c0481, or 0x000d0481 with global stores | 6 |
| mesh without a task program | 0x000c0481 | 7 |
| mesh after a task program | 0x020c0c81 (type 1, shader 3) | 7 |
| per-primitive outputs of a mesh program | 0x010c1081 (geometry, passthrough bit 24) | none |
sm86_sph_stage thus gives ST_VS or ST_TES for these programs, never -1. stage11 (gpu/nvn/nvn_object.c) now takes
the section's stage, so a mesh program no longer replaces the vertex or tessellation stage of its program. The
section's stage and the SPH agree for every other program of two runs.
A mesh or task program's section also gives (gpu/nvn/nvn_section.h):
| Offset | Field | Values seen |
|---|---|---|
| 0x58 (u16) | invocations of the workgroup | 8, 32 |
| 0x5a (u16) | task payload bytes, in 128-byte lines; a mesh program alone has 0x80 | 0x80, 0x100, 0x580 |
| 0x5e (u8) | 1 when a task program launches the mesh program | |
| 0x5f (u8) | vertices of a primitive | 3 |
| 0x60, 0x62 (u16) | most vertices, most primitives | 32/16, 128/64, 256/192 |
| 0x64, 0x68 | offset from the start of the program's code area (its own SPH included) and bytes of the per-primitive SPH (0 for none) | 0xd00, 0x80 |
The offset counts from the start of the code area, the program's own SPH included. A code area of 0xe00 bytes (0x44)
has the per-primitive SPH at 0xd00, and its last 128 bytes are zero. One of 0x4900 bytes has it at 0x4800. The dumps
of 11 mesh programs show the SPH word 010c1081 (or 010d1081) there in each program whose offset is not 0. The
renderer read it at 0x80 + the offset before, where the code area holds zeros, and so it dropped every per-primitive
output. Its OMAP gives the per-primitive output words, and the mesh SPH's OMAP the per-vertex ones.
The fields do not go in the program object. The Ounce's program object is 0xa0 bytes: the driver's
nvnProgramInitialize (sdk offset 0x5bf2c0) zeroes that many and uses offsets up to 0x98. The runtime keeps them,
and a compute program's c[0] record, in a table by the program's SetShaders serial (nvn_program_mesh,
nvn_program_c0). Before, the c[0] record was at bytes 0x98 to 0xab of the object, and each SetShaders wrote 12 bytes
of the game's memory after it. The game's own bytes there (0xc2 in one run) then took the place of the mesh
programs' per-primitive SPH offset.
Every output, input and count goes through the ISBE (the "internal stage buffer entry"), with ISBERD (0x923) and
ISBEWR (0x927), as NAK lowers them (nak_nir_lower_mesh_intrinsics.c). The fields (NAK's sm70_encode.rs): 24-31
the offset register, 32-39 the data (ISBEWR), 40-55 an immediate offset, 74-75 the size (U8, U16, B32), 76-77 the
access (MAP, PATCH, PRIM, ATTR), 78 SKEW, 79 output. The game's programs use no LDS, STS or BAR, and every workgroup
is one warp (at most 32 invocations, S2R SR_LANEID as the invocation).
| What | Instruction |
|---|---|
| workgroup index (task, mesh alone) | ISBERD.ATTR.SKEW [RZ+0x0] (the vertex ID of the point draw) |
| workgroup index (mesh after a task) | ISBERD.ATTR [RZ+0x0] |
| task payload, task side | ISBEWR.ATTR.O [Rn+0x10+...], from byte 0x10 |
| mesh groups to launch | ISBEWR.ATTR.O [RZ+0x4] (one count, x only; NAK also writes x, y, z at 0x8 to 0x10) |
| task payload, mesh side | ISBERD.ATTR [Rn+0x10+...], the same offsets |
| per-vertex output | ISBEWR.ATTR.SKEW.O at (v / 32) * G + (v % 32) * 4 + k * 0x80, word k of the used words in OMAP order, G = 0x80 times their count |
| per-primitive output | ISBEWR.ATTR.SKEW.O at V + (p / 32) * P + (p % 32) * 4 + k * 0x80, V the vertex area (G times the vertex groups), P from the per-primitive SPH |
| primitive indices | ISBEWR.MAP.O.U8 [4 + 3 p + i] |
| primitive count | ISBEWR.MAP.O.B32 [RZ+0x3]; no vertex count is written |
| draw parameters, buffers | constant banks as in vertex programs (c[0][0x670], c[0][0x680], banks 3 to 5), LDG/STG |
A mesh program after a task program, 8 invocations, 32 vertices of position and generic 1.xy, 16 primitives with generic 0.x per primitive:
ISBERD.ATTR.B32 R3, [RZ+0x0] ; this group's index in its task's launch
IMAD R3, R3, 0x28, RZ ; its payload record
ISBERD.ATTR.B32 R19, [R3+0x20] ; payload words
ISBEWR.ATTR.SKEW.O.B32 [R7+0x0], R16 ; position.x of vertex R7/4 (G = 6 words * 0x80 = 0x300)
ISBEWR.ATTR.SKEW.O.B32 [R7+0x180], R6 ; position.w
ISBEWR.ATTR.SKEW.O.B32 [R7+0x200], R2 ; generic 1.x
ISBEWR.MAP.O.U8 [R4+0x4], R9 ; R4 = lane * 6: two triangles a lane
ISBEWR.ATTR.SKEW.O.B32 [R0+0x0], R3 ; R0 = 2 * lane * 4 + 0x300: generic 0.x per primitive
MOV R0, 0x10 ; ISBEWR.MAP.O.B32 [RZ+0x3], R0 ; 16 primitives (lane 0)
Its task program, 32 invocations, one payload record of 0x28 bytes for each meshlet that passes the culling:
ISBERD.ATTR.SKEW.B32 R4, [RZ+0x0] ; workgroup index
S2R R15, SR_LANEID ; IMAD R4, R4, 0x20, R15 ; global invocation
VOTEU.ANY ; POPC R6 (lanes below) ; compacted slot
IMAD R1, R6, 0x28, RZ
ISBEWR.ATTR.O.B32 [R1+0x10], R2 ; payload, ten words
POPC R0, UR5 ; ISBEWR.ATTR.O.B32 [RZ+0x4], R0 ; mesh groups to launch
The game calls DrawMeshTasks(first 0, count 1), and (0, 6) and (0, 30). It calls no indirect mesh draw in the
runs so far, and it binds its mesh programs with stages 0xff. SetGeometryProcessingMode(2) comes before them.
The driver binds the task and mesh stages apart from the others (sdk offsets of the functions:
BindUniformBuffer 0x5db4c0, BindStorageBuffer 0x5dd080, BindTexture 0x5de120, BindProgram 0x5daa80).
Every function takes stages 6 and 7 through the same path as the graphics stages, with a table for each stage:
| Stage | BindProgram bit | uniform buffer group (method 0xe02) | storage buffers in c[0] | handle bank (method 0xe1c) |
|---|---|---|---|---|
| vertex 0, fragment 1, geometry 2, control 3, evaluation 4 | bits 0 to 4 | 8, 4, 3, 1, 0xa | 0x110, 0x510, 0x410, 0x210, 0x310 | 0, 4, 3, 1, 2 |
| task 6 | 0x40 | 9 | 0x670 + 16 i | 5 |
| mesh 7 | 0x80 | 0xb | 0x770 + 16 i | 6 |
The handles have the offsets of the other stages in their bank: textures at 0x20 + 8 r, images at 0x120 + 8 r,
separate textures at 0x168 + 8 r, separate samplers at 0x568 + 8 r. One mesh program reads its textures' handles at
c[2][0x20] and c[2][0x28]. The task programs read their storage buffer addresses at c[0][0x670] and
c[0][0x680], the mesh programs at c[0][0x770] to c[0][0x7b0]. A mesh stage's bindings thus never replace the
vertex stage's: the draw state keeps them apart (DS_TASK and DS_MESH in gpu/draw_state.h), and bank 0 of each
stage is 0x870 bytes.
DrawMeshTasksIndirect gives the GPU two words of the indirect buffer (a GPFIFO entry of 2 words after macro 0x31),
{count, first} as NV_mesh_shader's DrawMeshTasksIndirectCommandNV has them. A compute program writes them in the
same frame. Vulkan's indirect mesh draw reads three, x, y and z, and has no first workgroup, so the renderer copies
the record on the GPU into one of the frame's staging, {count, 1, 1} and the first workgroup a uniform buffer's
alignment after it (mesh_indirect in vk/render.c), which it binds at SNX_VKB_RS of the task or mesh stage: where
the push constant's z has SH_PUSH_GPU_MESH_FIRST, the task program, or the mesh program without one, takes its first
workgroup from there. The copy ends the rendering pass. In the first 3D scene of one game about 30 mesh draws a frame
are indirect; the 3D form's and the multi-draws, which no run calls, are still skipped.
With the mesh draws on, an RTX 2080 faulted in most menu runs: Xid 31 (GPCCLIENT_GCC, reads of addresses that no
memory backs), then Xid 109 and a lost device. NV diagnostic checkpoints put each hang in a draw with a task program,
and the device fault data put the faulting instruction in the task program, at the same address in each run. A task
program that does nothing launched no fault. A task program that reads no constant buffer still faulted. Every
program's outputs are within maxMeshOutputMemorySize. The faults stopped when the two mesh stages saw the
descriptor sets of both, the vertex stage's (the mesh program's) and the tessellation control stage's (the task
program's): vk_set_stages in gpu/vk/pipeline.c. The mechanism inside the driver is not known. After that change,
no run had Xid 31, but 2 of 7 menu runs still hung with Xid 109 alone. That hang also came once with the task
programs emptied, and the checkpoints of that run put it in a draw without a mesh program, so it has another cause.
No mesh draw of 16 menu runs (184,239 draws) goes to a cascade of the shadow map (depth only, 3072 by 3072). Each has
one color target. The programs after a task program draw into the scene's color and depth targets (832 by 466 to 1280
by 720), and the others into a color target alone. The mesh program of 128 vertices after a task program samples a
depth array texture with a compare (TEX.DC), as a program that receives shadows does.
The driver writes Turing macro calls (method 0xe00 + 2 n is CALL_MME_MACRO(n)), not 3D methods:
| Function (sdk offset from 0xbd0c000) | Push buffer |
|---|---|
SetGeometryProcessingMode (0x5e2e10) | 0x8000_0e26 | mode << 16 (IMMD, macro 0x13), 0x8000_0e3e (macro 0x1f, 0) |
DrawMeshTasks (0x5e2e80) | 0xa002_0ea2, count, first (macro 0x51) |
DrawMeshTasks3D (0x5e3320) | 0xa003_0ec8, x, y, z (macro 0x64) |
DrawMeshTasksIndirect (0x5e2f00) | 0x91120002, 0x81900e36, 0xa002_0e62 (macro 0x31), then a GPFIFO entry of the indirect buffer's words |
MultiDrawMeshTasks*Indirect* | a helper (0x5e2830) with macro methods 0x3b40 and 0x3990 |
On the hardware the macros end in NVK's sequence (nvk_mme_build_draw_mesh): SET_DRAW_CONTROL_A with points,
then DRAW_VERTEX_ARRAY_BEGIN_END_A (0x9c) with 0 and the task count x * y * z. Mesh state is SET_MESH_CONTROL
(0x453), SET_MESH_SHADER_A (0x454: topology, most vertices, most primitives), SET_MESH_SHADER_B (0x455: shared
lines, invocations) and SET_MESH_INIT_SHADER (0x456: invocations, local lines, payload lines) (clc597.h). The
runtime takes the API calls and needs none of the macros.
Made from docs/platforms/nx/ounce.md at 69237645142c. GPL-3.0-or-later.