mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
take resource lookup out of BufferUsageScope.merge_single
This commit is contained in:
parent
f5072261c7
commit
aaec1c37b9
@ -526,12 +526,19 @@ impl RenderBundleEncoder {
|
||||
size,
|
||||
} => {
|
||||
let scope = PassErrorScope::SetIndexBuffer(buffer_id);
|
||||
let buffer = state
|
||||
|
||||
let buffer = buffer_guard
|
||||
.get(buffer_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
state
|
||||
.trackers
|
||||
.buffers
|
||||
.write()
|
||||
.merge_single(&*buffer_guard, buffer_id, hal::BufferUses::INDEX)
|
||||
.merge_single(buffer, hal::BufferUses::INDEX)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
self.check_valid_to_use(buffer.device.info.id())
|
||||
.map_pass_err(scope)?;
|
||||
buffer.check_usage(wgt::BufferUsages::INDEX).map_pass_err(scope)?;
|
||||
@ -564,12 +571,17 @@ impl RenderBundleEncoder {
|
||||
.map_pass_err(scope);
|
||||
}
|
||||
|
||||
let buffer = state
|
||||
.trackers
|
||||
.buffers
|
||||
.write()
|
||||
.merge_single(&*buffer_guard, buffer_id, hal::BufferUses::VERTEX)
|
||||
let buffer = buffer_guard
|
||||
.get(buffer_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
state
|
||||
.trackers
|
||||
.buffers.write()
|
||||
.merge_single(buffer, hal::BufferUses::VERTEX)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
self.check_valid_to_use(buffer.device.info.id())
|
||||
.map_pass_err(scope)?;
|
||||
buffer.check_usage(wgt::BufferUsages::VERTEX).map_pass_err(scope)?;
|
||||
@ -690,12 +702,17 @@ impl RenderBundleEncoder {
|
||||
let pipeline = state.pipeline(scope)?;
|
||||
let used_bind_groups = pipeline.used_bind_groups;
|
||||
|
||||
let buffer = state
|
||||
.trackers
|
||||
.buffers
|
||||
.write()
|
||||
.merge_single(&*buffer_guard, buffer_id, hal::BufferUses::INDIRECT)
|
||||
let buffer = buffer_guard
|
||||
.get(buffer_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
state
|
||||
.trackers
|
||||
.buffers.write()
|
||||
.merge_single(buffer, hal::BufferUses::INDIRECT)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
self.check_valid_to_use(buffer.device.info.id())
|
||||
.map_pass_err(scope)?;
|
||||
buffer.check_usage(wgt::BufferUsages::INDIRECT).map_pass_err(scope)?;
|
||||
@ -728,12 +745,17 @@ impl RenderBundleEncoder {
|
||||
let pipeline = state.pipeline(scope)?;
|
||||
let used_bind_groups = pipeline.used_bind_groups;
|
||||
|
||||
let buffer = state
|
||||
.trackers
|
||||
.buffers
|
||||
.write()
|
||||
.merge_single(&*buffer_guard, buffer_id, hal::BufferUses::INDIRECT)
|
||||
let buffer = buffer_guard
|
||||
.get(buffer_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
state
|
||||
.trackers
|
||||
.buffers.write()
|
||||
.merge_single(buffer, hal::BufferUses::INDIRECT)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
self.check_valid_to_use(buffer.device.info.id())
|
||||
.map_pass_err(scope)?;
|
||||
buffer.check_usage(wgt::BufferUsages::INDIRECT).map_pass_err(scope)?;
|
||||
|
@ -70,6 +70,8 @@ pub enum DrawError {
|
||||
#[derive(Clone, Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum RenderCommandError {
|
||||
#[error("BufferId {0:?} is invalid")]
|
||||
InvalidBufferId(id::BufferId),
|
||||
#[error("BindGroupId {0:?} is invalid")]
|
||||
InvalidBindGroupId(id::BindGroupId),
|
||||
#[error("Render bundle {0:?} is invalid")]
|
||||
@ -119,12 +121,6 @@ impl crate::error::PrettyError for RenderCommandError {
|
||||
Self::InvalidPipeline(id) => {
|
||||
fmt.render_pipeline_label(&id);
|
||||
}
|
||||
Self::UsageConflict(UsageConflict::TextureInvalid { id }) => {
|
||||
fmt.texture_label(&id);
|
||||
}
|
||||
Self::UsageConflict(UsageConflict::BufferInvalid { id }) => {
|
||||
fmt.buffer_label(&id);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
|
@ -1662,10 +1662,15 @@ impl Global {
|
||||
api_log!("RenderPass::set_index_buffer {buffer_id:?}");
|
||||
|
||||
let scope = PassErrorScope::SetIndexBuffer(buffer_id);
|
||||
let buffer = info
|
||||
.usage_scope
|
||||
|
||||
let buffer = buffer_guard
|
||||
.get(buffer_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
info.usage_scope
|
||||
.buffers
|
||||
.merge_single(&*buffer_guard, buffer_id, hal::BufferUses::INDEX)
|
||||
.merge_single(buffer, hal::BufferUses::INDEX)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
buffer
|
||||
@ -1712,10 +1717,15 @@ impl Global {
|
||||
api_log!("RenderPass::set_vertex_buffer {slot} {buffer_id:?}");
|
||||
|
||||
let scope = PassErrorScope::SetVertexBuffer(buffer_id);
|
||||
let buffer = info
|
||||
.usage_scope
|
||||
|
||||
let buffer = buffer_guard
|
||||
.get(buffer_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
info.usage_scope
|
||||
.buffers
|
||||
.merge_single(&*buffer_guard, buffer_id, hal::BufferUses::VERTEX)
|
||||
.merge_single(buffer, hal::BufferUses::VERTEX)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
buffer
|
||||
@ -2020,11 +2030,16 @@ impl Global {
|
||||
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
let indirect_buffer = info
|
||||
.usage_scope
|
||||
.buffers
|
||||
.merge_single(&*buffer_guard, buffer_id, hal::BufferUses::INDIRECT)
|
||||
let indirect_buffer = buffer_guard
|
||||
.get(buffer_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
info.usage_scope
|
||||
.buffers
|
||||
.merge_single(indirect_buffer, hal::BufferUses::INDIRECT)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
indirect_buffer
|
||||
.check_usage(BufferUsages::INDIRECT)
|
||||
.map_pass_err(scope)?;
|
||||
@ -2090,26 +2105,32 @@ impl Global {
|
||||
.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
let indirect_buffer = info
|
||||
.usage_scope
|
||||
.buffers
|
||||
.merge_single(&*buffer_guard, buffer_id, hal::BufferUses::INDIRECT)
|
||||
let indirect_buffer = buffer_guard
|
||||
.get(buffer_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
info.usage_scope
|
||||
.buffers
|
||||
.merge_single(indirect_buffer, hal::BufferUses::INDIRECT)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
indirect_buffer
|
||||
.check_usage(BufferUsages::INDIRECT)
|
||||
.map_pass_err(scope)?;
|
||||
let indirect_raw =
|
||||
indirect_buffer.try_raw(&snatch_guard).map_pass_err(scope)?;
|
||||
|
||||
let count_buffer = info
|
||||
.usage_scope
|
||||
.buffers
|
||||
.merge_single(
|
||||
&*buffer_guard,
|
||||
count_buffer_id,
|
||||
hal::BufferUses::INDIRECT,
|
||||
)
|
||||
let count_buffer = buffer_guard
|
||||
.get(count_buffer_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBufferId(count_buffer_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
info.usage_scope
|
||||
.buffers
|
||||
.merge_single(count_buffer, hal::BufferUses::INDIRECT)
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
count_buffer
|
||||
.check_usage(BufferUsages::INDIRECT)
|
||||
.map_pass_err(scope)?;
|
||||
|
@ -835,8 +835,8 @@ impl<A: HalApi> LifetimeTracker<A> {
|
||||
for buffer in self.mapped.drain(..) {
|
||||
let submit_index = buffer.info.submission_index();
|
||||
log::trace!(
|
||||
"Mapping of {:?} at submission {:?} gets assigned to active {:?}",
|
||||
buffer.info.id(),
|
||||
"Mapping of {} at submission {:?} gets assigned to active {:?}",
|
||||
buffer.error_ident(),
|
||||
submit_index,
|
||||
self.active.iter().position(|a| a.index == submit_index)
|
||||
);
|
||||
|
@ -10,12 +10,10 @@ use std::{borrow::Cow, marker::PhantomData, sync::Arc};
|
||||
use super::{PendingTransition, ResourceTracker, TrackerIndex};
|
||||
use crate::{
|
||||
hal_api::HalApi,
|
||||
id::BufferId,
|
||||
lock::{rank, Mutex},
|
||||
resource::{Buffer, Resource},
|
||||
resource_log,
|
||||
snatch::SnatchGuard,
|
||||
storage::Storage,
|
||||
track::{
|
||||
invalid_resource_state, skip_barrier, ResourceMetadata, ResourceMetadataProvider,
|
||||
ResourceUses, UsageConflict,
|
||||
@ -227,18 +225,12 @@ impl<A: HalApi> BufferUsageScope<A> {
|
||||
///
|
||||
/// If the ID is higher than the length of internal vectors,
|
||||
/// the vectors will be extended. A call to set_size is not needed.
|
||||
pub fn merge_single<'a>(
|
||||
pub fn merge_single(
|
||||
&mut self,
|
||||
storage: &'a Storage<Buffer<A>>,
|
||||
id: BufferId,
|
||||
buffer: &Arc<Buffer<A>>,
|
||||
new_state: BufferUses,
|
||||
) -> Result<&'a Arc<Buffer<A>>, UsageConflict> {
|
||||
let buffer = storage
|
||||
.get(id)
|
||||
.map_err(|_| UsageConflict::BufferInvalid { id })?;
|
||||
|
||||
) -> Result<(), UsageConflict> {
|
||||
self.insert_merge_single(buffer.clone(), new_state)
|
||||
.map(|_| buffer)
|
||||
}
|
||||
|
||||
/// Merge a single state into the UsageScope, using an already resolved buffer.
|
||||
|
@ -340,10 +340,6 @@ fn skip_barrier<T: ResourceUses>(old_state: T, new_state: T) -> bool {
|
||||
|
||||
#[derive(Clone, Debug, Error, Eq, PartialEq)]
|
||||
pub enum UsageConflict {
|
||||
#[error("Attempted to use invalid buffer")]
|
||||
BufferInvalid { id: id::BufferId },
|
||||
#[error("Attempted to use invalid texture")]
|
||||
TextureInvalid { id: id::TextureId },
|
||||
#[error("Attempted to use buffer with {invalid_use}.")]
|
||||
Buffer {
|
||||
id: id::BufferId,
|
||||
@ -395,12 +391,6 @@ impl crate::error::PrettyError for UsageConflict {
|
||||
fn fmt_pretty(&self, fmt: &mut crate::error::ErrorFormatter) {
|
||||
fmt.error(self);
|
||||
match *self {
|
||||
Self::BufferInvalid { id } => {
|
||||
fmt.buffer_label(&id);
|
||||
}
|
||||
Self::TextureInvalid { id } => {
|
||||
fmt.texture_label(&id);
|
||||
}
|
||||
Self::Buffer { id, .. } => {
|
||||
fmt.buffer_label(&id);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user