Repository navigation
Runtime: preserve and replay sixteen D3D12 viewport and scissor slots - #4550
pmilewsskiedu-gif wants to merge 2 commits into
Conversation
Kam471
left a comment
There was a problem hiding this comment.
Built and ran d3d12_multi_viewport_test at e88f66a1 on Windows 11, RTX 5070 Ti: 5 scenarios, 0 failures, Vulkan validation errors=0.
The layer matches WARP byte-for-byte for two viewports, a scissor clipping half of viewport 1, all sixteen viewport/scissor slots, parent viewports inherited into a bundle, and arrays snapshotted before draw. No blocking issue.
whattheflop
left a comment
There was a problem hiding this comment.
Tested exact 548f810e on Windows 11, Ryzen 7 9800X3D Radeon iGPU, AMD 25.10.30.02. Stock multi-viewport test passed 5/5 with 320/320 pixels matching WARP, all ten command lists closed successfully, and zero Vulkan validation errors. The 16-slot case rendered through slot 1. Details in #166. AI-assisted.
|
Tested
Tested and written by Claude (Claude Code), posting from @theswiss24's account. |
Flyander
left a comment
There was a problem hiding this comment.
Two state/draw semantics differ from D3D12 in the current viewport/scissor path.
| // No viewport (never set, or unbound with RSSetViewports(0)) or an empty one: D3D12 rasterizes nothing, | ||
| // and Vulkan forbids a 0x0 viewport, so the draw is not recorded. | ||
| if (!(viewport_.width > 0) || !(viewport_.height > 0)) return; | ||
| if (!viewport_count_ || |
There was a problem hiding this comment.
[P2] Keep the draw when no viewport can rasterize
A zero viewport count disables viewport state; it does not cancel the draw command. Returning here drops input assembly and vertex-shader invocations along with rasterization, so pipeline-statistics queries (including VSInvocations) no longer match D3D12. Microsoft documents that undefined viewports are disabled and that VSInvocations count vertex-shader invocations. Please preserve the draw with a no-rasterization state (for example, a placeholder viewport plus an empty scissor), as the older #873 path did. RSSetViewports, pipeline statistics.
|
|
||
| void STDMETHODCALLTYPE RSSetScissorRects(UINT count, const D3D12_RECT* rects) override { | ||
| if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false); | ||
| if (!count || !rects) return; |
There was a problem hiding this comment.
[P2] Clear stored scissor state for a zero-count call
RSSetScissorRects(0, nullptr) is a valid way to bind no scissor rectangles. Returning without clearing scissors_ and scissor_count_ makes later draws reuse the previous rectangles, although D3D12 says rectangles not defined by the call are disabled. Reset the stored array/count when count == 0; keep the null-pointer rejection for a positive count. Microsoft RSSetScissorRects contract.
|
Tested 548f810 merged onto main d0835dd on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:
AI-assisted (Claude Code). |
Claimed before production implementation on current coordinator #4421: #4421 (comment)
Production defect and fix
Unmodified
origin/main03b09a086592a197db64d91655c6e65c30764d96records only viewport/scissor slot 0 inRSSetViewports/RSSetScissorRectsand in Draw IR, and creates Vulkan graphics pipelines with viewportCount=scissorCount=1. A shader writing D3D12SV_ViewportArrayIndex=1(translated GLSLgl_ViewportIndex=1) cannot rasterize through a separately bound viewport/scissor even though its shader translator already supports that output.Fixes the entire graphics path: COM copies every bound slot (up to D3D12's 16), resets viewport arrays on zero-viewports, snapshots the state in recorded Draw commands and inherited parent-to-bundle execution, and dynamically emits the selected Vulkan viewport/scissor slots. The graphics device enables
multiViewportonly where physically supported;GraphicsPipelinebuilds its normal 1-slot pipeline by default, lazily compiling a 16-slot variant only for multi-slot draws, avoiding a 16× dynamic state overhead on ordinary scenes. Additional slot snapshots are allocated only when needed. Vulkan-invalid missing/zero-size slots receive a legal placeholder viewport and empty scissor. The prepare path rejects a multi-viewport draw when the logical device lacks multiViewport rather than issuing invalid Vulkan commands; attachment-free rendering area spans the bound viewports. Unrelated zero-count scissor semantics are intentionally reserved to already published PR #4411 (no duplicate implementation here).Same-source original-main RED / patched GREEN, real GPU and WARP pixel oracle
Original synthetic VS compiled in HLSL to WARP (
SV_ViewportArrayIndex=1) and in GLSL to SPIR-V for the translator-style Leonida layer (gl_ViewportIndex=1); no game shaders or other game assets. Five scenarios: (1) two viewports, shader selects slot1; (2) independent scissor1 clips half; (3) full 16 viewport/scissor slot boundary; (4) parent viewports inherited by an ExecuteBundle draw; (5) host input arrays deliberately modified after binding to verify snapshot. Native WARP callsClose()==S_OKand draws expected red pixels through viewport1 in all cases.LeonidaMultiViewportBaseline20261122: all five WARP-vs-Leonida pixel scenarios fail (WARP slot1 red but Leonida all-blue), Close S_OK and zero Vulkan validation errors, executable exit 1. CMake and new test-only files are copied identically;runtime/srcandruntime/shimsare unchanged.e88f66a19f50800311647d95dd3e9d46ac5250bbon RTX 4060 Ti withLEONIDA_VK_VALIDATION=1: all five scenarios match WARP pixel-for-pixel, Close S_OK, 0 Vulkan validation errors, exit 0. Identical test source SHA2562698C9EDADC14CCBD24BF9DBE41D2DC04D0D34CB9E88A0C2890FB60174B7344Aon baseline and patched worktrees.vk_command_replay,d3d12_com,d3d12_draw,d3d12_bundle,d3d12_multi_viewport5/5 PASS (6.00 seconds).d3d12_bundleandd3d12_multi_viewporteach 10/10 consecutive repeats PASS (12.65 seconds total).replay_cpu_bench --self-testpasses 14 kinds and 296-command frame. New GLSL's SPIR-V passes Vulkan 1.3spirv-val;git diff --checkclean.Scope, limitations, disclosure
No authentic GTA VI execution is claimed (
game_scarlett_master.exeunavailable). Cross-GPU Vulkan and full-suite coverage not yet run; tested RTX 4060 Ti Vulkan and native Windows WARP. This PR does not duplicate #4411's zero-count scissor correction; future integration may require a small rebase of adjacent COM lines. Base03b09a08, heade88f66a19f50800311647d95dd3e9d46ac5250bb. Maintainer review required; I will not self-merge.