shader/gpu: add compute-to-draw fallback for mesh shaders #246

Open
rudy-07 wants to merge 2 commits from upstream-pr/246 into main
rudy-07 commented 2026-11-30 17:30:39 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by rudy-07 on 2026-11-30T17:30:39Z.


GPUs without D3D12 mesh shader support (e.g. AMD RDNA1 / Feature Level 12_1) currently have all mesh pipelines refused in victory-gpu. This adds a compute-to-draw fallback path when !host.mesh_shaders().

Changes:

  • crates/victory-shader:
    • Reserve SLOT_MESH_FALLBACK (251) and add mesh_fallback compute lowering (cs_6_6) in lower.rs / shader.rs so mesh shaders write triangle indices, per-vertex outputs, and per-primitive outputs into a per-group scratch buffer instead of calling setMeshOutputCounts / emitIndices / storeVertexOutput.
    • Add emit/mesh_fallback.rs (emit_mesh_fallback, mesh_fallback_vs) to generate the matching vs_6_6 pass-through shader reading SV_VertexID from the scratch buffer and forwarding OSG1 outputs to the pixel shader.
    • Add translate_mesh_fallback, Root::View support in Host::draw, and INPUT_PATHS registration in lib.rs.
  • crates/victory-gpu:
    • Populate Translated::mesh_fallback in pipeline.rs when the host lacks mesh shaders.
    • Build MeshFallbackPipeline (CS + VS/PS PSOs) in pipeline/host.rs instead of refusing the pipeline.
    • Add dispatch_mesh_fallback in draw.rs to allocate a scratch UAV buffer, dispatch the compute kernel, transition UAV -> SRV, and draw x * max_primitives * 3 vertices.

