Skip to content

d3d12: BeginRenderPass and EndRenderPass, Tier 0 emulation on the Vulkan-backed list (D3D-27) - #1062

Open
syntaxixr wants to merge 2 commits into
ProjectLeonida:mainfrom
syntaxixr:d3d12/render-passes
Open

syntaxixr wants to merge 2 commits into
ProjectLeonida:mainfrom
syntaxixr:d3d12/render-passes

Conversation

@syntaxixr

@syntaxixr syntaxixr commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-27 (#14 (comment)). #628 had it before and was closed by its author with the branch deleted; this is a fresh implementation.

Problem

On main, ID3D12GraphicsCommandList4::BeginRenderPass / EndRenderPass are the generated stubs. The device already reports RenderPassesTier = TIER_0, so a title that records a frame with render passes binds no targets, runs no clears and no resolves.

Change

Tier 0 emulation on the list's own commands, the way the D3D12 runtime handles a Tier 0 driver (runtime/shims/d3d12_com.cpp):

  • BeginRenderPass binds the pass's RTVs/DSV through the same code as OMSetRenderTargets (bind_targets) and records each CLEAR beginning access as a ClearRenderTargetView / ClearDepthStencilView. Depth and stencil each go by their own access, in one clear.
  • PRESERVE, DISCARD, NO_ACCESS and PRESERVE_LOCAL_* record nothing.
  • RESOLVE ending accesses are copied at BeginRenderPass and recorded at EndRenderPass, one per subresource parameter, through ResolveSubresourceRegion's checks. These are now in a resolve_region helper; ResolveSubresourceRegion behaves the same.
  • RESUMING_PASS skips the clears and SUSPENDING_PASS skips the resolves.
  • Close returns what Windows WARP returns (and, for the cases the review probed, the host D3D12 runtime on an RTX 5070 Ti):
    • E_INVALIDARG: EndRenderPass with no pass, EndRenderPass twice, a nested BeginRenderPass.
    • E_FAIL: a pass left open; more than eight targets; a pass on a bundle or a compute list; and OMSetRenderTargets, ClearRenderTargetView, ClearDepthStencilView, CopyResource, CopyTextureRegion, CopyBufferRegion, DiscardResource, ResolveSubresource, ResolveSubresourceRegion or Dispatch inside a pass (not recorded).
    • S_OK: a resource barrier inside a pass, and a CLEAR with no descriptor or a RESOLVE with no source, which WARP skips and so does the layer.
  • Pass state is reset by Reset only, not by ClearState.
  • docs/d3d12_vulkan.md section 4.3 and the M3 row are updated.

Tested

New d3d12_render_pass_test (in CMake and ctest). It runs eight cases through the D3D12 API on the Vulkan-backed device and on Windows WARP, and compares the readback bytes and Close HRESULTs. It also checks WARP against the values written in the test, so a case cannot pass by both sides being wrong:

case main this PR
CLEAR + PRESERVE on two RTs FAIL PASS
the same with ALLOW_UAV_WRITES FAIL PASS
D32S8: depth CLEAR, stencil PRESERVE FAIL PASS
D32S8: stencil CLEAR, depth NO_ACCESS FAIL PASS
4x MSAA CLEAR, RESOLVE into a 2x2 rect at (1,1) FAIL PASS
suspend in list 1, resume in list 2 (one ExecuteCommandLists); the suspended part's RESOLVE aims elsewhere FAIL PASS
4x MSAA D32_FLOAT depth RESOLVE (MIN; skipped on a device without MIN depth resolves) FAIL PASS
29 Close cases, each with its expected HRESULT FAIL PASS

The same eight pass with LEONIDA_VK_VALIDATION=1 (Khronos validation layer 1.4.341), 0 validation errors. Seven targeted mutations of the emulation (a forbidden call not checked, a bundle pass back to E_INVALIDARG, a null-RTV CLEAR made an error, RESUMING clearing, the depth resolve dropped, nine targets back to E_INVALIDARG, SUSPENDING resolving) each make one case fail.

Setup: AMD Radeon RX 6600 (RDNA2), AMD Windows driver 26.6.4 (32.0.21043.19003), Windows 10 22H2 19045, MSVC 14.44 + Windows SDK 10.0.26100, Ninja, RelWithDebInfo.

Full ctest on this branch: 299/308 passed. 8 failures fail the same way on main on this machine, because Windows 10 has an older D3D12 runtime and WARP: root_signature_oracle, d3d12_vulkan_device, d3d12_texture_tiles, d3d12_close_parity, d3d12_clear, d3d12_pso_validation, d3d12_mesh, d3d12_set_descriptor_heaps. d3d12_close_parity's output is line for line the same as on main. The ninth, xmem ("mapping them does not charge them", next to its remap race), failed once under the parallel run and passed 5/5 run alone; this PR does not touch xmem. The tests/test_docs_*.py suite, test_d3d12_stubs_generation.py and check_no_game_data.py pass.

Not covered: draws inside a pass (they use the same per-draw rendering scope as after OMSetRenderTargets), PRESERVE_LOCAL_*, the forbidden calls WARP was not measured for (UAV clears, CopyTiles, ExecuteIndirect, queries), and a Tier 1 path.

No game files. AI-assisted.

…kan-backed list (D3D-27)

BeginRenderPass binds the pass's RTVs/DSV as OMSetRenderTargets does and records
the CLEAR beginning accesses as ClearRenderTargetView / ClearDepthStencilView
(depth and stencil planes by their own access). RESOLVE ending accesses are
copied at BeginRenderPass and recorded at EndRenderPass through the
ResolveSubresourceRegion path. RESUMING_PASS skips the clears, SUSPENDING_PASS
the resolves. Close with a pass open returns E_FAIL, as measured on WARP.

d3d12_render_pass_test compares six cases with Windows WARP byte for byte.
@kawaii-shakal

Copy link
Copy Markdown
Contributor

Independent review of #1062 (D3D-27, BeginRenderPass / EndRenderPass, Tier 0 emulation)

Head: 7d19436 (one commit on 3295055). It merges into origin/main 3aa9754 with no conflicts (git merge-tree --write-tree, main is 17 commits ahead of the merge base).

Environment: Windows 11 Pro 26300, MSVC 19.50 (14.50.35717, VS 18 2026 generator), NVIDIA GeForce RTX 5070 Ti, driver 617.42, LEONIDA_VK_DEVICE=5070. RelWithDebInfo. I built only the targets below, with /m:3.

Claim

Commands and results

cmake -S runtime -B runtime/build -G "Visual Studio 18 2026" -DBUILD_TESTING=ON
cmake --build runtime/build --config RelWithDebInfo --target d3d12_render_pass_test d3d12_com_test d3d12_close_parity_test d3d12_depth_resolve_test d3d12_vulkan_device_test -- /m:3

The build added no new warnings in d3d12_com.cpp or in the new test. The only warnings are the existing ones in vulkan_present.h.

test no validation LEONIDA_VK_VALIDATION=1
d3d12_render_pass_test 6/6 PASS, exit 0, 0.3 s 6/6 PASS, exit 0, 0 validation errors
d3d12_com_test exit 0 exit 0
d3d12_close_parity_test 113 cases, 0 failures same
d3d12_depth_resolve_test (covers the resolve_region refactor) 71/71 match WARP, 168 host comparisons matched same
d3d12_vulkan_device_test (covers RenderPassesTier) exit 0 exit 0
  • On main's shim (git checkout 32950551e -- runtime/shims/d3d12_com.cpp, then a rebuild), all six cases FAIL, as the PR body says. I restored the file afterwards.
  • Mutation: I replaced clear_flags |= D3D12_CLEAR_FLAG_STENCIL; (d3d12_com.cpp:722) with a no-op. stencil_clear_depth_no_access then FAILs (WARP 09…, ours 03…) and the test exits 1. I restored the file with git checkout --, rebuilt and got 6/6 PASS again.
  • RenderPassesTier is D3D12_RENDER_PASS_TIER_0 (d3d12_vulkan_device.cpp:7688), the same as the docs and the test's check (d3d12_render_pass_test.cpp:412-417).
  • These pass: tests/test_docs_*.py (12 files), tests/test_d3d12_stubs_generation.py (28 tests) and scripts/check_no_game_data.py, all run with python -I.

Extra probe: Close HRESULTs on WARP, on the host D3D12 device on the RTX 5070 Ti, and on the layer

I wrote a throwaway probe that is not in the PR (copy: F:\recomp\tmp\rv-1062-probe.cpp). It records each case on a fresh list and calls only Close. Nothing is executed.

case WARP host NVIDIA layer
valid pass S_OK S_OK S_OK
pass left open E_FAIL E_FAIL E_FAIL
nested Begin, one End E_INVALIDARG E_INVALIDARG E_INVALIDARG
End twice E_INVALIDARG E_INVALIDARG E_INVALIDARG
SUSPENDING pass ended / RESUMING pass in a fresh list / empty pass S_OK S_OK S_OK
ResourceBarrier inside a pass S_OK S_OK S_OK
BeginRenderPass+End on a bundle E_FAIL E_FAIL E_INVALIDARG
BeginRenderPass+End on a compute list E_FAIL E_FAIL E_INVALIDARG
EndRenderPass alone on a bundle / compute list E_FAIL E_FAIL E_INVALIDARG
OMSetRenderTargets inside a pass E_FAIL E_FAIL S_OK
ClearRenderTargetView inside a pass E_FAIL E_FAIL S_OK
CopyResource inside a pass E_FAIL E_FAIL S_OK
DiscardResource inside a pass E_FAIL E_FAIL S_OK
Dispatch inside a pass (no PSO) E_FAIL E_FAIL E_INVALIDARG (the layer already rejects a Dispatch without a PSO outside a pass, which the host accepts)

For every case the PR claims, the HRESULTs match WARP and the host hardware runtime. The host NVIDIA runtime also returns E_FAIL for "pass left open", so the choice of E_FAIL is confirmed on real hardware too, not only on WARP.

Findings

  1. Non-blocking, and stated in the PR: the calls D3D12 forbids inside a pass are not checked. Both host runtimes fail Close with E_FAIL after OMSetRenderTargets, ClearRenderTargetView, CopyResource, DiscardResource or Dispatch inside a pass, and the layer returns S_OK (d3d12_com.cpp:685-760 keeps no state those calls read). A title would only hit this through its own bug. It is still a Close-parity gap. I suggest a follow-up that records an "in pass" check in those methods. Until then, list the cases in d3d12_close_parity_test as known layer-looser so the gap is visible, and post a finding: in Coordinating who works on what #14.
  2. Minor HRESULT difference: on a bundle or a compute list, BeginRenderPass/EndRenderPass make Close return E_INVALIDARG (d3d12_com.cpp:689 and :738, through check(false)). WARP and the host NVIDIA runtime both return E_FAIL. A small fix is to set the same "fail with E_FAIL" path that Close uses for an open pass (d3d12_com.cpp:222-229) when the list type is wrong.
  3. Minor: BeginRenderPass sets in_render_pass_ = true (d3d12_com.cpp:697) before it validates the RTV and DSV descriptors (lines 709 and 724). A CLEAR with a null descriptor therefore returns halfway: earlier clears are already recorded and later RESOLVE accesses are not captured. The list is invalid anyway, so Close still fails, but validating before recording would be cleaner.
  4. Test coverage: the six cases are compared against WARP only. Five of them also check WARP against hand-computed bytes. list_errors has no expected values (d3d12_render_pass_test.cpp:438), so its HRESULTs rest on WARP alone. The probe above shows the host NVIDIA runtime agrees. Draws inside a pass, depth/stencil RESOLVE ending accesses, PRESERVE_LOCAL_* and ALLOW_UAV_WRITES are not exercised. The PR states the draw gap.
  5. Nit: in runtime/CMakeLists.txt the new block is inserted directly above an existing stray set_tests_properties(d3d12_typeless_rtv ...) line that belongs to another test. It is harmless, but the stray line now sits under the render-pass comment.

The semantics I checked against the D3D12 render-pass rules look right:

  • CLEAR takes its color, depth and stencil values from their own accesses, and depth and stencil are cleared in one call with the matching flags.
  • PRESERVE, DISCARD and NO_ACCESS record nothing, which is valid at Tier 0.
  • RESOLVE parameters are deep-copied at Begin, which is necessary because the arrays need not outlive the call. They are replayed at End through the same checks as ResolveSubresourceRegion.
  • RESUMING skips the clears and SUSPENDING skips the resolves. WARP's expected bytes in suspend_resume confirm this.
  • Reset clears the pass state (d3d12_com.cpp:1493-1494).

The docs in section 4.3 and the M3 row describe what the code does.

Verdict

Approve with non-blocking follow-ups. The emulation is correct for every case tested. It matches WARP, and for Close the host NVIDIA D3D12 runtime too, with and without Vulkan validation on the RTX 5070 Ti. The new test fails on main and catches a targeted mutation. Findings 1 and 2 are Close-parity gaps against the host runtime and are suited to a follow-up, not to blocking this PR.

AI-assisted.

…onida#1062's review (D3D-27)

- The calls D3D12 forbids inside a pass (OMSetRenderTargets, the RTV/DSV
  clears, CopyResource, CopyTextureRegion, CopyBufferRegion, DiscardResource,
  ResolveSubresource(Region), Dispatch) make Close E_FAIL and are not recorded.
- A pass on a bundle or a compute list, and more than eight targets, make
  Close E_FAIL instead of E_INVALIDARG.
- A CLEAR with no descriptor and a RESOLVE with no source are skipped without
  an error, as WARP does, so an invalid access no longer leaves a pass half
  recorded.
- Pass state is reset by Reset only, not by ClearState.

d3d12_render_pass_test: 29 Close cases with expected values (each also checked
on WARP), a D32_FLOAT depth RESOLVE, ALLOW_UAV_WRITES, and a suspended part
whose RESOLVE would land elsewhere. The CMake block moves below the
unrelated d3d12_typeless_rtv line.
@syntaxixr

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the NVIDIA probe. All five findings are addressed in 3dcd091 (on top of 7d19436; it still merges into main with no conflicts).

  1. Forbidden calls inside a pass. OMSetRenderTargets, ClearRenderTargetView, ClearDepthStencilView, CopyResource, CopyTextureRegion, CopyBufferRegion, DiscardResource, ResolveSubresource, ResolveSubresourceRegion and Dispatch inside a pass are not recorded and make Close return E_FAIL. I measured all ten on WARP first; each gives E_FAIL, so they are now test cases with that expected value. The calls I did not measure (UAV clears, CopyTiles, ExecuteIndirect, queries) are left unchecked and listed in the docs. Since this closes the gap, there is no finding: in Coordinating who works on what #14 and no close-parity entry for it.

  2. Bundle / compute lists. BeginRenderPass and EndRenderPass there now go through the same E_FAIL path as an open pass. The test covers Begin+End, End alone and Begin alone on both list types: E_FAIL on WARP and on the layer.

  3. Validation before recording. I tried an upfront check first, then measured what WARP does with a bad description. It returns S_OK for a CLEAR with a null RTV, a depth CLEAR with a null DSV and a RESOLVE with no source; it just skips them. So the layer now skips them too, instead of failing halfway. A pass can no longer be half recorded, and the HRESULT matches. One more case WARP refuses is nine render targets (E_FAIL), and the layer now matches it as well. count > 0 with a null array faults inside WARP, so it is not a test case. The layer makes the list invalid there, before anything is recorded.

  4. Test coverage. list_errors has 29 cases now, each with an expected HRESULT, and WARP is checked against those values as well as against the layer. New cases:

    • ALLOW_UAV_WRITES on the CLEAR/PRESERVE pass.
    • A 4x MSAA D32_FLOAT depth RESOLVE. It uses MIN and is named R32_FLOAT, as in d3d12_depth_resolve_test. It is skipped if the Vulkan device has no MIN depth resolve.
    • In suspend_resume, the suspended part's RESOLVE now points at (0, 0), so a resolve that wrongly ran would be visible. Before, a SUSPENDING resolve that ran survived the test.

    I removed the temporary debug dump. Not added: draws inside a pass and PRESERVE_LOCAL_*. Both are listed under "Not covered".

  5. CMake. The block now sits below the d3d12_typeless_rtv line.

Also: in_render_pass_ and the related flags are now reset in Reset only, not in reset_state, so ClearState inside a pass does not drop the pass.

Results on an AMD Radeon RX 6600 (driver 26.6.4, Windows 10 19045):

check result
d3d12_render_pass_test 8/8 PASS; also 8/8 with LEONIDA_VK_VALIDATION=1, 0 validation errors
same test on main's shim 8/8 FAIL
7 targeted mutations each fails one case (listed in the PR body)
d3d12_close_parity output line for line the same as on main (that test fails on Windows 10 on main too)
full ctest 299/308. The same 8 pre-existing Windows 10 failures, plus one xmem failure under the parallel run that passed 5/5 alone; xmem is untouched
tests/test_docs_*.py, check_no_game_data.py pass

The PR body is updated to match. AI-assisted.

@Luna-OS

Luna-OS commented Nov 24, 2026

Copy link
Copy Markdown

Independent Windows verification of 7d1943643 (merge base 3295055).

Host: Windows 11 Pro 26300, NVIDIA GeForce RTX 5070 Ti (driver 621.24, Resizable BAR), live WARP, MSVC 19.44.35207 (VS 2022 Build Tools), Ninja, RelWithDebInfo, LEONIDA_VULKAN_HEADERS_FETCH=ON, LEONIDA_SDL3_FETCH=ON. Two full runs per head: without glslang (272 tests), and with glslang (KhronosGroup main-tot) so d3d12_compute, d3d12_draw and d3d12_mesh are built too (298 tests). No game files. AI-assisted (Claude Code).

base this PR
build OK OK
ctest (no glslang) 271/272 272/273
ctest (glslang) 296/298 296/299 (the extra one is xmem, which passes alone and on every other head: load flake)
new d3d12_render_pass - Passed (both runs)
d3d12_com, d3d12_close_parity, vk_command_replay, command_list Passed Passed

Failures shared with the merge base 3295055 and not caused by this PR: d3d12_execute_indirect_validation (the five rows of #504), and with glslang d3d12_draw SEGFAULTs on the base too (slot-14 false positive, claimed as D3D-SLOT14-TAIL-NULL-PAGE, PR follows).

@syntaxixr

Copy link
Copy Markdown
Contributor Author

Thanks for the independent run on the RTX 5070 Ti.

One note: this verified 7d1943643. The current head is 3dcd091d, which addresses kawaii-shakal's review findings (see my reply above). The render pass test now has 8 cases, and 29 of the Close checks have expected HRESULTs. If you rerun, d3d12_render_pass on that head should show 8/8 PASS. On my RX 6600 (Win10) it passes 8/8, also with LEONIDA_VK_VALIDATION=1.

The xmem flake matches what I saw: it failed once under the parallel ctest run and passed 5/5 alone. This PR does not touch xmem.

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.

3 participants