Skip to content

Commit

Permalink
Update wgpu to 0.19 (and other deps) (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximkaaa authored Feb 15, 2024
1 parent e8d4e07 commit 2e0fcf4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 36 deletions.
15 changes: 8 additions & 7 deletions galileo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ async-trait = "0.1.68"
bytemuck = { version = "1.14", features = ["derive"] }
bytes = "1.4.0"
futures = "0.3.28"
wgpu = { version = "0.18", optional = true }
winit = { version ="0.29", features = ["rwh_05"], optional = true }
winit = { version ="0.29", features = ["rwh_06"], optional = true }
log = "0.4"
lyon = { version = "1" }
galileo-types = { path = "../galileo-types", version = "0.1.1" }
galileo-mvt = { path = "../galileo-mvt", version = "0.1.1" }
num-traits = "0.2.17"
serde = { version = "1.0", optional = true, features = ["std", "derive"] }
web-time = "0.2"
web-time = "1.0"
thiserror = "1.0"
nalgebra = "0.32"
quick_cache = "0.4"
futures-intrusive = "0.5"
geojson = { version = "0.24", optional = true }
raw-window-handle = { version = "0.5", optional = true }
raw-window-handle = { version = "0.6", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
wgpu = { version = "0.19", optional = true }
tokio = { version = "1.28.2", features = ["macros", "rt", "rt-multi-thread" ] }
maybe-sync = { version = "0.1", features = ["sync"] }
reqwest = "0.11.18"
Expand All @@ -57,7 +57,7 @@ image = { version = "0.24", default-features = false, features = ["png", "jpeg"]
bytemuck = { version = "1.14", features = ["derive", "extern_crate_alloc"] }
console_error_panic_hook = "0.1"
console_log = "1.0"
wgpu = { version = "0.18", features = ["webgl"] }
wgpu = { version = "0.19", default-features = false, features = ["webgl", "wgsl"] }
wasm-bindgen-futures = { version = "0.4" }
wasm-bindgen = "0.2"
wasm-bindgen-derive = { version = "0.2" }
Expand All @@ -67,6 +67,7 @@ serde_bytes = { version = "0.11" }
bincode = "1.3"
serde-wasm-bindgen = "0.6"
maybe-sync = { version = "0.1", features = [] }
getrandom = { version = "0.2", features = ["js"] }
web-sys = { version = "0.3", features = [
"Document",
"Window",
Expand All @@ -92,7 +93,7 @@ winit = {version = "0.29", features = ["android-native-activity"] }

[dev-dependencies]
tokio-test = "0.4"
env_logger = "0.10"
env_logger = "0.11"
serde_json = "1.0"
notify = "6.1"
bincode = "1.3"
Expand All @@ -101,7 +102,7 @@ lazy_static = "1.4"
geo = "0.27"
csv = "1.3"
geo-types = "0.7"
geozero = "0.11"
geozero = "0.12"
las = { version = "0.8", features = ["laz"] }
anyhow = "1.0"
geojson = "0.24"
Expand Down
9 changes: 5 additions & 4 deletions galileo/examples/with_egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ version = "0.1.0"
name = "with_egui"

[dependencies]
egui = "0.25.0"
egui-wgpu = "0.25.0"
egui-winit = { version = "0.25.0", default-features = false }
egui = "0.26"
egui-wgpu = "0.26"
egui-winit = { version = "0.26", default-features = false }
env_logger = { version = "0.11", default-features = false }
galileo = { path = "../../../galileo" }
galileo-types = { path = "../../../galileo-types" }
wgpu = { version = "0.18", default-features = false }
wgpu = { version = "0.19", default-features = false }
winit = { version = "0.29", default-features = false }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.0", default-features = false, features = ["full"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies.egui-winit]
version = "0.26"
features = ["clipboard", "links", "wayland", "x11"]
6 changes: 3 additions & 3 deletions galileo/examples/with_egui/src/state/egui_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use egui::Context;
use egui_wgpu::renderer::ScreenDescriptor;
use egui_wgpu::Renderer;
use egui_wgpu::ScreenDescriptor;

use egui_winit::{EventResponse, State};
use wgpu::{Device, TextureFormat};
Expand Down Expand Up @@ -30,9 +30,9 @@ impl EguiState {
egui_context.set_visuals(visuals);
egui_context.set_pixels_per_point(window.scale_factor() as f32);

let egui_state = egui_winit::State::new(egui_context.clone(), id, &window, None, None);
let egui_state = State::new(egui_context.clone(), id, &window, None, None);

let egui_renderer = egui_wgpu::renderer::Renderer::new(
let egui_renderer = Renderer::new(
device,
output_color_format,
output_depth_format,
Expand Down
2 changes: 1 addition & 1 deletion galileo/examples/with_egui/src/state/galileo_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl GalileoState {
pub fn new(
window: Arc<Window>,
device: Arc<Device>,
surface: Arc<Surface>,
surface: Arc<Surface<'static>>,
queue: Arc<Queue>,
config: SurfaceConfiguration,
) -> Self {
Expand Down
11 changes: 6 additions & 5 deletions galileo/examples/with_egui/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct WgpuFrame<'frame> {
}

pub struct State {
pub surface: Arc<wgpu::Surface>,
pub surface: Arc<wgpu::Surface<'static>>,
pub device: Arc<wgpu::Device>,
pub queue: Arc<wgpu::Queue>,
pub config: wgpu::SurfaceConfiguration,
Expand All @@ -40,11 +40,11 @@ impl State {
..Default::default()
});

let surface = unsafe { instance.create_surface(&window) }.unwrap();
let surface = instance.create_surface(window.clone()).unwrap();

let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::default(),
power_preference: wgpu::PowerPreference::HighPerformance,
compatible_surface: Some(&surface),
force_fallback_adapter: false,
})
Expand All @@ -55,8 +55,8 @@ impl State {
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features: wgpu::Features::empty(),
limits: if cfg!(target_arch = "wasm32") {
required_features: wgpu::Features::empty(),
required_limits: if cfg!(target_arch = "wasm32") {
wgpu::Limits {
// NOTE(alexkirsz) These are the limits on my GPU w/ WebGPU,
// but your mileage may vary.
Expand Down Expand Up @@ -85,6 +85,7 @@ impl State {
width: size.width,
height: size.height,
present_mode: surface_caps.present_modes[0],
desired_maximum_frame_latency: 2,
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![],
};
Expand Down
2 changes: 1 addition & 1 deletion galileo/src/galileo_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl GalileoMap {
let size = window.inner_size();

let mut renderer = WgpuRenderer::new_with_window(
&window,
window.clone(),
Size::new(size.width, size.height),
)
.await
Expand Down
43 changes: 29 additions & 14 deletions galileo/src/render/wgpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use wgpu::{
ImageCopyBuffer, ImageCopyTexture, ImageDataLayout, Origin3d, Queue,
RenderPassDepthStencilAttachment, StoreOp, Surface, SurfaceConfiguration, SurfaceError,
SurfaceTexture, Texture, TextureAspect, TextureDescriptor, TextureDimension, TextureFormat,
TextureUsages, TextureView, TextureViewDescriptor,
TextureUsages, TextureView, TextureViewDescriptor, WasmNotSendSync,
};

use crate::error::GalileoError;
Expand Down Expand Up @@ -53,7 +53,7 @@ struct RenderSet {
enum RenderTarget {
Surface {
config: SurfaceConfiguration,
surface: Arc<Surface>,
surface: Arc<Surface<'static>>,
},
Texture(Texture, Size<u32>),
}
Expand Down Expand Up @@ -218,9 +218,12 @@ impl WgpuRenderer {
/// window size.
///
/// Returns `None` if a device adapter cannot be acquired.
pub async fn new_with_window<W>(window: &W, size: Size<u32>) -> Option<Self>
pub async fn new_with_window<W>(window: Arc<W>, size: Size<u32>) -> Option<Self>
where
W: raw_window_handle::HasRawWindowHandle + raw_window_handle::HasRawDisplayHandle,
W: raw_window_handle::HasWindowHandle
+ raw_window_handle::HasDisplayHandle
+ WasmNotSendSync
+ 'static,
{
let (surface, adapter) = Self::get_window_surface(window).await?;
let (device, queue) = Self::create_device(&adapter).await;
Expand All @@ -240,14 +243,17 @@ impl WgpuRenderer {
/// Creates a wgpu surface for the given window.
///
/// Returns `None` if a device adapter cannot be acquired.
pub async fn get_window_surface<W>(window: &W) -> Option<(Surface, Adapter)>
pub async fn get_window_surface<W>(window: Arc<W>) -> Option<(Surface<'static>, Adapter)>
where
W: raw_window_handle::HasRawWindowHandle + raw_window_handle::HasRawDisplayHandle,
W: raw_window_handle::HasWindowHandle
+ raw_window_handle::HasDisplayHandle
+ WasmNotSendSync
+ 'static,
{
let instance = Self::create_instance();

log::info!("Creating new surface");
let surface = match unsafe { instance.create_surface(window) } {
let surface = match instance.create_surface(window) {
Ok(s) => s,
Err(err) => {
log::warn!("Failed to create a surface from window: {err:?}");
Expand All @@ -257,7 +263,7 @@ impl WgpuRenderer {

let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::default(),
power_preference: wgpu::PowerPreference::HighPerformance,
compatible_surface: Some(&surface),
force_fallback_adapter: false,
})
Expand All @@ -284,6 +290,7 @@ impl WgpuRenderer {
width: size.width(),
height: size.height(),
present_mode: surface_caps.present_modes[0],
desired_maximum_frame_latency: 2,
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![],
}
Expand All @@ -292,7 +299,7 @@ impl WgpuRenderer {
/// Creates a new renderer from the initialized wgpu structs.
pub fn new_with_device_and_surface(
device: Arc<Device>,
surface: Arc<Surface>,
surface: Arc<Surface<'static>>,
queue: Arc<Queue>,
config: SurfaceConfiguration,
) -> Self {
Expand Down Expand Up @@ -339,8 +346,8 @@ impl WgpuRenderer {
adapter
.request_device(
&wgpu::DeviceDescriptor {
features: wgpu::Features::empty(),
limits: if cfg!(any(target_arch = "wasm32", target_os = "android")) {
required_features: wgpu::Features::empty(),
required_limits: if cfg!(any(target_arch = "wasm32", target_os = "android")) {
wgpu::Limits {
max_texture_dimension_2d: 4096,
..wgpu::Limits::downlevel_webgl2_defaults()
Expand Down Expand Up @@ -408,11 +415,14 @@ impl WgpuRenderer {
/// Returns an error if a device adapter cannot be acquired.
pub async fn init_with_window<W>(
&mut self,
window: &W,
window: Arc<W>,
size: Size<u32>,
) -> Result<(), GalileoError>
where
W: raw_window_handle::HasRawWindowHandle + raw_window_handle::HasRawDisplayHandle,
W: raw_window_handle::HasWindowHandle
+ raw_window_handle::HasDisplayHandle
+ WasmNotSendSync
+ 'static,
{
let Some((surface, adapter)) = Self::get_window_surface(window).await else {
return Err(GalileoError::Generic("Failed to create surface".into()));
Expand All @@ -423,7 +433,12 @@ impl WgpuRenderer {
}

/// Re-initializes the renderer with the given surface and adapter.
pub fn init_with_surface(&mut self, surface: Surface, adapter: Adapter, size: Size<u32>) {
pub fn init_with_surface(
&mut self,
surface: Surface<'static>,
adapter: Adapter,
size: Size<u32>,
) {
let config = Self::get_surface_configuration(&surface, &adapter, size);
surface.configure(&self.device, &config);

Expand Down
3 changes: 2 additions & 1 deletion galileo/src/render/wgpu/pipelines/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::render::wgpu::pipelines;
use crate::render::wgpu::pipelines::default_targets;
use crate::render::RenderOptions;
use std::sync::Arc;
use wgpu::util::DeviceExt;
use wgpu::util::{DeviceExt, TextureDataOrder};
use wgpu::{
BindGroup, BindGroupLayout, Device, Queue, RenderPass, RenderPipeline,
RenderPipelineDescriptor, TextureFormat,
Expand Down Expand Up @@ -110,6 +110,7 @@ impl ImagePipeline {
label: None,
view_formats: &[],
},
TextureDataOrder::default(),
&image.bytes,
);

Expand Down

0 comments on commit 2e0fcf4

Please sign in to comment.