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

Open
opened 2026-11-26 20:20:05 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1062
Author: @syntaxixr
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: d3d12/render-passes


📝 Commits (2)

  • 7d19436 d3d12: BeginRenderPass and EndRenderPass, Tier 0 emulation on the Vulkan-backed list (D3D-27)
  • 3dcd091 d3d12: render pass Close parity with the host runtime, from #1062's review (D3D-27)

📊 Changes

4 files changed (+889 additions, -6 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+33 -6)
📝 runtime/CMakeLists.txt (+8 -0)
📝 runtime/shims/d3d12_com.cpp (+157 -0)
➕ runtime/test/d3d12_render_pass_test.cpp (+691 -0)

📄 Description

Claimed in the coordination issue as: D3D-27 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7138565644). #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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1062 **Author:** [@syntaxixr](https://github.com/syntaxixr) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `d3d12/render-passes` --- ### 📝 Commits (2) - [`7d19436`](https://github.com/ubiquitarianism/leonida/commit/7d19436430076dcc6a51d2c2f797c7b4f131f9fd) d3d12: BeginRenderPass and EndRenderPass, Tier 0 emulation on the Vulkan-backed list (D3D-27) - [`3dcd091`](https://github.com/ubiquitarianism/leonida/commit/3dcd091da6d6ca566766bb6ac46794803861f6d6) d3d12: render pass Close parity with the host runtime, from #1062's review (D3D-27) ### 📊 Changes **4 files changed** (+889 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+33 -6) 📝 `runtime/CMakeLists.txt` (+8 -0) 📝 `runtime/shims/d3d12_com.cpp` (+157 -0) ➕ `runtime/test/d3d12_render_pass_test.cpp` (+691 -0) </details> ### 📄 Description Claimed in the coordination issue as: D3D-27 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7138565644). #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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1099
No description provided.