Skip to content

D3D-54: test upload-backed vertex, index, root CBV and descriptor-table bindings - #653

Open
VictorJulianiR wants to merge 12 commits into
ItsNotRexed:mainfrom
VictorJulianiR:codex/test-upload-indexed-draw
Open

VictorJulianiR wants to merge 12 commits into
ItsNotRexed:mainfrom
VictorJulianiR:codex/test-upload-indexed-draw

Conversation

@VictorJulianiR

@VictorJulianiR VictorJulianiR commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Depends on: #1995

D3D-54, claimed on the coordination board. The original dependencies #119 and #291 have merged. This branch includes @carlcdx's #1995 to wait for the bundle's GPU work before reading its image. Both current main and D3D-54 reproduced the stale readback without the fence fix. #1807 proposes the same fence correction. If that lands first, this branch can follow it. Paired reproduction · Three-file D3D-54 diff over #1995.

The added indexed draw binds vertices, indices and a root CBV at byte offsets 2048, 2176 and 2304 within one 4 KiB upload allocation. Its pixel-shader descriptor table selects between filters at offsets 2560 and 2816. A separate pixel shader and pipeline state keep the existing draw passes intact. The test checks the original capture and a second image for the upload draw.

@woreksami contributed the descriptor-table case from #648. @Vonsek identified why the filter needed a visibly different result when an old binding was reused. Both source commits are recorded in the co-authored commit. Original contribution · Offer and hardware results.

Verification on 93a5094. On a GitHub-hosted Windows runner using MSVC and Mesa llvmpipe, the original and upload-backed draws each matched all 4096 expected pixels. The MSAA readback also matched all 4096 pixels. Five independent controls exercised the vertex, index, root tint and descriptor-table bindings, including one vertex-color change that kept the geometry. In each case the original capture stayed correct, the upload assertion failed as intended, and the resulting image differed from the normal upload image at exactly the 1024 predicted pixels. The Vulkan validation layer reported zero errors. Both compute dispatches matched all 64 elements. The unmodified draw and compute executables also passed on the dependency alone. Candidate and five controls · Dependency control.

Earlier independent checks. A native D3D12 WARP reference on Windows Server 2022 (Microsoft Basic Render Driver 10.0.20348.5756) produced all six predicted images. @woreksami ran revision 80fc786 on a physical RTX 3060 (driver 610.88, Windows 11), where all 15 CTest tests passed. The current revision was tested on software Vulkan. WARP reference · Earlier RTX 3060 run.

AI-assisted. All inputs are synthetic. This covers input-assembler vertex fetch and full-width bindings. The translated vertex-shader buffer descriptor path is tracked separately in #699.

Ryx69 and others added 8 commits November 21, 2026 23:44
- 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.
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.
@woreksami

Copy link
Copy Markdown

Tested 80fc786 on an NVIDIA GeForce RTX 3060 (driver 610.88), Windows 11, MSVC (VS 18 Build Tools), Ninja, RelWithDebInfo: pass. ctest 15/15; d3d12_draw_test matches all 4096 pixels (default and upload vertex buffers, upload index buffer and root CBV, culled triangle); d3d12_compute_test 64/64 in both dispatches. First run on physical hardware for this PR, as far as I can see. No validation layer on this machine.

#653 was claimed first, so I'd keep it as D3D-54. The one case #648 has that this doesn't is a descriptor-table entry holding an upload-heap VA, read by the pixel shader (the 64-bit entry read as words, since a biased upload VA's high dword is usually 0xffffffff, a NaN pattern). If you want it, it's a few lines on top of yours: see #648's diff, the filter at s4:s5 in ps_draw.frag and draw 4's SetGraphicsRootDescriptorTable. Happy to send it as a suggestion or a PR against your branch instead, whichever you prefer. I'll close #648.

Adapt the graphics descriptor-table fixture from woreksami's ItsNotRexed#648
(f2dc190 and
1591fdd). Vonsek's review identified
the need for an observable difference when an earlier binding is reused.
Keep the existing vertex, index and root tint offsets and place both
filters in separate aligned regions of the same upload allocation.

Co-authored-by: woreksami <249861314+woreksami@users.noreply.github.com>
@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

This complements your test, and it's relevant to open question 17. In M1.5 (#699), a translated VS fetches its vertices through a V# (s_load the V#, then buffer_load_dwordx4 idxen), not through the input assembler. With the buffer in an UPLOAD heap, the draw faults and the whole submission is lost, on both GPUs here.

The cause is the V# base address:

  • The base is 48 bits, and the translator adds heap_base to it (tools/rdna2spirv.py ~433–446).
  • On both GPUs the upload buffer's device address lay below the arena base, so its console VA (device address − heap_base) was negative: 0xffffffffffce0000 on the Radeon 880M and 0xffffffffffedc000 on the RTX 5070.
  • Truncated to 48 bits, that gives a wild address.

Root CBVs, root views and table pointers are 64-bit, so the paths you test are unaffected. The safe rule seems to be that anything a V# can address (any buffer a game may describe with a V#) must be an arena range. #699 draws from a DEFAULT buffer for now and records this in docs/d3d12_vulkan.md §3.3. If your PR places UPLOAD/READBACK buffers in the arena, a V# fetch from an upload buffer would be a good extra case. I'm happy to test that on the 880M.

AI-assisted (Claude Code).

