Skip to content

Shader & GPU: merged geometry stages (rebase of #1399, with the batched GSVS write fix) - #1924

Open
slatefield wants to merge 3 commits into
Marvisak:mainfrom
slatefield:up-1399-rebase
Open

slatefield wants to merge 3 commits into
Marvisak:mainfrom
slatefield:up-1399-rebase

Conversation

@slatefield

Copy link
Copy Markdown
Contributor

Rebase of #1399 onto current main (4118f33), plus the regression fix a tester published in that PR's own comment thread. Two commits, both with their authors: the merged-geometry support is wbkepler's, the batched-write fix is molodayamama's. If #1399 is updated first, take that one.

Why it matters: current main refuses ES and GS stages in four places (victory-shader/src/native.rs, io.rs, emit/mod.rs, and victory-gpu/src/pipeline/host.rs), so pipelines with a merged geometry program never get a host pipeline and their draws are dropped. The tester measurement on this PR is +195 programs over main, 0 lost, all of them the "an address in an SGPR that is no root parameter" class, and the README's "merged geometry stages (195 programs)" plus the missing band of distant geometry is this.

The second commit is why this one should not be merged without it: sinan-cmyk's static review found, and molodayamama reproduced on an RTX 4060, that a geometry shader that writes a vertex's outputs before the previous vertex's emit (a compiler batching writes) renders 0 lit pixels instead of 496, while still validating as DXIL. The fix queues the ring writes by vertex and lowers each slot before its emit, with a regression test (emit::tests::merged_geometry_stages_draw_their_triangle).

Rebase conflicts, 3 hunks: native.rs keeps main's vs_outputs(data) wrapper from the mesh fix and moves the body into vs_outputs_at(data, at, count_at) for GS outputs; io.rs keeps main's corrected 9-bit mesh exp prim wording plus the PR's merged-geometry paragraph; lower.rs one test literal gains gs: None. A per-file comparison of added/removed lines against the original PR shows 20 of 21 files identical in both directions, the only delta being the vs_outputs wrapper. The ordering fix cherry-picked with no conflicts.

Checked here: cargo test -p victory-shader --lib 146 passed, 2 ignored (main baseline 144; the PR's two Linux-runnable tests are counted); victory-formats 38, victory-game 15, victory-core 13, victory-pipeline 7, all pass; Windows-target clippy --all-targets with and without --all-features clean for victory-shader and victory-gpu; cargo xtask policy 182 files ok.

Not checked, needs a Windows GPU: the two #[cfg(windows)] tests (the dxil.dll validation of the emitted vs_6_6/gs_6_6 and the live draw comparison), the whole-pipeline wiring, and the whole-title program count re-measured on this base. The PR's own review thread also lists open risks that this rebase does not change: the LDS layout assumed to follow signature rows rather than param slots, silent defaults for missing PSV0 geometry state, non-zero streams with no host consumer, and a write whose signature row is missing being dropped. Refusing those (as the review suggests) is a follow-up that belongs in the same file, not in the rebase.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This pull request does not merge cleanly into main. Conflicting files: crates/victory-shader/src/emit/bvh_tests.rs, crates/victory-shader/src/emit/host.rs, crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/memory_tests.rs, crates/victory-shader/src/emit/mod.rs, crates/victory-shader/src/emit/semantics_tests.rs and 4 more.

It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested PR head directly on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib emit::rect:: — passed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok
  • Merge status: Currently CONFLICTING with origin/main (940d32f). Once rebased onto main, happy to re-verify the full merged-geometry test suite on RTX 5090 + WARP and approve!

AI-assisted (Gemini 4 Neon).

suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 25, 2026
…ometry programs as gs_6_6)

Conflicts: Parts gains both gs (this PR) and view_marks (main); the
direct barycentrics read keeps this branch's SV_Barycentrics input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@slatefield a pointer and a suggestion, since the comparison of this PR with #1315 sits there and not here: #1315 (comment)

Same 642 containers, same command (victory translate --validate --list, CPU and dxil.dll only), each branch's own build:

branch validated of 642 geometry programs lost against main 940d32f
main 940d32f 295 0
this PR, 1aa7225 510 195 0
#1315, 0d45a59 490 195 0

So the two tie on the title's 195 geometry programs. This PR also validates 20 VS_*VfxVBuffer* vertex programs that main emits and the validator refuses (Flags must match usage), which has nothing to do with geometry. emit::tests::merged_geometry_stages_draw_their_triangle at 1aa7225 passes on WARP here (496 lit pixels, interleaved and batched); that is the software adapter only.

Where they differ is in what is refused rather than guessed: the four open risks this PR's description lists (LDS layout taken from signature rows, defaults for missing PSV0 geometry state, non-zero streams, a write whose signature row is missing) are each a refusal in #1315; the linked comment says how. #1315 also has a test for the batched ring writes that this PR's second commit fixes.

Where they stand: #1315 is on main 940d32f, merges cleanly and carries the triage's merge-candidate label; this one carries needs-rebase. My suggestion to the maintainers was to take one of the two, not both. Concretely:

Local title data was used for the counts only (offline, counts and reasons); the test uses none.

AI-assisted (Claude Code).

@zed6000

zed6000 commented Nov 25, 2026

Copy link
Copy Markdown

Measured offline on the title's shaders (the method in #1247: victory translate --validate --list over shaders.rpf 1.0.2.1, dxil.dll 1.8.2502, program by program). These are the 195 geometry programs that fail on main with "an address in an SGPR that is no root parameter", the largest remaining shader gap and the one #293 ranks highest by dropped draws.

Build Change Tests (RX 7900 XTX)
#1399 2900907 vs its base 940d32f +390, 0 lost 250 / 0
this PR 1aa7225 vs its base 4118f33 +390, 0 lost 249 / 0
this PR merged onto current main 13f91ca (resolution below) +390, 0 lost 273 / 0, clippy -D warnings clean with and without --all-features

The +390 is all 195 geometry programs (gs_6_6) plus their 195 export halves (vs_6_6, newly listed as programs), all validating. No program is left with the SGPR-address reason. #1399 and this PR gain exactly the same programs.

Rebase onto 13f91ca: 19 conflict hunks in 11 files. Every one is the same pattern: main's write marks (Options / view_marks) and this PR's geometry stages (gs / Geometry) touch the same lines, and both sides are kept:

  • emit/lower.rs: union of the io and ir imports (GsInput, GsOp, LdsOutput alongside main's Block, Phi); view_marks and gs both in Parts and its three initializers.
  • emit/mod.rs: main's rectangle doc line plus this PR's "Merged geometry stages" paragraph; main's Options struct kept, with the translate doc naming geometry too; view_marks: options.view_marks and gs both set.
  • emit/host.rs: view_marks: false and gs: None. emit/rect.rs: the union of both import lines.
  • 7 test files: view_marks: false and gs: None both in each initializer.
  • One addition git doesn't flag: emit/memory_tests.rs (added on main after this PR's base) builds Parts in two places, lines 554 and 670, and needs gs: None there, or the tests don't compile (E0063).

Offline counts only; no program names or data.

@zed6000

zed6000 commented Nov 26, 2026

Copy link
Copy Markdown

An update to the resolution above, for main 63bcca4. Main has moved since 13f91ca. Merging the 13f91ca port onto 63bcca4 adds one more conflict hunk plus four test initializers git doesn't flag:

  • crates/victory-shader/src/emit/lower.rs, one hunk: main's new code_table_start and this PR's merged_wave_masks sit at the same spot. Keep both: end code_table_start with its } and put merged_wave_masks after it.
  • gs: None, in the lower::Parts { .. } initializers main added since: emit/crosslane_tests.rs, the ds_bpermute test in emit/lower.rs, emit/memory_tests.rs (a second one) and emit/synthetic_tests.rs. Without them, the test build fails with E0063 missing field gs. The same applies to new tests in PRs that land first, such as Shaders: track every incoming edge of a lane-mask phi #385's emit/lower/phi.rs and Shaders: honor permlane EXEC and FI/BC flags (on #1014) #1737's permlane_tests.rs.

