d3d12/vulkan: implement multi-viewport and multi-scissor rendering (D3D-MULTI-VIEWPORT) #510
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!510
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/510/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@jujumoneylol on GitHub · 2026-11-24 06:38 UTC · original
jujumoneylol:pr/d3d12-multi-viewport→main· +652 −40 · 9 files · 1 commits · merged 2026-11-24 20:31 UTCClaimed in the coordination issue as: D3D-MULTI-VIEWPORT (#14)
Depends on: #469, #499 (adjacent lines in
vulkan_replay.hdraw replay,d3d12_vulkan_device.cpp,d3d12_com.cpp, andvk_test_device.hif multiple merge; this branch is based cleanly on currentmain8f481cf16with no code dependency on either)What and why
Previously,
RSSetViewportsandRSSetScissorRectssilently dropped every viewport and scissor past index 0 (stub("more than one viewport; the first is used")), and graphics pipelines fixedviewportCount = 1/scissorCount = 1even thoughmainalready enables Vulkan 1.2shaderOutputViewportIndexand advertisesVPAndRTArrayIndexFromAnyShaderFeedingRasterizerSupportedWithoutGSEmulation = TRUE.runtime/src/command_list.h,runtime/shims/d3d12_com.cpp):GraphicsCommandList(validatingcount <= 16on both) and caches a sharedDrawViewportsblock (zero allocation per draw, andnullptr/ zero overhead for the common 1-viewport case).record_drawandDispatchMeshto skip rasterization only when all bound viewports are empty, so draws with an empty viewport 0 and active viewports 1..15 still run.runtime/src/vulkan_backend.h,runtime/shims/d3d12_vulkan_device.cpp,runtime/src/vulkan_replay.h):VkPhysicalDeviceFeatures::multiViewportincreate_vulkan_device_standaloneandvktest::Device(plusshaderOutputViewportIndexinvktest::Device).vkCmdSetViewportWithCountandvkCmdSetScissorWithCount(Vulkan 1.3 core) and switches graphics pipelines toVK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT+VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT(withviewportCount = 0,scissorCount = 0) wheneverfeatures.multiViewportand the entry points are available (falling back cleanly to single-viewportvkCmdSetViewport/vkCmdSetScissorotherwise).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'swidth > 0VUID is satisfied, and clips unbound scissor slots with{0, 0, 0, 0}.runtime/test/d3d12_multi_viewport_test.cpp):OpCapability MultiViewport+OpCapability ShaderViewportIndexwritingBuiltIn ViewportIndex, HLSL viad3dcompiler_47for host reference).Tested
d3d12_multi_viewport_test,d3d12_state_map_test, andreplay_cpu_benchwith MSVC 19.44 (vcvars64) + Ninja on top ofmain8f481cf16.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.pyon 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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a — D3D12 → Vulkan runtime only)@sodove on GitHub · 2026-11-24 07:46 UTC · original
Independent Windows verification of the exact #510 diff (
7d50f3b) applied to main1c93c86. NVIDIA RTX 5070 Ti, driver 610.74, Windows 11 26100.7623, MSVC 19.44.35220 Release. Native D3D12 used the same adapter. Khronos Vulkan validation 1.4.369 was enabled and reported zero errors.Synthetic fixtures derived from the PR test. AI-assisted.
@Sangonapou on GitHub · 2026-11-24 14:54 UTC · original
Tested
7d50f3b7on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32, mesh shaders), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows: passRuntime built at this head with
scripts\build_runtime.ps1(MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0). No game files. Tested as it stands (it lists #469 and #499 as adjacent, not merged in).ctest -R ^d3d12_multi_viewport$ -V, host reference the same RTX 3080 Ti through the real D3D12 runtime:@aslan2142 on GitHub · 2026-11-24 20:31 UTC · original
Merged. This was compared with #827 for D3D-MULTI-VIEWPORT, and it is the better fix:
VkViewportthere would breakVUID-VkViewport-width-01770.main.Worth a follow-up, from #827: the
docs/d3d12_vulkan.mdline for this feature, and a notice whenmultiViewportis missing.AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).
@QemmHD on GitHub · 2026-11-24 20:43 UTC · original
Post-merge finding:
d3d12_close_parityhas failed on main since this PR (113 cases, 1 failure):The cause is the new line in
RSSetScissorRects(runtime/shims/d3d12_vulkan_device.cpp):if (count > D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE) return check(false);. That puts the list into the error state, soClosereturnsE_INVALIDARG. The parity row atruntime/test/d3d12_close_parity_test.cpp:362expects the layer to match WARP, and WARP'sClosesucceeds afterRSSetScissorRects(17, …). Before this PR the call only stubbed and used the first rectangle, so the row passed.Measured on Windows 11 / RTX 4070 SUPER (VS 2022, Ninja, RelWithDebInfo): it passes at
58be9cdf8, and fails at plain32a5d9698both plain and withLEONIDA_VK_VALIDATION=1. The only other runtime change in that range is #878 (stencil face masks), which doesn't touch scissors. The rest of the suite is unchanged.There are two ways to fix it, depending on which behaviour the project wants:
count > 16, ignore the call or keep the first 16 instead of callingcheck(false). That matches the existing row and native D3D12's Close.AI-assisted (Claude Code, Claude Opus 5.5).
@aslan2142 on GitHub · 2026-11-24 21:17 UTC · original
@QemmHD thanks, confirmed, and the fix is up as #1286.
d3d12_close_parityhas 0 failures ate0f171958(the commit before this merge) and fails atccd9c5f36with the sameRSSetScissorRects(17)line.RSSetScissorRectsinruntime/shims/d3d12_com.cpp, not ind3d12_vulkan_device.cpp.stubnotice, where the merged code calledcheck(false). Marking the rowstricterwould make the layer refuse lists that D3D12 runs.d3d12_close_parityandd3d12_multi_viewportpass on both devices, and no other test in the suite changes state.I merged #510 without running the whole Windows suite on it; that's on me, and I run it before every runtime merge now. I can't merge my own PR, so could you take a look at #1286? If it can't land soon, I'll revert
ccd9c5f36somainis green in the meantime.AI-assisted (Claude Code, Claude Fable 5.2).