Skip to content

Runtime: milestone M4 synthetic gate — copy/compute queues with cross-queue fences, compute PSO, UAV buffers and image, ExecuteIndirect dispatch (error 0) - #1791

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
AlxcBTW:m4-synthetic-gate
Nov 22, 2026

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

What and why

This is the synthetic part of milestone M4 in docs/d3d12_vulkan.md §6, claimed in #1548. d3d12_m4_compute_test uses only the D3D12 API and two hand-written RDNA2 compute shaders, translated at build time. It runs three stages behind cross-queue fences:

  1. COPY queue: uploads an input buffer into a DEFAULT buffer, then signals a fence.
  2. COMPUTE queue: waits on that fence and runs the compute work.
    • The root signature has four root constants and a table of five UAVs: a structured buffer, three raw buffers and an R32_UINT RWTexture2D (a storage image).
    • cs_m4_fill fills the buffer and the image from the input, and writes the arguments for the next dispatch.
    • Barriers move the arguments to INDIRECT_ARGUMENT and add UAV barriers.
    • ExecuteIndirect with a dispatch signature runs cs_m4_indirect for the group count the first dispatch wrote. It reads the buffer and image back.
  3. COPY queue: waits on the compute fence and reads everything back, including the image via CopyTextureRegion.

The copy and compute queues get their own VkQueues where the device has them; both test GPUs do. All 1,924 result words match the CPU reference (error 0).

Layer gaps the test found and closed:

  • CreateUnorderedAccessView on structured and raw buffers was a stub. It now writes a V#. Typed buffer UAVs and counters remain stubbed.
  • ExecuteIndirect of a dispatch ran whatever pipeline and root arguments happened to be bound. It now carries the list's pipeline and root arguments, like Dispatch.
  • An image created in UNORDERED_ACCESS and first written by a shader lost its data at the first barrier or copy. Images with a UAV view are now moved to GENERAL (zeroed) at the next submission. This touches the shared submit path; full ctest is unchanged on both GPUs.
  • COMPUTE and COPY command lists no longer log "unimplemented".

Docs:

Known gaps, not fixed here:

  • Layout tracking across queues follows submission order. A copy batch submitted before the compute batch it waits on is replayed against an UNDEFINED layout.
  • Dispatch signatures that change root arguments, and count buffers for dispatches, are still unsupported.

The new target uses the LEONIDA_SPIRV_TOOLS form from #1679, with the same build.py hunk, so it also builds under the Visual Studio generator.

Tested

