[PR #510] [MERGED] d3d12/vulkan: implement multi-viewport and multi-scissor rendering (D3D-MULTI-VIEWPORT) #558

Closed
opened 2026-11-26 20:18:17 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/510
Author: @jujumoneylol
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @aslan2142

Base: main ← Head: pr/d3d12-multi-viewport


📝 Commits (1)

  • 7d50f3b d3d12/vulkan: implement multi-viewport and multi-scissor rendering (1..16 viewports/scissors)

📊 Changes

9 files changed (+652 additions, -40 deletions)

View changed files

📝 runtime/CMakeLists.txt (+9 -0)
📝 runtime/shims/d3d12_com.cpp (+60 -9)
📝 runtime/shims/d3d12_vulkan_device.cpp (+24 -20)
📝 runtime/src/command_list.h (+10 -0)
📝 runtime/src/vulkan_backend.h (+3 -0)
📝 runtime/src/vulkan_replay.h (+56 -11)
➕ runtime/test/d3d12_multi_viewport_test.cpp (+484 -0)
📝 runtime/test/replay_cpu_bench.cpp (+2 -0)
📝 runtime/test/vk_test_device.h (+4 -0)

📄 Description

Claimed in the coordination issue as: D3D-MULTI-VIEWPORT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7124010841)

Depends on: #469, #499 (adjacent lines in vulkan_replay.h draw replay, d3d12_vulkan_device.cpp, d3d12_com.cpp, and vk_test_device.h if multiple merge; this branch is based cleanly on current main 8f481cf16 with no code dependency on either)

What and why

Previously, RSSetViewports and RSSetScissorRects silently dropped every viewport and scissor past index 0 (stub("more than one viewport; the first is used")), and graphics pipelines fixed viewportCount = 1 / scissorCount = 1 even though main already enables Vulkan 1.2 shaderOutputViewportIndex and advertises VPAndRTArrayIndexFromAnyShaderFeedingRasterizerSupportedWithoutGSEmulation = TRUE.

  • Command list (runtime/src/command_list.h, runtime/shims/d3d12_com.cpp):
    • Stores all 1..16 D3D12 viewports and 1..16 scissor rects in GraphicsCommandList (validating count <= 16 on both) and caches a shared DrawViewports block (zero allocation per draw, and nullptr / zero overhead for the common 1-viewport case).
    • Updates record_draw and DispatchMesh to skip rasterization only when all bound viewports are empty, so draws with an empty viewport 0 and active viewports 1..15 still run.
  • Vulkan 1.3 dynamic state (runtime/src/vulkan_backend.h, runtime/shims/d3d12_vulkan_device.cpp, runtime/src/vulkan_replay.h):
    • Enables VkPhysicalDeviceFeatures::multiViewport in create_vulkan_device_standalone and vktest::Device (plus shaderOutputViewportIndex in vktest::Device).
    • Loads vkCmdSetViewportWithCount and vkCmdSetScissorWithCount (Vulkan 1.3 core) and switches graphics pipelines to VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT + VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT (with viewportCount = 0, scissorCount = 0) whenever features.multiViewport and the entry points are available (falling back cleanly to single-viewport vkCmdSetViewport / vkCmdSetScissor otherwise).
    • Handles mismatched viewport/scissor counts and empty viewport slots per both D3D12 and Vulkan specs: passes matching count = max(vp_count, sc_count) to both calls, pairs empty/unbound viewport slots with a 1×1 dummy viewport and an empty {0, 0, 0, 0} scissor so nothing rasterizes and Vulkan's width > 0 VUID is satisfied, and clips unbound scissor slots with {0, 0, 0, 0}.
  • Live GPU host-parity test (runtime/test/d3d12_multi_viewport_test.cpp):
    • Self-contained (in-memory SPIR-V 1.5 VS with OpCapability MultiViewport + OpCapability ShaderViewportIndex writing BuiltIn ViewportIndex, HLSL via d3dcompiler_47 for host reference).
    • Verifies 4 simultaneous quadrant viewports in a single draw call, 4 independent half-clipping scissors, mismatched counts (4 viewports / 2 scissors), and empty viewport 0 + active viewports 1..3 — comparing all 64/64 pixels byte-for-byte against host Windows D3D12.

Tested

  • Built d3d12_multi_viewport_test, d3d12_state_map_test, and replay_cpu_bench with MSVC 19.44 (vcvars64) + Ninja on top of main 8f481cf16.
  • d3d12_multi_viewport_test: ALL 4 CASES PASSED (EXACT MATCH vs host D3D12) — 64/64 pixels exact on every case on NVIDIA GeForce GTX 1650 with 0 validation errors.
  • d3d12_state_map_test: PASSED.
  • py -3.13 -I scripts/check_no_game_data.py on all 9 touched files: clean.

GPUs tested: NVIDIA GeForce GTX 1650 Mobile 4 GB (driver 592.00, Vulkan 1.4.325, Windows 11 26200)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — D3D12 → Vulkan runtime only)

