nvnBootstrapLoader and nvnDeviceGetProcAddress. The loader
(gpu/nvn/nvn_loader.c) puts the runtime's handler in each one's dispatch slot (gpu/nvn/nvn.hook), so the game's
NVN driver never runs past its own name lookup. A game without nvnBootstrapLoader draws nothing.gpu/nvn/nvn_cmd.c). A queue submission
promises its fences and queues the replay on the GPU thread (gpu_call), and returns at once.gpu/nvn/nvn_replay.c): NVN's state makes the renderer's draw state
(gpu/draw_state.h), and the draws, clears, dispatches and copies go to g_renderer (gpu/renderer.h). Shaders:
Maxwell SASS -> SPIR-V (gpu/shader/).stream_incr lands compute writes in guest memory before incrementing the syncpoint.gpu_call).
present_buffer uses the matching RT and the crop, or converts guest memory.A program that writes its own command buffers (an OpenGL game, homebrew) submits them with /dev/nvhost-gpu's
SUBMIT_GPFIFO (gpu_submit_gpfifo in hle/services/nvdrv.c). The ioctl promises the fence and queues the entries
(gpu_submit), and the GPU thread runs them through the Maxwell front end: gpu.c pulls the GPFIFO and hands each
method to its engine in gpu/maxwell/. The 3D engine's registers make the same draw state as NVN's
(maxwell/draw_state.c), and its draws go to g_renderer. The macro engine (maxwell/mme.c) interprets every
macro, with no macro HLE or JIT.
The shader programs a game ships are translated at startup, on the renderer's shader file thread rather than the GPU
thread, into <id>.<driver>.vkshipped (prepare_shaders: before the game's first thread runs, behind main.c's loading screen,
or in the background as it runs). gpu/shipped_pass.c walks the RomFS and the executables' segments, and
gpu/shader/shipped.c finds the programs by NVN's code wrapper (or a bare NVN shader file's layout) in their bytes,
and in the Yaz0 SARCs whose names list a shader container. In a BNSH, a program's code record names its control
section, which gives where its constants (the bank 1 that its draws bind) start in its code area. The translation
reads the jump tables of BRX from them, and a draw takes such a shader only while its bank 1 holds the same words.
gpu/vk/pipeline.c translates each into the file, which a draw's lookup reads from when it has no shader of its own. The files the walk found nothing in are kept in
<id>.vkscan by their name, place and size, under the hash of the walk's sources (cmake/ship_walk.cmake) rather than
the build, so a new build or driver reads only the files that hold programs again.
guest_vulkan)A game that links NVIDIA's Vulkan driver (one module exports the loader's vk* entry points) runs that driver as
recompiled code by default. It writes Maxwell command buffers into the GPFIFO above. With the experimental
guest_vulkan setting, gpu/gvk/gvk.c puts a function of its own into the dispatch slot of each entry point that the
driver's module (the one that exports vkGetInstanceProcAddr) exports. gpu/gvk/gvk.hook routes the game's direct
calls to them, and a module recompiled before that list stops the game. gpu/gvk/gvk_api.c executes the calls on the
renderer's device and graphics queue after compatibility fixes. The driver's code then runs only for calls that no
slot takes. A host without memory import (gvk_check_device), a 32-bit game and a big-endian host give the slots back,
and the game's own driver runs. Save states cannot hold GVK objects.
Calls and memory:
gvk_in translates their
pointers from a table of structure fields.VK_EXT_external_memory_host). Where it cannot (RenderDoc takes no host memory), the host's own memory is exported
as a dma-buf and mapped over the guest pages, and linear images in it use the linear DRM format modifier.VK_EXT_mutable_descriptor_type), each guest descriptor pool has a
twin in host memory, and each set a twin in it. A write goes to the set and to its twin, and a copy reads the
source's twin. RADV keeps descriptors in write-combined device memory, where a copy's reads are uncached.VK_EXT_debug_report entry points that the guest driver does not export. Guest
debug messages reach guest callbacks. Host validation messages stay in the runtime log.vkUpdateDescriptorSets.gvk_check_device, after the device
check, so a host where gvk cannot run falls back to the game's driver whatever the recompile.What the console's driver takes and the host's does not:
GENERAL for most layouts, keeps discard transitions, and adds
the stages that barrier access masks require.gpu/gvk/gvk_spirv.c mends SPIR-V. A member's ArrayStride moves to its array type, a matrix with no order becomes
column-major, and an index into a buffer array that can vary by invocation is marked NonUniform. A pipeline that
blends with the second color can use a twin of its fragment module with that output at Location 0, Index 1.Present: the swapchain's images are host images, and a present blits one into the renderer's window
(present_image). It applies the android::Surface crop rectangle from vkCreateViSurfaceNN, scaled to host pixels,
so that dynamic resolution fills the display. If the next present has reached the display queue, acquire waits for it
within the application's timeout. Otherwise the renderer's copy already released the guest image from the display.
Resolution scaling: the resolution setting is a whole factor for GVK, none below 1.5×, otherwise the nearest integer.
It is at most the factor at which the largest swapchain the game can make (1920x1080, maxImageExtent) fits the
host's framebuffers (maxFramebufferWidth and maxFramebufferHeight, within maxImageDimension2D): 8 on an RX 9070,
whose images reach 32768 but its framebuffers 16384. A target gets a shadow only where it fits them too.
GVK scales an image by its use, not by its size or usage flags (one game gives every texture COLOR_ATTACHMENT).
gvk_spirv_scaled_size), because
one game normalizes indirect-texture and haze coordinates by textureSize. GVK keeps the last 16 bytes of the push
constants for it, and tells the game a limit of 240. Each descriptor set keeps a mask of the bindings that hold
images at the scale. At each draw, GVK pushes the bits of the images that the pipeline's queries read, and the
queries divide width and height by 1 + bit * (scale - 1).gl_FragCoord stays in the host's pixels. The games seen read only its depth.Invalidation: host write tracking + mem_unmap -> gpu_mem_changed. Vk treats zeroed unmap/heap-return ranges
as written at the next cache check. Write tracking (plat_ww_scan) is userfaultfd's asynchronous write protection
with PAGEMAP_SCAN on Linux 6.7 and later, and the reservation's write watch on Windows. Every other POSIX host
(macOS, FreeBSD, Android, older Linux; write_tracking=1 on any Linux) protects the pages a scan reported and takes the
first write to each in the fault handler, which opens the page again. A system call can't fault into the handler, so
the runtime opens what the kernel will write before the call (plat_ww_open, next to own_acquire). With
write_tracking_hot_pages at 1, or 2 (Auto, the default) a page the scans find written twice in a row stays
writable and reads as written at each scan, for 32 scans, without its fault. A cache takes a page reported so as one
more check of its bytes, but a render target's write-back keeps memory's bytes on the pages written since its
baseline: each baseline protects the target's hot pages again first, at every address of them (vk_ww_cool, after the
writes so far were taken in).
Renderer.save: optional pipeline-cache persistence every 300 frontend ticks (~5s) + exit, concurrent with execution.
Exit skips renderer teardown and guest-thread joins.
Each NVDEC/VIC fd owns a host1x_open channel, registers and syncpoints; NVDEC also owns a decoder.
NVDEC writes guest surfaces; VIC composites output.
Made from docs/dev/architecture.md at 69237645142c. GPL-3.0-or-later.