d3d12: support multi-viewport and multi-scissor up to 16 entries #827

Closed
kotekompotek wants to merge 1 commit from upstream-pr/827 into main
kotekompotek commented 2026-11-24 14:18:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kotekompotek on 2026-11-24T14:18:14Z.


Claimed in the coordination issue as: coordination issue #14

What and why

  • Rebased onto current main.
  • Supported up to 16 viewports and scissor rectangles via VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT / VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT when VkPhysicalDeviceFeatures::multiViewport is enabled, added log_once notice when clamped to 1, and synced docs/d3d12_vulkan.md.

Tested

  • Built d3d12_com_test and ran ctest -R ^d3d12_com$ (Passed, 1.47s).

GPUs tested: NVIDIA GeForce GTX 1050 (driver 582.28, Windows)

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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473893300 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/827). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-24T14:18:14Z. --- Claimed in the coordination issue as: coordination issue #14 ### What and why - Rebased onto current `main`. - Supported up to 16 viewports and scissor rectangles via `VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT` / `VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT` when `VkPhysicalDeviceFeatures::multiViewport` is enabled, added `log_once` notice when clamped to 1, and synced `docs/d3d12_vulkan.md`. ### Tested - Built `d3d12_com_test` and ran `ctest -R ^d3d12_com$` (`Passed`, 1.47s). GPUs tested: NVIDIA GeForce GTX 1050 (driver 582.28, Windows) 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
abnalstlll-byte commented 2026-11-24 14:22:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T14:22:38Z.

Review: APPROVED


Clean-Room Peer Review for PR #827 (d3d12: support multi-viewport and multi-scissor up to 16 entries)

Outstanding implementation of multi-viewport/scissor rasterizer state:

  • D3D12 API Boundary Parity:
    • RSSetViewports and RSSetScissorRects now support up to D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE (16) elements.
    • Zero-count invocation correctly unbinds all elements ( iewports_.fill({}) / scissors_.fill({})) and sets draw_views_stale_ = true.
    • Rejects count > 16 via check(false).
  • Vulkan Y-Axis Inversion & Dynamic Replay:
    • Replay backend correctly preserves D3D winding by calculating negative-height viewports ({v.x, v.y + v.height, v.width, -v.height, v.min_depth, v.max_depth}) across all array entries.
    • Employs k.set_viewport_with_count and k.set_scissor_with_count dynamically when enabled, while maintaining safe fallback to single-viewport devices.
  • Unit Test Coverage:
    untime/test/d3d12_com_test.cpp and k_test_device.h verify multi-viewport recording and zero-count clearing.
  • Clean-room verification: Strict C++20 compliance, clean MSVC/Clang build, zero proprietary data.

LGTM! Excellent work. Approved.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6040934480 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/827#pullrequestreview-6040934480). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:22:38Z. **Review:** APPROVED --- ### Clean-Room Peer Review for PR #827 (d3d12: support multi-viewport and multi-scissor up to 16 entries) Outstanding implementation of multi-viewport/scissor rasterizer state: - **D3D12 API Boundary Parity**: - RSSetViewports and RSSetScissorRects now support up to D3D12_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE (16) elements. - Zero-count invocation correctly unbinds all elements ( iewports_.fill({}) / scissors_.fill({})) and sets draw_views_stale_ = true. - Rejects count > 16 via check(false). - **Vulkan Y-Axis Inversion & Dynamic Replay**: - Replay backend correctly preserves D3D winding by calculating negative-height viewports ({v.x, v.y + v.height, v.width, -v.height, v.min_depth, v.max_depth}) across all array entries. - Employs k.set_viewport_with_count and k.set_scissor_with_count dynamically when enabled, while maintaining safe fallback to single-viewport devices. - **Unit Test Coverage**: untime/test/d3d12_com_test.cpp and k_test_device.h verify multi-viewport recording and zero-count clearing. - **Clean-room verification**: Strict C++20 compliance, clean MSVC/Clang build, zero proprietary data. LGTM! Excellent work. Approved.
abnalstlll-byte commented 2026-11-24 14:25:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T14:25:59Z.

Review: APPROVED


Clean-room verified (zero game data). Correct implementation of multi-viewport and multi-scissor arrays (up to 16) in GraphicsCommandList and Vulkan replay via multiViewport / vkCmdSetViewportWithCount. Test coverage in d3d12_com_test.cpp.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041002048 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/827#pullrequestreview-6041002048). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:25:59Z. **Review:** APPROVED --- Clean-room verified (zero game data). Correct implementation of multi-viewport and multi-scissor arrays (up to 16) in GraphicsCommandList and Vulkan replay via multiViewport / vkCmdSetViewportWithCount. Test coverage in d3d12_com_test.cpp.
aslan2142 commented 2026-11-24 19:50:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T19:50:41Z.


Thanks for working on multi-viewport support. I'm closing this in favour of #510, which covers the same item:

  • With an empty viewport 0 and other viewports in use, this PR passes a zero-width VkViewport to
    vkCmdSetViewportWithCount, which breaks VUID-VkViewport-width-01770. #510 sends a 1x1 dummy viewport with an
    empty scissor for those slots.
  • #510 includes a pixel test against native D3D12, with 4 quadrant viewports, separate scissors, mismatched counts
    and an empty viewport 0. Two other contributors have confirmed it on Windows. The d3d12_com_test lines here
    don't assert anything, so they also pass on main.
  • #510 also claimed the item before this PR was opened.
  • Your docs/d3d12_vulkan.md update is useful, and so is the idea of a notice when multiViewport is missing.
    Both are worth bringing into #510 or a follow-up.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7142668537 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/827#issuecomment-7142668537). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T19:50:41Z. --- Thanks for working on multi-viewport support. I'm closing this in favour of #510, which covers the same item: - With an empty viewport 0 and other viewports in use, this PR passes a zero-width `VkViewport` to `vkCmdSetViewportWithCount`, which breaks `VUID-VkViewport-width-01770`. #510 sends a 1x1 dummy viewport with an empty scissor for those slots. - #510 includes a pixel test against native D3D12, with 4 quadrant viewports, separate scissors, mismatched counts and an empty viewport 0. Two other contributors have confirmed it on Windows. The `d3d12_com_test` lines here don't assert anything, so they also pass on `main`. - #510 also claimed the item before this PR was opened. - Your `docs/d3d12_vulkan.md` update is useful, and so is the idea of a notice when `multiViewport` is missing. Both are worth bringing into #510 or a follow-up. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!827
No description provided.