Repository navigation
Shaders: declare each dx.op call once - #1824
slatefield wants to merge 2 commits into
Conversation
Every dx.op call rebuilt its declaration: a format!, the signature type, the pointer type, the opcode constant's type, four hashed lookups, and it cloned the argument vector even when no sampler choice had to be patched. A program repeats the same few operations, so keep the declarations in a 48-entry move-to-front list and build the call's arguments once. An 8000-instruction dx.op-heavy program lowers in 4.53 ms instead of 6.45 ms; the emitted bitcode is unchanged, which the pinned-bytes test checks.
Melow-code
left a comment
There was a problem hiding this comment.
The move-to-front cache is a good fit: dx.op opcodes cluster by shader stage, so the hot set stays small. The 281→88 ns/call and 6.45→4.53 ms on an 8000-instruction program are solid wins. The worst case (200 distinct ops, 402 vs 325 ns) is acceptable — no real shader uses that many distinct opcodes.
One thing to verify: the cache matches on the full signature (return type + parameter types + opcode), not just the opcode number, correct? Two calls to the same opcode with different overloads (e.g. dx.op.createHandle with different resource types) must get separate declarations.
VIctory V2: community PRs, merged and testedOpen PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: Unofficial community fork of Marvisak/VIctory, GPL-3.0. |
|
This changes results, not just speed. RTX 3070 (driver 616.56) plus WARP, Windows 11, debug,
For example The cause: the AI-assisted (Claude Code). Synthetic tests only. |
catminou4
left a comment
There was a problem hiding this comment.
Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (70564ae), cargo test -p victory-shader --locked → 118 passed, 0 failed. GPU execution tests are #[cfg(all(test, windows))] and run only on Windows.
Each dx.op call declared once: dedup of debug-op declarations — avoids duplicate dx.op metadata.
Translation speed (compile-storm CPU): Marvisak#1623 inline instruction words (decode -18..-45%), Marvisak#1834 VALU names without heap vector, Marvisak#1833 live-set bit walk, Marvisak#1802 relative shift bounds, Marvisak#1824 dx.op declarations once. Per-draw/per-list CPU: Marvisak#1825 view-stride table once per list, Marvisak#1826 object names only where logged, Marvisak#1800 capped-heap log spam once per 64Ki. Tooling: Marvisak#1809 list pipeline keys without cache init. Locking: Marvisak#1680 pipeline library loads without the global mutex. Held: Marvisak#1819 (2^20->2^14 loop bound) breaks transcendental convergence tests (sin/cos/exp/sqrt) — accuracy-lowering, rejected per policy.
The cache keyed declarations on (name, attributes, return and argument types) but returned the cached opcode constant with them. Operations sharing one DXIL name with different opcodes (unaryBits.i32 is first-bit-low/high and first-bit-high/low: 31/32/33/34) got the first opcode used in the program, miscompiling every later one (med3, min/max, cvt_pk_u8, sin/cos and gather GPU tests failed with hardware and WARP agreeing against the model). Key on the opcode as well.
upipibi caught this: dx.op.unary.f32 is one function for sin, cos, round, floor and the rest, so a declaration cache keyed on the name and the signature handed all of them the first call's opcode constant. v_sin_f32(0.25) came out as round(0.25 * 2pi). The opcode is part of the key now. 118 lib tests pass on Linux, windows-target clippy clean. The tests that caught it (semantics_tests, valu_tests) are host tests and need a GPU run to confirm.
|
Good catch, that one is real. Pushed as 4fbaa83 on the branch.
|
every dx.op call redeclared the same function: format! for the name, signature type, ptr type, i32 constant, 4 hashed lookups, and it cloned the args vec even when there was no sampler choice to patch.
now declarations sit in a 48 entry move to front cache so hot ops stay at the front. hot case 281 -> 88 ns/call. 8000 instruction dx.op-heavy program lowers 6.45 -> 4.53 ms (2000 instruction one: 1.57 -> 1.05).
output is byte identical,
written_bytes_unchangedstill pins the same bytes. worst case (200 distinct ops in one program) is 325 -> 402 ns, bounded by the cap.