Shaders: revert #2357's integer folds (hair scrambled since v2026.11.30.01) [pr-fix] #4567
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4567"
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 trustno1-coder/VIctory-NVIDIA. Originally posted by cafeoh on 2026-11-30T22:47:29Z.
Fixes #4187 (also #4260, #4313, #4065)
What it changes
Reverts #2357 (merge
467a002d4). Since .30.01, head hair on every character with physics hair is drawn as long spiky strands.Bisected over main's merges between .29.05 and .30.02: first bad #2357, last good #2349. With a local switch over its rules,
(x >> s) & m -> x >> salone brings the broken hair back;(x << s) & m -> x << salone does not. The rule is correct on paper, so either it or a later pass reading its output is at fault. Until that is found, the whole PR goes: its folds showed no gain (20 bytes on one large shader in the PR's own check), and the driver's compiler does the same integer folds itself.The revert applies cleanly on
e1251c319(opt.rs only).How it was tested
e1251c319: hair scrambled (and at every bisect step from #2357 on).cargo testpassed for the crates it touches:cargo test -p victory-shader --lib: 471 passed. The 64 failures are the same on maine1251c319(this card has no SM 6.6 device for the hardware tests); main's one extra pass is #2357's own test, which the revert removes.Checked for overlap
VICTORY_SHADER_OPT=445) posted in #4187.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by VibeCodeGuy on 2026-12-01T00:01:08Z.
Offline check of the rule itself. In short: on this title's shaders,
(x >> s) & m -> x >> sdoesn't change what any hair program computes.What I did. On
maine1251c31I added an env switch that turns off only that rule, theBin::LShrarm inBin::Andinopt.rs. Then I ranvictory translate shaders.rpf --listwith it on and off (VICTORY_EMIT_DUMP,VICTORY_HOST_WAVE=32, and play's shader-key settingsVICTORY_EARLY_DEPTH=1 VICTORY_NAN_SCRUB=1 VICTORY_BVH_MISS=1 VICTORY_SAMPLED_MARKS=1), on a v1.0.2.1 dump, cross-built and run under Wine.The rule changes the DXIL of 16,007 of 25,694 programs. 174 of them are the hair path, every changed program named
smh*or*hair*:smh_sim_*,smh_pose_*,smh_gen_*:CS_InterpolateStrands,smh_modify,smh_accessory,smh_draw_*:CS_VisHair,bvh_skinning_smh:CSGenerateHairVB,VS_HairStrandGeometry,PS_HairStrandGBuffer(list below).I disassembled each pair with DXC 1.9.2609 (
dxc -dumpbin) and compared them as expression graphs. Every value was hashed from its operands, with stores, void calls, terminators and phis as roots. In all 174, only two kinds of difference remain:and i32 (lshr i32 %x, s), Mis gone whereMkeeps every bit the shift can leave.LegacyF16ToF32(and(lshr %x, 16), 65535)and theLegacyF16ToF32(lshr %x, 16)that the translator already emits next to it become the same call, and the duplicate is merged.Nothing else differs: no operand, constant, branch, store or atomic. Only the
DXILpart differs;PSV0,RTS0and the signatures are byte-identical. The checker does catch a changed shift, mask or operand (self-tested by perturbing one of these files).Example,
smh_sim_0:CS_EstimateStartPosition. With the rule off it has%108 = and i32 %104, 65535(%104 = lshr i32 %82, 16) feedingLegacyF16ToF32, and also%163 = LegacyF16ToF32(%104)with no mask. With the rule on, the two calls are one. Before #2357 the program already had both forms side by side.Across a random 400 of the 16,007, 385 compare equal with the checker. The other 15 use folds the checker's simple rewrites don't cover. The one I followed by hand is
(lshr %x, 30) & 0xFFFF0000, folded to0by the rule's other arm, which is correct.So the rule is right, and no later translator pass misreads its output, at least on these programs. What's left is either NVIDIA's compiler handling the two equivalent forms differently, or something timing-sensitive in the hair passes that the shorter code exposes; the per-frame flicker fits the second. The revert hides both, which is fine as a stopgap. To pin it down, someone with a card could bisect over these 174 programs: keep the fold everywhere except in one family at a time, e.g. a switch that skips the fold pass for listed program hashes. That would point at the one program whose equivalent DXIL breaks the hair, and then either a minimal driver repro or a missing barrier in it.
The 174 hair-path programs the rule changes (all equivalent), by family
PS_HairStrandGBuffer(Ps)PS_MIRROR_PBR_MATERIAL_HAIR(Ps)PS_STUDIOSHOT_PBR_MATERIAL_HAIR_LIGHTING(Ps)PS_SmhPedEntityMask(Ps)TL_PS_NoDir_PBR_MATERIAL_HAIR(Ps)TL_PS_NoDir_PBR_MATERIAL_HAIR_GLOBAL_GLINTS(Ps)TL_PS_NoDir_PBR_MATERIAL_HAIR_UNDERWATER(Ps)TL_PS_NoDir_PBR_MATERIAL_HAIR_WETNESS(Ps)TL_PS_PBR_MATERIAL_HAIR(Ps)TL_PS_PBR_MATERIAL_HAIR_GLOBAL_GLINTS(Ps)TL_PS_PBR_MATERIAL_HAIR_UNDERWATER(Ps)TL_PS_PBR_MATERIAL_HAIR_WETNESS(Ps)VS_HairStrandGeometry(Vs)bvh_skinning_smh:CSGenerateHairVB(Cs)cascadeshadows_rendering:CS_ShadowRenderTiledMiscHair(Cs)cascadeshadows_rendering:CS_ShadowRenderTiledMiscHairAlpha(Cs)cascadeshadows_rendering:CS_ShadowRenderTiledMiscHairAlphaPPPC(Cs)cascadeshadows_rendering:CS_ShadowRenderTiledMiscHairPPPC(Cs)hair_bvh_resolve:CS_RaytracingResolve(Cs)hair_resolve:CS_ResolveToGBufferTiled_0(Cs)hair_resolve:CS_ResolveToGBufferTiled_1(Cs)hair_resolve:CS_ResolveToGBufferTiled_2(Cs)hair_resolve:CS_ResolveToGBufferTiled_3(Cs)hair_resolve:CS_ResolveToGBufferTiled_4(Cs)hair_resolve:CS_ResolveToGBufferTiled_5(Cs)hair_resolve:CS_ResolveToGBufferTiled_6(Cs)hair_resolve:CS_ResolveToGBufferTiled_7(Cs)hair_resolve:CS_ResolveToMirrorGBuffer(Cs)horse_standard_hair:CS_RaytracingResolve(Cs)shadowmask:CS_GenerateShadowMasksCheckerboard_SampleHairScreenSpace(Cs)shadowmask:CS_GenerateShadowMasksHairOnly_SampleHairScreenSpace(Cs)shadowmask:CS_GenerateShadowMasks_Checkerboard_NoHair(Cs)shadowmask:CS_GenerateShadowMasks_HairOnly(Cs)shadowmask:CS_GenerateShadowMasks_SampleHairScreenSpace(Cs)smh_accessory:CS_GenerateAccessories0(Cs)smh_accessory:CS_GenerateAccessories1(Cs)smh_accessory:CS_GenerateAccessories2(Cs)smh_accessory:CS_GenerateAccessories3(Cs)smh_accessory:CS_GenerateAccessories4(Cs)smh_accessory:CS_GenerateAccessories5(Cs)smh_accessory:CS_GenerateAccessories6(Cs)smh_accessory:CS_GenerateAccessories7(Cs)smh_draw:CS_VisHair(Cs)smh_gen:CS_InterpolateStrands(Cs)smh_modify:CS_CalculateFireVolumes(Cs)smh_modify:CS_CullMaskPass(Cs)smh_modify:CS_InterpolateStrandStyle(Cs)smh_modify:CS_ProjDecalCut(Cs)smh_pose:CS_PreSkinSimGuides(Cs)smh_pose:CS_PreSkinSimNodes(Cs)smh_pose:CS_UpdatePosePosition(Cs)smh_sim:CS_CachePrevPosition(Cs)smh_sim:CS_CachePrevVelocity(Cs)smh_sim:CS_EstimateStartPosition(Cs)smh_sim:CS_InitSimBuffer(Cs)smh_sim:CS_LodBlend(Cs)smh_sim:CS_SolvePerSplineConstraint(Cs)smh_sim:CS_SolvePerVertConstraint(Cs)smh_sim:CS_WavePerSplineConstraint_32(Cs)standard_hair_accessory:CS_RaytracingResolve(Cs)Hashes:
0ce887704e52e51d,4454eab1bf64eca9,cdeb13e0fa34536d,dd98419eb738db95,316642a29f9cd8b4,a944b2f732760372,0ec92cc4249a78bb,a526d35fb055216b,6714207ed48b0464,e5a6ec7657990b89,0267195778c9df59,6992feba843e3b84,8be3f98f633e3561,f9f378aa4d487320,e38865315b050ed9,643101624bd14159,ae6c164eea5aa84b,1df91ec81a678fd0,43cfb5b69105e332,72f552f4553fb5f9,abd7a22106898c66,1d44a723bdebbf27,b4b0427232707598,240cb516c1af0bc3,bff3758517ad9142,9f1e01df5796c330,1c8165626a581de4,0ccc14877cbec21e,a83a0864ccef9b67,738350c1a01b713a,d240837d597ce9d1,f7fecc64e2b98ed5,0c0380d9ec648626,54bcc8478432ba15,1204a7eb55bdb895,b69ef139ecd3b757,721c6b98cc129aa5,a98b2d2aa2acfffe,47608b6c13152cd1,888af37a584acf98,5cf00dc39042edaf,0a5ecfee6b79e13b,2889c21328c69e58,fd0abf1557673a1b,9be0368502fe75a0,f9528bddae9d784c,00f607218c949e38,c2dc7073dd57d0bd,39c8537b029be0c3,43a695e99d51bee3,abefa9e679c3f985,b6df66af105d8b2d,edc43d3e658a4b9d,7b2881ff62faba9d,58b1400a40af4738,23d107380df81cf1,8080af82aaac33df,f7c4f227a2a4c4b2,a68c4b8fc7bc4b5c,07fdf30955c4abbc,b3e7781d53ff8326,52089284117a310b,dabecdf6a76f6ac5,0a37689d055d5b44,c4f1becd11afec3e,25c5ee5063e1a41f,2e7a71c083a79dd7,ae83305f523f4b1b,77a7af30c430cd16,688acec013d202f3,010a50ce68d02c16,142831c820dca7a3,9aa4a785e0800cda,72b5ddf9b24d98d2,c2403765027d12b6,f384ff9b2bb127c5,b63e7606ee1302fa,3bfbe3f43cf57636,9aa3629668b8e7ab,44bb2d65d51ba5d1,f5f5e06abea6e83a,8c970301dd4eee4f,ee26678cdf63cf32,9ba277f4542cfd9c,b00958f7e581464d,bda486f4b8a3fd0f,e4688ae9d52294f8,1547305c505a7559,37322e35397bcb4f,cb31a20c7aeafb86,a3e722830cfa55fe,4814890b920fe12e,e7c9e7210ffff1fc,ac4c69f7c2aaa95a,d6e372a386b9e253,161bc88937af764c,a8b9e7724b6a6fdc,0743686596b14ec9,0d550b5f17df9bc1,029dfbaa64951060,f21917075db73dad,83b44924ab6657c2,5b6eed17c131f881,21d27f785da6d2b1,006d583a371f22ec,35813c04e939bc21,098fc28e44347a00,bd0dfdfb50657f60,b24d68169f04159a,0115b73d7e531e04,cbff6f05ed99958b,9ac37ee176bd2353,dedcc49075cfc1d9,45b8c316ec2f3e8c,9216e90f97b19283,64f4384125e1993b,234d47be72397f85,b5e3137b54ba16c4,6006c34443033b5a,ce3bba2e7a2c2c7b,54ccf3d13b5bf091,9267f0cfc6452000,7239c0d4326c9967,f29138d2ea4a0b9e,2a3522dae6b66c17,4e425adf8edeb96f,76ebccca0fd3851e,beee29e2da2b1461,ebce8db62fe43ed9,444715459ad11d5c,e6b1160ee45c1666,4220c55ebf8602de,706d91607b2b5516,e99d19aac5b0bcb4,31430354dd5c259c,269b802f878c24e1,3e28ebd6128bd351,d3d595d35a4ee7bb,b2b782b5d732607d,da1656ad2910e4c7,9b885ee6fdda77f5,0e45e59e93b736e4,d3e44e754b3eb6aa,38faf850f130d4dc,65732e201b1230d2,0102eac428002832,b8c6ee7eb35f23ea,dbfb6f9d172b3a43,959a530059731c41,d474a0f15cd0f545,251d57fa0adf0b53,deec5fb86d9cc5f3,fe71a5c67edd3d84,889d32cc4e668148,4a05640ec16718ad,1ea7e2dbf731c8dc,ab82f8d3b0809138,96ed122706539da9,7353bdc4c2c79fd1,f38afa09308835a3,418f3fdf020b9eda,93c52598be113a6b,9faf21803c0d8eea,c47e03e0e3946741,e35b7de6a9d2bfd4,746fd4d8b0d88c3c,dfba1b3a39e9a19d,27afb6546fe3e225,021587bdd5335e89,c8c53d32de5c858d,611e727832ef1ab9,3d03a8a88ad6670e,c0b9134fa622f802,f7abaa39145df433The revert itself, same corpus run (
translate --validate --listover the whole dump,maine1251c31againstmain+ this PR, 32 lanes, play's shader-key settings, DXC 1.9.2609 validator): 0 newly failing, 0 newly passing. 17,902 of 25,699 programs change DXIL, and all of them validate (apart from the 71 oversized mesh programs that already fail onmain). It is safe to merge as far as translation goes. Expect every player's shader cache to be rebuilt for most programs.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by BitWuehler on 2026-12-01T00:41:52Z.
Tested on Linux (CachyOS) / GE-Proton 11-14 (
vkd3d-proton master) / Ryzen 7 9800X3D / RTX 5080 16 GB (driver 620.73.04) on top of7d93ee07(Series X profile, 1440p, DLSS Balanced + DLSS Frame Generation 2x):(Test summary compiled with AI assistance.)
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by KyleS98 on 2026-12-01T02:55:33Z.
An independent bisect on other hardware landed on the same merge, so here is what it adds to the above: in-game runs for @VibeCodeGuy's point 2, the one case of the rule that matters, and that this rule is also a frame-time regression.
Setup. RTX 3090 Ti (driver 616.92), Ryzen 9 9950X3D, Windows 11, Series X profile at 2560x1440, DLSS performance, FSR 3 frame generation 2x; the prologue's cell with the character at the window. Hair judged from screenshots by a script and by eye at the end points; every run from an empty shader cache.
The bisect agrees: last good #2349 (
4308f5ce), first bad #2357 (467a002d), over main's first-parent line fromf889bb07, each step built with87dd67e1on top because of #1939'sRmw::Sub.It needs REUSE, measured in game. With a switch around the rule and the passes chosen by
VICTORY_SHADER_OPT, on a tree that hase1251c31merged into our fork (KyleS98/VIctory-Neo):lshrarm of the rule offVICTORY_SHADER_OPT=443)So it is not the missing mask by itself. It is the mask gone from
(x >> 16) & 0xFFFFand REUSE then merging the twoLegacyF16ToF32calls into one, exactly the second difference in the offline check above. With the two calls kept apart, masked or not, the hair is whole. That points at one shape to look at: a singleLegacyF16ToF32(lshr %x, 16)carrying the uses of both former calls.It is the frame-time regression too. The fps and long-frame columns move with the hair in every row. On
e1251c31as released,VICTORY_SHADER_OPT=445gives whole hair and 30.3 fps where the default gives torn hair and 23.3 (166 frames per 1000 over 50 ms down to 22). The strands across the screen are what costs the frames, so the revert should bring back frame rate on cards like this one, not only the hair.For the fix: the revert is fine by me. If you would rather keep the other folds, a smaller change also holds here: dropping only the "mask covers the shift" arm for
lshr(the arm that folds to zero can stay) gave whole hair on7d93ee07in one full run (29.6 fps), with the optimizer's 31 unit tests passing after the rule's own test is adjusted. I can send that as a pull request if it is wanted; I did not want to open a second one beside this.Not checked here: AMD and Intel cards, and why the card's compiler treats the merged call differently.
AI-assisted (Claude Code, Claude Fable 5.2)
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nick0451 on 2026-12-01T03:44:19Z.
@cafeoh A note on the branch, since the description says it's
opt.rsonly: the PR currently shows 14 commits and 33 files (+990 −1219). The branch starts from the release commite1251c31, and that commit isn't onmain. The release line carries its own copies of 13 of main's commits (for exampleec3ac62bthere and9e405ccbon main, "keep 512 MB below 4 GiB …"), so GitHub counts them as part of this PR. Your commit43e0df14on its own cherry-picks cleanly onto currentmain(5fabb46e):opt.rsonly, +35 −372. Rebasing the branch ontomainwould leave just the revert.One more data point for the change, on an RTX 3090 (Ampere), driver 610.88, Series S, DLSS performance. On the official v2026.11.30.03 at a balcony railing: the default build gave scrambled hair in 2 of 2 off-screen starts and in a watched session, and a 40-frame burst at about 12 frames/s caught the strands spread wide around the head in almost every frame.
VICTORY_SHADER_OPT=445gave whole hair and beard in 2 of 2 starts and in a watched session, with 40 of 40 frames clean in the burst, and 28–30 fps against 22–23 at the same spot. That agrees with KyleS98's frame-time finding.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by andrewpozdnakov7-jpg on 2026-12-01T09:03:26Z.
I cherry-picked your exact revert
43e0df14onto currentmain5fabb46eas86db371f4ab317011efeab41375d468d01dc65f4, preserving the Git author. The patch ID matches. The comparison with current main has one commit and one changed file,crates/victory-shader/src/emit/bitcode/opt.rs. This leaves the unrelated release-branch commits out of the diff. Rebased commitThe focused
extended_fold_algebraic_bitwise_shifts_and_strength_reductionunit test passed on Windows/MSVC with Rust 1.98.1, andcargo xtask policy --stagedaccepted the exact diff. The game has yet to be tested on this rebased commit. The original in-game bisect remains the evidence for the visual fix.If this base works for you, the review commit is ready to use in the existing PR.
AI-assisted with OpenAI Codex.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by cafeoh on 2026-12-01T09:44:54Z.
A speed data point, besides the hair: on main
f5c3d2434(RTX 2080 Ti, Windows 10, Series S, ray tracing on, DLSS off, launcher defaults, release, warm, 89 s after the world, PresentMon last 40 s), two runs each:(Both with the same unrelated ray-tracing fix on top, so the only difference is this PR.) Whatever the folds do on the card, on this NVIDIA card the frame is about 4 fps slower with them.
Tested: the above. Not tested: other cards, which of the 174 programs costs the time.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by andrewpozdnakov7-jpg on 2026-12-01T10:29:48Z.
SauliusGA confirmed the fix in #4793 on an RTX 3090: the long, jumping hair strands disappeared with the rebased 86db371 in the same save, with DLSS Ultra Performance, frame generation off and Skip Big Copy-Backs on. Tester report
I verified that the tested 86db371f4ab317011efeab41375d468d01dc65f4 and current PR head
c95ef843edhave the identical source tree7addc5a45d.AI-assisted with OpenAI Codex.
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.