mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
[wgpu-core] use Fallible
for Texture
This commit is contained in:
parent
68e8b7d4a8
commit
c630821f1d
@ -54,21 +54,12 @@ static BAD_TEXTURE: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(
|
||||
Some("dimension x is zero"),
|
||||
);
|
||||
|
||||
let error = match ctx.adapter_info.backend.to_str() {
|
||||
"vulkan" | "vk" => "textureid id(0,1,vk) is invalid",
|
||||
"dx12" | "d3d12" => "textureid id(0,1,d3d12) is invalid",
|
||||
"metal" | "mtl" => "textureid id(0,1,mtl) is invalid",
|
||||
"opengl" | "gles" | "gl" => "textureid id(0,1,gl) is invalid",
|
||||
"webgpu" => "textureid id(0,1,webgpu) is invalid",
|
||||
b => b,
|
||||
};
|
||||
|
||||
fail(
|
||||
&ctx.device,
|
||||
|| {
|
||||
let _ = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
},
|
||||
Some(error),
|
||||
Some("Texture with '' label is invalid"),
|
||||
);
|
||||
valid(&ctx.device, || texture.destroy());
|
||||
valid(&ctx.device, || texture.destroy());
|
||||
|
@ -27,8 +27,6 @@ use wgt::{math::align_to, BufferAddress, BufferUsages, ImageSubresourceRange, Te
|
||||
pub enum ClearError {
|
||||
#[error("To use clear_texture the CLEAR_TEXTURE feature needs to be enabled")]
|
||||
MissingClearTextureFeature,
|
||||
#[error("TextureId {0:?} is invalid")]
|
||||
InvalidTextureId(TextureId),
|
||||
#[error(transparent)]
|
||||
DestroyedResource(#[from] DestroyedResourceError),
|
||||
#[error("{0} can not be cleared")]
|
||||
@ -203,10 +201,7 @@ impl Global {
|
||||
return Err(ClearError::MissingClearTextureFeature);
|
||||
}
|
||||
|
||||
let dst_texture = hub
|
||||
.textures
|
||||
.get(dst)
|
||||
.map_err(|_| ClearError::InvalidTextureId(dst))?;
|
||||
let dst_texture = hub.textures.strict_get(dst).get()?;
|
||||
|
||||
dst_texture.same_device_as(cmd_buf.as_ref())?;
|
||||
|
||||
|
@ -41,8 +41,6 @@ pub enum CopySide {
|
||||
#[derive(Clone, Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum TransferError {
|
||||
#[error("TextureId {0:?} is invalid")]
|
||||
InvalidTextureId(TextureId),
|
||||
#[error("Source and destination cannot be the same buffer")]
|
||||
SameSourceDestinationBuffer,
|
||||
#[error(transparent)]
|
||||
@ -740,10 +738,7 @@ impl Global {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let dst_texture = hub
|
||||
.textures
|
||||
.get(destination.texture)
|
||||
.map_err(|_| TransferError::InvalidTextureId(destination.texture))?;
|
||||
let dst_texture = hub.textures.strict_get(destination.texture).get()?;
|
||||
|
||||
dst_texture.same_device_as(cmd_buf.as_ref())?;
|
||||
|
||||
@ -904,10 +899,7 @@ impl Global {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let src_texture = hub
|
||||
.textures
|
||||
.get(source.texture)
|
||||
.map_err(|_| TransferError::InvalidTextureId(source.texture))?;
|
||||
let src_texture = hub.textures.strict_get(source.texture).get()?;
|
||||
|
||||
src_texture.same_device_as(cmd_buf.as_ref())?;
|
||||
|
||||
@ -1082,14 +1074,8 @@ impl Global {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let src_texture = hub
|
||||
.textures
|
||||
.get(source.texture)
|
||||
.map_err(|_| TransferError::InvalidTextureId(source.texture))?;
|
||||
let dst_texture = hub
|
||||
.textures
|
||||
.get(destination.texture)
|
||||
.map_err(|_| TransferError::InvalidTextureId(source.texture))?;
|
||||
let src_texture = hub.textures.strict_get(source.texture).get()?;
|
||||
let dst_texture = hub.textures.strict_get(destination.texture).get()?;
|
||||
|
||||
src_texture.same_device_as(cmd_buf.as_ref())?;
|
||||
dst_texture.same_device_as(cmd_buf.as_ref())?;
|
||||
|
@ -196,11 +196,14 @@ impl Global {
|
||||
/// Assign `id_in` an error with the given `label`.
|
||||
///
|
||||
/// See `create_buffer_error` for more context and explanation.
|
||||
pub fn create_texture_error(&self, backend: wgt::Backend, id_in: Option<id::TextureId>) {
|
||||
let hub = &self.hub;
|
||||
let fid = hub.textures.prepare(backend, id_in);
|
||||
|
||||
fid.assign_error();
|
||||
pub fn create_texture_error(
|
||||
&self,
|
||||
backend: wgt::Backend,
|
||||
id_in: Option<id::TextureId>,
|
||||
desc: &resource::TextureDescriptor,
|
||||
) {
|
||||
let fid = self.hub.textures.prepare(backend, id_in);
|
||||
fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string())));
|
||||
}
|
||||
|
||||
#[cfg(feature = "replay")]
|
||||
@ -323,7 +326,7 @@ impl Global {
|
||||
Err(error) => break 'error error,
|
||||
};
|
||||
|
||||
let id = fid.assign(texture);
|
||||
let id = fid.assign(Fallible::Valid(texture));
|
||||
api_log!("Device::create_texture({desc:?}) -> {id:?}");
|
||||
|
||||
return (id, None);
|
||||
@ -331,7 +334,7 @@ impl Global {
|
||||
|
||||
log::error!("Device::create_texture error: {error}");
|
||||
|
||||
let id = fid.assign_error();
|
||||
let id = fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string())));
|
||||
(id, Some(error))
|
||||
}
|
||||
|
||||
@ -368,7 +371,7 @@ impl Global {
|
||||
Err(error) => break 'error error,
|
||||
};
|
||||
|
||||
let id = fid.assign(texture);
|
||||
let id = fid.assign(Fallible::Valid(texture));
|
||||
api_log!("Device::create_texture({desc:?}) -> {id:?}");
|
||||
|
||||
return (id, None);
|
||||
@ -376,7 +379,7 @@ impl Global {
|
||||
|
||||
log::error!("Device::create_texture error: {error}");
|
||||
|
||||
let id = fid.assign_error();
|
||||
let id = fid.assign(Fallible::Invalid(Arc::new(desc.label.to_string())));
|
||||
(id, Some(error))
|
||||
}
|
||||
|
||||
@ -420,10 +423,7 @@ impl Global {
|
||||
|
||||
let hub = &self.hub;
|
||||
|
||||
let texture = hub
|
||||
.textures
|
||||
.get(texture_id)
|
||||
.map_err(|_| resource::DestroyError::InvalidTextureId(texture_id))?;
|
||||
let texture = hub.textures.strict_get(texture_id).get()?;
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
if let Some(trace) = texture.device.trace.lock().as_mut() {
|
||||
@ -439,9 +439,10 @@ impl Global {
|
||||
|
||||
let hub = &self.hub;
|
||||
|
||||
if let Some(_texture) = hub.textures.unregister(texture_id) {
|
||||
#[cfg(feature = "trace")]
|
||||
if let Some(t) = _texture.device.trace.lock().as_mut() {
|
||||
let _texture = hub.textures.strict_unregister(texture_id);
|
||||
#[cfg(feature = "trace")]
|
||||
if let Ok(texture) = _texture.get() {
|
||||
if let Some(t) = texture.device.trace.lock().as_mut() {
|
||||
t.add(trace::Action::DestroyTexture(texture_id));
|
||||
}
|
||||
}
|
||||
@ -460,11 +461,9 @@ impl Global {
|
||||
let fid = hub.texture_views.prepare(texture_id.backend(), id_in);
|
||||
|
||||
let error = 'error: {
|
||||
let texture = match hub.textures.get(texture_id) {
|
||||
let texture = match hub.textures.strict_get(texture_id).get() {
|
||||
Ok(texture) => texture,
|
||||
Err(_) => {
|
||||
break 'error resource::CreateTextureViewError::InvalidTextureId(texture_id)
|
||||
}
|
||||
Err(e) => break 'error e.into(),
|
||||
};
|
||||
let device = &texture.device;
|
||||
|
||||
|
@ -619,10 +619,7 @@ impl Global {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let dst = hub
|
||||
.textures
|
||||
.get(destination.texture)
|
||||
.map_err(|_| TransferError::InvalidTextureId(destination.texture))?;
|
||||
let dst = hub.textures.strict_get(destination.texture).get()?;
|
||||
|
||||
dst.same_device_as(queue.as_ref())?;
|
||||
|
||||
@ -713,12 +710,6 @@ impl Global {
|
||||
|
||||
let snatch_guard = device.snatchable_lock.read();
|
||||
|
||||
// Re-get `dst` immutably here, so that the mutable borrow of the
|
||||
// `texture_guard.get` above ends in time for the `clear_texture`
|
||||
// call above. Since we've held `texture_guard` the whole time, we know
|
||||
// the texture hasn't gone away in the mean time, so we can unwrap.
|
||||
let dst = hub.textures.get(destination.texture).unwrap();
|
||||
|
||||
let dst_raw = dst.try_raw(&snatch_guard)?;
|
||||
|
||||
let (block_width, block_height) = dst.desc.format.block_dimensions();
|
||||
@ -865,7 +856,7 @@ impl Global {
|
||||
let src_width = source.source.width();
|
||||
let src_height = source.source.height();
|
||||
|
||||
let dst = hub.textures.get(destination.texture).unwrap();
|
||||
let dst = hub.textures.strict_get(destination.texture).get()?;
|
||||
|
||||
if !conv::is_valid_external_image_copy_dst_texture_format(dst.desc.format) {
|
||||
return Err(
|
||||
|
@ -177,7 +177,7 @@ pub struct Hub {
|
||||
pub(crate) query_sets: Registry<Arc<QuerySet>>,
|
||||
pub(crate) buffers: Registry<Fallible<Buffer>>,
|
||||
pub(crate) staging_buffers: Registry<Arc<StagingBuffer>>,
|
||||
pub(crate) textures: Registry<Arc<Texture>>,
|
||||
pub(crate) textures: Registry<Fallible<Texture>>,
|
||||
pub(crate) texture_views: Registry<Arc<TextureView>>,
|
||||
pub(crate) samplers: Registry<Arc<Sampler>>,
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ impl Global {
|
||||
.textures
|
||||
.insert_single(&texture, hal::TextureUses::UNINITIALIZED);
|
||||
|
||||
let id = fid.assign(texture);
|
||||
let id = fid.assign(resource::Fallible::Valid(texture));
|
||||
|
||||
if present.acquired_texture.is_some() {
|
||||
return Err(SurfaceError::AlreadyAcquired);
|
||||
@ -280,8 +280,8 @@ impl Global {
|
||||
|
||||
// The texture ID got added to the device tracker by `submit()`,
|
||||
// and now we are moving it away.
|
||||
let texture = hub.textures.unregister(texture_id);
|
||||
if let Some(texture) = texture {
|
||||
let texture = hub.textures.strict_unregister(texture_id).get();
|
||||
if let Ok(texture) = texture {
|
||||
device
|
||||
.trackers
|
||||
.lock()
|
||||
@ -350,9 +350,9 @@ impl Global {
|
||||
|
||||
// The texture ID got added to the device tracker by `submit()`,
|
||||
// and now we are moving it away.
|
||||
let texture = hub.textures.unregister(texture_id);
|
||||
let texture = hub.textures.strict_unregister(texture_id).get();
|
||||
|
||||
if let Some(texture) = texture {
|
||||
if let Ok(texture) = texture {
|
||||
device
|
||||
.trackers
|
||||
.lock()
|
||||
|
@ -1266,7 +1266,7 @@ impl Global {
|
||||
|
||||
let hub = &self.hub;
|
||||
|
||||
if let Ok(texture) = hub.textures.get(id) {
|
||||
if let Ok(texture) = hub.textures.strict_get(id).get() {
|
||||
let snatch_guard = texture.device.snatchable_lock.read();
|
||||
let hal_texture = texture.raw(&snatch_guard);
|
||||
let hal_texture = hal_texture
|
||||
@ -1646,8 +1646,6 @@ impl TextureView {
|
||||
pub enum CreateTextureViewError {
|
||||
#[error(transparent)]
|
||||
Device(#[from] DeviceError),
|
||||
#[error("TextureId {0:?} is invalid")]
|
||||
InvalidTextureId(TextureId),
|
||||
#[error(transparent)]
|
||||
DestroyedResource(#[from] DestroyedResourceError),
|
||||
#[error("Not enough memory left to create texture view")]
|
||||
@ -1690,6 +1688,8 @@ pub enum CreateTextureViewError {
|
||||
texture: wgt::TextureFormat,
|
||||
view: wgt::TextureFormat,
|
||||
},
|
||||
#[error(transparent)]
|
||||
InvalidResource(#[from] InvalidResourceError),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Error)]
|
||||
@ -1862,8 +1862,6 @@ impl QuerySet {
|
||||
#[derive(Clone, Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum DestroyError {
|
||||
#[error("TextureId {0:?} is invalid")]
|
||||
InvalidTextureId(TextureId),
|
||||
#[error("Resource is already destroyed")]
|
||||
AlreadyDestroyed,
|
||||
#[error(transparent)]
|
||||
|
Loading…
Reference in New Issue
Block a user