gpu: expand console primitive topologies into host list index buffers #690

Open
github-bot wants to merge 2 commits from github-bot/gh-690 into main AGit
Owner

@⁠wbkepler on GitHub · 2026-11-24 06:56 UTC · original
wbkepler:gpu/primitive-topology-expansion → main · +2318 −33 · 4 files · 2 commits · open

Summary

Expands console-only primitive topologies (TRIANGLE_FAN, LINE_LOOP, QUADS, QUAD_STRIP) into standard D3D12 TRIANGLELIST/LINELIST scratch index buffers in primitive.rs and draw.rs, exposing HostPipeline::strip_cut from pipeline/host.rs:

  • Supports non-indexed and submission-deferred indexed draws with R16_UINT/R32_UINT index formats, base_vertex/start_index offsets, strip_cut primitive restarts, consistent winding/provoking-vertex order, and degenerate tail padding.
  • Zero overhead on standard PC topologies and RECTANGLES.

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed (hardware GPU)
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib primitive — passed (6/6 including live GPU/WARP backface-culled winding, strip-cut, and LINE_LOOP closing-edge tests)
  • cargo xtask policy — passed (151 files ok)
**@⁠wbkepler** on GitHub · 2026-11-24 06:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/690) `wbkepler:gpu/primitive-topology-expansion` → `main` · +2318 −33 · 4 files · 2 commits · open ## Summary Expands console-only primitive topologies (`TRIANGLE_FAN`, `LINE_LOOP`, `QUADS`, `QUAD_STRIP`) into standard D3D12 `TRIANGLELIST`/`LINELIST` scratch index buffers in `primitive.rs` and `draw.rs`, exposing `HostPipeline::strip_cut` from `pipeline/host.rs`: - Supports non-indexed and submission-deferred indexed draws with `R16_UINT`/`R32_UINT` index formats, `base_vertex`/`start_index` offsets, `strip_cut` primitive restarts, consistent winding/provoking-vertex order, and degenerate tail padding. - Zero overhead on standard PC topologies and `RECTANGLES`. ## Verification - `cargo clippy --workspace --all-targets` — passed (zero new warnings) - `cargo clippy -p victory --features diagnostics --all-targets` — passed - `cargo test --workspace` — passed (hardware GPU) - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib primitive` — passed (6/6 including live GPU/WARP backface-culled winding, strip-cut, and `LINE_LOOP` closing-edge tests) - `cargo xtask policy` — passed (151 files ok)
- Add ExpandedTopology (TRIANGLE_FAN, LINE_LOOP, QUADS, QUAD_STRIP) in primitive.rs with 16-bit and 32-bit non-indexed and indexed expansion, strip-cut/primitive-restart handling, and degenerate tail padding.

- Map LINE_LOOP to D3D_PRIMITIVE_TOPOLOGY_LINELIST and TRIANGLE_FAN/QUADS/QUAD_STRIP to TRIANGLELIST in draw::State::set_topology.

- Expand non-indexed and indexed console topology draws via HostList scratch upload index buffers while honoring base_vertex, start_index, R16_UINT/R32_UINT index format, and HostPipeline::strip_cut.

- Add unit and live D3D12 hardware/WARP rendering tests covering winding order, backface culling, strip cuts, and LINE_LOOP closing edges.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:09 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 07:39 UTC · original · edited 2026-11-24 08:45 UTC

I exercised the indexed draw path on 79a476f with a synthetic 4×4 target, on RTX 5090 and WARP. Before the draw, a native CopyBufferRegion replaces three indices in the same VIctory index-buffer shadow.

On both backends, a standard triangle-list draw with that same-list copy rendered the expected 16/16 green pixels. The expanded triangle fan also matched 16/16 when the indices came from the CPU or from a GPU copy in a completed earlier submission. The expanded fan with the copy in the same list rendered all 16 pixels red, matching the old indices. After that submission the index copyback contained the new indices, even though the draw used the old triangle. The D3D12 debug layer reported no errors.

The fan expansion's deferred CPU read runs while the host prepares the list, before the preceding native copy executes. This case needs to exercise expansion from indices produced earlier on the GPU in the same list.

I tested a separate native prototype at the same head. A private indexed point-list pass with strip cut disabled captures SV_VertexID in order through stream output. A compute pass then expands the captured stream, applying the original restart rule, before the final indexed draw. The source stays in its ordinary IA index-buffer state.

On RTX 5090 and WARP, the same-list native copy followed by this path rendered 16/16 expected pixels with both 16-bit and 32-bit fan indices. On each adapter, 64 small expansion cases matched the existing CPU output index for index across all four topologies, including restart and padding. D3D12 reported zero errors. The prototype uses a serial compute kernel for these small cases.

The chunked version now matches the CPU expansion in 112 synthetic cases per adapter, up to 262,147 input indices, including restart markers across chunk boundaries. A test-only hook in the real State::draw_indexed path then restored the graphics PSO, root parameters and IA topology after capture and compute. In the same R32 fan fixture, stock output was 0/16 expected pixels and the hooked path was 16/16 on both RTX 5090 and WARP. All three controls still match and D3D12 reported zero errors.

