summaryrefslogtreecommitdiffstats
path: root/wgpu/src/image
diff options
context:
space:
mode:
Diffstat (limited to 'wgpu/src/image')
-rw-r--r--wgpu/src/image/atlas.rs48
-rw-r--r--wgpu/src/image/raster.rs4
-rw-r--r--wgpu/src/image/vector.rs5
3 files changed, 38 insertions, 19 deletions
diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs
index 366fe623..e3de1290 100644
--- a/wgpu/src/image/atlas.rs
+++ b/wgpu/src/image/atlas.rs
@@ -13,6 +13,7 @@ use allocator::Allocator;
pub const SIZE: u32 = 2048;
use crate::core::Size;
+use crate::graphics::color;
#[derive(Debug)]
pub struct Atlas {
@@ -35,7 +36,11 @@ impl Atlas {
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
- format: wgpu::TextureFormat::Rgba8UnormSrgb,
+ format: if color::GAMMA_CORRECTION {
+ wgpu::TextureFormat::Rgba8UnormSrgb
+ } else {
+ wgpu::TextureFormat::Rgba8Unorm
+ },
usage: wgpu::TextureUsages::COPY_DST
| wgpu::TextureUsages::COPY_SRC
| wgpu::TextureUsages::TEXTURE_BINDING,
@@ -65,7 +70,6 @@ impl Atlas {
pub fn upload(
&mut self,
device: &wgpu::Device,
- queue: &wgpu::Queue,
encoder: &mut wgpu::CommandEncoder,
width: u32,
height: u32,
@@ -112,7 +116,8 @@ impl Atlas {
padding,
0,
allocation,
- queue,
+ device,
+ encoder,
);
}
Entry::Fragmented { fragments, .. } => {
@@ -127,7 +132,8 @@ impl Atlas {
padding,
offset,
&fragment.allocation,
- queue,
+ device,
+ encoder,
);
}
}
@@ -280,8 +286,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 +301,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 +327,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,
);
}
@@ -333,7 +351,11 @@ impl Atlas {
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
- format: wgpu::TextureFormat::Rgba8UnormSrgb,
+ format: if color::GAMMA_CORRECTION {
+ wgpu::TextureFormat::Rgba8UnormSrgb
+ } else {
+ wgpu::TextureFormat::Rgba8Unorm
+ },
usage: wgpu::TextureUsages::COPY_DST
| wgpu::TextureUsages::COPY_SRC
| wgpu::TextureUsages::TEXTURE_BINDING,
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);