mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
take resource lookup out of StatelessTracker.add_single
This commit is contained in:
parent
2ec7254772
commit
7bd9195aa2
@ -410,13 +410,17 @@ impl RenderBundleEncoder {
|
|||||||
} => {
|
} => {
|
||||||
let scope = PassErrorScope::SetBindGroup(bind_group_id);
|
let scope = PassErrorScope::SetBindGroup(bind_group_id);
|
||||||
|
|
||||||
let bind_group = state
|
let bind_group = bind_group_guard
|
||||||
|
.get(bind_group_id)
|
||||||
|
.map_err(|_| RenderCommandError::InvalidBindGroup(bind_group_id))
|
||||||
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
|
state
|
||||||
.trackers
|
.trackers
|
||||||
.bind_groups
|
.bind_groups
|
||||||
.write()
|
.write()
|
||||||
.add_single(&*bind_group_guard, bind_group_id)
|
.add_single(bind_group);
|
||||||
.ok_or(RenderCommandError::InvalidBindGroup(bind_group_id))
|
|
||||||
.map_pass_err(scope)?;
|
|
||||||
self.check_valid_to_use(bind_group.device.info.id())
|
self.check_valid_to_use(bind_group.device.info.id())
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
@ -475,13 +479,17 @@ impl RenderBundleEncoder {
|
|||||||
RenderCommand::SetPipeline(pipeline_id) => {
|
RenderCommand::SetPipeline(pipeline_id) => {
|
||||||
let scope = PassErrorScope::SetPipelineRender(pipeline_id);
|
let scope = PassErrorScope::SetPipelineRender(pipeline_id);
|
||||||
|
|
||||||
let pipeline = state
|
let pipeline = pipeline_guard
|
||||||
|
.get(pipeline_id)
|
||||||
|
.map_err(|_| RenderCommandError::InvalidPipeline(pipeline_id))
|
||||||
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
|
state
|
||||||
.trackers
|
.trackers
|
||||||
.render_pipelines
|
.render_pipelines
|
||||||
.write()
|
.write()
|
||||||
.add_single(&*pipeline_guard, pipeline_id)
|
.add_single(pipeline);
|
||||||
.ok_or(RenderCommandError::InvalidPipeline(pipeline_id))
|
|
||||||
.map_pass_err(scope)?;
|
|
||||||
self.check_valid_to_use(pipeline.device.info.id())
|
self.check_valid_to_use(pipeline.device.info.id())
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
|
@ -353,10 +353,11 @@ impl Global {
|
|||||||
let raw_encoder = encoder.open()?;
|
let raw_encoder = encoder.open()?;
|
||||||
|
|
||||||
let query_set_guard = hub.query_sets.read();
|
let query_set_guard = hub.query_sets.read();
|
||||||
let query_set = tracker
|
let query_set = query_set_guard
|
||||||
.query_sets
|
.get(query_set_id)
|
||||||
.add_single(&*query_set_guard, query_set_id)
|
.map_err(|_| QueryError::InvalidQuerySet(query_set_id))?;
|
||||||
.ok_or(QueryError::InvalidQuerySet(query_set_id))?;
|
|
||||||
|
tracker.query_sets.add_single(query_set);
|
||||||
|
|
||||||
query_set.validate_and_write_timestamp(raw_encoder, query_index, None)?;
|
query_set.validate_and_write_timestamp(raw_encoder, query_index, None)?;
|
||||||
|
|
||||||
@ -397,11 +398,13 @@ impl Global {
|
|||||||
if destination_offset % wgt::QUERY_RESOLVE_BUFFER_ALIGNMENT != 0 {
|
if destination_offset % wgt::QUERY_RESOLVE_BUFFER_ALIGNMENT != 0 {
|
||||||
return Err(QueryError::Resolve(ResolveError::BufferOffsetAlignment));
|
return Err(QueryError::Resolve(ResolveError::BufferOffsetAlignment));
|
||||||
}
|
}
|
||||||
|
|
||||||
let query_set_guard = hub.query_sets.read();
|
let query_set_guard = hub.query_sets.read();
|
||||||
let query_set = tracker
|
let query_set = query_set_guard
|
||||||
.query_sets
|
.get(query_set_id)
|
||||||
.add_single(&*query_set_guard, query_set_id)
|
.map_err(|_| QueryError::InvalidQuerySet(query_set_id))?;
|
||||||
.ok_or(QueryError::InvalidQuerySet(query_set_id))?;
|
|
||||||
|
tracker.query_sets.add_single(query_set);
|
||||||
|
|
||||||
query_set.same_device_as(cmd_buf.as_ref())?;
|
query_set.same_device_as(cmd_buf.as_ref())?;
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ use crate::{
|
|||||||
api_log,
|
api_log,
|
||||||
binding_model::BindError,
|
binding_model::BindError,
|
||||||
command::{
|
command::{
|
||||||
self,
|
|
||||||
bind::Binder,
|
bind::Binder,
|
||||||
end_occlusion_query, end_pipeline_statistics_query,
|
end_occlusion_query, end_pipeline_statistics_query,
|
||||||
memory_init::{fixup_discarded_surfaces, SurfacesInDiscardState},
|
memory_init::{fixup_discarded_surfaces, SurfacesInDiscardState},
|
||||||
@ -903,10 +902,14 @@ impl<'a, 'd, A: HalApi> RenderPassInfo<'a, 'd, A> {
|
|||||||
let mut depth_stencil = None;
|
let mut depth_stencil = None;
|
||||||
|
|
||||||
if let Some(at) = depth_stencil_attachment {
|
if let Some(at) = depth_stencil_attachment {
|
||||||
let view: &TextureView<A> = trackers
|
let view = view_guard
|
||||||
.views
|
.get(at.view)
|
||||||
.add_single(view_guard, at.view)
|
.map_err(|_| RenderPassErrorInner::InvalidAttachment(at.view))?;
|
||||||
.ok_or(RenderPassErrorInner::InvalidAttachment(at.view))?;
|
|
||||||
|
trackers.views.add_single(view);
|
||||||
|
|
||||||
|
let view = view.as_ref();
|
||||||
|
|
||||||
check_multiview(view)?;
|
check_multiview(view)?;
|
||||||
add_view(view, AttachmentErrorLocation::Depth)?;
|
add_view(view, AttachmentErrorLocation::Depth)?;
|
||||||
|
|
||||||
@ -1036,10 +1039,13 @@ impl<'a, 'd, A: HalApi> RenderPassInfo<'a, 'd, A> {
|
|||||||
colors.push(None);
|
colors.push(None);
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let color_view: &TextureView<A> = trackers
|
|
||||||
.views
|
let color_view = view_guard
|
||||||
.add_single(view_guard, at.view)
|
.get(at.view)
|
||||||
.ok_or(RenderPassErrorInner::InvalidAttachment(at.view))?;
|
.map_err(|_| RenderPassErrorInner::InvalidAttachment(at.view))?;
|
||||||
|
|
||||||
|
trackers.views.add_single(color_view);
|
||||||
|
|
||||||
check_multiview(color_view)?;
|
check_multiview(color_view)?;
|
||||||
add_view(
|
add_view(
|
||||||
color_view,
|
color_view,
|
||||||
@ -1070,10 +1076,11 @@ impl<'a, 'd, A: HalApi> RenderPassInfo<'a, 'd, A> {
|
|||||||
|
|
||||||
let mut hal_resolve_target = None;
|
let mut hal_resolve_target = None;
|
||||||
if let Some(resolve_target) = at.resolve_target {
|
if let Some(resolve_target) = at.resolve_target {
|
||||||
let resolve_view: &TextureView<A> = trackers
|
let resolve_view = view_guard
|
||||||
.views
|
.get(resolve_target)
|
||||||
.add_single(view_guard, resolve_target)
|
.map_err(|_| RenderPassErrorInner::InvalidAttachment(resolve_target))?;
|
||||||
.ok_or(RenderPassErrorInner::InvalidAttachment(resolve_target))?;
|
|
||||||
|
trackers.views.add_single(resolve_view);
|
||||||
|
|
||||||
check_multiview(resolve_view)?;
|
check_multiview(resolve_view)?;
|
||||||
|
|
||||||
@ -1177,10 +1184,11 @@ impl<'a, 'd, A: HalApi> RenderPassInfo<'a, 'd, A> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let timestamp_writes = if let Some(tw) = timestamp_writes {
|
let timestamp_writes = if let Some(tw) = timestamp_writes {
|
||||||
let query_set = trackers
|
let query_set = query_set_guard
|
||||||
.query_sets
|
.get(tw.query_set)
|
||||||
.add_single(query_set_guard, tw.query_set)
|
.map_err(|_| RenderPassErrorInner::InvalidQuerySet(tw.query_set))?;
|
||||||
.ok_or(RenderPassErrorInner::InvalidQuerySet(tw.query_set))?;
|
|
||||||
|
trackers.query_sets.add_single(query_set);
|
||||||
|
|
||||||
if let Some(index) = tw.beginning_of_pass_write_index {
|
if let Some(index) = tw.beginning_of_pass_write_index {
|
||||||
pending_query_resets.use_query_set(tw.query_set, query_set, index);
|
pending_query_resets.use_query_set(tw.query_set, query_set, index);
|
||||||
@ -1199,10 +1207,11 @@ impl<'a, 'd, A: HalApi> RenderPassInfo<'a, 'd, A> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let occlusion_query_set = if let Some(occlusion_query_set) = occlusion_query_set {
|
let occlusion_query_set = if let Some(occlusion_query_set) = occlusion_query_set {
|
||||||
let query_set = trackers
|
let query_set = query_set_guard
|
||||||
.query_sets
|
.get(occlusion_query_set)
|
||||||
.add_single(query_set_guard, occlusion_query_set)
|
.map_err(|_| RenderPassErrorInner::InvalidQuerySet(occlusion_query_set))?;
|
||||||
.ok_or(RenderPassErrorInner::InvalidQuerySet(occlusion_query_set))?;
|
|
||||||
|
trackers.query_sets.add_single(query_set);
|
||||||
|
|
||||||
Some(query_set.raw.as_ref().unwrap())
|
Some(query_set.raw.as_ref().unwrap())
|
||||||
} else {
|
} else {
|
||||||
@ -1470,12 +1479,13 @@ impl Global {
|
|||||||
);
|
);
|
||||||
dynamic_offset_count += num_dynamic_offsets;
|
dynamic_offset_count += num_dynamic_offsets;
|
||||||
|
|
||||||
let bind_group = tracker
|
let bind_group = bind_group_guard
|
||||||
.bind_groups
|
.get(bind_group_id)
|
||||||
.add_single(&*bind_group_guard, bind_group_id)
|
.map_err(|_| RenderCommandError::InvalidBindGroup(bind_group_id))
|
||||||
.ok_or(RenderCommandError::InvalidBindGroup(bind_group_id))
|
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
|
tracker.bind_groups.add_single(bind_group);
|
||||||
|
|
||||||
bind_group
|
bind_group
|
||||||
.same_device_as(cmd_buf.as_ref())
|
.same_device_as(cmd_buf.as_ref())
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
@ -1538,12 +1548,13 @@ impl Global {
|
|||||||
let scope = PassErrorScope::SetPipelineRender(pipeline_id);
|
let scope = PassErrorScope::SetPipelineRender(pipeline_id);
|
||||||
state.pipeline = Some(pipeline_id);
|
state.pipeline = Some(pipeline_id);
|
||||||
|
|
||||||
let pipeline: &pipeline::RenderPipeline<A> = tracker
|
let pipeline = render_pipeline_guard
|
||||||
.render_pipelines
|
.get(pipeline_id)
|
||||||
.add_single(&*render_pipeline_guard, pipeline_id)
|
.map_err(|_| RenderCommandError::InvalidPipeline(pipeline_id))
|
||||||
.ok_or(RenderCommandError::InvalidPipeline(pipeline_id))
|
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
|
tracker.render_pipelines.add_single(pipeline);
|
||||||
|
|
||||||
pipeline
|
pipeline
|
||||||
.same_device_as(cmd_buf.as_ref())
|
.same_device_as(cmd_buf.as_ref())
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
@ -2231,12 +2242,13 @@ impl Global {
|
|||||||
.require_features(wgt::Features::TIMESTAMP_QUERY_INSIDE_PASSES)
|
.require_features(wgt::Features::TIMESTAMP_QUERY_INSIDE_PASSES)
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
let query_set = tracker
|
let query_set = query_set_guard
|
||||||
.query_sets
|
.get(query_set_id)
|
||||||
.add_single(&*query_set_guard, query_set_id)
|
.map_err(|_| RenderPassErrorInner::InvalidQuerySet(query_set_id))
|
||||||
.ok_or(RenderCommandError::InvalidQuerySet(query_set_id))
|
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
|
tracker.query_sets.add_single(query_set);
|
||||||
|
|
||||||
query_set
|
query_set
|
||||||
.validate_and_write_timestamp(
|
.validate_and_write_timestamp(
|
||||||
raw,
|
raw,
|
||||||
@ -2253,12 +2265,13 @@ impl Global {
|
|||||||
.ok_or(RenderPassErrorInner::MissingOcclusionQuerySet)
|
.ok_or(RenderPassErrorInner::MissingOcclusionQuerySet)
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
let query_set = tracker
|
let query_set = query_set_guard
|
||||||
.query_sets
|
.get(query_set_id)
|
||||||
.add_single(&*query_set_guard, query_set_id)
|
.map_err(|_| RenderPassErrorInner::InvalidQuerySet(query_set_id))
|
||||||
.ok_or(RenderCommandError::InvalidQuerySet(query_set_id))
|
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
|
tracker.query_sets.add_single(query_set);
|
||||||
|
|
||||||
validate_and_begin_occlusion_query(
|
validate_and_begin_occlusion_query(
|
||||||
query_set.clone(),
|
query_set.clone(),
|
||||||
raw,
|
raw,
|
||||||
@ -2281,12 +2294,13 @@ impl Global {
|
|||||||
api_log!("RenderPass::begin_pipeline_statistics_query {query_set_id:?} {query_index}");
|
api_log!("RenderPass::begin_pipeline_statistics_query {query_set_id:?} {query_index}");
|
||||||
let scope = PassErrorScope::BeginPipelineStatisticsQuery;
|
let scope = PassErrorScope::BeginPipelineStatisticsQuery;
|
||||||
|
|
||||||
let query_set = tracker
|
let query_set = query_set_guard
|
||||||
.query_sets
|
.get(query_set_id)
|
||||||
.add_single(&*query_set_guard, query_set_id)
|
.map_err(|_| RenderPassErrorInner::InvalidQuerySet(query_set_id))
|
||||||
.ok_or(RenderCommandError::InvalidQuerySet(query_set_id))
|
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
|
tracker.query_sets.add_single(query_set);
|
||||||
|
|
||||||
validate_and_begin_pipeline_statistics_query(
|
validate_and_begin_pipeline_statistics_query(
|
||||||
query_set.clone(),
|
query_set.clone(),
|
||||||
raw,
|
raw,
|
||||||
@ -2306,12 +2320,14 @@ impl Global {
|
|||||||
RenderCommand::ExecuteBundle(bundle_id) => {
|
RenderCommand::ExecuteBundle(bundle_id) => {
|
||||||
api_log!("RenderPass::execute_bundle {bundle_id:?}");
|
api_log!("RenderPass::execute_bundle {bundle_id:?}");
|
||||||
let scope = PassErrorScope::ExecuteBundle;
|
let scope = PassErrorScope::ExecuteBundle;
|
||||||
let bundle: &command::RenderBundle<A> = tracker
|
|
||||||
.bundles
|
let bundle = bundle_guard
|
||||||
.add_single(&*bundle_guard, bundle_id)
|
.get(bundle_id)
|
||||||
.ok_or(RenderCommandError::InvalidRenderBundle(bundle_id))
|
.map_err(|_| RenderCommandError::InvalidRenderBundle(bundle_id))
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
|
|
||||||
|
tracker.bundles.add_single(bundle);
|
||||||
|
|
||||||
bundle
|
bundle
|
||||||
.same_device_as(cmd_buf.as_ref())
|
.same_device_as(cmd_buf.as_ref())
|
||||||
.map_pass_err(scope)?;
|
.map_pass_err(scope)?;
|
||||||
|
@ -7,11 +7,9 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
id::Id,
|
|
||||||
lock::{rank, Mutex},
|
lock::{rank, Mutex},
|
||||||
resource::Resource,
|
resource::Resource,
|
||||||
resource_log,
|
resource_log,
|
||||||
storage::Storage,
|
|
||||||
track::ResourceMetadata,
|
track::ResourceMetadata,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -177,13 +175,7 @@ impl<T: Resource> StatelessTracker<T> {
|
|||||||
///
|
///
|
||||||
/// If the ID is higher than the length of internal vectors,
|
/// If the ID is higher than the length of internal vectors,
|
||||||
/// the vectors will be extended. A call to set_size is not needed.
|
/// the vectors will be extended. A call to set_size is not needed.
|
||||||
pub fn add_single<'a>(
|
pub fn add_single(&mut self, resource: &Arc<T>) {
|
||||||
&mut self,
|
|
||||||
storage: &'a Storage<T>,
|
|
||||||
id: Id<T::Marker>,
|
|
||||||
) -> Option<&'a Arc<T>> {
|
|
||||||
let resource = storage.get(id).ok()?;
|
|
||||||
|
|
||||||
let index = resource.as_info().tracker_index().as_usize();
|
let index = resource.as_info().tracker_index().as_usize();
|
||||||
|
|
||||||
self.allow_index(index);
|
self.allow_index(index);
|
||||||
@ -193,8 +185,6 @@ impl<T: Resource> StatelessTracker<T> {
|
|||||||
unsafe {
|
unsafe {
|
||||||
self.metadata.insert(index, resource.clone());
|
self.metadata.insert(index, resource.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(resource)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds the given resources from the given tracker.
|
/// Adds the given resources from the given tracker.
|
||||||
|
Loading…
Reference in New Issue
Block a user