Add TextureView::texture (#7907)

This commit is contained in:
Connor Fitzgerald 2025-07-09 19:53:55 -04:00 committed by GitHub
parent 13fec87fb2
commit a851eba5f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 4 deletions

View File

@ -51,6 +51,13 @@ Previously, if you wanted to get access to the wgpu-hal or underlying api types,
### New Features
#### New method `TextureView::texture`
You can now call `texture_view.texture()` to get access to the texture that
a given texture view points to.
By @cwfitzgerald in [#7907](https://github.com/gfx-rs/wgpu/pull/7907).
#### Naga
- Added `no_std` support with default features disabled. By @Bushrat011899 in [#7585](https://github.com/gfx-rs/wgpu/pull/7585).

View File

@ -169,8 +169,9 @@ async fn draw_test_with_reports(
assert_eq!(report.buffers.num_allocated, 1);
assert_eq!(report.texture_views.num_allocated, 1);
assert_eq!(report.texture_views.num_kept_from_user, 1);
assert_eq!(report.textures.num_allocated, 0);
assert_eq!(report.textures.num_kept_from_user, 0);
// TextureViews in `wgpu` have a reference to the texture.
assert_eq!(report.textures.num_allocated, 1);
assert_eq!(report.textures.num_kept_from_user, 1);
let mut encoder = ctx
.device
@ -208,7 +209,7 @@ async fn draw_test_with_reports(
assert_eq!(report.command_buffers.num_allocated, 1);
assert_eq!(report.render_bundles.num_allocated, 0);
assert_eq!(report.texture_views.num_allocated, 1);
assert_eq!(report.textures.num_allocated, 0);
assert_eq!(report.textures.num_allocated, 1);
function(&mut rpass);

View File

@ -70,7 +70,10 @@ impl Texture {
pub fn create_view(&self, desc: &TextureViewDescriptor<'_>) -> TextureView {
let view = self.inner.create_view(desc);
TextureView { inner: view }
TextureView {
inner: view,
texture: self.clone(),
}
}
/// Destroy the associated native resources as soon as possible.

View File

@ -15,6 +15,7 @@ use crate::*;
#[derive(Debug, Clone)]
pub struct TextureView {
pub(crate) inner: dispatch::DispatchTextureView,
pub(crate) texture: Texture,
}
#[cfg(send_sync)]
static_assertions::assert_impl_all!(TextureView: Send, Sync);
@ -22,6 +23,14 @@ static_assertions::assert_impl_all!(TextureView: Send, Sync);
crate::cmp::impl_eq_ord_hash_proxy!(TextureView => .inner);
impl TextureView {
/// Returns the [`Texture`] that this `TextureView` refers to.
///
/// All wgpu resources are refcounted, so you can own the returned [`Texture`]
/// by cloning it.
pub fn texture(&self) -> &Texture {
&self.texture
}
/// Get the [`wgpu_hal`] texture view from this `TextureView`.
///
/// Find the Api struct corresponding to the active backend in [`wgpu_hal::api`],