Integrate GTA renderer and GPU optimizations #2469
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2469
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2469"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@danekbiglike on GitHub · 2026-11-20 18:57 UTC · original
danekbiglike:gta5-rt-integration-20261120→main· +196686 −4196 · 327 files · 246 commits · openIntegrates the GTA renderer through
4c4eaac78with upstreama1fc5ae, together with GPU transfer and ray-tracing changes. The final diff excludes launcher changes.The integration carries original commit authorship and co-author credits. It includes substantial work by TheCruZ, chenxiao07, Senaxx, Jetsku and other contributors. The complete authorship is recorded in the commit history.
Reviewed simnJS/KytyPS5-GTA, Erlou93/KytyPS5-Erlou and Jetsku/KytyPS5. The reviewed simnJS engine changes and several GPU fixes were already present. Other experimental changes require independent compatibility and performance validation.
Validation on Windows, Ryzen 7 3700X and RTX 3090:
This is a large integration across 327 files. The unresolved failures and compatibility with other games require investigation before merging. Maintainer review of scope and whether to split the changes would be appreciated.
Submitted by Danek (@danekbiglike).
GTA V (PPSA04263) pixel shader 0xf6b18542ea0e938a, drawn at the car dealership, builds S# word 3 from data resource tracking cannot follow ("GetSamplerResource dword 3 is not a valid runtime value") and the emulator exited. Word 3 only holds the border color pointer and type, so sampling inside the texture does not depend on it. When only word 3 is untrackable, keep the runtime-valid operand of an OR that mixes lane data into it (the user-data border fields), or use a transparent black border, and print a warning. SampleAdjust scratch bits ORed into the word are dropped the same way instead of failing. The existing console warning becomes a "[HACK] sampler border color word changed" notice in the normal log (shader hash and pc) (src/common/hackNotice.h): the first application of each distinct case, then a summary every 10 s.The Windows job configures with KYTY_NATIVE_V3 and with KYTY_PGO_USE set to pgo/gtav.profdata; ThinLTO already comes from CMAKE_INTERPROCEDURAL_OPTIMIZATION. The profile was recorded with LLVM 22.1.8 and an older compiler rejects it ("unsupported instrumentation profile format version"), so the job installs that LLVM before configuring. A profile that is missing or that llvm-profdata cannot read builds without PGO and a warning instead of failing the release. macOS and Linux keep their default code generation.GTA San Andreas - The Definitive Edition crashed at random on the main thread in TSet<int32>::UnhashElements (0x900f9c2f0), called from FAsyncPackage::Event_ProcessImportsAndExports when it resets ExportsInThisBlock: a read at 0x20 = Data + 2 * 12 + 8 with Data == 0. The function is a frame-pointer leaf ("push rbp; mov rbp, rsp; push r15..rbx") that keeps the element pointer at [rbp-0x40], 0x18 bytes below RSP, and reloads it on every iteration. The registers show the previous iteration had read the same pointer successfully, so the slot was overwritten between two loads: a host exception taken on the store to the hash table makes Windows write its exception frame under the guest RSP. The red-zone patcher only recognised [rsp - n] operands, so functions that reach the red zone through RBP were never protected. Track RBP - RSP through each function (mov rbp, rsp, pushes and pops, mov/lea rsp from rbp and leave) and treat [rbp + d] operands that land below RSP like the RSP-relative ones in the liveness analysis.Demon's Souls reads (and overwrites) GPU results page by page: of its ~105 read faults a frame on GPU-written pages, 100 hit the page right after the previous one, and ~134 write faults behaved alike. Each page was a fault, an urgent command and a readback: ~110 us on the execution thread and ~400 us for the guest thread, every page. A readback for a guest fault now also takes the GPU-written pages that follow it in the same buffer, up to 256 KiB, while their writes were already submitted (or all of them when the faulting bytes force the GPU to drain anyway), and no GPU-written image covers them. Internal reads keep reading exactly what they ask for. Urgent commands drop from ~197 to ~69 a frame, and fewer readbacks wait for operations still being recorded, so the submissions made to shorten those waits drop from ~2,000 to ~340 a frame. In game 7.8 -> 9.0 fps. A page whose GPU-written bytes were all read through the mirror stayed GPU-dirty with nothing left to download, and a later guest write there stopped the emulator ("CPU dirty state conflicts with GPU dirty state"); the readback releases such pages too. Also: read ahead the GPU-written pages of a guest readback across pages without GPU writes. GTA V in Fidelity mode (Trevor on a buggy in Sandy Shores, native ray tracing) reads back a buffer of a few hundred pages a frame from its job threads, page by page in order. On many pages the faulting bytes are fields the CPU wrote between GPU-written ones, so the read-ahead, which looked at the faulting bytes only, read just the faulting page, and it stopped at the first following page without GPU writes. That made ~60 readbacks a frame, each waiting for the whole GPU backlog: ~35 ms a frame summed over the job threads, which then start the next frame late and miss the 30 Hz flip. Decide by the GPU writes of the faulting pages and skip the following pages without GPU writes (they need no download), still stopping at pages an image owns, at writes not submitted yet and after 256 KB. Trevor standing still: 20.8 -> 22.8 fps; readbacks 1250 -> 205 a second.Marvel's Wolverine's ray-tracing compute 0xe6d76d24f59f8015 reads the textures of each hit group through two pointers the GPU chooses: a call table row names a record, the record holds the V# of a T# table, and the T# or S# is read from that table. The translation stopped at pc 0x2fa0 with "GetImageResource dword 0 is not a valid runtime value". Record tables (TryMakeRecordTableDescriptor): the handle's key is the first word of the table V# the descriptor is read through (the value the GPU itself uses, no Phi mirror) and the element travels in its second word; the materialization maps each record table's first V# word to the block [count, ordinals] of its elements, reading only the rows that name the inlined callee's address. The unwritten lanes of an SGPR spill VGPR are UndefU32 (kept in the Phi, no substitution), and NativeDescriptorSource follows S_MOV and V_READLANE/V_WRITELANE copies in every descriptor source. e6d7 now translates, tracks and validates. Its first dispatch still reads a BDA page the buffer cache does not hold yet and hangs the GPU. The record tables of cs e6d76d24f59f8015 and cs 1a04c58a9fbc2052 then needed hardening in the materialization of this branch: - Candidates and table V#s were found with a linear search over the ones already seen: 88 thousand candidates from about 33 thousand distinct record tables, a quadratic cost (billions of comparisons) paid on every dispatch, so the title scene ran at 1-2 fps. They are now found through hash tables keyed by their descriptor words; the specialization is the same. - The element table of a record is read in one read and has its own limit of 2M elements: a record names a scene-wide sampler table of 720 thousand elements, above the 65536-candidate limit, which closed Wolverine on New Game. - Two records may name V#s at one base (a scene-wide table and a range of it, same first word): for the keys both cover they give the same elements, so the longer table serves both. Tables with different bases whose first words match still fail ("two record tables share the first word of their V#"). - A record table whose first or last word is not in guest memory gives the shader no elements and its key reads the null descriptor: one row of the 360 thousand names a record whose V# words are floats (a base outside guest memory and a size of a gigabyte) that the GPU never selects. Also: keep record-table candidates in the resident image heap. Marvel's Wolverine (PPSA03671) closed on its second start with "pipeline needs 2917028 sampled images" for its ray tracing shader cs 1a04c58a9fbc2052. The shader reads material T#s from tables that GPU-chosen records name, once per inlined hit group. Every image root materialized its own copy of all the candidates of those tables, padded to a power of two, as descriptors of the pipeline layout. Their count and order were part of the shader specialization, so cs e6d76d24f59f8015 (88 thousand candidates) got a new 3-minute pipeline compile whenever streaming changed them, and the host resolved every candidate again on each dispatch. Sampled roots of such tables now keep their candidates in the resident image heap. ImageHeap::AcquireList() interns a root's candidates in the view of the root's profile, which roots of one profile share with their elements and kinds, and keeps them in device slot words the root owns: a null slot, one slot per candidate and a trailing null slot. The blocks the records name hold slot numbers instead of ordinals of materialized descriptors; the shader reads the entry from the root's slots, whose count and address precede the record mapping, and selects the heap kind, as for heap tables. When the image behind an element changes or its memory is unmapped, the root's slots take a new element, as table slots do, so no dispatch reads a descriptor of a replaced image. The descriptor layout no longer depends on the candidates, and the host resolves only new elements. Hosts without the heap keep the materialized candidates. RenderExecutor::DispatchIndirectThreads() neither began a heap draw nor rebound the heap before writing descriptors, unlike the direct and indirect dispatch paths, so a heap program dispatched with GPU thread counts read elements whose descriptors were never written and Wolverine lost the device ("BufferCache: readback queue submission failed") six minutes into its first start. It now calls ImageHeap::BeginDraw() before resolving the program and ImageHeap::Rebind() before rebinding its images, as the other paths do. Also: keep flattened SRT offsets across small table size changes. Marvel's Wolverine (PPSA03671) compiled its ray tracing shader cs 1a04c58a9fbc2052 again on every start, and the driver pipeline cache never matched it: a 1.4 million word module whose pipeline takes the driver about three minutes, seven variants per start. Every start gave it a different module, because flattened SRT offsets reach the shader as constants and two variable-size regions moved them: the blocks of its record-table roots, one word per candidate (14537 candidates on one start, 14539 on the next), and the mapping of its bindless image table, one word per entry (14535 entries on one start, 14547 on the next). With stable indirect layouts both regions now round up to 4096 words, as the key mappings and the descriptor children already have a stable size, so the programs and their pipelines stay the same until a table crosses a 4096-word step. Record-table blocks also go after every other flattened SRT region, and the key mappings name them by data, so their size moves no constant: the blocks of one record-table root grew by three 4096-word steps between two starts, which moved every later flattened SRT offset the shader takes as a constant. Sampler roots pad their candidate children to a power of two with stable indirect layouts, as image roots already do, because the number of sampler candidates per root changed the size of its sampler arrays.Wolverine's ray-tracing compute 0xe6d76d24f59f8015 calls one of 20 hit-group functions from its traversal loop. The expansion inlines them into one program, and in a single SPIR-V function (1.6 M words) the NVIDIA compiler ran past 36 GB and several minutes without finishing. The emitter now gives each inlined call target its own DontInline function, which the compiler builds separately. The region of a target is every block its entry block dominates, leaving through edges to one block; the function receives in a struct the values defined before the region that it reads (also through operands without a SPIR-V value, such as resource handles) and returns the values the exit block's Phis take on its edges and the values later code reads. Main calls it where the entry block was and branches to the exit block, whose Phis take one operand per region. Values computed at function entry (GDS length, buffer-backed LDS base, buffer offsets and sizes) are recomputed in each function, and per-invocation memory (scratch, function LDS) becomes Private when a program has such functions. Programs without inlined calls emit as before. e6d7: main 245 K words and 20 functions of 8-107 K words. The memory helpers (get_bda_pointer, the runtime-V# buffer loads and the conversion that switches over every buffer format, 7.4 K words) are inlined at each use. In Wolverine's 0xe6d76d24f59f8015 the inlined hit-group functions use them from hundreds of sites (the largest function: 234 BDA pointers, 35 buffer loads), and the NVIDIA compiler inlining every copy took minutes and gigabytes per function: one 31 K word target with main 217 s and 6.7 GB, and the whole program did not finish in 10 minutes and 25 GB. Programs with inlined call targets now keep one DontInline copy of each helper (other programs keep inlining them): the whole program compiles in 166 s and 5.5 GB. Also: pass the values an outlined call target leaves unchanged to its function. Marvel's Wolverine's 0x1a04c58a9fbc2052 (a ray tracing compute program with call table hit groups) did not compile once the native ray tracing patch changed its control flow: "CompositeExtractU32x4 is read by an outlined call target without being passed to it". The exit block of an outlined call target takes a value from one of the target's edges that the target does not define (the value comes unchanged through the target: here a result of the native traversal's selection), and only the values the target's instructions and conditions read were collected as the function's inputs, so the Phi's incoming value was defined inside the function out of nowhere. The values the exit block's Phis take from the target's edges and that are defined outside it are inputs of the function too. Also: dispatch the indirect calls of a program with outlined targets with one switch. The expansion of a call table (ShaderFunctions.cpp) tests, for each target, the two words of its address against the register that holds the callee and calls the target on the first match, trying the next target only when no call was made. Emitted as the structured control flow of the program that is a nest as deep as there are targets: each level an `if (vote(hi == K.hi)) { if (vote(lo == K.lo)) { call } }` followed by two merge blocks that give every register of the program (90 of them) a Phi, plus a merge per level that falls into the previous one. Marvel's Wolverine ray tracing compute 0x1a04c58a9fbc2052 has up to 100 targets, and the compile of its nest costs the NVIDIA driver 25 % of what is left after the two commits before it (230 s and 5.4 GB for a module of 8.1 MB with the nest, 174 s and 5.0 GB with the switch). The tests are about the whole wave (votes) and the first level that matches wins, so the program now computes what every level tests first (the loads of the table are reads), selects the index of the first match and branches on it with one OpSwitch, into the calls of the outlined targets, to one merge with one Phi per register. The Phis of the merge blocks of the levels are what the program had before the call until a level matches, and the Phis of the join take, for each level, the value after the call of that level (the outputs of its region, or what the levels after it add on the way out). Programs whose call table has a different shape are emitted as before. Verified: the 3-target call table of the compute tests runs on the GPU in wave32 and wave64 with the switch, and the module of 1a04 validates.Marvel's Wolverine (PPSA03671) compiled its ray tracing shader cs 1a04c58a9fbc2052 again on every start (about three minutes in the driver per variant): the module differed even when its specialization matched. The call expansion compares the target of each GPU-chosen call against the addresses of its candidate functions, and moves return and GETPC addresses into registers, all as literals. The game loads most of its hit-group functions at a different address on each start, so the expanded code, and with it the program and its pipeline, changed. Addresses in the expansion are now runtime words: the code holds the index of a word, the shader reads the word from the flattened SRT after the walked SRT words (ReadCallWord, one load per use), and the pipeline cache passes each refresh's words to the materialization. Call targets follow their code instead of their addresses, so the expanded program is the same wherever the functions are loaded, and moving them no longer retranslates the shader. Also: let call table targets with the same code share one body. Gran Turismo 7's any-hit call table (shader 0x63bebca1b79e1d5c, V# 09776020 001000ec 00002976 00005204) has 10614 rows of 16 bytes naming 1695 distinct functions, the most used one in 1825 rows. The expansion gave each address a body of its own and stopped at 256 addresses ("shader call table exceeds the bounded target count"). With runtime words the targets are grouped by their exact code (a function that reads its own address keeps a body of its own); each address compares both words and branches to its group's body, and the 256 bound counts bodies, with up to 4096 addresses. Without runtime words every address still has its own body. InlinedCallBody::aliases carries the other addresses of a body into PointerTable::functions, so the descriptor tables read through the records of any of them are materialized. GT7 still has 352 distinct bodies among the 569 targets the call keeps, more than the bound.In Fidelity mode GTA V (PPSA04263) builds the four TLASes of its ray tracing passes every frame in its BVH compute queue: 18 shaders, each dispatched once per TLAS (9df701ab41f8ed18 ... 54ec6ec2689fd4c4), several of which wait for the GPU. 9df701ab41f8ed18 alone kept the execution thread waiting about 13 ms per frame: it reads the BLAS headers the refits just wrote on the GPU. With native ray tracing, the stage is replaced by one native build per TLAS (hle_tlas.comp): the command processor drops the stage's dispatches (from the first instance list to the last build, per queue; other shaders keep running), keeps the instance list of each build (the V# at s[6:9] of 9df701ab41f8ed18, 96-byte records the game's CPU writes: BLAS address, mask and flags, user data, object-to-world matrix) and the TLAS address (s[0:1] of 54ec6ec2689fd4c4), and after the last one a host command records the builds. Each build (one workgroup, up to 4096 instances, an empty list making an empty TLAS) writes the game's format into guest memory: the header, a 4-wide box32 tree over the instances sorted by Morton code (root at header + 256) and the 128-byte instance records (world-to-object and object-to-world 3x4, BLAS address with the flags the game derives from the instance and the BLAS header, mask, user data). The header depends only on the instance count, so the host also writes it to the backing: the RT shaders' resource tables read it without a readback. Checked in game against the game's own builds run side by side, standing and driving (80k instances): the instance records are the same (world-to-object within 2e-5) and every instance box holds the game's leaf box but for one instance in a few frames, by 0.3 mm (a few ulps of margin cover the different rounding of the transformed boxes). Shadows and reflections match; no hang in 300 s runs standing and driving through the city. [HACK] Two parts are cuts, and each reports a [HACK] notice when it happens: a list of more than 4096 instances builds a TLAS of its first 4096 (one workgroup builds it), and a build without a list or a TLAS address, or with records shorter than 96 bytes, is skipped, so the TLAS keeps what it held (the game's own build was dropped). Also: let the game build the TLASes whose lists the native build cannot read. With --native-raytracing the command processor drops the dispatches of the game's TLAS builds (Psr_Gpu_TopLevelBvh_Build) and hle_tlas.comp builds each TLAS in one workgroup, from instance records of 96 bytes, up to 4096 of them. The list was checked only after the build's dispatches had been dropped: a longer list made a TLAS of its first 4096 instances, and one with shorter records or without an address made none, the TLAS keeping what it held ([HACK] notices). GTA V's lists fit, so it never got there. The list (address, stride and count at s[6:8] of psr_morton_compute_bounding_box_for_instances) is known at the build's first dispatch: a list the native build cannot read now leaves the game's own build running, from that dispatch to its last pass (psr_collapse_to_qbvh_simple_top). Still a [HACK] notice: a build without a TLAS address, and a list the native build cannot read that comes while other builds of the stage are already native (their dispatches were dropped). Also: replace the TLAS builds of GTA V 01.005. GTA V 01.005 (PPSA04264) links an older build of sce::Psr (generation Base252, build J02232310) whose shaders the emulator recognizes by their code. With native ray tracing only its BLAS refits were replaced: its three TLAS builds of every frame ran as the game dispatches them, about 25 dispatches per TLAS (sort, rotations, scans and compaction) that wait for the GPU, only for the native traversal to walk the result. Its top level stage runs the same passes as the newer build with fewer of them (no indirect arguments, valid instance indices or vec2u scans), and its last pass, collapse_to_qbvh_simple, also ends its BLAS builds. The TLAS has the same box32 nodes from header + 256, but another header (version word 0xbbe6e938, 0x24 at +24, the records at header + [header + 40], the count plus 4 at +80 and the count at +116) and another instance record: the BLAS address as is at +0, the world-to-object 3x4 by columns at +8, the root at +56, the input's flags word with the flags in its low byte at +60 and the object-to-world 3x4 by columns at +64. The top level passes of Base252 are now listed, its list is taken from the V# at s[4:7] (count at s6) of morton_compute_bounding_box_for_instances, and hle_tlas.comp writes either format. A pass of the library the replacement does not know inside the stage still stops the replacement. Also: recognize GTA V's sce::Psr BVH shaders by the name they register. The native TLAS builds and BLAS refits replace dispatches of sce::Psr, Sony's ray tracing BVH library that GTA V links statically, which they recognized by the hash of the shader code: 18 hashes of the top level build and 4 of the triangle fan refit of GTA V. Those hashes only hold for GTA V's copy of the library: the shaders carry compiler metadata, so no Psr shader of Astro Bot or Wolverine has the same bytes, although Astro Bot's library is the same generation (its TLAS build and fan refit shaders have identical instructions or the same user data layout). The library registers every shader with the driver under its name: sceAgcDriverRegisterOwner("sce::Psr") and, when it succeeds, sceAgcDriverRegisterResource for each of its 460 compute shaders (code address, size and name such as psr_qbvh_fan_refit_async). GTA V's Agc::Toolkit does the same for its own shaders. Those driver functions always failed, so the games skipped the registration. Owners and resources are now registered, with handles, and can be unregistered one by one or with their owner. The name of each resource is kept by address: ShaderRegisteredName() returns the name of the shader whose code starts at an address and ShaderNameRegistered() whether a name was registered. The games only check that the calls succeed. The command processor now looks the shader of a dispatch up by name (psrShaders.h): psr_morton_compute_bounding_box_for_instances opens the TLAS window and psr_collapse_to_qbvh_simple_top closes each build, psr_qbvh_fan_refit_copy_dispatch_args opens the refit window and psr_qbvh_refit_bottom_level closes each refit. The user data the HLE reads (instance list V# and count, TLAS address, BLAS address, geometry table, geometry index) has the layout of the generation of 460 shaders that GTA V and Astro Bot link; the generation is told by the names the library registered (shaders the next generation, Wolverine's, removed or added), and a library of another generation keeps every dispatch emulated. Two pairs of names have byte-identical code (psr_morton_initialize_indirect_args_top and its _trinity copy, the _uint32 and _float descriptor initializations of the scan), which the hashes could not tell apart: both names belong to the stage. Also: recognize the shaders of sce::Psr by their code when the game does not name them. The BVH builds and refits of sce::Psr are replaced with native ray tracing only when the game registers the library's shaders under their psr_ names (sceAgcDriverRegisterResource), as GTA V 01.011 does. Other titles do not: GTA V 01.005 registers them without the prefix and ASTRO BOT registers none, so their passes were never recognized. Without those names, a shader is now recognized by its code. Its fingerprint is the sorted multiset of its instructions up to s_endpgm, each reduced to its opcode, operand kinds, constants (not the ones added to the program counter), modifiers and memory offsets and formats; registers, branch targets, order and waits are left out. It is looked up in a table of the fingerprints of every shader of the builds of the library the emulator knows (generated from the shader tables of the games' executables), for the build whose compiler revision is in the footer of the binary: the same code can be another generation's pass (Gran Turismo 7's build shares 91 fingerprints with GTA V's), and a build that is known but not measured is logged and emulated (ASTRO BOT's build of Base460: its 460 shaders are in the table, with the same passes, but not enabled). Only the shaders of an accepted build are fingerprinted, once per address. An opcode enters the fingerprint as its decoder enum value when the table was generated: an opcode the decoder learned later (upstream's V_CMP_U_F16, inserted in the middle of the enum) counts as the unknown instruction it was then, and the opcodes after it keep their earlier values. By their code, the 460 shaders of GTA V 01.010/01.011's build get the same passes as by their names except 11 copies under a _trinity name that have the code of a kBase pass (GTA V dispatches none of them). Also: stop replacing sce::Psr builds the native build does not know. With native ray tracing, the command processor drops the top level builds and the fan refits of the sce::Psr library (generation Base460: GTA V 01.010/01.011, ASTRO BOT, Nightreign) and replaces them with its own. It recognises them only by the first and last shader of their windows, and drops every listed shader in between. A game that runs another pass of the library inside a window (a build flow GTA V does not use: rebraiding, refittable TLASes, kTrinity BVHs of the PS5 Pro...) would have half of its build dropped and the rest emulated, and its TLAS would be garbage; a window that never sees its last shader would drop the scans and sorts of every later build. GTA V 01.011 in Fidelity runs nothing else of the library inside its 12 TLAS windows (4 builds each) and 12 refit windows of a 30 s run. Nightreign builds a TLAS of one instance on its title screen, whose build takes psr_morton_init_one_instance_root_node (the root node, in the scratch memory) instead of the sort and the hierarchy passes: it is now one of the stage's shaders. So: - the first TLAS window of each queue runs as the game dispatches it, and only shows which passes it runs; - another psr_ shader inside a TLAS or refit window, or any kTrinity shader (the _trinity copy of initialize_indirect_args_top is no longer taken for the kBase one), turns the replacement off for the rest of the session, with a line in the log: the window in progress is completed, later builds and refits are emulated as they are and the BLAS builds are no longer followed (the host finds those BLASes through the top level walk); - psr_morton_capture_memory, the first pass of every build, closes a window still open: the builds and refits that ended are replaced. Also: cache the guest memory HLE builds read through device addresses. The native builds that replace the TLAS builds and BLAS refits of sce::Psr read their inputs (the instance list the game's CPU writes, the BLASes, the refit's vertex buffers) through the BDA page table, and PrepareBda() uploads nothing more before them: the command processor makes each input reach a cached buffer first. It did so with ObtainBuffer(), which answers a read of up to 16 KiB of CPU-written memory from the stream buffer, without creating or updating the cached buffer the page table reaches. Draws and dispatches bind the buffer ObtainBuffer() returns and reach other memory through device addresses only after FindBuffers() and the BDA synchronization, so only these builds read zeros (no cached buffer) or older data there: a TLAS from a list under 16 KiB (GTA V 01.005 builds TLASes of 8 and 14 instances every frame) has every instance inactive for the native traversal, and a small vertex buffer the CPU writes (ASTRO BOT has BLASes the CPU writes) refits to stale or collapsed triangles. BufferCache::PrepareDeviceAddressRead() caches a range in a buffer the page table reaches and uploads the CPU writes it does not hold, as ObtainBuffer() does for larger reads. The HLE builds take every input they read through it: the instance list, the header and root node of each BLAS an instance references (its flags and bounds) unless the GPU wrote them, the vertex buffers and the header of each refit BLAS.ASTRO BOT (PPSA21564) draws broken ray traced shading during the arrival flight to Go-Go Archipelago. Its pass cs 0x1fc433499277ce93 traces TLASes that the game writes with the CPU (three that it rotates through, 101 instances each), and their last instance records lie on a caching page that no buffer covered. The TLAS walk found that page missing, left the context invalid and let the dispatch walk the guest BVH, counting on the guest's reads to get the page cached. They never did (the rays reached only the records before it): every dispatch of the level walked the guest BVH, read zeros there and ran into the loop exits of FinishBdaLoopExits. With 1.19 the age collection also released buffers that only the walks read ("buffer released by age reached again by a device-address fault"). The TLAS and BLAS walks now record the pages without a buffer that they read in the fault buffer, as the device-address accesses of guest shaders do, so that the host caches them for the next walks and pins them against the age collection. Pages with a buffer are not recorded as used: a load of the use bitmap in each read cost GTA V's walks in Fidelity about 7 % more GPU time (40 us of 630 per preparation); recording the faults costs nothing measurable. A walk that finds part of the TLAS, its header included, in memory that is not cached yet publishes what it read: the rays miss the rest for that dispatch instead of a guest traversal over zeros. The "[RT]" summary reports those walks apart from the ones whose header is not a TLAS. Also: cache a guest TLAS before the dispatch that reads it. ASTRO BOT (PPSA21564) writes the TLASes of each level with the CPU into memory that no other GPU work reads, so the first dispatches over a new one found no buffer there. In Go-Go Archipelago (cs 0x1fc433499277ce93) the first walk of each of the three TLASes of the flight found no header, and a pass of 64 dispatches in the first frame on the island, over a TLAS of 4242 instances, found none in all of them; without native ray tracing, the guest's own traversal read zeros instead. A BLAS that the CPU wrote too (before the level) was read as zeros the first time as well. That pass also got a host TLAS of the size of the source's previous one, 1024 instances: the instance count of a walk is only known after the frame. As for the DMA bases of a dispatch, the memory of the TLAS of a program whose BVH walk the ray tracing patch recognizes (now derived without native ray tracing too) gets cached buffers before the device-address synchronization: the header address (from the flattened SRT, or read through the user data pointer), the box nodes and instance records that the walk reaches, and the BLASes those instances reference, read on the CPU as rt_tlas_walk.comp and rt_blas_walk.comp read them, when the CPU wrote them last. The buffers are pinned, as the ones of device-address faults: the walks do not record their use. Memory the GPU wrote (GTA V's TLASes) is left alone: about 0.7 us per ray tracing dispatch there. The instance count read there sizes the host TLAS of the dispatch, and the "[RT]" summary reports the walks that do not fit the host structures.GTA V (PPSA04263) Fidelity binds two 4K depth targets as R32_UINT storage images in CS 0x24cbc249a5cf541a, in most frames, and their stencil planes as 8_UINT storage images in the same dispatch. Vulkan has no storage depth or stencil images, so the texture cache converts: it creates an R32_UINT image, copies the depth into it and deletes the D32S8 image, and the depth target that follows converts back into yet another new D32S8 image. Deleting the depth image deleted its stencil association too, so the stencil binding of the dispatch found no image: a new R8_UINT image was created and uploaded from guest memory, 8.3 MB that hold no stencil (the stencil is never written back), the stencil the game rendered was lost, and the stencil the dispatch wrote never reached the new depth image. The dispatch cost the execution thread ~0.9 ms, and every conversion created two 4K images. The image a depth/color conversion replaces is now kept, unregistered, instead of deleted, and the conversion back reuses it; a depth image keeps its stencil aspect and stencil associations meanwhile. A texture or storage image of the stencil plane of a kept depth image binds a persistent copy of its stencil aspect, refreshed on the GPU when the depth image was written since and written back into it when the depth image returns. Kept images are deleted after 2048 submissions, beyond eight, or when their memory is unmapped. The 512x2048 shadow map that GTA V renders as R32_SFLOAT and samples as depth converts twice per frame as well and reuses its two images the same way. Keeping a depth image and taking it back change what a lookup of its stencil planes finds (the depth image, or a copy of its stencil) while nothing is registered or deleted over the planes: both count as changes of the image set over the planes, so the lookups remembered over them (the texture cache's exact lookups, bindless table elements) are made again. SAROS (PPSA07631) binds a stencil plane as a texture and, in the same dispatch, the depth bytes in a color format after it: the conversion kept the depth image, and the stencil binding, looked up again, took the remembered lookup of its plane back to the kept, unregistered depth image and ended the emulator ("texture requires rediscovery before final acquisition").GTA V in Fidelity mode with native ray tracing, driving: the execution thread waited 95-110 ms per second for the GPU. The DispatchIndirect of cs c421273ce118f4a5 (a pass of Psr over the nodes of a BVH) builds two V#s, s[48:51] and s[24:27], as {s6, s1 | stride 64, the dword at s[6:7] + 0x58, format}: the record count is in a header of the buffer itself, which the BVH build before (cs cab98b9b1a31a38e) writes on the GPU. Resolved ahead of execution, that dword still held stale bytes; the execution thread read it again to bind the buffer's range, a load from a GPU-owned page that waits for all queued GPU work (~11 ms), and it always differed. Such a self-sized buffer (a V# whose base is user data and whose record count a scalar read takes at a fixed offset of that same base) is now accessed through device addresses in compute shaders, as the V#s a shader selects at runtime: its V# words stay in the shader, so the record count is a flattened SRT dword (copied on the GPU when the GPU wrote it) and the shader checks the V#'s own bounds, as the hardware does. The host never reads the header. Before the dispatch it caches the first 64 KiB from the base (other pages are found through the buffers that hold them, or fault and get cached, like any device-address access), and the pages the stores wrote come back through the write bitmap. Only V#s whose every use is a raw load or a raw DWORD store take this path; the others keep their binding.Resident Evil Village hung the GPU (TDR, device lost) a few seconds after starting a game. Its BVH builds compact their nodes with a single-pass scan with decoupled look-back (cs af3a06c77cbc67e7): each workgroup publishes {flag, value} with a GLC buffer_store_dwordx2, and the next workgroups spin on that pair with a GLC buffer_load_dwordx2. The load has been one 64-bit atomic read sinced1fe1324c("shader: keep coherent 64bit atomic"), but the store was still two DWORD stores, so a reader could see the new flag with the previous value. The scan then came out non-monotonic at block borders, the collapse pass (cs 213dffe426b387dc) wrote several nodes into the same slot, and box nodes ended up with float garbage as child pointers. The traversal in cs be0b848d2e06ec9b followed one of them into a leaf list it never left. On the guest GPU such a store is a single 64-bit write. Store an aligned GLC/DLC DWORD pair that lies inside its buffer with one 64-bit atomic store through the same 64-bit alias the load uses (release semantics, device scope); any other pair keeps the DWORD stores. This completes the 64-bit atomic read ofd1fe1324c; shaderBufferInt64Atomics is already a required device feature.Marvel's Wolverine (PPSA03671) lost the device right after New Game on NVIDIA ("Illegal Instruction Parameter", nvlddmkm 153): the ray tracing compute 0x1a04c58a9fbc2052 runs its hit groups through a call table, and the first dispatch that executes them with real data dies. Shader Instruction Error sits at the WARPSYNC after the BSYNC of a branch inside a helper function (the switch of indirect_buffer_format_geometry inlined into load_indirect_buffer_*_formatted, or the page table lookup of get_bda_pointer): the driver gives a function called from a lane guard (`if (exec)`) a software convergence mask, and the lanes of a call target that execute reach the helper with masks that do not match. With the loads returning zero, or with get_bda_pointer inlined at every site (which the driver cannot compile: 40 GB), every lane takes the same path and nothing fails; maximal reconvergence, subgroup uniform control flow, a switch-free format geometry, a branch-free get_bda_pointer and arrays without branches alone did not help. In a compute program with outlined call targets, no call of the memory accesses sits under a lane guard any more. LoadBuffer calls load_indirect_buffer_* from every lane (a lane that is not executing passes a V# without format, which loads nothing, and takes the zero result with a Select); the helpers and the other guest memory loads and stores take the pointer from get_bda_pointer_masked(address, active), a new function in which an inactive lane looks up page 0, records nothing and gets no pointer, and only the load or store itself stays under its guard. The per invocation arrays (LDS and scratch, Private variables in these programs) are read at a clamped index and written back unchanged where the lane does not store, so their accesses have no branch either. Other programs emit the same SPIR-V as before. Also: read guest memory through bda_load_u32 functions instead of a diamond at each site. Every read of guest memory through its device address (s_load and s_buffer_load of V#s, T# and SRT tables, runtime-V# buffer loads) was a call of get_bda_pointer followed, at the site, by a compare, a branch around the ConvertUToPtr and Load, and a Phi, and the guard of the access (bounds, EXEC) as one more diamond around all of it. Marvel's Wolverine ray tracing compute 0x1a04c58a9fbc2052 has about 4000 such sites: three blocks and about fourteen instructions each, a third of its instructions, and the NVIDIA compiler takes minutes and gigabytes for it (232 s and 7.4 GB for the 20-target module; 362 s and 13.8 GB for its largest variant without call targets). The access is now a call of bda_load_u32(address), or of bda_load_u32_g(guard, address) where the site has a guard: one function (DontInline in programs of outlined call targets, as the other shared helpers) that looks the page up, records its use or fault and loads, with the guard inside. The loads of runtime-V# buffers (load_indirect_buffer_*) take whether the lane executes as an argument in the same way, and every lane calls them. This is what the commit before it did for programs of outlined call targets with get_bda_pointer_masked: no call sits under a lane guard any more in any program, and loads no longer need that function, which only the stores use. Only the variants a program calls (coherent or not, guarded or not) are defined, after its other functions, so the programs that do not read memory by address are unchanged. GTA V Fidelity with native ray tracing is unchanged: the compile time of its largest compute programs is the same within the noise (14.0 s and 13.9 s, 6.7 s and 6.8 s, 24.8 s and 22.8 s), and the Franklin and Lamar scene runs at 26.6 fps before and 27.4 fps after (3 passes each).Marvel's Wolverine's 0x1a04c58a9fbc2052 closed the emulator ("its call tables do not expand: shader function needs nested calls or unsupported instructions") some 15 to 20 minutes after New Game, once its hit groups were no longer skipped. The call table of that compute lists, besides the hit groups, the address of the code of a pixel shader (746 words ending in `exp null ... done` and S_ENDPGM), which no lane calls but ReadFunction() rejects for the S_ENDPGM, and one such candidate failed the whole expansion. Of a call through a table, a candidate that cannot be read as a function (unmapped, not DWORD aligned, a call, S_ENDPGM, an instruction the decoder does not support) is now left out of the expansion, as a function that overwrites a dependency of the call already is: if a lane did reach its row it would end at the miss trap. A call through an immutable pointer, and a table with no readable target, still fail with the reason of the first one (which names the address); how many were left out, and the first, is logged. A pass of 1500 s after New Game with the first candidate of every table forced out ran without a problem.Gran Turismo 7 01.680 closed in PS5 Pro mode while loading a race: its cs f0ff5e4576313e72 stores DWORDs at pc 0xe38 (buffer_store_dword ... idxen) through s[4:7] = {base, stride 4, count, format} that it builds itself. The base is user data s[4:5] + 0x100 plus an offset it reads at s[4:5] + 0x6c, and the record count is the 32-aligned sum of two counters it loads from a buffer the GPU writes: a list whose length only the GPU knows. Resource tracking took GPU-selected V#s only for loads, and for stores through V#s read from a descriptor table, so it failed with "buffer descriptor is not a valid runtime value". Such a raw DWORD store becomes an indirect buffer store, which the SPIR-V emitter already writes by device address with the V#'s own bounds checked on the GPU. Like a FLAT store, it marks the program as one with address writes, so the pages it wrote come back through the write bitmap, and it records its user-data base, so the host caches that memory before the shader runs.Demon's Souls with a cold driver cache: the manifest's pipelines, and in the helper processes the compute pipelines the driver cache misses, are compiled while the game runs. The game competes with them for the processors and stalls on those it needs first: its loading screen stands still for minutes (436 s with ~570 frames in one pass) and nothing tells the player why. When what is left for the driver would take long (30 s with --pipeline-precompile ask, the default; 20 s with wait, or once the player waits), a thread of the pipeline cache stops the game and shows a small notice in the bottom right corner, drawn by the system overlay: how many pipelines are compiled of those known, the shaders still to translate, and, once a session, the choice. No time left is shown: the game keeps mapping shaders that add to the work. Esc or Circle plays at once, as before, with the rest compiled in the background, and the game is not stopped again in the session. Enter or Cross, or no answer, waits: the game goes on by itself once they are compiled, and stops again for the pipelines it maps later, with the progress alone. Demon's Souls maps its shaders in batches while it boots and loads: after a stop the notice stays 15 s, and a batch of 5 s or more in that time stops the game again under it, so that one notice shows the boot and another the loading, not one per batch. Without the question, Enter and Cross are the game's while the notice shows. --pipeline-precompile play never stops the game. The estimate counts a helper's job that has run t seconds as at least t more, and takes the longest job when it is longer than the jobs shared out among the helpers: a few pipelines that take minutes stop the game too (Wolverine stood minutes at 0 fps before its menu, with no notice, waiting for 1 to 5 of them). And when the guest GPU has waited more than 3 s for a pipeline, from a helper or created on the execution thread, the notice says the game waits for it and for how long, in every mode, also after playing at once; it goes 1 s after the game goes on. While the game waits so, it is stopped as soon as 5 s are left for the driver: it stands still anyway, and the helpers get the processors. It is one notice, under one title, whatever brings it: what the game does decides its text (asked, paused, waiting for a pipeline, or going on again while the notice stays), and its progress counts the pipelines compiled since it appeared. GTA V in Fidelity mode with native ray tracing, cold, showed two: "Waiting for pipelines" with every pending job as the pipelines the game waited for ("60"), then "Precompiling pipelines" counting the same jobs again from 0 of 60, and, the game going on, "The game is paused" for 15 s more; it looked as if the work were done twice. Nothing is compiled twice: in that pass no pipeline was created twice and no module built twice. The game's threads are suspended only while they run the game's own code (instruction pointer in an executable segment of its programs, taken before any is suspended), where they hold no lock of the emulator; one inside the emulator is resumed at once and tried again every 50 ms. Presentation, the helpers and the manifest's threads go on, and while the game is stopped the helpers get the processors it leaves: all but four, up to twice as many as while it runs, as many as half the free memory holds. Warm caches leave nothing for the driver: no notice, and the thread reads a few counters four times a second. No path per draw or dispatch changes. Demon's Souls, cold, the same save: playing at once at the first notice, the game is reached after 490 s (488 to 519 s in three passes with play); unanswered, after 386 s, with 2 notices (the boot and intro, 162 s; the level's loading, 213 s; the game's menu between them) and 24 stops, instead of a still loading screen. In the game, the compile stalls left are of variants the manifest does not list, either way. Warm, with ask: no notice, and GTA V is in the game after 51.0 to 52.0 s (52.0 s with play), ASTRO BOT in the garden after 80.4 s (89.3 s), Red Dead Redemption in the game after 22.1 s (22.6 s). Also: show the pipeline notice while any pipeline takes long to compile. The notice of the pipelines the driver compiles ahead of the game came up only while the game was stopped for them or once its GPU work had waited 3 s for one. Pipelines the driver creates on other threads (background and manifest threads, the helper processes) and shorter waits left the game stuttering with nothing on screen to say why. Count the driver's pipeline creations in progress on every thread of the process (the scope that already names the pipeline of a driver fault) and the helpers' running jobs. Whenever one has taken 0.5 s, or the game's GPU work has waited that long, show the notice in a new Compiling state: it takes no input, says the game keeps running but may stutter, and stays 3 s after the last slow compilation. The notice after the game goes on stays 3 s instead of 15 s, longer while another slow compilation comes; the watch looks every 100 ms instead of 250 ms, and the log says when the notice shows and hides and why. Also: estimate the helpers' pipelines by their size. The precompilation stops the game when what the driver has left would take long, and took every helper job for the mean of the latest ones. A title's largest pipelines take a hundred times the mean (GTA V's ray tracing programs, 20-40 s each against ~0.3 s), and the helpers compile them after the ones the game used before: with the code of GTA V's shaders known from the start (second session, cold driver cache), 217 of its 304 compute pipelines were compiled before the game ran, the 86 left counted for 3 s, and the game was only stopped at 36 s, while it loaded the save and already waited for them. The helpers now report what their jobs take by their size, from the time and size of their latest pipelines, for the jobs that wait and for the ones that run, and the estimate takes the larger of the two.SAROS (PPSA07631) closed on the screens after its first boot with "buffer descriptor is not a valid runtime value" in cs bbd2706c785082e8. At pc 0x3d4 it stores records with buffer_store_dwordx4 ... idxen through s[16:19] = {s3, s0 | stride 32, count, format} that it builds itself, and at pc 0x3f0 through {s6 + 0x100, s1 | stride, count, format}: the low dword of each base comes from one user-data register and the high 16 bits from another one that is not the next register. Raw stores through V#s the GPU completes (Gran Turismo 7's cs f0ff5e4576313e72) only took bases whose high dword is in the next register. Record DMA bases as {low, high} register pairs and, when the low and the high dword of a base each come from a single user-data register that is not the next one, take that pair too. The host builds the base from the low dword and the low 16 bits of the high one: guest addresses have 48 bits, and a V#'s dword 1 holds the stride above them.In GTA V Performance mode the resolve thread is the next limit after the execution thread: it spends ~1.95 us per draw choosing programs and walking the SRT of ~5,700 draws a frame, ~785 ms/s at 68 fps. With the execution thread's work ablated (draws skipped after resolution), the resolve thread saturates at 912 ms/s and the frame rate stops at 81.5 fps. KYTY_RESOLVE_HELPER=1 starts a helper thread (pinned to core 0, the last free core of the first CCD) that resolves some of the draws. The resolve thread still takes every operation in order: it reserves the draw's slot of the resolution ring (ReserveResolvedDraw(), state Pending), hands the draw over while the helper has fewer than two pending, and the helper resolves into it (ResolveDrawInto(), Ready or Failed). The execution thread waits for a Pending resolution before it uses or releases it (WaitResolvedDraw()). Walks ahead could not run on two threads: - GetAhead() held the program lock for the whole walk. Programs are added under the lock and never removed and a program found ahead keeps its resource plan, so a thread that resolves ahead with scratch of its own (BeginAheadThread()) now takes the lock only for the cache lookups. - The resource plan's walk and materialization scratch (srt_scratch, material_keys, selector_keys) is mutable state of the plan: two walks of the same plan overwrote each other's captures, and a draw read a texture range from the other walk's V# ("unsupported texture data range" at boot). Each such thread gets scratch slots of its own (PlanScratch()). - The buffer ranges earlier resolutions write, which later walks do not read control flow from, were thread-local to the resolve thread. The helper takes only draws of programs the resolve thread saw write no buffers, and copies the resolve thread's ranges as of the draw it was handed under a sequence count (SyncAheadWrites()). Draws resolve on the resolve thread while WRITE_DATA bytes that walks ahead must read are pending. GTA V Performance mode, the same save, one pass each: with the execution thread ablated, 81.5 -> 128.5 fps (the helper resolves 45-70% of the draws). Unablated the frame rate is the execution thread's (68.1 and 67.1 fps), with the image unchanged. Off by default: without the variable the resolve thread holds the program lock for the whole resolution as before.SAROS (PPSA07631): the scan of the game's files found 44 of the 1032 shaders its manifest lists, reading 6.3 GB in 11.3 s. Unreal Engine 5 keeps its shaders in the shader libraries of its IoStore containers (.utoc and .ucas): a library chunk lists groups of shaders, each another chunk compressed as a whole with Oodle (Mermaid), and every group of SAROS is compressed. The emulator carries no Oodle decoder, but the game links one in its own code (Oodle 2.9, statically in eboot.bin; no module of its own). The scan now reads an IoStore container through its table of contents (versions 3 to 8, not encrypted; blocks stored as they are, or compressed with Oodle, zlib or LZ4; partitions _s1.ucas...): each library chunk, then each of its groups, decompressed, instead of sampling the .ucas. Oodle streams go to the game's OodleLZ_Decompress, found in the programs loaded at start as the one function (by .eh_frame) that refers to two of its messages ("asked for len 0", "decoder memory given, but too small"), with no title or build in the code. It is called on the scan's thread once the programs are relocated, with fuzz safety, the exact size, no dictionary and 2 MB of decoder memory, so that it neither allocates nor logs through the game; the thread first commits 256 KB of its stack, as guest code has no Windows stack probes. SAROS, Code Violet and NHL 27 have the same decoder. SAROS: 1031 of 1032 listed shaders in 9.5 s, reading 1.4 GB. GTA V (1451 of 1480, 2.0 s) and Demon's Souls (7341 of 7341, 4.3 s) have no IoStore containers and do not change.ASTRO BOT's ps 9833d01b08e21d08 and ASTRO's PLAYROOM's ps 29289be6a0202b6d walk the TLAS for a packet of lanes and each BLAS with the whole wave, as the other wave-wide closest hit walks, with rays whose origin is the same in every lane. The decoded patch traced them ("recognize guest BVH walks whose rays start at the same point in every lane"); the IR pass left them to the guest's traversal, for two reasons: - The loop restores the exec mask in each round and copies the origin from SGPRs into the box test's VGPRs in those lanes before each test, so the lanes and the origin of the box test are values of the loop (Select(lanes, origin, -1)), not of before it. MatchPacketWalk now takes the lanes of the first round (EntryLanes: PathEntry through the selects whose condition it decides and the ands of the same lanes) and the copied values. - A switch before the walk sets the TLAS header's user data pair s[0:1] to other user data pairs in the cases that sample a texture and leave the program. The structurizer joins those cases with flags, so the address of the header load is a tree of phis of four pairs. DeriveHeaderSource now takes, for an address that is not a user data pair, the one value of each word that reaches the load (ReachingValue: the incoming values of the phis whose edges the branches into the load and into each edge do not rule out): s[0:1], as the patch did. Both derive the patch's site, TLAS source (s[0:1] + 0x28, root 0x25), layouts (9833d01b: 76543210 1dc6ba98 000dbb8f 000f2510; 29289be6: d951c840 4c25ea62 30482080 308f2511) and reach. The other 102 programs with BVH tests of the dumps (GTA V, ASTRO BOT, ASTRO's PLAYROOM, Wolverine, RE Village, Nightreign, Ghost of Yotei; wave32 and wave64), Wolverine's 1a04c58a9fbc2052 and Gran Turismo 7's expanded program keep their sites, TLAS sources and byte-identical SPIR-V, with and without native ray tracing. Both programs are pixel shaders, and the walks are traced only in compute programs, so the game does not use this yet. TestRayTracingNativeWalks checks them compiled as compute programs, without validating the SPIR-V (a compute stage has no exports).Demon's Souls, cold: while the game boots and loads, the threads of the pipeline manifest and the helper processes translate its shaders and have the driver create its pipelines ("Pipeline manifest: 655/2508 modules, 1282/5778 pipelines (813 modules wait for their shaders) at 2.0 s") side by side with the game, which runs slower until they are done: for minutes in Demon's Souls, less in ASTRO BOT. Nothing on screen said so: the pipeline notice only comes up when the game is stopped for them, when its GPU work waits for one, or when one takes long. Show a small bar in the bottom-right corner, over the notice when both are up: "Preparing pipelines: performance may drop until they are ready.", the share done, and the pipelines and shaders left. Its work counts shaders translated and pipelines created alike, from when the work began, against what is left now (queued modules and pipelines, helper jobs, what the manifest's threads run); not against the manifest's totals, which list pipelines whose shaders the game has not mapped yet, or never maps, so the bar would never fill. As in the notice, the total grows when the game maps more shaders. The bar comes up once there has been work for 1 s and goes after 2 s without any (Demon's Souls maps its shaders in batches: one bar for the batches that follow each other closely); not while the game is stopped for the pipelines, whose notice shows that progress, and only with a manifest. The precompilation thread, which already reads the manifest's backlog and the helpers' counts every 100 ms, decides it; the present thread reads three atomics. The bar does not keep the overlay refreshing on every vblank as the notice does (for a game that may be stopped): it is drawn on the frames the game presents, and the overlay is repainted once when it shows and once when it hides. No path per draw or dispatch changes.SAROS (PPSA07631) in PS5 Pro mode closed at boot with "buffer descriptor is not a valid runtime value" in cs 12070dfbb803ca3b at pc 0x2d8: buffer_atomic_or ... idxen through s[24:27], which a uniform branch on user data s2 builds either from {s6 + offset, s1 | stride 4} or from {s3 + offset, s0 | stride 4}, with a record count it loads. The shader also adds into counters through such V#s. Accesses through V#s the GPU completes only took loads, and raw DWORD stores whose base is in user data (Gran Turismo 7's cs f0ff5e4576313e72); atomics went to the failure. Take raw 32-bit integer atomics wherever such V#s take raw stores (bases in user data, V# table stores, self-sized buffers): the atomic runs on the guest memory through its device address, marks the page written and returns the old value, or zero where no cached buffer backs the page, as the indirect loads read it. Two cases the base search did not see in this shader: a V# whose dwords are Phis of one block now takes the base of each incoming edge, and the low dword of a 64-bit sum, difference, AND or left shift only follows the low dwords of its operands. Compiled for wave32, the shader offsets {s3, s0} by the low dword of S_LSHL_B64 {loaded dword, VCC_HI}, and VCC_HI (the initial s15) was taken for part of the base. Only a V# with a dword that derives from memory the shader reads counts as one the GPU computes: this shader and Gran Turismo 7's load their record counts. A V# built from user data alone, such as the merge of two user-data V#s a loop carries, stays the host's to bind, and fails when no single buffer is carried (TestLoopExitAtomicBindsCarriedBuffer).Demon's Souls (Boletaria, after ~20 min of play): the stone floor under the player turned black while debris and grass kept drawing. Its pixel shader 3f7b19201073e188 picks one of the eight T#s of its material block by a byte of a vertex attribute. The host cannot see the attribute and reads all 32 T#s the selector can reach; past the eighth come the block's sampler, its constants and leftovers of older T#s. One of them read as a 1D T# next to the 2D arrays of the real ones, BuildResourceSpecialization() failed with "indirect image table at pc 0x000000fc has incompatible candidates" and the floor draw was skipped every frame ("[HACK] draw or dispatch with unresolvable resources skipped") while that material block lived. In the last zone of Boletaria (m02_03) a second form skipped six more shaders (0d4527aa959ca0d1, e733fb1c7474ac30, 503037057cade3df, f2d2a73f22800e83, 0789276a30486bf4, 4758f30aeb525d2d...) about 110 times a second each: their 32-key domain wraps to key 0xffffffff, whose T# the shader's U32 arithmetic places 0x1000020c0 bytes past the table, in memory nothing maps, and the failed read failed the whole draw. The shader selects neither: the GPU would fault on the second, and the first cannot take the coordinates of the instruction's 2D array. A table offset past 4 GiB is no longer read and reads as null, as out-of-range byte keys already do. A candidate read from guest memory for a T# that is only sampled, whose dimension cannot take the coordinates of the first typed candidate, reads as null when that candidate has the dimension of the instruction and it reads fewer address components than the instruction supplies (a 2D T# under a 1D sample would read one the sample does not), as the slots of another dimension of a bounded table already do. Explicitly selected T#s, other accesses, candidates of another conversion format or swizzle, and reachable candidates of an unsupported format still fail the draw.SAROS (PPSA07631) traces its visibility rays with a flat walk (cs 0035a11651ca7301 and 050c80c3de19f034, wave32): one loop and one intersection take the TLAS and, from the instance records, the BLASes, each lane on its own stack in LDS and scratch; the first triangle a lane hits within a fixed t max ends its walk, which keeps the hit's distance and primitive word. The code after the walk reads only those. With --native-rt none of it traced on the host ("[RT]": the walk the patch does not recognize, last cs 0035a11651ca7301). That is the form the ray query pass's recognizer of flat walks (Match) takes, after resource tracking, for records of format 1 and 3 and a closest hit extent. Before resource tracking it now also takes the loop carrying the TLAS header >> 3 in its phis, records of format 10 (the BLAS >> 3 in 54 bits at +48, the instance mask in bits 24..31 of the flags) and a fixed t max (an any hit walk), and asks only for the phi of the primitive word; after resource tracking nothing changes. A native form of such any hit walks (Flat) derives the instance record layout from the walk's code (the world to object matrix from the object space ray its instance nodes give the ray phis), runs the guest loop on no lane whose host query traces, and gives the code after the walk the host's hit: every triangle opaque, both facings. TestRayTracingNativeWalks checks cs 0035a11651ca7301. SAROS's closest hit flat walk (cs 192d8cd7fb8773d8, with the facing of the instance flags) and its wave-wide walks with two copies of the leaf list loop (cs 2fa6b5a3b15e54d4) still walk the guest BVH.SAROS (PPSA07631) traces rays that keep the closest hit with the flat walk of its visibility rays (cs 192d8cd7fb8773d8, wave32), whose t max shrinks to each nearer hit: one loop and one intersection take the TLAS and the BLASes of sce::Psr format 10, and the code after the walk reads the hit's distance, its primitive word, its triangle node and the address of the instance record. A triangle counts when its distance is finite and nearer and, on the lanes that cull, when its facing (the sign of the intersection's numerator) is the one bit 3 of the instance flags selects, unless bit 2 takes both; the walk sets those flags at an instance node to dword 13 of the record >> 22, the bits above the BLAS. With --native-rt the walk ran on the guest BVH ("[RT]": programs whose BVH walk no form recognizes). The native form of flat walks (Flat) now also takes closest hit walks. Before resource tracking the recognizer of flat walks keeps the phis of the node and of the instance record where one phi alone carries each, and the leaf's accept condition gives the facing test: the instance flags of the layout (the record dword and the shift the flags phi takes), whether the test flips the facing, and the lanes that cull. The host query keeps the closest hit and gives the code after the walk its node and instance record too. TestRayTracingNativeWalks checks cs 192d8cd7fb8773d8.SAROS (PPSA07631) runs three wave-wide walks in one program (cs 2fa6b5a3b15e54d4, wave32): a TLAS walk and a BLAS walk of scalar nodes over sce::Psr format 10, whose leaf code keeps the closest hit. A branch on the instance flags before the leaf list takes one of two copies of its loop, each with its own triangle test: one keeps the nearest hit of both facings (bit 24 of record dword 13 set), the other the nearest hit of the facing bit 25 selects. Each copy writes the distance as min(t, T) where the hit is finite (and of that facing), and the primitive word where it is also nearer. With --native-rt the walks ran on the guest BVH ("[RT]": 252 dispatches every 10 s of programs whose BVH walk no form recognizes, last cs 2fa6b5a3b15e54d4). The recognizer of wave-wide BLAS walks (MatchWaveBlas) now also takes a box test with two triangle tests in two loops, and ClosestWave reads the facing of such a walk from its two copies (LeafFacingCopies). The branch's record bit is "both facings", and the other copy's test gives the facing bit and whether it flips. Each copy's writes must hold exactly where the hit is finite, nearer and of the facing (min(t, T) counts as written where T is nearer). The values read after the walk are those the copies write (HitResults with their conditions). LeafFacing's test of a record bit moved out of it (RecordBitTest) to serve both. TestRayTracingNativeWalks checks cs 2fa6b5a3b15e54d4.SAROS (PPSA07631) in PS5 Pro mode lost the device ~20 s after boot (~80 s with the intro videos): the GPU hung in cs 4a2181e0b7db95a7, the refit pass of its kTrinity BVHs (one dispatch per BVH, 770 at load), in its loop over the primitive records of a leaf. The earlier passes of each BVH (cs bbd2706c785082e8, 5d9d0b6be7ee2238, 12070dfbb803ca3b) write lists and counters into scratch memory at user data {s3, s0} through V#s they compute from offsets in the BVH header: ~140 KiB past the base for most BVHs, up to ~10 MiB for the largest ones, whose scratch the guest maps on its own. CacheDmaBases() cached 16 KiB after each base: past it the stores recorded faults and were dropped, and the next passes (cs ba6fc85f77dc1520, 4234bd3f182d2b20) took zeros from those lists for primitive indices. Keep the user-data bases of raw stores and atomics through V#s the GPU computes apart from the DMA bases of FLAT accesses (ShaderInfo::vsharp_base_registers) and cache the mapped memory that follows them without a gap, up to 32 MiB: the scratch of one BVH. A fixed window falls short: 1 MiB still lost the stores of four BVHs (up to 3 MiB past their base) and 8 MiB those of one (10 MiB). The scratch pages no longer fault and the refit ends. FLAT bases keep their 16 KiB window, gaps included. Only programs with such V#s change; GTA V has none (its shader corpus translates to the same programs).PrepareBda synchronized every cached buffer over all the mapped ranges whenever an epoch moved (a CPU-dirty page anywhere, a buffer registered, a range mapped), and the first program of a submission whose device-address reach is not bounded paid for it all. Demon's Souls (PPSA01341) runs 14 such compute programs a frame at Boletaria (cs a6c5ba75568fdc37 and a8ae237bf9b2f438 pay for most of it): 11-16 full synchronizations a frame, 3.3-4.3 ms of the execution thread, half of what its ~1,600 direct dispatches cost, in the part of the frame the game waits for before it can send its draws. chenxiao07's tree keeps BDA region requests instead: a tracker region's mapped, registered ranges with the proof (the region's CPU modification epoch and its registration epoch) that they were synchronized, so a preparation skips every request whose region did not change, and a dirty bit per region (bdaDirtyRegions.h) that a guest thread's write sets and the execution thread sees from the next submission or met WAIT_REG_MEM on (BdaDirtyRegions::Publish, where RenderContext::NoteOperation starts a new BDA generation; the execution thread's own writes are visible at once). A program's BdaReadPlan (the memory its loads through device addresses can reach, from the user data and the flattened SRT, built from its IR) lets a preparation visit only the regions of the ranges it reads. Ported: BdaReadPlan.{h,cpp} (CompiledShaderInfo::bda_read_plan, serialized with it), BufferCache:: SynchronizeRegionRequest / RegionRegistrationEpoch / TakeRegistrationSpans / CollectMappedRegisteredRanges / EnsureBdaReadable, RenderContext::PrepareBdaReadRanges and the region request lists. The plans are tried only for stages whose windows upstream's analysis could not bound: a bounded stage's windows cost less than a plan's ranges (with the plans first, the ~6,200 draws of the frame paid ~0.4 us each: 28.9 -> 26.1 fps). Not ported: the speculation's use of the requests. (The write protection an upload worker applies later is this tree's asynchronous reprotection: a request its uploads left unproven while that protection is queued is not marked dirty again, as in his tree.) On in Demon's Souls, where it was measured; KYTY_BDA_REGIONS=0/1 forces it off or on in any game (GTA V's Performance RT has the same full synchronizations), KYTY_BDA_DIRTY_REGIONS=0 turns the dirty bits off. Demon's Souls, Boletaria, the same debug exe with the execution thread's time by phase, one pass each with KYTY_BDA_REGIONS=0 and unset (table dispatches off in both; standing 30 s, then turning 24 s): the full synchronizations 2.0 ms a frame -> none, direct dispatches 6.2 -> 4.3 ms a frame, execution thread busy 21.8 -> 19.5 ms a frame; standing 35.4 -> 39.9 fps (frame 28.3 -> 25.0 ms), turning 37.2 -> 41.1 fps (26.9 -> 24.1 ms). The image is the same (grass and fire, which the port without Publish lost). GTA V Performance mode, 30 s in game, on an earlier base: 70.3 fps, no DeviceLost (the requests are off there). Ported from the chenxiao07 fork.4c4eaac78with KytyPS5a1fc5ae469f18f409View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.