feat(shader): translate native GFX10 geometry shaders #556

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

@⁠maple-quartz18 on GitHub · 2026-12-05 04:12 UTC · original
maple-quartz18:codex/native-gfx10-gs → main · +4226 −55 · 22 files · 2 commits · open

Summary

  • Parse native GFX10 geometry-stage PSV and FSSM output-ring metadata, with a geometry-only shader-cache revision.
  • Prove guest ES-to-GS ring reads and output writes before lowering them to DXIL geometry inputs/outputs, stream emit, and cut operations.
  • Carry primitive ID, interpolation modes, input/output topology, and GS metadata into the generated shader and host pipeline path.
  • Add fixtures and test-harness support for native GS validation, PSO creation, and GPU readback.

The supported subset accepts point, line, triangle, and adjacency inputs; point-list, line-strip, or triangle-strip outputs; one output stream; and bounded acyclic control flow whose branches are proven draw-uniform. The Xbox GS instance-count metadata is still unknown, so translation assumes one instance and logs that assumption. Lane-varying branches, loops, multiple streams, and unrecognized ring operations are explicitly refused.

Validation

  • cargo test -p victory-shader --lib: 305 passed, 25 ignored.
  • On Radeon 8060S / RADV 26.3.1 under Wine, all 195 native GS samples passed DXIL validation and D3D12 pipeline creation; all 195 candidate real VS+GS pairs created host pipelines.
  • 24 GPU draw/readback cases passed across primitive/topology combinations, adjacency, uniform branches, flat interpolation, primitive ID, strip splitting, emit/cut, and maximum-vertex behavior.
  • Windows GNU test binaries and the release application were built and exercised under Wine. MSVC-target test code passes cargo check; MSVC linking itself is unavailable on this CachyOS host because Windows SDK import libraries are not installed.
  • The release binary was installed at the path used by run.sh and its --version command succeeded. The running game was not launched for this deployment check.

This does not claim support for every native GS control-flow or invocation pattern, or verification against a game-created GS pipeline.

**@⁠maple-quartz18** on GitHub · 2026-12-05 04:12 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/556) `maple-quartz18:codex/native-gfx10-gs` → `main` · +4226 −55 · 22 files · 2 commits · open ## Summary - Parse native GFX10 geometry-stage PSV and FSSM output-ring metadata, with a geometry-only shader-cache revision. - Prove guest ES-to-GS ring reads and output writes before lowering them to DXIL geometry inputs/outputs, stream emit, and cut operations. - Carry primitive ID, interpolation modes, input/output topology, and GS metadata into the generated shader and host pipeline path. - Add fixtures and test-harness support for native GS validation, PSO creation, and GPU readback. The supported subset accepts point, line, triangle, and adjacency inputs; point-list, line-strip, or triangle-strip outputs; one output stream; and bounded acyclic control flow whose branches are proven draw-uniform. The Xbox GS instance-count metadata is still unknown, so translation assumes one instance and logs that assumption. Lane-varying branches, loops, multiple streams, and unrecognized ring operations are explicitly refused. ## Validation - `cargo test -p victory-shader --lib`: 305 passed, 25 ignored. - On Radeon 8060S / RADV 26.3.1 under Wine, all 195 native GS samples passed DXIL validation and D3D12 pipeline creation; all 195 candidate real VS+GS pairs created host pipelines. - 24 GPU draw/readback cases passed across primitive/topology combinations, adjacency, uniform branches, flat interpolation, primitive ID, strip splitting, emit/cut, and maximum-vertex behavior. - Windows GNU test binaries and the release application were built and exercised under Wine. MSVC-target test code passes `cargo check`; MSVC linking itself is unavailable on this CachyOS host because Windows SDK import libraries are not installed. - The release binary was installed at the path used by `run.sh` and its `--version` command succeeded. The running game was not launched for this deployment check. This does not claim support for every native GS control-flow or invocation pattern, or verification against a game-created GS pipeline.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 04:16:45 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-05 05:32 UTC · original

Checked f61da7b and the follow-up 87f15d9 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). Merge base is b581f7e, current main.

While I was on f61da7b the victory-shader test target didn't compile on Windows, because five Draw { .. } initializers in Windows-only tests in emit/mod.rs were missing the four new fields (cbvs, buffers, input_primitive, vertex_count), giving E0063. 87f15d9 adds them and cargo check -p victory-shader --tests is clean here now. The runs below were done on f61da7b with those five sites patched locally, and 87f15d9 only touches those tests, so they should carry over, but I only re-ran the check on 87f15d9, not the full suites.

