A program pick reads and decodes every stage of a new program under the shader lock, even when the same bytes were decoded before #1609
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot#1609
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Type: performance · Area: renderer, shaders, program pick · Part of: #1493
TL;DR
When the game makes a program object, the first draw that picks it reads each stage's control section and code from guest memory again, keys it and decodes the instructions, with the shaders' lock held. The decoded stages are kept by program serial, so the same bytes under a new serial are decoded again. The program's stage keys were already computed once at creation, without the decode, and the pick does not use them. We do not know what this costs on main, so we propose a counter first.
Breakdown
codes_ofreads, keys and decodes every stage of a new serial in full whileshader_muis held. The result is kept by serial, not by content. The creation-time read of the same stages is a second, separate pass.Evidence
Code on
forge/mainat430eef4f2:gpu/vk/vk_shader.cpp:1044-1052:codes_offills a serial's vector withread_codefor each of its stages when the vector is empty.:165-176:read_codereads the control section and the code area from guest memory, then callsparse_code, which takes the code key over both and decodes the instructions.:1012: the store is a mapcodes"by program serial".:2072-2073:program_picktakesshader_muand callscodes_ofwhile holding it. A comment at:2631saysshader_muis held through whole translations.:2635-2660and:2680-2700: at creation,read_code_headreads the same control section and code area and computes the key and the flags the pick needs (scene_fit,header_only), but does not decode the instructions.program_created_readkeeps the result by serial (created_codes) for the load-at-create path. The pick does not read from there.The fork's claim, not ours: an outside audit of a fork says program picks read and decode stage code for about 45 ms in a save's load-in frame (37 to 67 ms across sessions), that decoding a stage took about 48 microseconds and a cached hit about 1.4, and that the fork fixed it with a byte-keyed cache. These are figures from a comment in the fork's source on its own lab PC. We have not measured them on Longshot.
Proposed change
read_codeandparse_code, bytes read, and the count of serials whose stage bytes equal an earlier serial's. Print once per 600 presents with the other renderer lines. This changes no behaviour.shader_mu.Step 3 changes what a pick must be able to tell without decoding.
parse_codeandread_code_headhold two copies of the same logic forscene_fitandheader_only; they have to agree for the step to be safe, and that needs a careful look before anyone writes it.How we would test it
vk_shader.cppcannot be linked in a test today, so there is no game-free test of today'scodes_ofto make red.Related
New on this forge; not opened on GitHub.
Possibly related, for context: