ComputeCommandEncoder held its whole state (888 bytes) by value, so its open's return, each move by a caller (a consumer that boxes it copies it into the box), and end_encoding's self each copied it whole. Its state now lies in a box of its own (Body), and the encoder is that one pointer, as the render encoder already boxes its lowering. A core's end read the whole core out of its box onto the stack (EncoderCore::unboxed_apart in end_encoding) and passed it by value to end_with_replay, which took it apart again. end_with_replay now takes the boxed core, takes it apart where it ends, and hands its emptied box on: with a compute encoder's bind state to the command buffer's park (compute::Parking, then Parked), else back to the device's spares. The same Vulkan commands; no API change. Verified: tests::encoder_moves asserts the encoder is one pointer (it was 888 bytes against the old bound of 1 KiB). With: Compute encoders: fields through the body box everywhere; end_with_replay over a boxed or held core; end_with_replay: take the held core through one plain reference until it is taken apart. Why: a compute encoder was 888 bytes moved by value through open, the caller's Box::new and end, and its core was read out of its box whole at its end (reims decodecost: large-value memcpy 4.0% of the decoder thread). Now a move copies 8 bytes and the core is taken apart inside its box. Measured (lane encbox, msi lavapipe, dispatch_chain --dispatches 5 --groups 64 --only encoders, release, base/tip alternated twice, m3-max-37522): encode per encoder 4613 -> 4465 ns (-0.15 us), end 1102 -> 1013 ns; thread CPU 6645 -> 6488 ns. Below the 0.3 us bar for a perf claim; kept as a built, structural, measured-positive change. Checks: clippy plain, m2v_cpu_icd, m2v_gpu (-p metal2vulkan-runtime, all targets, all features) 0 in m3-max-37545; tests::encoder_moves asserts the encoder is one pointer; the lavapipe compute/encoder/render/blit suites (m3-max-37547) and rustdoc follow on development.
14 lines
746 B
Rust
14 lines
746 B
Rust
//! What a compute encoder moves by value: `compute_command_encoder` returns it, and
|
|
//! `end_encoding` takes it, so each of those, and each move of it in between, copies the encoder
|
|
//! whole. Its state lies in a box of its own, and its core and its bind state in boxes the device
|
|
//! recycles (`encoder::SpareCores`, `compute::SpareLiveDispatches`), so a move copies one pointer,
|
|
//! where its state held in place made each move a copy of 888 bytes.
|
|
|
|
/// A compute encoder is one pointer.
|
|
#[test]
|
|
fn a_compute_encoder_moves_one_pointer() {
|
|
let size = std::mem::size_of::<crate::ComputeCommandEncoder>();
|
|
println!("ENCODER-MOVES ComputeCommandEncoder {size} bytes");
|
|
assert_eq!(size, std::mem::size_of::<usize>(), "{size} bytes");
|
|
}
|