perf(vk): the Lens eye pass looks for the eye's multiply before it maps a program's uses #2743
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2743
Loading…
Reference in a new issue
No description provided.
Delete branch "bulldogsajr22/Longshot:perf/lens-eye-scan-first"
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?
Summary
Follow-up to #2713 for its review's L3 (BeanBot, #2713 (comment)): the cost of the Lens of Truth eye pass at shader translation.
LensEyePassruns on every graphics fragment program that reads the effect camera bank (13) as it is translated. Onmainit first puts every instruction's uses in a map, and only then looks for the eye's multiply by 1.26984131 (16:9 / 1.4). In a cold shader preparation that is 13,222 fragment programs and 59.4 million instructions mapped, for the one program that has the multiply (d547af983903a518, the eye's): 5.0 s of CPU time spread over the preparation's workers.Now the pass looks at each instruction for that multiply first, and a program with none leaves with "no eye" and nothing allocated. The uses are mapped only for a program that has one, the same map as before (the same loop over the same blocks, only after the look), so the eye and every other program translate as they did: 263 ms in all for the same programs, and the same SPIR-V (measured below).
Read first: the start of
LensEyePassingpu/vk/eden/shader_recompiler/ir_opt/lens_eye_pass.h, thentests/lens_eye_ir.cpp(theNoScaleshape and the allocation count).See #2713.
Testing
Tested: Windows 11 Pro (26H2, build 26300), Ryzen 9 9950X3D (16 cores, 32 threads), RTX 5090, NVIDIA 621.40.
longshot --prepare-shaders --compile-shaders most, what longshot-builder runs) of this PR and ofmain@22d0d200, each with an empty program cache, an empty shader store and an empty NVIDIA shader cache of its own (LONGSHOT_SHADER_CACHE,LONGSHOT_SHADER_STORE,__GL_SHADER_DISK_CACHE_PATH), 32 workers, interleaved main, PR, main, PR: all 38,809 programs prepared, 0 failed, and in eachvk: program d547af983903a518: the Lens of Truth's eye at the picture's shape, its ring with it, its swirl too.mainand on #2713, its tips 1.40 half heights from the centre, meeting the reveal, no unrevealed strip, the swirl round, its sides not burnt out. In play the game translated nothing (program census (play): created 0, every frame'stranslation 0 ms in all): a warm start never runs the pass.tests/test_lens_eye_pass.pypasses with clang++ (libstdc++) on Linux and llvm-mingw's clang++ (libc++) on Windows; withmain's pass and this test, it fails on both for the reason it checks:no eye's multiply: 24 allocations, not 0(26 with libc++).mise run test(Ubuntu 24.04 on WSL, 32 at once): 858 passed, 20 failed, 10 skipped (Windows-only). 19 of the failures fail the same way onmain@22d0d200on this PC (859 passed there): test_bug_report, test_cloth_kernels, test_control_picture, test_crash_record, test_framegen_hdr, test_framegen_resources, test_guest_holes, test_input_background, test_lifter, test_linux_saves_move, test_log_open_failure, test_oot_cloth, test_perf_send, test_pipeline_tour, test_present_source_crop, test_screensaver, test_switch_table, test_temporal_present_bandwidth, test_xinput_thread. The 20th, test_fsr4_own_cache ("longshot_fsr4_pipelines.bin.tmp-123-4 was not swept"), reads none of this PR's files and passed 5 runs of 5 alone on this head and onmain: it failed once under the suite's load.longshot-builder compile --only renderer, the pinned llvm, sysroot and cpm): 271 of 271 units,longshot_vk.solinked; and for Windows bylongshot-builderfrom this commit's source (the test build above).mise run lintpasses.Still to test:
main, expecting the same eye on both (its tips meeting the reveal, about 59 % of the picture's width) and the eye's log line; this also runs #2713's eye on Linux AMD, its review's L1 (@Beanstalk linux, amd).Measurements
Verdict: the pass's own time at a cold translation of every program down from 5,034 ms to 263 ms of CPU time (−95 %), with the same SPIR-V; on this 32-thread PC that is about 0.15 s of the translation's 50 s, within the spread of the whole preparation. A warm start translates nothing, so it is unchanged.
Baseline (first two rows): the pass's time is measured in one build, this PR plus a timing commit not in this PR (70a90119), which runs
main's first part (the uses mapped first, then the look; a copy that only reads) and this PR's pass on each of the same programs, which of them first alternating. The other rows aremain@22d0d200and this PR, built alike from source.Setup: Windows 11 Pro 26300, Ryzen 9 9950X3D, RTX 5090, NVIDIA 621.40;
longshot --prepare-shaders --compile-shaders mostwith empty caches of its own each run (Testing), 32 workers; the game's own log lines; interleaved main, PR, main, PR.22d0d200b6766b8amain's scan, timed beside the PR's)The SPIR-V: 50,841 blobs are in every run;
main's second run made exactly those and nothing else, so every program asmaintranslates it is in both of this PR's runs. Each other run also made 1 to 4 large blobs of its own (14,183 to 135,131 words), never the same twice,main's first run too: the preparation's run-to-run variation, not this change.The timing build's line, after the preparation:
The preparations' lines (
main1, PR 1,main2, PR 2):Risks
The same eye and the same SPIR-V for every program, by construction and as measured: a program with no eye's multiply returned "no eye" on
maintoo, after the map. A revert is enough.What a player notices after updating:
lens_eye_pass.his in the shader translator's stamp, so the nightly that carries this prepares the shaders again once (as any translator change does; 19 commits onmainmoved the stamp in the past week). Nothing else: no setting, no save, no switch.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Windows 11 Pro 26300, RTX 5090, NVIDIA 621.40, HDR, DLSS: a build of this head, the Shadow Temple B4 save at 5120x2160 (21:9), the Lens of Truth on, off and on again, the camera turned both ways. The eye as on main and #2713: its tips 1.40 half heights from the centre, meeting the reveal, no unrevealed strip, the swirl round. Cold shader preparations of this head and of main
22d0d200(empty caches each): 38,809 programs prepared, 0 failed, the eye's program made in each (log line "the Lens of Truth's eye at the picture's shape, its ring with it, its swirl too"), the same SPIR-V.@Beanstalk linux, amd, and a Steam Deck: this head (
b6766b8a) againstmain@22d0d200, the same steps on each. It also runs #2713's eye on both, its review's L1 and L2.kokiri-start. On the Insert menu's Debug tab, Inventory: unlock Lens of Truth and Magic Meter (Items section). Then Teleport to Bottom of the Well.Expected, the same on both sides: the purple eye's tips meeting the edge of what the Lens reveals, the eye about 59 % of the picture's width at 21:9 and about 88 % on the Steam Deck, no unrevealed strip inside its tips, the swirl round, not stretched. In each side's
longshot_log.txt(or the shader preparation's):vk: program d547af983903a518: the Lens of Truth's eye at the picture's shape, its ring with it, its swirl too.@bulldogsajr22 only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@review
Recommendation: Approve. The code is ready: only testing is left. The pass preserves the original matching and rewrite logic while avoiding the use map when the multiply is absent. The reported pass-time reduction is promising, but repeated measurements against the actual base are still needed. Recommend approval; not approved on the forge.
Cold shader translation skips use-map allocations for fragment programs without the eye’s multiply. The code is simpler on that common path, at the cost of a second instruction scan for programs that contain the multiply; warm starts that translate nothing are unchanged.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/eden/shader_recompiler/ir_opt/lens_eye_pass.h:75: The pass-time comparison is from one instrumented preparation using a copy of the base scan, and the whole preparation timings overlap. (more on the line) Do: Measure the pass and cold preparation in repeated interleaved runs of instrumented builds of the actual base and head, with the same setup and empty caches.Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven as a repeatable player-facing gain. One instrumented preparation reports 5,034 ms versus 263 ms summed CPU time for the pass, but its baseline was a copy of main’s scan in the PR build; cold translation was 50.5/51.4 s versus 50.6/50.2 s, within run-to-run spread.
Other systems: The pass runs during graphics fragment translation on Windows and Linux and can affect the eye’s linked vertex pass. The matching and map contents are unchanged for programs with the multiply; the reported Windows NVIDIA run and shader-store comparison support equivalent output. Linux AMD and Steam Deck game runs remain outstanding.
Switches: None.
Reviewed:
b6766b8a88against22d0d20098: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, the commit, both changed files and the test runner in full; inspected the translation and vertex-pass call sites and the reported runs. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No generated files or translations changed.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no tests or project code run. The author reports Windows and Linux fixture runs, renderer builds, lint and game testing; CI is still running.
Overlaps and merge order: Follow-up to #2713; no other overlaps identified from the supplied information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -74,2 +72,4 @@for (IR::Block* block : program.blocks)for (IR::Inst& inst : block->Instructions())if (inst.GetOpcode() == IR::Opcode::FPMul32 && (IsImm(inst.Arg(0), kEyeScale) != IsImm(inst.Arg(1), kEyeScale)))scales.push_back(&inst);L1 (should fix): The pass-time comparison is from one instrumented preparation using a copy of the base scan, and the whole preparation timings overlap.
When: On the reported 32-worker machine, cold translation varies from 50.2 to 51.4 seconds across the two versions, so the observed wall-time difference does not establish a repeatable gain.
Do: Measure the pass and cold preparation in repeated interleaved runs of instrumented builds of the actual base and head, with the same setup and empty caches.