Measured on that merge (offline, the title's shaders, RX 7900 XTX): +390, 0 lost again (195 geometry + 195 export halves; 25,240 validate against main's 24,850). cargo test -p victory-shader --lib passes 305/0, and cargo clippy -p victory-shader --all-targets --locked -- -D warnings is clean.

Offline counts only; no program names or data.

wbkepler and others added 3 commits November 26, 2026 11:05
…etry programs as gs_6_6)

The console runs a vertex shader that feeds a geometry shader, and that
geometry shader, as the two halves of one wave, the vertices between them
in LDS. An export program now translates to a plain vertex shader (its
LDS writes are its outputs) and a geometry program to a geometry shader
(its LDS reads are its input primitive's vertices, its LDS writes the
outputs of the vertex its next stream message emits).

- native: `StageIo::Es` / `StageIo::Gs(GsIo)` stage data.
- resource: the geometry stage's own table (`GS_TABLE`, s[8:9]).
- io: ring reads and writes raised to inputs and outputs by row and
  channel; `s_sendmsg` GS / GS_DONE raised to emit, cut and done.
- emit: the geometry-shader state of rectangle lists (`Shader::gs`, the
  `GSState` and `PSV0` it writes) is generalized from "triangles in,
  strips out, n vertices" to a `Geometry` (input primitive, output
  topology, maximum vertices, instances; one stream) that the generated
  rectangle shader and title shaders share. Lowering: vertex-axis
  `loadInput`, `emitStream` / `cutStream` / `emitThenCutStream`,
  `primitiveID`, `gsInstanceID`, the prologue's lane masks as "every
  invocation", no barrier and a return for the export program's handover.
  16-bit values in the rings and streams other than 0 are refused.
