diff --git a/Cargo.toml b/Cargo.toml index bf0b3812..d59a3ced 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,7 +81,7 @@ cpal = { path = "crates/vendor/cpal" } [workspace.dependencies.wgt] package = "wgpu-types" git = "https://github.com/triniwiz/wgpu" -rev = "04e9fef72" +rev = "87e00d492" @@ -103,8 +103,8 @@ quick-xml = "0.34" skia-safe = { git = "https://github.com/triniwiz/rust-skia", rev = "ab0e73f003ad675277ce2e7fdc1c57fd276ed04c", features = ["textlayout"] } itertools = "0.14.0" ustr = "1.1.0" -wgpu-core = { git = "https://github.com/triniwiz/wgpu", rev = "04e9fef72", features = ["wgsl"] } -wgpu-hal = { git = "https://github.com/triniwiz/wgpu", rev = "04e9fef72" } +wgpu-core = { git = "https://github.com/triniwiz/wgpu", rev = "87e00d492", features = ["wgsl"] } +wgpu-hal = { git = "https://github.com/triniwiz/wgpu", rev = "87e00d492" } ureq = "2.10.1" jni = "0.21.1" regex-lite = "0.1.9" diff --git a/crates/canvas-c/src/webgpu/enums.rs b/crates/canvas-c/src/webgpu/enums.rs index b01af3d1..582886e3 100644 --- a/crates/canvas-c/src/webgpu/enums.rs +++ b/crates/canvas-c/src/webgpu/enums.rs @@ -1439,6 +1439,7 @@ pub enum CanvasVertexFormat { Float64x4 = 42, Unorm10_10_10_2 = 43, Unorm8x4Bgra = 44, + Snorm10_10_10_2 = 45, } impl CanvasVertexFormat { @@ -1467,6 +1468,7 @@ impl CanvasVertexFormat { | Self::Uint32 | Self::Sint32 | Self::Unorm10_10_10_2 + | Self::Snorm10_10_10_2 | Self::Unorm8x4Bgra => 4, Self::Uint16x4 | Self::Sint16x4 @@ -1523,6 +1525,7 @@ impl From for CanvasVertexFormat { wgt::VertexFormat::Float64x3 => Self::Float64x3, wgt::VertexFormat::Float64x4 => Self::Float64x4, wgt::VertexFormat::Unorm10_10_10_2 => Self::Unorm10_10_10_2, + wgt::VertexFormat::Snorm10_10_10_2 => Self::Snorm10_10_10_2, VertexFormat::Uint8 => Self::Uint8, VertexFormat::Sint8 => Self::Sint8, VertexFormat::Unorm8 => Self::Unorm8, @@ -1575,6 +1578,7 @@ impl Into for CanvasVertexFormat { Self::Float64x3 => wgt::VertexFormat::Float64x3, Self::Float64x4 => wgt::VertexFormat::Float64x4, Self::Unorm10_10_10_2 => wgt::VertexFormat::Unorm10_10_10_2, + Self::Snorm10_10_10_2 => wgt::VertexFormat::Snorm10_10_10_2, Self::Uint8 => VertexFormat::Uint8, Self::Sint8 => VertexFormat::Sint8, Self::Unorm8 => VertexFormat::Unorm8, @@ -2262,7 +2266,9 @@ impl Into for CanvasBindGroupLayoutEntry { use std::num::NonZeroU64; BindGroupLayoutEntry { binding: self.binding, - visibility: wgt::ShaderStages::from_bits(self.visibility).unwrap(), + visibility: wgt::ShaderStages::from( + wgt::ShaderStagesWebGPU::from_bits(self.visibility).unwrap(), + ), ty: match self.binding_type { CanvasBindingType::Buffer(buffer) => wgt::BindingType::Buffer { ty: buffer.type_.into(), diff --git a/crates/canvas-c/src/webgpu/error.rs b/crates/canvas-c/src/webgpu/error.rs index b1c218a0..1834c264 100644 --- a/crates/canvas-c/src/webgpu/error.rs +++ b/crates/canvas-c/src/webgpu/error.rs @@ -177,10 +177,10 @@ impl From for CanvasGPUError { } } -impl From for CanvasGPUError { - fn from(value: wgpu_core::pipeline::CreateRenderPipelineError) -> Self { +impl From for CanvasGPUError { + fn from(value: wgpu_core::pipeline::CreatePipelineError) -> Self { match value { - wgpu_core::pipeline::CreateRenderPipelineError::Device(err) => err.into(), + wgpu_core::pipeline::CreatePipelineError::Device(err) => err.into(), err => CanvasGPUError::Validation(fmt_err(&err)), } } @@ -254,15 +254,6 @@ impl From for CanvasGPUError { } } -impl From for CanvasGPUError { - fn from(err: wgpu_core::pipeline::CreateComputePipelineError) -> Self { - match err { - wgpu_core::pipeline::CreateComputePipelineError::Device(err) => err.into(), - err => CanvasGPUError::Validation(fmt_err(&err)), - } - } -} - impl From for CanvasGPUError { fn from(err: wgpu_core::binding_model::GetBindGroupLayoutError) -> Self { CanvasGPUError::Validation(fmt_err(&err)) diff --git a/crates/canvas-c/src/webgpu/gpu_buffer.rs b/crates/canvas-c/src/webgpu/gpu_buffer.rs index aefa71c4..b877a0e4 100644 --- a/crates/canvas-c/src/webgpu/gpu_buffer.rs +++ b/crates/canvas-c/src/webgpu/gpu_buffer.rs @@ -37,20 +37,20 @@ pub enum GPUMapMode { Write, } -impl Into for GPUMapMode { - fn into(self) -> wgpu_core::device::HostMap { +impl Into for GPUMapMode { + fn into(self) -> wgt::MapMode { match self { - Self::Read => wgpu_core::device::HostMap::Read, - Self::Write => wgpu_core::device::HostMap::Write, + Self::Read => wgt::MapMode::Read, + Self::Write => wgt::MapMode::Write, } } } -impl From for GPUMapMode { - fn from(value: wgpu_core::device::HostMap) -> Self { +impl From for GPUMapMode { + fn from(value: wgt::MapMode) -> Self { match value { - wgpu_core::device::HostMap::Read => Self::Read, - wgpu_core::device::HostMap::Write => Self::Write, + wgt::MapMode::Read => Self::Read, + wgt::MapMode::Write => Self::Write, } } } @@ -151,7 +151,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_buffer_get_mapped_range( let range = buffer.buffer.get_mapped_range(offset, size); match range { - Ok((buf, _)) => buf.as_ptr() as *mut c_void, + Ok(mapping) => mapping.ptr().as_ptr() as *mut c_void, Err(err) => { handle_error_fatal(err, "canvas_native_webgpu_buffer_get_mapped_range"); std::ptr::null_mut() @@ -174,7 +174,7 @@ pub unsafe fn canvas_native_webgpu_buffer_get_mapped_range_size( let range = buffer.buffer.get_mapped_range(offset, size); match range { - Ok((buf, size)) => (buf.as_ptr() as *mut c_void, size), + Ok(mapping) => (mapping.ptr().as_ptr() as *mut c_void, mapping.len()), Err(err) => { handle_error_fatal(err, "canvas_native_webgpu_buffer_get_mapped_range"); (std::ptr::null_mut(), 0) @@ -221,47 +221,46 @@ pub extern "C" fn canvas_native_webgpu_buffer_map_async( let callback = callback as i64; let callback_data = callback_data as i64; - let op = wgpu_core::resource::BufferMapOperation { - host: mode.into(), - callback: Some( - (Box::new(move |result| { - let callback = unsafe { - std::mem::transmute::< - *const i64, - fn(CanvasGPUErrorType, *mut c_char, *mut c_void), - >(callback as _) - }; - let callback_data = callback_data as *mut c_void; - if let Err(error) = result { - let error: CanvasGPUError = error.into(); - let (typ, msg) = match error { - CanvasGPUError::None => (CanvasGPUErrorType::None, None), - CanvasGPUError::Lost => (CanvasGPUErrorType::Lost, None), - CanvasGPUError::OutOfMemory => (CanvasGPUErrorType::OutOfMemory, None), - CanvasGPUError::Validation(value) => ( - CanvasGPUErrorType::Validation, - Some(CString::new(value).unwrap()), - ), - CanvasGPUError::Internal => (CanvasGPUErrorType::Internal, None), - }; - - let msg = msg - .map(|value| value.into_raw()) - .unwrap_or(std::ptr::null_mut()); - - callback(typ, msg, callback_data); - } else { - callback( - CanvasGPUErrorType::None, - std::ptr::null_mut(), - callback_data, - ); - } - })), - ), - }; + let mode: wgt::MapMode = mode.into(); + let callback: wgpu_core::resource::BufferMapCallback = Box::new(move |result| { + let callback = unsafe { + std::mem::transmute::<*const i64, fn(CanvasGPUErrorType, *mut c_char, *mut c_void)>( + callback as _, + ) + }; + let callback_data = callback_data as *mut c_void; + if let Err(error) = result { + let error: CanvasGPUError = error.into(); + let (typ, msg) = match error { + CanvasGPUError::None => (CanvasGPUErrorType::None, None), + CanvasGPUError::Lost => (CanvasGPUErrorType::Lost, None), + CanvasGPUError::OutOfMemory => (CanvasGPUErrorType::OutOfMemory, None), + CanvasGPUError::Validation(value) => ( + CanvasGPUErrorType::Validation, + Some(CString::new(value).unwrap()), + ), + CanvasGPUError::Internal => (CanvasGPUErrorType::Internal, None), + }; + + let msg = msg + .map(|value| value.into_raw()) + .unwrap_or(std::ptr::null_mut()); + + callback(typ, msg, callback_data); + } else { + callback( + CanvasGPUErrorType::None, + std::ptr::null_mut(), + callback_data, + ); + } + }); - if buffer.buffer.map_async(offset, size, op).is_some() { + if buffer + .buffer + .map_async(mode, offset, size, Some(callback)) + .is_some() + { poll_mappings(Arc::clone(&buffer.instance)); } } diff --git a/crates/canvas-c/src/webgpu/gpu_canvas_context.rs b/crates/canvas-c/src/webgpu/gpu_canvas_context.rs index e3b8f4de..c4af7daf 100644 --- a/crates/canvas-c/src/webgpu/gpu_canvas_context.rs +++ b/crates/canvas-c/src/webgpu/gpu_canvas_context.rs @@ -143,7 +143,7 @@ fn configure_surface( device: &Arc, previous: Option<&wgt::SurfaceConfiguration>>, config: &wgt::SurfaceConfiguration>, -) -> Option { +) -> Result<(), wgpu_core::present::ConfigureSurfaceError> { #[cfg(all(target_os = "windows", feature = "d3d"))] if let Some(previous) = previous { let mut resized = previous.clone(); @@ -188,7 +188,7 @@ fn apply_pending_configuration( Some(&surface_data.previous_configuration), &config, ) { - None => { + Ok(()) => { surface_data.previous_configuration = config; surface_data.pending_failed = false; context @@ -196,7 +196,7 @@ fn apply_pending_configuration( .store(false, std::sync::atomic::Ordering::SeqCst); true } - Some(cause) => { + Err(cause) => { if !surface_data.pending_failed { surface_data.pending_failed = true; handle_error_fatal(cause, operation); @@ -318,6 +318,7 @@ fn offscreen_current_texture(context: &CanvasGPUCanvasContext) -> *const CanvasG format: data.format, usage, view_formats: surface_data.previous_configuration.view_formats.clone(), + texture_binding_view_dimension: None, }; let texture = surface_data.device.device.create_texture(&desc); *offscreen = Some(ReadBackTexture { @@ -646,14 +647,7 @@ fn with_mapped_texture( let id = encoder.finish(&wgt::CommandBufferDescriptor { label: None }); queue.queue.id.submit(&[id]); - output_buffer.map_async( - 0, - None, - wgpu_core::resource::BufferMapOperation { - host: wgpu_core::device::HostMap::Read, - callback: None, - }, - ); + output_buffer.map_async(wgt::MapMode::Read, 0, None, None); if device.device.poll(wgt::PollType::wait_indefinitely()).is_err() { output_buffer.destroy(); @@ -661,8 +655,8 @@ fn with_mapped_texture( } let result = match output_buffer.get_mapped_range(0, None) { - Ok((ptr, size)) => Some(f( - std::slice::from_raw_parts(ptr.as_ptr(), size as usize), + Ok(mapping) => Some(f( + std::slice::from_raw_parts(mapping.ptr().as_ptr(), mapping.len() as usize), row_bytes as usize, )), Err(_) => None, @@ -802,6 +796,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_resize_offscreen( format, usage: wgt::TextureUsages::COPY_SRC | wgt::TextureUsages::COPY_DST, view_formats: vec![], + texture_binding_view_dimension: None, }; let texture_data = TextureData { usage: desc.usage, @@ -954,6 +949,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_resize( | wgt::TextureUsages::COPY_DST.bits(), ), view_formats: vec![], + texture_binding_view_dimension: None, }; let texture_data = TextureData { usage: desc.usage, @@ -1170,6 +1166,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_resize_swap_chain_panel( format: surface_data.texture_data.format, usage: wgt::TextureUsages::COPY_SRC | wgt::TextureUsages::COPY_DST, view_formats: vec![], + texture_binding_view_dimension: None, }; let texture_data = TextureData { usage: desc.usage, @@ -1305,6 +1302,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_resize_uiview( | wgt::TextureUsages::COPY_DST.bits(), ), view_formats: vec![], + texture_binding_view_dimension: None, }; let texture_data = TextureData { @@ -1463,6 +1461,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_resize_nsview( | wgt::TextureUsages::COPY_DST.bits(), ), view_formats: vec![], + texture_binding_view_dimension: None, }; let texture_data = TextureData { usage: desc.usage, @@ -1486,7 +1485,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_resize_nsview( }); } - if let Some(cause) = + if let Err(cause) = surface_id.configure(&surface_data.device.device, &new_config) { handle_error_fatal(cause, "canvas_native_webgpu_context_resize_nsview"); @@ -1568,6 +1567,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_resize_layer( | wgt::TextureUsages::COPY_DST.bits(), ), view_formats: vec![], + texture_binding_view_dimension: None, }; let texture_data = TextureData { usage: desc.usage, @@ -1591,7 +1591,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_resize_layer( }); } - if let Some(cause) = + if let Err(cause) = surface_id.configure(&surface_data.device.device, &new_config) { handle_error_fatal(cause, "canvas_native_webgpu_context_resize_nsview"); @@ -1835,6 +1835,7 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_configure( wgt::TextureUsages::COPY_SRC.bits() | wgt::TextureUsages::COPY_DST.bits(), ), view_formats: vec![], + texture_binding_view_dimension: None, }; let texture_data = TextureData { @@ -1874,9 +1875,9 @@ pub unsafe extern "C" fn canvas_native_webgpu_context_configure( discard_current_texture(&context, "canvas_native_webgpu_context_configure"); configure_surface(surface, &device_id, previous.as_ref(), &config) } - _ => None, + _ => Ok(()), }; - if let Some(cause) = error { + if let Err(cause) = error { handle_error_fatal(cause, "canvas_native_webgpu_context_configure"); let mut lock = context.data.lock(); *lock = None; @@ -2161,6 +2162,7 @@ fn drawing_current_texture(context: &CanvasGPUCanvasContext) -> Option<*const Ca format: data.format, usage, view_formats: surface_data.previous_configuration.view_formats.clone(), + texture_binding_view_dimension: None, }; let texture = surface_data.device.device.create_texture(&desc); *drawing = Some(ReadBackTexture { @@ -2277,7 +2279,7 @@ fn present_drawing_buffer(context: &CanvasGPUCanvasContext, texture: &CanvasGPUT }); encoder.copy_texture_to_texture(©(Arc::clone(&texture.texture)), ©(target), &size); let id = encoder.finish(&wgt::CommandBufferDescriptor { label: None }); - data.presented_submission = Some(data.device.queue.queue.id.submit(&[id])); + data.presented_submission = data.device.queue.queue.id.submit(&[id]); } if let Err(cause) = surface.present() { @@ -2315,7 +2317,7 @@ fn present_now(context: &CanvasGPUCanvasContext, texture: &CanvasGPUTexture) { let id = encoder.finish(&wgt::CommandBufferDescriptor { label: None }); let index = data.device.queue.queue.id.submit(&[id]); if texture.surface_id.is_some() { - data.presented_submission = Some(index); + data.presented_submission = index; } } } diff --git a/crates/canvas-c/src/webgpu/gpu_device.rs b/crates/canvas-c/src/webgpu/gpu_device.rs index e5a632df..97548d77 100644 --- a/crates/canvas-c/src/webgpu/gpu_device.rs +++ b/crates/canvas-c/src/webgpu/gpu_device.rs @@ -6,7 +6,7 @@ use std::{ os::raw::{c_char, c_void}, }; use wgpu_core::binding_model::BufferBinding; -use wgpu_core::pipeline::{CreateRenderPipelineError, RenderPipelineDescriptor}; +use wgpu_core::pipeline::{CreatePipelineError as CreateRenderPipelineError, RenderPipelineDescriptor}; use wgpu_core::resource::CreateBufferError; use wgt::{Features, PrimitiveTopology}; @@ -424,12 +424,12 @@ Arc::into_raw(Arc::new(CanvasGPUBindGroupLayout { ) -> *const CanvasGPUBuffer { let label = ptr_into_label(label); - match wgt::BufferUsages::from_bits(usage) { - Some(usage) => { + match wgt::BufferUsagesWebGPU::from_bits(usage).map(wgt::BufferUsages::from) { + Some(flags) => { let desc = wgt::BufferDescriptor { label: label.clone(), size, - usage, + usage: flags, mapped_at_creation, }; @@ -438,14 +438,16 @@ Arc::into_raw(Arc::new(CanvasGPUBuffer { instance: self.instance.clone(), label, buffer, - usage: usage.bits(), + usage, size, error_sink: self.error_sink.clone(), })) } None => { let err = - CreateBufferError::InvalidUsage(wgt::BufferUsages::from_bits_truncate(usage)); + CreateBufferError::InvalidUsage(wgt::BufferUsages::from( + wgt::BufferUsagesWebGPU::from_bits_truncate(usage), + )); handle_error( self.error_sink.as_ref(), @@ -1630,6 +1632,7 @@ pub extern "C" fn canvas_native_webgpu_device_create_texture( dimension: descriptor.dimension.into(), usage: wgt::TextureUsages::from_bits_truncate(descriptor.usage), view_formats, + texture_binding_view_dimension: None, }; let texture_id = device.device.create_texture(&desc); diff --git a/crates/canvas-c/src/webgpu/gpu_native_texture.rs b/crates/canvas-c/src/webgpu/gpu_native_texture.rs index a47b2944..92df2ad9 100644 --- a/crates/canvas-c/src/webgpu/gpu_native_texture.rs +++ b/crates/canvas-c/src/webgpu/gpu_native_texture.rs @@ -240,6 +240,7 @@ pub(crate) unsafe fn import_platform_texture( format: FRAME_FORMAT, usage: wgt::TextureUsages::TEXTURE_BINDING, view_formats: vec![], + texture_binding_view_dimension: None, }; let (texture, error) = device.create_texture_from_hal( @@ -287,6 +288,7 @@ pub(crate) unsafe fn import_platform_texture( usage: wgt::TextureUses::RESOURCE, memory_flags: wgpu_hal::MemoryFlags::empty(), view_formats: vec![], + texture_binding_view_dimension: None, }; let hal_texture = { @@ -310,6 +312,7 @@ pub(crate) unsafe fn import_platform_texture( format: FRAME_FORMAT, usage: wgt::TextureUsages::TEXTURE_BINDING, view_formats: vec![], + texture_binding_view_dimension: None, }; let (texture, error) = device.create_texture_from_hal( diff --git a/crates/canvas-c/src/webgpu/gpu_shared_frame.rs b/crates/canvas-c/src/webgpu/gpu_shared_frame.rs index 1ae3d065..884b7433 100644 --- a/crates/canvas-c/src/webgpu/gpu_shared_frame.rs +++ b/crates/canvas-c/src/webgpu/gpu_shared_frame.rs @@ -118,6 +118,7 @@ pub(crate) unsafe fn import_and_stage( format: wgt::TextureFormat::Bgra8Unorm, usage: wgt::TextureUsages::TEXTURE_BINDING, view_formats: vec![], + texture_binding_view_dimension: None, }; let (texture, error) = device.create_texture_from_hal(Box::new(hal_texture), &descriptor, wgt::TextureUses::RESOURCE, true); @@ -164,6 +165,7 @@ pub(crate) unsafe fn import_external_plane( format: wgt::TextureFormat::Bgra8Unorm, usage: wgt::TextureUsages::TEXTURE_BINDING | wgt::TextureUsages::RENDER_ATTACHMENT, view_formats: vec![], + texture_binding_view_dimension: None, }); let source = import_and_stage(queue, handle, width, height)?; super::gpu_native_texture::blit_texture(queue, &source, width, height, 0, 0, false, &plane, 0, 0, (0, 0), size) diff --git a/crates/canvas-c/src/webgpu/linux_frames.rs b/crates/canvas-c/src/webgpu/linux_frames.rs index 5a92fdd4..73cd5112 100644 --- a/crates/canvas-c/src/webgpu/linux_frames.rs +++ b/crates/canvas-c/src/webgpu/linux_frames.rs @@ -309,6 +309,7 @@ pub(crate) unsafe fn create_exportable_texture( usage: uses, memory_flags: wgpu_hal::MemoryFlags::empty(), view_formats: view_formats.clone(), + texture_binding_view_dimension: None, }; let hal_texture = unsafe { hal.texture_from_raw( @@ -328,6 +329,7 @@ pub(crate) unsafe fn create_exportable_texture( format, usage, view_formats, + texture_binding_view_dimension: None, }; let (texture, error) = unsafe { device.create_texture_from_hal(Box::new(hal_texture), &desc, initial, true) }; diff --git a/crates/canvas-c/src/webgpu/linux_video_frame.rs b/crates/canvas-c/src/webgpu/linux_video_frame.rs index b7691983..3597365c 100644 --- a/crates/canvas-c/src/webgpu/linux_video_frame.rs +++ b/crates/canvas-c/src/webgpu/linux_video_frame.rs @@ -289,6 +289,7 @@ unsafe fn upload( usage: wgt::TextureUsages::TEXTURE_BINDING | wgt::TextureUsages::COPY_DST, view_formats: vec![], + texture_binding_view_dimension: None, }); cache.uploads.retain(|texture| fits(texture)); cache.uploads.push(Arc::clone(&texture)); @@ -366,6 +367,7 @@ pub(crate) unsafe fn import_external_plane( format: wgt::TextureFormat::Rgba8Unorm, usage: wgt::TextureUsages::TEXTURE_BINDING | wgt::TextureUsages::RENDER_ATTACHMENT, view_formats: vec![], + texture_binding_view_dimension: None, }); let source = unsafe { import_and_stage(queue, handle, width, height) }?; unsafe { diff --git a/packages/canvas/WebGPU/Types.ts b/packages/canvas/WebGPU/Types.ts index 1cd851d8..6954237c 100644 --- a/packages/canvas/WebGPU/Types.ts +++ b/packages/canvas/WebGPU/Types.ts @@ -166,6 +166,7 @@ export type GPUVertexFormat = | 'sint32x4' | 'unorm10-10-10-2' | 'unorm8x4-bgra' + | 'snorm10-10-10-2' | 'float64' | 'float64x2' | 'float64x3' diff --git a/packages/canvas/WebGPU/Utils.ts b/packages/canvas/WebGPU/Utils.ts index fbf9e749..e72430e7 100644 --- a/packages/canvas/WebGPU/Utils.ts +++ b/packages/canvas/WebGPU/Utils.ts @@ -101,6 +101,8 @@ export function parseVertexFormat(value: string) { return 43; case 'unorm8x4-bgra': return 44; + case 'snorm10-10-10-2': + return 45; } }