Shader & GPU: support merged ES+GS geometry stages (vs_6_6 / gs_6_6) #1399
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1399
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1399"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@wbkepler on GitHub · 2026-11-24 17:45 UTC · original
wbkepler:shader/merged-es-gs-stages→main· +1445 −76 · 21 files · 1 commits · openSummary
Rebased cleanly onto
upstream/main(ffe310e):Decodes, raises, lowers, validates, and wires console merged ES+GS hardware geometry stages (
HwStage::Es->vs_6_6andHwStage::Gs->gs_6_6):victory-shader/src/native.rs: DecodesHwStage::EsandHwStage::Gsstage data (StageIo::Es,StageIo::Gs(GsIo)including vertex stride, GSVS ring stride, invocations, and max vertices).victory-shader/src/resource.rs: Recognizes the console merged-GS internal ring-table SGPR pair (GS_TABLE) without disrupting root parameter tracking.victory-shader/src/io.rs: Raises ES->GS and GSVS LDS traffic (ds_read*->gs_reads,ds_write*->lds_outputs), ES system VGPRs (VertexId,PrimitiveId,InstanceId), GSGsInstanceId, ands_sendmsg(MSG_GS / MSG_GS_DONE)stream operations (gs_ops).victory-shader/src/emit/{container,shader,lower,mod,host}.rs:gs_6_6modules withGSStateentry property (tag 1), single-streamdx.viewIdState, and GSPSV0metadata.dx.op.loadInputwith vertex axis,dx.op.primitiveID.i32(108),dx.op.gsInstanceID.i32(100),dx.op.storeOutput, andemitStream/cutStream/emitThenCutStream(97/98/99), plus ES barrier elision and indirect handover return.Host::gs_pipelinefor live D3D12 VS+GS+PS pipeline creation.victory-gpu/src/pipeline{,/host}.rs: IncludesHwStage::Gsin shader resource extraction, allows"geometry"inHostPipeline::new, addsD3D12_SHADER_VISIBILITY_GEOMETRY, bindsdesc.GS, and includes GS bytecode in the pipeline library cache key.apps/victory/src/translate.rs: IncludesHwStage::GsandHwStage::Esin raising, DXIL emission, validation, host pipeline verification, and corpus reporting.Es/Gsstage data decoding, LDS/sendmsg raising, and livedxil.dllvalidation + D3D12 pipeline creation for bothEs(vs_6_6) andGs(gs_6_6).Verification
cargo clippy -p victory-shader --all-targets&-p victory-gpu --all-targets— passedcargo test -p victory-shader&cargo test -p victory-gpu pipeline— passedcargo xtask policy— passed@shortselow-byte on GitHub · 2026-11-24 19:32 UTC · original
For triage: #1315 also translates console geometry programs (single-stream triangle geometry, with a new
emit/geometry.rsand aStageIo::Gs), and neither PR mentions the other.git merge-treeagainst the current heads shows they conflict invictory-gpu/src/pipeline/host.rs,victory-shader/src/emit/container.rsandvictory-shader/src/emit/host.rs. Both are large (about 1,400 and 1,500 changed lines), so it is worth settling which one carries geometry stages before either is reviewed in depth.This PR on its own, at
d01f9a6onmainffe310e, isolated target directory, Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT: workspace 346 passed, 0 failed, including its four new tests; both clippy runs clean.@sinan-cmyk on GitHub · 2026-11-24 20:44 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: +195 programs over
main, 0 lost.Offline. I merged head d01f9a6 onto
mainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 onmain, 21,919 with this PR.mainNone of the 195 is among the programs that #1402 gains, so this PR adds to the bundles instead of overlapping them. It is the only open PR I have measured that clears "an address in an SGPR that is no root parameter" (195 on
main; #333, #302 and #489 gained 0 for it in #1247). I'm measuring it stacked on #1402 and #1597 as well.Tests: with the same merge,
cargo test --locked -p victory-shader --libpassed 124, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@sinan-cmyk on GitHub · 2026-11-24 21:31 UTC · original
Static review of the ES/GS lowering (head d01f9a6)
Summary: On a retail dump this PR gains 195 programs, 0 lost (measurement), and its tests pass on Ada. Those counts only prove that the DXIL validates. Below are the places where the output could still be wrong although it validates. Line numbers refer to the PR head.
Likely bug
1. The emitted vertex's index is computed, then ignored. Outputs are stored at the
ds_write, not at their emit. (emit/lower.rs:2308–2335,io.rs:811)raise_es_gs_ldsworks out which emitted vertex each GSVS write belongs to (LdsOutput.vertex = dword / vertex_dwords), but the lowering never readsout.vertex. Each write becomes astoreOutputat its own site, and eachs_sendmsg(MSG_GS, EMIT)becomes anemitStream.This is correct only if, for every vertex k, all of its writes come after emit k−1 and before emit k. The synthetic test (
emit/mod.rs,gs_shader_validates_and_builds_host_pipeline) has exactly that order. A compiler that batches writes breaks it, and the result still validates:ds_write2_b32whoseoffset0andoffset1fall into two vertex slots.In both cases the host emits the last-written values for several vertices, so primitives collapse or stretch.
Suggested fix: keep a counter of emits per stream. For every write between emit k−1 and emit k, require
out.vertex == k, and refuse the program otherwise (for example "GSVS write to a vertex other than the next emitted"). Or buffer the writes per vertex and store them right before the matchingemitStream.Risks (cannot be confirmed without one real ES/GS pair)
2. The LDS layout is assumed to follow signature rows, not
paramslots. (io.rsGS reads and ES/GS writes;lower.rs:2310)Both ES→GS and GSVS dwords are mapped as
row = dword / 4, channel = dword % 4and matched against the signature row (o.row == Some(out.row)). The VS export path maps rows through the native outputs table (VsOutput.param). The LDS path ignores that table.If the console lays out ES→GS or GSVS memory by parameter slot, or compacts unused components, inputs and outputs are silently mixed up. Both ES and GS use the same rule, so they agree with each other but can both be wrong.
A cheap guard: check
vertex_dwordsagainst the signature, for examplevertex_dwords == 4 * (max row + 1)of the ES outputs and GS inputs, and refuse when it does not match. Better: verify on one title pair whether the rows or the params decide the layout.3. Silent defaults for the GS state. (
emit/mod.rs:292–294)When
PSV0is missing or holds 0, these defaults apply:A wrong input primitive changes how many vertices
loadInputcan address. It also changes the host PSO's topology-type compatibility. Refusing ("a geometry shader without PSV0 state") would be safer than guessing.4. Non-zero streams have no host consumer. (
io.rs:832)Emit(stream)andCut(stream)pass the stream through, and the PSO has no stream-output. A console GS that feeds stream-out, or rasterizes a stream other than 0, would produce output that the host silently drops. Refusing when the stream mask is not 1, or when an op targets a stream other than 0, would make that visible.5. A GSVS or ES→GS write with no signature row is dropped silently. (
lower.rs:2317:let Some((id, col)) = found else { continue; })A real output whose row the signature lacks becomes undefined on the host. Other paths refuse in that case ("a GS input the signature lacks").
Nits
GS_TABLEacceptss[8:9]as the console GS table whenever no root parameter sits at user data 0–1 (resource.rs:42, 668). Any value loaded from it is refused (lower.rs:3072), so a wrong guess fails safely. Its only effect is the per-lane ring base, which the lowering ignores.lower.rs:527). That is fine for a VS on the host.s_barrierwould emit a DXIL barrier that the validator rejects. That costs a refusal, not wrong code.victory-gpu/src/pipeline.rs(note_why) andpipeline/host.rsmakes the diff harder to review.What looks right
s8for the merged stages (HwStage::user_sgpr).GSStatemetadata order (input primitive, max vertices, stream mask, topology, instance count), and the GS part ofPSV0.s_bfe s3→s_bfm→s_cselect) is treated as all lanes active. That is correct: one host invocation is one ES vertex or one GS primitive.s_setpchandover is lowered as a return.pipeline/host.rs:326).pipeline/host.rs:552).What the tests cover, and what they don't
Covered:
v_mad_u32_u24baseNot covered:
invocations > 1PSV0AI-assisted (Claude Code); static review only, nothing run.
@wbkepler on GitHub · 2026-11-24 22:40 UTC · original
Rebased onto
70564aease80b166(one commit; the old branch conflicted in about ten files, so this is a re-port rather than a replay).What changed in the design:
Shader::gs(and theGSState/PSV0/ view-id output it drives) is generalized from "triangles in, strips out, n vertices" to one smallGeometryvalue: input primitive, output topology, maximum vertices, instances, one stream.rectangle_gsand title geometry programs go through the same field; the rectangle test passes unchanged.lower.rs: vertex-axisloadInputshares the existing input loader, stream messages becomeemitStream/cutStream/emitThenCutStream, the merged prologue's lane masks are "every invocation", the export program's barrier is dropped and its handover jump is a return. The stage's own table (s[8:9]) gets its own address kind next toMEMORY/USER_DATA, so it is not taken for title memory.translatecounts export and geometry programs separately; the pipeline pre-build makes records that have an export and a geometry stage instead of skipping them.Checked on this base:
clippy -D warningsonvictory-shader,victory-gpu,victory-gameand onvictory --features diagnostics: clean.cargo xtask policy: ok.cargo test -p victory-shader -p victory-gpu -p victory-game: everything passes except five tests that fail the same way on unmodified70564aeon this machine (RTX 5090):stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardwareinvictory-shader, anddynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsinvictory-gpu. None of them touch this change.Not checked: the whole-title program counts were not re-measured on this base, no live run was made with these pipelines, and the pre-build path for these records has not been compared against a run's pipeline keys.
AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.
@molodayamama on GitHub · 2026-11-24 22:47 UTC · original
I reproduced the GSVS write/emit ordering issue raised above on the rebased head
e80b166, using the PR's existing synthetic triangle and an RTX 4060 (driver 610.88, Windows 10, D3D12 Agility SDK 620). I moved the three stream-0 Emit messages after all LDS writes, keeping the three positions and final Cut unchanged.e80b166with only the expanded testWith the patch the full 32 × 32 RGBA readbacks match exactly. The failure on the PR head was visible in rendering even though the generated shaders passed DXIL validation.
Patch and regression test ·
.patchfileThe patch queues writes by
LdsOutput.vertexfor straight-line geometry shaders and lowers each slot's writes, in original order and with their original masks, just before its Emit or EmitCut. The regression runs withcargo test -p victory-shader --lib merged_geometry_stages_draw_their_triangle -- --nocapture. This tests the single-block case only. The whole-title impact is unmeasured.Full
victory-shaderlibrary suite: 207 passed, 5 failed, 2 ignored. All five failures reproduced on the unmodified PR head with the same local setup.@slatefield on GitHub · 2026-11-25 01:03 UTC · original
Rebased this onto current
main(4118f33) and folded in the batched-write fix from the thread, since without it a geometry shader that writes a vertex ahead of the previous emit renders 0 lit pixels while still validating. Two commits on the branch, both with their authors: your merged-geometry commit unchanged, and molodayamama's9607c49"Publish batched geometry ring writes at each vertex emit" on top, with their regression test.Rebase conflicts were three hunks:
native.rskeeps main'svs_outputs(data)wrapper from the mesh fix and moves the body intovs_outputs_at(data, at, count_at)for GS outputs,io.rskeeps main's corrected 9-bit meshexp primwording plus your paragraph, and one test literal gainsgs: None. A per-file added/removed-line comparison against youre80b166shows 20 of the 21 files identical in both directions, the only delta being that wrapper.cargo test -p victory-shader --lib146 passed, 2 ignored on Linux (main 144), Windows-target clippy clean both feature sets, asset policy ok. The#[cfg(windows)]validation and draw tests need a GPU.It is open as #1924 so the maintainer can take a ready branch including the ordering fix. If you would rather update this PR yourself, reset
shader/merged-es-gs-stagesto the branch head there and I will close mine. The open review risks (LDS layout from signature rows vsparamslots, silentPSV0defaults, non-zero streams, missing-row writes) are listed in the description as follow-ups; I did not change them.@Marvisak on GitHub · 2026-11-25 01:25 UTC · original · edited 2026-11-25 16:03 UTC
Automated triage for the maintainers.
This pull request no longer merges cleanly into
main(conflicts incrates/victory-shader/src/emit/lower.rs,crates/victory-shader/src/emit/mod.rs,crates/victory-shader/src/emit/rect.rs). It will be reviewed once it is rebased onto the currentmain. The earlier verdict (needs-work) was for an older state ofmain.Generated by Claude Code
@wbkepler on GitHub · 2026-11-25 07:10 UTC · original
Rebased onto current main (
940d32f) as2900907; conflicts were with the new write-markOptions/Parts::view_marks(kept both,gsadded alongside) and the split-outvs_outputsinnative.rs(now takes the table offset so the geometry stage can share it).AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.
@zed6000 on GitHub · 2026-11-25 21:02 UTC · original
Measured offline on the title's shaders (the method in #1247). This head (
2900907) against its base940d32fgives +390, 0 lost: all 195 geometry programs that fail with "an address in an SGPR that is no root parameter", plus their 195 export halves, now validate.cargo test -p victory-shader --libpasses (250/0) on an RX 7900 XTX. #1924 gains exactly the same programs. Merged onto current main13f91ca, #1924 also gives +390 / 0 lost with tests and clippy clean. The conflict resolution, all "keep bothview_marksandgs" plus onememory_tests.rsfix git doesn't flag, is on #1924 and applies here the same way. Offline counts only; no program names or data.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.Merge
Merge the changes and update on Forgejo.