mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
refactor the StatelessTracker
to hold a Vec
of Arc
s
Also removes the `StatelessBindGroupState` since it does the same thing.
This commit is contained in:
parent
a3142ade91
commit
5cb1be63aa
@ -380,16 +380,6 @@ impl RenderBundleEncoder {
|
||||
.textures
|
||||
.write()
|
||||
.set_size(indices.textures.size());
|
||||
state
|
||||
.trackers
|
||||
.bind_groups
|
||||
.write()
|
||||
.set_size(indices.bind_groups.size());
|
||||
state
|
||||
.trackers
|
||||
.render_pipelines
|
||||
.write()
|
||||
.set_size(indices.render_pipelines.size());
|
||||
|
||||
let base = &self.base;
|
||||
|
||||
|
@ -484,15 +484,6 @@ impl Global {
|
||||
let indices = &state.device.tracker_indices;
|
||||
state.tracker.buffers.set_size(indices.buffers.size());
|
||||
state.tracker.textures.set_size(indices.textures.size());
|
||||
state
|
||||
.tracker
|
||||
.bind_groups
|
||||
.set_size(indices.bind_groups.size());
|
||||
state
|
||||
.tracker
|
||||
.compute_pipelines
|
||||
.set_size(indices.compute_pipelines.size());
|
||||
state.tracker.query_sets.set_size(indices.query_sets.size());
|
||||
|
||||
let timestamp_writes = if let Some(tw) = timestamp_writes.take() {
|
||||
tw.query_set
|
||||
|
@ -1620,13 +1620,6 @@ impl Global {
|
||||
let indices = &device.tracker_indices;
|
||||
tracker.buffers.set_size(indices.buffers.size());
|
||||
tracker.textures.set_size(indices.textures.size());
|
||||
tracker.views.set_size(indices.texture_views.size());
|
||||
tracker.bind_groups.set_size(indices.bind_groups.size());
|
||||
tracker
|
||||
.render_pipelines
|
||||
.set_size(indices.render_pipelines.size());
|
||||
tracker.bundles.set_size(indices.bundles.size());
|
||||
tracker.query_sets.set_size(indices.query_sets.size());
|
||||
|
||||
let raw = &mut encoder.raw;
|
||||
|
||||
|
@ -2005,7 +2005,7 @@ impl<A: HalApi> Device<A> {
|
||||
) -> Result<&'a A::Sampler, binding_model::CreateBindGroupError> {
|
||||
use crate::binding_model::CreateBindGroupError as Error;
|
||||
|
||||
used.samplers.add_single(sampler);
|
||||
used.samplers.insert_single(sampler.clone());
|
||||
|
||||
sampler.same_device(self)?;
|
||||
|
||||
@ -2054,7 +2054,7 @@ impl<A: HalApi> Device<A> {
|
||||
used_texture_ranges: &mut Vec<TextureInitTrackerAction<A>>,
|
||||
snatch_guard: &'a SnatchGuard<'a>,
|
||||
) -> Result<hal::TextureBinding<'a, A>, binding_model::CreateBindGroupError> {
|
||||
used.views.add_single(view);
|
||||
used.views.insert_single(view.clone());
|
||||
|
||||
view.same_device(self)?;
|
||||
|
||||
|
@ -117,7 +117,7 @@ pub(crate) use buffer::{
|
||||
BufferBindGroupState, BufferTracker, BufferUsageScope, DeviceBufferTracker,
|
||||
};
|
||||
use metadata::{ResourceMetadata, ResourceMetadataProvider};
|
||||
pub(crate) use stateless::{StatelessBindGroupState, StatelessTracker};
|
||||
pub(crate) use stateless::StatelessTracker;
|
||||
pub(crate) use texture::{
|
||||
DeviceTextureTracker, TextureBindGroupState, TextureSelector, TextureTracker,
|
||||
TextureTrackerSetSingle, TextureUsageScope,
|
||||
@ -423,8 +423,8 @@ impl<T: ResourceUses> fmt::Display for InvalidUse<T> {
|
||||
pub(crate) struct BindGroupStates<A: HalApi> {
|
||||
pub buffers: BufferBindGroupState<A>,
|
||||
pub textures: TextureBindGroupState<A>,
|
||||
pub views: StatelessBindGroupState<resource::TextureView<A>>,
|
||||
pub samplers: StatelessBindGroupState<resource::Sampler<A>>,
|
||||
pub views: StatelessTracker<resource::TextureView<A>>,
|
||||
pub samplers: StatelessTracker<resource::Sampler<A>>,
|
||||
}
|
||||
|
||||
impl<A: HalApi> BindGroupStates<A> {
|
||||
@ -432,8 +432,8 @@ impl<A: HalApi> BindGroupStates<A> {
|
||||
Self {
|
||||
buffers: BufferBindGroupState::new(),
|
||||
textures: TextureBindGroupState::new(),
|
||||
views: StatelessBindGroupState::new(),
|
||||
samplers: StatelessBindGroupState::new(),
|
||||
views: StatelessTracker::new(),
|
||||
samplers: StatelessTracker::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,79 +1,26 @@
|
||||
//! Stateless Trackers
|
||||
//!
|
||||
//! Stateless trackers don't have any state, so make no
|
||||
//! distinction between a usage scope and a full tracker.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{resource::Trackable, track::ResourceMetadata};
|
||||
|
||||
/// Stores all the resources that a bind group stores.
|
||||
/// A tracker that holds strong references to resources.
|
||||
///
|
||||
/// This is only used to keep resources alive.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct StatelessBindGroupState<T: Trackable> {
|
||||
pub(crate) struct StatelessTracker<T> {
|
||||
resources: Vec<Arc<T>>,
|
||||
}
|
||||
|
||||
impl<T: Trackable> StatelessBindGroupState<T> {
|
||||
impl<T> StatelessTracker<T> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
resources: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds the given resource.
|
||||
pub fn add_single(&mut self, resource: &Arc<T>) {
|
||||
self.resources.push(resource.clone());
|
||||
}
|
||||
}
|
||||
|
||||
/// Stores all resource state within a command buffer or device.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct StatelessTracker<T: Trackable> {
|
||||
metadata: ResourceMetadata<Arc<T>>,
|
||||
}
|
||||
|
||||
impl<T: Trackable> StatelessTracker<T> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
metadata: ResourceMetadata::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn tracker_assert_in_bounds(&self, index: usize) {
|
||||
self.metadata.tracker_assert_in_bounds(index);
|
||||
}
|
||||
|
||||
/// Sets the size of all the vectors inside the tracker.
|
||||
///
|
||||
/// Must be called with the highest possible Resource ID of this type
|
||||
/// before all unsafe functions are called.
|
||||
pub fn set_size(&mut self, size: usize) {
|
||||
self.metadata.set_size(size);
|
||||
}
|
||||
|
||||
/// Extend the vectors to let the given index be valid.
|
||||
fn allow_index(&mut self, index: usize) {
|
||||
if index >= self.metadata.size() {
|
||||
self.set_size(index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// Inserts a single resource into the resource tracker.
|
||||
///
|
||||
/// If the resource already exists in the tracker, it will be overwritten.
|
||||
///
|
||||
/// If the ID is higher than the length of internal vectors,
|
||||
/// the vectors will be extended. A call to set_size is not needed.
|
||||
///
|
||||
/// Returns a reference to the newly inserted resource.
|
||||
/// (This allows avoiding a clone/reference count increase in many cases.)
|
||||
pub fn insert_single(&mut self, resource: Arc<T>) -> &Arc<T> {
|
||||
let index = resource.tracker_index().as_usize();
|
||||
|
||||
self.allow_index(index);
|
||||
|
||||
self.tracker_assert_in_bounds(index);
|
||||
|
||||
unsafe { self.metadata.insert(index, resource) }
|
||||
self.resources.push(resource);
|
||||
unsafe { self.resources.last().unwrap_unchecked() }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user