Shader size: census of the 2.4x (25,635 programs), two measured reductions, and what avatarmanz's fork has for the black shadows #1383

Open
opened 2026-11-26 21:28:11 +00:00 by marekpastuszczak-lang · 0 comments
marekpastuszczak-lang commented 2026-11-26 21:28:11 +00:00 (Migrated from github.com)
Contributor

Imported from fxceless/victory-fork. Originally posted by marekpastuszczak-lang on 2026-11-26T21:28:11Z.


Two things that may save you time, from reading this fork next to avatarmanz/VIctory-7900XTX and from an offline look at the translated shaders. Nothing here was run in the game; where a number is a measurement it says of what.

1. Where the 2.4x goes: a census of the whole archive

The README says the translated programs are about 2.4 times the console's instruction count "broadly, with no single" cause. I ran VICTORY_SHADER_CENSUS over the whole shader archive (build 085ee7c, 25,635 programs) and weighted it by the per-pipeline card times of one world run:

  • host / console instructions over the archive: 2.38x; weighted by card time in the world: about 2.7x, so the expensive pipelines are a little worse than the average
  • by kind, share of host instructions: arithmetic 44%, select 12%, bitcast 12%, math calls 12%, memory and texture reads a few percent each

So it is indeed broad, but two things stand out.

a) The legacy multiply. legacy_mul / legacy_fmad in emit/lower.rs emit fmul + two fcmp oeq 0.0 + or + select for every v_mul_legacy_f32. Compares of a float against zero alone are 6.7% of all host instructions; the whole pattern is my estimate of 12 to 15%.

avatarmanz already has a cheaper form: rdna::LEGACY in crates/victory-shader/src/emit/mod.rs and the first branch of legacy_mul in lower.rs return the plain product when the factors are the same value, both bounded, or one a finite non-zero constant, and one compare otherwise. Their own note in mod.rs puts it in proportion, though: the whole float set took the title's dispatches and draws from 18.4 to 17.6 ms on an RX 7900 XTX, 0.4 ms of that from LEGACY. So a real saving in instructions, a small one in card time on that card. It is gated to RDNA hosts there.

b) An LLVM pass over the finished module. The five passes in emit/bitcode/opt.rs are the only optimiser. I fed 400 modules from the shader cache to DXC's IDxcOptimizer (dxcompiler.dll 1.8.2502, from the Windows SDK) and counted instructions from the disassembly:

passes instructions
-instcombine -gvn -adce -simplifycfg -9.3%
-sroa -early-cse -simplifycfg -instcombine -reassociate -sccp -jump-threading -correlated-propagation -simplifycfg -instcombine -licm -gvn -dse -bdce -adce -simplifycfg -instcombine -strip-dead-prototypes -11.2%

0.03 to 0.07 s a shader. The gain is in bitcast, select, shifts and branches, not in the arithmetic. dxil.dll's validator accepts 386 of the 400 after the passes against 388 of 400 for the modules as translated; the two new refusals are "Flags must match usage", so the shader flags would have to be recomputed after the passes. Whether 10% fewer cheap instructions moves the card's 84 to 128 ms I cannot say; I did not run it.

This is the measured side of point 2 in #1382.

2. Two open items here that avatarmanz's fork has answers for

Their fork left yours at a26859f and has not come back, so in case you have not looked:

  • "Anything the sun does not hit directly is black." crates/victory-gpu/src/ambient.rs there is a stand-in for the bounced light (VICTORY_AMBIENT, with creases and air), and since today a band that keeps the traced indirect light in range when ray tracing is on (VICTORY_AMBIENT_RT=<least>,<most>).
  • Trees dropping out for a few frames, light swinging in lamp-lit rooms (if you see these too). Their finding: indirect draws whose arguments sit in renderer port 1's in-place memory were prepared before the title's culling had written them. They now prepare those one at a time right before they run (VICTORY_PORT_CONSTANTS_ORDER, on by default, 2 to 5 ms; reports/POPIN.md, runs pop-14 to pop-17).