Head 967564a2, on AMD Radeon 880M (26.11.2) and NVIDIA RTX 5070 Laptop (617.42), Windows 11:

  • d3d12_m4_compute: 1,924 words exact, two VkQueues, 0 validation errors with LEONIDA_VK_VALIDATION=1 (synchronization validation included).
  • Full ctest on both GPUs: 101 of 102 pass. d3d12_draw fails identically on a clean main build (bundle blend pixel (0, 0): got 255,0,0,255, expected red 64); reported in Coordinating who works on what (7) (moved to #1745) #1548.
  • Built and run with -G "Visual Studio 17 2022" -A x64 as well.
  • tests/test_ctest_registration.py and tests/test_shader_checks.py: 62 passed.

Checklist

  • No game data, keys or decryption; nothing online
  • CPU reference, error 0
  • Registered with ctest (SKIP_RETURN_CODE 77) and as a D3D12-harness fixture in run_gpu_tests.py
  • Docs updated (§6 M3 and M4 rows, descriptor gaps)

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…copy queues; buffer UAV views and indirect dispatch state

d3d12_m4_compute_test, through the proxy with D3D12 API only and two
translator-output compute shaders (cs_m4_fill.asm, cs_m4_indirect.asm):
a COPY queue streams an input buffer in, a COMPUTE queue waits on it and runs a
compute PSO over a UAV table (structured buffer, raw buffers, an R32_UINT
RWTexture2D), then ExecuteIndirect of a second PSO from arguments the first
wrote (with a transition to INDIRECT_ARGUMENT and UAV barriers), and a COPY
queue behind a cross-queue fence reads the results back. 1,924 words match the
CPU reference with error 0.

Layer gaps the test found, fixed:
- CreateUnorderedAccessView of a buffer was a stub: structured and raw views are
  now a V# in the slot.
- ExecuteIndirect of a dispatch ran whatever pipeline and root arguments the
  command buffer had bound; the command now carries the list's, as Dispatch does.
- An image created in UNORDERED_ACCESS and first used by a shader was
  zero-filled by the first barrier or copy that named it, losing the shader's
  writes; images with a UAV view are now moved to GENERAL (zeroed) at the next
  submission.
- COMPUTE and COPY command lists no longer log "unimplemented".

Test infrastructure: vk_test_device.h can create more than one VkQueue;
build.py gives a compute shader's FSSM program extra words (fssm-at/fssm-data
from 0x148) so two compute shaders with the same group size get distinct hashes,
and honours LEONIDA_SPIRV_TOOLS (as ItsNotRexed#1679) so the target builds under the Visual
Studio generator. docs/d3d12_vulkan.md section 6: M4 synthetic part met; M3 row
credits @whattheflop's ItsNotRexed#1584 measurement of fences in flight.

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

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independently verified commit 967564a2 on Windows 11 (MSVC 19.44, Ninja, VK_LOADER_LAYERS_DISABLE=~implicit~, synthetic scene, translated RDNA2 shaders via llvm-mc + spirv-as/spirv-val):

  • Shader translation: 2 shaders: 2 translated, 2 pass spirv-val (cs_m4_fill, cs_m4_indirect).
  • NVIDIA GeForce RTX 5080 (driver 616.92, Vulkan 1.4.351):
    • d3d12_m4_compute_test.exe: PASS (exit=0) — M4: a COPY queue streamed an input buffer in, a COMPUTE queue ran a compute PSO over a UAV table (structured buffer, raw buffers, an R32_UINT storage image) and a second dispatch through ExecuteIndirect from arguments the first wrote, and a COPY queue behind a cross-queue fence read the results back (two VkQueues): 1924 words matched the CPU reference (error 0).
  • AMD Radeon(TM) Graphics (driver 26.10.1, Vulkan 1.4.315):
    • d3d12_m4_compute_test.exe: PASS (exit=0) — exact same 1924 words matched the CPU reference (error 0) across two VkQueues.
  • Note: VK_LAYER_KHRONOS_validation is not installed locally.

AI Assisted.

@whattheflop

Copy link
Copy Markdown
Contributor

Independently tested the stock synthetic M4 gate (D3D-235) at 967564a20c96f188982832102c0206957e761a2a against the PR's pinned base and merge base 89b047cd8fab50675a43d76722a6a8a881f55dc2. Upstream main was already at 003e78129303643a3fdc9e5f0e31a01b09759236 when checked.

Native adapter Windows display driver Stock CTest with Khronos sync validation
GeForce RTX 3080 616.64 (32.0.16.1664) PASS, 1,924/1,924 exact
Radeon(TM) Graphics (Ryzen 7 9800X3D iGPU) 32.0.21030.2001 PASS, 1,924/1,924 exact

On each adapter the stock comparator matched 256 input words, 1,024 structured-buffer words, 4 dispatch-argument words, 256 image words, and 384 indirect-output words. Both validation-only runs exited 0 with zero Vulkan validation warnings or errors and no skip. The shim logged three unknown-IID queries on each adapter and continued.

I reviewed the shader accesses, resource states, and submission path before running. The stock path runs COPY upload and signals copy fence 1, then COMPUTE waits on copy fence 1, fills the UAVs, executes the indirect dispatch and signals compute fence 1. COPY then waits on compute fence 1, reads the buffers and image, and signals copy fence 2. Each producer signal is submitted before its dependent wait. The test uses a 20-second host fence wait and I set a 45-second CTest timeout. This exercises the synthetic portion of M4 in that submission order. Original M4 claim

The runs were serial with one native ICD per process and an empty implicit-layer manifest directory. Loader logs confirmed the SDK Khronos validation layer loaded. Separate LunarG API-dump runs with validation enabled confirmed the synchronization-validation create flag and showed two distinct queried VkQueue handles on each adapter (family 0, indices 0 and 1), used for COPY and COMPUTE respectively in the six successful submissions. The trace observed both producer signals before the corresponding Vulkan waits. The traced NVIDIA run passed. The traced AMD run segfaulted at teardown, with vkDestroyDevice as the last recorded call, after the readback fence and successful idle calls. The AMD validation-only run passed after removing API dump. The cause of the traced teardown fault is undetermined.

Build was native Windows 11 25H2 (26200.9974), MSVC 19.38 x64, Windows SDK 10.0.26100.0, Ninja 1.13.2, uv Python 3.12.13, and Vulkan SDK/validation 1.4.363.0. WSL LLVM 21.1.8 was used for AMDGPU assembly only. The D3D12 COM library built at both revisions. CTest registers d3d12_m4_compute with SKIP_RETURN_CODE=77 at the head, and the pinned base has no matching test. MSVC emitted the same C4456 shadowing warning in vulkan_replay.h at both revisions.

Both synthetic shader modules passed spirv-val --target-env vulkan1.3 (SPIRV-Tools v2026.4). The trace recorded two successful module creations matching their byte sizes.

Module Bytes SHA-256
cs_m4_fill.spv 23,132 dd3d78ed8e1fae118da9ecde09b50531ef6047cebe843397a996f3761eab1cb6
cs_m4_indirect.spv 18,292 3cad760d51f579bffc0a18be1aa8c168c1be73ea02708d47f9d9dad0a8f816a3

Test scope was the stock synthetic M4 case. AI-assisted (Codex).

…ions, ordered for other queues

- The zero-fill/GENERAL init of images with a UAV view no longer drains on a copy
  queue or in a submission that runs no dispatch or draw; every other queue's next
  submission waits on the initializing one's progress semaphore.
- storage_pending_ is a set (UAV descriptors are rewritten every frame).
- write_buffer_uav: FirstElement and element count are checked against
  Width / unit, so the byte range cannot overflow.
- docs: M4 row names the remaining limitation.

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

Copy link
Copy Markdown
Contributor

Retested the stock synthetic M4 gate at 2d2eec9a75e3f98cf26b6a55df58d0bd90366ba3 against base and live main 003e78129303643a3fdc9e5f0e31a01b09759236.

  • RTX 3080 (616.64) and Ryzen 7 9800X3D Radeon iGPU (32.0.21030.2001) each passed with 1,924/1,924 exact: 256 input, 1,024 structured-buffer, 4 dispatch-argument, 256 image, and 384 indirect-output words.
  • Both serial runs used one native ICD, an empty implicit-layer path, and only Khronos validation 1.4.363.0. The harness requests synchronization validation in the instance create chain and the loader confirmed the layer was active. Both exited 0 with zero validation warnings or errors and no skips. Both printed two VkQueues from the stock harness. The shim logged three unknown-IID queries on each adapter and continued.
  • By source inspection, the initial COPY upload leaves the pending image alone. The COMPUTE submission waits on the already-submitted upload signal, initializes the image in GENERAL before dispatch, then fills the UAVs and runs the indirect dispatch. The COPY readback follows the already-submitted compute signal and also picks up the initializing queue's progress wait. The terminal fence completes before queue teardown. This covers the ordered synthetic path from the original M4 claim. Claim

One source-review concern outside this stock path: VulkanContext caches the initializing queue's raw progress_ semaphore for later waits. ~VulkanQueue destroys it without clearing the cached handle. A later submission from another queue can therefore pick up a destroyed semaphore even if the initializer had already completed. This is a source finding. The stock case keeps the queues alive through readback. Cache and wait · Destruction

Built native x64 with MSVC 19.38, Windows SDK 10.0.26100.0, Ninja 1.13.2, uv Python 3.12.13, and WSL LLVM 21.1.8 for AMDGPU assembly only. The D3D12 COM library built at both revisions. M4 builds through the merged shader-tool path integration, and CTest has one M4 entry with SKIP_RETURN_CODE=77 at the head and zero M4 entries at base. Both freshly generated modules passed spirv-val --target-env vulkan1.3.

Module SHA-256
cs_m4_fill.spv 696b9dab4d247adaa3f7904e27a40d9e4b8ea9dc04696558cf525b5f248025c2
cs_m4_indirect.spv da044978f4c496bae2b6efe2ba7f3fa2717b84a8997f7a9c6a7019b671f872e7

AI-assisted (Codex).

@mokkymiah

Copy link
Copy Markdown
Contributor

Tested 2d2eec9a on NVIDIA GeForce RTX 3070, driver 621.01, Vulkan 1.4.357, Windows 11 x64, with LEONIDA_VK_VALIDATION=1.

  • Build: cs_m4_fill and cs_m4_indirect both translated and passed spirv-val (2/2).
  • d3d12_m4_compute_test.exe: PASS, 1,924/1,924 words matched the CPU reference, error 0.
  • The run used two VkQueues: COPY upload, COMPUTE with the UAV table (structured buffer, raw buffers, R32_UINT storage image) and ExecuteIndirect from the first dispatch's arguments, then COPY behind the cross-queue fence for readback.
  • No Vulkan validation messages or synchronization errors.

This adds a third NVIDIA data point (RTX 3070, driver 621.01) alongside the RTX 5070/5080/3080 runs; the M4 gate is clean here too. No game data used. AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit 3b7cd5e into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
ItsNotRexed pushed a commit that referenced this pull request Nov 22, 2026
…# in the slot), d3d12_buffer_uav_test

CreateUnorderedAccessView on a buffer with a typed Format writes a typed V# (GFX10_FORMAT code, element size as
stride, element count, OOB_SELECT structured, the format's own DST_SEL), and a structured view with pCounterResource +
CounterOffsetInBytes writes a second raw 4-byte V# in the upper 16 bytes of the slot (a hypothesis for the console
contract, documented in section 3.4). The combinations D3D12 documents as invalid leave a null slot.

d3d12_buffer_uav_test runs two hand-written RDNA2 compute shaders through the translator (typed store/load/atomic on
five formats with NUM_RECORDS as the bound; append by 256 lanes and consume by 128 on a counter at offset 4096, read
back with CopyBufferRegion) against a CPU reference, then compares typed-buffer and counter clears with the host D3D12
runtime on the same adapter (LUID).

Depends on: #1791

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

5 participants