From 4945edcd0b89042bc2e70404fdfe9cfa9cf8b76c Mon Sep 17 00:00:00 2001 From: Max Ammann Date: Mon, 10 Apr 2023 19:53:19 -0400 Subject: [PATCH] Upgrade to wgpu from this PR: gfx-rs/wgpu#3657 (#272) --- maplibre/Cargo.toml | 3 ++- maplibre/src/raster/upload_system.rs | 4 ++-- maplibre/src/render/resource/surface.rs | 29 +++++++++++-------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/maplibre/Cargo.toml b/maplibre/Cargo.toml index 86142dfe..2867e727 100644 --- a/maplibre/Cargo.toml +++ b/maplibre/Cargo.toml @@ -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" diff --git a/maplibre/src/raster/upload_system.rs b/maplibre/src/raster/upload_system.rs index 6623fa0e..0d5265a3 100644 --- a/maplibre/src/raster/upload_system.rs +++ b/maplibre/src/raster/upload_system.rs @@ -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, ); diff --git a/maplibre/src/render/resource/surface.rs b/maplibre/src/render/resource/surface.rs index c1435714..289fec18 100644 --- a/maplibre/src/render/resource/surface.rs +++ b/maplibre/src/render/resource/surface.rs @@ -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, });