Repository navigation
perf(shader): select the record of a T# whose offset the CPU evaluates - #6243
oneandonlydean merged 18 commits into
Conversation
Since boykopovar#757, a T# loaded from a buffer heap at a runtime offset is an image table column, and every capture snapshots the whole heap, up to 65,536 records, even when user data or an SRT read fixes the offset. When the T#'s eight dwords and its offset are runtime values the SRT walker evaluates, the column is now selected: the offset is kept as a descriptor source, the shader indexes entry 0, and the snapshot reads only the record at the evaluated offset, with the heap base moved to that record. The column keeps a table's semantics. An invalid T#, an unmapped record or an offset that carries past 32 bits is poison that faults only when a lane selects it; an offset the walker cannot read faults the table instead of throwing; the record's mode is picked per entry, so no pipeline variant is added; and a dispatch that writes the record faults it as written by its dispatch. Dwords past the heap read zeros, as the scalar loads would, and a record past the key cap is read rather than poisoned. A column stays a whole table when its offset is chosen per lane, or when the shader may write the memory the offset is read from at run time: the buffer it is read from (by V#), or any memory when the read or a write goes through a pointer or a GPU-only descriptor. Samplers are unchanged: an S# the walker evaluates is already a direct sampler. The plan stores the selection, so the disk cache format is 36. Five agc_shader_memory and agc_shader_bindless checks asserted the old planning and now assert the selected record: - "image table SRT key": a key read through the SRT narrowed a 4-key table to records 0 and 2. It now selects record 2 alone, captures no other record, and a changed key moves the capture without changing the module or its disk key. - "image table key union" and "image table late key": two keys of one heap shared one column with two value key domains. Each key now selects its own record, as two one-record tables. - "image table unkeyed access": a read keyed through the SRT shared a whole column with a read keyed per lane. The first now selects its record; the second keeps the whole, unnarrowed table. - "uniform table image": the T# at a user data offset was one key of a full table. It is now the one selected record, and the record the user data does not select is not read. A value key domain only arises for a key the walker evaluates, so it no longer narrows an image column; key buffer domains (keys loaded per lane) still do.
The [image-table] line under APS5_PROFILE_DRAW now splits the skipped narrowings by reason: a value key that cannot be evaluated, a key descriptor that is not a buffer, a key buffer with more positions than APS5_IMAGE_TABLE_KEY_SCAN (with the most positions seen), pending GPU writes over the key buffer, and an unmapped key page. Selected records never narrow, so the line counts them apart.
agc_shader_memory and agc_shader_bindless: an invalid selected T# is poisoned with its words without changing the artifact; a key past the heap selects a null image without reading the heap; an unmapped selected record is Unmapped poison and is not read; a key loaded from a constant buffer at an SRT offset selects its record, and one that cannot be read faults the table instead of throwing; a key loaded from a buffer the shader writes keeps the whole table; a key chosen per lane keeps the table; a record past the 65,536-key cap is selected; and a selected record whose second load carries past 32 bits is OffsetCarry poison while the record past the wrap is read. agc_driver_image_table: a dispatch keyed from a constant buffer at an SRT offset samples three records exactly as their direct bindings do, with one module and one bound image; samples zeros for a key past the table; does not fault for an invalid record under a clear EXEC; reports the invalid record's address, words and reason when it selects it; and faults when it stores over its selected record. agc_shader_disk_cache: a selected column round-trips in the hand-built plan, a fixture plans one and materializes it after a round trip, and a selection past the sources is rejected.
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
… table cannot express its operation An image table cannot store, update atomically or read PCK and BY2/BY4 through its records (boykopovar#757): those operations fault and read zeros. boykopovar#6243 turns a heap T# whose words and record offset the SRT walker evaluates into a selected one-record table, which kept that limitation although such a T# is one known descriptor, as boykopovar#5188's direct images were. PlanTableColumns now binds such a T# directly, for every operation of the shader on it, when any of them is a store, an atomic, a packed or a BY2/BY4 access. A T# keyed per lane, or by a value the walker cannot evaluate, keeps its table and its unsupported-operation fault. The disk format moves to 37 so that plans cached by boykopovar#6243's builds are not reused.
…hose record the CPU evaluates verifySelectedRecordDirectOperations plans image_store, image_atomic_add, image_load_pck and image_load_by2 through a heap T# keyed by an SRT value, which must be bound directly, and through a T# keyed per lane, which must stay a table with its unsupported mark. A T# that is both sampled and stored is bound directly for both, and one that is only sampled still selects its record. RunSelectedStoreTests stores through a record keyed by an SRT value on the GPU and reads the texels back. Before the fix both failed: the T# was planned through an image table, and the store faulted as an unsupported operation.
…directly A sampler column is planned only when DirectSampler cannot evaluate the S#, so no sampler record is ever selected: an S# read from a heap at an offset the SRT walker evaluates is a direct sampler, and one keyed per lane is a sampler table.
…e record A selected record is one map entry for the whole dispatch, so its descriptor index is dynamically uniform. The emitter decorated it NonUniform like any table index whenever the workgroup spans more than one subgroup, and on every graphics stage, which makes drivers scalarize the access. The element index, its access chain, the loaded image and the sampled image of a selected record are no longer decorated; table samplers and tables keyed per lane keep the decoration.
…iform verifySelectedRecordUniformIndex compiles the program keyed by an SRT value and the one keyed per lane with a two-wave workgroup. The selected record's table index carries no NonUniform decoration and the per-lane table's still does. Before the change the selected record's was decorated.
… key may be written CheckTableStores deselects a selected column whose key the dispatch may write: a key read through a pointer or a V# while the shader stores through a pointer, or through a V# the shader writes. The column kept the key domains narrowed from that same key buffer, which the domain rule clears only when the domain's own V# is written, so a shader storing through a pointer still narrowed its whole table on a key it may overwrite. Deselection now clears them as well.
… domain The key loaded from a constant buffer at an SRT offset has a key domain. With a global_store_dword added, the column is deselected and keeps no key domain. Before the fix it kept the domain.
Since 682b07e, an image whose dword 3 wasn't captured is poisoned (OutsideSnapshot). A record selected past the end of its heap reads nothing there, so it was poisoned instead of selecting a null image, and agc_shader_bindless and agc_driver_image_table failed after the merge of main. A scalar buffer load returns zeros past the end of the buffer, so those dwords now count as read zeros, and the dwords the selection reads count as captured. Every other path keeps main's rule.
|
Small doc mismatch: this PR bumps |
The line said FormatVersion 36 while the code is at 37, as main's says 33 against 36. Without the number it no longer goes stale on each bump or conflicts between PRs that bump it.
|
Thanks, @LeandroLP23. The line now reads "The disk cache stores ...", without the number (ca174bc here, merged into #6454 too). |
Main's boykopovar#7101 reads a key buffer's words in one call where this branch names the reason a narrowing is skipped. Keep main's bulk read and count both of its unmapped-page skips as unmapped.
Main's boykopovar#6402 runs image stores through an image table, so a T# keyed per lane keeps its table with a supported image_store and an unsupported mark for the other operations.
Main's boykopovar#7325 adds verifyChainedTableOffset to the image table tests where this branch adds its selected-record tests. Keep both, with main's call after this branch's.
|
Thanks for this. Our review of 9dcf408 passed (the bindless, disk cache and image table tests pass with the change merged onto main), so this is close. It now conflicts with main in One more thing to know: #6488 also uses cache FormatVersion 37. Whichever of the two merges second will need to move to 38, so we may ask for that bump after the rebase. |
1 similar comment
|
Thanks for this. Our review of 9dcf408 passed (the bindless, disk cache and image table tests pass with the change merged onto main), so this is close. It now conflicts with main in One more thing to know: #6488 also uses cache FormatVersion 37. Whichever of the two merges second will need to move to 38, so we may ask for that bump after the rebase. |
|
@oneandonlydean On the cache format: if #6488 lands first, the next merge of |
…image and pair limits Since #6243, each read whose record offset the CPU evaluates gets its own selected table column, so a shader that reads one heap at many such keys plans one image per key. Past 64 keys that is refused with "image resource limit exceeded", or with "sampled image/sampler pair limit exceeded" when each read is sampled twice, where the shader planned within both limits before. After planning the table columns, the tracker now estimates the images and sampled pairs that collecting the program would add, keyed as AddImage and AddSampledPair key them, from the planned column sources and the direct handles. If either is over its limit, it plans again with the columns of one heap unselected, the heap with the most selected columns first, until both fit or no heap is left. Those reads then share one keyed column, as before #6243: the union of their key domains and the largest key. A shader within both limits plans exactly as before, from one planning pass. The estimate counts images exactly. A direct sampler is told apart by its handle's words and whether the sample adjusts, before the canonicalization collecting it applies, so the pair count can only be too high and errs toward merging.
#6243's new head merges main f1af6c5, whose #7325 adds verifyChainedTableOffset next to the selected-record tests this branch carries from #6243. That test reads the record words from the snapshot's shared word list; this branch keeps the words with each table's snapshot, so the merge reads them from the table it checks.
What
Since #757, a T# loaded from a buffer heap at a runtime offset is an image table column. Every capture then snapshots the whole heap, up to 65,536 records, even when user data or an SRT read fixes the offset. That covers #5188's case, a T# read from a constant buffer at a user-data offset: #757 made it a one-column table instead of an ordinary image.
In Resident Evil Village (PPSA01556) narrowing never applies to these tables, and the cost is large. With
APS5_PROFILE_DRAW=1at the title:With image tables switched off (
APS5_NO_IMAGE_TABLES=1), the title runs about 16x faster. That's not a fix, though: 26 shaders read a T# chosen per lane and then get a null image.With this change, a column whose T# words and offset are runtime values the SRT walker evaluates is selected:
The column keeps a table's semantics:
A column stays a whole table in two cases:
When the shader also uses such a T# for an operation a table can't express (an image store, an image atomic, or a packed or BY2/BY4 load), the T# is bound directly instead, through #5188's path, for every operation of that shader on it. A T# keyed per lane keeps the table: its image stores are table operations since #6402, and its atomics and packed or BY2/BY4 loads still fault, as on
main.A selected record's descriptor index is uniform for the whole draw or dispatch, so it isn't decorated
NonUniform. A column deselected because its key may be written also drops the key domains narrowed from that key.Samplers need no change: an S# whose words the walker evaluates is already bound directly on
main, so no sampler column has an offset the CPU evaluates. A test pins that. The disk cache format becomes 37, above the 36 that #1193 gavemain. Mergingmaine49ec59 into this branch conflicted only on that line, and the merges ofmain8856f18 and 4186f06 had no conflicts. The merge ofmain55f82fe takes #7101's bulk scan of key buffers, and its two skips for an inaccessible key page give this PR'sNarrowSkip::Unmappedreason. The merge ofmainf1af6c5 keeps both sides' tests intests/ShaderMemory.cpp, with #7325'sverifyChainedTableOffsetafter this PR's selected-record tests. The last commit adapts the selection to 682b07e, which came with 4186f06:mainnow poisons an image whose dword 3 wasn't captured, and a record selected past the end of its heap reads nothing there, so it was poisoned instead of selecting a null image. Dwords past the end of the buffer now count as read zeros, which is what a scalar buffer load returns there; every other path keepsmain's rule.The second commit names why narrowing is skipped in the
[image-table]profile line, with selected records counted apart. The third covers the selected records and their fallbacks, and each later commit adds one of the changes above, with its test after it:agc_shader_memoryandagc_shader_bindless: invalid, unmapped, past-the-heap, past-the-cap and carried records, a written key buffer and a per-lane key;agc_driver_image_table: a dispatch samples selected records exactly as direct bindings do, and faults on a store over its record;agc_shader_disk_cache: the round trip.After the merges,
docs(agc)drops the disk cache's format version fromARCHITECTURE.md, which said 36, so the line no longer goes stale or conflicts on each bump. After the merge ofmain55f82fe,test(agc)expects an image store through a T# keyed per lane to be a supported table operation, as #6402 makes it.Not changed here:
main, and image stores takemain's path since feat(agc): store to images selected through image tables #6402.Related: #757 and #5188 (both merged).
Tested
mainf1af6c5 (with fix(recompiler): fold chained immediate addends of image-table record offsets #7325), on GitHub's runners (run):^agctests (684, 0 failed). libc'sprecise_waittiming test failed in that run's suite; this PR doesn't touch libc.agc_driver_pm4_replay_toolandagc_shader_replay_tool, which fail the same way on that runner for an unrelated branch (run).main55f82fe (with feat(agc): store to images selected through image tables #6402 and perf(recompiler): scan image-table key buffers in bulk #7101) and adds thetest(agc)commit:agc_shader_bindlessfails on Linux and Windows: "selected record direct operations: image_store through a T# keyed per lane left the image table or lost its unsupported mark" (run).^agctests (681, 0 failed), and the libc and libkernel suites pass. On Windows the only failures are the same two replay tools (run).main4186f06:check_skips.py.ctest -R '^agc'runs 601 tests, 1 failed (agc_driver_preparation_scope_settle), 41 skipped (run), the same asmain2e5dd5a, ten commits earlier, on that runner (run).agc_shader_bindlessandagc_driver_image_tablefail in every one of 3 runs on Linux, andagc_shader_bindlesson Windows, whose runner has no GPU for the other. With it, both pass 5 runs in a row on both (run).main8856f18 (pipelined draws on by default):check_skips.py. The workflow carried the runner-image CA-bundle fix (CI only, no source change).ctest -R '^agc'runs 589 tests, 0 failed, 42 skipped (run), the same counts asmain8856f18 on that runner (run).^agcruns 589 tests, 0 failed, 42 skipped, asmaine49ec59 does there, and the full suite fails only the five socket tests that machine can't run.The only difference between 8f28ea4 and 43855cb is a test variable renamed because it clashed with the Windows
farmacro.libspass;guest_datagram_*andguest_tcp), as onmainthere;^agcruns 576 tests with 0 failures.agc_shader_bindless:NonUniformin a two-wave workgroup;agc_driver_image_table, on the GPU: 64 lanesimage_storethrough a selected record, and the texels read back hold the value.agc_shader_bindlessfails on Linux and Windows, andagc_driver_image_tableon Linux (the Windows runner has no GPU for it). With them, the 14 related tests pass 5 runs on both, and the libc and libkernel suites pass apart from main's intermittentguest_kqueueon Windows, which fails on both trees.Resident Evil Village (PPSA01556, 01.210.000) at the static main menu, on Windows 11 Home 10.0.26300, RTX 3070 Laptop (driver 617.42), Ryzen 9 5900HS, 15.4 GB RAM:
capture_resourcesself time per draw (queue worker 0x0)maine34c479 plus the title's test commits, with this PR's three commits ported and no extra commit. That tree predatesmain's pointer and two-load table columns, so the port leaves out the offset-carry case and its test, and its disk cache format is 34. Every column that tree can plan behaves as in this PR.APS5_TRACE_SECONDS=1500:180 APS5_TRACE_EVENTS=1048576;APS5_RE8_LAZY_PREPARE=1 APS5_NO_GPL=1, which the test tree needs to run the title on this PC;Driver.Dispatch: 248 and 240 ms;GpuMutex.wait.dispatch: 135 and 127 ms;Vulkan.Dispatch.shader_resources: 90 and 94 ms.aps5-trace-a762c980a2ea-24852.json.gz(before) andaps5-trace-320af7a8feb1-21124.json.gz(after).Before:
{"commit":"a762c980a2ea","dirty":false,"env":{"APS5_NO_GPL":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_RE8_LAZY_PREPARE":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"1500:180"},"gpu":"NVIDIA GeForce RTX 3070 Laptop GPU","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","resolution":"3840x2160","window":{"spec":"seconds 1500:180","first_present":875,"ms":180753.229},"presents":15,"frame_ms":{"p50":11809.09,"p90":13168.687,"p99":13975.212,"max":13975.212},"gpu_busy_ms_per_present":597.261,"worker_busy_pct":{"queue worker 0x0":99.957,"queue worker 0x38":0.034,"queue worker 0x20":98.635,"queue worker 0x28":99.604},"top_phases_ms_per_frame":{"Driver.Packet":35927.067,"Driver.Packet.memory_wait":23629.307,"Driver.Packet.draw":11731.423,"Driver.Draw":11728.805,"Shader.DrawStage":6719.182,"Driver.Draw.shader_compile_and_link":5654.378,"Shader.DrawStage.capture_resources":5554.289,"Driver.Draw.draw_and_resource_release":4505.873},"trace_dropped":false,"trace":"aps5-trace-a762c980a2ea-24852.json.gz"}After:
{"commit":"320af7a8feb1","dirty":false,"env":{"APS5_NO_GPL":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_RE8_LAZY_PREPARE":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_SECONDS":"1500:180"},"gpu":"NVIDIA GeForce RTX 3070 Laptop GPU","driver":"NVIDIA 617.42","os":"Windows 10.0.26300","resolution":"3840x2160","window":{"spec":"seconds 1500:180","first_present":1074,"ms":181174.051},"presents":49,"frame_ms":{"p50":3661.649,"p90":4171.06,"p99":4280.652,"max":4280.652},"gpu_busy_ms_per_present":414.233,"worker_busy_pct":{"queue worker 0x0":99.891,"queue worker 0x38":0.221,"queue worker 0x20":96.478,"queue worker 0x28":98.551},"top_phases_ms_per_frame":{"Driver.Packet":10891.181,"Driver.Packet.memory_wait":6946.788,"Driver.Packet.draw":3399.883,"Driver.Draw":3398.48,"Shader.DrawStage":1929.28,"Shader.DrawStage.capture_resources":1621.917,"Driver.Draw.shader_compile_and_link":1587.204,"Driver.Draw.draw_and_resource_release":1215.804},"trace_dropped":false,"trace":"aps5-trace-320af7a8feb1-21124.json.gz"}On
main, unprofiled. A later pair on Resident Evil Village's test tree ofmain0c4816f, with the fixes it needs to reach the menu, before and after this PR's head (090c0da). Same PC and driver, the same environment in both (APS5_HOST_IMPORT_MIB=6400 APS5_NO_GPL=1 APS5_TRACE_SUMMARY_EVERY=60, and the test tree'sAPS5_LAZY_SHADER_PREPARE=1, which it needs to run the title on this PC), no profiler connected, the game window in the foreground, at the static main menu:Driver.Packetper frametrace_digest of the before trace
seconds 1500:180 from present 875: 15 presents, frame p50 11809.1 / p90 13168.7 / p99 13975.2 / max 13975.2 ms, GPU busy 597.3 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 3840x2160, commit a762c98, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 35915.9, Driver.Packet.memory_wait 23629.1, Driver.Packet.draw 11731.4, Driver.Draw 11728.8, Driver.WorkerWait 10567.6, Driver.WorkerWait.dequeue_order 10362.5, Shader.DrawStage 6715.2, Driver.Draw.shader_compile_and_link 5654.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest of the after trace
seconds 1500:180 from present 1074: 49 presents, frame p50 3661.6 / p90 4171.1 / p99 4280.7 / max 4280.7 ms, GPU busy 414.2 ms per present
NVIDIA GeForce RTX 3070 Laptop GPU, NVIDIA 617.42, Windows 10.0.26300, 3840x2160, commit 320af7a, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 10881.8, Driver.Packet.memory_wait 6946.6, Driver.WorkerWait 3796.8, Driver.WorkerWait.dequeue_order 3613.1, Driver.Packet.draw 3399.9, Driver.Draw 3398.5, Shader.DrawStage 1925.3, Shader.DrawStage.capture_resources 1615.1
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Overlap (checked against
mainbc400be and the open PRs, 2026-10-16): #6232 also adds aTableColumnfield (pointerHops), so the two conflict inTableColumn::operator==, the plan encoder's size and field-count asserts inShaderDiskCache.cpp, and the test lists. Whichever merges second keeps both fields in the comparison, the encoder and the decoder, updates those asserts and setsFormatVersionabovemain's. #6488 (waterfall loops over per-lane T#s) adds twoTableColumnfields,laneKeyandimplicitDerivatives, and conflicts inTableColumn::operator==and the test list inShaderMemory.cpp. It also sets the field-count assert to 17 andFormatVersionto 37, as this PR does, so git merges those two lines without a conflict; whichever merges second raises them by hand (19 fields with both, and the next format version), and keeps all four fields in the encoder and the decoder. #6440 (reuse an image table column's records while its words are unchanged) adds its memo counters where this PR adds its narrowing and selection counters inResourceMaterializer.cpp, changes the same[image-table]statistics line, and adds its test at the same place inShaderMemory.cpp; keep both sets of counters, print both, and keep both tests. #6032, #6296 and #6858 each addEntryHeaderByteson the line afterFormatVersion; keep both lines. #6674 (uncompressed FMASK images) adds a debt line next to this PR's image-table line indocs/dev/debt/shader.md; keep both.#6402 (Pipodi, merged: stores to images selected through image tables) makes an
image_storethrough a T# keyed per lane a supported table operation. It merged without conflicts here, and thetest(agc)commit after the merge ofmain55f82fe changes the one expectation it broke: inagc_shader_bindless'sselected record direct operationscase, that store is nowTableOperation::Supported, while atomics, PCK and BY2/BY4 keyed per lane still fault. A store whose record the CPU evaluates stays a direct binding here, and #6402's storage table takes the stores keyed per lane.