diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 6ae8ca5aef..9262741d7b 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -26,14 +26,14 @@ vulkan-portability = ["wgc/gfx-backend-vulkan", "gfx-backend-vulkan"] package = "wgpu-core" #version = "0.6" git = "https://github.com/gfx-rs/wgpu" -rev = "8059c03273bd7272688e3dac661e72c4973a2d0b" +rev = "44a41dc9a4eac8ddc37675f0d52486ded27bdbb3" features = ["raw-window-handle"] [dependencies.wgt] package = "wgpu-types" #version = "0.6" git = "https://github.com/gfx-rs/wgpu" -rev = "8059c03273bd7272688e3dac661e72c4973a2d0b" +rev = "44a41dc9a4eac8ddc37675f0d52486ded27bdbb3" [dependencies] arrayvec = "0.5" diff --git a/wgpu/examples/framework.rs b/wgpu/examples/framework.rs index 27c1157ab3..622c51d6b2 100644 --- a/wgpu/examples/framework.rs +++ b/wgpu/examples/framework.rs @@ -108,7 +108,20 @@ async fn setup(title: &str) -> Setup { log::info!("Initializing the surface..."); - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let backend = if let Ok(backend) = std::env::var("WGPU_TRACE") { + match backend.to_lowercase().as_str() { + "vulkan" => wgpu::BackendBit::VULKAN, + "metal" => wgpu::BackendBit::METAL, + "dx12" => wgpu::BackendBit::DX12, + "dx11" => wgpu::BackendBit::DX11, + "gl" => wgpu::BackendBit::GL, + "webgpu" => wgpu::BackendBit::BROWSER_WEBGPU, + other => panic!("Unknown backend: {}", other), + } + } else { + wgpu::BackendBit::PRIMARY + }; + let instance = wgpu::Instance::new(backend); let (size, surface) = unsafe { let size = window.inner_size(); let surface = instance.create_surface(&window); diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 13ad529772..319732b7e9 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -88,14 +88,12 @@ mod pass_impl { ) } } - fn set_push_constants(&mut self, offset: u32, data: &[u32]) { + fn set_push_constants(&mut self, offset: u32, data: &[u8]) { unsafe { wgpu_compute_pass_set_push_constant( self, offset, - (data.len() * std::mem::size_of::()) - .try_into() - .unwrap(), + data.len().try_into().unwrap(), data.as_ptr(), ) } @@ -165,15 +163,13 @@ mod pass_impl { ) { wgpu_render_pass_set_vertex_buffer(self, slot, buffer.id, offset, size) } - fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u32]) { + fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) { unsafe { wgpu_render_pass_set_push_constants( self, stages, offset, - (data.len() * std::mem::size_of::()) - .try_into() - .unwrap(), + data.len().try_into().unwrap(), data.as_ptr(), ) } @@ -362,15 +358,13 @@ mod pass_impl { wgpu_render_bundle_set_vertex_buffer(self, slot, buffer.id, offset, size) } - fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u32]) { + fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) { unsafe { wgpu_render_bundle_set_push_constants( self, stages, offset, - (data.len() * std::mem::size_of::()) - .try_into() - .unwrap(), + data.len().try_into().unwrap(), data.as_ptr(), ) } @@ -1212,9 +1206,21 @@ impl crate::Context for Context { ) } + fn buffer_destroy(&self, buffer: &Self::BufferId) { + let global = &self.0; + wgc::gfx_select!(buffer.id => global.buffer_destroy(buffer.id)).unwrap_pretty() + } + fn buffer_drop(&self, buffer: &Self::BufferId) { + let global = &self.0; + wgc::gfx_select!(buffer.id => global.buffer_drop(buffer.id, false)) + } + fn texture_destroy(&self, texture: &Self::TextureId) { + let global = &self.0; + wgc::gfx_select!(texture.id => global.texture_destroy(texture.id)).unwrap_pretty() + } fn texture_drop(&self, texture: &Self::TextureId) { let global = &self.0; - wgc::gfx_select!(texture.id => global.texture_drop(texture.id)) + wgc::gfx_select!(texture.id => global.texture_drop(texture.id, false)) } fn texture_view_drop(&self, texture_view: &Self::TextureViewId) { let global = &self.0; @@ -1224,10 +1230,6 @@ impl crate::Context for Context { let global = &self.0; wgc::gfx_select!(*sampler => global.sampler_drop(*sampler)) } - fn buffer_drop(&self, buffer: &Self::BufferId) { - let global = &self.0; - wgc::gfx_select!(buffer.id => global.buffer_drop(buffer.id, false)) - } fn bind_group_drop(&self, bind_group: &Self::BindGroupId) { let global = &self.0; wgc::gfx_select!(*bind_group => global.bind_group_drop(*bind_group)) diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index b051d0f424..d0dce39506 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -109,7 +109,7 @@ impl crate::ComputePassInner for ComputePass { offsets.len() as u32, ); } - fn set_push_constants(&mut self, _offset: u32, _data: &[u32]) { + fn set_push_constants(&mut self, _offset: u32, _data: &[u8]) { panic!("PUSH_CONSTANTS feature must be enabled to call multi_draw_indexed_indirect") } @@ -184,7 +184,7 @@ impl crate::RenderInner for RenderPass { self.0 .set_vertex_buffer_with_f64_and_f64(slot, &buffer.0, offset as f64, mapped_size); } - fn set_push_constants(&mut self, _stages: wgt::ShaderStage, _offset: u32, _data: &[u32]) { + fn set_push_constants(&mut self, _stages: wgt::ShaderStage, _offset: u32, _data: &[u8]) { panic!("PUSH_CONSTANTS feature must be enabled to call multi_draw_indexed_indirect") } fn draw(&mut self, vertices: Range, instances: Range) { @@ -1267,6 +1267,15 @@ impl crate::Context for Context { Sendable(texture.0.create_view_with_descriptor(&mapped)) } + fn buffer_destroy(&self, _buffer: &Self::BufferId) { + // TODO + } + fn buffer_drop(&self, _buffer: &Self::BufferId) { + // Dropped automatically + } + fn texture_destroy(&self, _texture: &Self::TextureId) { + // TODO + } fn texture_drop(&self, _texture: &Self::TextureId) { // Dropped automatically } @@ -1276,9 +1285,6 @@ impl crate::Context for Context { fn sampler_drop(&self, _sampler: &Self::SamplerId) { // Dropped automatically } - fn buffer_drop(&self, _buffer: &Self::BufferId) { - // Dropped automatically - } fn bind_group_drop(&self, _bind_group: &Self::BindGroupId) { // Dropped automatically } diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 25ced1d2a9..e08dff11c6 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -55,7 +55,7 @@ trait ComputePassInner { bind_group: &Ctx::BindGroupId, offsets: &[DynamicOffset], ); - fn set_push_constants(&mut self, offset: u32, data: &[u32]); + fn set_push_constants(&mut self, offset: u32, data: &[u8]); fn insert_debug_marker(&mut self, label: &str); fn push_debug_group(&mut self, group_label: &str); fn pop_debug_group(&mut self); @@ -88,7 +88,7 @@ trait RenderInner { offset: BufferAddress, size: Option, ); - fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u32]); + fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]); fn draw(&mut self, vertices: Range, instances: Range); fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range); fn draw_indirect(&mut self, indirect_buffer: &Ctx::BufferId, indirect_offset: BufferAddress); @@ -301,10 +301,13 @@ trait Context: Debug + Send + Sized + Sync { texture: &Self::TextureId, desc: &TextureViewDescriptor, ) -> Self::TextureViewId; + + fn buffer_destroy(&self, buffer: &Self::BufferId); + fn buffer_drop(&self, buffer: &Self::BufferId); + fn texture_destroy(&self, buffer: &Self::TextureId); fn texture_drop(&self, texture: &Self::TextureId); fn texture_view_drop(&self, texture_view: &Self::TextureViewId); fn sampler_drop(&self, sampler: &Self::SamplerId); - fn buffer_drop(&self, buffer: &Self::BufferId); fn bind_group_drop(&self, bind_group: &Self::BindGroupId); fn bind_group_layout_drop(&self, bind_group_layout: &Self::BindGroupLayoutId); fn pipeline_layout_drop(&self, pipeline_layout: &Self::PipelineLayoutId); @@ -1716,6 +1719,11 @@ impl Buffer { self.map_context.lock().reset(); Context::buffer_unmap(&*self.context, &self.id); } + + /// Destroy the associated native resources as soon as possible. + pub fn destroy(&self) { + Context::buffer_destroy(&*self.context, &self.id); + } } impl<'a> BufferSlice<'a> { @@ -1802,6 +1810,11 @@ impl Texture { owned: true, } } + + /// Destroy the associated native resources as soon as possible. + pub fn destroy(&self) { + Context::texture_destroy(&*self.context, &self.id); + } } impl Drop for Texture { @@ -2316,7 +2329,7 @@ impl<'a> RenderPass<'a> { /// /// You would need to upload this in three set_push_constants calls. First for the `Vertex` only range 0..4, second /// for the `Vertex | Fragment` range 4..8, third for the `Fragment` range 8..12. - pub fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u32]) { + pub fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) { self.id.set_push_constants(stages, offset, data); } } @@ -2392,7 +2405,7 @@ impl<'a> ComputePass<'a> { /// Data size must be a multiple of 4 and must be aligned to the 4s, so we take an array of u32. /// For example, with an offset of 4 and an array of `[u32; 3]`, that will write to the range /// of 4..16. - pub fn set_push_constants(&mut self, offset: u32, data: &[u32]) { + pub fn set_push_constants(&mut self, offset: u32, data: &[u8]) { self.id.set_push_constants(offset, data); } } @@ -2561,7 +2574,7 @@ impl<'a> RenderBundleEncoder<'a> { /// /// You would need to upload this in three set_push_constants calls. First for the `Vertex` only range 0..4, second /// for the `Vertex | Fragment` range 4..8, third for the `Fragment` range 8..12. - pub fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u32]) { + pub fn set_push_constants(&mut self, stages: wgt::ShaderStage, offset: u32, data: &[u8]) { self.id.set_push_constants(stages, offset, data); } }