Preserve fractional viewport coverage in attachmentless draws #2271

Closed
Bonchaloo wants to merge 1 commit from upstream-pr/2271 into main
Bonchaloo commented 2026-11-26 11:57:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Bonchaloo on 2026-11-26T11:57:22Z.


Claimed in #1608 as RT-ATTACHMENTLESS-FRACTIONAL-AREA.

Fix

With no color or depth attachment, Vulkan replay derives the render area from the viewports. Converting their right and bottom edges directly to integers could clip a row or column that contains covered samples. Round the maximum right and bottom edges outward after considering all viewports.

Tests

  • The replay regression fails on the parent commit for a viewport ending at (3.75, 2.75). With this change the recorded render area is 4×3. A second viewport extending to y = 5.75 produces 4×6, and the integer 8×8 control retains its extent.
  • Five focused CTests passed: state map, bounded index view, quad-list replay, and both pipeline compile replay modes. The changed files passed the no-game-data check.
  • GPU tested: Apple M5 Max, Apple Metal driver, macOS 27.3. A separate synthetic attachmentless Metal draw with the same fractional viewport wrote six pixel positions with a 3×2 render area and twelve with a 4×3 area. The regression test captures the Vulkan command; the Metal probe measures raster coverage.

Full native runtime CTest suite on Apple M5 Max with MoltenVK 1.4.2: 105 passed, 0 failed, 3 skipped (shader_library_corpus, vk_device_markers, vk_sync_validation).

