Shaders, second round: geometry programs as geometry shaders, loops as the console runs them, lighter wave64 forms, dispatches past 65,535 groups in x (stacked on #854) #993
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!993
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@PiloteCode on GitHub · 2026-11-25 15:20 UTC · original
PiloteCode:pr/shaders2→main· +9443 −1665 · 50 files · 36 commits · openStacked on #854. The branch is #854's head (
0751197e) withmain(0b0074e0) merged in, which had no conflict. The 25 commits after that merge are this PR's. Once #854 is in, only they remain. The first one is the clippy fix formainthat our other open PRs also start with (shadow.rs,manual_is_multiple_of).Offline census over the title's whole shader pack (
victory translate --validate --list,VICTORY_HOST_MAX_WAVE=32, CPU only: translation and DXIL validation, no pipelines, as the card was reserved): 25,948 of 25,953 programs translate and validate, against 25,682 with #854 alone.The 71 mesh programs pass in the form they take when drawn without a pixel program (below); #854 links them with their pixel program for the pipelines that have one. The five left are shadow-mask trace programs (a descriptor read only as data). Our ray-tracing PR, stacked on this one, makes four of them translate.
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/regions.rs,emit/trip.rs,lower.rs)A helper lane of a pixel program is its own first lane. The console runs a pixel program's helper lanes as lanes of EXEC (the program starts with
s_wqm), so a waterfall loop over descriptors serves a helper lane in a pass of its own. The host's wave operations leave helper lanes out (SM 6.6) and give them undefined results. A helper lane whose value no other lane held never met it as the first lane. It went round the translated loop to the iteration limit, sampling each pass, and left with nothing computed, which its quad's derivatives then read. The character skin and cloth program (94d281151ca58b4f) samples its material layers in nine such nested loops.VICTORY_HELPER_OWN=0turns it off, for an A/B on screen.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 each lane leaves on its own is not code every lane runs. Where two host waves run one console wave of 64 lanes, they exchange first lanes, masks and LDS order through group barriers, and only in blocks every lane runs. A waterfall loop in one block was taken for such code and got two host waves' exchange: four group barriers a pass, which lanes that had left met at other barriers.
1f1fbd86759b3da2), lanes then never met their descriptor and ran to the compute limit of 4,096 passes, losing their loads.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, only the 69 paired programs change: host instructions 2,303,768 -> 1,617,871 (-30 %), guard selects 360,668 -> 124,509.form=withVICTORY_SHADER_CENSUS).Dispatches of more than 65,535 groups in x run whole (
lower.rs,shader.rs,draw.rs,indirect.rs)One host dispatch runs at most 65,535 groups in a dimension; the console runs more. The screen-probe final gather of the indirect diffuse light asks for up to 2 x 57,600 = 115,200 groups in x: one group per 8x8 tile of each of its two layers at 2560x1440. The clamp of indirect records cut such a record to 65,535, so the tiles past that point never ran. This showed as blocks along the bottom of the picture, and on a head lit by the window as a washed-out orange light with a vertical seam.
USER_GROUP_BASE(RootType::Other(0x104)). Programs with a spilled user-data table do not ask for it: their root signatures are close to the host's 64 dwords.indirect::SPLIT_DISPATCH):In our tree, in the save's gameplay (the cell window, the same static view): before, about 0.8 records a frame were cut, blue and white blocks lined the bottom edge, and the hair took the washed-out light. After, 166 frame lines asked for more than 65,535 groups, none was cut, the bottom edge was clean and the hair was lit as the rest of the room. That tree clamped into a ring of the list's (not in
main). Here the split is written ontomain's clamp program and scratch buffer: the same records and signature, tested on WARP.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_HELPER_OWN=0: helper lanes read the host wave's first lane, 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 (its head merged with
mainalready). The card was reserved for other work, so the tests ran on the software adapter:cargo test -p victory-shader -- --test-threads=1withVICTORY_WARP=1: 259 passed, 5 failed, 2 ignored. The same five fail on #854's head merged withmain(237 passed, 5 failed), all on the software adapter (WARP refuses the pipelines of the first four, E_INVALIDARG, and reads another lane count in the fifth):ds_min_max_f32_order_floats_and_return_the_old_value,lds_subtractions_get_a_pipeline_and_stay_atomic,v_permlane16_and_x16_read_the_lanes_their_selectors_pick,whole_wave_f64_sum_and_cvt_f32_f64anda_lane_mask_joined_with_a_number_is_read_as_the_number_it_is. Tests that need the card's 32-lane waves run on WARP here; they passed on the RTX 5090 when they went in.cargo test -p victory-gpu --features diagnostics -- --test-threads=1withVICTORY_D3D12_WARP=1: 186 passed, 1 failed, 6 ignored. The failure,depth_bounds_pipeline_loads_and_filters_draws, fails the same way on #854's head merged withmain(185 passed): WARP does not reject the pixels outside the depth bounds.cargo test -p victory: 1 passed.cargo clippy --workspace --all-targets --locked -- -D warnings, and the same with--all-features: clean.cargo build --release -p victory,cargo build --profile diag -p victory --features diagnosticsandcargo xtask policypass.New tests:
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
USER_GROUP_BASE,RootType::Other(0x104)), to the group id in x. Here one execution of split records runs up to 262,140 groups, and direct dispatches are split too. The translator parts are nearly the same; whichever goes in second keeps one.RootType::Other(0x104), for another word (USER_DISPATCH_THREADS). With both, one of the two needs another code. Our ray-tracing PR (stacked on this one) does thread counts with0x105.IsHelperLane, and adds quad reads. Here a helper lane reads its own value in a pixel program's first-lane reads.Not tested
0b0074e0) into the translator's branch: upstream's frame-rate sessions; no conflict 94c6c3ae55With loop notes (VICTORY_LOOP_NOTES=1) every program with a counted loop binds the notes as a root UAV. A vertex or mesh program that binds a UAV must say so (ShaderFlags bit 16, SFI0 0x4); without it the validator refused 62 of the 801 vertex and mesh programs of a game run translated with notes ("Flags must match usage"); with it they all validate (but the two whose outputs pass 32 KiB, as without notes). The runtime does not validate, so the game ran them as they were. Test: a vertex program writing the notes' UAV validates.A pipeline whose stream has a geometry shader was refused ("only vertex, mesh, pixel and compute stages are translated") and its draws dropped. Its geometry program now translates (the commit before): the host pipeline is the vertex program, the pixel program and the geometry program between them, its user data and views bound per stage as the others' (stage last, so the pixel stage keeps its place; no rectangle stage beside it, and none in a mesh pipeline). Its library entry has a name of its own. The translated geometry stage brings its used-resource entries like the other stages. shortcut: not run in the title yet: none of the runs so far (opening cutscene, gameplay from the user's save) drew with a geometry stage.c36971b2) into the translator's branch: upstream's frame-rate sessions, frame capture, texture copy-back and wide loads; no conflict f66feef7a1c36971b2) into the second translator branch: upstream's gathered indirect records, frame capture, card-memory windows, texture copy-back and wide loads; no conflict f2d66cb813@PiloteCode on GitHub · 2026-11-25 22:11 UTC · original
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
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.