From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- third_party/rust/wgpu-hal/src/lib.rs | 253 ++++++++++++++++++++--------------- 1 file changed, 146 insertions(+), 107 deletions(-) (limited to 'third_party/rust/wgpu-hal/src/lib.rs') diff --git a/third_party/rust/wgpu-hal/src/lib.rs b/third_party/rust/wgpu-hal/src/lib.rs index f1794a4a89..79bd54e66e 100644 --- a/third_party/rust/wgpu-hal/src/lib.rs +++ b/third_party/rust/wgpu-hal/src/lib.rs @@ -191,13 +191,13 @@ impl InstanceError { } pub trait Api: Clone + fmt::Debug + Sized { - type Instance: Instance; - type Surface: Surface; - type Adapter: Adapter; - type Device: Device; + type Instance: Instance; + type Surface: Surface; + type Adapter: Adapter; + type Device: Device; - type Queue: Queue; - type CommandEncoder: CommandEncoder; + type Queue: Queue; + type CommandEncoder: CommandEncoder; type CommandBuffer: WasmNotSendSync + fmt::Debug; type Buffer: fmt::Debug + WasmNotSendSync + 'static; @@ -218,18 +218,22 @@ pub trait Api: Clone + fmt::Debug + Sized { type AccelerationStructure: fmt::Debug + WasmNotSendSync + 'static; } -pub trait Instance: Sized + WasmNotSendSync { +pub trait Instance: Sized + WasmNotSendSync { + type A: Api; + unsafe fn init(desc: &InstanceDescriptor) -> Result; unsafe fn create_surface( &self, display_handle: raw_window_handle::RawDisplayHandle, window_handle: raw_window_handle::RawWindowHandle, - ) -> Result; - unsafe fn destroy_surface(&self, surface: A::Surface); - unsafe fn enumerate_adapters(&self) -> Vec>; + ) -> Result<::Surface, InstanceError>; + unsafe fn destroy_surface(&self, surface: ::Surface); + unsafe fn enumerate_adapters(&self) -> Vec>; } -pub trait Surface: WasmNotSendSync { +pub trait Surface: WasmNotSendSync { + type A: Api; + /// Configures the surface to use the given device. /// /// # Safety @@ -240,7 +244,7 @@ pub trait Surface: WasmNotSendSync { /// - All surfaces created using other devices must have been unconfigured before this call. unsafe fn configure( &self, - device: &A::Device, + device: &::Device, config: &SurfaceConfiguration, ) -> Result<(), SurfaceError>; @@ -252,7 +256,7 @@ pub trait Surface: WasmNotSendSync { /// - All [`AcquiredSurfaceTexture`]s must have been destroyed. /// - All [`Api::TextureView`]s derived from the [`AcquiredSurfaceTexture`]s must have been destroyed. /// - The surface must have been configured on the given device. - unsafe fn unconfigure(&self, device: &A::Device); + unsafe fn unconfigure(&self, device: &::Device); /// Returns the next texture to be presented by the swapchain for drawing /// @@ -267,16 +271,18 @@ pub trait Surface: WasmNotSendSync { unsafe fn acquire_texture( &self, timeout: Option, - ) -> Result>, SurfaceError>; - unsafe fn discard_texture(&self, texture: A::SurfaceTexture); + ) -> Result>, SurfaceError>; + unsafe fn discard_texture(&self, texture: ::SurfaceTexture); } -pub trait Adapter: WasmNotSendSync { +pub trait Adapter: WasmNotSendSync { + type A: Api; + unsafe fn open( &self, features: wgt::Features, limits: &wgt::Limits, - ) -> Result, DeviceError>; + ) -> Result, DeviceError>; /// Return the set of supported capabilities for a texture format. unsafe fn texture_format_capabilities( @@ -287,7 +293,10 @@ pub trait Adapter: WasmNotSendSync { /// Returns the capabilities of working with a specified surface. /// /// `None` means presentation is not supported for it. - unsafe fn surface_capabilities(&self, surface: &A::Surface) -> Option; + unsafe fn surface_capabilities( + &self, + surface: &::Surface, + ) -> Option; /// Creates a [`PresentationTimestamp`] using the adapter's WSI. /// @@ -295,97 +304,111 @@ pub trait Adapter: WasmNotSendSync { unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp; } -pub trait Device: WasmNotSendSync { +pub trait Device: WasmNotSendSync { + type A: Api; + /// Exit connection to this logical device. - unsafe fn exit(self, queue: A::Queue); + unsafe fn exit(self, queue: ::Queue); /// Creates a new buffer. /// /// The initial usage is `BufferUses::empty()`. - unsafe fn create_buffer(&self, desc: &BufferDescriptor) -> Result; - unsafe fn destroy_buffer(&self, buffer: A::Buffer); + unsafe fn create_buffer( + &self, + desc: &BufferDescriptor, + ) -> Result<::Buffer, DeviceError>; + unsafe fn destroy_buffer(&self, buffer: ::Buffer); //TODO: clarify if zero-sized mapping is allowed unsafe fn map_buffer( &self, - buffer: &A::Buffer, + buffer: &::Buffer, range: MemoryRange, ) -> Result; - unsafe fn unmap_buffer(&self, buffer: &A::Buffer) -> Result<(), DeviceError>; - unsafe fn flush_mapped_ranges(&self, buffer: &A::Buffer, ranges: I) + unsafe fn unmap_buffer(&self, buffer: &::Buffer) -> Result<(), DeviceError>; + unsafe fn flush_mapped_ranges(&self, buffer: &::Buffer, ranges: I) where I: Iterator; - unsafe fn invalidate_mapped_ranges(&self, buffer: &A::Buffer, ranges: I) + unsafe fn invalidate_mapped_ranges(&self, buffer: &::Buffer, ranges: I) where I: Iterator; /// Creates a new texture. /// /// The initial usage for all subresources is `TextureUses::UNINITIALIZED`. - unsafe fn create_texture(&self, desc: &TextureDescriptor) -> Result; - unsafe fn destroy_texture(&self, texture: A::Texture); + unsafe fn create_texture( + &self, + desc: &TextureDescriptor, + ) -> Result<::Texture, DeviceError>; + unsafe fn destroy_texture(&self, texture: ::Texture); unsafe fn create_texture_view( &self, - texture: &A::Texture, + texture: &::Texture, desc: &TextureViewDescriptor, - ) -> Result; - unsafe fn destroy_texture_view(&self, view: A::TextureView); - unsafe fn create_sampler(&self, desc: &SamplerDescriptor) -> Result; - unsafe fn destroy_sampler(&self, sampler: A::Sampler); + ) -> Result<::TextureView, DeviceError>; + unsafe fn destroy_texture_view(&self, view: ::TextureView); + unsafe fn create_sampler( + &self, + desc: &SamplerDescriptor, + ) -> Result<::Sampler, DeviceError>; + unsafe fn destroy_sampler(&self, sampler: ::Sampler); /// Create a fresh [`CommandEncoder`]. /// /// The new `CommandEncoder` is in the "closed" state. unsafe fn create_command_encoder( &self, - desc: &CommandEncoderDescriptor, - ) -> Result; - unsafe fn destroy_command_encoder(&self, pool: A::CommandEncoder); + desc: &CommandEncoderDescriptor, + ) -> Result<::CommandEncoder, DeviceError>; + unsafe fn destroy_command_encoder(&self, pool: ::CommandEncoder); /// Creates a bind group layout. unsafe fn create_bind_group_layout( &self, desc: &BindGroupLayoutDescriptor, - ) -> Result; - unsafe fn destroy_bind_group_layout(&self, bg_layout: A::BindGroupLayout); + ) -> Result<::BindGroupLayout, DeviceError>; + unsafe fn destroy_bind_group_layout(&self, bg_layout: ::BindGroupLayout); unsafe fn create_pipeline_layout( &self, - desc: &PipelineLayoutDescriptor, - ) -> Result; - unsafe fn destroy_pipeline_layout(&self, pipeline_layout: A::PipelineLayout); + desc: &PipelineLayoutDescriptor, + ) -> Result<::PipelineLayout, DeviceError>; + unsafe fn destroy_pipeline_layout(&self, pipeline_layout: ::PipelineLayout); unsafe fn create_bind_group( &self, - desc: &BindGroupDescriptor, - ) -> Result; - unsafe fn destroy_bind_group(&self, group: A::BindGroup); + desc: &BindGroupDescriptor, + ) -> Result<::BindGroup, DeviceError>; + unsafe fn destroy_bind_group(&self, group: ::BindGroup); unsafe fn create_shader_module( &self, desc: &ShaderModuleDescriptor, shader: ShaderInput, - ) -> Result; - unsafe fn destroy_shader_module(&self, module: A::ShaderModule); + ) -> Result<::ShaderModule, ShaderError>; + unsafe fn destroy_shader_module(&self, module: ::ShaderModule); unsafe fn create_render_pipeline( &self, - desc: &RenderPipelineDescriptor, - ) -> Result; - unsafe fn destroy_render_pipeline(&self, pipeline: A::RenderPipeline); + desc: &RenderPipelineDescriptor, + ) -> Result<::RenderPipeline, PipelineError>; + unsafe fn destroy_render_pipeline(&self, pipeline: ::RenderPipeline); unsafe fn create_compute_pipeline( &self, - desc: &ComputePipelineDescriptor, - ) -> Result; - unsafe fn destroy_compute_pipeline(&self, pipeline: A::ComputePipeline); + desc: &ComputePipelineDescriptor, + ) -> Result<::ComputePipeline, PipelineError>; + unsafe fn destroy_compute_pipeline(&self, pipeline: ::ComputePipeline); unsafe fn create_query_set( &self, desc: &wgt::QuerySetDescriptor, + desc: &GetAccelerationStructureBuildSizesDescriptor, ) -> AccelerationStructureBuildSizes; unsafe fn get_acceleration_structure_device_address( &self, - acceleration_structure: &A::AccelerationStructure, + acceleration_structure: &::AccelerationStructure, ) -> wgt::BufferAddress; unsafe fn destroy_acceleration_structure( &self, - acceleration_structure: A::AccelerationStructure, + acceleration_structure: ::AccelerationStructure, ); } -pub trait Queue: WasmNotSendSync { +pub trait Queue: WasmNotSendSync { + type A: Api; + /// Submits the command buffers for execution on GPU. /// /// Valid usage: @@ -422,14 +447,14 @@ pub trait Queue: WasmNotSendSync { /// passed to the surface_textures argument. unsafe fn submit( &self, - command_buffers: &[&A::CommandBuffer], - surface_textures: &[&A::SurfaceTexture], - signal_fence: Option<(&mut A::Fence, FenceValue)>, + command_buffers: &[&::CommandBuffer], + surface_textures: &[&::SurfaceTexture], + signal_fence: Option<(&mut ::Fence, FenceValue)>, ) -> Result<(), DeviceError>; unsafe fn present( &self, - surface: &A::Surface, - texture: A::SurfaceTexture, + surface: &::Surface, + texture: ::SurfaceTexture, ) -> Result<(), SurfaceError>; unsafe fn get_timestamp_period(&self) -> f32; } @@ -472,7 +497,9 @@ pub trait Queue: WasmNotSendSync { /// built it. /// /// - A `CommandEncoder` must not outlive its `Device`. -pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { +pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { + type A: Api; + /// Begin encoding a new command buffer. /// /// This puts this `CommandEncoder` in the "recording" state. @@ -510,7 +537,7 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { /// /// [`CommandBuffer`]: Api::CommandBuffer /// [`begin_encoding`]: CommandEncoder::begin_encoding - unsafe fn end_encoding(&mut self) -> Result; + unsafe fn end_encoding(&mut self) -> Result<::CommandBuffer, DeviceError>; /// Reclaim all resources belonging to this `CommandEncoder`. /// @@ -525,22 +552,26 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { /// [`CommandBuffer`]: Api::CommandBuffer unsafe fn reset_all(&mut self, command_buffers: I) where - I: Iterator; + I: Iterator::CommandBuffer>; unsafe fn transition_buffers<'a, T>(&mut self, barriers: T) where - T: Iterator>; + T: Iterator>; unsafe fn transition_textures<'a, T>(&mut self, barriers: T) where - T: Iterator>; + T: Iterator>; // copy operations - unsafe fn clear_buffer(&mut self, buffer: &A::Buffer, range: MemoryRange); + unsafe fn clear_buffer(&mut self, buffer: &::Buffer, range: MemoryRange); - unsafe fn copy_buffer_to_buffer(&mut self, src: &A::Buffer, dst: &A::Buffer, regions: T) - where + unsafe fn copy_buffer_to_buffer( + &mut self, + src: &::Buffer, + dst: &::Buffer, + regions: T, + ) where T: Iterator; /// Copy from an external image to an internal texture. @@ -551,7 +582,7 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { unsafe fn copy_external_image_to_texture( &mut self, src: &wgt::ImageCopyExternalImage, - dst: &A::Texture, + dst: &::Texture, dst_premultiplication: bool, regions: T, ) where @@ -563,9 +594,9 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { /// Note: the copy extent is in physical size (rounded to the block size) unsafe fn copy_texture_to_texture( &mut self, - src: &A::Texture, + src: &::Texture, src_usage: TextureUses, - dst: &A::Texture, + dst: &::Texture, regions: T, ) where T: Iterator; @@ -574,8 +605,12 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { /// Works with a single array layer. /// Note: `dst` current usage has to be `TextureUses::COPY_DST`. /// Note: the copy extent is in physical size (rounded to the block size) - unsafe fn copy_buffer_to_texture(&mut self, src: &A::Buffer, dst: &A::Texture, regions: T) - where + unsafe fn copy_buffer_to_texture( + &mut self, + src: &::Buffer, + dst: &::Texture, + regions: T, + ) where T: Iterator; /// Copy from texture to buffer. @@ -583,9 +618,9 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { /// Note: the copy extent is in physical size (rounded to the block size) unsafe fn copy_texture_to_buffer( &mut self, - src: &A::Texture, + src: &::Texture, src_usage: TextureUses, - dst: &A::Buffer, + dst: &::Buffer, regions: T, ) where T: Iterator; @@ -596,9 +631,9 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { /// of all the preceding groups to be taken from `layout`. unsafe fn set_bind_group( &mut self, - layout: &A::PipelineLayout, + layout: &::PipelineLayout, index: u32, - group: &A::BindGroup, + group: &::BindGroup, dynamic_offsets: &[wgt::DynamicOffset], ); @@ -612,7 +647,7 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { /// - The range of push constants written must be valid for the pipeline layout at draw time. unsafe fn set_push_constants( &mut self, - layout: &A::PipelineLayout, + layout: &::PipelineLayout, stages: wgt::ShaderStages, offset_bytes: u32, data: &[u32], @@ -627,18 +662,18 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { /// # Safety: /// /// - If `set` is an occlusion query set, it must be the same one as used in the [`RenderPassDescriptor::occlusion_query_set`] parameter. - unsafe fn begin_query(&mut self, set: &A::QuerySet, index: u32); + unsafe fn begin_query(&mut self, set: &::QuerySet, index: u32); /// # Safety: /// /// - If `set` is an occlusion query set, it must be the same one as used in the [`RenderPassDescriptor::occlusion_query_set`] parameter. - unsafe fn end_query(&mut self, set: &A::QuerySet, index: u32); - unsafe fn write_timestamp(&mut self, set: &A::QuerySet, index: u32); - unsafe fn reset_queries(&mut self, set: &A::QuerySet, range: Range); + unsafe fn end_query(&mut self, set: &::QuerySet, index: u32); + unsafe fn write_timestamp(&mut self, set: &::QuerySet, index: u32); + unsafe fn reset_queries(&mut self, set: &::QuerySet, range: Range); unsafe fn copy_query_results( &mut self, - set: &A::QuerySet, + set: &::QuerySet, range: Range, - buffer: &A::Buffer, + buffer: &::Buffer, offset: wgt::BufferAddress, stride: wgt::BufferSize, ); @@ -646,17 +681,17 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { // render passes // Begins a render pass, clears all active bindings. - unsafe fn begin_render_pass(&mut self, desc: &RenderPassDescriptor); + unsafe fn begin_render_pass(&mut self, desc: &RenderPassDescriptor); unsafe fn end_render_pass(&mut self); - unsafe fn set_render_pipeline(&mut self, pipeline: &A::RenderPipeline); + unsafe fn set_render_pipeline(&mut self, pipeline: &::RenderPipeline); unsafe fn set_index_buffer<'a>( &mut self, - binding: BufferBinding<'a, A>, + binding: BufferBinding<'a, Self::A>, format: wgt::IndexFormat, ); - unsafe fn set_vertex_buffer<'a>(&mut self, index: u32, binding: BufferBinding<'a, A>); + unsafe fn set_vertex_buffer<'a>(&mut self, index: u32, binding: BufferBinding<'a, Self::A>); unsafe fn set_viewport(&mut self, rect: &Rect, depth_range: Range); unsafe fn set_scissor_rect(&mut self, rect: &Rect); unsafe fn set_stencil_reference(&mut self, value: u32); @@ -679,29 +714,29 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { ); unsafe fn draw_indirect( &mut self, - buffer: &A::Buffer, + buffer: &::Buffer, offset: wgt::BufferAddress, draw_count: u32, ); unsafe fn draw_indexed_indirect( &mut self, - buffer: &A::Buffer, + buffer: &::Buffer, offset: wgt::BufferAddress, draw_count: u32, ); unsafe fn draw_indirect_count( &mut self, - buffer: &A::Buffer, + buffer: &::Buffer, offset: wgt::BufferAddress, - count_buffer: &A::Buffer, + count_buffer: &::Buffer, count_offset: wgt::BufferAddress, max_count: u32, ); unsafe fn draw_indexed_indirect_count( &mut self, - buffer: &A::Buffer, + buffer: &::Buffer, offset: wgt::BufferAddress, - count_buffer: &A::Buffer, + count_buffer: &::Buffer, count_offset: wgt::BufferAddress, max_count: u32, ); @@ -709,13 +744,17 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { // compute passes // Begins a compute pass, clears all active bindings. - unsafe fn begin_compute_pass(&mut self, desc: &ComputePassDescriptor); + unsafe fn begin_compute_pass(&mut self, desc: &ComputePassDescriptor); unsafe fn end_compute_pass(&mut self); - unsafe fn set_compute_pipeline(&mut self, pipeline: &A::ComputePipeline); + unsafe fn set_compute_pipeline(&mut self, pipeline: &::ComputePipeline); unsafe fn dispatch(&mut self, count: [u32; 3]); - unsafe fn dispatch_indirect(&mut self, buffer: &A::Buffer, offset: wgt::BufferAddress); + unsafe fn dispatch_indirect( + &mut self, + buffer: &::Buffer, + offset: wgt::BufferAddress, + ); /// To get the required sizes for the buffer allocations use `get_acceleration_structure_build_sizes` per descriptor /// All buffers must be synchronized externally @@ -729,8 +768,8 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { descriptor_count: u32, descriptors: T, ) where - A: 'a, - T: IntoIterator>; + Self::A: 'a, + T: IntoIterator>; unsafe fn place_acceleration_structure_barrier( &mut self, -- cgit v1.2.3