diff --git a/deno_webgpu/surface.rs b/deno_webgpu/surface.rs index b48dbd2c8..ca5e795aa 100644 --- a/deno_webgpu/surface.rs +++ b/deno_webgpu/surface.rs @@ -87,7 +87,6 @@ pub fn op_webgpu_surface_get_current_texture( let rid = state.resource_table.add(crate::texture::WebGpuTexture { instance: instance.clone(), id, - owned: false, }); Ok(WebGpuResult::rid(rid)) } diff --git a/deno_webgpu/texture.rs b/deno_webgpu/texture.rs index a432c7b62..0f78d0774 100644 --- a/deno_webgpu/texture.rs +++ b/deno_webgpu/texture.rs @@ -13,7 +13,6 @@ use super::error::WebGpuResult; pub(crate) struct WebGpuTexture { pub(crate) instance: crate::Instance, pub(crate) id: wgpu_core::id::TextureId, - pub(crate) owned: bool, } impl Resource for WebGpuTexture { @@ -22,10 +21,8 @@ impl Resource for WebGpuTexture { } fn close(self: Rc) { - if self.owned { - let instance = &self.instance; - instance.texture_drop(self.id); - } + let instance = &self.instance; + instance.texture_drop(self.id); } } @@ -85,7 +82,6 @@ pub fn op_webgpu_create_texture( let rid = state.resource_table.add(WebGpuTexture { instance: instance.clone(), id: val, - owned: true, }); Ok(WebGpuResult::rid_err(rid, maybe_err)) diff --git a/wgpu-core/src/present.rs b/wgpu-core/src/present.rs index 6f242cd3c..d03a72bae 100644 --- a/wgpu-core/src/present.rs +++ b/wgpu-core/src/present.rs @@ -17,8 +17,7 @@ use crate::{ conv, device::{Device, DeviceError, MissingDownlevelFlags, WaitIdleError}, global::Global, - hal_label, id, - resource::{self, Trackable}, + hal_label, id, resource, }; use thiserror::Error; @@ -30,7 +29,7 @@ const FRAME_TIMEOUT_MS: u32 = 1000; pub(crate) struct Presentation { pub(crate) device: Arc, pub(crate) config: wgt::SurfaceConfiguration>, - pub(crate) acquired_texture: Option, + pub(crate) acquired_texture: Option>, } #[derive(Clone, Debug, Error)] @@ -212,12 +211,12 @@ impl Global { .textures .insert_single(&texture, hal::TextureUses::UNINITIALIZED); - let id = fid.assign(resource::Fallible::Valid(texture)); - if present.acquired_texture.is_some() { return Err(SurfaceError::AlreadyAcquired); } - present.acquired_texture = Some(id); + present.acquired_texture = Some(texture.clone()); + + let id = fid.assign(resource::Fallible::Valid(texture)); let status = if ast.suboptimal { Status::Suboptimal @@ -249,8 +248,6 @@ impl Global { pub fn surface_present(&self, surface_id: id::SurfaceId) -> Result { profiling::scope!("SwapChain::present"); - let hub = &self.hub; - let surface = self.surfaces.get(surface_id); let mut presentation = surface.presentation.lock(); @@ -269,35 +266,21 @@ impl Global { device.check_is_valid()?; let queue = device.get_queue().unwrap(); - let result = { - let texture_id = present - .acquired_texture - .take() - .ok_or(SurfaceError::AlreadyAcquired)?; + let texture = present + .acquired_texture + .take() + .ok_or(SurfaceError::AlreadyAcquired)?; - // The texture ID got added to the device tracker by `submit()`, - // and now we are moving it away. - let texture = hub.textures.remove(texture_id).get(); - if let Ok(texture) = texture { - device - .trackers - .lock() - .textures - .remove(texture.tracker_index()); - let suf = surface.raw(device.backend()).unwrap(); - match texture - .inner - .snatch(&mut device.snatchable_lock.write()) - .unwrap() - { - resource::TextureInner::Surface { raw } => unsafe { - queue.raw().present(suf, raw) - }, - _ => unreachable!(), - } - } else { - Err(hal::SurfaceError::Outdated) //TODO? - } + let result = match texture + .inner + .snatch(&mut device.snatchable_lock.write()) + .unwrap() + { + resource::TextureInner::Surface { raw } => unsafe { + let raw_surface = surface.raw(device.backend()).unwrap(); + queue.raw().present(raw_surface, raw) + }, + _ => unreachable!(), }; match result { @@ -319,8 +302,6 @@ impl Global { pub fn surface_texture_discard(&self, surface_id: id::SurfaceId) -> Result<(), SurfaceError> { profiling::scope!("SwapChain::discard"); - let hub = &self.hub; - let surface = self.surfaces.get(surface_id); let mut presentation = surface.presentation.lock(); let present = match presentation.as_mut() { @@ -337,34 +318,21 @@ impl Global { device.check_is_valid()?; + let texture = present + .acquired_texture + .take() + .ok_or(SurfaceError::AlreadyAcquired)?; + + match texture + .inner + .snatch(&mut device.snatchable_lock.write()) + .unwrap() { - let texture_id = present - .acquired_texture - .take() - .ok_or(SurfaceError::AlreadyAcquired)?; - - // The texture ID got added to the device tracker by `submit()`, - // and now we are moving it away. - let texture = hub.textures.remove(texture_id).get(); - - if let Ok(texture) = texture { - device - .trackers - .lock() - .textures - .remove(texture.tracker_index()); - let suf = surface.raw(device.backend()); - match texture - .inner - .snatch(&mut device.snatchable_lock.write()) - .unwrap() - { - resource::TextureInner::Surface { raw } => { - unsafe { suf.unwrap().discard_texture(raw) }; - } - _ => unreachable!(), - } + resource::TextureInner::Surface { raw } => { + let raw_surface = surface.raw(device.backend()).unwrap(); + unsafe { raw_surface.discard_texture(raw) }; } + _ => unreachable!(), } Ok(()) diff --git a/wgpu-core/src/track/metadata.rs b/wgpu-core/src/track/metadata.rs index 22576207a..7ecb2773e 100644 --- a/wgpu-core/src/track/metadata.rs +++ b/wgpu-core/src/track/metadata.rs @@ -27,11 +27,6 @@ impl ResourceMetadata { } } - /// Returns the number of indices we can accommodate. - pub(super) fn size(&self) -> usize { - self.owned.len() - } - pub(super) fn set_size(&mut self, size: usize) { self.resources.resize(size, None); resize_bitvec(&mut self.owned, size); diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index 60c223896..f3b4c7617 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -18,7 +18,7 @@ //! is known to be in some undefined state. Any transition away from UNINITIALIZED //! will treat the contents as junk. -use super::{range::RangedStates, PendingTransition, PendingTransitionList, TrackerIndex}; +use super::{range::RangedStates, PendingTransition, PendingTransitionList}; use crate::{ resource::{Texture, TextureInner, TextureView, Trackable}, snatch::SnatchGuard, @@ -826,32 +826,6 @@ impl DeviceTextureTracker { pending.into_hal(tex) }) } - - /// Unconditionally removes the given resource from the tracker. - /// - /// Returns true if the resource was removed. - /// - /// If the index is higher than the length of internal vectors, - /// false will be returned. - pub fn remove(&mut self, index: TrackerIndex) -> bool { - let index = index.as_usize(); - - if index >= self.metadata.size() { - return false; - } - - self.tracker_assert_in_bounds(index); - - unsafe { - if self.metadata.contains_unchecked(index) { - self.current_state_set.complex.remove(&index); - self.metadata.remove(index); - return true; - } - } - - false - } } impl TextureTrackerSetSingle for DeviceTextureTracker { diff --git a/wgpu/src/api/device.rs b/wgpu/src/api/device.rs index 8c565ef52..5da9f6c80 100644 --- a/wgpu/src/api/device.rs +++ b/wgpu/src/api/device.rs @@ -252,7 +252,6 @@ impl Device { Texture { context: Arc::clone(&self.context), data, - owned: true, descriptor: TextureDescriptor { label: None, view_formats: &[], @@ -291,7 +290,6 @@ impl Device { Texture { context: Arc::clone(&self.context), data: Box::new(texture), - owned: true, descriptor: TextureDescriptor { label: None, view_formats: &[], diff --git a/wgpu/src/api/surface.rs b/wgpu/src/api/surface.rs index ecb0d9693..6e433596d 100644 --- a/wgpu/src/api/surface.rs +++ b/wgpu/src/api/surface.rs @@ -142,7 +142,6 @@ impl Surface<'_> { texture: Texture { context: Arc::clone(&self.context), data, - owned: false, descriptor, }, suboptimal, diff --git a/wgpu/src/api/texture.rs b/wgpu/src/api/texture.rs index 5d01ecdea..6e94e20a3 100644 --- a/wgpu/src/api/texture.rs +++ b/wgpu/src/api/texture.rs @@ -12,7 +12,6 @@ use crate::*; pub struct Texture { pub(crate) context: Arc, pub(crate) data: Box, - pub(crate) owned: bool, pub(crate) descriptor: TextureDescriptor<'static>, } #[cfg(send_sync)] @@ -138,7 +137,7 @@ impl Texture { impl Drop for Texture { fn drop(&mut self) { - if self.owned && !thread::panicking() { + if !thread::panicking() { self.context.texture_drop(self.data.as_ref()); } }