From 07bddd2a8c42f0cb906586f01eaaefb94dc34f7a Mon Sep 17 00:00:00 2001 From: Maximilian Ammann Date: Thu, 2 Jun 2022 15:04:06 +0200 Subject: [PATCH] Upgrade wgpu to git --- maplibre-build-tools/Cargo.toml | 2 +- maplibre-build-tools/src/wgsl.rs | 22 +++++--- maplibre/Cargo.toml | 4 +- maplibre/src/render/resource/surface.rs | 54 +++++++++---------- .../src/render/shaders/tile.fragment.wgsl | 6 +-- maplibre/src/render/shaders/tile.vertex.wgsl | 34 ++++++------ .../render/shaders/tile_mask.fragment.wgsl | 6 +-- .../src/render/shaders/tile_mask.vertex.wgsl | 26 ++++----- 8 files changed, 81 insertions(+), 73 deletions(-) diff --git a/maplibre-build-tools/Cargo.toml b/maplibre-build-tools/Cargo.toml index c7469d92..e44f51fe 100644 --- a/maplibre-build-tools/Cargo.toml +++ b/maplibre-build-tools/Cargo.toml @@ -12,7 +12,7 @@ readme = "../README.md" sqlite = ["rusqlite"] [dependencies] -naga = { version = "0.8", features = ["wgsl-in"] } +naga = { git = "https://github.com/gfx-rs/naga", branch = "master", features = ["wgsl-in"] } walkdir = "2.3" log = "0.4" rusqlite = {version= "0.26", optional=true} diff --git a/maplibre-build-tools/src/wgsl.rs b/maplibre-build-tools/src/wgsl.rs index eb5a1156..e7fd5e00 100644 --- a/maplibre-build-tools/src/wgsl.rs +++ b/maplibre-build-tools/src/wgsl.rs @@ -4,7 +4,7 @@ use std::process::exit; use naga::front::wgsl; use naga::valid::{Capabilities, ValidationFlags, Validator}; -use naga::{front::wgsl::ParseError, valid::ValidationError}; +use naga::{front::wgsl::ParseError, valid::ValidationError, SourceLocation}; use walkdir::WalkDir; #[derive(Debug)] @@ -12,8 +12,7 @@ pub enum WgslError { ValidationErr(ValidationError), ParserErr { error: String, - line: usize, - pos: usize, + location: Option, }, IoErr(std::io::Error), } @@ -26,9 +25,9 @@ impl From for WgslError { impl WgslError { pub fn from_parse_err(err: ParseError, src: &str) -> Self { - let (line, pos) = err.location(src); + let location = err.location(src); let error = err.emit_to_string(src); - Self::ParserErr { error, line, pos } + Self::ParserErr { error, location } } } @@ -72,8 +71,17 @@ pub fn validate_project_wgsl() { path.to_str().unwrap(), match err { WgslError::ValidationErr(error) => format!(": {:?}", error), - WgslError::ParserErr { error, line, pos } => - format!(":{}:{} {}", line, pos, error), + WgslError::ParserErr { error, location } => + if let Some(SourceLocation { + line_number, + line_position, + .. + }) = location + { + format!(":{}:{} {}", line_number, line_position, error) + } else { + format!("{}", error) + }, WgslError::IoErr(error) => format!(": {:?}", error), } ); diff --git a/maplibre/Cargo.toml b/maplibre/Cargo.toml index ac9de778..35ffbcb2 100644 --- a/maplibre/Cargo.toml +++ b/maplibre/Cargo.toml @@ -50,7 +50,9 @@ geozero = { version = "0.9.4", default-features = false, features = ["with-mvt", tile-grid = "0.3" # Rendering -wgpu = { version = "0.12" } +wgpu = { git = "https://github.com/gfx-rs/wgpu.git", branch = "master" } +wgpu-core = { git = "https://github.com/gfx-rs/wgpu.git", branch = "master" } +wgpu-hal = { git = "https://github.com/gfx-rs/wgpu.git", branch = "master" } lyon = { version = "0.17", features = [] } raw-window-handle = "0.4" diff --git a/maplibre/src/render/resource/surface.rs b/maplibre/src/render/resource/surface.rs index e18c3f83..3e56237d 100644 --- a/maplibre/src/render/resource/surface.rs +++ b/maplibre/src/render/resource/surface.rs @@ -71,42 +71,40 @@ impl BufferedTextureHead { ) { // Note that we're not calling `.await` here. let buffer_slice = self.output_buffer.slice(..); - let buffer_future = buffer_slice.map_async(wgpu::MapMode::Read); + let buffer_future = buffer_slice.map_async(wgpu::MapMode::Read, |_| ()); // Poll the device in a blocking manner so that our future resolves. // In an actual application, `device.poll(...)` should // be called in an event loop or on another thread. device.poll(wgpu::Maintain::Wait); - if let Ok(()) = buffer_future.await { - let padded_buffer = buffer_slice.get_mapped_range(); + let padded_buffer = buffer_slice.get_mapped_range(); - let mut png_encoder = png::Encoder::new( - File::create(png_output_path).unwrap(), - self.buffer_dimensions.width as u32, - self.buffer_dimensions.height as u32, - ); - png_encoder.set_depth(png::BitDepth::Eight); - png_encoder.set_color(png::ColorType::Rgba); - let mut png_writer = png_encoder - .write_header() - .unwrap() - .into_stream_writer_with_size(self.buffer_dimensions.unpadded_bytes_per_row) + let mut png_encoder = png::Encoder::new( + File::create(png_output_path).unwrap(), + self.buffer_dimensions.width as u32, + self.buffer_dimensions.height as u32, + ); + png_encoder.set_depth(png::BitDepth::Eight); + png_encoder.set_color(png::ColorType::Rgba); + let mut png_writer = png_encoder + .write_header() + .unwrap() + .into_stream_writer_with_size(self.buffer_dimensions.unpadded_bytes_per_row) + .unwrap(); + + // 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) { + png_writer + .write_all(&chunk[..self.buffer_dimensions.unpadded_bytes_per_row]) .unwrap(); - - // 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) { - png_writer - .write_all(&chunk[..self.buffer_dimensions.unpadded_bytes_per_row]) - .unwrap(); - } - png_writer.finish().unwrap(); - - // With the current interface, we have to make sure all mapped views are - // dropped before we unmap the buffer. - drop(padded_buffer); - - self.output_buffer.unmap(); } + png_writer.finish().unwrap(); + + // With the current interface, we have to make sure all mapped views are + // dropped before we unmap the buffer. + drop(padded_buffer); + + self.output_buffer.unmap(); } } diff --git a/maplibre/src/render/shaders/tile.fragment.wgsl b/maplibre/src/render/shaders/tile.fragment.wgsl index 62305297..977de422 100644 --- a/maplibre/src/render/shaders/tile.fragment.wgsl +++ b/maplibre/src/render/shaders/tile.fragment.wgsl @@ -1,8 +1,8 @@ struct Output { - [[location(0)]] out_color: vec4; + @location(0) out_color: vec4, }; -[[stage(fragment)]] -fn main([[location(0)]] v_color: vec4) -> Output { +@fragment +fn main(@location(0) v_color: vec4) -> Output { return Output(v_color); } diff --git a/maplibre/src/render/shaders/tile.vertex.wgsl b/maplibre/src/render/shaders/tile.vertex.wgsl index 74232d23..fd3ed512 100644 --- a/maplibre/src/render/shaders/tile.vertex.wgsl +++ b/maplibre/src/render/shaders/tile.vertex.wgsl @@ -1,31 +1,31 @@ struct ShaderCamera { - view_proj: mat4x4; - view_position: vec4; + view_proj: mat4x4, + view_position: vec4, }; struct ShaderGlobals { - camera: ShaderCamera; + camera: ShaderCamera, }; -[[group(0), binding(0)]] var globals: ShaderGlobals; +@group(0) @binding(0) var globals: ShaderGlobals; struct VertexOutput { - [[location(0)]] v_color: vec4; - [[builtin(position)]] position: vec4; + @location(0) v_color: vec4, + @builtin(position) position: vec4, }; -[[stage(vertex)]] +@vertex fn main( - [[location(0)]] position: vec2, - [[location(1)]] normal: vec2, - [[location(4)]] translate1: vec4, - [[location(5)]] translate2: vec4, - [[location(6)]] translate3: vec4, - [[location(7)]] translate4: vec4, - [[location(8)]] color: vec4, - [[location(9)]] zoom_factor: f32, - [[location(10)]] z_index: f32, - [[builtin(instance_index)]] instance_idx: u32 // instance_index is used when we have multiple instances of the same "object" + @location(0) position: vec2, + @location(1) normal: vec2, + @location(4) translate1: vec4, + @location(5) translate2: vec4, + @location(6) translate3: vec4, + @location(7) translate4: vec4, + @location(8) color: vec4, + @location(9) zoom_factor: f32, + @location(10) z_index: f32, + @builtin(instance_index) instance_idx: u32 // instance_index is used when we have multiple instances of the same "object" ) -> VertexOutput { let z = 0.0; let width = 3.0 * zoom_factor; diff --git a/maplibre/src/render/shaders/tile_mask.fragment.wgsl b/maplibre/src/render/shaders/tile_mask.fragment.wgsl index 62305297..977de422 100644 --- a/maplibre/src/render/shaders/tile_mask.fragment.wgsl +++ b/maplibre/src/render/shaders/tile_mask.fragment.wgsl @@ -1,8 +1,8 @@ struct Output { - [[location(0)]] out_color: vec4; + @location(0) out_color: vec4, }; -[[stage(fragment)]] -fn main([[location(0)]] v_color: vec4) -> Output { +@fragment +fn main(@location(0) v_color: vec4) -> Output { return Output(v_color); } diff --git a/maplibre/src/render/shaders/tile_mask.vertex.wgsl b/maplibre/src/render/shaders/tile_mask.vertex.wgsl index 5f899fdd..5d866e56 100644 --- a/maplibre/src/render/shaders/tile_mask.vertex.wgsl +++ b/maplibre/src/render/shaders/tile_mask.vertex.wgsl @@ -1,29 +1,29 @@ struct ShaderCamera { - view_proj: mat4x4; - view_position: vec4; + view_proj: mat4x4, + view_position: vec4, }; struct ShaderGlobal { - camera: ShaderCamera; + camera: ShaderCamera, }; -[[group(0), binding(0)]] var globals: ShaderGlobal; +@group(0) @binding(0) var globals: ShaderGlobal; struct VertexOutput { - [[location(0)]] v_color: vec4; - [[builtin(position)]] position: vec4; + @location(0) v_color: vec4, + @builtin(position) position: vec4, }; let EXTENT = 4096.0; -[[stage(vertex)]] +@vertex fn main( - [[location(4)]] translate1: vec4, - [[location(5)]] translate2: vec4, - [[location(6)]] translate3: vec4, - [[location(7)]] translate4: vec4, - [[builtin(vertex_index)]] vertex_idx: u32, - [[builtin(instance_index)]] instance_idx: u32 // instance_index is used when we have multiple instances of the same "object" + @location(4) translate1: vec4, + @location(5) translate2: vec4, + @location(6) translate3: vec4, + @location(7) translate4: vec4, + @builtin(vertex_index) vertex_idx: u32, + @builtin(instance_index) instance_idx: u32 // instance_index is used when we have multiple instances of the same "object" ) -> VertexOutput { let z = 0.0;