Shaders, second round: geometry programs as geometry shaders, loops as the console runs them, lighter wave64 forms (stacked on #854) #991
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/993"
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?
Imported from fxceless/victory-fork. Originally posted by PiloteCode on 2026-11-25T15:20:09Z.
Stacked on #854 (
pilote:pr/shaders,7c9a2f98), onmain9a9091d1. The 17 commits after #854's are this PR's. Once #854 is in, only they remain.Rebuilt on today's
mainmainhas taken several of this PR's pieces meanwhile, in its own way. They are left out here:mainspreads them across z (USER_DISPATCH_SPREAD,06702fe8). This PR's split dispatches, its group base and the four diagnostics and test commits that went with them are left out.mainhas this (helper_reads_own, after upstream 0601955), the same way this PR did. The test stays as a test ofmain's fix (commit "Tests: a helper lane ..."): on the software adapter the helper lane's count is 1.VICTORY_HELPER_OWNis left out.maintook it withVICTORY_WAVE_WIDE=1(loop_exits_on,b1d777a8, "adapted from fork PR #993"). This PR's version, which applied it to every form, is not carried. The lane regions stay inlower.rsasmainhas them.main's now (#1397, see #854). The raw reads of guarded writes (below) are re-applied ontomain's paired code.The census of the shader pack for this rebuild follows.
What changes
Geometry programs translate as geometry shaders (
geometry.rs,emit/rings.rs,native.rs,pipeline/host.rs)The title's 195 geometry programs (all
GS_VoxelizeGenericvariants) stopped at resource tracking: their first load reads the console driver's table that user data 0 and 1 point at.How the console runs such a program: in one hardware stage, after the ES half of its vertex program. It reads its triangle's vertices from LDS at the offsets in v0 and v1 (16 bits each), writes the vertices it emits to its lane's slot of the GS-VS ring (also in LDS), and sends a GS message for each emit and cut. The stage data gives the ring's layout (
StageIo::Gs).How the host runs it now:
crate::geometry,emit/rings.rs). The address of each LDS access is followed to the input vertex and dword it reads, or to the emitted vertex and dword it writes:loadInput;resource::DRIVER).NativeProgram::patched_code).A title pipeline with a geometry stage was refused before ("only vertex, mesh, pixel and compute stages are translated"). It now gets a host pipeline: the vertex program, the geometry program and the pixel program, each stage's user data and views bound as the others are. The geometry stage comes last, so the pixel stage keeps its place.
Offline, all 195 translate and validate, and the DXIL of every other program is unchanged by this commit. Their pipelines, between a stub vertex and pixel shader, build on WARP. No run so far drew with a geometry stage.
A mesh program over 32 KiB drawn without a pixel program keeps only its system values (
emit/link.rs,pipeline/host.rs)#854 links each of the 71 oversized mesh programs with the pixel program of its pipeline. A pipeline without a pixel program, as the title makes for depth, still got the invalid translation: the runs so far bound 143 mesh programs alone 14,576 times.
link_mesh_alonetranslates such a program again without its outputs of arbitrary semantics, which only a pixel program reads. Position, clip and cull distances stay, and it fits. The runtime makes those pipelines with it. The census checks that form of the 71, since its stub pixel program reads nothing: all 71 validate and get a pipeline (RTX 5090).VICTORY_MESH_LINK=0turns this form off too.Loops (
emit/loops.rs,emit/trip.rs,lower.rs)A loop whose code fixes its count runs to its end, whatever the limit. The limit is for loops whose end the data decides. A loop has a fixed count when its exit is a scalar counter that:
Such a loop now runs as often as the console's, up to 65,536 passes. The environment BRDF integration tables (
PS_IntegrateEnvBRDFand its Beckmann and thin-film variants) integrate 1,024 samples a texel in six loops of 256 or 512 passes. At the pixel limit of 128, every one of the 65,536 texels of each table stopped at a half or a quarter of its samples (loop notes, opening cutscene). Every specular reflection reads those tables.A loop closed by a jump leaves at its exit at the limit. Such a loop has its exit test elsewhere in its body. At the limit, its jump back could only end the lane: a pixel discarded, a mesh or compute lane stopped before its writes. Its exit tests now take the limit too, so a lane at the limit leaves there and goes on with the program. A lane whose way round passes no exit test still ends.
A vertex or mesh program with a root UAV declares UAVs at every stage (ShaderFlags bit 16). With loop notes on, the validator refused 62 of 801 such programs of a run.
Diagnostics.
VICTORY_SHADER_LOOP_LIMITtakes one number, orstage:npairs.VICTORY_LOOP_NOTES=1: each lane that reaches a loop's limit adds one to that loop's record in a root UAV of ours, and the log names the loops whose counts grew, every five seconds (crate::loop_notes).The limits themselves stay. With them raised to 1,024 / 4,096 / 65,536, the notes named loops that never end, for example a cascade search that reads its count as 0, and a decal resolve's walk.
Wave64 programs on 32-lane GPUs (
emit/split.rs,emit/guarded.rs,emit/forms.rs)VICTORY_WAVE_SPLIT=0turns it off). Some console wave64 programs use their wave-wide values only as the allocation idiom uses them: each wave's first lane reserves its count on a shared counter, and every lane takes the base plus its rank. Such a program is exact with each host wave on its own: the same records, reserved by each half in another order. Before, a program that the exchange form also translated took that form: two host waves meeting at two group barriers for each first-lane read, mask and sum.CS_Primary_RegisterAllocationRequests(33 group barriers in 681 host instructions) took 3.7 ms of card time per dispatch in the opening cutscene, 2.8 ms a frame: the most of any wave64 program.split::read_inside_only).VICTORY_WAVE_RAW=0turns it off). In the paired form every per-lane branch is the wave's, so a guarded write isselect(guard, new, old). That was about a sixth of the paired programs' host code, each select keeping the register's old value alive. A lane that reads the register under a guard that implies the writer's guard reads the computed value. This holds only for its own registers: a DPP source, lane read or write, swizzle or permute reads other lanes. Offline when it went in, on this PR's own paired form, only the 69 paired programs changed: host instructions 2,303,768 -> 1,617,871 (-30 %), guard selects 360,668 -> 124,509.form=withVICTORY_SHADER_CENSUS).Switches
VICTORY_WAVE_SPLIT=0: allocation-only wave64 programs take the forms they took beforeVICTORY_WAVE_RAW=0: the paired form selects every guarded write, as beforeVICTORY_MESH_LINK=0now also turns off the system-values-only form of oversized mesh programs drawn aloneVICTORY_SHADER_LOOP_LIMITpixel:<n>,vertex:<n>,compute:<n>,trace:<n>VICTORY_LOOP_NOTES=1Every
VICTORY_*switch the translator reads is part of the shader cache key.Tested
The branch was checked as it is (on #854 on
9a9091d1), on the software adapter (no card):cargo test -p victory-shader -- --test-threads=1withVICTORY_WARP=1: 293 passed, 6 failed, 18 ignored. These are the same six as on #854 (main's five, and #854's LDS subtraction test, whose pipeline WARP refuses).cargo test -p victory-gpu --features diagnostics -- --test-threads=1 --skip stacks_that_mean_nothing_are_walked_without_a_faultwithVICTORY_D3D12_WARP=1: 261 passed, none failed.cargo clippy -p victory-shader -p victory-gpu -p victory --locked -- -D warnings: clean. With--all-targets,victory-shaderfails only onmain's own 7 lints in its tests, as onmain.cargo build --profile diag -p victory --features diagnosticspasses.Tests of the card (the paired form's raw reads and the local form against the console's 64 lanes) return early on WARP, whose waves hold 4 lanes. They passed on the RTX 5090 when they went in, on this PR's own paired form.
Earlier, all of these changes ran in our tree on the RTX 5090 with our layer work: its general test (an opening cutscene run and gameplay runs from a save) had no device loss, no refused pipeline and no exception.
Overlaps with open pull requests
maintook #592's by hand).Not tested
Where this also lives
These changes are also in PiloteBox (https://github.com/PiloteCode/PiloteBox), a tree kept up to date for NVIDIA cards. Its 0.13.1 runs the Series X profile at about 21 frames a second on an RTX 5090 (46.6 and 48.8 ms a frame in one scene; its changelog says how that was measured).
Imported from fxceless/victory-fork. Originally posted by PiloteCode on 2026-11-25T22:11:40Z.
Merged
main(c36971b) into the branch: a merge commit on top of the commits already here (f2d66cb), then one lint commit. No conflict. The branch still holds #854's head as it was.Merged without a conflict, and read through where both sides changed the same code:
indirect.rs: the clamp's shader now hasmain's gathered records (a record's place read from a table) and this branch's split dispatch (kind 3). Only a windowed draw's record is gathered, never a dispatch's, so the two do not meet. The tests of both pass.draw.rs:execute_indirectends the list's gathering for a dispatch before the split clamp, and a direct dispatch split past 65,535 groups ends it on entry.main's loads of four dwords a call (VICTORY_SHADER_OPTbit 64, not in the default) sit beside this branch's forms.main's new paths are taken only with the bit on, and its test of them passes here.emit/lower.rsis 511,375 bytes of the policy's 524,288.Added after the merge: one lint commit for
main's newer code, the same as on our other open branches:map_entryinfpsbox.rs,collapsible_ifinpipeline/library.rs,manual_is_multiple_ofinqueue.rs,shadow.rs,draw.rsandwatch.rs. Without itcargo clippy --workspace --all-targets --locked -- -D warningsfails onc36971b, with or without--all-features.Checked, the branch as it is (
5a6f243), every test on the software adapter:cargo clippy --workspace --all-targets --locked -- -D warnings, and the same with--all-features: clean.cargo xtask policy,cargo build --release -p victoryandcargo build --profile diag -p victory --features diagnostics: pass.cargo test -p victory-shader -- --test-threads=1withVICTORY_WARP=1: 260 passed, 5 failed, 2 ignored. The five are the ones the description names; four of them fail onmainalone on the software adapter (212 passed, 4 failed, 3 ignored), and the fifth is #854's LDS subtraction test. The one test more than before ismain's new one.cargo test -p victory-gpu --features diagnostics -- --test-threads=1withVICTORY_D3D12_WARP=1: 201 passed, 1 failed, 6 ignored. The failure isdepth_bounds_pipeline_loads_and_filters_draws, as onmain(200 passed, 1 failed, 6 ignored).cargo test -p victory-hle -- --test-threads=1: 100 + 1 passed, as onmain.cargo test -p victory -p victory-loader: passed.victory translate --validate --list,VICTORY_HOST_MAX_WAVE=32, CPU only, no pipelines): 25,948 of 25,953 programs translate and validate. Its list is the same, program for program, as the one taken before the merge: the one line that differs is the example it quotes for the five that fail.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.