Shaders: declare each dx.op call once #1824
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1824
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1824"
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?
@slatefield on GitHub · 2026-11-24 23:02 UTC · original
slatefield:shader/dxop-declaration-cache→main· +70 −11 · 1 files · 2 commits · openevery 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.@DesertGamer on GitHub · 2026-11-24 23:06 UTC · original
VIctory V2: community PRs, merged and tested
Open 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).
⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.
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:
https://DesertGamer/VIctory-V2
Unofficial community fork of Marvisak/VIctory, GPL-3.0.
@upipibi on GitHub · 2026-11-24 23:10 UTC · original
This changes results, not just speed. RTX 3070 (driver 616.56) plus WARP, Windows 11, debug,
48de010(onmain70564ae).cargo test -p victory-shader --locked: 195 passed, 14 failed, 2 ignored.mainfails only #1744's 3. The 11 new ones fail identically on the hardware and on WARP:semantics_tests::{byte_packing, rounding, min_max_and_clamp, min_max_and_selects_take_denormals_on_the_bits, med3_orders_signed_zeros, transcendental_specials}_…valu_tests::{v_cvt_u16_and_i16_f16_saturate, v_med3_f16/f32_matches_rdna2_with_nan, v_sin_and_v_cos_f16/f32_reduce_large_turns}For example
v_sin_f32(0.25)returns 2, which isround(0.25 · 2π).v_med3_f32(0, 0, -1)returns -1, andv_cvt_pk_u8_f32(0, …)writes 255.The cause: the
op_declslookup matchesname,attr,retand the argument types, but notopcode. On a hit it returns the cachedcode, the opcode constant of the first call that declared that function. Everydx.opsharing a function (unary.f32for sin, cos, round, frc…;binaryfor min / max…) then runs the first one's opcode. Comparingopcodein thepositionclosure, or buildingself.m.i32(opcode)on every call and caching onlyf, should fix it.written_bytes_unchangedprobably uses only one opcode per function, so it can't see this.AI-assisted (Claude Code). Synthetic tests only.
@slatefield on GitHub · 2026-11-25 00:37 UTC · original
Good catch, that one is real.
dx.op.unary.f32is a single function for sin, cos, round, floor and the rest, so keying the declaration on the name, attributes, return and argument types put them all under one entry and every hit returned the first call's opcode constant. The opcode is part of the cache key now (OpDecl.opcode, compared in the position closure and stored on insert), so each opcode gets its own entry and its own constant; the function and the hashed lookups are still shared when the same op passes again, which is the common case.Pushed as
4fbaa83on the branch.cargo test -p victory-shader --lib118 passed, 1 ignored on Linux and the Windows-target clippy with--all-targets --all-featuresis clean. Your 11 failing host tests are the ones that would confirm it on real hardware or WARP:semantics_tests::{byte_packing, rounding, min_max_and_clamp, ..., transcendental_specials}and thevalu_teststranscendentals. I could not rerun them here, no D3D12 host. If you still have the 3070 and WARP setup, a rerun ofcargo test -p victory-shader --lockedwould settle it; I do not want this merged on my say-so alone.written_bytes_unchangednot seeing it is right, it pins one opcode per function shape.@upipibi on GitHub · 2026-11-25 02:37 UTC · original
Re-checked
4fbaa83on the RTX 3070 (driver 616.56) and WARP: with the opcode now part of the declaration cache key,cargo test -p victory-shader --lockedgives 206 passed, with only #1744's 3 NVIDIA failures. The 11 wrong-opcode failures from before are gone.AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-25 06:31 UTC · original · edited 2026-11-25 14:53 UTC
Automated triage for the maintainers.
Merge candidate.
Shader::op(crates/victory-shader/src/emit/shader.rs) now keeps up to 48dx.opdeclarations, most recent first. They are keyed by name, attribute, return type, argument types and opcode, so a repeated operation skips theformat!, the signature type and the hashed lookups. The cache is perShader, so per program. The opcode is part of the key becausedx.op.unary.f32and friends are one function for many opcodes. The call itself is unchanged, including the sampler-choice duplicate.On your reply: the two missing points are covered now. On the GPU run: upipibi re-ran this head (
4fbaa83) on an RTX 3070 and WARP, and only #1744's three known failures remain, so the 11 wrong-opcode failures from the first head are gone. I missed that report in the last note. On the measurement: your synthetic numbers (Shader::op281 → 88 ns, a one-dx.op-per-instruction program 6.45 → 4.53 ms) show where the saving comes from, and sinan-cmyk's program-by-program run on the pack shows no change in what translates or validates. Atranslatetiming over the pack atmainand at this head would still be useful for the maintainer, but it is no longer a blocker.CI: no check runs on the head commit.
Generated by Claude Code
@sinan-cmyk on GitHub · 2026-11-25 12:24 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head
4fbaa835ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@slatefield on GitHub · 2026-11-25 12:59 UTC · original
The triage asks for a translation-time measurement before this is a candidate, and I cannot produce one: no game data on my machine. If either of you still has the tree, the run that would settle it is a
translateover the pack atmain940d32fand at this head (4fbaa83), same command and same machine, e.g.or
--listif the cache write dominates. What matters is the delta between the two heads, not the absolute number.For reference, the per-call microbenchmark I measured while writing it:
Shader::op281 -> 88 ns in the hot case, and a synthetic 8000-instruction program that is onedx.opper instruction lowers in 6.45 -> 4.53 ms. Those are synthetic; a pack number from someone with the files is worth more than both.@Melow-code on GitHub · 2026-11-24 23:04 UTC · original · approved these changes
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.createHandlewith different resource types) must get separate declarations.@catminou4 on GitHub · 2026-11-24 23:52 UTC · original · approved these changes
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.
@fuzeofficlal on GitHub · 2026-11-26 18:47 UTC · original · approved these changes
Verified
4fbaa83516ad5eb3d67eb5f01d7358179f436d4fcleanly merged ontomain(63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDKdxil.dll):OpDecl(crates/victory-shader/src/emit/shader.rs:163-171, 259-299) keys the 48-entry move-to-front cache byname(including overload suffix),attr,ret,opcode, and all argument types, fixing the shared-callee opcode collision (dx.op.unary.f32forsin/cos/round/abs). Noemit/callers pass conflictingAttror signatures for a shareddx.op.*name.cargo test -p xtask --locked policy::tests::repository_passes_policy:1 passed(asset policy: 191 files ok);cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features): clean.emit::shader::tests::(1 passed),emit::tests::constant_color_validates(1 passed),v_sin_and_v_cos_f16_reduce_large_turns,v_sin_and_v_cos_f32_reduce_large_turns,transcendental_specials_match_the_hardware, androunding_matches_the_hardwareall pass on WARP and RTX 5090 (v_sin_and_v_cos_f32_reduce_large_turns2.80s,transcendental_specials_match_the_hardware1.56son RTX 5090).Ready to merge.
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.