From c434b94ca20e9ccab8b0afdd7406c595dd37e7c3 Mon Sep 17 00:00:00 2001 From: Aron Granberg Date: Tue, 13 Jul 2021 16:26:24 +0200 Subject: [PATCH] Implicitly add `COPY_DST` when using `create_texture_with_data` (#1622) * Implicitly add `COPY_DST` when using `create_texture_with_data` * Always clone texture descriptor --- wgpu/src/util/device.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wgpu/src/util/device.rs b/wgpu/src/util/device.rs index b0a9b2323d..2e934d0cc6 100644 --- a/wgpu/src/util/device.rs +++ b/wgpu/src/util/device.rs @@ -26,6 +26,9 @@ pub trait DeviceExt { /// /// Example: /// Layer0Mip0 Layer0Mip1 Layer0Mip2 ... Layer1Mip0 Layer1Mip1 Layer1Mip2 ... + /// + /// Implicitly adds the `COPY_DST` usage if it is not present in the descriptor, + /// as it is required to be able to upload the data to the gpu. fn create_texture_with_data( &self, queue: &crate::Queue, @@ -79,7 +82,10 @@ impl DeviceExt for crate::Device { desc: &crate::TextureDescriptor, data: &[u8], ) -> crate::Texture { - let texture = self.create_texture(desc); + // Implicitly add the COPY_DST usage + let mut desc = desc.to_owned(); + desc.usage |= crate::TextureUsages::COPY_DST; + let texture = self.create_texture(&desc); let format_info = desc.format.describe(); let layer_iterations = desc.array_layer_count();