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

Open
wbkepler wants to merge 2 commits from upstream-pr/690 into main
wbkepler commented 2026-11-24 06:56:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-24T06:56:27Z.


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)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6576411501 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/690). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-24T06:56:27Z. --- ## 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)
catminou4 commented 2026-11-24 07:01:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T07:00:05Z.

Review: COMMENTED


Static review only (victory-gpu is Windows/D3D12; can't compile or run here):

  • The expansion module is pure index math with four tests, two of which (expand_non_indexed_topologies, expand_indexed_topologies_with_strip_cuts) don't need a GPU — they only need the crate to build, which today means Windows. If the crate ever gets a portable test lane, these are the ones to ungate first.
  • The two GPU tests (quad_strip_and_line_loop_render_on_gpu, backface-culling check) are the right shape for WARP verification on the Windows runner.
  • draw.rs replaces the old once! "console topology drawn as a triangle list" fallback with real DrawIndexedInstanced through a scratch index buffer — the right direction, and the ExpandedTopology::from_console mapping keeps standard PC topologies untouched.

One thing to confirm on Windows: DrawIndexedInstanced(count, instances, 0, base, first_instance) — base as BaseVertexLocation works only if the scratch indices are relative to it; the pure tests cover the index sequences, so the GPU tests should confirm end-to-end.

<!-- greyfinch-sync:Marvisak/VIctory:review:6034974840 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/690#pullrequestreview-6034974840). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T07:00:05Z. **Review:** COMMENTED --- Static review only (victory-gpu is Windows/D3D12; can't compile or run here): - The expansion module is pure index math with four tests, two of which (`expand_non_indexed_topologies`, `expand_indexed_topologies_with_strip_cuts`) don't need a GPU — they only need the crate to build, which today means Windows. If the crate ever gets a portable test lane, these are the ones to ungate first. - The two GPU tests (`quad_strip_and_line_loop_render_on_gpu`, backface-culling check) are the right shape for WARP verification on the Windows runner. - draw.rs replaces the old `once!` "console topology drawn as a triangle list" fallback with real `DrawIndexedInstanced` through a scratch index buffer — the right direction, and the `ExpandedTopology::from_console` mapping keeps standard PC topologies untouched. One thing to confirm on Windows: `DrawIndexedInstanced(count, instances, 0, base, first_instance)` — `base` as BaseVertexLocation works only if the scratch indices are relative to it; the pure tests cover the index sequences, so the GPU tests should confirm end-to-end.
LAKSHYA-cmd-tech commented 2026-11-24 08:02:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T07:13:18Z.

Review: APPROVED


Tested on Windows 11 MSVC (rustc 1.98.1):

  • cargo test -p victory-gpu --lib primitive: 6 passed, 0 failed (including live GPU backface-culled winding, strip-cut triangle fan, and quad-strip / line-loop execution)
  • cargo test -p victory-gpu: 47 passed, 0 failed, 1 ignored
  • cargo xtask policy: 151 files ok

Confirmed: BaseVertexLocation offset handling correctly addresses scratch index sequences and non-indexed topology expansions with accurate winding and primitive restart cuts.

<!-- greyfinch-sync:Marvisak/VIctory:review:6035105763 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/690#pullrequestreview-6035105763). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T07:13:18Z. **Review:** APPROVED --- Tested on Windows 11 MSVC (rustc 1.98.1): - cargo test -p victory-gpu --lib primitive: 6 passed, 0 failed (including live GPU backface-culled winding, strip-cut triangle fan, and quad-strip / line-loop execution) - cargo test -p victory-gpu: 47 passed, 0 failed, 1 ignored - cargo xtask policy: 151 files ok Confirmed: BaseVertexLocation offset handling correctly addresses scratch index sequences and non-indexed topology expansions with accurate winding and primitive restart cuts.
fuzeofficlal commented 2026-11-24 08:02:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T07:39:00Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7125219532 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/690#issuecomment-7125219532). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T07:39:00Z. --- 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.
Marvisak commented 2026-11-25 01:08:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:35:27Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148670714 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/690#issuecomment-7148670714). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:35:27Z. --- <!-- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/690:upstream-pr/690'
git switch 'upstream-pr/690'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/690'
git switch 'upstream-pr/690'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/690'
git switch 'upstream-pr/690'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/690'
git switch 'main'
git merge --squash 'upstream-pr/690'
git switch 'main'
git merge --ff-only 'upstream-pr/690'
git switch 'main'
git merge 'upstream-pr/690'
git push origin 'main'
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
Marvisak/VIctory!690
No description provided.