remove all internal RenderBundleScope RwLocks

This commit is contained in:
teoxoy 2024-08-02 19:08:52 +02:00 committed by Teodor Tanasoaia
parent 5cb1be63aa
commit 826e3716e5
3 changed files with 17 additions and 54 deletions

View File

@ -370,16 +370,8 @@ impl RenderBundleEncoder {
};
let indices = &state.device.tracker_indices;
state
.trackers
.buffers
.write()
.set_size(indices.buffers.size());
state
.trackers
.textures
.write()
.set_size(indices.textures.size());
state.trackers.buffers.set_size(indices.buffers.size());
state.trackers.textures.set_size(indices.textures.size());
let base = &self.base;
@ -626,7 +618,7 @@ fn set_bind_group<A: HalApi>(
state.set_bind_group(index, &bind_group, offsets_range);
unsafe { state.trackers.merge_bind_group(&bind_group.used)? };
state.trackers.bind_groups.write().insert_single(bind_group);
state.trackers.bind_groups.insert_single(bind_group);
// Note: stateless trackers are not merged: the lifetime reference
// is held to the bind group itself.
Ok(())
@ -671,11 +663,7 @@ fn set_pipeline<A: HalApi>(
state.invalidate_bind_groups(&pipeline_state, &pipeline.layout);
state.pipeline = Some(pipeline_state);
state
.trackers
.render_pipelines
.write()
.insert_single(pipeline);
state.trackers.render_pipelines.insert_single(pipeline);
Ok(())
}
@ -694,7 +682,6 @@ fn set_index_buffer<A: HalApi>(
state
.trackers
.buffers
.write()
.merge_single(&buffer, hal::BufferUses::INDEX)?;
buffer.same_device(&state.device)?;
@ -739,7 +726,6 @@ fn set_vertex_buffer<A: HalApi>(
state
.trackers
.buffers
.write()
.merge_single(&buffer, hal::BufferUses::VERTEX)?;
buffer.same_device(&state.device)?;
@ -881,7 +867,6 @@ fn multi_draw_indirect<A: HalApi>(
state
.trackers
.buffers
.write()
.merge_single(&buffer, hal::BufferUses::INDIRECT)?;
buffer.same_device(&state.device)?;

View File

@ -129,10 +129,6 @@ define_lock_ranks! {
rank DEVICE_USAGE_SCOPES "Device::usage_scopes" followed by { }
rank IDENTITY_MANAGER_VALUES "IdentityManager::values" followed by { }
rank REGISTRY_STORAGE "Registry::storage" followed by { }
rank RENDER_BUNDLE_SCOPE_BUFFERS "RenderBundleScope::buffers" followed by { }
rank RENDER_BUNDLE_SCOPE_TEXTURES "RenderBundleScope::textures" followed by { }
rank RENDER_BUNDLE_SCOPE_BIND_GROUPS "RenderBundleScope::bind_groups" followed by { }
rank RENDER_BUNDLE_SCOPE_RENDER_PIPELINES "RenderBundleScope::render_pipelines" followed by { }
rank RESOURCE_POOL_INNER "ResourcePool::inner" followed by { }
rank SHARED_TRACKER_INDEX_ALLOCATOR_INNER "SharedTrackerIndexAllocator::inner" followed by { }
rank SURFACE_PRESENTATION "Surface::presentation" followed by { }

View File

@ -104,7 +104,7 @@ mod texture;
use crate::{
binding_model, command,
hal_api::HalApi,
lock::{rank, Mutex, RwLock},
lock::{rank, Mutex},
pipeline,
resource::{self, Labeled, ResourceErrorIdent},
snatch::SnatchGuard,
@ -452,33 +452,21 @@ impl<A: HalApi> BindGroupStates<A> {
/// and need to be owned by the render bundles.
#[derive(Debug)]
pub(crate) struct RenderBundleScope<A: HalApi> {
pub buffers: RwLock<BufferUsageScope<A>>,
pub textures: RwLock<TextureUsageScope<A>>,
pub buffers: BufferUsageScope<A>,
pub textures: TextureUsageScope<A>,
// Don't need to track views and samplers, they are never used directly, only by bind groups.
pub bind_groups: RwLock<StatelessTracker<binding_model::BindGroup<A>>>,
pub render_pipelines: RwLock<StatelessTracker<pipeline::RenderPipeline<A>>>,
pub bind_groups: StatelessTracker<binding_model::BindGroup<A>>,
pub render_pipelines: StatelessTracker<pipeline::RenderPipeline<A>>,
}
impl<A: HalApi> RenderBundleScope<A> {
/// Create the render bundle scope and pull the maximum IDs from the hubs.
pub fn new() -> Self {
Self {
buffers: RwLock::new(
rank::RENDER_BUNDLE_SCOPE_BUFFERS,
BufferUsageScope::default(),
),
textures: RwLock::new(
rank::RENDER_BUNDLE_SCOPE_TEXTURES,
TextureUsageScope::default(),
),
bind_groups: RwLock::new(
rank::RENDER_BUNDLE_SCOPE_BIND_GROUPS,
StatelessTracker::new(),
),
render_pipelines: RwLock::new(
rank::RENDER_BUNDLE_SCOPE_RENDER_PIPELINES,
StatelessTracker::new(),
),
buffers: BufferUsageScope::default(),
textures: TextureUsageScope::default(),
bind_groups: StatelessTracker::new(),
render_pipelines: StatelessTracker::new(),
}
}
@ -495,12 +483,8 @@ impl<A: HalApi> RenderBundleScope<A> {
&mut self,
bind_group: &BindGroupStates<A>,
) -> Result<(), ResourceUsageCompatibilityError> {
unsafe { self.buffers.write().merge_bind_group(&bind_group.buffers)? };
unsafe {
self.textures
.write()
.merge_bind_group(&bind_group.textures)?
};
unsafe { self.buffers.merge_bind_group(&bind_group.buffers)? };
unsafe { self.textures.merge_bind_group(&bind_group.textures)? };
Ok(())
}
@ -586,10 +570,8 @@ impl<'a, A: HalApi> UsageScope<'a, A> {
&mut self,
render_bundle: &RenderBundleScope<A>,
) -> Result<(), ResourceUsageCompatibilityError> {
self.buffers
.merge_usage_scope(&*render_bundle.buffers.read())?;
self.textures
.merge_usage_scope(&*render_bundle.textures.read())?;
self.buffers.merge_usage_scope(&render_bundle.buffers)?;
self.textures.merge_usage_scope(&render_bundle.textures)?;
Ok(())
}