@VictorJulianiR VictorJulianiR changed the title D3D-54: draw from upload-backed vertex and index buffers with a root CBV D3D-54: test upload-backed vertex, index, root CBV and descriptor-table bindings Nov 22, 2026
@VictorJulianiR

Copy link
Copy Markdown
Contributor Author

@woreksami, I incorporated your #648 descriptor-table case in co-authored commit 084e6a6, including the integer address read and @Vonsek's stale-binding check. Switching only the descriptor entry changed exactly the 1024 top-right pixels from (64,255,0) to (64,255,255). The other 3072 pixels stayed identical. Thank you for the fixture and the RTX 3060 run on 80fc786. Combined hosted test and controls.

@AlxcBTW, the vertex buffer in this test goes through the input assembler. The update changes only the test and its pixel shader. I linked #699 in the PR description so the translated vertex fetch and its allocation requirement stay visible.

@VictorJulianiR

Copy link
Copy Markdown
Contributor Author

Rebase status against 8df277f. Git reports the same nine conflicted files and the same conflict-stage blobs for #291 alone and for #291 with this PR. Both files changed by #653 apply cleanly. I also tested this head on @AlxcBTW's proposed #291 update (25b5563): all 4096 draw pixels and both 64-element compute dispatches matched on Windows Server 2022, Mesa llvmpipe 26.3.1, with Khronos validation enabled. That proposed parent still conflicts with current main in four dependency files. The next restack of #653 depends on the updated #291 head. Git comparison · Combined draw and compute results.

carlcdx and others added 2 commits November 22, 2026 16:25
…ending bundle fence fix

Preserve the upstream readbacks, run the D3D-54 pixel filter on its own graphics pipeline and read its output separately. The upstream parent includes the existing ItsNotRexed#1995 fence fix by carlcdx.
@carlcdx

carlcdx commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 93a50943 on Windows 11 (26300, MSVC 19.44, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, VK_LOADER_LAYERS_DISABLE=~implicit~): pass on two physical AMD GPUs (covering both ReBAR VRAM and system-memory upload-heap paths).

Commands run:

cmake --build runtime/build --config RelWithDebInfo --target d3d12_draw_test d3d12_compute_test --parallel
ctest --test-dir runtime/build -C RelWithDebInfo -R "^(d3d12_draw|d3d12_compute)$" --output-on-failure -V

Results:

  • AMD Radeon RX 9070 XT (RDNA 4, Adrenalin 26.10.44 LLPC, driverVersion 2.0.395, Vulkan 1.4.349, upload heaps in VRAM / Resizable BAR):
    • d3d12_compute: Passed (0.27 sec) — CreateConstantBufferView 64/64 + OOB/negative controls exact; 64 elements matched in both compute dispatches.
    • d3d12_draw: Passed (0.21 sec) — Upload-backed vertex, index, root CBV and descriptor table: 4096/4096 pixels matched, plus strip cut (4096/4096), 4x MSAA (4096/4096), bundle blend, and M1 passes all clean (no timeline fence warning).
  • AMD Radeon(TM) Graphics (Ryzen 7 9800X3D RDNA 2 iGPU, AMD 24.30.18 SC, driverVersion 2.0.331, Vulkan 1.3.302, upload heaps in system memory / no Resizable BAR):
    • d3d12_compute: Passed (0.22 sec) — same exact output.
    • d3d12_draw: Passed (0.16 sec) — Upload-backed vertex, index, root CBV and descriptor table: 4096/4096 pixels matched, all other passes exact.

Synthetic tests only; no game files. AI-assisted.

Resolve the two conflicts as unions: runtime/CMakeLists.txt builds and
defines both main's vs_draw_int/gs_double shaders and this branch's
ps_draw_filter, and d3d12_draw_test copies ps_draw_filter.spv through
main's vktest::shader_fixture_path like the other fixtures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VictorJulianiR

Copy link
Copy Markdown
Contributor Author

Merged current main (d0835dd9) into this branch as aa389026 (a merge commit, no force-push); the PR is mergeable again. All three dependencies (#119, #291, #1995) are on main now. There were two conflicts, both resolved by keeping both sides:

  • runtime/CMakeLists.txt: d3d12_draw_test builds and defines main's vs_draw_int/gs_double shaders as well as this branch's ps_draw_filter.
  • runtime/test/d3d12_draw_test.cpp: ps_draw_filter.spv is now copied through main's vktest::shader_fixture_path, like the other fixtures. The rest of the file merged without conflicts.

I haven't built it locally. Upstream CI is running on this head. AI-assisted (Claude).

@ricardotanaka

Copy link
Copy Markdown

Tested the current head aa389026 (the main merge from 03:27 UTC, after the checks above at 93a50943) on AMD Radeon RX 7600 (RDNA 3, AMD 26.11.2 LLPC, Vulkan 1.4.359), Windows 11 Pro 26200, MSVC 19.44, Vulkan SDK 1.4.363.0, VK_LOADER_LAYERS_DISABLE=~implicit~: pass. So the merge resolution builds and runs on hardware.

  • Merged onto main d0835dd9 (clean), full scripts/build_runtime.ps1 build.
  • ctest -R "^(d3d12_draw|d3d12_compute)$" -V: 2/2 passed. d3d12_draw prints Upload-backed vertex, index, root CBV and descriptor table: 4096/4096 pixels matched; strip cut, 4x MSAA and instance step rate also 4096/4096.
  • Same with LEONIDA_VK_VALIDATION=1 (plus vk_sync_validation, which confirms the layer is active): 3/3 passed, no VUID in the output.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants