Repository navigation
Runtime: compute path and graphics draws on Vulkan (D3D-3, D3D-4, milestone M1) - #291
Conversation
|
Update: Tested f921105 (merged on current main) on RTX 3090, driver 616.56, Windows 11: pass. The arena fix works here. With Original report, for 476d588: Tested 476d588 on RTX 3090, driver 616.56, Windows 11: fail under validation ( Without validation: With The other four tests stay validation-clean. With Cause: Possible fix: in AI-assisted test run and analysis; synthetic tests only, no game files. |
476d588 to
f921105
Compare
|
@CharlyRien Thanks for testing this on a card without ReBAR. Your diagnosis was right: allocate() asked the ~214 MiB BAR heap for the 256 MiB arena. Fixed in f921105, along with the fix you suggested. A memory type is only tried if its heap can hold the whole allocation (memory_type_order in vulkan_backend.h), so on your 3090 the arena now goes to host-visible system memory. d3d12_state_map_test checks this on your card's heap layout (including the 224395264-byte BAR heap) and with ReBAR on. I didn't add a VK_EXT_memory_budget check: when a heap is big enough but partly used, a failed vkAllocateMemory already moves on to the next type. The branch is also rebased onto main 83d0637. I can only test with ReBAR on (RTX 5060 Ti, driver 621.24, everything passes under validation, including 1 GiB and 4095 MiB arenas), so a re-run of d3d12_compute_test and d3d12_draw_test with LEONIDA_VK_VALIDATION=1 on your 3090 would confirm it. |
|
Tested f921105 on RTX 3090, driver 616.56, Windows 11: pass. With AI-assisted test run. |
IAmNotSiob
left a comment
There was a problem hiding this comment.
Big step, nice. I only reviewed the user-data / pipeline-layout side, against docs/design.md's push-constant contract (144 bytes: s0..s31, heap_base, code_base). ShaderUserData and its static_assert match it. Two questions:
1. #224's fallback flag isn't consulted. Both pipeline layouts here always declare a 144-byte range (sizeof(leonida::ShaderUserData)). #224 (on main now) detects devices whose maxPushConstantsSize is below 144 and sets push_constants_need_fallback, but nothing in this PR reads it. On a 128-byte device, which is the Vulkan minimum and what a number of Intel/mobile drivers report, vkCreatePipelineLayout gets a range that violates VUID-VkPushConstantRange-size-00298. That's a validation error at best, a driver failure at worst, and both PSO paths return E_FAIL. Is the plan to fail cleanly here for now, with a log naming the limit, and do the uniform-buffer tail in a follow-up? Either way, a check before vkCreatePipelineLayout would turn a confusing E_FAIL into an obvious message.
2. Push-constant stage flags vs. future stages. The graphics range is VERTEX | FRAGMENT, which is right for what's accepted today (HS/DS/GS refused, no mesh). Just flagging it: when geometry or mesh pipelines come (9,282 mesh and 195 GS shaders in the corpus), the range's stageFlags has to grow with the stages. Otherwise the layout won't cover the user SGPRs those shaders read.
Smaller: create_graphics refuses a pipeline when both stages read code_base (question 14). Do you have a corpus count of how many VS+PS pairs that would hit? If it's common, a per-stage code base (VS in the 144-byte range, PS via a second range at offset 144) might be worth planning for, on devices whose limit allows it.
I can't run the d3d12_* tests here (Windows+GPU), so this is from reading, not from a run.
|
One cross-PR note, since #286 builds on the same arena: #306 (D3D-21) puts copy and compute queues on their own Vulkan queue families and creates every buffer and image |
|
Code review of f921105, this PR's own commits only (not #119's). It was AI-assisted: three independent passes on the shader library, the device/PSO side, and recording/replay. Items marked proved were reproduced with a synthetic probe on an RTX 3090 (driver 616.56) under Likely to matter for the game
Robustness
Smaller (reasoned)
Checked and found correct
Synthetic inputs only, no game files. The test results are in my comments above. |
|
Thanks @IAmNotSiob , both fixed in b18aedf. Both PSO paths now check maxPushConstantsSize before vkCreatePipelineLayout. Below 144 bytes they return E_NOTIMPL and log the limit, and the uniform-buffer tail is left for a follow-up. d3d12_compute_test covers it with a device that reports 128 bytes. Code base: with the current translator, of the 662 shaders with s_getpc_b64, 53 VS, 92 PS, 246 MS and 263 CS read it (table in section 5.2). Which VS and PS share a PSO is only known when the game creates it, so the pair count is still open; the refusal is logged, so the first boot will measure it. MS+PS looks like the likelier case for a per-stage code base. On #306: agreed. If this lands first, the state_.share(info) line in create_arena is yours. |
|
Tested b18aedf on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass
No game files used. AI-assisted run (Claude Code). |
|
Tested PR #291 (
No game files used. All reported tests completed successfully. |
0xTehuti
left a comment
There was a problem hiding this comment.
Independent Windows Hardware Test & Review (D3D-3, D3D-4, Milestone M1)
Tested and verified on Windows 11 with an NVIDIA GeForce RTX 2070 SUPER (Driver 595.79, Vulkan 1.4.321) in isolated worktree D:\Workspaces\Leonida-pr291 (b18aedf), providing native Windows MSVC hardware test coverage for the critical path PR #291.
Hardware & Toolchain Environment
- OS: Windows 11 Pro 24H2 (x64)
- GPU: NVIDIA GeForce RTX 2070 SUPER (8203 MB dedicated VRAM)
- Driver: NVIDIA 595.79 (Vulkan 1.4.321, WDDM 3.2)
- Compiler: MSVC 2022 v14.44 (19.44.35225) + Ninja 1.13 + CMake 3.31 (
RelWithDebInfo) - Flags:
/std:c++20 /W4 /permissive- /utf-8 - Vulkan Headers: 1.4.321 (
C:\Users\Geko\AppData\Local\VulkanSDK\include)
Compilation Results
- 104 / 104 targets compiled cleanly under MSVC.
- Diagnostics: 0 errors, 0 warnings under
/W4 /permissive- /utf-8.
Test Execution Summary
| Test Target / Suite | Status | Execution Summary |
|---|---|---|
| CTest Suite (15 / 15) | PASSED | 100% pass rate (loader, pe_loader, device_proxy, command_list, descriptor_table, shader_library, bink_decode, bink_audio, xmem, xgameruntime, root_signature, root_signature_oracle, d3d12_gcl8, d3d12_state_map, gfx10_descriptors). |
shader_library_test.exe |
PASSED | SHA-256 (FIPS 180-4 vectors), deflate inflation (stored, fixed, dynamic), JSON parsing, FSSM extraction from synthetic container, and index lookup all OK. |
d3d12_vulkan_device_test.exe |
PASSED | Detected NVIDIA GeForce RTX 2070 SUPER (maxPushConstantsSize: 256 bytes). Verified clears, zero-filled first use, uploads, texture/buffer/BC copies, resolve, and GetCopyableFootprints through the Xbox-ABI proxy. |
d3d12_com_test.exe |
PASSED | 16 colour, depth, and stencil texels matched; queue wait held the GPU. |
vk_command_replay_test.exe |
PASSED | 32 colour texels across two layers, 16 depth/stencil texels; rectangle clears, per-plane depth clears, promotion and enhanced barriers on 64 texels; 4x4x4 volume uploaded, copied in part and whole and read back; 4x resolve of 64 texels. |
d3d12_present_test.exe |
PASSED | 70 frames cleared and presented through the Xbox-ABI proxy on Vulkan, swapchain recreated on resize. |
d3d12_descriptor_test.exe |
PASSED | CopyDescriptorsSimple and CopyDescriptors copied the expected descriptor slots. |
d3d12_gcl8_test.exe |
PASSED | QueryInterface, OMSetFrontAndBackStencilRef(1, 2), balanced refcounts. |
| Python Unit Tests | PASSED | 38/38 tests passed (test_gen_d3d12_stubs.py, test_root_sig_contract.py, test_gfx10_descriptors.py). |
Verified Fixes in b18aedf:
- Verified the
maxPushConstantsSizedevice check: our RTX 2070 SUPER reports 256 bytes (>= 144), proceeding cleanly. - Graphics push-constant stage flags properly inherit from the stage table into
GraphicsPipeline::push_stages.
Exceptional work on the critical path milestone M1. Approved.
AI-assisted hardware review and verification (synthetic fixtures only, zero game data).
|
Tested
AI-assisted. Synthetic tests only. |
|
Tested
The stack includes #119's device and presentation commits. No game files were used. |
|
Tested b18aedf on an NVIDIA GeForce RTX 3050 Laptop GPU (driver 621.01, Vulkan 1.4.357), Windows 11 Pro 26300: pass Build: MSVC 19.44, Vulkan SDK 1.4.363.0, CMake + Ninja, RelWithDebInfo: 113/113 targets, no warnings. Every run had
All three 680M failures come from one cause. This driver reports
One more thing these tests don't reach: a PSO with no vertex input (a full-screen triangle from AI-assisted (Claude Code). |
|
Tested b18aedf on an RTX 4090 (Ada, NVIDIA 621.24) and on the AMD Radeon(TM) Graphics iGPU (AMD Vulkan driver 2.0.353), Windows 11 (26300), MSVC 19.44 (VS 2022 17.14), Vulkan SDK 1.4.363.0, RelWithDebInfo + Ninja, with
Tested as the PR head is (base 83d0637), not merged with current main. No game files. AI-assisted (Claude Code), run on my machine. |
|
@aslan2142, the changed d3d12_indirect_rt test passed on b957ac8 in a fresh Windows MSVC Release build, on RTX 5080 and Radeon gfx1036 with Vulkan validation enabled. At argument base 64 and count base 128, count 0 kept the center black and count 1 rendered the triangle on both adapters. Both also passed the ray query hit/miss check. I changed only the test resolver's count buffer_offset from 128 to 0 in a separate control build. Both GPUs then read the intentionally reversed count at the prefix and returned RGBA (32,160,240,255) where the test expected (0,0,0,255). The test failed on that first readback as predicted. The same source-built guest's direct DRAW still matched the CPU image at 4,096/4,096 pixels on both GPUs through gta6rt --run. The stock indirect CTest begins Vulkan rendering and binds its own graphics pipeline before replay. The guest ExecuteIndirect preparation code is unchanged from 6e2db3d; its separate previously measured open issue remains relevant to a COM guest doing the whole draw. I also checked direct DrawIndexedInstanced through the same guest loader. The 16-bit index view begins 840 bytes into an upload buffer, StartIndexLocation=8, BaseVertexLocation=-1. Both GPUs matched the CPU image at all 4,096 pixels. Changing only the middle draw's StartIndexLocation to 14 selects six identical indices: exactly the expected 1,024 pixels went back to the clear color, with zero mismatches on both GPUs and validation enabled. AI-assisted. |
whattheflop
left a comment
There was a problem hiding this comment.
AI-assisted Windows/MSVC follow-up on b957ac8. I rechecked the published pr291-on-main tip and local HEAD. Its parents are the previously tested 6e2db3d273a0333f74539cdffa34f828dab46077 and live upstream main bb2e18421dac527374eb837c88b5063c5d96f81f. The exact live #291 head 2aed14455052d973f53a3a986fa2fad77f81b659 is an ancestor. Published candidate · Integration notes
I rebuilt the candidate runtime dependencies and three fixture targets using MSVC 19.38, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, and uv CPython 3.12.13. The same disposable positive-only M1 fixtures ran serially with one live queue, one ICD per run, and Khronos synchronization validation.
| Windows adapter | Direct compute | Offscreen direct draw | Validation errors |
|---|---|---|---|
| RTX 3080, 616.64 | 128/128 words across two dispatches | 8,192/8,192 RGBA8 pixels across two passes | 0 |
| Ryzen 7 9800X3D integrated Radeon, 25.10.30.02 | 128/128 words across two dispatches | 8,192/8,192 RGBA8 pixels across two passes | 0 |
Stock d3d12_present_test exited before window creation in both startup controls:
| Process-local setup | Startup diagnostic | Raw exit | CTest |
|---|---|---|---|
| Empty ICD directory | Loader reports “Found no drivers” | 77 | 1 skipped, exit 0 |
| Normal RTX ICD selected, empty explicit-layer path, Khronos validation requested | Harness reports the requested layer is unavailable | 77 | 1 skipped, exit 0 |
Live main bb2e1842 has the same Present source. The d.create(true) bool check maps both unavailable Vulkan and the observed missing-requested-layer startup failure to skip. On candidate 6e2db3d2, Present used the status-aware check. CTest registers Present, compute, and draw once each with SKIP_RETURN_CODE 77. Previous candidate report · Earlier main control · Open Present follow-up #1391
Scope was offscreen M1 and stock Present startup only. No queue wait, leasing, pending-work teardown, standalone capability test, or foreground test ran. Indirect RT has its own Windows result on this commit. Indirect RT report
… unencodable stdout - d3d12_compute_test and d3d12_draw_test (built when glslangValidator is found) had no add_test, which test_ctest_registration catches; registered like their neighbours (exit 77 is a skip). - awc_names.py (#1421) and bink_names.py (#1403) are new tools without #1428's stdout errors='replace' guard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Post-merge check of
AI-assisted. No game files. |
…onflicts here Composes main's newer surface (debug markers, ExecuteIndirect and ray tracing with their IR commands, predication snapshots and predicated copies, deferred deletion, hardened copy validation, GCL9 stubs generation change, host comparisons) with ItsNotRexed#291's draw/compute path and the GPU address arena, plus this branch's RSSetDepthBias. Conflict resolutions (all nine files conflicted identically with and without this branch's own commit — every conflict is inherited from ItsNotRexed#291's layer): - README.md / docs/d3d12_vulkan.md: main's newer feature lists and gap wording combined with ItsNotRexed#291's M0/M1 progress text; the dynamic-state bullet keeps the new RSSetDepthBias paragraph. - runtime/CMakeLists.txt: the stubs generation takes main's quoted interpreter and --header plumbing with the union of both interface lists (GCL9, RootSignature, PipelineState from here, CommandSignature from main). - runtime/shims/d3d12_com.h: VulkanDeviceInfo unions both sides' flags (min_lod, debug_utils, features, shader_dir, ray_tracing over ItsNotRexed#291's arena fields). - runtime/src/command_list.h: the IR command variant unions main's DebugMarker, ExecuteIndirect and BuildAccelerationStructure with ItsNotRexed#291's Dispatch and Draw. - runtime/src/vulkan_backend.h: the device function table and VulkanContext methods are unions; ItsNotRexed#291's buffer_at (which cuts a range at the buffer's end instead of rejecting it) wins over main's; the replay wiring takes both sides' pointers. - runtime/src/vulkan_replay.h: ReplayFunctions and Prepared union both sides; the copy paths take main's hardened validation and predicated copies; predication takes main's snapshot design; the draw/dispatch emit blocks sit beside main's ray-tracing build emit, with the app's console VAs translated by heap_base where Vulkan wants device addresses. - runtime/shims/d3d12_vulkan_device.cpp: create_buffer composes ItsNotRexed#291's arena path with main's ray-tracing acceleration structures (an RT-state buffer keeps its own VkBuffer; GetGPUVirtualAddress returns the structure's device address for one, the console VA otherwise); the arena and ray tracing are mutually exclusive per device (a ray-tracing device keeps every buffer standalone: the 256 MiB mapped arena makes acceleration-structure builds silently produce empty structures on the NVIDIA driver tried, with no validation error); Resource::Unmap restored (both parents had it; the textual merge lost it); allocation keeps ItsNotRexed#291's memory_type_order. - runtime/test/d3d12_state_map_test.cpp: both sides' additions to the state-map coverage line and ItsNotRexed#291's memory-type-order checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…5 + M2 on main Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed#291 landed in main, so this branch is rebuilt on main with only the M1.5 changes; this commit keeps the push a fast-forward. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ItsNotRexed#291 landed in main, so this branch is rebuilt on main with only the subgroup-size changes; this commit keeps the push a fast-forward. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Resolved along the lines in #291 (comment by ItsNotRexed, 2026-11-22 08:27): - Default-heap buffers stay in the GPU address arena: a VA is an arena offset, and every buffer's device address is heap_base + VA (upload and readback buffers: device address minus heap_base, as before). - Acceleration structures: a buffer created in RAYTRACING_ACCELERATION_STRUCTURE state on a ray-tracing device stays out of the arena and keeps main's model, its VA being the VkAccelerationStructureKHR's device address, so BLAS addresses in TLAS instance descriptions are what Vulkan reads. It is registered by that VA. BuildRaytracingAccelerationStructure turns build inputs and scratch into heap_base + VA, and the arena gets the build-input usage on ray-tracing devices. Resource keeps one va_ (gpu_va_/buffer_va_ removed). - buffer_at keeps the size& signature; main's only caller (WriteBufferImmediate) is the branch's version, and ExecuteIndirect resolves its buffers by id. - ~Resource keeps arena_release and main's defer_destroy. - Main's split context locks: pipeline registration and heap_base/zero page take resource_mutex_ (prepare looks pipelines up under its shared lock); VulkanPresenter takes resource_mutex_ shared, plus tracker_mutex_ while it records the back buffer's transition. - Standalone device: main's single instance-extension list and DXGI swapchain enable; info.presentation follows the same swapchain/surface condition, so create_window_presenter keeps working. Main's DeferredDeletionQueue, calibrated timestamps and ray-tracing extensions are kept next to the branch's presentation and feature enables. - Command IR: Dispatch and Draw follow main's DebugMarker, ExecuteIndirect and BuildAccelerationStructure in the variant.
On top of the merge candidate 70178d3 (Ryx69#6, which merged main at 426023a): the 219 commits main gained since. Three hunks conflicted, in two files; both follow the notes on #291 (ItsNotRexed 08:27 UTC, Vonsek 09:58 UTC on 2026-11-22). runtime/shims/d3d12_vulkan_device.cpp, device setup after the VulkanContext: - the branch's GPU address arena is created first, as before; - main's block that configures predication and the predicated byte copy (#1277) follows it; - one load_host_image_copy call and main's lazy D24 converter (enabled only where D24_UNORM_S8_UINT is not usable) replace the branch's unconditional enable_depth24, which was the same code before main changed it. runtime/src/vulkan_replay.h: - CopyBuffer: main's version. It already adds ResourceBinding::buffer_offset to both offsets, as the branch did, and adds the overflow and overlap checks and the predicated copy. With the arena, source and destination are often the same VkBuffer; the overlap check compares the adjusted ranges. - Predication: main's version. prepare() passes buffer_offset + the command's offset to prepare_predicate, so a default-heap buffer inside the arena is read at its own range; emit() captures the word and tests the capture's scratch slot, not the application's buffer. Everything else merged without conflicts. Nothing in main's 219 commits adds a caller that takes a buffer's Vulkan device address for its GPU VA. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ExecuteBundle copies the two stencil references back to the calling list only when the bundle set them (stencil_ref_set_). OMSetFrontAndBackStencilRef marks that; the older OMSetStencilRef assigned both faces without it, so a bundle that only calls OMSetStencilRef lost its reference and the next draw tested against the caller's old value. Reported by Vonsek on #291 with a fixture compared against native D3D12: 1,050 red pixels expected after the bundle, 0 before this change. d3d12_com_test gets the case next to its other bundle checks; it fails without the change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The device tracks the arena's peak end offset, its peak live bytes overall and per use (buffers, shader-visible descriptor heaps, shader code and D3D12 heaps), and its allocations and refusals, and prints one line at release. LEONIDA_ARENA_LOG=1 also logs every VA handed out, every refused request, and upload/readback VAs outside the arena. This answers open question 5 (how large the arena must be) once the game runs. Rebased onto main now that #291 is in: arena_allocate/arena_release take the use, and every call site passes it, including the heap ranges #291 added since.
What and why
D3D-3 and D3D-4 from #156, one PR as claimed: the compute path and graphics pipelines with draws (milestone M1) on
the Vulkan-backed device behind the Xbox-ABI proxy.
Depends on: #119. This branch sits on #119's two commits (presentation and the GPU-test validation fix).
Until #119 lands, GitHub shows them here too; the three commits below are this PR's own.
1. Compute groundwork (
df83350)runtime/src/shader_library.hfinds the translated SPIR-V for a shader the game hands to D3D12 (docs section 3.6):SHA-256 as
fssm_sha256inspirv/index.json.Dispatchin the IR, with its root arguments captured at record time.2. Compute path end to end (
c6fb7f7)(
LEONIDA_ARENA_MB, default 256, at most 4095, so addresses fit 32-bit table pointers).CreateRootSignatureon main's model (Runtime: implement root-signature packer, reconciler and hard-fail #138):parse_rts0, thenpack()for each parameter's user dword.Anything
pack()refuses is refused with its reason.CreateComputePipelineStatethrough Xbox slot 62, in the measured(desc, 0, 0, riid, out)shape (28cf235).It finds the shader by its FSSM hash and copies the FSSM blob into the arena as the code base.
Dispatch.ClearStatealso resets Runtime: add ID3D12GraphicsCommandList8 to the proxy #164's stencil references. Misuse makesClosereturnE_INVALIDARG.3. Graphics pipelines and draws, M1 (
476d588)CreateGraphicsPipelineState:element's register (the translator's vertex-fetch rule). A layout that leaves an input unfed is refused, as
D3D12 refuses it.
references and blend factor are dynamic.
OMSetRenderTargets, read at the call as D3D12 does;DrawInstanced/DrawIndexedInstanced, each recording a copy of that state;CreateCommandList's initial pipeline state is applied.layout tracker, and the draw runs in a dynamic-rendering scope. The viewport is flipped (translated vertex
shaders write D3D clip coordinates), so front-face winding matches D3D12's.
Docs:
docs/d3d12_vulkan.md(section 3.2, the known gaps, the M1 row),runtime/README.md, the README statusrow.
Still missing:
with a log until it lands;
Overlap with #157 (D3D-8): it also implements
GetGPUVirtualAddressand the command-list state setters.Whichever lands first, the other rebases. I'm happy to rebase onto #157 if it goes first.
Tested
AI-assisted change. MSVC 2022, Vulkan SDK 1.4.363, NVIDIA GeForce RTX 5060 Ti (driver 621.24), rebased on main
36ace71:ctest: all 13 tests pass (main's tests plusshader_library;command_listcovers dispatch recording).No compiler warnings.
shader_library: FIPS 180-4 vectors; stored, fixed and dynamic deflate blocks; corrupt and truncatedstreams; FSSM extraction from a synthetic container; input signatures and PS outputs from the index.
LEONIDA_VK_VALIDATION=1(Khronos validation layer, zero messages):d3d12_draw_test(M1): a VS+PS PSO whose input layout order differs from the VS registers; a vertex buffercopied into the arena; indices read from an upload heap; two indexed draws with different root constants and
root CBVs; and a back-facing triangle that must be culled. All 4096 read-back pixels match, which also checks
the viewport flip and the winding.
d3d12_compute_test: a root signature from the PC serializer, a PSO via slot 62 from a game-shaped container,and root constants, a root UAV and a descriptor table pointing at an upload buffer. Two dispatches each give
64/64 correct values.
d3d12_present_test,d3d12_vulkan_device_test,vk_command_replay_testandd3d12_com_teststill pass.d3d12_com_testnow usesSetMarkeras its unimplemented-method example, sinceDrawInstancedisimplemented.
compiled with
glslangValidator.llvm-mcisn't available here to build RDNA2 test shaders.Checklist
docs/design.md, with how it was confirmed. (n/a: no translator change)