mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Arcanization of wgpu_core resources --------- Co-authored-by: Elabajaba <Elabajaba@users.noreply.github.com> Co-authored-by: Niklas Korz <niklas@niklaskorz.de> Co-authored-by: grovesNL <josh@joshgroves.com> Co-authored-by: Jim Blandy <jimb@red-bean.com> Co-authored-by: Mauro Gentile <Mauro.Gentile@ubisoft.com> Co-authored-by: Sludge <96552222+SludgePhD@users.noreply.github.com>
40 lines
1.3 KiB
Rust
40 lines
1.3 KiB
Rust
use super::{InitTracker, MemoryInitKind};
|
|
use crate::{hal_api::HalApi, resource::Buffer};
|
|
use std::{ops::Range, sync::Arc};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub(crate) struct BufferInitTrackerAction<A: HalApi> {
|
|
pub buffer: Arc<Buffer<A>>,
|
|
pub range: Range<wgt::BufferAddress>,
|
|
pub kind: MemoryInitKind,
|
|
}
|
|
|
|
pub(crate) type BufferInitTracker = InitTracker<wgt::BufferAddress>;
|
|
|
|
impl BufferInitTracker {
|
|
/// Checks if an action has/requires any effect on the initialization status
|
|
/// and shrinks its range if possible.
|
|
pub(crate) fn check_action<A: HalApi>(
|
|
&self,
|
|
action: &BufferInitTrackerAction<A>,
|
|
) -> Option<BufferInitTrackerAction<A>> {
|
|
self.create_action(&action.buffer, action.range.clone(), action.kind)
|
|
}
|
|
|
|
/// Creates an action if it would have any effect on the initialization
|
|
/// status and shrinks the range if possible.
|
|
pub(crate) fn create_action<A: HalApi>(
|
|
&self,
|
|
buffer: &Arc<Buffer<A>>,
|
|
query_range: Range<wgt::BufferAddress>,
|
|
kind: MemoryInitKind,
|
|
) -> Option<BufferInitTrackerAction<A>> {
|
|
self.check(query_range)
|
|
.map(|range| BufferInitTrackerAction {
|
|
buffer: buffer.clone(),
|
|
range,
|
|
kind,
|
|
})
|
|
}
|
|
}
|