With that, victory-shader --lib gives 430 passed, 1 failed, 30 ignored on the PR against 419 passed, 1 failed, 4 ignored on main. The one failure is size_tests::a_reused_descriptor_register_read_only_behind_its_flag on both sides, and the 26 extra ignored are the new GS tests. victory-gpu --lib (skipping descriptor::tests::views_die_with_their_resource) gives 354 passed, 4 failed, 26 ignored. The four are failures I already know from main (indirect host_list_* x2, the mesh and depth-bounds pipeline library loads), though I didn't rerun main's gpu suite for this. The mesh library test is the one that goes through the code(1) to stage_code("pixel") change. geometry_revision_changes_only_geometry_cache_keys passes, and the pipeline::host and shader_cache subsets give the same results with --features diagnostics on WARP and with VICTORY_D3D12_DEBUG=1.

Non-GS output is unchanged. I hashed every container that comes out of Shader::finish across the whole victory-shader suite on main and on the PR. All 840 modules from 169 tests are byte-identical, including the rectangle GS from rect.rs, which now goes through the generalised GS metadata and PSV code. TRANSLATOR_VERSION stays at 20. Geometry gets its own derived key in shader_cache.rs:233-238, keyed on PSV stage 2 (is_geometry_container at :242), and non-GS keys are untouched, so nobody's existing cache gets invalidated.

Real GS coverage is thin, though. Every test that touches a real GS is #[ignore] and reads VICTORY_GS_FIXTURE, VICTORY_VS_FIXTURE or VICTORY_GS_CORPUS from local files, and no fixtures are committed. The "fixtures for real GS containers" in the body are fixture builders (fixture_max_four, fixture_adjacency and the rest in geometry.rs) that need those files. So the default suite never runs ring analysis, prepare/normalize, the uniform-branch proof on real code, PSO creation from a translated guest GS, or any of the readback draws, on Windows or anywhere else. The GS tests that do run are CPU-only and cover PSV parsing, the input-address proof on hand-written words, path enumeration, the E+0x280 check, the FSSM layout read and the cache key. I don't have the containers either, so none of the ignored tests ran here.

I could check the layer under the ring lowering on the card. In a throwaway test (not pushed) I built a GS by hand with the PR's Shader and Geometry. It reads SV_Position from every input vertex, emits three vertices with SV_PrimitiveID+1 in a TEXCOORD, then cuts. I ran it for every accepted pair of input primitive 1/2/3/6/7 and output topology 1/3/5. All 15 pass dxil.dll validation, Host::geometry_pipeline, pipeline_with_gs with the new topology mapping (emit/host.rs:512-518), and a two-primitive draw with readback. Points light exactly 6 pixels, line strips stay thin, triangle strips fill, and both primitive IDs reach the pixel shader. The results match on the card and on WARP. With VICTORY_D3D12_DEBUG=1 no pipeline was refused and no draw failed, but the harness only prints debug-layer messages for a refused pipeline, so I can't claim a clean log. The rect.rs draw tests pass in the same three setups. The diff_tests draws skip here because there's no console or PC compiler. A test along these lines, not ignored, would cover the emitter side in CI without any game data.

A few things in the code. pipeline/host.rs never compares the title's g.topology with the GS input primitive. A mismatch should just fail PSO creation and get refused, but a refuse with its own reason would be easier to find in logs. The title's stream-output subobject (type 7) is skipped by size only (pipeline.rs:930), so if a GS is ever used for stream-out without rasterization it will now be rasterized on the host. I don't know whether the game does that. When a GS doesn't translate, translated() returns None and the whole pipeline is refused, which is what main already did for every pipeline with a geometry stage. That means no crash and no fallback, which seems right to me.

The uniform-branch proof (geometry.rs:478-617) looks conservative. It only accepts s_cbranch_scc0/1 on values built from layout root SGPRs (s8/s9 excluded), scalar ALU and s_load/s_buffer_load. It rejects VCC, EXEC, M0 and vector inputs, and analyze rejects any EXEC write after the prologue (:762-769). The one assumption left is that memory behind a root address doesn't change during the draw, which seems fine. analyze also refuses any Image, Buffer, Flat or Exp instruction (:988-996), so a GS that samples a texture or does a vector memory read is refused. That's reasonable for a first cut, but it could go in the body next to loops and multiple streams.

