Repository navigation
Runtime: CreateHeap and CreatePlacedResource on the Vulkan layer (D3D-16) - #286
Conversation
|
Rebased onto #291 ( Re-ran everything on the new base (RTX 4060, driver 621.14, MSVC 19.51, Vulkan SDK 1.4.363.0):
One conflict to resolve on the way: #291 added the graphics helpers ( The PR shows |
|
Rebased again, onto #291's new head
Re-verified on Still |
|
Tested 673003b on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass
The first run had This is the head as pushed. It conflicts with current No game files used. AI-assisted run (Claude Code). |
|
Thanks @kotorvr, that's the first independent run on a 40-series card and it matches mine. Two notes so the numbers line up with the current head:
The The |
|
Tested 1ab7626 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass
This re-tests the new head (earlier pass: 673003b). It's the head as pushed, and it conflicts with current No game files used. AI-assisted run (Claude Code). |
|
Got it — Nothing pending from your side. The remaining |
|
Rebased onto #291's head Three things changed on the way, all resolved toward the base's newer code:
Re-verified on |
- vulkan_present.h: VulkanPresenter blits a back buffer (an ordinary texture in D3D12's PRESENT state, layout tracked like any other) to an acquired swapchain image and presents it on the same VkQueue, after the application's work. Two frames in flight, a present semaphore per image, FIFO for vsync else MAILBOX/IMMEDIATE, swapchain recreated on resize or out-of-date/suboptimal, minimised windows skip presents. - rt::d3d12::create_window_presenter / WindowPresenter: Win32 surface for a Vulkan device created with presentation; holds the device. This is the back end a DXGI shim or PresentX would call; the game's own front end is still open (docs question 6), so neither is invented here. - Standalone device enables VK_KHR_surface/win32_surface and VK_KHR_swapchain when present; the test helper can too. Test: d3d12_present_test opens a window and presents 60 frames through the Xbox-ABI proxy (reset, PRESENT->RENDER_TARGET, clear, ->PRESENT, execute, present, fence), resizes the window (swapchain recreated, scaled blit), switches to unsynchronised presents, and reads the screen with GDI: 51,153,229 for a 51,153,230 clear. Clean under the Khronos validation layer, as are the other GPU tests; 6/6 ctest.
The debug messenger in test/vk_test_device.h counted every error-severity message, so a broken third-party implicit layer (ReShade's, reported on an RTX 5090) failed every GPU test. Only VALIDATION-type errors are counted now; general loader and layer messages are still printed, marked "not counted". A real validation error still fails the test (checked by replaying part B of vk_command_replay_test without the layout tracker). runtime/README.md says so and mentions VK_LOADER_LAYERS_DISABLE.
…s only shown frames (review) From VictorJulianiR's review of the presenter, with Vonsek's measurements: - A failed blit submission left the frame's fence reset with nothing to signal it, so the next present waited forever (Vonsek: the retry reached vkWaitForFences with UINT64_MAX). An empty batch now takes the acquire semaphore and signals the fence, and the swapchain is recreated next time to give back the image that was never presented. If that batch fails too, or a fence wait or reset fails, the presenter stops (ok() is false). A back buffer the device does not know is refused before an image is acquired for it. - A swapchain recreation published the new swapchain before its per-image semaphores existed, so a failed semaphore left a presenter that could submit with a null one. The images and semaphores are now built in local storage and published only when all exist; on a failure the partial objects are released and the next present tries again. - An out-of-date present was counted as presented (Vonsek: 69 VK_SUCCESS and one VK_ERROR_OUT_OF_DATE_KHR reached 70). presented() now counts VK_SUCCESS and VK_SUBOPTIMAL_KHR only; the caller still gets VK_SUCCESS. d3d12_present_test gives the device and presenter their functions through a driver double that forwards to the real driver. It counts real out-of-date presents (the frame counts allow for them) and live binary semaphores. It reports one present as out of date and one as suboptimal, fails the second semaphore of a recreation, and fails one blit submission. Against the old presenter the test fails at the frame count after the resize, where this RTX 5060 Ti reported a real out-of-date present. Docs: the presenter is named as leonida::VulkanPresenter, made by rt::d3d12::create_window_presenter, and the test is described as 60 frames then 10 after a resize (AlxcBTW).
First pieces of D3D-3 (compute path), no pipelines wired up yet: - shader_library.h: FSSM extraction from the DXBC container (DXIL, XDAT 0x0D, XBCH, zlib), SHA-256, a minimal JSON reader and the spirv/index.json lookup by fssm_sha256. Self-contained inflate, no dependencies. - IR Dispatch with user data captured at record time; replay binds the pipeline, pushes the 144-byte block (s0..s31, heap base, code base) and dispatches. Arena buffers get a buffer_offset that copies honour. - Root signatures use main's model (runtime/src/root_signature.h); the docs say so. Tests: shader_library_test (FIPS 180-4 vectors; stored, fixed and dynamic deflate blocks; corrupt and truncated streams; FSSM from a synthetic container) joins ctest; command_list_test covers dispatch recording.
… compute PSOs, Dispatch) - GPU address arena (docs 3.3), when the device has bufferDeviceAddress: one host-visible, device-addressable buffer (LEONIDA_ARENA_MB, default 256, max 4095 so VAs fit 32-bit table pointers). Default-heap buffers are 64 KiB-aligned ranges with VA = offset, zeroed through the mapping; shader-visible descriptor heaps live there (CPU handle = mapping, GPU handle = VA); upload/readback buffers get VA = device address - heap base; GetGPUVirtualAddress returns these. - CreateRootSignature on main's model (rt::rootsig): parse_rts0, then pack() for each parameter's place in the 32 user-data dwords; what pack() refuses is refused with its reason. CreateComputePipelineState (PC slot 11, Xbox slot 62 via the proxy) finds the shader by the SHA-256 of its FSSM program in the translator's index (VulkanDeviceInfo::shader_dir or LEONIDA_SHADERS); its FSSM blob is copied into the arena as the code base. Shaders that declare set-0 bindings are refused with a log until the bindless set exists (M2). - Command list: root signatures (arguments cleared on change), pipeline state, constant / root view / descriptor-table setters for compute and graphics, SetDescriptorHeaps, Dispatch recording the user data as it is, ClearState (which also resets ProjectLeonida#164's stencil references); misuse makes Close return E_INVALIDARG. - Test helper and standalone device enable bufferDeviceAddress. Test: d3d12_compute_test (through the proxy) creates the root signature from the PC serializer's blob and the PSO through slot 62 in the measured (desc, 0, 0, riid, out) shape (28cf235) from a container shaped like the game's, sets root constants, a root UAV and a table whose application-written entry points at an upload buffer, runs two dispatches that each keep their own arguments, and reads the results back: 64/64 twice. Its shader is GLSL written to the translator's push-constant and address contract, compiled with glslangValidator. Clean under the Khronos validation layer, as are the other GPU tests; 13/13 ctest.
- CreateGraphicsPipelineState (PC slot 10): VS and PS found by the SHA-256 of their FSSM programs in the translator's index. Input-layout elements are matched to the VS input signature by semantic name and index; location = the element's register (the translator's vertex-fetch rule); a layout that leaves an input unfed is refused, as D3D12 does. Rasterizer, blend and depth-stencil state map one to one; viewport, scissor, topology, vertex strides, stencil references and blend factor are dynamic; dynamic rendering takes the RTV/DSV formats. Hull/domain/geometry, stream output, MSAA, set-0 bindings and two code-base stages (question 14) are refused with a log. - Command list: IASetPrimitiveTopology / VertexBuffers / IndexBuffer, RSSetViewports / ScissorRects (first of each), OMSetRenderTargets (views read at the call, single-range handles too), OMSetBlendFactor, OMSetStencilRef and CommandList8's front/back references (now applied), DrawInstanced / DrawIndexedInstanced recording a copy of that state. CreateCommandList's initial pipeline state is applied. Reset and ClearState share one state reset. - Replay: vertex/index views resolve to buffers by VA (arena or upload), attachments move to attachment layouts through the tracker (first use zero-fills), the draw runs in a dynamic-rendering scope with a flipped viewport (translated VS write D3D clip coordinates), stencil references per face, then vkCmdDraw / vkCmdDrawIndexed. Render-target views take the pipeline's formats (the view cache keys on format). - shader_library.h reads the index's input_signature and PS outputs. Test: d3d12_draw_test (through the proxy) builds a VS+PS PSO whose input layout order differs from the VS registers, uploads a vertex buffer into the arena, reads indices from an upload heap, and draws two indexed quads with different root constants and root CBVs plus a back-facing triangle: all 4096 read-back pixels match (which also checks the viewport flip and winding). Shaders are GLSL written to the translator's contract. d3d12_com_test now uses SetMarker as its unimplemented-method example, since DrawInstanced is implemented. 13/13 ctest; all six GPU tests clean under the Khronos validation layer.
…n (arena without Resizable BAR) Without Resizable BAR the only DEVICE_LOCAL | HOST_VISIBLE memory type sits in a heap of 256 MiB or less (214 MiB on an RTX 3090, driver 616.56). The 256 MiB default arena preferred that type, so vkAllocateMemory was asked for more than the heap holds (VUID-vkAllocateMemory-pAllocateInfo-01713). The NVIDIA driver still returned VK_SUCCESS, so the fallback to plain host-visible memory never ran, and d3d12_compute_test and d3d12_draw_test failed under validation. Reported by CharlyRien. memory_type_order (vulkan_backend.h) now leaves out every type whose heap is smaller than the allocation, so the preference falls through to system memory there. DeviceState::allocate uses it for every allocation. d3d12_state_map_test checks the order on that card's heap layout and with Resizable BAR on.
… stages from the stage table Review feedback from IAmNotSiob: - Both PSO paths declared a 144-byte push-constant range without consulting ProjectLeonida#224's limit. On a device with maxPushConstantsSize 128 (the Vulkan minimum) that breaks VUID-VkPushConstantRange-size-00298 and returns a bare E_FAIL. Both paths now refuse with E_NOTIMPL and log the limit until the uniform-buffer tail exists. d3d12_compute_test checks this with a device that reports 128 bytes. - The graphics range's stage flags are now the whole stage table create_graphics accepts, kept in GraphicsPipeline::push_stages, and the replay pushes with the same flags. A geometry or mesh stage added to the table is covered without another change. docs/d3d12_vulkan.md section 5.2 now counts code-base readers per stage with the current translator: of the 662 shaders with s_getpc_b64, 53 VS, 92 PS, 246 MS and 263 CS read the code base. VS+PS pairs are only known at PSO creation.
Shader library - fssm_program takes the last XDAT 0x0D payload, as tools/fssm_unpack.py does by default (195 of 26,503 containers have two different ones, and fssm_sha256 is computed from the last). - The JSON reader parses numbers with from_chars and \u escapes as exactly four hex digits, so a malformed index is refused instead of throwing into the shim. Integer fields outside 0..2^32-1 read as 0. - Index entries that share a program are all kept; CreateGraphicsPipelineState takes the VS whose input signature the input layout feeds. Command list - Setting the root signature that is already bound keeps the root arguments, as D3D12 does. - A draw with no viewport (never set, or RSSetViewports(0, ...)) or an empty one is not recorded: D3D12 rasterizes nothing and Vulkan forbids a 0x0 viewport. - More than eight render targets is an invalid call, in OMSetRenderTargets and in a PSO. Device - Buffers of 0 bytes, or with a size that wraps when aligned, are E_INVALIDARG. The arena refuses zero-size ranges, and its fit test cannot wrap. - A shader-visible descriptor heap the arena cannot hold is E_OUTOFMEMORY instead of a host heap with GPU handle 0. - A failed arena releases its buffer and memory, so other buffers do not get raw device addresses as VAs. - Graphics PSOs that need independentBlend, fillModeNonSolid, depthBiasClamp or dualSrcBlend are refused unless VulkanDeviceInfo::features has them. The standalone device enables those the GPU supports. - A draw that leaves a slot unbound where the PSO names a format uses a pipeline variant with that format undefined (built on first use, kept with the PSO), instead of breaking dynamicRenderingUnusedAttachments-08912. - Instance step rate 0 reads element 0 for every instance (stride 0 at draw time). - The Vulkan 1.0 graphics entry points are required; the 1.3 ones are checked before a graphics PSO is made. Replay - An unbound vertex slot, or an indexed draw with no index buffer, reads the arena's reserved first 64 KiB, which is kept zero, as D3D12 reads zeros. A view that runs past its buffer is cut at the buffer's end instead of failing the whole ExecuteCommandLists. - The rendering layer count is the smallest layer count of the bound views. Tests: shader_library_test covers two payloads, malformed JSON and duplicate programs. d3d12_draw_test covers an unbound RT and DSV, a rebound root signature, step rate 0, an unbound vertex slot, a draw with no viewport, the feature and count refusals, and bad buffer and heap sizes. Each of the rebind, step-rate and variant fixes, undone on its own, makes the test fail. Still open, documented: instance step rates above 1, read-only DSV layouts, and the index buffer's view size.
…rs after the rebase onto main From the reviews and test runs on ProjectLeonida#291: - A pipeline without vertex bindings (a full-screen pass from SV_VertexID) no longer declares the vertex-stride dynamic state, which nothing would set (VUID-vkCmdDraw-pStrides-04913; aslan2142, AlxcBTW, ezwinxdlmao). - Logic ops are applied from RenderTarget[0] instead of being logged and ignored (Vonsek's XOR case), and DepthClipEnable = FALSE is depth clamping (AlxcBTW). Both need their feature (logicOp, depthClamp), or the PSO is refused. - The standalone device also enables shaderInt64, shaderFloat64, shaderInt16, shaderClipDistance and shaderCullDistance where the GPU has them (AlxcBTW, whattheflop: VUID-...-pCode-08740), plus logicOp and depthClamp. - Among index entries for one program, a PSO takes the first that fits and declares no set-0 bindings, as pipelines do not bind set 0 yet. This covers the compute group in poke900310's corpus count, where an entry with 10 bindings shadowed a binding-free one. - The command list holds a reference to every root signature and pipeline state it is given until Reset or its release, so releasing them right after Set* (as D3D12 allows) no longer leaves dangling layouts or drops the submission (AlxcBTW). After the rebase onto main: main's SetPredication reads the predicate through the resource's VkBuffer, so a default-heap buffer (a range of the GPU address arena) adds its offset in the arena, and the arena gets the conditional-rendering usage when the extension is on (lahlousaad4's integration note). Tests: d3d12_draw_test has a second pass with a full-screen triangle first in its submission and an XOR quad, and a depth-clamp refusal. d3d12_compute_test releases its root signature and PSO right after setting them, sets the signature again after the arguments, and has a bound entry ahead of the binding-free one in its index. Each new fix, undone on its own, fails a test: pStrides-04913, wrong XOR pixels, a heap-corruption crash without the hold, a refused PSO without the binding-free choice. Documented as known gaps, not fixed here: wave64 subgroup size (AlxcBTW's follow-up in ProjectLeonida#313), cross-queue waits on one VkQueue and CPU fence signals below a pending GPU signal (woreksami), and the linear buffer_at.
|
Rebased again, onto #291's head Three conflicts this time, all mechanical:
Re-verified on |
Depends on D3D-16 (PR ProjectLeonida#286).
Depends on D3D-16 (PR ProjectLeonida#286).
Claimed in #156 as: D3D-16
What and why
CreateHeapandCreatePlacedResourcewere generated stubs returningE_NOTIMPL, so any content that places a buffer in a heap (streaming, transient targets) had nothing to run on.docs/d3d12_vulkan.md§3.3 already says how it should work — heaps live in the one GPU address arena, and a console VA is an offset into it — so this implements that design.ID3D12Heapis now in the stub generator's interface list (runtime/CMakeLists.txt), which gives it a COM class.CreateHeapreservespDesc.SizeInBytesin the arena atD3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT(64 KiB) and exposes the reserved properties and flags. It returnsE_INVALIDARGfor a null or empty desc,E_NOTIMPLwhen the device has no arena (the caller-ownedVulkanDeviceInfopath withoutbuffer_device_address),E_OUTOFMEMORYwhen the arena is full, andS_FALSEwith a null output pointer, as D3D12 does. Destroying the heap returns its range to the arena.CreatePlacedResourcetakes its properties and flags from the heap and:heap offset + placed offsetin the arena, soGetGPUVirtualAddress()is the heap's place plus the offset, exactly the VA the shaders already see;VkDeviceMemoryand a null VA, as D3D12 does for placed textures.It refuses an offset that isn't 64 KiB aligned or that runs past the end of the heap (
E_INVALIDARG), and aD3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLEplacement (E_NOTIMPL) instead of placing it wrongly.Known gaps, also in §3.3: tiled (
64KB_UNDEFINED_SWIZZLE) placements are refused, and reserved resources remain unimplemented (someone else is ondocs/d3d12_vulkan.md§4.2).Depends on: #291 (the GPU address arena,
GetGPUVirtualAddressand the push-constant base; #291 also carries #119's device work). This branch is2aed144, the head of #291.Tested
RTX 4060, NVIDIA driver 621.14, Windows, MSVC 19.51, Vulkan SDK 1.4.363.0, on
206f27b(#291):cmake --build: clean (170 targets).ctest: 33/33 pass,gameinputdisabled.d3d12_vulkan_device_test,d3d12_com_test,d3d12_compute_test,d3d12_draw_test,d3d12_present_testandvk_command_replay_test: all pass underLEONIDA_VK_VALIDATION=1, 0 validation errors; the compute and draw tests exercise the arena this feature places into.d3d12_vulkan_device_test, on the standalone device (the caller-owned device has no arena, which is whyCreateHeapanswersE_NOTIMPLthere):GetGPUVirtualAddress()= heap place + offset;CopyBufferRegioninto aUPLOADbuffer, are zero;The memory-type guard this PR used to carry (skip a heap smaller than the allocation, VUID-vkAllocateMemory-pAllocateInfo-01713) has landed in #291 as
leonida::memory_type_order, with its own test, so it is no longer duplicated here.AI-assisted (OpenCode, DeepSeek V4.1 Flash).
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator change.)