The local source candidate now reuses capture, work and result buffers on the host list and preserves per-draw CPU snapshots for deferred CPU copies. I tested one closed list with two expanded fans, a following ordinary indexed draw, and two CPU-copy fan draws targeting separate regions. The R32 fan used 32,769 input indices to force scratch growth after the R16 fan. With new producer uploads, a second synchronous submission of the same list swapped the GPU-produced fan colors and still matched all 20 pixels on both adapters for both runs. The R16 case also used a nonzero start index and negative base vertex, and a graphics root constant verified restored bindings. The D3D12 debug layer reported zero errors.

The native copy fixture explicitly puts its source in index-buffer state.

I tested the UAV handoff with a source branch stacked on this PR at 79a476f and #334 at af2aecf. The integration commit c2ce583 requests #334's tracked index-read state after the private expansion buffers are ready and before the capture draw.

A native compute shader wrote R32 indices through a UAV in the same list. The fixture registered the producer with the tracker, then used the guest indexed draw entry for an expanded fan and an ordinary triangle list. Each drew 8/8 expected pixels on RTX 5090 and WARP. Replaying the same closed list with new shader parameters changed both draws from green to blue and returned the new indices to CPU memory. Both runs had zero D3D12 debug-layer errors. This covers a tracked writer. Resource discovery for bindless or aliased UAVs is outside this result.

**@⁠fuzeofficlal** on GitHub · 2026-11-24 07:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/690#issuecomment-7125219532) · edited 2026-11-24 08:45 UTC I exercised the indexed draw path on `79a476f` with a synthetic 4×4 target, on RTX 5090 and WARP. Before the draw, a native `CopyBufferRegion` replaces three indices in the same VIctory index-buffer shadow. On both backends, a standard triangle-list draw with that same-list copy rendered the expected 16/16 green pixels. The expanded triangle fan also matched 16/16 when the indices came from the CPU or from a GPU copy in a completed earlier submission. The expanded fan with the copy in the same list rendered all 16 pixels red, matching the old indices. After that submission the index copyback contained the new indices, even though the draw used the old triangle. The D3D12 debug layer reported no errors. The fan expansion's deferred CPU read runs while the host prepares the list, before the preceding native copy executes. This case needs to exercise expansion from indices produced earlier on the GPU in the same list. I tested a separate native prototype at the same head. A private indexed point-list pass with strip cut disabled captures `SV_VertexID` in order through stream output. A compute pass then expands the captured stream, applying the original restart rule, before the final indexed draw. The source stays in its ordinary IA index-buffer state. On RTX 5090 and WARP, the same-list native copy followed by this path rendered 16/16 expected pixels with both 16-bit and 32-bit fan indices. On each adapter, 64 small expansion cases matched the existing CPU output index for index across all four topologies, including restart and padding. D3D12 reported zero errors. The prototype uses a serial compute kernel for these small cases. The chunked version now matches the CPU expansion in 112 synthetic cases per adapter, up to 262,147 input indices, including restart markers across chunk boundaries. A test-only hook in the real `State::draw_indexed` path then restored the graphics PSO, root parameters and IA topology after capture and compute. In the same R32 fan fixture, stock output was 0/16 expected pixels and the hooked path was 16/16 on both RTX 5090 and WARP. All three controls still match and D3D12 reported zero errors. The local source candidate now reuses capture, work and result buffers on the host list and preserves per-draw CPU snapshots for deferred CPU copies. I tested one closed list with two expanded fans, a following ordinary indexed draw, and two CPU-copy fan draws targeting separate regions. The R32 fan used 32,769 input indices to force scratch growth after the R16 fan. With new producer uploads, a second synchronous submission of the same list swapped the GPU-produced fan colors and still matched all 20 pixels on both adapters for both runs. The R16 case also used a nonzero start index and negative base vertex, and a graphics root constant verified restored bindings. The D3D12 debug layer reported zero errors. The native copy fixture explicitly puts its source in index-buffer state. I tested the UAV handoff with [a source branch](https://github.com/fuzeofficlal/VIctory/tree/fix/gpu-index-shadow-handoff) stacked on this PR at `79a476f` and #334 at `af2aecf`. [The integration commit `c2ce583`](https://github.com/fuzeofficlal/VIctory/commit/c2ce583470c56c5ba881f4d199656df0df334a25) requests #334's tracked index-read state after the private expansion buffers are ready and before the capture draw. A native compute shader wrote R32 indices through a UAV in the same list. The fixture registered the producer with the tracker, then used the guest indexed draw entry for an expanded fan and an ordinary triangle list. Each drew 8/8 expected pixels on RTX 5090 and WARP. Replaying the same closed list with new shader parameters changed both draws from green to blue and returned the new indices to CPU memory. Both runs had zero D3D12 debug-layer errors. This covers a tracked writer. Resource discovery for bindless or aliased UAVs is outside this result.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:35 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/primitive.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/690#issuecomment-7148670714) <!-- victory-triage v1 head=a354403666025e79e0844d8d0494face88a09fd2 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/primitive.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/pipeline/host.rs
  • crates/victory-gpu/src/primitive.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/690/head:github-bot/gh-690'
git switch 'github-bot/gh-690'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-690'
git switch 'github-bot/gh-690'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-690'
git switch 'github-bot/gh-690'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-690'
git switch 'main'
git merge --squash 'github-bot/gh-690'
git switch 'main'
git merge --ff-only 'github-bot/gh-690'
git switch 'main'
git merge 'github-bot/gh-690'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!690
No description provided.