In the other direction I have told them about VICTORY_HEAP_WORKER and VICTORY_LOOKUP_CACHE, which they do not have.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6635364956 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/issues/1383). Originally posted by [marekpastuszczak-lang](https://github.com/marekpastuszczak-lang) on 2026-11-26T21:28:11Z. --- Two things that may save you time, from reading this fork next to avatarmanz/VIctory-7900XTX and from an offline look at the translated shaders. Nothing here was run in the game; where a number is a measurement it says of what. ## 1. Where the 2.4x goes: a census of the whole archive The README says the translated programs are about 2.4 times the console's instruction count "broadly, with no single" cause. I ran `VICTORY_SHADER_CENSUS` over the whole shader archive (build `085ee7c`, 25,635 programs) and weighted it by the per-pipeline card times of one world run: - host / console instructions over the archive: **2.38x**; weighted by card time in the world: about **2.7x**, so the expensive pipelines are a little worse than the average - by kind, share of host instructions: arithmetic 44%, select 12%, bitcast 12%, math calls 12%, memory and texture reads a few percent each So it is indeed broad, but two things stand out. **a) The legacy multiply.** `legacy_mul` / `legacy_fmad` in `emit/lower.rs` emit `fmul` + two `fcmp oeq 0.0` + `or` + `select` for every `v_mul_legacy_f32`. Compares of a float against zero alone are 6.7% of all host instructions; the whole pattern is my estimate of 12 to 15%. avatarmanz already has a cheaper form: `rdna::LEGACY` in `crates/victory-shader/src/emit/mod.rs` and the first branch of `legacy_mul` in `lower.rs` return the plain product when the factors are the same value, both bounded, or one a finite non-zero constant, and one compare otherwise. Their own note in `mod.rs` puts it in proportion, though: the whole float set took the title's dispatches and draws from 18.4 to 17.6 ms on an RX 7900 XTX, 0.4 ms of that from `LEGACY`. So a real saving in instructions, a small one in card time on that card. It is gated to RDNA hosts there. **b) An LLVM pass over the finished module.** The five passes in `emit/bitcode/opt.rs` are the only optimiser. I fed 400 modules from the shader cache to DXC's `IDxcOptimizer` (`dxcompiler.dll` 1.8.2502, from the Windows SDK) and counted instructions from the disassembly: | passes | instructions | |---|---| | `-instcombine -gvn -adce -simplifycfg` | -9.3% | | `-sroa -early-cse -simplifycfg -instcombine -reassociate -sccp -jump-threading -correlated-propagation -simplifycfg -instcombine -licm -gvn -dse -bdce -adce -simplifycfg -instcombine -strip-dead-prototypes` | -11.2% | 0.03 to 0.07 s a shader. The gain is in bitcast, select, shifts and branches, not in the arithmetic. `dxil.dll`'s validator accepts 386 of the 400 after the passes against 388 of 400 for the modules as translated; the two new refusals are "Flags must match usage", so the shader flags would have to be recomputed after the passes. Whether 10% fewer cheap instructions moves the card's 84 to 128 ms I cannot say; I did not run it. This is the measured side of point 2 in #1382. ## 2. Two open items here that avatarmanz's fork has answers for Their fork left yours at `a26859f` and has not come back, so in case you have not looked: - **"Anything the sun does not hit directly is black."** `crates/victory-gpu/src/ambient.rs` there is a stand-in for the bounced light (`VICTORY_AMBIENT`, with creases and air), and since today a band that keeps the traced indirect light in range when ray tracing is on (`VICTORY_AMBIENT_RT=<least>,<most>`). - **Trees dropping out for a few frames, light swinging in lamp-lit rooms** (if you see these too). Their finding: indirect draws whose arguments sit in renderer port 1's in-place memory were prepared before the title's culling had written them. They now prepare those one at a time right before they run (`VICTORY_PORT_CONSTANTS_ORDER`, on by default, 2 to 5 ms; `reports/POPIN.md`, runs pop-14 to pop-17). In the other direction I have told them about `VICTORY_HEAP_WORKER` and `VICTORY_LOOKUP_CACHE`, which they do not have.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork#1383
No description provided.