summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-05-12 11:53:02 +0200
committerLibravatar GitHub <noreply@github.com>2023-05-12 11:53:02 +0200
commit9706c99310d6fc7fedf40e579e652634ad8c2a87 (patch)
tree4db36140bff155342995d34ddc21ce93ceb2e8d7
parentcf434236e7e15e0fa05e5915b8d4d78dcaf1b7e8 (diff)
parent0ef5ab6c84643784d37801598c68a259f0ca64ff (diff)
downloadiced-9706c99310d6fc7fedf40e579e652634ad8c2a87.tar.gz
iced-9706c99310d6fc7fedf40e579e652634ad8c2a87.tar.bz2
iced-9706c99310d6fc7fedf40e579e652634ad8c2a87.zip
Merge pull request #1847 from iced-rs/fix/image-atlas-race-condition
Fix race condition when growing an `image::Atlas`
-rw-r--r--wgpu/src/image.rs2
-rw-r--r--wgpu/src/image/atlas.rs35
-rw-r--r--wgpu/src/image/raster.rs4
-rw-r--r--wgpu/src/image/vector.rs5
4 files changed, 27 insertions, 19 deletions
diff --git a/wgpu/src/image.rs b/wgpu/src/image.rs
index 263bcfa2..dd297a79 100644
--- a/wgpu/src/image.rs
+++ b/wgpu/src/image.rs
@@ -369,7 +369,6 @@ impl Pipeline {
layer::Image::Raster { handle, bounds } => {
if let Some(atlas_entry) = raster_cache.upload(
device,
- queue,
encoder,
handle,
&mut self.texture_atlas,
@@ -395,7 +394,6 @@ impl Pipeline {
if let Some(atlas_entry) = vector_cache.upload(
device,
- queue,
encoder,
handle,
*color,
diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs
index 366fe623..9b6dcc46 100644
--- a/wgpu/src/image/atlas.rs
+++ b/wgpu/src/image/atlas.rs
@@ -65,7 +65,6 @@ impl Atlas {
pub fn upload(
&mut self,
device: &wgpu::Device,
- queue: &wgpu::Queue,
encoder: &mut wgpu::CommandEncoder,
width: u32,
height: u32,
@@ -112,7 +111,8 @@ impl Atlas {
padding,
0,
allocation,
- queue,
+ device,
+ encoder,
);
}
Entry::Fragmented { fragments, .. } => {
@@ -127,7 +127,8 @@ impl Atlas {
padding,
offset,
&fragment.allocation,
- queue,
+ device,
+ encoder,
);
}
}
@@ -280,8 +281,11 @@ impl Atlas {
padding: u32,
offset: usize,
allocation: &Allocation,
- queue: &wgpu::Queue,
+ device: &wgpu::Device,
+ encoder: &mut wgpu::CommandEncoder,
) {
+ use wgpu::util::DeviceExt;
+
let (x, y) = allocation.position();
let Size { width, height } = allocation.size();
let layer = allocation.layer();
@@ -292,7 +296,22 @@ impl Atlas {
depth_or_array_layers: 1,
};
- queue.write_texture(
+ let buffer =
+ device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
+ label: Some("image upload buffer"),
+ contents: data,
+ usage: wgpu::BufferUsages::COPY_SRC,
+ });
+
+ encoder.copy_buffer_to_texture(
+ wgpu::ImageCopyBuffer {
+ buffer: &buffer,
+ layout: wgpu::ImageDataLayout {
+ offset: offset as u64,
+ bytes_per_row: Some(4 * image_width + padding),
+ rows_per_image: Some(image_height),
+ },
+ },
wgpu::ImageCopyTexture {
texture: &self.texture,
mip_level: 0,
@@ -303,12 +322,6 @@ impl Atlas {
},
aspect: wgpu::TextureAspect::default(),
},
- data,
- wgpu::ImageDataLayout {
- offset: offset as u64,
- bytes_per_row: Some(4 * image_width + padding),
- rows_per_image: Some(image_height),
- },
extent,
);
}
diff --git a/wgpu/src/image/raster.rs b/wgpu/src/image/raster.rs
index 9b38dce4..a6cba76a 100644
--- a/wgpu/src/image/raster.rs
+++ b/wgpu/src/image/raster.rs
@@ -63,7 +63,6 @@ impl Cache {
pub fn upload(
&mut self,
device: &wgpu::Device,
- queue: &wgpu::Queue,
encoder: &mut wgpu::CommandEncoder,
handle: &image::Handle,
atlas: &mut Atlas,
@@ -73,8 +72,7 @@ impl Cache {
if let Memory::Host(image) = memory {
let (width, height) = image.dimensions();
- let entry =
- atlas.upload(device, queue, encoder, width, height, image)?;
+ let entry = atlas.upload(device, encoder, width, height, image)?;
*memory = Memory::Device(entry);
}
diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs
index 58bdf64a..6b9be651 100644
--- a/wgpu/src/image/vector.rs
+++ b/wgpu/src/image/vector.rs
@@ -74,7 +74,6 @@ impl Cache {
pub fn upload(
&mut self,
device: &wgpu::Device,
- queue: &wgpu::Queue,
encoder: &mut wgpu::CommandEncoder,
handle: &svg::Handle,
color: Option<Color>,
@@ -138,8 +137,8 @@ impl Cache {
});
}
- let allocation = atlas
- .upload(device, queue, encoder, width, height, &rgba)?;
+ let allocation =
+ atlas.upload(device, encoder, width, height, &rgba)?;
log::debug!("allocating {} {}x{}", id, width, height);