Cut shadowed textures' copies to what their commands touch, merge back every buffer another writer may write, and count copies by cause
A texture over a buffer's bytes or another image whose own image is a shadow now copies in, keeps, merges and copies back only the texels its commands reach, with fewer barriers, descriptor pools and scratch fills, and merges its writes back wherever another writer may write the bytes during the run. What changes: - Which shadows merge. A shadow merges back (kept before the first command that writes through it, only the words its commands changed reaching the bytes) over every buffer's bytes but a tracked Private or Memoryless buffer the runtime made: Shared buffers and host pages as before, and now Managed buffers (on unified memory the CPU writes the GPU's memory, and without it a later upload may run on another queue) and untracked buffers another queue may write. A tracked Private buffer's shadow, a command replacing every texel, an image's shadow, and turned and two-plane textures still copy back. A merge goes in place wherever the texture's first and last words lie in the buffer and the bytes lie in pages; only a first byte inside a word, a staging buffer or a last word past the buffer still merges through a copy, a new FAST-PATHS known gap since that round trip can undo another writer's write between its copies. - Correct merges. A command that replaces every texel followed by one that writes part of it is copied back before the keep, so the merge carries the later writes. A merge of a part leaves a twin stale there alone. A detached buffer's shadow binds no stand-in (the null handle while detached), so no merge binds a range past a 256-byte stand-in. - Cut copies. A read inside a rectangle keeps the rest of the changed rectangle for the next read; an image's one-level, one-slice shadow cuts its copies in as a buffer texture's do; a keep and merge are cut to the rectangle the encoder's commands write in, in bands within the device's limits; a loaded shadowed colour's copies are cut to its draws' scissors also in passes that clear another attachment or take a reach clear (Vulkan's scissor test leaves coverage outside at 0). - Cheaper copies. On ANV (DriverFact::ShadowCopyBackDispatchFaster, now every ANV device measured) a merge's keep and changed copy are the copy back's dispatch, and a cut merge reads the changed texels straight from the shadow's integer view (bind::shadow_merge_image_module), with no copy after the commands. On the UHD 770 (new DriverFact::ShadowCopyInDispatchFaster) a merged shadow's copy in and its keep are one dispatch (bind::shadow_copy_in_module), its 4-byte view R8G8B8A8_UINT because ANV drops a storage image's compression for an R32 view. The shadow kernels take a bind::ShadowTexelView. A cut merge's scratch is kept for the next merges and not zeroed. The shadow kernels and a linear attachment's merge push their descriptors where the device pushes set 0, so a shadowed pass makes no descriptor pool. A run of shadow copies in an unordered encoder shares one barrier before and one after, keeping a barrier only between copies that touch the same memory and one writes. - Counters (WorkCounts): every copy in by why it is made and by what holds the texture's truth, first copies apart (shadow_texels_first_copied_in_*, shadow_texels_recopied_*, shadow_texels_copied_in_images, shadow_texels_bounded_copied_in), shadow_texels_kept, shadow_merge_copies_dispatched, shadow_merges_fetched, shadow_copies_in_dispatched, shadow_merge_scratches_reused and _zeroed, owned_descriptor_pools, how passes take shadowed colours (shadow_attachment_loads_*, _clears, _clears_in_part), shadows_sharing_truth, and the tiles a loaded colour's scissors cover against their bounds. - Docs: shadow.rs and shadow_merge.rs module rules, API.md's shadow entries, FAST-PATHS' costs of matching Metal and known gaps; the snapshot rule's figure is now an upper bound. Why: Metal writes only the texels a command writes, and another writer may write bytes no command touches during a run. On an M3 Max under macOS 27.0.1, a fill of an untracked Private buffer from a second queue ran inside a first queue's kernel or render pass 5 times of 6 and both texels kept their writes, as did a CPU write to a Managed buffer; a tracked Private buffer's fill always ran after. And in the consumer's Finder drag on the Iris Xe, whole 1080p shadow copies were most of the composite command buffers' GPU time. Verified: - Iris Xe, four shadowed textures a frame over anonymous pages, commit to completion: merged passes that draw 11.7-11.8 ms -> 5.0-5.4 ms and scissored ones 11.3-11.4 -> 3.6-3.9 ms across the dispatched copies, cut keeps and fetched merges; a 1080p Load pass's GPU time 4572 -> 3484 us with the fetched merge. - UHD 770: a 1080p Load/Store pass 2390 -> 1683 us GPU with the fetched merge; a 1080p Load pass 1.64-1.67 -> 1.43 ms with the fused copy in; the kept scratch took a 1080p Load pass 4205-4755 -> 2626-3595 us commit to completion (RX 7900 XTX 4112-4392 -> 1628-1697 us). Shared barriers saved about 0.65 us of GPU time per barrier removed on the Iris Xe (680 -> 120 barriers a frame). - runtime_lane::pitched_surfaces 28 of 28 on the UHD 770, Iris Xe, Radeon 780M, RX 7900 XTX and lavapipe, with merges under changing scissors, split instances and two textures over one buffer matching a private texture's bytes; under synchronization validation with no message. The shadow lanes 123 to 132 of 123 to 132 on the M3 Max, lavapipe, Iris Xe and RADV; extended_range_blends, linear_attachments and padded_loads on the RTX 5080 with no validation message. - Unit tests: tests::shadow (24), clear_reach, owned_pushes, shadow kernels through all four views on the CPU interpreter, driver_facts. clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd), rustdoc.
This commit is contained in:
1 parent
ca8340b4ee
commit
f514cb9a7d
52 files changed
+5862
-818
No files matched your search
+21
-8
@@ -973,20 +973,33 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound.
|
||||
it).
|
||||
Cost: its texels are copied into an image before each use and back after each write; a render
|
||||
pass that loads it as an attachment, takes it in no other way and draws under scissors copies in
|
||||
and back only the texels inside them (`WorkCounts::shadow_texels_copied_in`,
|
||||
`shadow_texels_copied_back`). Where the device is measured to run it faster so
|
||||
(`DriverFact::ShadowCopyBackDispatchFaster`), a copy back of a one-slice texture of 4-, 8- or
|
||||
16-byte texels is a compute dispatch that stores the same bytes
|
||||
(`WorkCounts::shadow_copies_back_dispatched`).
|
||||
only the texels inside them (`WorkCounts::shadow_texels_copied_in`). Over a buffer's bytes that
|
||||
another writer may write while a command buffer runs, the image is kept in a scratch buffer
|
||||
before the first command that writes through it, and each copy back is a dispatch that merges
|
||||
only the words the commands changed, so that writer's writes to the texels they left stay, as on
|
||||
Metal: the CPU's, over a `Shared` or `Managed` buffer's bytes, host pages or the caller's
|
||||
`VkBuffer`, and another queue's commands', over an untracked buffer's. A tracked `Private`
|
||||
buffer's bytes have no such writer (the runtime orders another queue's commands that touch them
|
||||
before or after the command buffer, as Metal does), and are copied back
|
||||
(`shadow_texels_copied_back`), as a command that replaces every texel is. The scratch keeps the
|
||||
rectangle the commands write in, where they bound it and the copies are cut so
|
||||
(`WorkCounts::shadow_texels_kept`).
|
||||
Where the device is measured to run it faster so (`DriverFact::ShadowCopyBackDispatchFaster`), a
|
||||
copy back of a one-slice texture of 4-, 8- or 16-byte texels is a compute dispatch that stores
|
||||
the same bytes (`WorkCounts::shadow_copies_back_dispatched`), and so is a merge's copy of such a
|
||||
texture's image into its scratch buffer before the commands
|
||||
(`WorkCounts::shadow_merge_copies_dispatched`), which on a device measured faster so
|
||||
(`DriverFact::ShadowCopyInDispatchFaster`) also takes the copy in of the same texels before it,
|
||||
storing them in the image through that view (`WorkCounts::shadow_copies_in_dispatched`); after
|
||||
them, a cut merge reads the texels the commands left from the image itself, through an
|
||||
- `metal2vulkan-degrade-staged-texture-buffer` (performance). `StagedTextureBuffer`: A texture
|
||||
buffer is viewed through a staging buffer: its texels start where the device views none
|
||||
(`minTexelBufferOffsetAlignment`). Cost: its texels are copied into a staging buffer before each
|
||||
use and back after each write.
|
||||
- `metal2vulkan-degrade-shadow-merge` (performance). `ShadowMerge`: One command writes a buffer's
|
||||
bytes through a shadowed texture or a staged texture buffer and also another way. Cost: the
|
||||
shadow's texels are kept in a scratch buffer of three times the texture's bytes before the
|
||||
command, and after it a dispatch merges the bytes it changed through the texture into the
|
||||
buffer's: three copies and a dispatch in place of one copy back.
|
||||
buffer's, in place where the texture's bytes start and end in whole words of the buffer: one to
|
||||
three copies and a dispatch in place of one copy back.
|
||||
- `metal2vulkan-degrade-copied-draw-bytes` (performance). `CopiedDrawBytes`: A draw's index buffer
|
||||
or indirect arguments start where Vulkan reads neither. Cost: they are copied into a buffer of the
|
||||
command buffer before the pass, and the draw reads the copy.
|
||||
|
||||
Reference in new issue
Block a user