summaryrefslogtreecommitdiffstats
path: root/wgpu/src/image
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-07 22:53:08 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-02-24 13:37:31 +0100
commit363966ee9e7aa81a3679eaea776d2c867aa6c3b0 (patch)
treedf76191179cf23da9153ab00dc91791d7113d829 /wgpu/src/image
parent34c963f7b39e3f16b55665a978948ead5b869f0f (diff)
downloadiced-363966ee9e7aa81a3679eaea776d2c867aa6c3b0.tar.gz
iced-363966ee9e7aa81a3679eaea776d2c867aa6c3b0.tar.bz2
iced-363966ee9e7aa81a3679eaea776d2c867aa6c3b0.zip
Refactor `image::Pipeline` into `prepare` and `render` architecture
Diffstat (limited to 'wgpu/src/image')
-rw-r--r--wgpu/src/image/atlas.rs49
1 files changed, 24 insertions, 25 deletions
diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs
index eafe2f96..7df67abd 100644
--- a/wgpu/src/image/atlas.rs
+++ b/wgpu/src/image/atlas.rs
@@ -185,13 +185,13 @@ impl Atlas {
fn upload_allocation(
&mut self,
- buffer: &wgpu::Buffer,
+ data: &[u8],
image_width: u32,
image_height: u32,
padding: u32,
offset: usize,
allocation: &Allocation,
- encoder: &mut wgpu::CommandEncoder,
+ queue: &wgpu::Queue,
) {
let (x, y) = allocation.position();
let Size { width, height } = allocation.size();
@@ -203,15 +203,7 @@ impl Atlas {
depth_or_array_layers: 1,
};
- encoder.copy_buffer_to_texture(
- wgpu::ImageCopyBuffer {
- buffer,
- layout: wgpu::ImageDataLayout {
- offset: offset as u64,
- bytes_per_row: NonZeroU32::new(4 * image_width + padding),
- rows_per_image: NonZeroU32::new(image_height),
- },
- },
+ queue.write_texture(
wgpu::ImageCopyTexture {
texture: &self.texture,
mip_level: 0,
@@ -222,6 +214,12 @@ impl Atlas {
},
aspect: wgpu::TextureAspect::default(),
},
+ data,
+ wgpu::ImageDataLayout {
+ offset: offset as u64,
+ bytes_per_row: NonZeroU32::new(4 * image_width + padding),
+ rows_per_image: NonZeroU32::new(image_height),
+ },
extent,
);
}
@@ -301,17 +299,19 @@ impl Atlas {
impl image::Storage for Atlas {
type Entry = Entry;
- type State<'a> = (&'a wgpu::Device, &'a mut wgpu::CommandEncoder);
+ type State<'a> = (
+ &'a wgpu::Device,
+ &'a wgpu::Queue,
+ &'a mut wgpu::CommandEncoder,
+ );
fn upload(
&mut self,
width: u32,
height: u32,
data: &[u8],
- (device, encoder): &mut Self::State<'_>,
+ (device, queue, encoder): &mut Self::State<'_>,
) -> Option<Self::Entry> {
- use wgpu::util::DeviceExt;
-
let entry = {
let current_size = self.layers.len();
let entry = self.allocate(width, height)?;
@@ -344,17 +344,16 @@ impl image::Storage for Atlas {
)
}
- let buffer =
- device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
- label: Some("iced_wgpu::image staging buffer"),
- contents: &padded_data,
- usage: wgpu::BufferUsages::COPY_SRC,
- });
-
match &entry {
Entry::Contiguous(allocation) => {
self.upload_allocation(
- &buffer, width, height, padding, 0, allocation, encoder,
+ &padded_data,
+ width,
+ height,
+ padding,
+ 0,
+ allocation,
+ queue,
);
}
Entry::Fragmented { fragments, .. } => {
@@ -363,13 +362,13 @@ impl image::Storage for Atlas {
let offset = (y * padded_width as u32 + 4 * x) as usize;
self.upload_allocation(
- &buffer,
+ &padded_data,
width,
height,
padding,
offset,
&fragment.allocation,
- encoder,
+ queue,
);
}
}