🔄 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/510 **Author:** [@jujumoneylol](https://github.com/jujumoneylol) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `pr/d3d12-multi-viewport` --- ### 📝 Commits (1) - [`7d50f3b`](https://github.com/ubiquitarianism/leonida/commit/7d50f3b749ab8c2902bef94ef8cc76885c22712a) d3d12/vulkan: implement multi-viewport and multi-scissor rendering (1..16 viewports/scissors) ### 📊 Changes **9 files changed** (+652 additions, -40 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+9 -0) 📝 `runtime/shims/d3d12_com.cpp` (+60 -9) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+24 -20) 📝 `runtime/src/command_list.h` (+10 -0) 📝 `runtime/src/vulkan_backend.h` (+3 -0) 📝 `runtime/src/vulkan_replay.h` (+56 -11) ➕ `runtime/test/d3d12_multi_viewport_test.cpp` (+484 -0) 📝 `runtime/test/replay_cpu_bench.cpp` (+2 -0) 📝 `runtime/test/vk_test_device.h` (+4 -0) </details> ### 📄 Description Claimed in the coordination issue as: D3D-MULTI-VIEWPORT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7124010841) Depends on: #469, #499 (adjacent lines in `vulkan_replay.h` draw replay, `d3d12_vulkan_device.cpp`, `d3d12_com.cpp`, and `vk_test_device.h` if multiple merge; this branch is based cleanly on current `main` `8f481cf16` with no code dependency on either) ### What and why Previously, `RSSetViewports` and `RSSetScissorRects` silently dropped every viewport and scissor past index 0 (`stub("more than one viewport; the first is used")`), and graphics pipelines fixed `viewportCount = 1` / `scissorCount = 1` even though `main` already enables Vulkan 1.2 `shaderOutputViewportIndex` and advertises `VPAndRTArrayIndexFromAnyShaderFeedingRasterizerSupportedWithoutGSEmulation = TRUE`. - **Command list (`runtime/src/command_list.h`, `runtime/shims/d3d12_com.cpp`)**: - Stores all 1..16 D3D12 viewports and 1..16 scissor rects in `GraphicsCommandList` (validating `count <= 16` on both) and caches a shared `DrawViewports` block (zero allocation per draw, and `nullptr` / zero overhead for the common 1-viewport case). - Updates `record_draw` and `DispatchMesh` to skip rasterization only when *all* bound viewports are empty, so draws with an empty viewport 0 and active viewports 1..15 still run. - **Vulkan 1.3 dynamic state (`runtime/src/vulkan_backend.h`, `runtime/shims/d3d12_vulkan_device.cpp`, `runtime/src/vulkan_replay.h`)**: - Enables `VkPhysicalDeviceFeatures::multiViewport` in `create_vulkan_device_standalone` and `vktest::Device` (plus `shaderOutputViewportIndex` in `vktest::Device`). - Loads `vkCmdSetViewportWithCount` and `vkCmdSetScissorWithCount` (Vulkan 1.3 core) and switches graphics pipelines to `VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT` + `VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT` (with `viewportCount = 0`, `scissorCount = 0`) whenever `features.multiViewport` and the entry points are available (falling back cleanly to single-viewport `vkCmdSetViewport` / `vkCmdSetScissor` otherwise). - Handles mismatched viewport/scissor counts and empty viewport slots per both D3D12 and Vulkan specs: passes matching `count = max(vp_count, sc_count)` to both calls, pairs empty/unbound viewport slots with a 1×1 dummy viewport and an empty `{0, 0, 0, 0}` scissor so nothing rasterizes and Vulkan's `width > 0` VUID is satisfied, and clips unbound scissor slots with `{0, 0, 0, 0}`. - **Live GPU host-parity test (`runtime/test/d3d12_multi_viewport_test.cpp`)**: - Self-contained (in-memory SPIR-V 1.5 VS with `OpCapability MultiViewport` + `OpCapability ShaderViewportIndex` writing `BuiltIn ViewportIndex`, HLSL via `d3dcompiler_47` for host reference). - Verifies 4 simultaneous quadrant viewports in a single draw call, 4 independent half-clipping scissors, mismatched counts (4 viewports / 2 scissors), and empty viewport 0 + active viewports 1..3 — comparing all 64/64 pixels byte-for-byte against host Windows D3D12. ### Tested - Built `d3d12_multi_viewport_test`, `d3d12_state_map_test`, and `replay_cpu_bench` with MSVC 19.44 (`vcvars64`) + Ninja on top of `main` `8f481cf16`. - `d3d12_multi_viewport_test`: **ALL 4 CASES PASSED (EXACT MATCH vs host D3D12)** — 64/64 pixels exact on every case on NVIDIA GeForce GTX 1650 with 0 validation errors. - `d3d12_state_map_test`: PASSED. - `py -3.13 -I scripts/check_no_game_data.py` on all 9 touched files: clean. GPUs tested: NVIDIA GeForce GTX 1650 Mobile 4 GB (driver 592.00, Vulkan 1.4.325, Windows 11 26200) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — D3D12 → Vulkan runtime only) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:17 +01:00
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#558
No description provided.