AI-assisted: yes.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5509593649 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2271). Originally posted by [Bonchaloo](https://github.com/Bonchaloo) on 2026-11-26T11:57:22Z. --- Claimed in [#1608 as RT-ATTACHMENTLESS-FRACTIONAL-AREA](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7191340976). ### Fix With no color or depth attachment, Vulkan replay derives the render area from the viewports. Converting their right and bottom edges directly to integers could clip a row or column that contains covered samples. Round the maximum right and bottom edges outward after considering all viewports. ### Tests - The replay regression fails on the parent commit for a viewport ending at (3.75, 2.75). With this change the recorded render area is 4×3. A second viewport extending to y = 5.75 produces 4×6, and the integer 8×8 control retains its extent. - Five focused CTests passed: state map, bounded index view, quad-list replay, and both pipeline compile replay modes. The changed files passed the no-game-data check. - GPU tested: Apple M5 Max, Apple Metal driver, macOS 27.3. A separate synthetic attachmentless Metal draw with the same fractional viewport wrote six pixel positions with a 3×2 render area and twelve with a 4×3 area. The regression test captures the Vulkan command; the Metal probe measures raster coverage. Full native runtime CTest suite on Apple M5 Max with MoltenVK 1.4.2: 105 passed, 0 failed, 3 skipped (shader_library_corpus, vk_device_markers, vk_sync_validation). AI-assisted: yes.
real-rusher commented 2026-11-26 12:24:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T12:24:01Z.


Verified on main a73a57e1 (Ubuntu 24.04 x86-64, GCC 13.3, CMake 3.28, Ninja, no GPU). Merges cleanly. ctest -R '^d3d12_state_map$' passes with this PR; the PR's runtime/test/d3d12_state_map_test.cpp built against main's vulkan_replay.h fails, so the new case fails on main and passes with the change.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7191951647 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2271#issuecomment-7191951647). Originally posted by [real-rusher](https://github.com/real-rusher) on 2026-11-26T12:24:01Z. --- Verified on main a73a57e1 (Ubuntu 24.04 x86-64, GCC 13.3, CMake 3.28, Ninja, no GPU). Merges cleanly. ctest -R '^d3d12_state_map$' passes with this PR; the PR's runtime/test/d3d12_state_map_test.cpp built against main's vulkan_replay.h fails, so the new case fails on main and passes with the change. AI-assisted: yes (Claude Code)
ecox982745 commented 2026-11-26 14:20:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-26T14:20:09Z.


On an RTX 4090, the fractional viewport in the PR covered six samples with the parent’s render area and twelve with the PR’s. The six recovered samples are exactly the missing right column and bottom row.

I captured the Vulkan viewport, scissor and attachmentless render area emitted by replay at parent a73a57e13 and head 39434d439. I then applied those states in a separate Vulkan dynamic-rendering probe. It drew two triangles forming a viewport-sized quad, at one sample per pixel, with a fixed 8×8 scissor. A precise occlusion query counted the samples. Per-pixel queries located them on an 8×8 grid.

Synthetic case Parent samples PR samples Expected from pixel centers
PR example, right/bottom edges at (3.75, 2.75) 6 12 12
Fractional right edge only 12 16 16
Fractional bottom edge only 8 12 12
Shifted viewport with two fractional edges 6 12 12
Edges at (3.25, 2.25) 6 6 6
Integer 8×8 viewport 64 64 64
Integer viewport at an offset 6 6 6

All seven head coverage masks matched the pixel-center reference, including the quarter-pixel case where outward rounding adds no covered sample. The 30 distinct GPU configurations included a full 8×8 render-area control and an explicit scissor control. Zero Vulkan validation errors. Windows 11, NVIDIA 616.64, synthetic inputs.

AI-assisted verification by OpenAI Codex (GPT-6).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7194653579 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2271#issuecomment-7194653579). Originally posted by [ecox982745](https://github.com/ecox982745) on 2026-11-26T14:20:09Z. --- On an RTX 4090, the fractional viewport in the PR covered six samples with the parent’s render area and twelve with the PR’s. The six recovered samples are exactly the missing right column and bottom row. I captured the Vulkan viewport, scissor and attachmentless render area emitted by replay at parent `a73a57e13` and head `39434d439`. I then applied those states in a separate Vulkan dynamic-rendering probe. It drew two triangles forming a viewport-sized quad, at one sample per pixel, with a fixed 8×8 scissor. A precise occlusion query counted the samples. Per-pixel queries located them on an 8×8 grid. | Synthetic case | Parent samples | PR samples | Expected from pixel centers | | --- | ---: | ---: | ---: | | PR example, right/bottom edges at (3.75, 2.75) | 6 | 12 | 12 | | Fractional right edge only | 12 | 16 | 16 | | Fractional bottom edge only | 8 | 12 | 12 | | Shifted viewport with two fractional edges | 6 | 12 | 12 | | Edges at (3.25, 2.25) | 6 | 6 | 6 | | Integer 8×8 viewport | 64 | 64 | 64 | | Integer viewport at an offset | 6 | 6 | 6 | All seven head coverage masks matched the pixel-center reference, including the quarter-pixel case where outward rounding adds no covered sample. The 30 distinct GPU configurations included a full 8×8 render-area control and an explicit scissor control. Zero Vulkan validation errors. Windows 11, NVIDIA 616.64, synthetic inputs. AI-assisted verification by OpenAI Codex (GPT-6).
Bonchaloo commented 2026-11-26 14:50:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Bonchaloo on 2026-11-26T14:50:37Z.


Confirmed the seven coverage cases above in an independent native Metal probe on Apple M5 Max (macOS 27.3). Two triangles formed a viewport-sized quad in an attachmentless, single-sample pass. Compared every pixel in an 8×8 mask to a pixel-center reference with the truncated and outward-rounded extents.

Covered samples (truncated → outward): original 6 → 12, fractional right edge 12 → 16, fractional bottom edge 8 → 12, shifted viewport 6 → 12, quarter-pixel edges 6 → 6, integer viewport 64 → 64, offset integer viewport 6 → 6. All 14 masks matched. This tests raster coverage directly in Metal; the PR’s replay regression separately checks the Vulkan render area.

AI-assisted: yes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7195411487 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2271#issuecomment-7195411487). Originally posted by [Bonchaloo](https://github.com/Bonchaloo) on 2026-11-26T14:50:37Z. --- Confirmed the seven coverage cases above in an independent native Metal probe on Apple M5 Max (macOS 27.3). Two triangles formed a viewport-sized quad in an attachmentless, single-sample pass. Compared every pixel in an 8×8 mask to a pixel-center reference with the truncated and outward-rounded extents. Covered samples (truncated → outward): original 6 → 12, fractional right edge 12 → 16, fractional bottom edge 8 → 12, shifted viewport 6 → 12, quarter-pixel edges 6 → 6, integer viewport 64 → 64, offset integer viewport 6 → 6. All 14 masks matched. This tests raster coverage directly in Metal; the PR’s replay regression separately checks the Vulkan render area. AI-assisted: yes.
lixonik commented 2026-11-28 08:43:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T08:43:14Z.

Review: APPROVED


Reviewed and tested merged onto main (493867366) on Windows 11 (MSVC 19.44, Ninja Release).

  • Computing right / bottom as floats across all active viewports and rounding up with std::ceil() in prepare_draw() cleanly preserves the final partially covered pixel row/column for attachmentless draws with fractional viewport edges.
  • Built d3d12_state_map_test and ran ctest --output-on-failure -V -R ^d3d12_state_map$: 1/1 passed (0.02 s).

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6096807422 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2271#pullrequestreview-6096807422). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T08:43:14Z. **Review:** APPROVED --- Reviewed and tested merged onto `main` (`493867366`) on Windows 11 (MSVC 19.44, Ninja Release). - Computing `right` / `bottom` as floats across all active viewports and rounding up with `std::ceil()` in `prepare_draw()` cleanly preserves the final partially covered pixel row/column for attachmentless draws with fractional viewport edges. - Built `d3d12_state_map_test` and ran `ctest --output-on-failure -V -R ^d3d12_state_map$`: 1/1 passed (0.02 s). AI-assisted (Antigravity, Gemini).
fiestorra commented 2026-11-30 11:07:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T11:07:45Z.


Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites.

1. It applies. merge-tree clean; the commits cherry-pick onto main d367675c7 without a conflict. Two files: runtime/src/vulkan_replay.h and runtime/test/d3d12_state_map_test.cpp.

2. With the branch its test passes:

ctest -R 'd3d12_state_map'
100% tests passed, 0 tests failed out of 1

3. The control - revert only the header, keep the test:

git checkout origin/main -- runtime/src/vulkan_replay.h
cmake --build … --target d3d12_state_map_test
ctest -R 'd3d12_state_map' --output-on-failure
0% tests passed, 1 tests failed out of 1
line 900: render_area.width == 4 && render_area.height == 3

The failing assertion is the change: the replay must compute a render area of 4 by 3 for this state-map case, and main computes something else. It is a CPU test of the replay's state tracking - no GPU, no device.

What I did not test: the other state combinations the header now maps, and whether 4x3 is the correct area per the console's rule rather than merely what the branch computes - the control shows the test notices the change, not that the change is right.

Why I am commenting: I verify open pull requests that replay onto current main, build the binaries their tests name in ctest --show-only=json-v1, run them, then revert only the source change. 26 controls so far: 18 bite.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7276579486 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2271#issuecomment-7276579486). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-30T11:07:45Z. --- Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites. **1. It applies.** `merge-tree` clean; the commits cherry-pick onto `main` `d367675c7` without a conflict. Two files: `runtime/src/vulkan_replay.h` and `runtime/test/d3d12_state_map_test.cpp`. **2. With the branch its test passes:** ``` ctest -R 'd3d12_state_map' 100% tests passed, 0 tests failed out of 1 ``` **3. The control - revert only the header, keep the test:** ``` git checkout origin/main -- runtime/src/vulkan_replay.h cmake --build … --target d3d12_state_map_test ctest -R 'd3d12_state_map' --output-on-failure 0% tests passed, 1 tests failed out of 1 line 900: render_area.width == 4 && render_area.height == 3 ``` **The failing assertion is the change**: the replay must compute a render area of **4 by 3** for this state-map case, and `main` computes something else. **It is a CPU test of the replay's state tracking** - no GPU, no device. **What I did not test:** the other state combinations the header now maps, and whether `4x3` is the correct area per the console's rule rather than merely what the branch computes - **the control shows the test notices the change, not that the change is right.** **Why I am commenting:** I verify open pull requests that replay onto current `main`, build the binaries their tests name in `ctest --show-only=json-v1`, run them, then revert **only** the source change. **26 controls so far: 18 bite.** Written with an AI assistant.
aslan2142 commented 2026-12-01 12:28:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:28:01Z.


Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7311172201 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2271#issuecomment-7311172201). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:28:01Z. --- Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
aslan2142 commented 2026-12-01 16:43:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:43:23Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318104529 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2271#issuecomment-7318104529). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:43:23Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

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!2271
No description provided.