Bind a storage view of a whole buffer from its space's start, so draws that move only an offset keep their set 0
What: `bind::instantiate::planned_range` gives a descriptor-form slot read through a storage view of its `Whole` window the range from the start of the bound buffer's space to its padded end, whatever the bind offset, and the bind offset as its `SlotBindOffset` residual. `bind_buffers` (every draw's and dispatch's instantiation) and `rebind_slots` (`rebind_draw_slots_into`) take it. Every other slot keeps `descriptor_range`'s range: uniform views (whose `RangeAtBindOffset` specialization reads a range from the bind offset), bounded windows, and a storage view whose range from 0 would pass the view's `maxStorageBufferRange` (`PlannedBuffer::max_range`) or 2^32 bytes (a 32-bit residual and offset), or whose bind offset lies at or past the padded end. The tessellation factor and index bindings keep it too. Why: `EncoderCore::set_zero_of` was 14.3% (draws.10k) and 8.8% (WS-like) of the encoding thread's samples: every draw allocated, wrote and bound a set 0 of its own. A `device T *` slot's range started at the bind offset aligned down, so each new offset wrote another descriptor and neither `LastSetZero` nor `SetCache` could match. Vulkan: the descriptor's offset is the space's start (256-aligned, as a bind at offset 0 has it today) and its range ends where today's ends (the padded end), so offset + range, and a dynamic binding's effective offset + range (VUID-vkCmdBindDescriptorSets-pDescriptorSets-01979), are what they were. dynamic_writes moves that same start into the dynamic offset for every bind offset. The range is explicit, never VK_WHOLE_SIZE (06715 does not apply). Hazard ranges are untouched: they come from the plan's use ranges from the bind offset (`binding::bytes_use`). Behaviour: a Metal offset m from the bind offset reads byte residual + m of the range, the same byte as before for every access inside the window. An access that reaches back before the bind offset (a negative index, the 32-bit offset wrapping) and lands in the buffer's space now reads and writes the buffer's bytes there, as Metal's does; before, it lay outside the descriptor range unless it stayed within the alignment's residue. On a device with robustBufferAccess (or under in-shader containment against the view's size) accesses are bounded by the larger range [space start, padded end) instead of [bind offset aligned down, padded end): such an access before the bind offset is in range and reaches the buffer's bytes where it was a robust out-of-bounds access (a zero, a value from within the buffer, or a dropped write). Accesses past the end are bounded as before. SEMANTICS_VERSION 1957 -> 1958: instantiated descriptor ranges and residuals change. golden_hashes_match_the_table passed unchanged here (it hashes compiled modules, which this does not change); the re-bless on development decides. Tests: planned_range's unit tests (the range from 0 and the residual at every 4-byte offset for base alignments 16, 64 and 256, and a 2^32-byte buffer at its last word; each fallback equal to descriptor_range's answer). A device test, set_zero_at_offsets: 9 draws of colored_vertex moving only two device buffers' offsets reuse 8 sets and bind 1, and draw what 9 draws of buffers of their own draw (0 reused, 9 bound). dynamic_multi_variable's moved-offset dispatches now reuse their predecessor's set (7 of 8) and still answer Metal's values from each dispatch's own offset. docs/API.md states the range. Verified: the translator suite, 3324 of 3324 (plain). On the M3 Max (MoltenVK 1.4.2), debug, --cfg m2v_gpu, under maclock and memcap: 96 of 96 runtime tests (fix 1's set plus set_zero_at_offsets, dynamic_multi_variable, uniform_bind_offsets, binding_view, range, rebind_descriptor_slip, rebind_behind_a_wait, depth_ranges, attributes), and 220 of 220 validation lanes under the validation layer (fix 1's set plus stage_in_regions, stage_in_strides, padded_loads, escaped_slots, absent_reads, chosen_pointers, dispatch_*, read_through_views, guarded_effects, index_fetches, first_vertex, vertex_strides, host_bytes, pointer_uploads, commands_recorded, runtime_lane::tests, among them renders::public_render_cases_match_metal and tests::stage_in_region_cases_match_metal). Negative control: planned_range forced to fall back fails set_zero_at_offsets ((0, 9) against (8, 1)) and both dynamic_multi_variable moved-offset tests ((0, 0) against (7, 0)). clippy plain and with --cfg m2v_gpu clean. Per draw on the encoding thread, release with thin LTO, 3 interleaved rounds against the parent build, medians: draws.10k 11201.7 -> 9212.4 instructions (-17.8%), 616-661 -> 485-495 ns WS-like 23121.1 -> 21752.5 instructions (-5.9%) One round's counts: draws.10k 0 -> 29880 sets reused, 30000 -> 120 vkCmdBindDescriptorSets, 6 -> 60000 vkCmdPushConstants (the residuals; both stages' writes are pushed where either changes); WS-like 0 -> 3744 sets found in the command buffer's cache, binds unchanged at 4000. (cherry picked from commit b875660ecbad7dd6f9dfa9f976ef1c2b32bded1e) (cherry picked from commit b09293e9c22d80e4ae4c505b00ba0e07e6a8165c)
This commit is contained in:
1 parent
cc6b083fc2
commit
b2df1add01
8 files changed
+410
-41
No files matched your search
@@ -1053,6 +1053,15 @@ let draw = DrawCall::Primitives {
|
||||
let commands = plan.instantiate_draw(&state, &draw)?;
|
||||
```
|
||||
|
||||
A buffer slot read through a storage view of its whole window (a `device` pointer the function
|
||||
indexes) takes the descriptor range from the start of the bound buffer's space to its end padded
|
||||
to 16 bytes, whatever its bind offset, which its `SlotBindOffset` push field holds: draws and
|
||||
dispatches that bind one buffer at other offsets write the same descriptors, and only push data
|
||||
differs. Where that range would pass the view's `maxStorageBufferRange` or 4 GiB, or the offset
|
||||
lies at or past the padded end, the range starts at the bind offset aligned down to the
|
||||
descriptor base alignment, as every other descriptor-form slot's does. An access that reaches
|
||||
back before the bind offset, inside the buffer, reads the buffer's bytes there, as Metal's does.
|
||||
|
||||
`instantiate_draw_into` writes the same commands over a `DrawCommands` you keep, in the storage
|
||||
its vectors already hold: keep one from draw to draw (`DrawCommands::default()` to start) and the
|
||||
draws allocate none of it again once it holds as much.
|
||||
|
||||
Reference in new issue
Block a user