A draw's and a dispatch's set 0 is pushed where the device can, its uniform buffers are read at
constant offsets where the binding allows, and alike pipeline layouts are one object, so switches
between alike states keep set 0.
What changes:
- Pushed set 0. Where the device has vkCmdPushDescriptorSet (Vulkan 1.4 or VK_KHR_push_descriptor),
a variant whose set 0 fits maxPushDescriptors, takes no set or binding flags and binds at one
bind point makes set 0 a push descriptor set layout. Its draws, dispatches and tile dispatches
push set 0's writes instead of allocating, writing and binding a set. Draws push incrementally:
only the writes that differ from what set 0 holds, as Vulkan allows until the set is disturbed;
baked samplers are pushed with every full push, as Vulkan requires. Every other variant and
every device without the command keeps the allocate-write-bind path. vkCmdPushDescriptorSetKHR
joins the exit guard's table and the device's priming. WorkCounts draws_pushing_set_zero,
set_zero_writes_pushed and dispatches_pushing_set_zero.
- Two driver defects, both typed RuntimeDriverDefect variants:
- PushedBufferSizesUnset on MoltenVK (every release): its pushed sets leave the buffers'
sizes unfilled, so a runtime array length reads 0. MoltenVK binds set 0 from pools.
- PushedDescriptorsStaleAfterPipelineBinds on ANV: a descriptor kept across a pipeline bind
reads zeros. There the first push after each pipeline bind carries at least one write.
- Uniform reads. Each uniform-view slot declares a specialization, SpecKey::RangeAtBindOffset:
where its descriptor range starts at the bind offset (inline bytes, an unbound slot, or a bind
offset the views' base alignment A divides), a read takes the Metal offset alone, a constant
for a constant member, so ANV pushes the constants into registers. Elsewhere it adds the
residual as before. Both forms are exact.
- Bind-offset classes. A bind offset is classed only by what a plan reads: A where the slot reads
through a uniform view and A divides it, else its alignment up to 4 for the vertex fetch. A slot
bound at an offset A does not divide leaves the specialized slots for good, so a slot at moving
offsets keeps one shape and one pipeline. The debug check of a table brought in place compares
those slots.
- Shared pipeline layouts. The device keys set and pipeline layouts by everything their creation
takes (sets, bindings, baked sampler handles, push-constant ranges), so variants defined alike
share one VkPipelineLayout; set 0 and the push constants then survive a pipeline bind between
them. WorkCounts pipeline_layouts_made and pipeline_layouts_shared, and set_zero_equal_shape_switches,
set_zero_writes_on_equal_shape_switches and set_zero_writes_if_shapes_shared for the switches
between layouts of one set-0 shape that are still apart. A new bench, frame_costs_alternating.
- New owned fixture engine/ubo_bind_offsets; docs/API.md states the alignment and the mask.
Why: on an RTX 5080 laptop GPU in runtime D3, vkCmdBindDescriptorSets waits about 973 ms for the
GPU to wake after 20 s idle, and vkCmdPushDescriptorSet 0.02 ms. ANV loads a uniform buffer ahead
of the shader only for constant offsets: the guest's display present spent 18 of its 29 sends on
uniform loads. And the guest pushed 597 set-0 writes a frame on switches between alike layouts,
where 244 would do.
Verified:
- RTX 5080 laptop after 20 s idle: a draw's call 957-974 ms binding set 0, 0.20-0.25 ms pushing it.
draw_work and dispatch_work 14 passed on it and on lavapipe, both taking the push path, and the
bind path with the extension withheld.
- On the M3 Max, the push path failed 30 of 61 tests (runtime array lengths reading 0) and crashed
Metal's compiler service on render variants; with set 0 bound on MoltenVK they pass as before.
- Iris Xe, 1080p passes of a full-screen draw: a float4x3 matrix and two packed_float3 per pixel
691.6 -> 407.7 us (-41%), twelve float4 451.0 -> 429.7 us; INTEL_DEBUG showed 21 sends -> 3.
RADV was unchanged. With the offset classes, a guest-shaped bench's encoding thread went from
5.65-5.70 back to 5.16-5.45 ms a frame and 194 pipeline lookups a frame to 0.
- The ANV defect: unorm_depth_bias failed 3 of 3 without the guard, passed 3 of 3 with it, on the
Iris Xe and the UHD 770.
- Shared layouts, frame_costs_alternating: set-0 writes 1920 -> 1320 a frame and draw states 2600
-> 2000 on RADV and ANV; a draw -2.3% instructions on both. On lavapipe (debug) the runtime unit
tests 1057 passed and every runtime lane test passed but for failures that reproduce without the
change; on RADV 115 lane tests passed, no VUID message.
- Unit tests: engine_access, bind::plan::slots, bind_shape_of, render::bound, argument_table,
driver_defects; uniform_bind_offsets device tests on lavapipe and ANV. clippy -D warnings (plain,
m2v_gpu, m2v_cpu_icd) and rustdoc.