replace the tracker in Device with a new DeviceTracker

This commit is contained in:
teoxoy 2024-07-04 18:59:56 +02:00 committed by Teodor Tanasoaia
parent 3142e15907
commit 0e1c1f7c07
6 changed files with 48 additions and 41 deletions

View File

@ -583,12 +583,6 @@ impl RenderBundleEncoder {
let render_bundle = Arc::new(render_bundle);
device
.trackers
.lock()
.bundles
.insert_single(render_bundle.clone());
Ok(render_bundle)
}

View File

@ -8,7 +8,7 @@ use crate::{
init_tracker::*,
resource::{DestroyedResourceError, ParentDevice, Texture, Trackable},
snatch::SnatchGuard,
track::{TextureTracker, Tracker},
track::{DeviceTracker, TextureTracker},
FastHashMap,
};
@ -167,7 +167,7 @@ impl<A: HalApi> BakedCommands<A> {
// executing the commands and updates resource init states accordingly
pub(crate) fn initialize_buffer_memory(
&mut self,
device_tracker: &mut Tracker<A>,
device_tracker: &mut DeviceTracker<A>,
snatch_guard: &SnatchGuard<'_>,
) -> Result<(), DestroyedResourceError> {
profiling::scope!("initialize_buffer_memory");
@ -267,7 +267,7 @@ impl<A: HalApi> BakedCommands<A> {
// uninitialized
pub(crate) fn initialize_texture_memory(
&mut self,
device_tracker: &mut Tracker<A>,
device_tracker: &mut DeviceTracker<A>,
device: &Device<A>,
snatch_guard: &SnatchGuard<'_>,
) -> Result<(), DestroyedResourceError> {

View File

@ -35,7 +35,7 @@ use crate::snatch::SnatchGuard;
use crate::init_tracker::BufferInitTrackerAction;
use crate::resource::Labeled;
use crate::track::{Tracker, UsageScope};
use crate::track::{DeviceTracker, Tracker, UsageScope};
use crate::LabelHelpers;
use crate::{api_log, global::Global, hal_api::HalApi, id, resource_log, Label};
@ -421,6 +421,30 @@ impl<A: HalApi> CommandBuffer<A> {
raw.transition_textures(texture_barriers);
}
}
pub(crate) fn insert_barriers_from_device_tracker(
raw: &mut A::CommandEncoder,
base: &mut DeviceTracker<A>,
head: &Tracker<A>,
snatch_guard: &SnatchGuard,
) {
profiling::scope!("insert_barriers_from_device_tracker");
base.buffers.set_from_tracker(&head.buffers);
base.textures.set_from_tracker(&head.textures);
let buffer_barriers = base.buffers.drain_transitions(snatch_guard);
let (transitions, textures) = base.textures.drain_transitions(snatch_guard);
let texture_barriers = transitions
.into_iter()
.enumerate()
.map(|(i, p)| p.into_hal(textures[i].unwrap().raw().unwrap()));
unsafe {
raw.transition_buffers(buffer_barriers);
raw.transition_textures(texture_barriers);
}
}
}
impl<A: HalApi> CommandBuffer<A> {

View File

@ -1320,7 +1320,7 @@ impl Global {
baked.initialize_texture_memory(&mut *trackers, device, &snatch_guard)?;
//Note: stateless trackers are not merged:
// device already knows these resources exist.
CommandBuffer::insert_barriers_from_tracker(
CommandBuffer::insert_barriers_from_device_tracker(
&mut baked.encoder,
&mut *trackers,
&baked.trackers,

View File

@ -28,7 +28,7 @@ use crate::{
resource_log,
snatch::{SnatchGuard, SnatchLock, Snatchable},
track::{
BindGroupStates, TextureSelector, Tracker, TrackerIndexAllocators, UsageScope,
BindGroupStates, DeviceTracker, TextureSelector, TrackerIndexAllocators, UsageScope,
UsageScopePool,
},
validation::{self, validate_color_attachment_bytes_per_sample},
@ -112,7 +112,7 @@ pub struct Device<A: HalApi> {
///
/// Has to be locked temporarily only (locked last)
/// and never before pending_writes
pub(crate) trackers: Mutex<Tracker<A>>,
pub(crate) trackers: Mutex<DeviceTracker<A>>,
pub(crate) tracker_indices: TrackerIndexAllocators,
// Life tracker should be locked right after the device and before anything else.
life_tracker: Mutex<LifetimeTracker<A>>,
@ -261,7 +261,7 @@ impl<A: HalApi> Device<A> {
fence: RwLock::new(rank::DEVICE_FENCE, Some(fence)),
snatchable_lock: unsafe { SnatchLock::new(rank::DEVICE_SNATCHABLE_LOCK) },
valid: AtomicBool::new(true),
trackers: Mutex::new(rank::DEVICE_TRACKERS, Tracker::new()),
trackers: Mutex::new(rank::DEVICE_TRACKERS, DeviceTracker::new()),
tracker_indices: TrackerIndexAllocators::new(),
life_tracker: Mutex::new(rank::DEVICE_LIFE_TRACKER, LifetimeTracker::new()),
bgl_pool: ResourcePool::new(),
@ -1273,8 +1273,6 @@ impl<A: HalApi> Device<A> {
views.push(Arc::downgrade(&view));
}
self.trackers.lock().views.insert_single(view.clone());
Ok(view)
}
@ -1390,8 +1388,6 @@ impl<A: HalApi> Device<A> {
let sampler = Arc::new(sampler);
self.trackers.lock().samplers.insert_single(sampler.clone());
Ok(sampler)
}
@ -2286,11 +2282,6 @@ impl<A: HalApi> Device<A> {
bind_groups.push(weak_ref.clone());
}
self.trackers
.lock()
.bind_groups
.insert_single(bind_group.clone());
Ok(bind_group)
}
@ -2711,11 +2702,6 @@ impl<A: HalApi> Device<A> {
let pipeline = Arc::new(pipeline);
self.trackers
.lock()
.compute_pipelines
.insert_single(pipeline.clone());
if is_auto_layout {
for bgl in pipeline.layout.bind_group_layouts.iter() {
bgl.exclusive_pipeline
@ -3342,11 +3328,6 @@ impl<A: HalApi> Device<A> {
let pipeline = Arc::new(pipeline);
self.trackers
.lock()
.render_pipelines
.insert_single(pipeline.clone());
if is_auto_layout {
for bgl in pipeline.layout.bind_group_layouts.iter() {
bgl.exclusive_pipeline
@ -3523,11 +3504,6 @@ impl<A: HalApi> Device<A> {
let query_set = Arc::new(query_set);
self.trackers
.lock()
.query_sets
.insert_single(query_set.clone());
Ok(query_set)
}

View File

@ -598,12 +598,26 @@ impl<'a, A: HalApi> UsageScope<'a, A> {
}
}
/// A full double sided tracker used by CommandBuffers and the Device.
/// A tracker used by Device.
pub(crate) struct DeviceTracker<A: HalApi> {
pub buffers: BufferTracker<A>,
pub textures: TextureTracker<A>,
}
impl<A: HalApi> DeviceTracker<A> {
pub fn new() -> Self {
Self {
buffers: BufferTracker::new(),
textures: TextureTracker::new(),
}
}
}
/// A full double sided tracker used by CommandBuffers.
pub(crate) struct Tracker<A: HalApi> {
pub buffers: BufferTracker<A>,
pub textures: TextureTracker<A>,
pub views: StatelessTracker<resource::TextureView<A>>,
pub samplers: StatelessTracker<resource::Sampler<A>>,
pub bind_groups: StatelessTracker<binding_model::BindGroup<A>>,
pub compute_pipelines: StatelessTracker<pipeline::ComputePipeline<A>>,
pub render_pipelines: StatelessTracker<pipeline::RenderPipeline<A>>,
@ -617,7 +631,6 @@ impl<A: HalApi> Tracker<A> {
buffers: BufferTracker::new(),
textures: TextureTracker::new(),
views: StatelessTracker::new(),
samplers: StatelessTracker::new(),
bind_groups: StatelessTracker::new(),
compute_pipelines: StatelessTracker::new(),
render_pipelines: StatelessTracker::new(),