diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 6ce0039e46..ae7078cc35 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -28,14 +28,14 @@ vulkan = ["wgc/gfx-backend-vulkan"] package = "wgpu-core" version = "0.5" git = "https://github.com/gfx-rs/wgpu" -rev = "a02a56684114da702a64e30af49d0167e273402b" +rev = "c7be94047d156a3bde88d03cd5c229bedb6efe62" features = ["raw-window-handle"] [dependencies.wgt] package = "wgpu-types" version = "0.5" git = "https://github.com/gfx-rs/wgpu" -rev = "a02a56684114da702a64e30af49d0167e273402b" +rev = "c7be94047d156a3bde88d03cd5c229bedb6efe62" [dependencies] arrayvec = "0.5" @@ -68,6 +68,9 @@ test = true #wgpu-types = { version = "0.5.0", path = "../wgpu/wgpu-types" } #wgpu-core = { version = "0.5.0", path = "../wgpu/wgpu-core" } +[patch."https://github.com/gfx-rs/naga"] +#naga = { path = "../naga" } + [patch.crates-io] #gfx-hal = { version = "0.5.0", path = "../gfx/src/hal" } #gfx-backend-empty = { version = "0.5.0", path = "../gfx/src/backend/empty" } diff --git a/wgpu/examples/boids/main.rs b/wgpu/examples/boids/main.rs index 460ac5215a..ee0c954b61 100644 --- a/wgpu/examples/boids/main.rs +++ b/wgpu/examples/boids/main.rs @@ -65,9 +65,7 @@ impl framework::Example for Example { wgpu::ShaderStage::COMPUTE, wgpu::BindingType::UniformBuffer { dynamic: false, - min_binding_size: wgpu::NonZeroBufferAddress::new( - sim_param_data.len() as _ - ), + min_binding_size: wgpu::BufferSize::new(sim_param_data.len() as _), }, ), wgpu::BindGroupLayoutEntry::new( @@ -75,9 +73,7 @@ impl framework::Example for Example { wgpu::ShaderStage::COMPUTE, wgpu::BindingType::StorageBuffer { dynamic: false, - min_binding_size: wgpu::NonZeroBufferAddress::new( - (NUM_PARTICLES * 16) as _, - ), + min_binding_size: wgpu::BufferSize::new((NUM_PARTICLES * 16) as _), readonly: false, }, ), @@ -86,9 +82,7 @@ impl framework::Example for Example { wgpu::ShaderStage::COMPUTE, wgpu::BindingType::StorageBuffer { dynamic: false, - min_binding_size: wgpu::NonZeroBufferAddress::new( - (NUM_PARTICLES * 16) as _, - ), + min_binding_size: wgpu::BufferSize::new((NUM_PARTICLES * 16) as _), readonly: false, }, ), @@ -269,9 +263,12 @@ impl framework::Example for Example { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color::BLACK, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: wgpu::Color::BLACK, + read_only: false, + }, }], depth_stencil_attachment: None, }; diff --git a/wgpu/examples/capture/main.rs b/wgpu/examples/capture/main.rs index 09c8d035ca..136ce424ac 100644 --- a/wgpu/examples/capture/main.rs +++ b/wgpu/examples/capture/main.rs @@ -86,9 +86,12 @@ async fn run() { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &texture.create_default_view(), resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color::RED, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: wgpu::Color::RED, + read_only: false, + }, }], depth_stencil_attachment: None, }); diff --git a/wgpu/examples/cube/main.rs b/wgpu/examples/cube/main.rs index cb02ecbf75..e5ac3b9cd7 100644 --- a/wgpu/examples/cube/main.rs +++ b/wgpu/examples/cube/main.rs @@ -140,7 +140,7 @@ impl framework::Example for Example { wgpu::ShaderStage::VERTEX, wgpu::BindingType::UniformBuffer { dynamic: false, - min_binding_size: wgpu::NonZeroBufferAddress::new(64), + min_binding_size: wgpu::BufferSize::new(64), }, ), wgpu::BindGroupLayoutEntry::new( @@ -326,13 +326,16 @@ impl framework::Example for Example { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color { - r: 0.1, - g: 0.2, - b: 0.3, - a: 1.0, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: wgpu::Color { + r: 0.1, + g: 0.2, + b: 0.3, + a: 1.0, + }, + read_only: false, }, }], depth_stencil_attachment: None, diff --git a/wgpu/examples/hello-compute/main.rs b/wgpu/examples/hello-compute/main.rs index b37ef2f978..699d956002 100644 --- a/wgpu/examples/hello-compute/main.rs +++ b/wgpu/examples/hello-compute/main.rs @@ -68,7 +68,7 @@ async fn execute_gpu(numbers: Vec) -> Vec { wgpu::BindingType::StorageBuffer { dynamic: false, readonly: false, - min_binding_size: wgpu::NonZeroBufferAddress::new(4), + min_binding_size: wgpu::BufferSize::new(4), }, )], }); diff --git a/wgpu/examples/hello-triangle/main.rs b/wgpu/examples/hello-triangle/main.rs index f6febdb682..478ea6ca14 100644 --- a/wgpu/examples/hello-triangle/main.rs +++ b/wgpu/examples/hello-triangle/main.rs @@ -114,9 +114,12 @@ async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu:: color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color::GREEN, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: wgpu::Color::GREEN, + read_only: false, + }, }], depth_stencil_attachment: None, }); diff --git a/wgpu/examples/mipmap/main.rs b/wgpu/examples/mipmap/main.rs index e57af3c387..cce3d25898 100644 --- a/wgpu/examples/mipmap/main.rs +++ b/wgpu/examples/mipmap/main.rs @@ -186,9 +186,12 @@ impl Example { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &views[target_mip], resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color::WHITE, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: wgpu::Color::WHITE, + read_only: false, + }, }], depth_stencil_attachment: None, }); @@ -226,7 +229,7 @@ impl framework::Example for Example { wgpu::ShaderStage::VERTEX, wgpu::BindingType::UniformBuffer { dynamic: false, - min_binding_size: wgpu::NonZeroBufferAddress::new(64), + min_binding_size: wgpu::BufferSize::new(64), }, ), wgpu::BindGroupLayoutEntry::new( @@ -412,13 +415,16 @@ impl framework::Example for Example { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color { - r: 0.1, - g: 0.2, - b: 0.3, - a: 1.0, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: wgpu::Color { + r: 0.1, + g: 0.2, + b: 0.3, + a: 1.0, + }, + read_only: false, }, }], depth_stencil_attachment: None, diff --git a/wgpu/examples/msaa-line/main.rs b/wgpu/examples/msaa-line/main.rs index 19d9c57d78..e0728ea63e 100644 --- a/wgpu/examples/msaa-line/main.rs +++ b/wgpu/examples/msaa-line/main.rs @@ -255,21 +255,23 @@ impl framework::Example for Example { let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); { + let channel = wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: wgpu::Color::BLACK, + read_only: false, + }; let rpass_color_attachment = if self.sample_count == 1 { wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color::BLACK, + channel, } } else { wgpu::RenderPassColorAttachmentDescriptor { attachment: &self.multisampled_framebuffer, resolve_target: Some(&frame.view), - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color::BLACK, + channel, } }; diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs index 8526a00655..59778c3873 100644 --- a/wgpu/examples/shadow/main.rs +++ b/wgpu/examples/shadow/main.rs @@ -247,11 +247,9 @@ impl framework::Example for Example { wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, wgpu::BindingType::UniformBuffer { dynamic: false, - min_binding_size: wgpu::NonZeroBufferAddress::new(mem::size_of::< - EntityUniforms, - >( - ) - as _), + min_binding_size: wgpu::BufferSize::new( + mem::size_of::() as _ + ), }, )], label: None, @@ -437,7 +435,7 @@ impl framework::Example for Example { wgpu::ShaderStage::VERTEX, wgpu::BindingType::UniformBuffer { dynamic: false, - min_binding_size: wgpu::NonZeroBufferAddress::new(uniform_size), + min_binding_size: wgpu::BufferSize::new(uniform_size), }, )], label: None, @@ -521,7 +519,7 @@ impl framework::Example for Example { wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, wgpu::BindingType::UniformBuffer { dynamic: false, - min_binding_size: wgpu::NonZeroBufferAddress::new(mem::size_of::< + min_binding_size: wgpu::BufferSize::new(mem::size_of::< ForwardUniforms, >( ) @@ -533,9 +531,7 @@ impl framework::Example for Example { wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, wgpu::BindingType::UniformBuffer { dynamic: false, - min_binding_size: wgpu::NonZeroBufferAddress::new( - light_uniform_size, - ), + min_binding_size: wgpu::BufferSize::new(light_uniform_size), }, ), wgpu::BindGroupLayoutEntry::new( @@ -760,14 +756,18 @@ impl framework::Example for Example { color_attachments: &[], depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor { attachment: &light.target_view, - depth_load_op: wgpu::LoadOp::Clear, - depth_store_op: wgpu::StoreOp::Store, - depth_read_only: false, - stencil_load_op: wgpu::LoadOp::Clear, - stencil_store_op: wgpu::StoreOp::Store, - clear_depth: 1.0, - clear_stencil: 0, - stencil_read_only: false, + depth: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: 1.0, + read_only: false, + }, + stencil: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: 0, + read_only: false, + }, }), }); pass.set_pipeline(&self.shadow_pass.pipeline); @@ -787,25 +787,32 @@ impl framework::Example for Example { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color { - r: 0.1, - g: 0.2, - b: 0.3, - a: 1.0, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: wgpu::Color { + r: 0.1, + g: 0.2, + b: 0.3, + a: 1.0, + }, + read_only: false, }, }], depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor { attachment: &self.forward_depth, - depth_load_op: wgpu::LoadOp::Clear, - depth_store_op: wgpu::StoreOp::Store, - depth_read_only: false, - stencil_load_op: wgpu::LoadOp::Clear, - stencil_store_op: wgpu::StoreOp::Store, - clear_depth: 1.0, - clear_stencil: 0, - stencil_read_only: false, + depth: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Clear, + clear_value: 1.0, + read_only: false, + }, + stencil: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Clear, + clear_value: 0, + read_only: false, + }, }), }); pass.set_pipeline(&self.forward_pass.pipeline); diff --git a/wgpu/examples/skybox/main.rs b/wgpu/examples/skybox/main.rs index 8b275c3513..24612e0596 100644 --- a/wgpu/examples/skybox/main.rs +++ b/wgpu/examples/skybox/main.rs @@ -278,13 +278,16 @@ impl framework::Example for Skybox { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color { - r: 0.1, - g: 0.2, - b: 0.3, - a: 1.0, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: wgpu::Color { + r: 0.1, + g: 0.2, + b: 0.3, + a: 1.0, + }, + read_only: false, }, }], depth_stencil_attachment: None, diff --git a/wgpu/examples/texture-arrays/main.rs b/wgpu/examples/texture-arrays/main.rs index 0a45ee3875..849cbde96e 100644 --- a/wgpu/examples/texture-arrays/main.rs +++ b/wgpu/examples/texture-arrays/main.rs @@ -371,13 +371,11 @@ impl framework::Example for Example { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color { - r: 0.0, - g: 0.0, - b: 0.0, - a: 1.0, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: wgpu::Color::BLACK, + read_only: false, }, }], depth_stencil_attachment: None, diff --git a/wgpu/examples/water/main.rs b/wgpu/examples/water/main.rs index a692ab220d..7123ba3a0c 100644 --- a/wgpu/examples/water/main.rs +++ b/wgpu/examples/water/main.rs @@ -358,11 +358,9 @@ impl framework::Example for Example { wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, wgpu::BindingType::UniformBuffer { dynamic: false, - min_binding_size: wgpu::NonZeroBufferAddress::new(mem::size_of::< - WaterUniforms, - >( - ) - as _), + min_binding_size: wgpu::BufferSize::new( + mem::size_of::() as _, + ), }, ), // Reflection texture. @@ -404,11 +402,9 @@ impl framework::Example for Example { wgpu::ShaderStage::VERTEX, wgpu::BindingType::UniformBuffer { dynamic: false, - min_binding_size: wgpu::NonZeroBufferAddress::new(mem::size_of::< - TerrainUniforms, - >( - ) - as _), + min_binding_size: wgpu::BufferSize::new( + mem::size_of::() as _, + ), }, ), ], @@ -687,6 +683,12 @@ impl framework::Example for Example { ) -> wgpu::CommandBuffer { // Increment frame count regardless of if we draw. self.current_frame += 1; + let back_color = wgpu::Color { + r: 161.0 / 255.0, + g: 246.0 / 255.0, + b: 255.0 / 255.0, + a: 1.0, + }; // Write the sin/cos values to the uniform buffer for the water. let (water_sin, water_cos) = ((self.current_frame as f32) / 600.0).sin_cos(); @@ -717,27 +719,29 @@ impl framework::Example for Example { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &self.reflect_view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color { - r: 161.0 / 255.0, - g: 246.0 / 255.0, - b: 255.0 / 255.0, - a: 1.0, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: back_color, + read_only: false, }, }], // 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_load_op: wgpu::LoadOp::Clear, - depth_store_op: wgpu::StoreOp::Clear, - clear_depth: 1.0, - depth_read_only: false, - stencil_load_op: wgpu::LoadOp::Clear, - stencil_store_op: wgpu::StoreOp::Store, - clear_stencil: 0, - stencil_read_only: false, + depth: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Clear, + clear_value: 1.0, + read_only: false, + }, + stencil: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Clear, + clear_value: 0, + read_only: false, + }, }), }); rpass.set_pipeline(&self.terrain_pipeline); @@ -752,25 +756,27 @@ impl framework::Example for Example { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color { - r: 161.0 / 255.0, - g: 246.0 / 255.0, - b: 255.0 / 255.0, - a: 1.0, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: back_color, + read_only: false, }, }], depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor { attachment: &self.depth_buffer, - depth_load_op: wgpu::LoadOp::Clear, - depth_store_op: wgpu::StoreOp::Store, - clear_depth: 1.0, - depth_read_only: false, - stencil_load_op: wgpu::LoadOp::Clear, - stencil_store_op: wgpu::StoreOp::Store, - clear_stencil: 0, - stencil_read_only: false, + depth: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: 1.0, + read_only: false, + }, + stencil: wgpu::PassChannel { + load_op: wgpu::LoadOp::Clear, + store_op: wgpu::StoreOp::Store, + clear_value: 0, + read_only: false, + }, }), }); rpass.set_pipeline(&self.terrain_pipeline); @@ -785,25 +791,27 @@ impl framework::Example for Example { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &frame.view, resolve_target: None, - load_op: wgpu::LoadOp::Load, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color { - r: 161.0 / 255.0, - g: 246.0 / 255.0, - b: 255.0 / 255.0, - a: 1.0, + channel: wgpu::PassChannel { + load_op: wgpu::LoadOp::Load, + store_op: wgpu::StoreOp::Store, + clear_value: back_color, + read_only: false, }, }], depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor { attachment: &self.depth_buffer, - depth_load_op: wgpu::LoadOp::Load, - depth_store_op: wgpu::StoreOp::Store, - clear_depth: 1.0, - depth_read_only: true, - stencil_load_op: wgpu::LoadOp::Load, - stencil_store_op: wgpu::StoreOp::Store, - clear_stencil: 0, - stencil_read_only: false, + depth: wgpu::PassChannel { + load_op: wgpu::LoadOp::Load, + store_op: wgpu::StoreOp::Store, + clear_value: 1.0, + read_only: true, + }, + stencil: wgpu::PassChannel { + load_op: wgpu::LoadOp::Load, + store_op: wgpu::StoreOp::Store, + clear_value: 0, + read_only: false, + }, }), }); diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 5dba242c4b..744ca32a96 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -36,9 +36,9 @@ mod pass_impl { use std::ops::Range; use wgc::command::{bundle_ffi::*, compute_ffi::*, render_ffi::*}; - impl crate::ComputePassInner for wgc::command::RawPass { + impl crate::ComputePassInner for wgc::command::ComputePass { fn set_pipeline(&mut self, pipeline: &wgc::id::ComputePipelineId) { - unsafe { wgpu_compute_pass_set_pipeline(self, *pipeline) } + wgpu_compute_pass_set_pipeline(self, *pipeline) } fn set_bind_group( &mut self, @@ -57,20 +57,20 @@ mod pass_impl { } } fn dispatch(&mut self, x: u32, y: u32, z: u32) { - unsafe { wgpu_compute_pass_dispatch(self, x, y, z) } + wgpu_compute_pass_dispatch(self, x, y, z) } fn dispatch_indirect( &mut self, indirect_buffer: &wgc::id::BufferId, indirect_offset: wgt::BufferAddress, ) { - unsafe { wgpu_compute_pass_dispatch_indirect(self, *indirect_buffer, indirect_offset) } + wgpu_compute_pass_dispatch_indirect(self, *indirect_buffer, indirect_offset) } } - impl crate::RenderInner for wgc::command::RawPass { + impl crate::RenderInner for wgc::command::RenderPass { fn set_pipeline(&mut self, pipeline: &wgc::id::RenderPipelineId) { - unsafe { wgpu_render_pass_set_pipeline(self, *pipeline) } + wgpu_render_pass_set_pipeline(self, *pipeline) } fn set_bind_group( &mut self, @@ -92,66 +92,60 @@ mod pass_impl { &mut self, buffer: &wgc::id::BufferId, offset: wgt::BufferAddress, - size: wgt::BufferSize, + size: Option, ) { - unsafe { wgpu_render_pass_set_index_buffer(self, *buffer, offset, size) } + wgpu_render_pass_set_index_buffer(self, *buffer, offset, size) } fn set_vertex_buffer( &mut self, slot: u32, buffer: &wgc::id::BufferId, offset: wgt::BufferAddress, - size: wgt::BufferSize, + size: Option, ) { - unsafe { wgpu_render_pass_set_vertex_buffer(self, slot, *buffer, offset, size) } + wgpu_render_pass_set_vertex_buffer(self, slot, *buffer, offset, size) } fn draw(&mut self, vertices: Range, instances: Range) { - unsafe { - wgpu_render_pass_draw( - self, - vertices.end - vertices.start, - instances.end - instances.start, - vertices.start, - instances.start, - ) - } + wgpu_render_pass_draw( + self, + vertices.end - vertices.start, + instances.end - instances.start, + vertices.start, + instances.start, + ) } fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { - unsafe { - wgpu_render_pass_draw_indexed( - self, - indices.end - indices.start, - instances.end - instances.start, - indices.start, - base_vertex, - instances.start, - ) - } + wgpu_render_pass_draw_indexed( + self, + indices.end - indices.start, + instances.end - instances.start, + indices.start, + base_vertex, + instances.start, + ) } fn draw_indirect( &mut self, indirect_buffer: &wgc::id::BufferId, indirect_offset: wgt::BufferAddress, ) { - unsafe { wgpu_render_pass_draw_indirect(self, *indirect_buffer, indirect_offset) } + wgpu_render_pass_draw_indirect(self, *indirect_buffer, indirect_offset) } fn draw_indexed_indirect( &mut self, indirect_buffer: &wgc::id::BufferId, indirect_offset: wgt::BufferAddress, ) { - unsafe { - wgpu_render_pass_draw_indexed_indirect(self, *indirect_buffer, indirect_offset) - } + wgpu_render_pass_draw_indexed_indirect(self, *indirect_buffer, indirect_offset) } } - impl crate::RenderPassInner for wgc::command::RawPass { + impl crate::RenderPassInner for wgc::command::RenderPass { fn set_blend_color(&mut self, color: wgt::Color) { - unsafe { wgpu_render_pass_set_blend_color(self, &color) } + wgpu_render_pass_set_blend_color(self, &color) } fn set_scissor_rect(&mut self, x: u32, y: u32, width: u32, height: u32) { - unsafe { wgpu_render_pass_set_scissor_rect(self, x, y, width, height) } + wgpu_render_pass_set_scissor_rect(self, x, y, width, height) } fn set_viewport( &mut self, @@ -162,12 +156,10 @@ mod pass_impl { min_depth: f32, max_depth: f32, ) { - unsafe { - wgpu_render_pass_set_viewport(self, x, y, width, height, min_depth, max_depth) - } + wgpu_render_pass_set_viewport(self, x, y, width, height, min_depth, max_depth) } fn set_stencil_reference(&mut self, reference: u32) { - unsafe { wgpu_render_pass_set_stencil_reference(self, reference) } + wgpu_render_pass_set_stencil_reference(self, reference) } fn insert_debug_marker(&mut self, label: &str) { @@ -185,9 +177,7 @@ mod pass_impl { } fn pop_debug_group(&mut self) { - unsafe { - wgpu_render_pass_pop_debug_group(self); - } + wgpu_render_pass_pop_debug_group(self); } fn execute_bundles<'a, I: Iterator>( @@ -207,7 +197,7 @@ mod pass_impl { impl crate::RenderInner for wgc::command::RenderBundleEncoder { fn set_pipeline(&mut self, pipeline: &wgc::id::RenderPipelineId) { - unsafe { wgpu_render_bundle_set_pipeline(self, *pipeline) } + wgpu_render_bundle_set_pipeline(self, *pipeline) } fn set_bind_group( &mut self, @@ -229,57 +219,51 @@ mod pass_impl { &mut self, buffer: &wgc::id::BufferId, offset: wgt::BufferAddress, - size: wgt::BufferSize, + size: Option, ) { - unsafe { wgpu_render_bundle_set_index_buffer(self, *buffer, offset, size) } + wgpu_render_bundle_set_index_buffer(self, *buffer, offset, size) } fn set_vertex_buffer( &mut self, slot: u32, buffer: &wgc::id::BufferId, offset: wgt::BufferAddress, - size: wgt::BufferSize, + size: Option, ) { - unsafe { wgpu_render_bundle_set_vertex_buffer(self, slot, *buffer, offset, size) } + wgpu_render_bundle_set_vertex_buffer(self, slot, *buffer, offset, size) } fn draw(&mut self, vertices: Range, instances: Range) { - unsafe { - wgpu_render_bundle_draw( - self, - vertices.end - vertices.start, - instances.end - instances.start, - vertices.start, - instances.start, - ) - } + wgpu_render_bundle_draw( + self, + vertices.end - vertices.start, + instances.end - instances.start, + vertices.start, + instances.start, + ) } fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range) { - unsafe { - wgpu_render_bundle_draw_indexed( - self, - indices.end - indices.start, - instances.end - instances.start, - indices.start, - base_vertex, - instances.start, - ) - } + wgpu_render_bundle_draw_indexed( + self, + indices.end - indices.start, + instances.end - instances.start, + indices.start, + base_vertex, + instances.start, + ) } fn draw_indirect( &mut self, indirect_buffer: &wgc::id::BufferId, indirect_offset: wgt::BufferAddress, ) { - unsafe { wgpu_render_bundle_draw_indirect(self, *indirect_buffer, indirect_offset) } + wgpu_render_bundle_draw_indirect(self, *indirect_buffer, indirect_offset) } fn draw_indexed_indirect( &mut self, indirect_buffer: &wgc::id::BufferId, indirect_offset: wgt::BufferAddress, ) { - unsafe { - wgpu_render_pass_bundle_indexed_indirect(self, *indirect_buffer, indirect_offset) - } + wgpu_render_pass_bundle_indexed_indirect(self, *indirect_buffer, indirect_offset) } } } @@ -314,8 +298,8 @@ impl crate::Context for Context { type RenderPipelineId = wgc::id::RenderPipelineId; type ComputePipelineId = wgc::id::ComputePipelineId; type CommandEncoderId = wgc::id::CommandEncoderId; - type ComputePassId = wgc::command::RawPass; - type RenderPassId = wgc::command::RawPass; + type ComputePassId = wgc::command::ComputePass; + type RenderPassId = wgc::command::RenderPass; type CommandBufferId = wgc::id::CommandBufferId; type RenderBundleEncoderId = wgc::command::RenderBundleEncoder; type RenderBundleId = wgc::id::RenderBundleId; @@ -469,7 +453,7 @@ impl crate::Context for Context { bindings: &bindings, }, PhantomData - )) + )).unwrap() } fn device_create_pipeline_layout( @@ -647,7 +631,7 @@ impl crate::Context for Context { device: &Self::DeviceId, desc: &wgt::RenderBundleEncoderDescriptor, ) -> Self::RenderBundleEncoderId { - wgc::command::RenderBundleEncoder::new(desc, *device) + wgc::command::RenderBundleEncoder::new(desc, *device, None) } fn device_drop(&self, device: &Self::DeviceId) { @@ -711,7 +695,7 @@ impl crate::Context for Context { let ptr = gfx_select!(*buffer => self.buffer_get_mapped_range( *buffer, sub_range.start, - wgt::BufferSize(size) + wgt::BufferSize::new(size) )); unsafe { slice::from_raw_parts(ptr, size as usize) } } @@ -725,7 +709,7 @@ impl crate::Context for Context { let ptr = gfx_select!(*buffer => self.buffer_get_mapped_range( *buffer, sub_range.start, - wgt::BufferSize(size) + wgt::BufferSize::new(size) )); unsafe { slice::from_raw_parts_mut(ptr, size as usize) } } @@ -873,7 +857,7 @@ impl crate::Context for Context { &self, encoder: &Self::CommandEncoderId, ) -> Self::ComputePassId { - unsafe { wgc::command::RawPass::new_compute(*encoder) } + wgc::command::ComputePass::new(*encoder) } fn command_encoder_end_compute_pass( @@ -881,13 +865,7 @@ impl crate::Context for Context { encoder: &Self::CommandEncoderId, pass: &mut Self::ComputePassId, ) { - let data = unsafe { - let mut length = 0; - let ptr = wgc::command::compute_ffi::wgpu_compute_pass_finish(pass, &mut length); - slice::from_raw_parts(ptr, length) - }; - gfx_select!(*encoder => self.command_encoder_run_compute_pass(*encoder, data)); - unsafe { pass.invalidate() }; + gfx_select!(*encoder => self.command_encoder_run_compute_pass(*encoder, pass)); } fn command_encoder_begin_render_pass<'a>( @@ -898,39 +876,28 @@ impl crate::Context for Context { let colors = desc .color_attachments .iter() - .map(|ca| wgc::command::RenderPassColorAttachmentDescriptor { + .map(|ca| wgc::command::ColorAttachmentDescriptor { attachment: ca.attachment.id, resolve_target: ca.resolve_target.map(|rt| rt.id), - load_op: ca.load_op, - store_op: ca.store_op, - clear_color: ca.clear_color, + channel: ca.channel.clone(), }) - .collect::>(); + .collect::>(); let depth_stencil = desc.depth_stencil_attachment.as_ref().map(|dsa| { - wgc::command::RenderPassDepthStencilAttachmentDescriptor { + wgc::command::DepthStencilAttachmentDescriptor { attachment: dsa.attachment.id, - depth_load_op: dsa.depth_load_op, - depth_store_op: dsa.depth_store_op, - depth_read_only: dsa.depth_read_only, - clear_depth: dsa.clear_depth, - stencil_load_op: dsa.stencil_load_op, - stencil_store_op: dsa.stencil_store_op, - clear_stencil: dsa.clear_stencil, - stencil_read_only: dsa.depth_read_only, + depth: dsa.depth.clone(), + stencil: dsa.stencil.clone(), } }); - unsafe { - wgc::command::RawPass::new_render( - *encoder, - &wgc::command::RenderPassDescriptor { - color_attachments: colors.as_ptr(), - color_attachments_length: colors.len(), - depth_stencil_attachment: depth_stencil.as_ref(), - }, - ) - } + wgc::command::RenderPass::new( + *encoder, + wgc::command::RenderPassDescriptor { + color_attachments: &colors, + depth_stencil_attachment: depth_stencil.as_ref(), + }, + ) } fn command_encoder_end_render_pass( @@ -938,13 +905,7 @@ impl crate::Context for Context { encoder: &Self::CommandEncoderId, pass: &mut Self::RenderPassId, ) { - let data = unsafe { - let mut length = 0; - let ptr = wgc::command::render_ffi::wgpu_render_pass_finish(pass, &mut length); - slice::from_raw_parts(ptr, length) - }; - gfx_select!(*encoder => self.command_encoder_run_render_pass(*encoder, data)); - unsafe { pass.invalidate() }; + gfx_select!(*encoder => self.command_encoder_run_render_pass(*encoder, pass)); } fn command_encoder_finish(&self, encoder: &Self::CommandEncoderId) -> Self::CommandBufferId { @@ -958,7 +919,11 @@ impl crate::Context for Context { desc: &crate::RenderBundleDescriptor, ) -> Self::RenderBundleId { let owned_label = OwnedLabel::new(desc.label.as_deref()); - gfx_select!(encoder.parent() => self.render_bundle_encoder_finish(encoder, &desc.map_label(|_| owned_label.as_ptr()), PhantomData)) + gfx_select!(encoder.parent() => self.render_bundle_encoder_finish( + encoder, + &desc.map_label(|_| owned_label.as_ptr()), + PhantomData + )) } fn queue_write_buffer( diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index ccbb50da66..f6607aa98e 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -107,22 +107,27 @@ impl crate::RenderInner for RenderPass { &mut self, buffer: &Sendable, offset: wgt::BufferAddress, - size: wgt::BufferSize, + size: Option, ) { - assert_ne!(size, wgt::BufferSize::WHOLE); //TODO - self.0 - .set_index_buffer_with_f64_and_f64(&buffer.0, offset as f64, size.0 as f64); + self.0.set_index_buffer_with_f64_and_f64( + &buffer.0, + offset as f64, + size.expect("TODO").get() as f64, + ); } fn set_vertex_buffer( &mut self, slot: u32, buffer: &Sendable, offset: wgt::BufferAddress, - size: wgt::BufferSize, + size: Option, ) { - assert_ne!(size, wgt::BufferSize::WHOLE); //TODO - self.0 - .set_vertex_buffer_with_f64_and_f64(slot, &buffer.0, offset as f64, size.0 as f64); + self.0.set_vertex_buffer_with_f64_and_f64( + slot, + &buffer.0, + offset as f64, + size.expect("TODO").get() as f64, + ); } fn draw(&mut self, vertices: Range, instances: Range) { self.0 @@ -879,8 +884,8 @@ impl crate::Context for Context { let mut mapped_buffer_binding = web_sys::GpuBufferBinding::new(&buffer_slice.buffer.id.0); mapped_buffer_binding.offset(buffer_slice.offset as f64); - if buffer_slice.size != wgt::BufferSize::WHOLE { - mapped_buffer_binding.size(buffer_slice.size.0 as f64); + if let Some(s) = buffer_slice.size { + mapped_buffer_binding.size(s.get() as f64); } JsValue::from(mapped_buffer_binding.clone()) } @@ -1286,9 +1291,9 @@ impl crate::Context for Context { let mut mapped_color_attachment = web_sys::GpuRenderPassColorAttachmentDescriptor::new( &ca.attachment.id.0, - &match ca.load_op { + &match ca.channel.load_op { wgt::LoadOp::Clear => { - wasm_bindgen::JsValue::from(map_color(ca.clear_color)) + wasm_bindgen::JsValue::from(map_color(ca.channel.clear_value)) } wgt::LoadOp::Load => { wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load) @@ -1300,7 +1305,7 @@ impl crate::Context for Context { mapped_color_attachment.resolve_target(&rt.id.0); } - mapped_color_attachment.store_op(map_store_op(ca.store_op)); + mapped_color_attachment.store_op(map_store_op(ca.channel.store_op)); mapped_color_attachment }) @@ -1314,16 +1319,16 @@ impl crate::Context for Context { let mapped_depth_stencil_attachment = web_sys::GpuRenderPassDepthStencilAttachmentDescriptor::new( &dsa.attachment.id.0, - &match dsa.depth_load_op { - wgt::LoadOp::Clear => wasm_bindgen::JsValue::from(dsa.clear_depth), + &match dsa.depth.load_op { + wgt::LoadOp::Clear => wasm_bindgen::JsValue::from(dsa.depth.clear_value), wgt::LoadOp::Load => wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load), }, - map_store_op(dsa.depth_store_op), - &match dsa.stencil_load_op { - wgt::LoadOp::Clear => wasm_bindgen::JsValue::from(dsa.clear_stencil), + map_store_op(dsa.depth.store_op), + &match dsa.stencil.load_op { + wgt::LoadOp::Clear => wasm_bindgen::JsValue::from(dsa.stencil.clear_value), wgt::LoadOp::Load => wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load), }, - map_store_op(dsa.stencil_store_op), + map_store_op(dsa.stencil.store_op), ); mapped_desc.depth_stencil_attachment(&mapped_depth_stencil_attachment); diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index b5e839581a..9c492894df 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -26,7 +26,7 @@ pub use wgt::{ Capabilities, Color, ColorStateDescriptor, ColorWrite, CommandBufferDescriptor, CompareFunction, CullMode, DepthStencilStateDescriptor, DeviceDescriptor, DynamicOffset, Extensions, Extent3d, FilterMode, FrontFace, IndexFormat, InputStepMode, Limits, LoadOp, - NonZeroBufferAddress, Origin3d, PowerPreference, PresentMode, PrimitiveTopology, + Origin3d, PassChannel, PowerPreference, PresentMode, PrimitiveTopology, RasterizationStateDescriptor, RenderBundleEncoderDescriptor, ShaderLocation, ShaderStage, StencilOperation, StencilStateFaceDescriptor, StoreOp, SwapChainDescriptor, SwapChainStatus, TextureAspect, TextureComponentType, TextureDataLayout, TextureDimension, TextureFormat, @@ -60,13 +60,18 @@ trait RenderInner { bind_group: &Ctx::BindGroupId, offsets: &[DynamicOffset], ); - fn set_index_buffer(&mut self, buffer: &Ctx::BufferId, offset: BufferAddress, size: BufferSize); + fn set_index_buffer( + &mut self, + buffer: &Ctx::BufferId, + offset: BufferAddress, + size: Option, + ); fn set_vertex_buffer( &mut self, slot: u32, buffer: &Ctx::BufferId, offset: BufferAddress, - size: BufferSize, + size: Option, ); fn draw(&mut self, vertices: Range, instances: Range); fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range); @@ -420,11 +425,10 @@ impl MapContext { ); } - fn add(&mut self, offset: BufferAddress, size: BufferSize) -> BufferAddress { - let end = if size == BufferSize::WHOLE { - self.initial_range.end - } else { - offset + size.0 + fn add(&mut self, offset: BufferAddress, size: Option) -> BufferAddress { + let end = match size { + Some(s) => offset + s.get(), + None => self.initial_range.end, }; assert!(self.initial_range.start <= offset && end <= self.initial_range.end); for sub in self.sub_ranges.iter() { @@ -438,11 +442,10 @@ impl MapContext { end } - fn remove(&mut self, offset: BufferAddress, size: BufferSize) { - let end = if size == BufferSize::WHOLE { - self.initial_range.end - } else { - offset + size.0 + fn remove(&mut self, offset: BufferAddress, size: Option) { + let end = match size { + Some(s) => offset + s.get(), + None => self.initial_range.end, }; // Switch this out with `Vec::remove_item` once that stabilizes. @@ -474,7 +477,7 @@ pub struct Buffer { pub struct BufferSlice<'a> { buffer: &'a Buffer, offset: BufferAddress, - size: BufferSize, + size: Option, } /// Handle to a texture on the GPU. @@ -1313,16 +1316,18 @@ pub enum MapMode { Write, } -fn range_to_offset_size>(bounds: S) -> (BufferAddress, BufferSize) { +fn range_to_offset_size>( + bounds: S, +) -> (BufferAddress, Option) { let offset = match bounds.start_bound() { Bound::Included(&bound) => bound, Bound::Excluded(&bound) => bound + 1, Bound::Unbounded => 0, }; let size = match bounds.end_bound() { - Bound::Included(&bound) => BufferSize(bound + 1 - offset), - Bound::Excluded(&bound) => BufferSize(bound - offset), - Bound::Unbounded => BufferSize::WHOLE, + Bound::Included(&bound) => BufferSize::new(bound + 1 - offset), + Bound::Excluded(&bound) => BufferSize::new(bound - offset), + Bound::Unbounded => None, }; (offset, size) @@ -1408,31 +1413,7 @@ impl Buffer { } impl BufferSlice<'_> { - /// Use only a portion of this BufferSlice for a given operation. Choosing a range with no end - /// will use the rest of the buffer. Using a totally unbounded range will use the entire BufferSlice. - pub fn slice>(&self, bounds: S) -> Self { - let (sub_offset, sub_size) = range_to_offset_size(bounds); - let new_offset = self.offset + sub_offset; - let new_size = if sub_size == BufferSize::WHOLE { - BufferSize( - self.size - .0 - .checked_sub(sub_offset) - .expect("underflow when slicing `BufferSlice`"), - ) - } else { - assert!( - new_offset + sub_size.0 <= self.offset + self.size.0, - "offset and size must stay within the bounds of the parent slice" - ); - sub_size - }; - Self { - buffer: self.buffer, - offset: new_offset, - size: new_size, - } - } + //TODO: fn slice(&self) -> Self /// Map the buffer. Buffer is ready to map once the future is resolved. /// @@ -1454,10 +1435,9 @@ impl BufferSlice<'_> { "Buffer {:?} is already mapped", self.buffer.id ); - let end = if self.size == BufferSize::WHOLE { - mc.total_size - } else { - self.offset + self.size.0 + let end = match self.size { + Some(s) => self.offset + s.get(), + None => mc.total_size, }; mc.initial_range = self.offset..end; end