wgpu_core/init_tracker/
buffer.rs

1use super::{InitTracker, MemoryInitKind};
2use crate::resource::Buffer;
3use std::{ops::Range, sync::Arc};
4
5#[derive(Debug, Clone)]
6pub(crate) struct BufferInitTrackerAction {
7    pub buffer: Arc<Buffer>,
8    pub range: Range<wgt::BufferAddress>,
9    pub kind: MemoryInitKind,
10}
11
12pub(crate) type BufferInitTracker = InitTracker<wgt::BufferAddress>;
13
14impl BufferInitTracker {
15    /// Checks if an action has/requires any effect on the initialization status
16    /// and shrinks its range if possible.
17    pub(crate) fn check_action(
18        &self,
19        action: &BufferInitTrackerAction,
20    ) -> Option<BufferInitTrackerAction> {
21        self.create_action(&action.buffer, action.range.clone(), action.kind)
22    }
23
24    /// Creates an action if it would have any effect on the initialization
25    /// status and shrinks the range if possible.
26    pub(crate) fn create_action(
27        &self,
28        buffer: &Arc<Buffer>,
29        query_range: Range<wgt::BufferAddress>,
30        kind: MemoryInitKind,
31    ) -> Option<BufferInitTrackerAction> {
32        self.check(query_range)
33            .map(|range| BufferInitTrackerAction {
34                buffer: buffer.clone(),
35                range,
36                kind,
37            })
38    }
39}