The instance count is hard-coded to 1. The E+0x280 == 1 check (:699-707) doesn't prove it, since the comment at :697-698 says that field's meaning isn't established. If the count lives somewhere else, a GS with several instances would translate silently as one. Worth saying in the body that this is an assumption rather than something the code checks.

Smaller things. geometry::prepare runs twice per GS, once in translate_plain (mod.rs:560) and again in emit_program (mod.rs:897), so path enumeration and every proof run twice. geometry.rs:69 is an eprintln! in library code, and tracing would match the rest of the crate. native.rs:2015-2025 now fails programs() for the whole container if a GS record's stage data is short or overlaps, but that only affects containers with a GS slot, which main couldn't draw anyway.

New clippy warnings against main (lib and tests, keep-going, since the guard_runs bench fails to compile with E0603 on both sides) are geometry.rs:149 (collapsible if), :499 (9 arguments), :501 (parameter only used in recursion), pipeline/host.rs:767 (redundant closure, &code), plus two in test code, mod.rs:4282 (two f32 to f32 casts) and :4314 (manual Range::contains).

The refusal claims in the body match the code. stream_mask must be 1 (geometry.rs:727), cycles and more than 32 paths are refused in control_paths (:338-403), lane-varying branches in prove_uniform_branches, and unknown LDS ops and messages in analyze (:942-973). The own-cache-revision claim is accurate.

