diff options
Diffstat (limited to '')
-rw-r--r-- | third_party/rust/wgpu-core/src/command/bundle.rs | 21 | ||||
-rw-r--r-- | third_party/rust/wgpu-core/src/command/clear.rs | 7 | ||||
-rw-r--r-- | third_party/rust/wgpu-core/src/command/compute.rs | 9 | ||||
-rw-r--r-- | third_party/rust/wgpu-core/src/command/memory_init.rs | 11 | ||||
-rw-r--r-- | third_party/rust/wgpu-core/src/command/render.rs | 15 | ||||
-rw-r--r-- | third_party/rust/wgpu-core/src/command/transfer.rs | 19 |
6 files changed, 53 insertions, 29 deletions
diff --git a/third_party/rust/wgpu-core/src/command/bundle.rs b/third_party/rust/wgpu-core/src/command/bundle.rs index ab2d18bc59..47beda8ec6 100644 --- a/third_party/rust/wgpu-core/src/command/bundle.rs +++ b/third_party/rust/wgpu-core/src/command/bundle.rs @@ -99,6 +99,7 @@ use crate::{ pipeline::{PipelineFlags, RenderPipeline, VertexStep}, resource::{Buffer, Resource, ResourceInfo, ResourceType}, resource_log, + snatch::SnatchGuard, track::RenderBundleScope, validation::check_buffer_usage, Label, LabelHelpers, @@ -165,7 +166,7 @@ fn validate_indexed_draw<A: HalApi>( ) -> Result<(), DrawError> { let last_index = first_index as u64 + index_count as u64; let index_limit = index_state.limit(); - if last_index <= index_limit { + if last_index > index_limit { return Err(DrawError::IndexBeyondLimit { last_index, index_limit, @@ -894,7 +895,11 @@ impl<A: HalApi> RenderBundle<A> { /// Note that the function isn't expected to fail, generally. /// All the validation has already been done by this point. /// The only failure condition is if some of the used buffers are destroyed. - pub(super) unsafe fn execute(&self, raw: &mut A::CommandEncoder) -> Result<(), ExecutionError> { + pub(super) unsafe fn execute( + &self, + raw: &mut A::CommandEncoder, + snatch_guard: &SnatchGuard, + ) -> Result<(), ExecutionError> { let mut offsets = self.base.dynamic_offsets.as_slice(); let mut pipeline_layout = None::<Arc<PipelineLayout<A>>>; if !self.discard_hal_labels { @@ -903,8 +908,6 @@ impl<A: HalApi> RenderBundle<A> { } } - let snatch_guard = self.device.snatchable_lock.read(); - use ArcRenderCommand as Cmd; for command in self.base.commands.iter() { match command { @@ -914,7 +917,7 @@ impl<A: HalApi> RenderBundle<A> { bind_group, } => { let raw_bg = bind_group - .raw(&snatch_guard) + .raw(snatch_guard) .ok_or(ExecutionError::InvalidBindGroup(bind_group.info.id()))?; unsafe { raw.set_bind_group( @@ -938,7 +941,7 @@ impl<A: HalApi> RenderBundle<A> { size, } => { let buffer: &A::Buffer = buffer - .raw(&snatch_guard) + .raw(snatch_guard) .ok_or(ExecutionError::DestroyedBuffer(buffer.info.id()))?; let bb = hal::BufferBinding { buffer, @@ -954,7 +957,7 @@ impl<A: HalApi> RenderBundle<A> { size, } => { let buffer = buffer - .raw(&snatch_guard) + .raw(snatch_guard) .ok_or(ExecutionError::DestroyedBuffer(buffer.info.id()))?; let bb = hal::BufferBinding { buffer, @@ -1041,7 +1044,7 @@ impl<A: HalApi> RenderBundle<A> { indexed: false, } => { let buffer = buffer - .raw(&snatch_guard) + .raw(snatch_guard) .ok_or(ExecutionError::DestroyedBuffer(buffer.info.id()))?; unsafe { raw.draw_indirect(buffer, *offset, 1) }; } @@ -1052,7 +1055,7 @@ impl<A: HalApi> RenderBundle<A> { indexed: true, } => { let buffer = buffer - .raw(&snatch_guard) + .raw(snatch_guard) .ok_or(ExecutionError::DestroyedBuffer(buffer.info.id()))?; unsafe { raw.draw_indexed_indirect(buffer, *offset, 1) }; } diff --git a/third_party/rust/wgpu-core/src/command/clear.rs b/third_party/rust/wgpu-core/src/command/clear.rs index e404fabb14..72c923f82e 100644 --- a/third_party/rust/wgpu-core/src/command/clear.rs +++ b/third_party/rust/wgpu-core/src/command/clear.rs @@ -12,6 +12,7 @@ use crate::{ id::{BufferId, CommandEncoderId, DeviceId, TextureId}, init_tracker::{MemoryInitKind, TextureInitRange}, resource::{Resource, Texture, TextureClearMode}, + snatch::SnatchGuard, track::{TextureSelector, TextureTracker}, }; @@ -239,6 +240,7 @@ impl Global { } let (encoder, tracker) = cmd_buf_data.open_encoder_and_tracker()?; + let snatch_guard = device.snatchable_lock.read(); clear_texture( &dst_texture, TextureInitRange { @@ -249,6 +251,7 @@ impl Global { &mut tracker.textures, &device.alignments, device.zero_buffer.as_ref().unwrap(), + &snatch_guard, ) } } @@ -260,10 +263,10 @@ pub(crate) fn clear_texture<A: HalApi>( texture_tracker: &mut TextureTracker<A>, alignments: &hal::Alignments, zero_buffer: &A::Buffer, + snatch_guard: &SnatchGuard<'_>, ) -> Result<(), ClearError> { - let snatch_guard = dst_texture.device.snatchable_lock.read(); let dst_raw = dst_texture - .raw(&snatch_guard) + .raw(snatch_guard) .ok_or_else(|| ClearError::InvalidTexture(dst_texture.as_info().id()))?; // Issue the right barrier. diff --git a/third_party/rust/wgpu-core/src/command/compute.rs b/third_party/rust/wgpu-core/src/command/compute.rs index c2fd3ab397..b38324984c 100644 --- a/third_party/rust/wgpu-core/src/command/compute.rs +++ b/third_party/rust/wgpu-core/src/command/compute.rs @@ -272,14 +272,14 @@ where } } -struct State<A: HalApi> { +struct State<'a, A: HalApi> { binder: Binder<A>, pipeline: Option<id::ComputePipelineId>, - scope: UsageScope<A>, + scope: UsageScope<'a, A>, debug_scope_depth: u32, } -impl<A: HalApi> State<A> { +impl<'a, A: HalApi> State<'a, A> { fn is_ready(&self) -> Result<(), DispatchError> { let bind_mask = self.binder.invalid_mask(); if bind_mask != 0 { @@ -407,7 +407,7 @@ impl Global { let mut state = State { binder: Binder::new(), pipeline: None, - scope: UsageScope::new(&device.tracker_indices), + scope: device.new_usage_scope(), debug_scope_depth: 0, }; let mut temp_offsets = Vec::new(); @@ -868,6 +868,7 @@ impl Global { transit, &mut tracker.textures, device, + &snatch_guard, ); CommandBuffer::insert_barriers_from_tracker( transit, diff --git a/third_party/rust/wgpu-core/src/command/memory_init.rs b/third_party/rust/wgpu-core/src/command/memory_init.rs index 3bfc71f4f7..54bdedb792 100644 --- a/third_party/rust/wgpu-core/src/command/memory_init.rs +++ b/third_party/rust/wgpu-core/src/command/memory_init.rs @@ -7,6 +7,7 @@ use crate::{ hal_api::HalApi, init_tracker::*, resource::{Resource, Texture}, + snatch::SnatchGuard, track::{TextureTracker, Tracker}, FastHashMap, }; @@ -144,6 +145,7 @@ pub(crate) fn fixup_discarded_surfaces< encoder: &mut A::CommandEncoder, texture_tracker: &mut TextureTracker<A>, device: &Device<A>, + snatch_guard: &SnatchGuard<'_>, ) { for init in inits { clear_texture( @@ -156,6 +158,7 @@ pub(crate) fn fixup_discarded_surfaces< texture_tracker, &device.alignments, device.zero_buffer.as_ref().unwrap(), + snatch_guard, ) .unwrap(); } @@ -167,6 +170,7 @@ impl<A: HalApi> BakedCommands<A> { pub(crate) fn initialize_buffer_memory( &mut self, device_tracker: &mut Tracker<A>, + snatch_guard: &SnatchGuard<'_>, ) -> Result<(), DestroyedBufferError> { // Gather init ranges for each buffer so we can collapse them. // It is not possible to do this at an earlier point since previously @@ -225,16 +229,15 @@ impl<A: HalApi> BakedCommands<A> { .unwrap() .1; - let snatch_guard = buffer.device.snatchable_lock.read(); let raw_buf = buffer .raw - .get(&snatch_guard) + .get(snatch_guard) .ok_or(DestroyedBufferError(buffer_id))?; unsafe { self.encoder.transition_buffers( transition - .map(|pending| pending.into_hal(&buffer, &snatch_guard)) + .map(|pending| pending.into_hal(&buffer, snatch_guard)) .into_iter(), ); } @@ -271,6 +274,7 @@ impl<A: HalApi> BakedCommands<A> { &mut self, device_tracker: &mut Tracker<A>, device: &Device<A>, + snatch_guard: &SnatchGuard<'_>, ) -> Result<(), DestroyedTextureError> { let mut ranges: Vec<TextureInitRange> = Vec::new(); for texture_use in self.texture_memory_actions.drain_init_actions() { @@ -310,6 +314,7 @@ impl<A: HalApi> BakedCommands<A> { &mut device_tracker.textures, &device.alignments, device.zero_buffer.as_ref().unwrap(), + snatch_guard, ); // A Texture can be destroyed between the command recording diff --git a/third_party/rust/wgpu-core/src/command/render.rs b/third_party/rust/wgpu-core/src/command/render.rs index 9141ddb021..7e859e3cc8 100644 --- a/third_party/rust/wgpu-core/src/command/render.rs +++ b/third_party/rust/wgpu-core/src/command/render.rs @@ -739,9 +739,9 @@ impl<A: HalApi> TextureView<A> { const MAX_TOTAL_ATTACHMENTS: usize = hal::MAX_COLOR_ATTACHMENTS + hal::MAX_COLOR_ATTACHMENTS + 1; type AttachmentDataVec<T> = ArrayVec<T, MAX_TOTAL_ATTACHMENTS>; -struct RenderPassInfo<'a, A: HalApi> { +struct RenderPassInfo<'a, 'd, A: HalApi> { context: RenderPassContext, - usage_scope: UsageScope<A>, + usage_scope: UsageScope<'d, A>, /// All render attachments, including depth/stencil render_attachments: AttachmentDataVec<RenderAttachment<'a, A>>, is_depth_read_only: bool, @@ -754,7 +754,7 @@ struct RenderPassInfo<'a, A: HalApi> { multiview: Option<NonZeroU32>, } -impl<'a, A: HalApi> RenderPassInfo<'a, A> { +impl<'a, 'd, A: HalApi> RenderPassInfo<'a, 'd, A> { fn add_pass_texture_init_actions<V>( channel: &PassChannel<V>, texture_memory_actions: &mut CommandBufferTextureMemoryActions<A>, @@ -790,7 +790,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> { } fn start( - device: &Device<A>, + device: &'d Device<A>, label: Option<&str>, color_attachments: &[Option<RenderPassColorAttachment>], depth_stencil_attachment: Option<&RenderPassDepthStencilAttachment>, @@ -1214,7 +1214,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> { Ok(Self { context, - usage_scope: UsageScope::new(&device.tracker_indices), + usage_scope: device.new_usage_scope(), render_attachments, is_depth_read_only, is_stencil_read_only, @@ -1230,7 +1230,7 @@ impl<'a, A: HalApi> RenderPassInfo<'a, A> { mut self, raw: &mut A::CommandEncoder, snatch_guard: &SnatchGuard, - ) -> Result<(UsageScope<A>, SurfacesInDiscardState<A>), RenderPassErrorInner> { + ) -> Result<(UsageScope<'d, A>, SurfacesInDiscardState<A>), RenderPassErrorInner> { profiling::scope!("RenderPassInfo::finish"); unsafe { raw.end_render_pass(); @@ -2374,7 +2374,7 @@ impl Global { .extend(texture_memory_actions.register_init_action(action)); } - unsafe { bundle.execute(raw) } + unsafe { bundle.execute(raw, &snatch_guard) } .map_err(|e| match e { ExecutionError::DestroyedBuffer(id) => { RenderCommandError::DestroyedBuffer(id) @@ -2427,6 +2427,7 @@ impl Global { transit, &mut tracker.textures, &cmd_buf.device, + &snatch_guard, ); cmd_buf_data diff --git a/third_party/rust/wgpu-core/src/command/transfer.rs b/third_party/rust/wgpu-core/src/command/transfer.rs index 0a952dfc84..8e98a4c9b9 100644 --- a/third_party/rust/wgpu-core/src/command/transfer.rs +++ b/third_party/rust/wgpu-core/src/command/transfer.rs @@ -14,6 +14,7 @@ use crate::{ TextureInitTrackerAction, }, resource::{Resource, Texture, TextureErrorDimension}, + snatch::SnatchGuard, track::{TextureSelector, Tracker}, }; @@ -452,6 +453,7 @@ fn handle_texture_init<A: HalApi>( copy_texture: &ImageCopyTexture, copy_size: &Extent3d, texture: &Arc<Texture<A>>, + snatch_guard: &SnatchGuard<'_>, ) -> Result<(), ClearError> { let init_action = TextureInitTrackerAction { texture: texture.clone(), @@ -480,6 +482,7 @@ fn handle_texture_init<A: HalApi>( &mut trackers.textures, &device.alignments, device.zero_buffer.as_ref().unwrap(), + snatch_guard, )?; } } @@ -499,6 +502,7 @@ fn handle_src_texture_init<A: HalApi>( source: &ImageCopyTexture, copy_size: &Extent3d, texture: &Arc<Texture<A>>, + snatch_guard: &SnatchGuard<'_>, ) -> Result<(), TransferError> { handle_texture_init( MemoryInitKind::NeedsInitializedMemory, @@ -509,6 +513,7 @@ fn handle_src_texture_init<A: HalApi>( source, copy_size, texture, + snatch_guard, )?; Ok(()) } @@ -525,6 +530,7 @@ fn handle_dst_texture_init<A: HalApi>( destination: &ImageCopyTexture, copy_size: &Extent3d, texture: &Arc<Texture<A>>, + snatch_guard: &SnatchGuard<'_>, ) -> Result<(), TransferError> { // Attention: If we don't write full texture subresources, we need to a full // clear first since we don't track subrects. This means that in rare cases @@ -549,6 +555,7 @@ fn handle_dst_texture_init<A: HalApi>( destination, copy_size, texture, + snatch_guard, )?; Ok(()) } @@ -779,6 +786,8 @@ impl Global { let (dst_range, dst_base) = extract_texture_selector(destination, copy_size, &dst_texture)?; + let snatch_guard = device.snatchable_lock.read(); + // Handle texture init *before* dealing with barrier transitions so we // have an easier time inserting "immediate-inits" that may be required // by prior discards in rare cases. @@ -790,10 +799,9 @@ impl Global { destination, copy_size, &dst_texture, + &snatch_guard, )?; - let snatch_guard = device.snatchable_lock.read(); - let (src_buffer, src_pending) = { let buffer_guard = hub.buffers.read(); let src_buffer = buffer_guard @@ -935,6 +943,8 @@ impl Global { let (src_range, src_base) = extract_texture_selector(source, copy_size, &src_texture)?; + let snatch_guard = device.snatchable_lock.read(); + // Handle texture init *before* dealing with barrier transitions so we // have an easier time inserting "immediate-inits" that may be required // by prior discards in rare cases. @@ -946,10 +956,9 @@ impl Global { source, copy_size, &src_texture, + &snatch_guard, )?; - let snatch_guard = device.snatchable_lock.read(); - let src_pending = tracker .textures .set_single(&src_texture, src_range, hal::TextureUses::COPY_SRC) @@ -1152,6 +1161,7 @@ impl Global { source, copy_size, &src_texture, + &snatch_guard, )?; handle_dst_texture_init( encoder, @@ -1161,6 +1171,7 @@ impl Global { destination, copy_size, &dst_texture, + &snatch_guard, )?; let src_pending = cmd_buf_data |