mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 14:55:05 +00:00
make check_texture_usage
a texture method
This commit is contained in:
parent
87382d7133
commit
862f19524f
@ -8,11 +8,13 @@ use crate::{
|
|||||||
hal_api::HalApi,
|
hal_api::HalApi,
|
||||||
id::{BindGroupLayoutId, BufferId, SamplerId, TextureViewId},
|
id::{BindGroupLayoutId, BufferId, SamplerId, TextureViewId},
|
||||||
init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction},
|
init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction},
|
||||||
resource::{MissingBufferUsageError, ParentDevice, Resource, ResourceInfo, ResourceType},
|
resource::{
|
||||||
|
MissingBufferUsageError, MissingTextureUsageError, ParentDevice, Resource, ResourceInfo,
|
||||||
|
ResourceType,
|
||||||
|
},
|
||||||
resource_log,
|
resource_log,
|
||||||
snatch::{SnatchGuard, Snatchable},
|
snatch::{SnatchGuard, Snatchable},
|
||||||
track::{BindGroupStates, UsageConflict},
|
track::{BindGroupStates, UsageConflict},
|
||||||
validation::MissingTextureUsageError,
|
|
||||||
Label,
|
Label,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,9 +7,8 @@ use crate::{
|
|||||||
hal_api::HalApi,
|
hal_api::HalApi,
|
||||||
id,
|
id,
|
||||||
pipeline::RenderPipeline,
|
pipeline::RenderPipeline,
|
||||||
resource::{Buffer, MissingBufferUsageError, QuerySet},
|
resource::{Buffer, MissingBufferUsageError, MissingTextureUsageError, QuerySet},
|
||||||
track::UsageConflict,
|
track::UsageConflict,
|
||||||
validation::MissingTextureUsageError,
|
|
||||||
};
|
};
|
||||||
use wgt::{BufferAddress, BufferSize, Color, VertexStepMode};
|
use wgt::{BufferAddress, BufferSize, Color, VertexStepMode};
|
||||||
|
|
||||||
|
@ -26,12 +26,11 @@ use crate::{
|
|||||||
init_tracker::{MemoryInitKind, TextureInitRange, TextureInitTrackerAction},
|
init_tracker::{MemoryInitKind, TextureInitRange, TextureInitTrackerAction},
|
||||||
pipeline::{self, PipelineFlags},
|
pipeline::{self, PipelineFlags},
|
||||||
resource::{
|
resource::{
|
||||||
MissingBufferUsageError, ParentDevice, QuerySet, Texture, TextureView,
|
MissingBufferUsageError, MissingTextureUsageError, ParentDevice, QuerySet, Texture,
|
||||||
TextureViewNotRenderableReason,
|
TextureView, TextureViewNotRenderableReason,
|
||||||
},
|
},
|
||||||
storage::Storage,
|
storage::Storage,
|
||||||
track::{TextureSelector, Tracker, UsageConflict, UsageScope},
|
track::{TextureSelector, Tracker, UsageConflict, UsageScope},
|
||||||
validation::{check_texture_usage, MissingTextureUsageError},
|
|
||||||
Label,
|
Label,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1248,7 +1247,7 @@ impl<'a, 'd, A: HalApi> RenderPassInfo<'a, 'd, A> {
|
|||||||
|
|
||||||
for ra in self.render_attachments {
|
for ra in self.render_attachments {
|
||||||
let texture = &ra.texture;
|
let texture = &ra.texture;
|
||||||
check_texture_usage(texture.desc.usage, TextureUsages::RENDER_ATTACHMENT)?;
|
texture.check_usage(TextureUsages::RENDER_ATTACHMENT)?;
|
||||||
|
|
||||||
// the tracker set of the pass is always in "extend" mode
|
// the tracker set of the pass is always in "extend" mode
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -34,7 +34,7 @@ use crate::{
|
|||||||
BindGroupStates, TextureSelector, Tracker, TrackerIndexAllocators, UsageScope,
|
BindGroupStates, TextureSelector, Tracker, TrackerIndexAllocators, UsageScope,
|
||||||
UsageScopePool,
|
UsageScopePool,
|
||||||
},
|
},
|
||||||
validation::{self, check_texture_usage, validate_color_attachment_bytes_per_sample},
|
validation::{self, validate_color_attachment_bytes_per_sample},
|
||||||
FastHashMap, LabelHelpers as _, SubmissionIndex,
|
FastHashMap, LabelHelpers as _, SubmissionIndex,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2059,7 +2059,7 @@ impl<A: HalApi> Device<A> {
|
|||||||
|
|
||||||
texture.same_device_as(view)?;
|
texture.same_device_as(view)?;
|
||||||
|
|
||||||
check_texture_usage(texture.desc.usage, pub_usage)?;
|
texture.check_usage(pub_usage)?;
|
||||||
|
|
||||||
used_texture_ranges.push(TextureInitTrackerAction {
|
used_texture_ranges.push(TextureInitTrackerAction {
|
||||||
texture: texture.clone(),
|
texture: texture.clone(),
|
||||||
|
@ -431,6 +431,14 @@ pub struct MissingBufferUsageError {
|
|||||||
pub(crate) expected: wgt::BufferUsages,
|
pub(crate) expected: wgt::BufferUsages,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Error)]
|
||||||
|
#[error("Usage flags {actual:?} of {res} do not contain required usage flags {expected:?}")]
|
||||||
|
pub struct MissingTextureUsageError {
|
||||||
|
pub(crate) res: ResourceErrorIdent,
|
||||||
|
pub(crate) actual: wgt::TextureUsages,
|
||||||
|
pub(crate) expected: wgt::TextureUsages,
|
||||||
|
}
|
||||||
|
|
||||||
pub type BufferAccessResult = Result<(), BufferAccessError>;
|
pub type BufferAccessResult = Result<(), BufferAccessError>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -967,6 +975,25 @@ pub struct Texture<A: HalApi> {
|
|||||||
pub(crate) bind_groups: Mutex<Vec<Weak<BindGroup<A>>>>,
|
pub(crate) bind_groups: Mutex<Vec<Weak<BindGroup<A>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A: HalApi> Texture<A> {
|
||||||
|
/// Checks that the given texture usage contains the required texture usage,
|
||||||
|
/// returns an error otherwise.
|
||||||
|
pub(crate) fn check_usage(
|
||||||
|
&self,
|
||||||
|
expected: wgt::TextureUsages,
|
||||||
|
) -> Result<(), MissingTextureUsageError> {
|
||||||
|
self.desc
|
||||||
|
.usage
|
||||||
|
.contains(expected)
|
||||||
|
.then_some(())
|
||||||
|
.ok_or_else(|| MissingTextureUsageError {
|
||||||
|
res: self.error_ident(),
|
||||||
|
actual: self.desc.usage,
|
||||||
|
expected,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<A: HalApi> Drop for Texture<A> {
|
impl<A: HalApi> Drop for Texture<A> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
resource_log!("Destroy raw Texture {:?}", self.info.label());
|
resource_log!("Destroy raw Texture {:?}", self.info.label());
|
||||||
|
@ -133,26 +133,6 @@ pub struct Interface {
|
|||||||
entry_points: FastHashMap<(naga::ShaderStage, String), EntryPoint>,
|
entry_points: FastHashMap<(naga::ShaderStage, String), EntryPoint>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Error)]
|
|
||||||
#[error("Texture usage is {actual:?} which does not contain required usage {expected:?}")]
|
|
||||||
pub struct MissingTextureUsageError {
|
|
||||||
pub(crate) actual: wgt::TextureUsages,
|
|
||||||
pub(crate) expected: wgt::TextureUsages,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks that the given texture usage contains the required texture usage,
|
|
||||||
/// returns an error otherwise.
|
|
||||||
pub fn check_texture_usage(
|
|
||||||
actual: wgt::TextureUsages,
|
|
||||||
expected: wgt::TextureUsages,
|
|
||||||
) -> Result<(), MissingTextureUsageError> {
|
|
||||||
if !actual.contains(expected) {
|
|
||||||
Err(MissingTextureUsageError { actual, expected })
|
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Error)]
|
#[derive(Clone, Debug, Error)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum BindingError {
|
pub enum BindingError {
|
||||||
|
Loading…
Reference in New Issue
Block a user