Upgrade to wgpu from this PR: gfx-rs/wgpu#3657 (#272)

This commit is contained in:
Max Ammann 2023-04-10 19:53:19 -04:00 committed by GitHub
parent bca19c8ace
commit 4945edcd0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 19 deletions

View File

@ -55,7 +55,8 @@ geozero = { version = "0.9.7", default-features = false, features = ["with-mvt",
tile-grid = "0.3.0"
# Rendering
wgpu = "0.15.0"
#wgpu = "0.15.0"
wgpu = { git = "https://github.com/gfx-rs/wgpu.git", rev = "cfc038aeb9b732019dc03fa7eeaac1c7f37fc71f" }
# wgpu = { git = "https://github.com/gfx-rs/wgpu" }
lyon = { version = "1.0.0", features = [] }
raw-window-handle = "0.5.0"

View File

@ -93,8 +93,8 @@ fn upload_raster_layer(
image,
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: std::num::NonZeroU32::new(4 * width),
rows_per_image: std::num::NonZeroU32::new(height),
bytes_per_row: Some(4 * width),
rows_per_image: Some(height),
},
texture.size,
);

View File

@ -1,7 +1,7 @@
//! Utilities for handling surfaces which can be either headless or headed. A headed surface has
//! a handle to a window. A headless surface renders to a texture.
use std::{mem::size_of, num::NonZeroU32, sync::Arc};
use std::{mem::size_of, sync::Arc};
use wgpu::TextureFormatFeatures;
@ -18,8 +18,8 @@ use crate::{
pub struct BufferDimensions {
pub width: u32,
pub height: u32,
pub unpadded_bytes_per_row: NonZeroU32,
pub padded_bytes_per_row: NonZeroU32,
pub unpadded_bytes_per_row: u32,
pub padded_bytes_per_row: u32,
}
impl BufferDimensions {
@ -33,9 +33,8 @@ impl BufferDimensions {
Self {
width: size.width(),
height: size.height(),
unpadded_bytes_per_row: NonZeroU32::new(unpadded_bytes_per_row)
.expect("can not be zero"), // expect is fine because this can never happen
padded_bytes_per_row: NonZeroU32::new(padded_bytes_per_row).expect("can not be zero"),
unpadded_bytes_per_row,
padded_bytes_per_row,
}
}
}
@ -133,16 +132,14 @@ impl BufferedTextureHead {
);
png_encoder.set_depth(png::BitDepth::Eight);
png_encoder.set_color(png::ColorType::Rgba);
let mut png_writer = png_encoder.write_header()?.into_stream_writer_with_size(
self.buffer_dimensions.unpadded_bytes_per_row.get() as usize,
)?;
let mut png_writer = png_encoder
.write_header()?
.into_stream_writer_with_size(self.buffer_dimensions.unpadded_bytes_per_row as usize)?;
// from the padded_buffer we write just the unpadded bytes into the image
for chunk in
padded_buffer.chunks(self.buffer_dimensions.padded_bytes_per_row.get() as usize)
{
for chunk in padded_buffer.chunks(self.buffer_dimensions.padded_bytes_per_row as usize) {
png_writer
.write_all(&chunk[..self.buffer_dimensions.unpadded_bytes_per_row.get() as usize])?
.write_all(&chunk[..self.buffer_dimensions.unpadded_bytes_per_row as usize])?
}
png_writer.finish()?;
Ok(())
@ -156,7 +153,7 @@ impl BufferedTextureHead {
&self.output_buffer
}
pub fn bytes_per_row(&self) -> NonZeroU32 {
pub fn bytes_per_row(&self) -> u32 {
self.buffer_dimensions.padded_bytes_per_row
}
}
@ -190,7 +187,7 @@ impl Surface {
.texture_format
.or_else(|| capabilities.formats.first().cloned())
.unwrap_or(wgpu::TextureFormat::Rgba8Unorm);
log::info!("format description: {:?}", texture_format.describe());
log::info!("format description: {:?}", texture_format);
let texture_format_features = adapter.get_texture_format_features(texture_format);
log::info!("format features: {:?}", texture_format_features);
@ -223,7 +220,7 @@ impl Surface {
// The output buffer lets us retrieve the data as an array
let output_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("BufferedTextureHead buffer"),
size: (buffer_dimensions.padded_bytes_per_row.get() * buffer_dimensions.height) as u64,
size: (buffer_dimensions.padded_bytes_per_row * buffer_dimensions.height) as u64,
usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});