Not tested here is any real GS container, which means ring analysis, ES to GS input mapping, normalization, and linking a real translated VS with a GS (signature and interpolation matching) are all unchecked. Neither are the geometry tally in victory translate, AMD or Intel hardware, or the game.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-05 05:32 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/556#issuecomment-7432706815) Checked f61da7b and the follow-up 87f15d9 on native Windows (one NVIDIA desktop card plus WARP, didn't run the game). Merge base is b581f7e, current main. While I was on f61da7b the victory-shader test target didn't compile on Windows, because five `Draw { .. }` initializers in Windows-only tests in emit/mod.rs were missing the four new fields (cbvs, buffers, input_primitive, vertex_count), giving E0063. 87f15d9 adds them and `cargo check -p victory-shader --tests` is clean here now. The runs below were done on f61da7b with those five sites patched locally, and 87f15d9 only touches those tests, so they should carry over, but I only re-ran the check on 87f15d9, not the full suites. With that, victory-shader --lib gives 430 passed, 1 failed, 30 ignored on the PR against 419 passed, 1 failed, 4 ignored on main. The one failure is size_tests::a_reused_descriptor_register_read_only_behind_its_flag on both sides, and the 26 extra ignored are the new GS tests. victory-gpu --lib (skipping descriptor::tests::views_die_with_their_resource) gives 354 passed, 4 failed, 26 ignored. The four are failures I already know from main (indirect host_list_* x2, the mesh and depth-bounds pipeline library loads), though I didn't rerun main's gpu suite for this. The mesh library test is the one that goes through the code(1) to stage_code("pixel") change. geometry_revision_changes_only_geometry_cache_keys passes, and the pipeline::host and shader_cache subsets give the same results with --features diagnostics on WARP and with VICTORY_D3D12_DEBUG=1. Non-GS output is unchanged. I hashed every container that comes out of Shader::finish across the whole victory-shader suite on main and on the PR. All 840 modules from 169 tests are byte-identical, including the rectangle GS from rect.rs, which now goes through the generalised GS metadata and PSV code. TRANSLATOR_VERSION stays at 20. Geometry gets its own derived key in shader_cache.rs:233-238, keyed on PSV stage 2 (is_geometry_container at :242), and non-GS keys are untouched, so nobody's existing cache gets invalidated. Real GS coverage is thin, though. Every test that touches a real GS is `#[ignore]` and reads VICTORY_GS_FIXTURE, VICTORY_VS_FIXTURE or VICTORY_GS_CORPUS from local files, and no fixtures are committed. The "fixtures for real GS containers" in the body are fixture builders (fixture_max_four, fixture_adjacency and the rest in geometry.rs) that need those files. So the default suite never runs ring analysis, prepare/normalize, the uniform-branch proof on real code, PSO creation from a translated guest GS, or any of the readback draws, on Windows or anywhere else. The GS tests that do run are CPU-only and cover PSV parsing, the input-address proof on hand-written words, path enumeration, the E+0x280 check, the FSSM layout read and the cache key. I don't have the containers either, so none of the ignored tests ran here. I could check the layer under the ring lowering on the card. In a throwaway test (not pushed) I built a GS by hand with the PR's Shader and Geometry. It reads SV_Position from every input vertex, emits three vertices with SV_PrimitiveID+1 in a TEXCOORD, then cuts. I ran it for every accepted pair of input primitive 1/2/3/6/7 and output topology 1/3/5. All 15 pass dxil.dll validation, Host::geometry_pipeline, pipeline_with_gs with the new topology mapping (emit/host.rs:512-518), and a two-primitive draw with readback. Points light exactly 6 pixels, line strips stay thin, triangle strips fill, and both primitive IDs reach the pixel shader. The results match on the card and on WARP. With VICTORY_D3D12_DEBUG=1 no pipeline was refused and no draw failed, but the harness only prints debug-layer messages for a refused pipeline, so I can't claim a clean log. The rect.rs draw tests pass in the same three setups. The diff_tests draws skip here because there's no console or PC compiler. A test along these lines, not ignored, would cover the emitter side in CI without any game data. A few things in the code. pipeline/host.rs never compares the title's g.topology with the GS input primitive. A mismatch should just fail PSO creation and get refused, but a refuse with its own reason would be easier to find in logs. The title's stream-output subobject (type 7) is skipped by size only (pipeline.rs:930), so if a GS is ever used for stream-out without rasterization it will now be rasterized on the host. I don't know whether the game does that. When a GS doesn't translate, translated() returns None and the whole pipeline is refused, which is what main already did for every pipeline with a geometry stage. That means no crash and no fallback, which seems right to me. The uniform-branch proof (geometry.rs:478-617) looks conservative. It only accepts s_cbranch_scc0/1 on values built from layout root SGPRs (s8/s9 excluded), scalar ALU and s_load/s_buffer_load. It rejects VCC, EXEC, M0 and vector inputs, and analyze rejects any EXEC write after the prologue (:762-769). The one assumption left is that memory behind a root address doesn't change during the draw, which seems fine. analyze also refuses any Image, Buffer, Flat or Exp instruction (:988-996), so a GS that samples a texture or does a vector memory read is refused. That's reasonable for a first cut, but it could go in the body next to loops and multiple streams. The instance count is hard-coded to 1. The E+0x280 == 1 check (:699-707) doesn't prove it, since the comment at :697-698 says that field's meaning isn't established. If the count lives somewhere else, a GS with several instances would translate silently as one. Worth saying in the body that this is an assumption rather than something the code checks. Smaller things. geometry::prepare runs twice per GS, once in translate_plain (mod.rs:560) and again in emit_program (mod.rs:897), so path enumeration and every proof run twice. geometry.rs:69 is an eprintln! in library code, and tracing would match the rest of the crate. native.rs:2015-2025 now fails programs() for the whole container if a GS record's stage data is short or overlaps, but that only affects containers with a GS slot, which main couldn't draw anyway. New clippy warnings against main (lib and tests, keep-going, since the guard_runs bench fails to compile with E0603 on both sides) are geometry.rs:149 (collapsible if), :499 (9 arguments), :501 (parameter only used in recursion), pipeline/host.rs:767 (redundant closure, `&code`), plus two in test code, mod.rs:4282 (two f32 to f32 casts) and :4314 (manual Range::contains). The refusal claims in the body match the code. stream_mask must be 1 (geometry.rs:727), cycles and more than 32 paths are refused in control_paths (:338-403), lane-varying branches in prove_uniform_branches, and unknown LDS ops and messages in analyze (:942-973). The own-cache-revision claim is accurate. Not tested here is any real GS container, which means ring analysis, ES to GS input mapping, normalization, and linking a real translated VS with a GS (signature and interpolation matching) are all unchecked. Neither are the geometry tally in `victory translate`, AMD or Intel hardware, or the game. AI-assisted: yes
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-556'
git switch 'github-bot/gh-556'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-556'
git switch 'github-bot/gh-556'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-556'
git switch 'main'
git merge --squash 'github-bot/gh-556'
git switch 'main'
git merge --ff-only 'github-bot/gh-556'
git switch 'main'
git merge 'github-bot/gh-556'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.