Offset-only rebinds compare bind offset classes without classing the length

A rebound draw whose buffer slot moved only its offset (refresh_offset) asked
Reshape::replace whether the slot's shape changed by making both bindings'
BufferShapes: two length_class calls (u128 arithmetic) for a length the two
bindings share by construction. The fp call graph of draws.10k on lavapipe
(release, line tables, frame pointers) put BoundBuffer::shape at 1.24% of the
process, 0.78% in length_class, all of it under refresh_offset.

BoundBuffer::same_shape answers as the two shapes compare, skipping the class
of a length or offset the two bindings share; Reshape::replace_by takes such a
predicate, and replace is written over it. refresh_offset uses same_shape.

Test: bind_shape_of's new test checks same_shape against shape equality over
every pair of 184 bindings at three view base alignments. API signatures
blessed (one new method).

(cherry picked from commit 29fc8605db0229f0e2d7ca5522bb2e56855ee86d)
This commit is contained in:
Anees Iqbal committed 2026-11-08 02:55:36 -08:00
1 parent dc064aec27
commit e318666636
5 files changed
+110 -6

No files matched your search

@@ -1510,9 +1510,10 @@ impl ArgumentTable {
/// addresses are as `kept` read them, as no no-copy buffer moved since (the callers' reads
/// stand only while none did: `live_bind::ReadFrom`), so the buffer is not looked at
/// (`WorkCounts::bound_offsets_moved`; checked against [`refresh_buffer`](Self::refresh_buffer)'s
/// binding in builds with debug assertions). The function reads the slot bound as `kept` was
/// read: a buffer `kept` binds there was read bound, and no call since bound a visible-function
/// table there, which changes the slot otherwise than by its offset
/// binding in builds with debug assertions), and the length the two bindings share is not
/// classed to compare their shapes ([`BoundBuffer::same_shape`]). The function reads the slot
/// bound as `kept` was read: a buffer `kept` binds there was read bound, and no call since
/// bound a visible-function table there, which changes the slot otherwise than by its offset
/// ([`binds_buffer`](Self::binds_buffer)), through the same interface (checked in builds with
/// debug assertions). Else as `refresh_buffer`.
fn refresh_offset(
@@ -1557,7 +1558,7 @@ impl ArgumentTable {
"a buffer slot whose offset alone moved brought in otherwise than read whole"
);
counts.bound_offset_moved();
reshape.replace(slot, bound, |b| b.shape(a));
reshape.replace_by(slot, bound, |was, now| was.same_shape(now, a));
}
/// Buffer slot `index` of `kept` brought in place as [`refresh_reading`](Self::refresh_reading)
+12 -1
View File
@@ -152,7 +152,18 @@ impl Reshape {
value: V,
shape: impl Fn(&V) -> S,
) {
if !self.0 && *slot != value && shape(&*slot) != shape(&value) {
self.replace_by(slot, value, |was, now| shape(was) == shape(now));
}
/// Store `value` in `slot` as [`replace`](Self::replace) does, where `same_shape` tells
/// whether two bindings have one shape without making either's.
pub(super) fn replace_by<V: PartialEq>(
&mut self,
slot: &mut V,
value: V,
same_shape: impl FnOnce(&V, &V) -> bool,
) {
if !self.0 && *slot != value && !same_shape(&*slot, &value) {
self.0 = true;
}
*slot = value;
+42
View File
@@ -1132,6 +1132,48 @@ impl BoundBuffer {
} => BufferShape::Bytes { attribute_stride },
}
}
/// Whether this binding and `other` have one shape under `view_base_alignment`, as their
/// [`shape`](Self::shape)s compare: a length or bind offset the two share is not classed.
pub fn same_shape(&self, other: &BoundBuffer, view_base_alignment: u32) -> bool {
match (*self, *other) {
(
BoundBuffer::Buffer {
length,
offset,
device_address,
attribute_stride,
..
},
BoundBuffer::Buffer {
length: other_length,
offset: other_offset,
device_address: other_address,
attribute_stride: other_stride,
..
},
) => {
attribute_stride == other_stride
&& device_address.is_some() == other_address.is_some()
&& (length == other_length
|| length_class(length) == length_class(other_length))
&& (offset == other_offset
|| offset_alignment(offset, view_base_alignment)
== offset_alignment(other_offset, view_base_alignment))
}
(
BoundBuffer::Bytes {
attribute_stride, ..
},
BoundBuffer::Bytes {
attribute_stride: other_stride,
..
},
) => attribute_stride == other_stride,
(BoundBuffer::Buffer { .. }, BoundBuffer::Bytes { .. })
| (BoundBuffer::Bytes { .. }, BoundBuffer::Buffer { .. }) => false,
}
}
}
/// The alignment class of bind offset `offset` (a buffer's,
+50 -1
View File
@@ -1,6 +1,7 @@
//! `BindState::has_shape` answers `state.shape() == *shape` without making the shape: over states
//! that each differ from a base in one field of the shape (and some in fields the shape leaves
//! out, or in two ways that give one shape), for every pair of them.
//! out, or in two ways that give one shape), for every pair of them. `BoundBuffer::same_shape`
//! answers as two bindings' shapes compare, over every pair of a set of bindings.
use crate::bind::{
ArgumentFunctionTable, ArgumentSampler, BindState, BoundBuffer, BoundSampler, BoundTexture,
@@ -436,3 +437,51 @@ fn a_state_listed_in_token_order_compares_its_used_resources_in_place() {
// reads and writes it in both stages (three of one shape).
assert_eq!(same, 2 + 3 * 2, "pairs of one shape");
}
/// `BoundBuffer::same_shape` answers `a.shape(x) == b.shape(x)` for every pair of bindings over
/// lengths of one length class and of others, bind offsets of one alignment class and of others,
/// with and without a device address and a stride, and inline bytes, at view base alignments that
/// tell no offset class past the vertex fetch's apart and one that does.
#[test]
fn a_buffer_binding_has_the_shape_of_another_exactly_where_their_shapes_compare_equal() {
let mut bindings = Vec::new();
for length in [1, 16, 17, 4096, u64::MAX] {
for offset in [0, 2, 4, 6, 64, 96] {
for device_address in [None, Some(0x2000)] {
for attribute_stride in [None, Some(4), Some(6)] {
bindings.push(BoundBuffer::Buffer {
length,
offset,
gpu_address: 0x1000,
device_address,
attribute_stride,
});
}
}
}
}
for len in [4, 8] {
for attribute_stride in [None, Some(4)] {
bindings.push(BoundBuffer::Bytes {
len,
attribute_stride,
});
}
}
let (mut alike, mut apart) = (0, 0);
for alignment in [0, 4, 64] {
for (at, binding) in bindings.iter().enumerate() {
for (of, other) in bindings.iter().enumerate() {
let equal = binding.shape(alignment) == other.shape(alignment);
assert_eq!(
binding.same_shape(other, alignment),
equal,
"binding {at} against binding {of} at alignment {alignment}"
);
alike += usize::from(equal && at != of);
apart += usize::from(!equal);
}
}
}
assert!(alike > 0 && apart > 0, "{alike} pairs alike, {apart} apart");
}
@@ -8670,6 +8670,7 @@ method metal2vulkan::bind::BindingPlan::slot_rebinds_into pub fn slot_rebinds_in
method metal2vulkan::bind::BindingPlan::specialized_value pub fn specialized_value(&self, key: SpecKey) -> Option<u64>
method metal2vulkan::bind::BlockDecodeModule::shape pub fn shape([width, height, depth]: [u32; 3]) -> [u8; Self::SHAPE_WORDS as usize * 4]
method metal2vulkan::bind::BoundAccelerationStructure::new pub fn new(instance_count: u32) -> BoundAccelerationStructure
method metal2vulkan::bind::BoundBuffer::same_shape pub fn same_shape(&self, other: &BoundBuffer, view_base_alignment: u32) -> bool
method metal2vulkan::bind::BoundBuffer::shape pub fn shape(&self, view_base_alignment: u32) -> BufferShape
method metal2vulkan::bind::BoundSampler::new pub fn new(desc: SamplerDescriptor) -> BoundSampler
method metal2vulkan::bind::BoundSampler::shape pub fn shape(&self) -> BoundSamplerShape
Can't render this file because it is too large.