Skip to content

Add TextureView::texture #7907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 4 additions & 3 deletions tests/tests/wgpu-gpu/mem_leaks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion wgpu/src/api/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions wgpu/src/api/texture_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ 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);

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`],
Expand Down