Repository navigation
D3D-90: castable formats on placed resources (CreatePlacedResource2) - #1083
Conversation
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 ItsNotRexed#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 ItsNotRexed#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 ItsNotRexed#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 ItsNotRexed#313), cross-queue waits on one VkQueue and CPU fence signals below a pending GPU signal (woreksami), and the linear buffer_at.
Keep the creation-time castable list on the resource, reject an SRV format that is neither the resource format nor listed, and allow listed same-size cross-family casts such as R8G8B8A8_UINT to R32_UINT.
The placed half of D3D-85: CreatePlacedResource1/2 wrap the placed path, and 2 carries NumCastableFormats/pCastableFormats exactly as CreateCommittedResource3 does. The castable list is mapped by a shared helper (also used by the committed path) that refuses unmapped formats and casts whose texel size differs from the resource's, matching the host's E_INVALIDARG and avoiding a size-mismatched VkImageFormatListCreateInfo. A typed UNORM texture with a castable list also accepts an RTV in a listed RGBA8 family format, cleared through the same reinterpretation a typeless RTV uses.
|
AI-assisted independent test of the published pre-rebase stack at A disposable wrapper linked the published runtime library and ran the unchanged stock D3D-90 placed clear/readback scenario against the normal host D3D12 selection. It ran only the sRGB cast and no-list UNORM control. Both runs gave the same comparison:
Khronos validation was loaded on both Vulkan instances and emitted no diagnostics. This result covers the two clear/readback cases. |
|
Tested 9c7e223 on AMD RDNA2 iGPU and RTX 5070: pass. Windows 11 Home 10.0.26300, MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, Ninja RelWithDebInfo ( Run directly, exit 0 on both GPUs:
ctest: RTX 5070 33/33; AMD iGPU 32/33. The AMD failure is the base's AI-assisted (Claude Code). No game files. |
…conflicts) Keep-both resolutions per ItsNotRexed#313's conflict analysis: main's ExecuteIndirect / acceleration-structure / debug-marker / depth24 / node-mask features alongside the stack's arena, compute and draw paths. Main's indirect and AS offsets gain the arena's buffer_offset / heap_base compensation; AS resources on default heaps get their GENERIC structure over the arena range. Reset clears stencil_ref_set_ next to reset_state, and OMSetStencilRef sets it. README takes main's (the crypto-token lines stay deleted).
# Conflicts: # runtime/src/vulkan_backend.h # runtime/src/vulkan_replay.h
quackottu
left a comment
There was a problem hiding this comment.
Tested 36d073f on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass
- Build ok.
ctest: 100% tests passed, 0 tests failed out of 55 (gameinputdisabled, no SDL3). d3d12_vulkan_device_test(changed here): exit 0. Its only validation messages are the standalone-device01387above.d3d12_draw_test,d3d12_compute_test,d3d12_present_test,command_list_test,gfx10_descriptors_testandshader_library_testexit 0.- 48 test programs exit 0 with 0 validation messages.
- Same on
main, not from this PR:d3d12_clear_test(NVIDIA 0.5 tie rounding, #521),vk_binary_occlusion_test(needs an input file), andVUID-vkCreateDevice-ppEnabledExtensionNames-01387from the standalone device ind3d12_fence_timing_test/d3d12_vulkan_device_test(#1027).
|
Tested 36d073f on NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 Home 25H2 (26200.9974), VS 2022 Build Tools, Vulkan SDK 1.4.363.1: pass, with one validation error to fix.
Likely cause: on main, AI-assisted. No game files. |
…f69741; keep draw/dispatch replay fields)
|
Correction to my comment above: the AI-assisted. |
|
Validated and fixed — new head 7afab7f (branch re-merged onto main d3841c0, which includes ff69741). Reproduced on 36d073f: with Which occurrence this branch carries: the stack was still on pre-ff697417 standalone code, and the bug there has two halves:
Because of (1), Fix: the re-merge takes ff69741 verbatim — the instance keeps New head 7afab7f — NVIDIA GeForce RTX 5060 Ti, driver 621.24 (Vulkan 1.4.357), Windows 11 25H2 (build 26200), loader pinned to the NVIDIA ICD:
AI-assisted. No game files. |
…conflicts) - register_samplers (main) and create_window_presenter (stack) both kept. - Resource dtor: stack arena release + main deferred destroys. - AS binding: main size/host_readable + stack console va. - VulkanContext: main's lock split kept; stack arena/pipeline accessors moved to resource_mutex_ (execute copies replay_ under its shared lock), presenter lookups take it shared. - README takes main wholesale; D3D-90 code and tests untouched.
|
Re-merged main (fourth pass) — new head 8163c74, branch Conflicts (7 hunks / 5 files) and how resolved:
Validation — NVIDIA GeForce RTX 5060 Ti, driver 621.24, loader pinned via HKLM settings file; Windows 11 25H2 (26200):
Branch is maintained against main; it will re-merge when #286 lands or on request — no need to flag each hourly round. AI-assisted (omp orchestrator). No game files. |
|
Tested placed-resource integer RTV casting at 8163c74, using the existing D3D-90 clear/copy scenario with a synthetic UINT case. On Windows 11 with Khronos validation enabled, the RTX 5080 (616.92) and Radeon Graphics (32.0.21045.16010) each returned (3, 19, 93, 247) in all 16 texels when clearing a 4×4 RGBA8_UNORM placed texture through a listed RGBA8_UINT RTV. A separate placement cleared through its ordinary UNORM RTV returned (64, 0, 191, 255) in all 16 texels. The native D3D12 comparison matched both buffers, with all four channels checked. Neither Vulkan run reported a validation error. As a control I pointed the first RTV at the resource's own UNORM format and kept the integer clear values. All 16 texels on that placement became (255, 255, 255, 255) on each Vulkan device. All 16 on the second placement still matched. AI-assisted verification. |
|
Tested 8163c74 on AMD Radeon RX 7900 XTX (RDNA3), AMD proprietary 26.10.1, Windows 11, MSVC 19.44: pass.
This is a build-and-regression check on AMD. I ran what ctest registers; I did not read the 18 commits or run any test by hand beyond that. AI-assisted (Claude wrote the test script and read the logs); the runs are from my machine. |
…conflicts) Both sides extended the same spots: the PR's castable-format flag and main's R9G9B9E5-as-R32_UINT view emulation meet in bind_image (two extra defaulted parameters), image_descriptor's view format (resource_format + castable list), create_texture (TextureCreateInfo carries the VkImageFormatListCreateInfo the castable list fills) and the device init (arena creation plus main's predication configuration). Main's hardened CopyBuffer preparation and predicate capture keep the PR's arena-buffer offsets; the PR's old emit-side offset math is superseded by main's prepare-side buffer_offset handling.
Second merge round: main added rgb96 views, the device filter, the present source-rect path and its own ctest registration of d3d12_present_test. bind_image keeps both defaulted parameters and the rgb96 view fallback; image_descriptor runs main's 96-bit family check before the castable-list check; Resource keeps main's rgb96_ member; register_samplers and the presentation plumbing follow main's positions, and the duplicated d3d12_present_test block and stale 'surfaces' local are dropped in favour of main's.
|
Rebased onto current main: head
Tested on
Depends on: #286 AI-assisted (omp orchestrator). |
Third merge round (118 commits): D3D-97's per-queue priorities keep the GPU address arena's bufferDeviceAddress enable; main's VK_KHR_shader_fma probing chains after the PR's PSO feature enables; the backing-offset and hardened whole-buffer-copy refactors replace the PR's older lines.
|
Main moved again after the last push (118 commits, D3D-97 queues and VK_KHR_shader_fma among them), so this is a third merge round: new head |
Part of D3D-90 / #1006 — the placed half of D3D-85's castable formats. Claimed in #1006 as D3D-90.
Depends on: #286
Depends on: #693
This branch is stacked on #286's head (heaps /
CreatePlacedResource) with #693's committed-castable commit cherry-picked on top, so the diff carries the stack until those land.What and why
CreatePlacedResource2was a generatedE_NOTIMPLstub, so a placed texture could not take a castable-format list even though the committed path (#693) accepts one. This implements the placed half with the same semantics:CreatePlacedResource1/2wrap the shared placed path (create_placed);2carriesNumCastableFormats/pCastableFormatsexactly asCreateCommittedResource3does.1is the DESC1 variant without a list. Both keep the placed path's existing refusals (unaligned offset, past the heap end, tiled layout) and the DESC1 mip-region / buffer-layout rules the committed variants use. A nonzero count with a null list is still no list.castable_view_formats): each format must map to Vulkan and be the same texel size as the resource's. An unmapped format or a different-size cast isE_INVALIDARG, matching the host — and a size-mismatchedVkImageFormatListCreateInfois also a Vulkan validation error (VUID-VkImageCreateInfo-pNext-06722), so it is refused before reaching the driver. The image is mutable and carries the format list; the resource's own format is always added when the D3D12 list omits it.R8G8B8A8_UNORMtexture with a castable list now accepts an RTV in a listed RGBA8 family format and clears through the cast — the same reinterpretation a typeless RTV uses (ResourceBinding::castable_view_formats+color_view_format). Without a list, a typed resource still refuses a different-format RTV (the pre-existing behavior, covered byd3d12_typeless_rtv_test).Supporting change in
runtime/src/vulkan_replay.h: the binding flag and the clear-path format resolution that let a cast RTV reinterpret the image.Tested
RTX 5060 Ti, NVIDIA driver 621.24, Windows 11 26200, MSVC /W4, Vulkan SDK 1.4.363.0, on
9c7e223, withLEONIDA_VK_VALIDATION=1(0 validation errors). The Vulkan device was pinned to the RTX 5060 Ti via the HKLM loader settings for the GPU runs; the pin was restored afterwards (5 devices enumerate again).d3d12_vulkan_device_test: new D3D-90 block on the standalone device. A placed texture with an SRGB castable list and a no-list control are each cleared through an RTV (the cast one inR8G8B8A8_UNORM_SRGB) and read back; 128 texel bytes match the host PC runtime (default adapter, which reportsRelaxedFormatCastingSupported; WARP is the fallback when the default host cannot cast). 3 refusal HRESULTs match the host (castable list on a buffer, unmapped format, different-size cast). CPU-side: listed SRV/RTV formats write a descriptor, unlisted ones leave it null, and a listed same-size cross-family SRV cast (R8G8B8A8_UINT→R32_UINT) writes one. A castable placed texture keeps a null GPU VA.d3d12_method_variants_test(D3D-85: accept castable formats on committed textures #693's committed castable checks),d3d12_typeless_rtv_test,d3d12_descriptor_test,d3d12_com_test,d3d12_compute_test,d3d12_draw_test,d3d12_present_test,vk_command_replay_test: all pass, 0 validation errors.ctest: 33/33 pass on the pinned GPU (gameinputdisabled).d3d12_clear_teststill shows the pre-existing WARP clear-rounding mismatch already noted in D3D-85: accept castable formats on committed textures #693 (same-format clears, unaffected by this change).No game files, keys or decryption; synthetic textures only.
AI-assisted (omp orchestrator).