Skip to content

Commit edf38ba

Browse files
authored
headless_renderer example overallocates Buffer. (#24005)
# Objective headless_renderer example over allocates the Buffer `RenderDevice::align_copy_bytes_per_row` takes bytes per row, the example is passing pixels - then multiplying the padded result by bytes per pixel. So it allocates 8192 bytes per row instead of 7680. ## Solution Multiply pixels per row by bytes per pixel and pass that to `align_copy_bytes_per_row` ## Testing - Did you test these changes? If so, how? Ran the example with various pixel widths. The over allocation doesn't affect the rendered output because the other call to `align_copy_bytes_per_row` in `update` is correct, so we properly extract the image from the padded buffer.
1 parent 8d88f59 commit edf38ba

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

examples/app/headless_renderer.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,7 @@ impl ImageCopier {
289289
size: Extent3d,
290290
render_device: &RenderDevice,
291291
) -> ImageCopier {
292-
let padded_bytes_per_row =
293-
RenderDevice::align_copy_bytes_per_row((size.width) as usize) * 4;
294-
292+
let padded_bytes_per_row = RenderDevice::align_copy_bytes_per_row(size.width as usize * 4);
295293
let cpu_buffer = render_device.create_buffer(&BufferDescriptor {
296294
label: None,
297295
size: padded_bytes_per_row as u64 * size.height as u64,

0 commit comments

Comments
 (0)