From 2acc010ab7251cb519ec5c7eacba8f7a8bbf083b Mon Sep 17 00:00:00 2001 From: grovesNL Date: Wed, 21 Apr 2021 20:30:27 -0230 Subject: [PATCH] Remove zero padding from `create_buffer_init` The buffer should already be zeroed so zeroing shouldn't be necessary --- examples/hello-compute/main.rs | 2 +- src/util/device.rs | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/examples/hello-compute/main.rs b/examples/hello-compute/main.rs index 79523677a..501b53d61 100644 --- a/examples/hello-compute/main.rs +++ b/examples/hello-compute/main.rs @@ -101,7 +101,7 @@ async fn execute_gpu(numbers: Vec) -> Vec { // It is to WebGPU what a descriptor set is to Vulkan. // `binding` here refers to the `binding` of a buffer in the shader (`layout(set = 0, binding = 0) buffer`). - // A pipeline specifices the operation of a shader + // A pipeline specifies the operation of a shader // Instantiates the pipeline. let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { diff --git a/src/util/device.rs b/src/util/device.rs index 3820fd386..2c7f4c93e 100644 --- a/src/util/device.rs +++ b/src/util/device.rs @@ -53,14 +53,10 @@ impl DeviceExt for crate::Device { }; let buffer = self.create_buffer(&wgt_descriptor); - { - let mut slice = buffer.slice(..).get_mapped_range_mut(); - slice[0..unpadded_size as usize].copy_from_slice(descriptor.contents); - - for i in unpadded_size..padded_size { - slice[i as usize] = 0; - } - } + buffer + .slice(..unpadded_size) + .get_mapped_range_mut() + .copy_from_slice(descriptor.contents); buffer.unmap(); buffer }