fix(vk): report native shader keys in draw statistics #169
No reviewers
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
6 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!169
Loading…
Reference in a new issue
No description provided.
Delete branch "klimovich008/Longshot:codex/longshot-draw-stats378"
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: fix · Risk: low · Tested on: Windows 11, RX 9070 XT; Linux (WSL Ubuntu):
vk_draw.cppas an object and the fixture only · Needs: Linux, any GPU (T-FVS2)Why
RX_VK_DRAW_STATSreports how many draws each program made in a frame, but not which native shaders it ran, so a missing or wrong piece of geometry in the report can't be traced back to the game's shader. This adds the native stage keys to the report. The tracker was searched (forge.py issue list); no issue covers it.How to reproduce
Seen on: any OS and GPU
Settings and switches:
RX_VK_DRAW_STATS=<folder>, with<folder>/draw_stats.nowcreated to measure one frameSteps: on main, measure a frame and open the report written in that folder
Expected: each program's rows name the native shader keys it was recorded with
Actual: only per-program counts; no native keys, so programs loaded from the cache can't be identified
What changed
Each statistics query now copies the program's four native stage keys when it is recorded, and the report adds
coderows grouped by those keys. Off unlessRX_VK_DRAW_STATSis set.gpu/vk/vk_draw.cpp:StatsMeta/StatsQuerycopy the keys at record time (graphics, mesh and compute) into the bounded query slot;stats_code_keysgroups and writes thecoderows. The occlusion queries'OccGuardand its ordering are unchanged.tests/test_draw_stats_codes.py(new): the real snapshot/report code, cut from the source.docs/development.md: a "Draw statistics" section; twodocs/tested/run files.Measurements
Verdict: the report gains its native code rows (one a report in the measured frame); no performance effect claimed: the A/B differences are within run-to-run spread.
Hardware: Windows 11, RX 9070 XT, AMD 26.10.2, Ryzen 7 5700X3D, 64 GB
Scene: Hyrule Field (the standard test's save), camera turning at full speed; 1280x720 window (16:9), fixed Custom profile, no upscaler, no frame generation,
HOS_FPS_MAX=240Method: the standard test (std_test.py) with
RX_VK_DRAW_STATSon both arms anddraw_stats.nowpresent at the start (one frame measured, at boot), 20 s windows, 3 alternating pairs without warm-ups, all valid; the median;coderows counted in each report.How to reproduce: set
RX_VK_DRAW_STATS=<folder>, create<folder>/draw_stats.now, start the game; the report in<folder>hascoderowsBaseline: this PR measured as its code and test on main
839e85ff(66f11e37, a renderer-only pack, docs left out).839e85ff6660e13bcoderows a reportFlags and settings
None new. The existing
RX_VK_DRAW_STATSstays off by default.Testing
Tested:
tests/test_draw_stats_codes.py: snapshots and report for graphics, mesh and compute, lifetime, distinct tuples, inactive capture and capacity; fails on main (no native-key report), passes here. Windows (llvm-mingw clang) and Linux (clang 21, WSL). Since8449fbf5it cuts the source withtests/srccut.py: on Windows it passes, cuts the same text as the old counter (SRCCUT_CHECK_NAIVE=1), stops with srccut's message on a source with a secondstruct StatsQuery {, and fails on main 876dc360'svk_draw.cpp.python -I -B tests/run_all.py --jobs 4(Windows, llvm-mingw 20261104, switches cleared) at8449fbf5: 610 passed, 23 failed, 45 skipped. On clean main71b1edd8: 609 passed, 23 failed, 45 skipped (this PR adds one test). The failure lists are identical:test_audio_output_devices.py,test_auto_handheld.py,test_bug_report_defaults.py,test_crash_dialog.py,test_crt_options.py,test_dlss_feature_size.py,test_failed_compile_keeps_objects.py,test_fsr_uniform_ownership.py,test_guest_imported.py,test_import_reach.py,test_job_queue.py,test_linux_preflight.py,test_longshot_ctl.py,test_make_game_cache.py,test_missing_nup.py,test_pads_after_menu.py,test_parallel_init_order.py,test_pending_guest_import.py,test_replay_write_order.py,test_run_all_changed.py,test_tested_configurations.py,test_vk_occlusion_queries.py,test_walk_key.py. (The earlier run ataa9af402had 608/25/45 with the same 25 on main; their names were not recorded.)vk_draw.cppcompiled to an object with clang 21 and the build's Linux flags, and the fixture above. No full Linux build or link was made.0cab3548plus this PR's two commits and #239's four (longshot_vk.dllsha256c3bba234...; the pack tool takes one renderer per runtime; #239's code runs only withRX_VK_LOG_PROGRAM_LIFE, unset here), Hyrule, render thread on,draw_stats.nowcreated during play, 30 s after the load: one report for frame 6647 (1,969 queries, 368 programs, query result VK_SUCCESS); per-program rows for 261 draw, 42 mesh and 65 compute programs, and acoderow with non-zero native keys for every one of them (compute: 130 dispatches); no error or draw-stats failure lines.Not tested: the same capture on Linux (the linked Linux renderer); a full Linux build. Resident memory and commit charge with the switch unset (see Risks).
Must be tested:
RX_VK_DRAW_STATS=<folder>and create<folder>/draw_stats.nowduring play, expecting the report to keep its per-program counts and addcoderows for graphics and compute programs, with no error lines (Test Farm:@Beanstalkrequest on this PR, linux, for no crash or error lines with the switch on; it creates the trigger before the start, so it does not close this. Thecoderows during play by hand: test request T-FVS2, open; asked of a tester with a Linux PC in #agent-updates on 2026-11-18 at 15:47Z, with the mesh rows where present and the query result)Risks
What could break: behaviour: nothing with
RX_VK_DRAW_STATSunset; with it on, the report gains rows. Memory: the 32,768 query slots' static metadata (stats_meta) gains four 64-bit keys each, 1 MiB more static storage, also with the switch unset. How much of it becomes resident or adds to the commit charge was not measured. The per-query key copies and the report's grouping map run only while a frame is captured and reported.Turning it off: leave
RX_VK_DRAW_STATSunset (the default), or revert the commit.Compatibility: Nothing changes.
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md).mainand passing here.tests/that reads changed source updated in this PR, not weakened.vk_draw.cppcompiled to an object and the fixture, under WSL. No full Linux build or link; that is T-FVS2.)🤖 Generated with Claude Code
From Codex's review: Source review found no code defect at 684333d3. The production-block C++ fixture fails against main
39647e1aand passes with this change, covering snapshot lifetime, distinct tuples, graphics/mesh/compute, inactive recording and query capacity. The full Windows source suite completed in two 4-worker shards: 497 passed, 4 failed, 38 skipped. Failure names are listed in the description; a release recheck with the existing OpenSSL still failed checksum/trust fixtures, so those failures have not been cleared. Longshot gameplay, full validation and a refresh onto the selected new main remain pending. This stays WIP.Merged the shared test base and reran all source checks: 496 passed, 4 existing main failures, 37 skipped. The focused check fails on the old source and passes here. Gameplay and latest-main refresh remain pending; stays WIP.
Merged current main and resolved the documentation conflict. Full source checks: 483 passed, 5 failed, 35 skipped; all five failures also reproduce on unmodified main. The native-key check fails on old source and passes here. Gameplay and Vulkan validation remain pending; this stays WIP.
Refreshed the synthetic diagnostic test against pinned main
5b81a8a1: PR 2b04e006 passes and the pinned main lacks the native-key report. Historical suite results retain their original commits. That main snapshot conflicts beside OccGuard; refresh, final gameplay, measurement, Linux and test requests remain open. This stays WIP.2b04e0066f6660e13bebRebased linearly onto main
5e072fc8(Codex:bc1be8cd; the StatsQuery/OccGuard conflict resolved with OccGuard unchanged, test_vk_occlusion_queries passes), plus the run records (6660e13b). The fixture fails on main and passes here; full suite 517/9/36 with the same 9 failures as clean main. Measured: the standard test with draw statistics on both arms, 3 valid pairs, one native code row per PR report and none on main, no speed-up claimed. Linux: object and fixture with clang 21; the full Linux build is T-FVS2. Taking it out of WIP.WIP: fix(vk): report native shader keys in draw statisticsto fix(vk): report native shader keys in draw statisticsCode-only review of
6660e13beb; informational findings, with final approval left to another reviewer.No new correctness defect found in the native-key snapshot/report change. The four keys are copied into each bounded query slot while the program is available; reporting groups the recorded tuple rather than dereferencing the program later. The graphics/compute call sites and the existing occlusion-query lifetime ordering are preserved. The new fixture exercises snapshot lifetime, distinct tuples, graphics/mesh/compute, disabled capture and capacity; removing the key copy would break its assertions.
The remaining validation is the already documented Linux/GPU run (T-FVS2). The recorded Windows result establishes that a boot capture emits a code row; it does not establish a gameplay capture containing the full mix of graphics, mesh and compute programs. A Linux capture during gameplay would close that practical gap as well as exercise the linked renderer. This is a validation request, not a confirmed defect or a performance claim.
Read the full diff, query/report callers, shader-key population, fixture and run records. Current main still lacks this report change; the other draw-path fixes inspected do not replace it. No tests, builds or game runs performed, and no source changes made.
theguyser referenced this pull request2026-11-16 13:51:42 +00:00
71b1edd8into codex/longshot-draw-stats378Merged main
71b1edd8(aa9af402, a fast-forward, no force-push) and rewrote the description in the new template.--jobs 4): 608 passed, 25 failed, 45 skipped. The same 25 fail on clean main71b1edd8on this PC (607 passed there; this PR addstests/test_draw_stats_codes.py),test_vk_occlusion_queries.pyamong them.coderows during play.@Beanstalk linux, any GPU: with RX_VK_DRAW_STATS set to a folder and draw_stats.now created in it before the game starts, 60 s in Hyrule Field. Fail on a crash or error lines in the log; compare frame times with main.
@klimovich008 only members of
BigBeanscan start the farm.One of them can approve this request by reacting 👍 to it or to this comment.This request was foraa9af40, and the PR has changed since (8449fbf), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.Code-only review of
aa9af402ee; informational findings, with final approval left to another reviewer.Rechecked the merge of main
71b1edd8since the previous review. The native-key production patch and its fixture are unchanged; the occlusion test retains the updated constructor check alongside main’s newer query-copy coverage. Snapshot ownership, bounded slots, graphics/compute callers and report integration still show no new defect.The description now records the post-merge Windows suite comparison and retains T-FVS2. The existing Linux request is awaiting a BigBean’s authorization; no new request is needed from this review. That remaining validation is unchanged. No tests, builds or game runs performed.
Each draw-statistics query copies the program's four native stage keys when it is recorded, and the report adds
coderows for those tuples. I read the change on headaa9af402. This stays a comment. The description's own Must be tested (a capture during play, T-FVS2) has not been posted, so I am not approving it.The copy happens while the program is still in hand, into the query slot, and the report groups those stored keys. It does not look the program up again. Graphics, mesh and compute all go through that constructor. The occlusion query still begins after the statistics query. The fixture checks that a later change to the program does not rewrite an earlier slot, that two tuples of one program stay separate, and that a full slot list does not begin another query.
The Windows run created
draw_stats.nowbefore the game started, so the onecoderow is a boot frame. The farm request on this head does the same thing: the trigger is already there at start, and it asks for no crash and a frame-time comparison. T-FVS2 asks for the trigger created during play, withcoderows for graphics and compute. A farm run of the posted request would not close that. The patch itself is the one bibiburl rechecked on this head.@TrashPanda, the check this PR asked for (T-FVS2), with the trigger created during play, run on Windows rather than Linux, on this PR's two commits over main
0cab3548(renderer only), Ryzen 7 5700X3D + RX 9070 XT, AMD 26.11.1, Hyrule, render thread on:RX_VK_DRAW_STATS=<folder>set at start, and<folder>/draw_stats.nowcreated 30 s after the load, during play: the renderer loggedmeasuring frame 6647, then wrote one report for it (1,969 queries of 368 programs, query result VK_SUCCESS).coderows: every one of the 368 programs has its native key row, with no orphans either way. The first key is non-zero in all of them; fragment keys are non-zero for every draw and mesh program and zero for compute, as expected. The scene does dispatch compute: 130 dispatches of 65 programs in that frame.You were right that the farm request (trigger at start) wouldn't close this one. The description's Testing section now has this run; Linux stays open for the same capture (T-FVS2).
Correction to my comment above: the renderer that ran was not this PR alone. The pack tool takes one renderer per runtime, so it was main
0cab3548plus this PR's two commits and #239's four (c3bba234...). #239's code only runs withRX_VK_LOG_PROGRAM_LIFE, which this run did not set, so the result stands; the description now says so. A this-PR-only renderer was built (2141a54a...) but not run.Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).
@HumanBean, checked: both boxes match. The in-game run is the T-FVS2 check from 2026-11-17 (trigger created during play), and the cost is the about 1 MiB of query metadata named in Risks.
Verdict: Request changes. Recording the shader key with each query is sound in source. The new fixture needs the shared source-cut helper, and the required Linux during-play capture is still open.
Reviewed
aa9af402ee26against71b1edd89bfd. Read the draw-statistics and occlusion changes, both fixtures and the measurement records. Checked query-slot ownership, capacity, native key population and successful report generation. Code review only. No changes pushed.Blocking
tests/test_draw_stats_codes.py:13has a private first-match block extractor. Use the sharedtests/srccut.pyhelper required for new source-cut tests, so duplicate markers fail explicitly. Keep the suite-selected compiler and the snapshot and grouping assertions.coderows, mesh rows where present, and no errors. The pending farm request creates the trigger before launch. It does not exercise that scenario. The reported Windows capture did and found matching rows for all 368 programs. Its renderer also included PR 239, whose clock flag was unset.Please make the memory note precise. The 32,768 slots reserve 1 MiB more static storage even with the switch unset. Source alone does not establish the resident-memory or commit-charge increase. New slot writes and the temporary grouping map are limited to capture and reporting. The suite report compares 25 failures against the same baseline failures. Please record their names and keep the Linux build checkbox aligned with the WSL object and fixture coverage actually reported.
The indexed-quad fix touches separate hunks. No merge-order dependency found.
@ -6041,6 +6041,7 @@ struct StatsMeta {uint8_t dispatch; // (a compute dispatch: its grid, or its indirect arguments as above)uint32_t grid[3];uint64_t args_vkbuf, args_vkoff; // (the Vulkan buffer and offset the arguments were read from)uint64_t codes[4]{}; // native vertex/mesh/compute, fragment, task, header-only keys at recording timePlease distinguish an extra 1 MiB of static slot storage from resident memory, which was not measured. The new per-query writes and grouping work are capture-only.
@ -0,0 +10,4 @@def block(text, marker):start = text.index(marker)Please use tests/srccut.py here. The current first-match extractor silently accepts duplicate markers. The suite-selected compiler and behavioral assertions can stay.
@futondestroyer, on review 1753, point by point. Pushed
8449fbf5(a fast-forward onaa9af402, no force-push, main not merged again: it still merges cleanly).tests/test_draw_stats_codes.py:13, the private extractor: fixed in8449fbf5. The fixture now importsblockfromtests/srccut.py, and the private counter is gone. The suite's compiler (RUN_ALL_ARGS = ["--cxx", "{cxx}"]) and every snapshot and grouping assertion are unchanged. Run on Windows, llvm-mingw 20261104:SRCCUT_CHECK_NAIVE=1it cuts the same text as the old counter;vk_draw.cppwith a secondstruct StatsQuery {it stops with srccut's "more than once (lines 6488 and 10938)" message;vk_draw.cppit still fails (no native-key report).A gpt-6.2-sol review of the commit found no defect.
The memory note (
vk_draw.cpp:5793): Risks now separates the two:stats_metagains 1 MiB of static storage, also with the switch unset.The suite's failure names: rerun at
8449fbf5and on clean main71b1edd8(Windows, llvm-mingw, switches cleared). This branch: 610 passed, 23 failed, 45 skipped. Main: 609 / 23 / 45. The failure lists are identical:test_audio_output_devices.py,test_auto_handheld.py,test_bug_report_defaults.py,test_crash_dialog.py,test_crt_options.py,test_dlss_feature_size.py,test_failed_compile_keeps_objects.py,test_fsr_uniform_ownership.py,test_guest_imported.py,test_import_reach.py,test_job_queue.py,test_linux_preflight.py,test_longshot_ctl.py,test_make_game_cache.py,test_missing_nup.py,test_pads_after_menu.py,test_parallel_init_order.py,test_pending_guest_import.py,test_replay_write_order.py,test_run_all_changed.py,test_tested_configurations.py,test_vk_occlusion_queries.py,test_walk_key.py. Testing names them all. The earlier 25 ataa9af402were not recorded by name, and Testing says so.The Linux build checkbox: the box now says exactly what was done. On Windows the renderer was built and run. On Linux,
vk_draw.cppwas compiled to an object and the fixture was run under WSL; there was no full Linux build or link. The status line says the same.T-FVS2, the Linux capture during play: still open, as you say. Must be tested now says:
coderows, mesh rows where present, no errors) was asked of a tester with a Linux PC in #agent-updates today at 15:47Z.Testing gets the result when it comes back.
@Beanstalk linux, any GPU: with RX_VK_DRAW_STATS set to a folder and draw_stats.now created in it before the game starts, 60 s in Hyrule Field. Fail on a crash or error lines in the log; compare frame times with main. (The same request as before, for the new commit
8449fbf5: the test now uses tests/srccut.py. The capture with the trigger created during play, T-FVS2, is asked of a Linux tester by hand.)@klimovich008 only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.Re-review at head
8449fbf5, against the points of the earlier request for changes onaa9af402. Code review only; nothing run.The earlier points, at this head
tests/test_draw_stats_codes.pynow importsblockfromtests/srccut.py(unique markers by default), and the private counter is gone. Resolved.stats_metastorage (also with the switch unset) from resident memory and commit charge, which it says were not measured. Resolved. From the code: with the switch unset nothing ever writes those pages, so on Linux they stay demand-zero and are not resident.coderow for each) is good evidence for the code. The Linux run is still the description's own Must be tested, and the farm request on this head creates the trigger before the start, so it can't close it.What I checked in the code (no new defect)
StatsQuerynow takesconst Program&instead ofp.key, andbegin()returns on!stats_dir() || !stats_poolbefore it touches a slot. The key copy happens only for a slot claimed in the measured frame.stats_used.fetch_add.Program::codesis set once, when the program is made (vk_shader.cpp), and read the same way, without a lock, on the existing draw path (vk_draw.cpp:1957). The reporter reads the slots understats_mu, 8 frames later, aftervkGetQueryPoolResults(..., WAIT_BIT). That is the same ordering every otherStatsMetafield already relies on.min(stats_used, kStatsQueries). The fixture covers the overflow case.RX_VK_DRAW_STATSalready has its row on main, so nothing is needed.StatsMeta, its initializer, both call sites andtest_vk_occlusion_queries.py's assertion are unchanged from the fork point.Measurements: this is a diagnostic with no speed claim. The A/B runs the switch on in both arms (one measured frame at boot, 3 alternating pairs). The medians are 63.09 vs 63.45 fps with a spread of about 4 fps, so there is no gain and no loss, as the description says. The path players run (switch unset) was not measured, but from the code it adds no per-draw work.
Verdict: from the code and the evidence it is ready apart from the Linux capture during play (T-FVS2). It stays a comment until that run is posted. The head's CI is still waiting on its required conditions. One nit is inline.
@ -6284,6 +6298,7 @@ void stats_tick() {(unsigned long long)x.fs, k == 0 ? "RAN, NO PRIMITIVES" : k == 1 ? "primitives, no fragments" : k == 2 ? "no shader work" : "",x.indirect ? (" (indirect)" + x.args).c_str() : "");}if (res == VK_SUCCESS) stats_code_keys(f, n);Nit: the native keys are recorded on the CPU and don't depend on the query results. Writing the
coderows even whenres != VK_SUCCESS(with the result already in the header) would keep the program identities in exactly the report where the counts are missing. Take it or leave it.