Runtime tests: a serial dispatch that writes after a read through an address outside every resource takes a barrier
A serial compute encoder records no barrier between a dispatch that reads through an address outside its resources and a later dispatch that writes a resource through its slot or a use_resource declaration: the read marks nothing in the hazard sets (Hazards::mark_wild_read sets touched alone), and the unbound test in Building::dispatch_hazards looks at earlier writes for an unbound read and at any earlier access for an unbound write, never at an earlier unbound read for a write. Metal runs a serial encoder's dispatches in dispatched order (MTLCommandBuffer.h), so the read sees the bytes from before the write; on Vulkan the two may overlap. every_device_orders_a_write_after_an_unbound_read: the wild step kernel (reads_unbound) over y, then step over x, in one serial encoder; it asserts one barrier in the unbound source and two barriers with the segment's end. It fails before the fix (no source, one barrier). Verified: not run yet; the lavapipe run follows.
This commit is contained in:
1 parent
d8735b75f0
commit
58305fb9cd
1 file changed
+46
@@ -770,6 +770,52 @@ pub(crate) mod on_device {
|
||||
});
|
||||
}
|
||||
|
||||
/// A dispatch that writes a resource after a dispatch that read through an address outside
|
||||
/// its resources takes a barrier in a serial encoder: the read may have been of the resource
|
||||
/// the write reaches, and Metal runs a serial encoder's dispatches in their order, so the read
|
||||
/// sees the bytes from before the write. Here the second dispatch writes a buffer the first
|
||||
/// did not bind, so that barrier counts among the unbound ones, the segment's end the only
|
||||
/// other. Lavapipe runs dispatches one after another, so the values cannot show the order;
|
||||
/// the count by source does.
|
||||
#[test]
|
||||
fn every_device_orders_a_write_after_an_unbound_read() {
|
||||
each_device("compute_unbound_read", |name, _, device| {
|
||||
let mut arena = Arena::new(&device);
|
||||
let step = step(&device);
|
||||
let fields = vec![region(), address(0, Place::Push(32))];
|
||||
let mut wild = interface(vec![(0, Access::ReadWrite)], fields, 40);
|
||||
wild.reads_unbound = true;
|
||||
let wild = (ComputePipelineState::for_test(&device, &kernels::STEP, wild))
|
||||
.expect("the step kernel, reading outside its resources");
|
||||
let queue = device.new_command_queue(4).expect("a queue");
|
||||
let [x, y] = std::array::from_fn(|_| arena.buffer());
|
||||
for buffer in [&x, &y] {
|
||||
write_words(buffer, |index| index);
|
||||
}
|
||||
let before = device.counters().metrics();
|
||||
let command_buffer = queue.command_buffer().expect("a command buffer");
|
||||
let mut encoder = command_buffer
|
||||
.compute_command_encoder(DispatchType::Serial)
|
||||
.expect("an encoder");
|
||||
dispatch(&mut encoder, &wild, &[&y]);
|
||||
dispatch(&mut encoder, &step, &[&x]);
|
||||
encoder.end_encoding();
|
||||
run(name, &command_buffer);
|
||||
let after = device.counters().metrics();
|
||||
let split = sources(&after, &before);
|
||||
assert_eq!(
|
||||
split,
|
||||
only(5, 1),
|
||||
"{name}: the barrier between the unbound read and the write after it"
|
||||
);
|
||||
let barriers = after.barriers - before.barriers;
|
||||
assert_eq!(barriers, 2, "{name}: that barrier and the segment's end");
|
||||
let once: Vec<u32> = (0..WORDS as u32).map(|x| x * 2 + 1).collect();
|
||||
assert_eq!(words(&x), once, "{name}: the step of x");
|
||||
assert_eq!(words(&y), once, "{name}: the step of y");
|
||||
});
|
||||
}
|
||||
|
||||
/// What an encoder's commands count reaches the device's counters once, at the encoder's
|
||||
/// end: 2,000 dispatches that each read the one before's writes move none of them while the
|
||||
/// encoder is open, and its end adds the pass, the 1,999 barriers between them, the push and
|
||||
|
||||
Reference in new issue
Block a user