mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 16:24:24 +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,
|
||||
id::{BindGroupLayoutId, BufferId, SamplerId, TextureViewId},
|
||||
init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction},
|
||||
resource::{MissingBufferUsageError, ParentDevice, Resource, ResourceInfo, ResourceType},
|
||||
resource::{
|
||||
MissingBufferUsageError, MissingTextureUsageError, ParentDevice, Resource, ResourceInfo,
|
||||
ResourceType,
|
||||
},
|
||||
resource_log,
|
||||
snatch::{SnatchGuard, Snatchable},
|
||||
track::{BindGroupStates, UsageConflict},
|
||||
validation::MissingTextureUsageError,
|
||||
Label,
|
||||
};
|
||||
|
||||
|
@ -7,9 +7,8 @@ use crate::{
|
||||
hal_api::HalApi,
|
||||
id,
|
||||
pipeline::RenderPipeline,
|
||||
resource::{Buffer, MissingBufferUsageError, QuerySet},
|
||||
resource::{Buffer, MissingBufferUsageError, MissingTextureUsageError, QuerySet},
|
||||
track::UsageConflict,
|
||||
validation::MissingTextureUsageError,
|
||||
};
|
||||
use wgt::{BufferAddress, BufferSize, Color, VertexStepMode};
|
||||
|
||||
|
@ -26,12 +26,11 @@ use crate::{
|
||||
init_tracker::{MemoryInitKind, TextureInitRange, TextureInitTrackerAction},
|
||||
pipeline::{self, PipelineFlags},
|
||||
resource::{
|
||||
MissingBufferUsageError, ParentDevice, QuerySet, Texture, TextureView,
|
||||
TextureViewNotRenderableReason,
|
||||
MissingBufferUsageError, MissingTextureUsageError, ParentDevice, QuerySet, Texture,
|
||||
TextureView, TextureViewNotRenderableReason,
|
||||
},
|
||||
storage::Storage,
|
||||
track::{TextureSelector, Tracker, UsageConflict, UsageScope},
|
||||
validation::{check_texture_usage, MissingTextureUsageError},
|
||||
Label,
|
||||
};
|
||||
|
||||
@ -1248,7 +1247,7 @@ impl<'a, 'd, A: HalApi> RenderPassInfo<'a, 'd, A> {
|
||||
|
||||
for ra in self.render_attachments {
|
||||
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
|
||||
unsafe {
|
||||
|
@ -34,7 +34,7 @@ use crate::{
|
||||
BindGroupStates, TextureSelector, Tracker, TrackerIndexAllocators, UsageScope,
|
||||
UsageScopePool,
|
||||
},
|
||||
validation::{self, check_texture_usage, validate_color_attachment_bytes_per_sample},
|
||||
validation::{self, validate_color_attachment_bytes_per_sample},
|
||||
FastHashMap, LabelHelpers as _, SubmissionIndex,
|
||||
};
|
||||
|
||||
@ -2059,7 +2059,7 @@ impl<A: HalApi> Device<A> {
|
||||
|
||||
texture.same_device_as(view)?;
|
||||
|
||||
check_texture_usage(texture.desc.usage, pub_usage)?;
|
||||
texture.check_usage(pub_usage)?;
|
||||
|
||||
used_texture_ranges.push(TextureInitTrackerAction {
|
||||
texture: texture.clone(),
|
||||
|
@ -431,6 +431,14 @@ pub struct MissingBufferUsageError {
|
||||
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>;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -967,6 +975,25 @@ pub struct Texture<A: HalApi> {
|
||||
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> {
|
||||
fn drop(&mut self) {
|
||||
resource_log!("Destroy raw Texture {:?}", self.info.label());
|
||||
|
@ -133,26 +133,6 @@ pub struct Interface {
|
||||
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)]
|
||||
#[non_exhaustive]
|
||||
pub enum BindingError {
|
||||
|
Loading…
Reference in New Issue
Block a user