From bff018f6af38d8632ebefa54992167baeec7a2aa Mon Sep 17 00:00:00 2001 From: Matheus Rangel <67433366+devrangel@users.noreply.github.com> Date: Sat, 18 Jan 2025 22:59:56 -0300 Subject: [PATCH] Upgrade to wgpu 24 (#127) --- Cargo.toml | 4 ++-- benches/state.rs | 14 +++++++++++--- examples/custom-glyphs.rs | 2 +- examples/hello-world.rs | 2 +- examples/text-sizes.rs | 2 +- src/text_atlas.rs | 6 +++--- src/text_render.rs | 8 ++++---- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a48b84b..0bffd3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/grovesNL/glyphon" license = "MIT OR Apache-2.0 OR Zlib" [dependencies] -wgpu = { version = "23", default-features = false, features = ["wgsl"] } +wgpu = { version = "24", default-features = false, features = ["wgsl"] } etagere = "0.2.10" cosmic-text = "0.12" lru = { version = "0.12.1", default-features = false } @@ -16,7 +16,7 @@ rustc-hash = "2.0" [dev-dependencies] winit = "0.30.3" -wgpu = "23" +wgpu = "24" resvg = { version = "0.44", default-features = false } pollster = "0.4.0" criterion = { version = "0.5", features = ["html_reports"] } diff --git a/benches/state.rs b/benches/state.rs index c1fd4d5..c408e50 100644 --- a/benches/state.rs +++ b/benches/state.rs @@ -1,3 +1,5 @@ +use wgpu::{BackendOptions, Dx12BackendOptions}; + use pollster::block_on; pub struct State { @@ -7,11 +9,17 @@ pub struct State { impl State { pub fn new() -> Self { - let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { + let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor { backends: wgpu::Backends::all(), flags: wgpu::InstanceFlags::empty(), - dx12_shader_compiler: wgpu::Dx12Compiler::Fxc, - gles_minor_version: wgpu::Gles3MinorVersion::Automatic, + backend_options: BackendOptions { + gl: wgpu::GlBackendOptions { + gles_minor_version: wgpu::Gles3MinorVersion::Automatic + }, + dx12: Dx12BackendOptions { + shader_compiler: wgpu::Dx12Compiler::Fxc + }, + } }); let adapter = block_on(wgpu::util::initialize_adapter_from_env_or_default( diff --git a/examples/custom-glyphs.rs b/examples/custom-glyphs.rs index 98f6616..d8bf3c9 100644 --- a/examples/custom-glyphs.rs +++ b/examples/custom-glyphs.rs @@ -47,7 +47,7 @@ impl WindowState { let scale_factor = window.scale_factor(); // Set up surface - let instance = Instance::new(InstanceDescriptor::default()); + let instance = Instance::new(&InstanceDescriptor::default()); let adapter = instance .request_adapter(&RequestAdapterOptions::default()) .await diff --git a/examples/hello-world.rs b/examples/hello-world.rs index 51c5c49..38fb917 100644 --- a/examples/hello-world.rs +++ b/examples/hello-world.rs @@ -43,7 +43,7 @@ impl WindowState { let scale_factor = window.scale_factor(); // Set up surface - let instance = Instance::new(InstanceDescriptor::default()); + let instance = Instance::new(&InstanceDescriptor::default()); let adapter = instance .request_adapter(&RequestAdapterOptions::default()) .await diff --git a/examples/text-sizes.rs b/examples/text-sizes.rs index 6296a75..9f1392b 100644 --- a/examples/text-sizes.rs +++ b/examples/text-sizes.rs @@ -62,7 +62,7 @@ impl WindowState { let scale_factor = window.scale_factor() as f32; // Set up surface - let instance = Instance::new(InstanceDescriptor::default()); + let instance = Instance::new(&InstanceDescriptor::default()); let adapter = instance .request_adapter(&RequestAdapterOptions::default()) .await diff --git a/src/text_atlas.rs b/src/text_atlas.rs index ca91801..2c9f28c 100644 --- a/src/text_atlas.rs +++ b/src/text_atlas.rs @@ -7,7 +7,7 @@ use lru::LruCache; use rustc_hash::FxHasher; use std::{collections::HashSet, hash::BuildHasherDefault, sync::Arc}; use wgpu::{ - BindGroup, DepthStencilState, Device, Extent3d, ImageCopyTexture, ImageDataLayout, + BindGroup, DepthStencilState, Device, Extent3d, TexelCopyTextureInfo, TexelCopyBufferLayout, MultisampleState, Origin3d, Queue, RenderPipeline, Texture, TextureAspect, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages, TextureView, TextureViewDescriptor, }; @@ -186,7 +186,7 @@ impl InnerAtlas { }; queue.write_texture( - ImageCopyTexture { + TexelCopyTextureInfo { texture: &self.texture, mip_level: 0, origin: Origin3d { @@ -197,7 +197,7 @@ impl InnerAtlas { aspect: TextureAspect::All, }, &image_data, - ImageDataLayout { + TexelCopyBufferLayout { offset: 0, bytes_per_row: Some(width as u32 * self.kind.num_channels() as u32), rows_per_image: None, diff --git a/src/text_render.rs b/src/text_render.rs index cb7bce2..3189ab3 100644 --- a/src/text_render.rs +++ b/src/text_render.rs @@ -6,8 +6,8 @@ use crate::{ use cosmic_text::{Color, SubpixelBin}; use std::{slice, sync::Arc}; use wgpu::{ - Buffer, BufferDescriptor, BufferUsages, DepthStencilState, Device, Extent3d, ImageCopyTexture, - ImageDataLayout, MultisampleState, Origin3d, Queue, RenderPass, RenderPipeline, TextureAspect, + Buffer, BufferDescriptor, BufferUsages, DepthStencilState, Device, Extent3d, TexelCopyTextureInfo, + TexelCopyBufferLayout, MultisampleState, Origin3d, Queue, RenderPass, RenderPipeline, TextureAspect, COPY_BUFFER_ALIGNMENT, }; @@ -468,7 +468,7 @@ where let atlas_min = allocation.rectangle.min; queue.write_texture( - ImageCopyTexture { + TexelCopyTextureInfo { texture: &inner.texture, mip_level: 0, origin: Origin3d { @@ -479,7 +479,7 @@ where aspect: TextureAspect::All, }, &image.data, - ImageDataLayout { + TexelCopyBufferLayout { offset: 0, bytes_per_row: Some(image.width as u32 * inner.num_channels() as u32), rows_per_image: None,