diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 992cc1e3b2..96e0538a3a 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -28,20 +28,20 @@ cross = ["wgc/cross"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies.wgc] package = "wgpu-core" git = "https://github.com/gfx-rs/wgpu" -rev = "c831c5512ac528775d983c747b78535cc585b9e0" +rev = "9c98ebc48cc53ec696e073da510bef9a819b1916" features = ["raw-window-handle"] [target.'cfg(target_arch = "wasm32")'.dependencies.wgc] package = "wgpu-core" git = "https://github.com/gfx-rs/wgpu" -rev = "c831c5512ac528775d983c747b78535cc585b9e0" +rev = "9c98ebc48cc53ec696e073da510bef9a819b1916" features = ["raw-window-handle"] optional = true [dependencies.wgt] package = "wgpu-types" git = "https://github.com/gfx-rs/wgpu" -rev = "c831c5512ac528775d983c747b78535cc585b9e0" +rev = "9c98ebc48cc53ec696e073da510bef9a819b1916" [dependencies] arrayvec = "0.5" diff --git a/wgpu/examples/boids/main.rs b/wgpu/examples/boids/main.rs index 0a40797643..c84dd6cd58 100644 --- a/wgpu/examples/boids/main.rs +++ b/wgpu/examples/boids/main.rs @@ -268,8 +268,8 @@ impl framework::Example for Example { _spawner: &framework::Spawner, ) { // create render pass descriptor and its color attachments - let color_attachments = [wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + let color_attachments = [wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), diff --git a/wgpu/examples/capture/main.rs b/wgpu/examples/capture/main.rs index b61c86b189..319dea25ae 100644 --- a/wgpu/examples/capture/main.rs +++ b/wgpu/examples/capture/main.rs @@ -45,7 +45,7 @@ async fn create_red_image_with_dimensions( .await .unwrap(); - // It is a webgpu requirement that BufferCopyView.layout.bytes_per_row % wgpu::COPY_BYTES_PER_ROW_ALIGNMENT == 0 + // It is a WebGPU requirement that ImageCopyBuffer.layout.bytes_per_row % wgpu::COPY_BYTES_PER_ROW_ALIGNMENT == 0 // So we calculate padded_bytes_per_row by rounding unpadded_bytes_per_row // up to the next multiple of wgpu::COPY_BYTES_PER_ROW_ALIGNMENT. // https://en.wikipedia.org/wiki/Data_structure_alignment#Computing_padding @@ -81,8 +81,8 @@ async fn create_red_image_with_dimensions( device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &texture.create_view(&wgpu::TextureViewDescriptor::default()), + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &texture.create_view(&wgpu::TextureViewDescriptor::default()), resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::RED), @@ -94,17 +94,20 @@ async fn create_red_image_with_dimensions( // Copy the data from the texture to the buffer encoder.copy_texture_to_buffer( - wgpu::TextureCopyView { + wgpu::ImageCopyTexture { texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, }, - wgpu::BufferCopyView { + wgpu::ImageCopyBuffer { buffer: &output_buffer, - layout: wgpu::TextureDataLayout { + layout: wgpu::ImageDataLayout { offset: 0, - bytes_per_row: buffer_dimensions.padded_bytes_per_row as u32, - rows_per_image: 0, + bytes_per_row: Some( + std::num::NonZeroU32::new(buffer_dimensions.padded_bytes_per_row as u32) + .unwrap(), + ), + rows_per_image: None, }, }, texture_extent, diff --git a/wgpu/examples/conservative-raster/main.rs b/wgpu/examples/conservative-raster/main.rs index e379520fab..763b7e9a7c 100644 --- a/wgpu/examples/conservative-raster/main.rs +++ b/wgpu/examples/conservative-raster/main.rs @@ -267,8 +267,8 @@ impl framework::Example for Example { { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("low resolution"), - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &self.low_res_target, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &self.low_res_target, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), @@ -286,8 +286,8 @@ impl framework::Example for Example { { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("full resolution"), - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), diff --git a/wgpu/examples/cube/main.rs b/wgpu/examples/cube/main.rs index ec5ada9880..bb6670dda0 100644 --- a/wgpu/examples/cube/main.rs +++ b/wgpu/examples/cube/main.rs @@ -196,16 +196,16 @@ impl framework::Example for Example { }); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); queue.write_texture( - wgpu::TextureCopyView { + wgpu::ImageCopyTexture { texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, }, &texels, - wgpu::TextureDataLayout { + wgpu::ImageDataLayout { offset: 0, - bytes_per_row: 4 * size, - rows_per_image: 0, + bytes_per_row: Some(std::num::NonZeroU32::new(4 * size).unwrap()), + rows_per_image: None, }, texture_extent, ); @@ -380,8 +380,8 @@ impl framework::Example for Example { { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs index db168a9ba3..23d8b3ff6e 100644 --- a/wgpu/examples/hello-triangle/main.rs +++ b/wgpu/examples/hello-triangle/main.rs @@ -101,8 +101,8 @@ async fn run(event_loop: EventLoop<()>, window: Window) { { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::GREEN), diff --git a/wgpu/examples/hello-windows/main.rs b/wgpu/examples/hello-windows/main.rs index 68e584f1f2..3e55d65397 100644 --- a/wgpu/examples/hello-windows/main.rs +++ b/wgpu/examples/hello-windows/main.rs @@ -123,8 +123,8 @@ async fn run(event_loop: EventLoop<()>, viewports: Vec<(Window, wgpu::Color)>) { { let _rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(viewport.desc.background), diff --git a/wgpu/examples/mipmap/main.rs b/wgpu/examples/mipmap/main.rs index 6ab80330d4..bb096f4bf5 100644 --- a/wgpu/examples/mipmap/main.rs +++ b/wgpu/examples/mipmap/main.rs @@ -155,8 +155,8 @@ impl Example { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &views[target_mip], + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &views[target_mip], resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::WHITE), @@ -241,15 +241,15 @@ impl framework::Example for Example { usage: wgpu::BufferUsage::COPY_SRC, }); init_encoder.copy_buffer_to_texture( - wgpu::BufferCopyView { + wgpu::ImageCopyBuffer { buffer: &temp_buf, - layout: wgpu::TextureDataLayout { + layout: wgpu::ImageDataLayout { offset: 0, - bytes_per_row: 4 * size, - rows_per_image: 0, + bytes_per_row: Some(NonZeroU32::new(4 * size).unwrap()), + rows_per_image: None, }, }, - wgpu::TextureCopyView { + wgpu::ImageCopyTexture { texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, @@ -465,8 +465,8 @@ impl framework::Example for Example { }; let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(clear_color), diff --git a/wgpu/examples/msaa-line/main.rs b/wgpu/examples/msaa-line/main.rs index 8714185419..0f02f089eb 100644 --- a/wgpu/examples/msaa-line/main.rs +++ b/wgpu/examples/msaa-line/main.rs @@ -261,14 +261,14 @@ impl framework::Example for Example { store: true, }; let rpass_color_attachment = if self.sample_count == 1 { - wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops, } } else { - wgpu::RenderPassColorAttachmentDescriptor { - attachment: &self.multisampled_framebuffer, + wgpu::RenderPassColorAttachment { + view: &self.multisampled_framebuffer, resolve_target: Some(&frame.view), ops, } diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs index c0649e1f62..d6cde07506 100644 --- a/wgpu/examples/shadow/main.rs +++ b/wgpu/examples/shadow/main.rs @@ -764,16 +764,14 @@ impl framework::Example for Example { let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, color_attachments: &[], - depth_stencil_attachment: Some( - wgpu::RenderPassDepthStencilAttachmentDescriptor { - attachment: &light.target_view, - depth_ops: Some(wgpu::Operations { - load: wgpu::LoadOp::Clear(1.0), - store: true, - }), - stencil_ops: None, - }, - ), + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &light.target_view, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: true, + }), + stencil_ops: None, + }), }); pass.set_pipeline(&self.shadow_pass.pipeline); pass.set_bind_group(0, &self.shadow_pass.bind_group, &[]); @@ -795,8 +793,8 @@ impl framework::Example for Example { { let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -808,8 +806,8 @@ impl framework::Example for Example { store: true, }, }], - depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor { - attachment: &self.forward_depth, + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &self.forward_depth, depth_ops: Some(wgpu::Operations { load: wgpu::LoadOp::Clear(1.0), store: false, diff --git a/wgpu/examples/skybox/main.rs b/wgpu/examples/skybox/main.rs index d2cf0f4bfe..d906b2c594 100644 --- a/wgpu/examples/skybox/main.rs +++ b/wgpu/examples/skybox/main.rs @@ -412,8 +412,8 @@ impl framework::Example for Skybox { { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { @@ -425,8 +425,8 @@ impl framework::Example for Skybox { store: true, }, }], - depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor { - attachment: &self.depth_view, + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &self.depth_view, depth_ops: Some(wgpu::Operations { load: wgpu::LoadOp::Clear(1.0), store: false, diff --git a/wgpu/examples/texture-arrays/main.rs b/wgpu/examples/texture-arrays/main.rs index 2eeb066968..1bc974d3aa 100644 --- a/wgpu/examples/texture-arrays/main.rs +++ b/wgpu/examples/texture-arrays/main.rs @@ -2,7 +2,7 @@ mod framework; use bytemuck::{Pod, Zeroable}; - +use std::num::NonZeroU32; use wgpu::util::DeviceExt; #[repr(C)] @@ -151,30 +151,30 @@ impl framework::Example for Example { let green_texture_view = green_texture.create_view(&wgpu::TextureViewDescriptor::default()); queue.write_texture( - wgpu::TextureCopyView { + wgpu::ImageCopyTexture { mip_level: 0, origin: wgpu::Origin3d::ZERO, texture: &red_texture, }, &red_texture_data, - wgpu::TextureDataLayout { + wgpu::ImageDataLayout { offset: 0, - bytes_per_row: 4, - rows_per_image: 0, + bytes_per_row: Some(NonZeroU32::new(4).unwrap()), + rows_per_image: None, }, wgpu::Extent3d::default(), ); queue.write_texture( - wgpu::TextureCopyView { + wgpu::ImageCopyTexture { mip_level: 0, origin: wgpu::Origin3d::ZERO, texture: &green_texture, }, &green_texture_data, - wgpu::TextureDataLayout { + wgpu::ImageDataLayout { offset: 0, - bytes_per_row: 4, - rows_per_image: 0, + bytes_per_row: Some(NonZeroU32::new(4).unwrap()), + rows_per_image: None, }, wgpu::Extent3d::default(), ); @@ -192,7 +192,7 @@ impl framework::Example for Example { view_dimension: wgpu::TextureViewDimension::D2, multisampled: false, }, - count: std::num::NonZeroU32::new(2), + count: NonZeroU32::new(2), }, wgpu::BindGroupLayoutEntry { binding: 1, @@ -297,8 +297,8 @@ impl framework::Example for Example { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), diff --git a/wgpu/examples/water/main.rs b/wgpu/examples/water/main.rs index 71666a924b..dbc931cd1a 100644 --- a/wgpu/examples/water/main.rs +++ b/wgpu/examples/water/main.rs @@ -706,8 +706,8 @@ impl framework::Example for Example { { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &self.reflect_view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &self.reflect_view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(back_color), @@ -716,8 +716,8 @@ impl framework::Example for Example { }], // We still need to use the depth buffer here // since the pipeline requires it. - depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor { - attachment: &self.depth_buffer, + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &self.depth_buffer, depth_ops: Some(wgpu::Operations { load: wgpu::LoadOp::Clear(1.0), store: true, @@ -735,16 +735,16 @@ impl framework::Example for Example { { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(back_color), store: true, }, }], - depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor { - attachment: &self.depth_buffer, + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &self.depth_buffer, depth_ops: Some(wgpu::Operations { load: wgpu::LoadOp::Clear(1.0), store: true, @@ -762,16 +762,16 @@ impl framework::Example for Example { { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, - color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { - attachment: &frame.view, + color_attachments: &[wgpu::RenderPassColorAttachment { + view: &frame.view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Load, store: true, }, }], - depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor { - attachment: &self.depth_buffer, + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &self.depth_buffer, depth_ops: None, stencil_ops: None, }), diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 20316f1d99..5cc32891b1 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -528,15 +528,15 @@ mod pass_impl { } } -fn map_buffer_copy_view(view: crate::BufferCopyView) -> wgc::command::BufferCopyView { - wgc::command::BufferCopyView { +fn map_buffer_copy_view(view: crate::ImageCopyBuffer) -> wgc::command::ImageCopyBuffer { + wgc::command::ImageCopyBuffer { buffer: view.buffer.id.id, layout: view.layout, } } -fn map_texture_copy_view(view: crate::TextureCopyView) -> wgc::command::TextureCopyView { - wgc::command::TextureCopyView { +fn map_texture_copy_view(view: crate::ImageCopyTexture) -> wgc::command::ImageCopyTexture { + wgc::command::ImageCopyTexture { texture: view.texture.id.id, mip_level: view.mip_level, origin: view.origin, @@ -774,11 +774,10 @@ impl crate::Context for Context { desc: &wgt::SwapChainDescriptor, ) -> Self::SwapChainId { let global = &self.0; - match wgc::gfx_select!( - device.id => global.device_create_swap_chain(device.id, *surface, desc) - ) { - Ok(sc) => sc, - Err(err) => self.handle_error_fatal(err, "Device::create_swap_chain"), + let (sc, error) = wgc::gfx_select!(device.id => global.device_create_swap_chain(device.id, *surface, desc)); + match error { + Some(e) => self.handle_error_fatal(e, "Device::create_swap_chain"), + None => sc, } } @@ -1522,8 +1521,8 @@ impl crate::Context for Context { fn command_encoder_copy_buffer_to_texture( &self, encoder: &Self::CommandEncoderId, - source: crate::BufferCopyView, - destination: crate::TextureCopyView, + source: crate::ImageCopyBuffer, + destination: crate::ImageCopyTexture, copy_size: wgt::Extent3d, ) { let global = &self.0; @@ -1544,8 +1543,8 @@ impl crate::Context for Context { fn command_encoder_copy_texture_to_buffer( &self, encoder: &Self::CommandEncoderId, - source: crate::TextureCopyView, - destination: crate::BufferCopyView, + source: crate::ImageCopyTexture, + destination: crate::ImageCopyBuffer, copy_size: wgt::Extent3d, ) { let global = &self.0; @@ -1566,8 +1565,8 @@ impl crate::Context for Context { fn command_encoder_copy_texture_to_texture( &self, encoder: &Self::CommandEncoderId, - source: crate::TextureCopyView, - destination: crate::TextureCopyView, + source: crate::ImageCopyTexture, + destination: crate::ImageCopyTexture, copy_size: wgt::Extent3d, ) { let global = &self.0; @@ -1673,16 +1672,16 @@ impl crate::Context for Context { let colors = desc .color_attachments .iter() - .map(|ca| wgc::command::ColorAttachmentDescriptor { - attachment: ca.attachment.id, + .map(|ca| wgc::command::RenderPassColorAttachment { + view: ca.view.id, resolve_target: ca.resolve_target.map(|rt| rt.id), channel: map_pass_channel(Some(&ca.ops)), }) .collect::>(); let depth_stencil = desc.depth_stencil_attachment.as_ref().map(|dsa| { - wgc::command::DepthStencilAttachmentDescriptor { - attachment: dsa.attachment.id, + wgc::command::RenderPassDepthStencilAttachment { + view: dsa.view.id, depth: map_pass_channel(dsa.depth_ops.as_ref()), stencil: map_pass_channel(dsa.stencil_ops.as_ref()), } @@ -1800,9 +1799,9 @@ impl crate::Context for Context { fn queue_write_texture( &self, queue: &Self::QueueId, - texture: crate::TextureCopyView, + texture: crate::ImageCopyTexture, data: &[u8], - data_layout: wgt::TextureDataLayout, + data_layout: wgt::ImageDataLayout, size: wgt::Extent3d, ) { let global = &self.0; diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 3d7170b7b0..026ab094c5 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -798,15 +798,19 @@ fn map_texture_view_dimension( } } -fn map_buffer_copy_view(view: crate::BufferCopyView) -> web_sys::GpuImageCopyBuffer { +fn map_buffer_copy_view(view: crate::ImageCopyBuffer) -> web_sys::GpuImageCopyBuffer { let mut mapped = web_sys::GpuImageCopyBuffer::new(&view.buffer.id.0); - mapped.bytes_per_row(view.layout.bytes_per_row); - mapped.rows_per_image(view.layout.rows_per_image); + if let Some(bytes_per_row) = view.layout.bytes_per_row { + mapped.bytes_per_row(bytes_per_row.get()); + } + if let Some(rows_per_image) = view.layout.rows_per_image { + mapped.rows_per_image(rows_per_image.get()); + } mapped.offset(view.layout.offset as f64); mapped } -fn map_texture_copy_view(view: crate::TextureCopyView) -> web_sys::GpuImageCopyTexture { +fn map_texture_copy_view(view: crate::ImageCopyTexture) -> web_sys::GpuImageCopyTexture { let mut mapped = web_sys::GpuImageCopyTexture::new(&view.texture.id.0); mapped.mip_level(view.mip_level); mapped.origin(&map_origin_3d(view.origin)); @@ -1719,8 +1723,8 @@ impl crate::Context for Context { fn command_encoder_copy_buffer_to_texture( &self, encoder: &Self::CommandEncoderId, - source: crate::BufferCopyView, - destination: crate::TextureCopyView, + source: crate::ImageCopyBuffer, + destination: crate::ImageCopyTexture, copy_size: wgt::Extent3d, ) { encoder.copy_buffer_to_texture_with_gpu_extent_3d_dict( @@ -1733,8 +1737,8 @@ impl crate::Context for Context { fn command_encoder_copy_texture_to_buffer( &self, encoder: &Self::CommandEncoderId, - source: crate::TextureCopyView, - destination: crate::BufferCopyView, + source: crate::ImageCopyTexture, + destination: crate::ImageCopyBuffer, copy_size: wgt::Extent3d, ) { encoder.copy_texture_to_buffer_with_gpu_extent_3d_dict( @@ -1747,8 +1751,8 @@ impl crate::Context for Context { fn command_encoder_copy_texture_to_texture( &self, encoder: &Self::CommandEncoderId, - source: crate::TextureCopyView, - destination: crate::TextureCopyView, + source: crate::ImageCopyTexture, + destination: crate::ImageCopyTexture, copy_size: wgt::Extent3d, ) { encoder.copy_texture_to_texture_with_gpu_extent_3d_dict( @@ -1793,7 +1797,7 @@ impl crate::Context for Context { }; let mut mapped_color_attachment = - web_sys::GpuRenderPassColorAttachment::new(&load_value, &ca.attachment.id.0); + web_sys::GpuRenderPassColorAttachment::new(&load_value, &ca.view.id.0); if let Some(rt) = ca.resolve_target { mapped_color_attachment.resolve_target(&rt.id.0); @@ -1847,7 +1851,7 @@ impl crate::Context for Context { depth_store_op, &stencil_load_op, stencil_store_op, - &dsa.attachment.id.0, + &dsa.view.id.0, ); mapped_desc.depth_stencil_attachment(&mapped_depth_stencil_attachment); @@ -1956,14 +1960,18 @@ impl crate::Context for Context { fn queue_write_texture( &self, queue: &Self::QueueId, - texture: crate::TextureCopyView, + texture: crate::ImageCopyTexture, data: &[u8], - data_layout: wgt::TextureDataLayout, + data_layout: wgt::ImageDataLayout, size: wgt::Extent3d, ) { let mut mapped_data_layout = web_sys::GpuImageDataLayout::new(); - mapped_data_layout.bytes_per_row(data_layout.bytes_per_row); - mapped_data_layout.rows_per_image(data_layout.rows_per_image); + if let Some(bytes_per_row) = data_layout.bytes_per_row { + mapped_data_layout.bytes_per_row(bytes_per_row.get()); + } + if let Some(rows_per_image) = data_layout.rows_per_image { + mapped_data_layout.rows_per_image(rows_per_image.get()); + } mapped_data_layout.offset(data_layout.offset as f64); /* Skip the copy once gecko allows BufferSource instead of ArrayBuffer diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index f0f036891b..7804c91adc 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -29,15 +29,15 @@ pub use wgt::{ BlendComponent, BlendFactor, BlendOperation, BlendState, BufferAddress, BufferBindingType, BufferSize, BufferUsage, Color, ColorTargetState, ColorWrite, CommandBufferDescriptor, CompareFunction, DepthBiasState, DepthStencilState, DeviceType, DynamicOffset, Extent3d, Face, - Features, FilterMode, FrontFace, IndexFormat, InputStepMode, Limits, MultisampleState, - Origin3d, PipelineStatisticsTypes, PolygonMode, PowerPreference, PresentMode, PrimitiveState, - PrimitiveTopology, PushConstantRange, QuerySetDescriptor, QueryType, SamplerBorderColor, - ShaderFlags, ShaderLocation, ShaderStage, StencilFaceState, StencilOperation, StencilState, - StorageTextureAccess, SwapChainDescriptor, SwapChainStatus, TextureAspect, TextureDataLayout, - TextureDimension, TextureFormat, TextureSampleType, TextureUsage, TextureViewDimension, - VertexAttribute, VertexFormat, BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, - COPY_BYTES_PER_ROW_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, - VERTEX_STRIDE_ALIGNMENT, + Features, FilterMode, FrontFace, ImageDataLayout, IndexFormat, InputStepMode, Limits, + MultisampleState, Origin3d, PipelineStatisticsTypes, PolygonMode, PowerPreference, PresentMode, + PrimitiveState, PrimitiveTopology, PushConstantRange, QuerySetDescriptor, QueryType, + SamplerBorderColor, ShaderFlags, ShaderLocation, ShaderStage, StencilFaceState, + StencilOperation, StencilState, StorageTextureAccess, SwapChainDescriptor, SwapChainStatus, + TextureAspect, TextureDimension, TextureFormat, TextureSampleType, TextureUsage, + TextureViewDimension, VertexAttribute, VertexFormat, BIND_BUFFER_ALIGNMENT, + COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT, + QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT, }; use backend::{BufferMappedRange, Context as C}; @@ -356,22 +356,22 @@ trait Context: Debug + Send + Sized + Sync { fn command_encoder_copy_buffer_to_texture( &self, encoder: &Self::CommandEncoderId, - source: BufferCopyView, - destination: TextureCopyView, + source: ImageCopyBuffer, + destination: ImageCopyTexture, copy_size: Extent3d, ); fn command_encoder_copy_texture_to_buffer( &self, encoder: &Self::CommandEncoderId, - source: TextureCopyView, - destination: BufferCopyView, + source: ImageCopyTexture, + destination: ImageCopyBuffer, copy_size: Extent3d, ); fn command_encoder_copy_texture_to_texture( &self, encoder: &Self::CommandEncoderId, - source: TextureCopyView, - destination: TextureCopyView, + source: ImageCopyTexture, + destination: ImageCopyTexture, copy_size: Extent3d, ); @@ -432,9 +432,9 @@ trait Context: Debug + Send + Sized + Sync { fn queue_write_texture( &self, queue: &Self::QueueId, - texture: TextureCopyView, + texture: ImageCopyTexture, data: &[u8], - data_layout: TextureDataLayout, + data_layout: ImageDataLayout, size: Extent3d, ); fn queue_submit>( @@ -1002,9 +1002,9 @@ impl Default for Operations { /// Describes a color attachment to a [`RenderPass`]. #[derive(Clone, Debug)] -pub struct RenderPassColorAttachmentDescriptor<'a> { +pub struct RenderPassColorAttachment<'a> { /// The view to use as an attachment. - pub attachment: &'a TextureView, + pub view: &'a TextureView, /// The view that will receive the resolved output if multisampling is used. pub resolve_target: Option<&'a TextureView>, /// What operations will be performed on this color attachment. @@ -1013,9 +1013,9 @@ pub struct RenderPassColorAttachmentDescriptor<'a> { /// Describes a depth/stencil attachment to a [`RenderPass`]. #[derive(Clone, Debug)] -pub struct RenderPassDepthStencilAttachmentDescriptor<'a> { +pub struct RenderPassDepthStencilAttachment<'a> { /// The view to use as an attachment. - pub attachment: &'a TextureView, + pub view: &'a TextureView, /// What operations will be performed on the depth part of the attachment. pub depth_ops: Option>, /// What operations will be performed on the stencil part of the attachment. @@ -1162,9 +1162,9 @@ pub struct RenderPassDescriptor<'a, 'b> { /// Debug label of the render pass. This will show up in graphics debuggers for easy identification. pub label: Option<&'b str>, /// The color attachments of the render pass. - pub color_attachments: &'b [RenderPassColorAttachmentDescriptor<'a>], + pub color_attachments: &'b [RenderPassColorAttachment<'a>], /// The depth and stencil attachment of the render pass, if any. - pub depth_stencil_attachment: Option>, + pub depth_stencil_attachment: Option>, } /// Describes how the vertex buffer is interpreted. @@ -1242,13 +1242,13 @@ pub struct ComputePipelineDescriptor<'a> { pub entry_point: &'a str, } -pub use wgt::BufferCopyView as BufferCopyViewBase; +pub use wgt::ImageCopyBuffer as ImageCopyBufferBase; /// View of a buffer which can be used to copy to/from a texture. -pub type BufferCopyView<'a> = BufferCopyViewBase<&'a Buffer>; +pub type ImageCopyBuffer<'a> = ImageCopyBufferBase<&'a Buffer>; -pub use wgt::TextureCopyView as TextureCopyViewBase; +pub use wgt::ImageCopyTexture as ImageCopyTextureBase; /// View of a texture which can be used to copy to/from a buffer/texture. -pub type TextureCopyView<'a> = TextureCopyViewBase<&'a Texture>; +pub type ImageCopyTexture<'a> = ImageCopyTextureBase<&'a Texture>; /// Describes a [`BindGroupLayout`]. #[derive(Clone, Debug)] @@ -2003,8 +2003,8 @@ impl CommandEncoder { /// - `source.layout.bytes_per_row` isn't divisible by [`COPY_BYTES_PER_ROW_ALIGNMENT`]. pub fn copy_buffer_to_texture( &mut self, - source: BufferCopyView, - destination: TextureCopyView, + source: ImageCopyBuffer, + destination: ImageCopyTexture, copy_size: Extent3d, ) { Context::command_encoder_copy_buffer_to_texture( @@ -2025,8 +2025,8 @@ impl CommandEncoder { /// - `source.layout.bytes_per_row` isn't divisible by [`COPY_BYTES_PER_ROW_ALIGNMENT`]. pub fn copy_texture_to_buffer( &mut self, - source: TextureCopyView, - destination: BufferCopyView, + source: ImageCopyTexture, + destination: ImageCopyBuffer, copy_size: Extent3d, ) { Context::command_encoder_copy_texture_to_buffer( @@ -2047,8 +2047,8 @@ impl CommandEncoder { /// - Copy would overrun either texture pub fn copy_texture_to_texture( &mut self, - source: TextureCopyView, - destination: TextureCopyView, + source: ImageCopyTexture, + destination: ImageCopyTexture, copy_size: Extent3d, ) { Context::command_encoder_copy_texture_to_texture( @@ -2289,7 +2289,7 @@ impl<'a> RenderPass<'a> { /// [`Features::MULTI_DRAW_INDIRECT`] must be enabled on the device in order to call these functions. impl<'a> RenderPass<'a> { - /// Disptaches multiple draw calls from the active vertex buffer(s) based on the contents of the `indirect_buffer`. + /// Dispatches multiple draw calls from the active vertex buffer(s) based on the contents of the `indirect_buffer`. /// `count` draw calls are issued. /// /// The active vertex buffers can be set with [`RenderPass::set_vertex_buffer`]. @@ -2317,7 +2317,7 @@ impl<'a> RenderPass<'a> { .multi_draw_indirect(&indirect_buffer.id, indirect_offset, count); } - /// Disptaches multiple draw calls from the active index buffer and the active vertex buffers, + /// Dispatches multiple draw calls from the active index buffer and the active vertex buffers, /// based on the contents of the `indirect_buffer`. `count` draw calls are issued. /// /// The active index buffer can be set with [`RenderPass::set_index_buffer`], while the active @@ -2397,7 +2397,7 @@ impl<'a> RenderPass<'a> { ); } - /// Disptaches multiple draw calls from the active index buffer and the active vertex buffers, + /// Dispatches multiple draw calls from the active index buffer and the active vertex buffers, /// based on the contents of the `indirect_buffer`. The count buffer is read to determine how many draws to issue. /// /// The indirect buffer must be long enough to account for `max_count` draws, however only `count` will @@ -2496,7 +2496,7 @@ impl<'a> RenderPass<'a> { } } -/// [`Features::PIPEILNE_STATISTICS_QUERY`] must be enabled on the device in order to call these functions. +/// [`Features::PIPELINE_STATISTICS_QUERY`] must be enabled on the device in order to call these functions. impl<'a> RenderPass<'a> { /// Start a pipeline statistics query on this render pass. It can be ended with /// `end_pipeline_statistics_query`. Pipeline statistics queries may not be nested. @@ -2601,7 +2601,7 @@ impl<'a> ComputePass<'a> { } } -/// [`Features::PIPEILNE_STATISTICS_QUERY`] must be enabled on the device in order to call these functions. +/// [`Features::PIPELINE_STATISTICS_QUERY`] must be enabled on the device in order to call these functions. impl<'a> ComputePass<'a> { /// Start a pipeline statistics query on this render pass. It can be ended with /// `end_pipeline_statistics_query`. Pipeline statistics queries may not be nested. @@ -2804,9 +2804,9 @@ impl Queue { /// internally to happen at the start of the next `submit()` call. pub fn write_texture( &self, - texture: TextureCopyView, + texture: ImageCopyTexture, data: &[u8], - data_layout: TextureDataLayout, + data_layout: ImageDataLayout, size: Extent3d, ) { Context::queue_write_texture(&*self.context, &self.id, texture, data, data_layout, size) diff --git a/wgpu/src/util/device.rs b/wgpu/src/util/device.rs index ca58b16e87..0120943ee9 100644 --- a/wgpu/src/util/device.rs +++ b/wgpu/src/util/device.rs @@ -1,4 +1,4 @@ -use std::convert::TryFrom; +use std::{convert::TryFrom, num::NonZeroU32}; /// Describes a [Buffer](crate::Buffer) when allocating. #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -115,7 +115,7 @@ impl DeviceExt for crate::Device { let end_offset = binary_offset + data_size as usize; queue.write_texture( - crate::TextureCopyView { + crate::ImageCopyTexture { texture: &texture, mip_level: mip as u32, origin: crate::Origin3d { @@ -125,10 +125,14 @@ impl DeviceExt for crate::Device { }, }, &data[binary_offset..end_offset], - crate::TextureDataLayout { + crate::ImageDataLayout { offset: 0, - bytes_per_row, - rows_per_image: mip_physical.height, + bytes_per_row: Some( + NonZeroU32::new(bytes_per_row).expect("invalid bytes per row"), + ), + rows_per_image: Some( + NonZeroU32::new(mip_physical.height).expect("invalid height"), + ), }, mip_physical, );