Files
metal2vulkan/docs
Anees Iqbal 734e1cac02 RUNTIME 2339: Bind a slot read at its residual over a range its bind offsets share
What: bind::instantiate::shared_range gives a descriptor-form slot of a
Bounded window that its functions read at the residual one range for a run
of bind offsets of the bound buffer: the padded buffer from 0 where it fits
the view's maximum range (and 4 GiB), else the block of half that maximum
its window starts in, to the maximum past the block's start; its
SlotBindOffset residual the rest. A window of at most half the maximum never
straddles its block's range; a longer one, or one at or past the padded end,
keeps descriptor_range's range. planned_range takes it for every Bounded
storage view (no function reads one at its bind offset alone), and for a
uniform view where the new BindState::uniform_views_at_residual says the
consumer reads every uniform view at its residual: its keys all take their
residual forms. The runtime states it where pipeline::reads_views_at_bind
does not hold (every device today: no driver carries
DriverFact::ConstantOffsetUniformReadsPreloaded), through AtBindViews, at
each bind state that states the view base alignment (render, compute twice,
tile dispatch). Shapes, plans and keys are unchanged; the flag is not part
of the shape.

Why: a constant reference at a buffer index (constant float4 &) is a uniform
view of a 16-byte Bounded window, whose range started at the bind offset
with residual 0. Every offset-only rebind (a consumer's staged
setVertexBytes: setVertexBuffer at the next 256 bytes of an upload chunk)
then wrote another descriptor: rebind_into, push_set and the driver's
vkCmdPushDescriptorSet at every draw (reims-vgpu's Iris: +538 ns a draw
against a device pointer, +93 inside the push and +99 under record). The
range at the bind offset serves only keys reading the view at the bind
offset alone, which no device takes today: the shader already adds the
residual. Now such a draw keeps its set-0 writes (writes_kept) and pushes
only its residual, as a device pointer's draw does.

Metal and Vulkan: each read inside the window reads byte
lo + (bind - lo) + m = bind + m, the bytes it read before, through the same
instructions. A read outside the window, which Metal leaves undefined,
reads the buffer's bytes inside the range. The range starts at 0 or a block
multiple, a multiple of the base alignment
(VUID-VkWriteDescriptorSet-descriptorType-00327/00328), stays within the
view's maximum (00332/00333) and the padded allocation
(VUID-VkDescriptorBufferInfo-range-00342); a dynamic descriptor's offset is
its start as before (VUID-vkCmdBindDescriptorSets-pDynamicOffsets-01971).

Verified: by the jobs that follow (unit tests of shared_range and
planned_range, the lavapipe runtime test
constants_moved_along_one_buffer_keep_their_set_zero, the release medians
of runtime_lane::constant_offsets before and after).

With (bench and tests): 78463d1e1d The moved-constant set-0 test counts every second draw again as taking every step in builds with debug assertions; 5e7d715629 The moved-constant set-0 test lists which of the second pass's draws were rebound; 99a3459dc6 The moved-constant set-0 test moves the vertex constant alone, as constant_offsets does; a9c4b07790 The moved-constant set-0 test names what the second pass's draws did where some were not moved; 5e938c75c5 The moved-constant set-0 test draws the bench's shape; a bounded storage window's dispatch test binds the shared range; 69e598a6b5 Drop the stale copy of the range-from-bind-offset test; round-trip the new BindState field; ea4602012c cof_device reads its float4 at the instance's element; cd6492fd41 constant_offsets also draws over chunks in host pages, under the consumer's policy; 4d6e17bb89 constant_offsets takes the AIR library trait into scope; 1221f53ce0 Time draws that rebind a constant reference by offset against a device pointer.

Compiled in m3-max-31548 (msi: clippy, lavapipe uniform_bind_offsets/draw_again/general_form/inline_continues/
kept_shadowed_draws 48/48). The set-0 test fails at the base (16 writes pushed, want 0; 31536). Release counts
(31392): set-0 pushes per constant draw 1.00 -> 0, push constants 0 -> 1.00. The new fixture's golden rows re-bless
on development.
2026-11-14 22:47:14 -08:00
..