Repository navigation
GPU: boot on NVIDIA when a format cannot be a typed UAV - #1926
QuentinDanblon wants to merge 247 commits into
Conversation
Rust workspace for VIctory: PE analysis, loader, HLE skeleton, DXBC/DXIL parsing with a GFX10 decoder, conversion cache, CLI and asset-policy enforcement. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Decode the operand fields of every GFX10 encoding (Instruction::fields) and print them in SP3 syntax (Instruction::text, shader-info --disasm). Read the wave size from the FSSM stage record flags. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Loader: map title-shipped DLLs, patch static TLS loads to slot 0, crash reporter, title paths for GetModuleFileName*. HLE: task queue and async, XUser (one offline user), system ids, title id, features, invites, game events, persistent local storage, GameInput with no devices, xmem, console audio hardware queues, life cycle (close suspends, then terminates), and a file layer with virtual drives rewritten in path-taking imports. GPU: D3D12.X device, DXGI chain, heaps, resources, fences, queues and command lists translated onto a host D3D12 device; clears, barriers, copies, resolves and PresentX into the title's window. Shaders: SGD5 reader and `victory translate`; SSA IR with node splitting for irreducible flow; structurisation removing EXEC. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GetModuleHandle* and LoadLibrary* find the title's images and our console modules by file name. LoadLibrary* of a title DLL nothing imports maps, binds and attaches it on the calling thread (a title's own loader DLL may load its backends this way). FreeLibrary never unloads title images. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The prepared images get no DLL_THREAD_ATTACH/DETACH from Windows. A TLS callback in our exe, called on every thread of the process, passes each start and end on to the attached images: their TLS callbacks, then a DLL's DllMain. DisableThreadLibraryCalls stops the DllMain calls and fails for images with static TLS, as on Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Their TLS callbacks run before std's start routine records the thread, and std aborts if anything asks for the current thread first (stdout and stderr locks do, so title code calling our logging functions would). Threads starting in our exe (the title's main thread and our runtime's workers) now get no notices; the probe test starts its thread in title code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The title now boots through every first-boot and menu screen at its own 30 fps, drawing with translated shaders, with input, sound, saves and loading served; it reaches the world, where the host GPU path still fails (see "Not working yet"). Loader and runtime - Crash reports unwind properly, name C++ throws and host GPU failures, carry the title's last debug lines and are appended to crashes.log. - Thread notices on our own threads, reentrant late DLL loading, exit in the console's order, relaunch on a launch-new-game request. - Offline guard: the title cannot reach the network (sockets, name lookups, WinHTTP, the media source resolver); by-name lookups and loads follow the import rules. - Every runtime area the title calls is served (networking hint, packages, store, saves, display, UI, speech stubs, user, async pool). Saves persist; an update is one rename and survives a kill at any step. - DirectStorage reads for real: shared worker pool, priorities, zlib and BCPack. BCPack is our own decoder; the format's constant tables ship in crates/victory-formats/src/bcpack-tables.bin (the asset policy's one exception, see docs/asset-policy.md). - GameInput from XInput pads and the keyboard, with a keyboard stand-in pad; console timers (1 ms) for the whole process. - Audio: XMA2 decoding on the emulated contexts, Opus on the decoder queues, the DSP interface as a stub; title memory placed below 2^40. - Console texture layouts (sizes, tiling, detiling) and the layout library's imports. GPU - Draws, mesh dispatches and compute dispatches run on the host with shaders translated at first use and cached on disk; descriptor heaps, views, root signatures, barriers and host texture states; rectangle lists; comparison samplers. - Title memory reaches the host through persistent mirrors that copy only pages written since the last copy; shader-written buffers are copied back. - Presentation with frame pacing per event kind; framerate in the window caption. Shaders - DXIL emission for vertex, pixel, compute and mesh programs from the console's native code, with a differential test suite against the PC compile. World set: mesh 8,191 of 8,506, vertex/pixel 10,617 of 12,346, compute 1,643 of 2,539; utility set complete. Build - Debugging aids (debug logs, frame capture, stack dumps, scripted keys, the host debug layer, the software adapter) exist only with the `diagnostics` feature; `[profile.diag]` keeps that build apart. Not working yet - In the world the host device is removed within seconds (descriptor handling fixes are in, unproven by a surviving run) and frames present black. - 64-bit image atomics, merged geometry stages and the BVH builder's own shaders do not translate; reverb is silent. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Says how far the title gets (menus at 30 fps, the world reached but not rendering), what each subsystem does and still needs, and warns that the world can reset the display driver on a real GPU. Adds how to run the title, the translate command, and tables for the keyboard pad and the debugging switches. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
prepare() zeroes the title's TLS AddressOfCallBacks but left the IMAGE_REL_BASED_DIR64 entry that patches it. When the loader maps the prepared copy away from its preferred base, that entry turns the 0 into the rebase delta and the loader reads TLS callbacks from there. On Windows the copy lands at 0x140000000 so the delta is 0; under Wine, which maps DYNAMIC_BASE images high, LoadLibraryExW faults in ntdll before any title code runs. The entry is now rewritten as IMAGE_REL_BASED_ABSOLUTE (a no-op), and the prepare test checks that no relocation targets the cleared field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Loader: keep the cleared TLS callback pointer out of base relocations
The title is built for Zen 2 and uses clzero, monitorx/mwaitx and SSE4a's extrq/insertq, which Intel CPUs lack: it died at startup with an illegal instruction on an i7-14700KF. The vectored handler now does their job and resumes: clzero zeroes the 64-byte line at rax, monitorx is skipped, mwaitx yields, extrq/insertq run on the saved XMM registers. Tested: victory-loader crash tests (new one runs each instruction), and the title now gets past startup on an i7-14700KF with an RTX 4070 SUPER. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
next_frame walks the frames before `start` to learn whether the frame at `start` is the packet's last. A damaged packet whose earlier frame has a length of 0 never advanced `at`, so the walk spun forever (in a debug build it overflowed `number` after about 4 billion rounds and panicked). Apply the rule read_frame already uses: a length that does not cover its own 15-bit field is not a frame, and the search ends. Found with a random-input harness. The new test hangs without the fix and passes at once with it.
The exit code ended the other threads first and then started the watchdog. A thread that ends can hold the heap lock or the loader lock. A new thread needs both, so the watchdog did not start and the exit did not stop. Now the exit code starts the watchdog and waits until it runs its own code: only then are its loader notices and Rust's thread set-up done. The watchdog publishes its thread id, and end_other_threads does not end it. The wait has the same deadline as the detach, because this thread, or a thread that waits for it, can hold the loader lock; then the watchdog cannot start. After the deadline the watchdog only ends the process. It does not log, because logging needs the heap and the lock of the log writer. The exit test now also checks that a thread in `keep` is not ended.
…tructions loader: emulate AMD-only instructions on Intel CPUs
Layout::new checked that width, height and depth are non-zero but not that they are bounded, so values a title passes unchecked (up to u32::MAX) overflowed the size arithmetic: `offset * depth` in the linear layout, `slice_size * slices` and the per-mip sizes in the tiled one, and a u32 next_multiple_of in Layout::tiled. Debug builds panicked; release builds wrapped silently and returned a wrong size. Refuse anything past 16384 texels per side, the most a GFX10 image descriptor holds, so no texture the GPU can use is affected. Found with a random-input harness (four distinct overflow sites, none left after this change).
Three lowerings gave results the console's GPU does not (issue Marvisak#2, from hardware measurements published by another project): - v_med3_f32/f16: with a NaN operand the hardware gives the minimum of the three; we gave the median of the other two. - v_fract_f32/f16: the hardware never reaches 1.0 (a tiny negative input gives the largest value below it); the host's own fract differs by vendor and can give 1.0. - v_bfe_i32/s_bfe_i32: a signed field running past bit 31 extends from bit 31; the shift is arithmetic now. Fields that fit are unchanged. The fract case is asserted in float_semantics_are_the_consoles (the console compiler emits v_fract_f32 for frac). The other two cannot be produced from HLSL with the compiler the tests use and rest on the measured values in the issue. Still open from the issue: range reduction before sine and cosine, and denormal operands of the legacy multiply. Refs Marvisak#2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
v_sin and v_cos (f32 and f16) take an angle in turns. The whole turns now come off first (x - round_even(x), exact), so a large angle keeps its fraction of a turn instead of losing it when scaled to radians. The sine of a half turn and the cosine of a quarter turn are exactly +0, as the hardware gives; the host's functions of the rounded angle give about 1e-7. A zero operand passes unreduced, so sin(-0) stays -0. float_semantics_are_the_consoles asserts the exact zeros (it failed before this change). The compiler the tests use takes whole turns off itself, so the large-angle path cannot be reached from HLSL and rests on the measurements cited in issue Marvisak#2. Left from the issue: denormal operands of the legacy multiply, which needs the float mode register as state first. Refs Marvisak#2 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The host device was removed seconds into the world because a shader read a descriptor of the wrong kind: empty slots held a null 2D texture view where the shader expected a buffer, which gave a garbage heap index and a read far past the view heap. Null descriptors now have the kind the shader expects (raw buffer, constant buffer, or a texture of the title's own dimension). The world then ran to a 240 s time limit with no removal. Also: - Host lists hold the textures, pipelines, root signatures and heaps they name, and heap slots hold the resource they view (the title releases objects before submitting lists that use them). - The device-removed report places the fault against the host descriptor heaps and names our own uploads; VICTORY_D3D12_GBV turns on GPU-based validation, VICTORY_DUMP_TARGETS works. - Indirect execution (draw, indexed draw, dispatch, mesh dispatch): the world draws most of its geometry this way. Arguments are clamped and charged to a per-list budget by a small compute pass first, so garbage cannot hang the GPU. Off by default (VICTORY_INDIRECT=1): with it on the title's own GPU watchdog ends the run about 30 s into the world. - Shader-written ranges are copied back once per submission and only where they differ; refreshes beside them copy only stale pages. The frame-rate line counts copy-backs and dropped draws. Not working yet: the world's picture is black (indirect draws off, and hundreds of draws per frame have no translated shader). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The title's shader-visible view heap has 1,245,184 slots. NVIDIA caps shader-visible view heaps at 1,000,000, so HostHeap::new falls back to a heap of 1,000,000 whose title part ends at 934,464, with the dynamic slots after it. The title binds a per-frame table ring in its top slots (934,464 to 1,245,184, moving 4,096 slots a frame), so those tables' host offsets either aliased the dynamic slots or ran past the heap's end. On NVIDIA the GPU then hangs within the first-boot screens (DXGI_ERROR_DEVICE_HUNG), after black and glitched frames. A table that reaches past the host heap's title slots is now made afresh in dynamic slots, as tables holding constant buffers already are, and the shader is given the new offset. Hosts that take the whole heap (AMD) are unchanged. mirror() logs the highest title slot it meets past the host heap, once per new maximum. Tested on an RTX 3080 (driver 32.0.16.2114): the first-boot screens and menus run without glitches, and the title loads into the intro with no device loss (before: device removed about 45-60 s in, 3 of 3 runs). The slot warning went from 78 lines to none. cargo test --workspace passes. Refs Marvisak#16, Marvisak#11 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ength xma: stop at a zero-length frame instead of looping forever
A section whose PointerToRawData lies near 4 GiB made file_offset + delta overflow: a panic in debug builds, a wrong offset in release ones. The section now yields no offset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tents texture: refuse extents past 16384 texels instead of overflowing
The test for the emulation runs the real instructions. AMD CPUs, and most CI runners, execute them natively, so the emulation was tested only on Intel CPUs. The new tests give the emulation instruction bytes and saved registers directly, so they work on any CPU. They cover clzero, monitorx/mwaitx, the immediate and register forms of extrq/insertq, xmm8 to xmm15, length 0, and the instructions and exceptions it must not emulate. The old test stays: on an Intel CPU it is the only test of the full path through the vectored handler.
Process exit: start the watchdog before other threads end
GPU: make tables past a capped host view heap afresh (NVIDIA menu hang)
…wing the stack In a wave64 compute program, writing only EXEC's high dword (for example s_mov_b32 exec_hi, 0) and then running any vector instruction crashed the whole process with a stack overflow. The new mask is opaque and keyed by the unchanged low dword, so lowering the instruction's guard asked for that dword's value, the value is a lane mask read as data, its ballot needs the mask's lane bit, and that bit needs the value again: mask_dword -> boolean -> atom -> get -> mask_dword, without end. mask_dword now notes the masks whose ballot it is building, and a mask reached again on the way fails with a reason. The instruction then fails like any other that cannot be expressed: its result is missing, and only a side effect that uses it stops the translation. A shader the translator cannot handle must not take the title down at pipeline creation. Found with a random-input harness over the whole translation (ir, resource, io, structure, emit) of random decodable compute programs. The new test overflows the stack without the fix. One million further programs (about 160,000 fully translated) gave no panic, hang or overflow.
…IA boot) D3D12 refuses a texture description that asks for unordered access in a format it cannot use as a typed UAV, and NVIDIA removes the device for one anyway. The title asks for it on its 2560x1440 B5G5R5A1_UNORM target, which ended every run 30 s in, before the menus. Drop the permission before any device call names the description; UAV views of such formats become null views and their writes are dropped. The format check is the host's, cached by format, so a format the host does use as a UAV keeps it. The title now boots to the menus on the RTX 5090, in release and diagnostics builds; it previously removed the device at frame 64. Reaching the world still needs the shadow-trace loop handled (a separate issue); VICTORY_GPU_TIMING=1 gets past it for diagnosis.
VICTORY_DUMP_DXIL=<hash>,... writes those shaders' DXIL to VICTORY_DUMP_DIR (the temporary folder by default) when they are first translated, so a disassembler can show what the translator emitted. The world's slow shaders were found with it.
A global --cpu-percent (VICTORY_CPU_PERCENT), 1 to 100, puts the process in a job object with that hard rate cap, so a long translate or a run beside other work leaves the machine responsive. Unset, nothing changes. A process already in a job this one cannot nest under is told so and runs without the cap.
Document --cpu-percent and VICTORY_DUMP_DXIL beside the other debugging switches.
|
Independent second-read at head (not merged with main). The actual NVIDIA UAV fix is small and correct: However, the fix is buried in a massive 104-file, +992/-11,875 line architectural simplification PR that removes many internal crates, tests, and features (memory.rs, bindless.rs, pipelines.rs, shaderpack.rs, publish.rs, many diagnostic features). The PR title severely understates the scope, making review difficult and obscuring potential regressions from the wholesale test removal. The removed tests covered title writes under GPU write ranges, snapshots, off-element buffer views, and root UAV write-back. Recommendation: the UAV fix should land, but ideally split from the architectural simplification. The massive test removal is a regression risk and should be documented with rationale. A commit message explaining the removals would help reviewers understand the trade-offs. Arch Linux, kernel 7.3.5-arch1-1, zero-CPU read, AI-assisted. |
|
Measured both bit choices on the cards where this matters: they agree, so the queue has two pull requests for one fix I ran the two format-support tests side by side on the RTX 4090 (driver
So for the format this is about, Two consequences, and the second is the one worth acting on:
I am not precious about which. Mine is smaller and was measured on the card that fails; yours is the one that reads the documented flag and additionally refuses the unsupported view at creation, which is a real improvement over dropping the permission alone. If you want yours in, say so and I close mine — I would only ask that the tri-state behaviour be kept: when the host cannot be asked, the description should stay as the title wrote it, because dropping a permission that was legal loses a texture's writes silently. If it is easier the other way round, mine is No game data is involved: formats, support masks and counts. Written with an AI assistant. |
|
RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC. No game files, unit tests only. Head
Adds a Blackwell row next to the RTX 4090 run above. Written with AI help (Claude/Kiro); the numbers are from runs on my machine. |
|
Automated triage for the maintainers. This pull request no longer merges cleanly into Generated by Claude Code |
|
I found an in-game regression from the exact-format UAV check in The game requested a 2560×1440 R8G8B8A8_UNORM_SRGB render target with unordered access and created an R8G8B8A8_UNORM UAV on it. The integration normalized the resource to R8G8B8A8_TYPELESS, tested that exact format and stripped ALLOW_UNORDERED_ACCESS. The active hair pass ended up with a null output. The texture was newly allocated and the requested UAV referred to that same resource. I compared this rule with kotekompotek's castable-view check from #2442 (
With #2442 the host resource retained both flags. All 6,809 changed samples over the shirt also switched to material ID 6. The long curly ponytail was visible over the lettering in the final frame. Its lighting is still dark. The camera poses differ slightly between runs, so the counts above compare writes within each single frame. This tests one RGBA8 family case on Windows 11. The separate Device10-less case is already documented on #2442. |
|
RTX 4060 Laptop (610.47), merged onto main 13f91ca (README conflict only, tested with main's README): B5G5R5A1 UAV half fixed, B4G4R4A4 target half still removes the device; no new failures. Details and the side-by-side table with the other #1753 PRs: #1753 (comment). Tested with the help of an AI assistant (Claude Code). |
Comments, docs and the crate description now say "the title". The README heading becomes Grand RTX 5090. No code changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured frame rates, where a frame's time goes, the changes kept and the ones taken back out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a5db367 to
948b7de
Compare
What this fixes
The title removed the host GPU on NVIDIA about 30 s after launch, before the menus. The debug layer names the calls:
GetResourceAllocationInfo/CreateCommittedResource3for a 2560x1440B5G5R5A1_UNORMtexture withALLOW_UNORDERED_ACCESS: "must be created with a format that either can be used as unordered access, or cast to a format that could be used as unordered access".CreateUnorderedAccessViewwith a typed UAV ofB5G5R5A1_UNORM: "the current graphics implementation does not even support this Format", thenRemoveDevice(DXGI_ERROR_INVALID_CALL).B5G5R5A1_UNORMis not a typed-UAV format on this NVIDIA driver. The old code asked anyway, so the device was removed.This PR asks the host once per format (
resource::typed_uav,D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW):host_descdropsALLOW_UNORDERED_ACCESSbefore any resource creation call when the format cannot carry it.descriptor::host::fitsrefuses unordered views for those formats, so a null UAV is made instead and its writes are dropped.A format the host does support as a typed UAV keeps the permission, so the AMD path is unchanged.
Related: #1754, #1753, #1758, #1832, #1843. This unifies the two checks (#1832 dropped the resource flag, #1843 refused the view) behind one host query, and covers the no-description/default-view path as well.
Verification
Windows 11, RTX 5090, retail Series X build, Series X mode, 90% CPU cap.
crashes.logrecords0x887A0004and0x887A0001, and the debug layer points at the B5G5R5A1 UAV.Performance findings (not fixed here)
With
VICTORY_GPU_TIMING=1the world loads and the GPU timestamps name the costs:WindNew:CS_CopyLatestWindFieldForRenderingWithSmooth(00167d58cc5a78d7): about 1.3 s per frame.MSNC_VS_TransformSkinDplusPS_DeferredTextured(d0503aa87911743e,5a0b31c2cd7fb82e): about 1.8 s for two indirect draws.CS_Gather_Classified(8bbcbda6008eaa37): about 94 ms.The shadow-trace shader
f607780aa8e502d0(CS_IrradianceCache_ShadowTrace_WithFar) makes one world-load submission run 4.8 s. WithoutVICTORY_GPU_TIMING=1(which submits lists one at a time) the 2 s driver watchdog removes the device.VICTORY_SKIP_PIPELINES=f607780aa8e502d0also gets into the world. That loop and the translated-code cost are the next work. This PR addsVICTORY_DUMP_DXILto inspect the emitted code and an optional CPU ceiling so a long run leaves the machine responsive.Host copies of title memory are system memory (
D3D12_MEMORY_POOL_L0, write-back), so the shaders read them over PCIe. Mapping a GPU-local write-combine heap directly and letting the CPU write it reached the menus but crashed the title about 30 s into the world load, even afterFlushProcessWriteBuffers, so a VRAM mirror fed by GPU copies of the changed pages, with the shader writes copied back, is the next experiment.Known limitations left as on main
HEAP_VIEWSis still 2^21, so a computed index in the gap is not safe. GPU: keep heap indices and the null views inside a host heap the driver caps #1848 and NVIDIA: the title's view heap (1,245,184) cannot fit the driver's 1,000,000 limit, and shrinking one title budget value to 140 fits it and removes the world stall #1760 are the right place for that.B4G4R4A4_UNORMrender target the title asks for (format 115). The warning remains and the host texture is missing.cargo test --workspacestill fails the two heap-cap tests and the threevictory-shadertests reported in NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #1835, exactly as on main.cargo clippy --workspace --all-targets --locked -- -D warningspasses, and the new ignored GPU test passes withcargo test -p victory-gpu -- --ignored unordered_access_follows_typed_uav.Testing