WIP: perf(vk): resolved texture handles in a flat table by era (RX_VK_TEX_HIT_FLAT) #2003
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2003
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/vk-tex-hit-flat"
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
texture_view_of(gpu/vk/vk_draw.cpp) keeps what each texture handle resolved to (view, texture, level) by slot, view type, use and storage format. Main keeps them inhandle_hits, aFlatMap(#231) whose entries each hold their own destroy generation. This adds the branch's table beside it, behind a switch, on by default (RX_VK_TEX_HIT_FLAT=0gives main's map), so both can be compared in one build: one array of 40-byte places (HitSlot) found by the key's hash, the next place on a collision, at most half full; the destroy generation kept once for the table as an era (a place resolved in an older era is stale, as the generation only goes up); the texture touched once a submission as before. A new key is searched once: the place the search gave is used for it after the resolution unless the resolution changed the table. The bound is the map's 65,536 keys, checked where the map's is, at a submission's first recording: there a full table starts over and gives its places back; until then a new key past the bound is resolved and not kept, the keys kept serving on (nothing is cleared inside a recording). Growth whose memory is refused leaves the table as it was and the view is returned uncached. A miss is the same resolution as ever. The expected result is a cheaper lookup for every texture binding; it is not measured.A behaviour fix of its own, both ways (this changes the map's way too): a view refused for want of memory this frame (the texture's
view_failed_frame) is not kept, so it is made again from the next frame on, ascached_image_viewretries it, instead of the dummy standing until the slot or the destroy generation moves. The frame it is compared with is read once before the resolution, so a refusal is not kept either when another thread's present moves the frame on meanwhile. The lookups are counted only withRX_VK_LOG_HITS=1, the same counts both ways; its 200,000-binding line is logged both ways, and with the table also a frame-log line (vk: a frame: ... texture handles kept as resolved, every 120 presents), whose last figure is the times a thread's table found its places stale (one count a table, not the generation's own moves). Off, nothing is counted.Switch:
RX_VK_TEX_HIT_FLAT(kind kill, on by default as the change proposes, docs/dev/standards.md, Switches; its row ingpu/vk/switches.def). Unset,1or any value but those below: the flat table.0(or an empty value,false,offorno, in any case, spaces around it not counted): main's map, and only its bound is kept at a submission's start. It is read once, at its first use (soHOS_ABcannot alternate it); its first read logs what it chose.From 2816697a on
exp/x86-asm-sync.Read first: the comment above
HitSlot,HitTable,resolved_handles_new_submissionandtexture_view_ofingpu/vk/vk_draw.cpp.Testing
Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head
09f185c9on main @9dd41326(the branch's earlier commits unchanged by the rebase,git range-diff), in jobsdyl-2003(light, two checks at once) anddyh-2003(build) of the PC's job queue, each check in a hidden console of its own, the Vulkan headers from the builder's CPM cache (RX_CPM):tests/run_all.py --strict --exact:tests/test_tex_hit_flat.py(the table against a model of the map's rules over random keys, slot re-registrations, generation moves (also inside a resolution), a resolution that puts another key first, epochs with the bound kept at a submission's start, tiny and real bounds and an era wrap; then the bound and memory refused for more places, case by case; the switch's reader in fresh processes: unset and1,onand another value on,0,off,false,no, empty and spaces off, twice each, set to the other answer after its first read with the setter's result checked; itskillrow),tests/test_flat_map.py(the realtexture_view_ofwithRX_VK_TEX_HIT_FLATunset (the table),0(the map) and1against a std::unordered_map reference, every stub call compared, the destroy generation moved inside some resolutions;RX_VK_LOG_HITSunset counts nothing, set logs the 200,000-binding line both ways; a view refused for want of memory is not kept, also when the frame moves on between the refusal andtexture_view_of's look at it),tests/test_handle_lookup.py,tests/test_switch_table.py: pass.ddfa3fda(the earlier code with these checks):test_flat_map.pyfails (std::unordered_map: a view refused as the frame moved on was kept) andtest_tex_hit_flat.pyfails (nokillrow); at the head both pass.tests/test_recording_admission.py,tests/test_draw_stream_visibility.pyandtests/test_fsr_uniform_ownership.py(the fixtures whosedraw_begin_recordingstub this PR changes) fail at the head and at the test commit; bothtest_draw_stream_visibility.pyandtest_fsr_uniform_ownership.pyfail on main @9dd41326too, the same way (jobdyh-2003);test_recording_admission.py(worker slot ownership, the parallel case that fails now and then on main as well, 3 of 5 runs onf1f2dc5bin the earlier round's job fb-2003-3) passed at the head in the--changedrun below.gpu/vk/vk_draw.cppcompiled (no object) with the game build's own command for it, from a local build's compile_commands.json: no error.tests/run_all.py --changed origin/main,RX_CPMset; jobdyh-2003, build, 8 at once): 158 passed, 18 failed, 6 skipped (Linux only). Each failure fails on main @9dd41326too, the same way, run in the same job:tests/test_crash_dialog.py,tests/test_dev_ab.py,tests/test_dev_packs.py,tests/test_device_lost_exit.py,tests/test_draw_binds.py,tests/test_draw_stream_visibility.py,tests/test_frame_overlap.py,tests/test_fsr_uniform_ownership.py,tests/test_linux_pressure.py,tests/test_mesh_conv.py,tests/test_pipeline_play_cache.py,tests/test_prepare_cache_save.py,tests/test_present_queue_default.py,tests/test_recorder_own_idle.py,tests/test_sampler_admission.py,tests/test_target_reuse_memory.py,tests/test_upscaler_rows.py,tests/test_vk_occlusion_queries.py. None stopped for want of the Vulkan headers.tests/test_vbytes.pyis not among them and was not run.It has NOT run in the game on this PC yet.
Still to test:
9dd41326, this PR unset (the table, as it ships) and this PR withRX_VK_TEX_HIT_FLAT=0(the map), each warmed a minute in the scene first, then interleaved (main, =0, unset, unset, =0, main), two runs each, withRX_VK_PROF_FINE=1: the replay's CPU time a frame (vk: a frame's replay time (ms), its texture lookups part, and thetexturespart ofvk: a frame (fine): ms:), beside FPS and p99, expecting the same picture all three ways, =0 as main, and unset the texture lookups' time lower than =0's beyond the spread; then one run each withRX_VK_LOG_HITS=1, the log'stexture handles kept as resolvedline read for its hits (by hand)RX_VK_TEX_HIT_FLAT=0, warmed, in ABBA order, expecting the same picture every way and no crash or validation error, with the replay's CPU time (RX_VK_PROF_FINE=1, its textures line) and RAM beside p99 (by hand or on the farm, not run yet)tests/test_tex_hit_flat.py,tests/test_handle_lookup.py,tests/test_flat_map.pywith--cxx g++and--cxx clang++, expecting PASS (by hand)Measurements
Verdict: not measured in play yet: no micro-benchmark of the table and no run in the game on this PC yet; the in-game A/B is in Still to test.
RX_VK_TEX_HIT_FLATships on (kind kill,0gives main's map), the value this change proposes (docs/dev/standards.md, Switches); it goes off, or the change is dropped, if that A/B goes against it.Risks
Unset (the default) it is the table;
RX_VK_TEX_HIT_FLAT=0is main's map. Both ways two things change: a view refused for want of memory is made again from the next frame on instead of being kept as the dummy, and the lookups are counted only withRX_VK_LOG_HITS=1. With the table: a stale place taken as good would show another texture's view, or a freed one (a crash): the era stands for the destroy generation as the map's per-entry generation did, and the tests check the table against the map's rules and run the realtexture_view_ofboth ways against the map's. The table costs memory: up to 131,072 places of 40 bytes on each thread that resolves textures (about 5 MB a thread at the bound), given back when it starts over at a submission's start; below the bound it keeps its size, as the map does. A frame that meets more than 65,536 keys resolves the new ones again until the next submission. A thread that resolves handles but never runsdraw_begin_recordingnever starts its table over: at the bound it would keep no new key for good (each resolved again at every lookup, a cost in time only), where the map grows on (the comment atresolved_handles_new_submissionsays so). The renderer is compiled again after updating.Overlap: #1232 (jcabarca's, not a draft) also changes
texture_view_ofingpu/vk/vk_draw.cpp; the two conflict there. #1232 goes first; this PR rebases onto it.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). Not yet: only the checks in Testing ran.main, or Measurements says why there is nothing to measure. Not yet (Measurements).third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def. Its row is in; it ships on, as the change proposes (docs/dev/standards.md, Switches), not measured yet.tests/that reads changed source is updated, not weakened.vk_draw.cppcompiled with the game build's command (Testing); no full build.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Possibly related, for context:
Recommendation: Request changes. The default path adds a shared counter update to every lookup and can clear 5 MiB of cache slots in the middle of recording a draw. It also caches transient image-view failures past the intended retry frame, and the reported tests never execute the flat branch of texture_view_of.
Adds a smaller cache entry for resolved Vulkan texture handles and keeps main's FlatMap as a fallback. The intended gain is cheaper descriptor building. The new path adds another probing implementation, always-on instrumentation, and a cache that retains its peak allocation until the replay thread exits.
@fixwill do (12)gpu/vk/vk_draw.cpp:3830: A transient vkCreateImageView allocation failure is cached as a valid null result until the slot version or destroy generation changes. (more on the line)gpu/vk/vk_draw.cpp:3772: Use RX_VK_LOG_HITS to guard lookup counters and bulk reporting. The existing replay lock also serializes the current writers and reporter, so counters kept under that lock can use ordinary increments.gpu/vk/vk_draw.cpp:3668: Skip insertion of new keys at the cap and defer the reset to the next submission boundary. Keep serving existing entries until then.gpu/vk/vk_draw.cpp:3629: Release oversized backing storage on a cap reset or after sustained low occupancy, and retain small tables for reuse.gpu/vk/vk_draw.cpp:3654: An allocation failure in the optional cache can escape replay after the texture has already resolved. (more on the line)tests/test_tex_hit_flat.py:241: The fixture runs a hand-written copy of the hit and touch logic. (more on the line)gpu/vk/vk_draw.cpp:3667: A new key repeats the same unsuccessful probe three times when the table can accept it without growing or clearing. (more on the line)gpu/vk/vk_draw.cpp:3781: RX_VK_LOG_HITS=1 no longer produces its documented 200,000-binding diagnostic in the default configuration. (more on the line)gpu/vk/vk_draw.cpp:3709: The log labels observations by individual tables as moves of the global destroy generation. (more on the line)gpu/vk/vk_draw.cpp:6224: An on-mode recording still constructs the fallback FlatMap and registers it for TLS cleanup even if that thread never looks up a texture. Guard this maintenance with the selected implementation and update the source check to allow the guard.gpu/vk/switches.def:696: The row says any other value enables the table, but an explicitly empty or whitespace-only value disables it. (more on the line)tests/test_flat_map.py:273: When the changed check is invoked directly, it ignores CXX and the configured llvm-mingw directory. A Windows builder with its compiler outside PATH gets a skip even when CXX points to the correct compiler. Use the same compiler selection as the new check or share the lookup.For the author (4) (a run, a measurement or a decision)
gpu/vk/vk_draw.cpp:3772: The default path performs diagnostics in every timed lookup while main's lookup counters default off. (more on the line)gpu/vk/vk_draw.cpp:3668: The first new key after the table fills clears every slot inside an active recording. (more on the line)gpu/vk/vk_draw.cpp:3629: A replay thread keeps the largest table it ever needed, including after a saturated area gives way to a light scene. (more on the line)Checks: Still running:
CI / Conventional Commit title (pull_request),CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request),CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request),CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request),CI / Workflow lint (actionlint) (pull_request),CI / Website build and checks (pull_request),Guide screenshots / Guide images and local UI source review (pull_request),Third-party parts / As their notes say (pull_request),Third-party parts / The same as upstream (pull_request),PR description / Description follows the template (pull_request_target).More: does it help, other systems, switches, what was read
Does it help: Unproven. The PR reports 158 passing Windows source checks and 18 failures also seen on base
75317e1f. There are no game runs, lookup timings, frame-time distributions, or RAM comparisons for head9fd4c4b4.Other systems: Both paths feed sampled and storage descriptors for graphics and compute, as well as upscaler and frame-generation dispatches. The changed code is shared across Windows and Linux, GPU vendors, and Steam Deck. Replay holds replay_mu around lookup and frame reporting, and the slot versions retain their existing atomic publication order. Texture retirement, queue ordering, and descriptor reuse still use the same generation source. The table itself consumes host RAM. Its effect on Vulkan work, frame pacing, and shared-memory systems still needs in-game verification. The diff leaves saves, audio, input, the renderer API, and shader generation untouched.
Switches: RX_VK_TEX_HIT_FLAT is a developer kill switch, on when unset, read once and fixed for the process. Its row is present. Main's map is selected by 0, false, off, no, or an empty value. The on default is suitable for gathering WIP evidence and has no shipping measurements yet. RX_VK_LOG_HITS still defaults off, but its existing output only works with the flat table disabled.
Reviewed:
9fd4c4b46eagainst75317e1f31: Read all five diffs, the full three Python tests, the complete changed C++ sections, and the switch row and its neighbors. Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, and the developer standards. Read the relevant FlatMap, TLS ownership, replay locking, slot publication, image-view retry, descriptor and upscaler callers, and test-runner sections. Skimmed unrelated parts of vk_draw.cpp and switches.def and the referenced architecture and switch docs. The supplied Testing summary is the available run record. The named logs and sibling Tooling checkout were unavailable locally. There are no changed translations or generated files.; nothing run (a code review).Checked and fine:
Testing: Read-only review. The author reports that the three targeted checks passed on Windows with llvm-mingw. The 176 changed-source checks had 18 failures also seen on main. Full renderer builds, gameplay and Tier 1 runs, the complete test suite, and CI results are outstanding.
Overlaps and merge order: The FlatMap work from #231 is already in the base. No other overlap is visible in the supplied material or local history.
Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.
@ -693,6 +693,7 @@ SW(RX_VK_TEX_AHEAD_MS, tune, float, "12 ms", "<n>: the time in ms a light frameSW(RX_VK_TEX_CAPTURE, kill, bool, "on, when the capture is on", "0 keeps the storage of textures uploaded from guest memory out of the submit-time capture.")SW(RX_VK_TEX_CAPTURE_MAX_MB, tune, int, "2048 MB, in effect any size", "Sets the largest uploaded texture whose storage joins the submit-time memory capture; it was 8 MB before.")SW(RX_VK_TEX_CAPTURE_OFF_FILE, diag, string, "not set: uploads read the captured copies", "A path: while that file exists, texture uploads read live guest memory as before, for A/B runs in one session.")SW(RX_VK_TEX_HIT_FLAT, kill, bool, "on: texture_view_of keeps the resolved texture handles in a flat table of its own, the destroy generation kept once for the table as an era", "=0 (or false, off, no): the handle_hits map, as before; any other value is on. Read once, at its first use (HOS_AB cannot alternate it). The views found are the same either way (tests/test_tex_hit_flat.py); the frame log's `vk: a frame: ... texture handles kept as resolved` line counts its lookups.")L11 (minor): The row says any other value enables the table, but an explicitly empty or whitespace-only value disables it. Describe the shared parser's behavior in the row and PR summary. Add switch fixture cases for
noand whitespace, which the current matrix omits.@ -3591,0 +3626,4 @@static size_t home(uint64_t key, size_t mask) {return (size_t)((key * 0x9E3779B97F4A7C15ull) >> 32) & mask;}void wipe() {L4: A replay thread keeps the largest table it ever needed, including after a saturated area gives way to a light scene. Main's cap-triggered clear releases the backing array. Compare retained RAM after a heavy-to-light transition, including on Steam Deck and with threaded rendering off.
@ -3591,0 +3651,4 @@}}void grow() {std::vector<HitSlot> old(slots.empty() ? (size_t)256 : slots.size() * 2);L5: An allocation failure in the optional cache can escape replay after the texture has already resolved. For example, growth from 32,768 to 32,769 keys asks for a fresh 5 MiB block while main still has room in its existing table. On allocation failure, keep the old table intact and return the resolved view uncached. Apply the same fallback to first-use table allocation.
@ -3591,0 +3664,4 @@/// The key's place for a resolution just made: the one it had, or a new one, taken (its key and this era set; the caller/// fills in the rest). At `most` keys the table starts over first. Places are never more than half taken, so a search endsHitSlot& put(uint64_t key) {if (HitSlot* s = find(key)) return *s;L7 (minor): A new key repeats the same unsuccessful probe three times when the table can accept it without growing or clearing. The caller searches, put calls find again, and insertion walks the collision chain again. Carry the matched or first empty slot across resolution and reprobe only when growth or reset invalidates it. The current source-count check misses both probes inside put.
@ -3591,0 +3665,4 @@/// fills in the rest). At `most` keys the table starts over first. Places are never more than half taken, so a search endsHitSlot& put(uint64_t key) {if (HitSlot* s = find(key)) return *s;if (used >= most) wipe();L3: The first new key after the table fills clears every slot inside an active recording. For example, if the table starts a recording with 65,536 entries, the next new binding discards even the still-valid entries that later draws in that recording need. Main checks its cap at a recording boundary. Measure the cap-crossing frame and the following frames.
@ -3591,0 +3706,4 @@double a[7];for (int i = 0; i < 7; i++) a[i] = (now[i] - last[i]) / frames, last[i] = now[i];logf("vk: a frame: %.0f texture handles kept as resolved (%.0f of them touched for their submission, %.0f by the whole check), ""%.0f resolved again (%.0f first met, %.0f whose slot was registered anew, %.0f after the destroy generation moved); "L9 (minor): The log labels observations by individual tables as moves of the global destroy generation. One table observing a jump from 10 to 13 counts once, and two populated tables can each count the same move. Label the number as table invalidations or report the global generation delta separately.
@ -3648,0 +3769,4 @@}h->epoch = texture_epoch();}st_bump(st_flat_hits);L2: The default path performs diagnostics in every timed lookup while main's lookup counters default off. A texture-heavy frame pays for these updates even when nobody requested the counts. Gate the stats and time base, flat off, and flat on with diagnostics disabled on all three sides. Collect hit breakdowns separately with diagnostics enabled.
@ -3648,0 +3778,4 @@else if (h->version != version) st_bump(st_flat_ver);else st_bump(st_flat_gen);} else {static const bool log_hits = env_on("RX_VK_LOG_HITS");L8 (minor): RX_VK_LOG_HITS=1 no longer produces its documented 200,000-binding diagnostic in the default configuration. Keep that diagnostic available on both paths or explicitly document the replacement and the switch combination needed for the old output.
@ -3678,1 +3828,3 @@handle_hits()[key] = {view, tex, dgen, level, version, texture_epoch(), use == ViewUse::Sample || use == ViewUse::Storage};if (flat) { // (its place asked for here, not kept from the search above: this is where the table grows or starts over)HitSlot& h = flat_hits().put(key);h.view = view, h.tex = tex, h.version = version, h.epoch = texture_epoch(), h.era = era, h.level = level;L1: A transient vkCreateImageView allocation failure is cached as a valid null result until the slot version or destroy generation changes. A texture that remains registered can keep sampling the dummy after memory recovers, because the handle cache bypasses cached_image_view's next-frame retry. The fallback already has this gap. Preserve negative caching for permanent misses and give transient failures a frame-limited entry or skip caching them in the shared resolution path.
@ -0,0 +238,4 @@a.cxx = compiler(a.cxx)src = (ROOT / "gpu" / "vk" / "vk_draw.cpp").read_text(encoding="utf-8")# ---- how texture_view_of uses it ----L6: The fixture runs a hand-written copy of the hit and touch logic. The existing executable fixture forces the map branch. A mistake such as clearing a cached storage view just before the hit return can leave both fixtures green. Extend the executable fixture to run the actual flat and map branches with controlled initial switch values. Compare the view, texture, level and touch calls, including a generation bump during resolution.
WIP: perf(vk): resolved texture handles in a flat table by era (RX_VK_TEX_HIT_FLAT, on)to WIP: perf(vk): resolved texture handles in a flat table by era (RX_VK_TEX_HIT_FLAT, off by default)9fd4c4b46e76ab28dd4eThank you for the review (#issuecomment-63405). Pushed
76ab28dd, rebased on main @b62932a9(the branch's own commit unchanged by the rebase,git range-diff); test commit5bed75f2(its checks fail on the branch's earlier code: job fb-2003-6, as c4f200e3), fix76ab28dd. The checks ran at c17363c2 on main @7c23d2be(job fb-2003-8);b62932a9adds only pipeline lists underassets/. All checks named below ran in those jobs on this PC; nothing has run in the game.Default: there is no measurement in play, so
RX_VK_TEX_HIT_FLATis now off by default (kind attempt): unset is main's map. The in-game A/B that could turn it on is in Still to test.76ab28ddin the shared resolution path, both ways: a view refused for want of memory this frame (the texture'sview_failed_frame) is not kept, so it is made again from the next frame on ascached_image_viewretries it; permanent misses are still kept.tests/test_flat_map.pyrefuses one view in the realtexture_view_ofand checks it is resolved again that frame and has a view the next, on the map, the flat table and the std::unordered_map reference.76ab28dd: every count is behindRX_VK_LOG_HITS, both ways, the same counts with the map and the table; off, nothing is counted (test_flat_map.pyrunstexture_view_ofwith it unset and set and checks the counts;test_handle_lookup.pychecks no count is outside the switch). I kept them relaxed atomics without a locked add rather than plain integers: they cost nothing with the switch off and stay free of a data race should two recorders count at once. The gated three-way timing is pending (Still to test).76ab28ddas you suggest: at its boundputkeeps no new key (resolved and returned uncached) and the others keep serving; the table starts over only at a submission's first recording, where the map's bound is checked (resolved_handles_new_submission).test_tex_hit_flat.pychecks it case by case and in its model runs (never started over inside a recording). The cap-crossing frames are not measured (Still to test).76ab28ddfor the bound: starting over at a submission's start gives the places back (the first growth makes 256 again); below the bound it keeps its size, as the map does. No sustained-low-occupancy shrink. The RAM after a heavy-to-light change is pending (Still to test, with the heavy scene).76ab28dd:growcatches it and leaves the table as it was,putreturns null and the view is returned uncached, the first places too.test_tex_hit_flat.pyrefuses the memory (its ownoperator new) for a first and a later growth.5bed75f2:test_flat_map.pynow runs the realtexture_view_ofwithRX_VK_TEX_HIT_FLATunset, 0 and 1 against the std::unordered_map reference (forced to the map), comparing view, texture, level, every stub call in order (touches included) and the destroy generation, whichtexture_getnow moves inside some resolutions.76ab28dd:seekgives the key's place or the empty place its search ends at, andputtakes it unless the table's stamp moved during the resolution (a put, a growth or a start-over). The model run puts another key in one resolution in five, so a stale place is searched again;test_handle_lookup.pychecks one seek and one put a lookup.76ab28dd: logged both ways (test_flat_map.pychecks the table logs it as often as the map); the frame-log line is the table's addition, withRX_VK_LOG_HITS=1. Both rows say so.76ab28dd: the figure is now "a thread's table found its places stale ... times a frame", and the comment says it is one count a table, not the generation's moves.76ab28dd:draw_begin_recordingcallsresolved_handles_new_submission, which keeps the bound of the way in use only; the three fixtures that cutdraw_begin_recordingstub it, andtest_tex_hit_flat.pychecks neither table is touched there directly.76ab28dd(row, description) and5bed75f2: the switch's fixture hasno, empty and spaces among the off values, and checks the setter's result and the value read back.test_flat_map.py's compiler: fixed in5bed75f2: it usestest_tex_hit_flat.py's lookup (--cxx,CXX, the configured llvm-mingw, then PATH); it ran with no compiler on PATH and found llvm-mingw throughLONGSHOT_MINGW.test_tex_hit_flat.pyalso no longer declares{cxx}to the runner, whose lookup skips the configured llvm-mingw (the same as #2005's L1).@Beanstalk This adds RX_VK_TEX_HIT_FLAT, off by default: with RX_VK_TEX_HIT_FLAT=1 the renderer's texture handle lookups for every draw and dispatch go through a new resolved-handle table instead of main's (gpu/vk/vk_draw.cpp); unset, main's way. It has not run in the game on these PCs yet. Please play Kokiri Forest for three minutes after a minute's warm-up, the PR against main on the same PC, on the PR's side with RX_VK_TEX_HIT_FLAT=1 and with it unset, with a picture compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash and no validation error; set, frame time p99 equal to unset or better; unset, as main's.
@siantm 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 for76ab28d, and the PR has changed since (09f185c), so a 👍 no longer approves it. Comment@Beanstalkagain to ask for the new commit.Verdict: Request changes. The code now answers every BeanBot point and I found no bug in the table. But the switch was turned off because it is unmeasured, which standards rule out ("ships at that value from the branch's first push ... never off just because it is new or unmeasured"). As pushed, testers, the farm and the PR's own runs play main's map unless they set it by hand.
For a player it is meant to make every texture and storage-image binding a cheaper lookup (one 40-byte place in a flat table instead of a FlatMap entry with its own destroy generation). That is a CPU gain in descriptor building, not measured yet. Unset, it is main's way plus one real fix both ways: a view refused for want of memory is no longer kept as the dummy.
Reviewed:
76ab28ddagainstb62932a9(the merge base with main; it merges cleanly into current main). I read in full:gpu/vk/vk_draw.cpp(HitSlot/HitTable,tex_hit_flat,resolved_handles_new_submission, the counters,tex_hits_report, all oftexture_view_of,draw_begin_recording's change), theswitches.defrows, the threetests/*_test.cppstubs,tests/test_tex_hit_flat.py, and thetest_flat_map.pyandtest_handle_lookup.pydiffs. Also read:cached_image_viewandtexture_viewinvk_texture.cpp(for L1) andenv_value_offinlongshot_env.h(for L11). I checked each point against BeanBot's review at9fd4c4b4, which is still reachable through #2058. Nothing run (a code review).Fixed in this review: nothing.
Checked and fine:
againholds back from both ways only a viewcached_image_viewrefused this frame (view_failed_frame == frame_no). Permanent misses are still kept.texture_viewpasses the null through rather than swapping in a dummy.test_flat_map.py'srefusedcase fails if the!againguard is undone, because the second call would hit with notexture_ofin the trace.st_bumpsits behindlog_hits(the&&short-circuits). Off, nothing is counted in either way.putrefuses a new key atmostand never wipes. A start-over happens only innew_submission, fromdraw_begin_recording.growisnoexceptand catches inside, so the old array is untouched on failure, andputreturns null. The fixture'soperator newchecks both the first growth and a later one.test_flat_map.pynow compiles the realtexture_view_ofwith the table and compares view, texture, level, the stub trace and the destroy generation against the unordered_map reference, with generation moves inside a resolution.seekbefore the resolution.putsearches again only whenstampmoved (a put, a growth or a wipe). An era move without a wrap changes no place, so leavingstampalone there is right.env_value_off(trimmed, any case; empty is off).texture_gettherefore leaves the new place stale, as the map's storeddgendoes. After a wrap, an outer resolution's old era cannot be met as current for another 2^32 moves.samplingworked out fromuseequals what the map stores, becauseuseis in the key.sizeof(HitSlot) == 40. The table holds at most 65,536 keys in 131,072 places (about 5 MB a thread).Blocking (to change before merge)
gpu/vk/switches.def:698:RX_VK_TEX_HIT_FLATshipsattempt/off "until a measurement in play chooses its default". Standards say a switch ships at its intended default from the first push, WIP or not, and goes off only if measurements go against it. (BeanBot's L2 was about the counters; it called the on default fine for WIP evidence.) The farm, testers and your own A/B should run the branch as it would merge. Fix: on by default again, kindkill(0gives main's map), the readerenv_on_or(..., 1), and update the row,test_tex_hit_flat.py'sattemptcheck and default, the description and the @Beanstalk request. If the in-game A/B goes against it, turn it off or drop it then, and say which.Suggestions (the author may take or leave)
gpu/vk/vk_draw.cpp:3872:againreadstexture_frame_no()after the resolution. Ifframe_nomoves on another thread betweencached_image_view's failure and this line, the refused view is kept as null until its slot or the generation moves, which is the L1 gap in a narrow window. Reading the frame once before the resolution and testingtex->view_failed_frame >= thatcloses it.draw_begin_recording(if an upscaler or present-side call ever runs off the recording thread) never start their table over. At 65,536 keys they would stop keeping new ones for good, where the map grows. This only costs time, and a handful of keys will never reach the bound, but a comment atresolved_handles_new_submissionwould say so.Questions
Testing: the author's checks on Windows (llvm-mingw) pass:
test_tex_hit_flat.py,test_flat_map.py,test_handle_lookup.py,test_switch_table.py. The test commit fails on the earlier code, andvk_draw.cppcompiles with the game's command. Missing, and holding the merge: any run in the game, including the author's own on the RTX 4060 (Kokiri and a heavy/streaming scene, three ways). Also missing: a full Windows and Linux build, Tier 1 hardware, and a measurement. CI is pending. The @Beanstalk request should follow the default change. When it is re-asked, it should add Windows AMD and a heavy or streaming scene (the light Kokiri walk never reaches the 65,536-key bound or a start-over). Its criteria should be the replay's CPU time (RX_VK_PROF_FINE=1, the textures line) and RAM beside p99: a CPU-side lookup saving rarely moves p99 frame time on a GPU-bound or capped run.Overlaps and merge order:
9fd4c4b4, before every fix here. It needs rebasing onto76ab28dd(or later), and its prefetch works only with the table on. This one goes first.texture_view_of's signature (version passed in). That is a textual conflict at the function's head, compatible in meaning; whichever merges second rebases.tests/*_test.cppstubs next to thehandle_hitsstub line this PR replaces. That may be a small textual conflict there; they don't touchtexture_view_of.switches.defis a row conflict with most open PRs.@ -695,6 +695,7 @@ SW(RX_VK_TEX_AHEAD_MS, tune, float, "12 ms", "<n>: the time in ms a light frameSW(RX_VK_TEX_CAPTURE, kill, bool, "on, when the capture is on", "0 keeps the storage of textures uploaded from guest memory out of the submit-time capture.")SW(RX_VK_TEX_CAPTURE_MAX_MB, tune, int, "2048 MB, in effect any size", "Sets the largest uploaded texture whose storage joins the submit-time memory capture; it was 8 MB before.")SW(RX_VK_TEX_CAPTURE_OFF_FILE, diag, string, "not set: uploads read the captured copies", "A path: while that file exists, texture uploads read live guest memory as before, for A/B runs in one session.")SW(RX_VK_TEX_HIT_FLAT, attempt, bool, "off: texture_view_of keeps the resolved texture handles in the handle_hits map", "1 (any value but an empty one, 0, false, off or no, in any case, spaces around it not counted): a flat table of its own, the destroy generation kept once for the table as an era; a thread's table starts over at 65536 keys at a submission's start, its places given back, and keeps no new key past them until then. Not measured in play. Read once, at its first use (HOS_AB cannot alternate it). The views found are the same either way (tests/test_flat_map.py runs texture_view_of both ways); RX_VK_LOG_HITS=1 counts its lookups.")Blocking: this ships off because it is unmeasured, which standards rule out (a switch ships at its intended default from the first push; off only if measurements go against it). On by default again, kind kill, the reader env_on_or(..., 1), and the test, description and @Beanstalk request updated to match.
@ -3680,1 +3870,3 @@handle_hits()[key] = {view, tex, dgen, level, version, texture_epoch(), use == ViewUse::Sample || use == ViewUse::Storage};// (a view not made for want of memory this frame (cached_image_view: the texture's view_failed_frame) is made again from// the next frame on: not kept, either way, or the dummy would stand for it until its slot or the destroy generation moved)const bool again = tex && !view && tex->view_failed_frame == texture_frame_no();Suggestion: texture_frame_no() is read after the resolution. If frame_no moves between cached_image_view's failure and here, the refused view is kept as null again (L1 in a narrow window). Read the frame once before the resolution and test view_failed_frame >= it.
76ab28dd4e09f185c90f@Beanstalk This makes the renderer's texture binding lookups for every draw and dispatch go through a flat resolved-handle table (gpu/vk/vk_draw.cpp), on by default; RX_VK_TEX_HIT_FLAT=0 turns it off (main's map). This head is on main
9dd41326: please compare with main at that merge base. Please play Kokiri Forest for two minutes, then Hyrule Field galloping into Kakariko Village (a heavy, streaming scene), with RX_VK_PROF_FINE=1 on both sides, the PR against main on the same PC, on the PR's side with the switch unset and with RX_VK_TEX_HIT_FLAT=0, with a picture in each scene compared with main's, on Windows with AMD, Linux with NVIDIA, Linux with AMD (RADV) and the Steam Deck. The same picture, no crash or validation error; please report the replay CPU time from the log's textures line and RAM beside frame time p99; unset, p99 equal to main's or better and to the switch off.@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.WIP: perf(vk): resolved texture handles in a flat table by era (RX_VK_TEX_HIT_FLAT, off by default)to WIP: perf(vk): resolved texture handles in a flat table by era (RX_VK_TEX_HIT_FLAT)Thank you for the review (#issuecomment-65681). Pushed
09f185c9, rebased on main @9dd41326(the branch's earlier commits unchanged by the rebase,git range-diff): test commitddfa3fda, fix429ae236, default09f185c9. The checks named below ran in jobdyl-2003of this PC's queue (Windows 11, llvm-mingw clang 23): the PR's own at the head and at the test commit, andvk_draw.cppcompiled with the game build's command; the--changedchecks and their failures on main are in jobdyh-2003, queued, and the description will give them. Nothing has run in the game.switches.def:698): you are right.RX_VK_TEX_HIT_FLATis on by default again, restored per docs/dev/standards.md (Switches), in09f185c9: kindkill, the readerenv_on_or(..., 1),=0(or empty,false,off,no) gives main's map; the row, the log line andRX_VK_LOG_HITS's row match.test_tex_hit_flat.pychecks thekillrow and unset as on;test_flat_map.pyruns unset as the table (ddfa3fda). Still to test now plans=0against unset, with the replay's CPU time and RAM beside p99 and a heavy or streaming scene; if that A/B goes against it the switch goes off or the change is dropped, and the description will say which. The farm request is made again for this head (#issuecomment-65983), with the default on, Windows AMD, Hyrule Field into Kakariko Village and the replay's CPU time and RAM beside p99.vk_draw.cpp:3872(#issuecomment-65680): taken.texture_view_ofnow reads the frame once before the resolution and holds back a refused view whenview_failed_frame >= that frame(429ae236).test_flat_map.py(ddfa3fda) has the refusal move the frame on beforetexture_view_oflooks, as another thread's present can, and checks the next call resolves it again and gets its view, on the map, the table and the reference. At the test commit it fails with the earlier code (std::unordered_map: a view refused as the frame moved on was kept); at the head it passes.draw_begin_recording: the comment atresolved_handles_new_submissionnow says such a thread never starts its table over and, at the bound, keeps no new key for good (each resolved again, a cost in time only) where the map grows on (09f185c9). No code change.09f185c9; its owner has the new head. #2055 and thetests/*_test.cppstub lines: whichever merges second rebases.Description: Risks now says that this conflicts with #1232 in
texture_view_of(gpu/vk/vk_draw.cpp), the overlap BeanBot pointed to (#issuecomment-63304), and that #1232 goes first, this one rebasing onto it. No push.@Beanstalk One correction to my request 65983 above, for its picture point: please take each picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between, and take the main-against-itself picture from the same point. A picture taken during the load's fade-in from black is not comparable: run 70269 on #2156 caught the fade in 3 of 4 starts.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.