Tested on Windows 11 x64 (AMD Radeon RX 5600M, driver 32.0.21043.19003):

  • cargo test -p victory-shader --locked mesh_fallback: 1 passed (DXIL validation + compute dispatch + VS/PS draw, including edge flags and culling)
  • cargo test -p victory-shader --locked source_tests: 1 passed
  • cargo test -p xtask --locked: 4 passed
  • cargo clippy --workspace --all-targets --locked -- -D warnings: pass
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass
<!-- greyfinch-sync:DexNom/VIctory:issue:5570366955 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/246). Originally posted by [rudy-07](https://github.com/rudy-07) on 2026-11-30T17:30:39Z. --- GPUs without D3D12 mesh shader support (e.g. AMD RDNA1 / Feature Level 12_1) currently have all mesh pipelines refused in `victory-gpu`. This adds a compute-to-draw fallback path when `!host.mesh_shaders()`. Changes: - `crates/victory-shader`: - Reserve `SLOT_MESH_FALLBACK` (`251`) and add `mesh_fallback` compute lowering (`cs_6_6`) in `lower.rs` / `shader.rs` so mesh shaders write triangle indices, per-vertex outputs, and per-primitive outputs into a per-group scratch buffer instead of calling `setMeshOutputCounts` / `emitIndices` / `storeVertexOutput`. - Add `emit/mesh_fallback.rs` (`emit_mesh_fallback`, `mesh_fallback_vs`) to generate the matching `vs_6_6` pass-through shader reading `SV_VertexID` from the scratch buffer and forwarding `OSG1` outputs to the pixel shader. - Add `translate_mesh_fallback`, `Root::View` support in `Host::draw`, and `INPUT_PATHS` registration in `lib.rs`. - `crates/victory-gpu`: - Populate `Translated::mesh_fallback` in `pipeline.rs` when the host lacks mesh shaders. - Build `MeshFallbackPipeline` (CS + VS/PS PSOs) in `pipeline/host.rs` instead of refusing the pipeline. - Add `dispatch_mesh_fallback` in `draw.rs` to allocate a scratch UAV buffer, dispatch the compute kernel, transition UAV -> SRV, and draw `x * max_primitives * 3` vertices. Tested on Windows 11 x64 (AMD Radeon RX 5600M, driver 32.0.21043.19003): - `cargo test -p victory-shader --locked mesh_fallback`: 1 passed (DXIL validation + compute dispatch + VS/PS draw, including edge flags and culling) - `cargo test -p victory-shader --locked source_tests`: 1 passed - `cargo test -p xtask --locked`: 4 passed - `cargo clippy --workspace --all-targets --locked -- -D warnings`: pass - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: pass
Zippp69 commented 2026-11-30 18:04:37 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Zippp69 on 2026-11-30T18:04:37Z.


The mesh fallback test needs a writable scratch buffer and a visible pixel output. My Windows run on fad0bcd failed with missing root UAV output. The test binds Root::Uav(0) but passes a View::Buffer SRV. Using views: &[View::RawUavData(&scratch_words)] got through dispatch, and readback contained the expected indices and positions. The next assertion failed because stub_ps() writes zero to red while the test counts pixels with red greater than 0.5. After making the pixel stub write 1.0 to red, the test passed for the triangle, edge flags, and cull cases. Test fixture · Pixel stub

Per-primitive outputs are still unhandled. The compute path reserves and writes per-primitive data, but the generated VS builds its output signature from fallback.outputs and reads only vertex records. Mesh pipelines that need the primitive outputs cannot receive them through this fallback. The passing triangle fixture has no per-primitive outputs. Forward those outputs or refuse the fallback for affected shaders until it supports them. This finding is from static inspection. Generated VS

<!-- greyfinch-sync:DexNom/VIctory:comment:7287308824 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/246#issuecomment-7287308824). Originally posted by [Zippp69](https://github.com/Zippp69) on 2026-11-30T18:04:37Z. --- **The mesh fallback test needs a writable scratch buffer and a visible pixel output.** My Windows run on `fad0bcd` failed with `missing root UAV output`. The test binds `Root::Uav(0)` but passes a `View::Buffer` SRV. Using `views: &[View::RawUavData(&scratch_words)]` got through dispatch, and readback contained the expected indices and positions. The next assertion failed because `stub_ps()` writes zero to red while the test counts pixels with red greater than 0.5. After making the pixel stub write 1.0 to red, the test passed for the triangle, edge flags, and cull cases. [Test fixture](https://github.com/DexNom/VIctory/blob/fad0bcd0a6ae1f7acd4995774ea08778888b1bf6/crates/victory-shader/src/emit/mesh_fallback.rs#L347-L421) · [Pixel stub](https://github.com/DexNom/VIctory/blob/fad0bcd0a6ae1f7acd4995774ea08778888b1bf6/crates/victory-shader/src/emit/host.rs#L560-L595) **Per-primitive outputs are still unhandled.** The compute path reserves and writes per-primitive data, but the generated VS builds its output signature from `fallback.outputs` and reads only vertex records. Mesh pipelines that need the primitive outputs cannot receive them through this fallback. The passing triangle fixture has no per-primitive outputs. Forward those outputs or refuse the fallback for affected shaders until it supports them. This finding is from static inspection. [Generated VS](https://github.com/DexNom/VIctory/blob/fad0bcd0a6ae1f7acd4995774ea08778888b1bf6/crates/victory-shader/src/emit/mesh_fallback.rs#L139-L265)
rudy-07 commented 2026-11-30 18:21:46 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by rudy-07 on 2026-11-30T18:21:46Z.


Addressed both points in crates/victory-shader/src/emit/mesh_fallback.rs:

  • Fixed mesh_fallback_validates_and_draws_triangle to bind View::RawUavData(&scratch_words) for the compute scratch UAV and use a local solid_red_ps() (since stub_ps() writes zeros).
  • Refused emit_mesh_fallback when PSG1 has per-primitive outputs (with a unit test emit_mesh_fallback_refuses_per_primitive_outputs) until the fallback VS forwards them.

Re-verified cargo test -p victory-shader --locked mesh_fallback (2 passed), clippy (default & --all-features), and cargo xtask policy --staged.

<!-- greyfinch-sync:DexNom/VIctory:comment:7287738476 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/246#issuecomment-7287738476). Originally posted by [rudy-07](https://github.com/rudy-07) on 2026-11-30T18:21:46Z. --- Addressed both points in `crates/victory-shader/src/emit/mesh_fallback.rs`: - Fixed `mesh_fallback_validates_and_draws_triangle` to bind `View::RawUavData(&scratch_words)` for the compute scratch UAV and use a local `solid_red_ps()` (since `stub_ps()` writes zeros). - Refused `emit_mesh_fallback` when `PSG1` has per-primitive outputs (with a unit test `emit_mesh_fallback_refuses_per_primitive_outputs`) until the fallback VS forwards them. Re-verified `cargo test -p victory-shader --locked mesh_fallback` (2 passed), `clippy` (default & `--all-features`), and `cargo xtask policy --staged`.
Zippp69 commented 2026-11-30 18:30:46 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Zippp69 on 2026-11-30T18:30:46Z.


Verified the follow-up on bd28d77. I reran cargo test --locked --offline -p victory-shader --lib mesh_fallback -- --nocapture on Windows. The triangle/edge-flag/cull test and the new per-primitive rejection test both passed. The new guard safely refuses unsupported per-primitive attributes while the fallback VS lacks forwarding for them. Thanks for addressing both points.

<!-- greyfinch-sync:DexNom/VIctory:comment:7287957377 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/246#issuecomment-7287957377). Originally posted by [Zippp69](https://github.com/Zippp69) on 2026-11-30T18:30:46Z. --- **Verified the follow-up on bd28d77.** I reran `cargo test --locked --offline -p victory-shader --lib mesh_fallback -- --nocapture` on Windows. The triangle/edge-flag/cull test and the new per-primitive rejection test both passed. The new guard safely refuses unsupported per-primitive attributes while the fallback VS lacks forwarding for them. Thanks for [addressing both points](https://github.com/DexNom/VIctory/pull/246#issuecomment-7287738476).
rudy-07 commented 2026-11-30 19:34:30 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by rudy-07 on 2026-11-30T19:34:30Z.


No probs

<!-- greyfinch-sync:DexNom/VIctory:comment:7289612940 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/246#issuecomment-7289612940). Originally posted by [rudy-07](https://github.com/rudy-07) on 2026-11-30T19:34:30Z. --- No probs
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/246:upstream-pr/246'
git switch 'upstream-pr/246'

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