- gpu: a title's geometry shader takes the host pipeline's geometry
  stage (root parameters visible to it); a pipeline with one and a
  rectangle-list topology is refused with a reason rather than chained.
- app: `translate` counts export and geometry programs; the pipeline
  pre-build makes records with an export and a geometry stage.

Tests: stage data, I/O raising, and a merged pair drawn on the host
(export program as vertex shader, geometry program after it).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…elds together

Resolution of the rebase onto current main, following zed6000's note in
the PR: main's write marks (Options/view_marks) and the geometry stages
(gs/Geometry) are both kept in Parts, Options and the tester harnesses,
code_table_start and merged_wave_masks both stay in lower.rs, and the
test initializers main added since get gs: None. No behaviour change on
either side.

Windows-target clippy --all-targets, with and without --all-features,
clean; the native lib check passes. The Linux test build fails on the
validator module exactly as main does (pre-existing on 63bcca4).
@slatefield

Copy link
Copy Markdown
Contributor Author

Rebased onto current main 63bcca4 following zed6000's resolution note above, and force-pushed. The branch is now three commits: wbkepler's geometry commit, molodayamama's batched-write fix, and one resolution commit on top.

What the resolution did, beyond the list in that note:

  • Parts/Options/tester harnesses carry both main's view_marks and the geometry gs field, everywhere.
  • lower.rs keeps both code_table_start (main) and merged_wave_masks (this PR), and the imports are the union.
  • All Parts initializers main added since the base got gs: None: memory_tests (the two the note names), crosslane_tests, the ds_bpermute and clmul tests in lower.rs, synthetic_tests, and the harnesses in host.rs/mod.rs (those last ones are HostShader literals, where my first pass wrongly added it and the compiler caught it).

Checked here, Linux box with no GPU: Windows-target clippy --all-targets, with and without --all-features, clean; native cargo check -p victory-shader --lib passes. The Linux test build fails in super::super::validator exactly as it does on unmodified 63bcca4 (the validator module is Windows-only and the shader tests are not gated), so the suite itself has to run on Windows; zed6000's run at the equivalent tree was 305/0. No game data.

The triage should now see a clean merge. The open review risks in the description are unchanged, and #1315 remains the other candidate the maintainers may prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants