mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 16:24:24 +00:00
change BindGroup.raw
to BindGroup.try_raw
This commit is contained in:
parent
08f5eb82cd
commit
b0d2517bf4
@ -894,17 +894,24 @@ impl<A: HalApi> Drop for BindGroup<A> {
|
||||
}
|
||||
|
||||
impl<A: HalApi> BindGroup<A> {
|
||||
pub(crate) fn raw(&self, guard: &SnatchGuard) -> Option<&A::BindGroup> {
|
||||
pub(crate) fn try_raw<'a>(
|
||||
&'a self,
|
||||
guard: &'a SnatchGuard,
|
||||
) -> Result<&A::BindGroup, DestroyedResourceError> {
|
||||
// Clippy insist on writing it this way. The idea is to return None
|
||||
// if any of the raw buffer is not valid anymore.
|
||||
for buffer in &self.used_buffer_ranges {
|
||||
let _ = buffer.buffer.raw(guard)?;
|
||||
buffer.buffer.try_raw(guard)?;
|
||||
}
|
||||
for texture in &self.used_texture_ranges {
|
||||
let _ = texture.texture.raw(guard)?;
|
||||
texture.texture.try_raw(guard)?;
|
||||
}
|
||||
self.raw.get(guard)
|
||||
|
||||
self.raw
|
||||
.get(guard)
|
||||
.ok_or_else(|| DestroyedResourceError(self.error_ident()))
|
||||
}
|
||||
|
||||
pub(crate) fn validate_dynamic_bindings(
|
||||
&self,
|
||||
bind_group_index: u32,
|
||||
|
@ -412,7 +412,7 @@ impl RenderBundleEncoder {
|
||||
|
||||
let bind_group = bind_group_guard
|
||||
.get(bind_group_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBindGroup(bind_group_id))
|
||||
.map_err(|_| RenderCommandError::InvalidBindGroupId(bind_group_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
state
|
||||
@ -837,17 +837,12 @@ pub enum CreateRenderBundleError {
|
||||
pub enum ExecutionError {
|
||||
#[error(transparent)]
|
||||
DestroyedResource(#[from] DestroyedResourceError),
|
||||
#[error("BindGroup {0:?} is invalid")]
|
||||
InvalidBindGroup(id::BindGroupId),
|
||||
#[error("Using {0} in a render bundle is not implemented")]
|
||||
Unimplemented(&'static str),
|
||||
}
|
||||
impl PrettyError for ExecutionError {
|
||||
fn fmt_pretty(&self, fmt: &mut ErrorFormatter) {
|
||||
fmt.error(self);
|
||||
if let Self::InvalidBindGroup(id) = *self {
|
||||
fmt.bind_group_label(&id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -919,9 +914,7 @@ impl<A: HalApi> RenderBundle<A> {
|
||||
num_dynamic_offsets,
|
||||
bind_group,
|
||||
} => {
|
||||
let raw_bg = bind_group
|
||||
.raw(snatch_guard)
|
||||
.ok_or(ExecutionError::InvalidBindGroup(bind_group.info.id()))?;
|
||||
let raw_bg = bind_group.try_raw(snatch_guard)?;
|
||||
unsafe {
|
||||
raw.set_bind_group(
|
||||
pipeline_layout.as_ref().unwrap().raw(),
|
||||
|
@ -158,8 +158,8 @@ pub enum ComputePassErrorInner {
|
||||
Encoder(#[from] CommandEncoderError),
|
||||
#[error("Parent encoder is invalid")]
|
||||
InvalidParentEncoder,
|
||||
#[error("Bind group at index {0:?} is invalid")]
|
||||
InvalidBindGroup(u32),
|
||||
#[error("BindGroupId {0:?} is invalid")]
|
||||
InvalidBindGroupId(id::BindGroupId),
|
||||
#[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")]
|
||||
BindGroupIndexOutOfRange { index: u32, max: u32 },
|
||||
#[error("Compute pipeline {0:?} is invalid")]
|
||||
@ -615,10 +615,7 @@ impl Global {
|
||||
let pipeline_layout = pipeline_layout.as_ref().unwrap().raw();
|
||||
for (i, e) in entries.iter().enumerate() {
|
||||
if let Some(group) = e.group.as_ref() {
|
||||
let raw_bg = group
|
||||
.raw(&snatch_guard)
|
||||
.ok_or(ComputePassErrorInner::InvalidBindGroup(i as u32))
|
||||
.map_pass_err(scope)?;
|
||||
let raw_bg = group.try_raw(&snatch_guard).map_pass_err(scope)?;
|
||||
unsafe {
|
||||
raw.set_bind_group(
|
||||
pipeline_layout,
|
||||
@ -661,10 +658,8 @@ impl Global {
|
||||
if !entries.is_empty() {
|
||||
for (i, e) in entries.iter().enumerate() {
|
||||
if let Some(group) = e.group.as_ref() {
|
||||
let raw_bg = group
|
||||
.raw(&snatch_guard)
|
||||
.ok_or(ComputePassErrorInner::InvalidBindGroup(i as u32))
|
||||
.map_pass_err(scope)?;
|
||||
let raw_bg =
|
||||
group.try_raw(&snatch_guard).map_pass_err(scope)?;
|
||||
unsafe {
|
||||
raw.set_bind_group(
|
||||
pipeline.layout.raw(),
|
||||
@ -972,7 +967,7 @@ impl Global {
|
||||
.bind_groups
|
||||
.read()
|
||||
.get_owned(bind_group_id)
|
||||
.map_err(|_| ComputePassErrorInner::InvalidBindGroup(index))
|
||||
.map_err(|_| ComputePassErrorInner::InvalidBindGroupId(bind_group_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
base.commands.push(ArcComputeCommand::SetBindGroup {
|
||||
|
@ -98,7 +98,7 @@ impl ComputeCommand {
|
||||
bind_group: bind_group_guard.get_owned(bind_group_id).map_err(|_| {
|
||||
ComputePassError {
|
||||
scope: PassErrorScope::SetBindGroup(bind_group_id),
|
||||
inner: ComputePassErrorInner::InvalidBindGroup(index),
|
||||
inner: ComputePassErrorInner::InvalidBindGroupId(bind_group_id),
|
||||
}
|
||||
})?,
|
||||
},
|
||||
|
@ -70,8 +70,8 @@ pub enum DrawError {
|
||||
#[derive(Clone, Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum RenderCommandError {
|
||||
#[error("Bind group {0:?} is invalid")]
|
||||
InvalidBindGroup(id::BindGroupId),
|
||||
#[error("BindGroupId {0:?} is invalid")]
|
||||
InvalidBindGroupId(id::BindGroupId),
|
||||
#[error("Render bundle {0:?} is invalid")]
|
||||
InvalidRenderBundle(id::RenderBundleId),
|
||||
#[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")]
|
||||
@ -113,7 +113,7 @@ impl crate::error::PrettyError for RenderCommandError {
|
||||
fn fmt_pretty(&self, fmt: &mut ErrorFormatter) {
|
||||
fmt.error(self);
|
||||
match *self {
|
||||
Self::InvalidBindGroup(id) => {
|
||||
Self::InvalidBindGroupId(id) => {
|
||||
fmt.bind_group_label(&id);
|
||||
}
|
||||
Self::InvalidPipeline(id) => {
|
||||
|
@ -601,8 +601,6 @@ pub enum RenderPassErrorInner {
|
||||
SurfaceTextureDropped,
|
||||
#[error("Not enough memory left for render pass")]
|
||||
OutOfMemory,
|
||||
#[error("The bind group at index {0:?} is invalid")]
|
||||
InvalidBindGroup(usize),
|
||||
#[error("Unable to clear non-present/read-only depth")]
|
||||
InvalidDepthOps,
|
||||
#[error("Unable to clear non-present/read-only stencil")]
|
||||
@ -1471,7 +1469,7 @@ impl Global {
|
||||
|
||||
let bind_group = bind_group_guard
|
||||
.get(bind_group_id)
|
||||
.map_err(|_| RenderCommandError::InvalidBindGroup(bind_group_id))
|
||||
.map_err(|_| RenderCommandError::InvalidBindGroupId(bind_group_id))
|
||||
.map_pass_err(scope)?;
|
||||
|
||||
tracker.bind_groups.add_single(bind_group);
|
||||
@ -1516,10 +1514,8 @@ impl Global {
|
||||
let pipeline_layout = pipeline_layout.as_ref().unwrap().raw();
|
||||
for (i, e) in entries.iter().enumerate() {
|
||||
if let Some(group) = e.group.as_ref() {
|
||||
let raw_bg = group
|
||||
.raw(&snatch_guard)
|
||||
.ok_or(RenderPassErrorInner::InvalidBindGroup(i))
|
||||
.map_pass_err(scope)?;
|
||||
let raw_bg =
|
||||
group.try_raw(&snatch_guard).map_pass_err(scope)?;
|
||||
unsafe {
|
||||
raw.set_bind_group(
|
||||
pipeline_layout,
|
||||
@ -1598,10 +1594,8 @@ impl Global {
|
||||
if !entries.is_empty() {
|
||||
for (i, e) in entries.iter().enumerate() {
|
||||
if let Some(group) = e.group.as_ref() {
|
||||
let raw_bg = group
|
||||
.raw(&snatch_guard)
|
||||
.ok_or(RenderPassErrorInner::InvalidBindGroup(i))
|
||||
.map_pass_err(scope)?;
|
||||
let raw_bg =
|
||||
group.try_raw(&snatch_guard).map_pass_err(scope)?;
|
||||
unsafe {
|
||||
raw.set_bind_group(
|
||||
pipeline.layout.raw(),
|
||||
@ -2366,9 +2360,6 @@ impl Global {
|
||||
ExecutionError::DestroyedResource(e) => {
|
||||
RenderCommandError::DestroyedResource(e)
|
||||
}
|
||||
ExecutionError::InvalidBindGroup(id) => {
|
||||
RenderCommandError::InvalidBindGroup(id)
|
||||
}
|
||||
ExecutionError::Unimplemented(what) => {
|
||||
RenderCommandError::Unimplemented(what)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user