Skip to content

Commit 4779772

Browse files
committed
Add TextureView::texture
1 parent 9834d9a commit 4779772

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ Bottom level categories:
4242

4343
### New Features
4444

45+
#### New method `TextureView::texture`
46+
47+
You can now call `texture_view.texture()` to get access to the texture that
48+
a given texture view points to.
49+
50+
By @cwfitzgerald in [#7907](https://github.com/gfx-rs/wgpu/pull/7907).
51+
4552
#### Naga
4653

4754
- Added `no_std` support with default features disabled. By @Bushrat011899 in [#7585](https://github.com/gfx-rs/wgpu/pull/7585).

tests/tests/wgpu-gpu/mem_leaks.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,9 @@ async fn draw_test_with_reports(
169169
assert_eq!(report.buffers.num_allocated, 1);
170170
assert_eq!(report.texture_views.num_allocated, 1);
171171
assert_eq!(report.texture_views.num_kept_from_user, 1);
172-
assert_eq!(report.textures.num_allocated, 0);
173-
assert_eq!(report.textures.num_kept_from_user, 0);
172+
// TextureViews in `wgpu` have a reference to the texture.
173+
assert_eq!(report.textures.num_allocated, 1);
174+
assert_eq!(report.textures.num_kept_from_user, 1);
174175

175176
let mut encoder = ctx
176177
.device

wgpu/src/api/texture.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ impl Texture {
5151
pub fn create_view(&self, desc: &TextureViewDescriptor<'_>) -> TextureView {
5252
let view = self.inner.create_view(desc);
5353

54-
TextureView { inner: view }
54+
TextureView {
55+
inner: view,
56+
texture: self.clone(),
57+
}
5558
}
5659

5760
/// Destroy the associated native resources as soon as possible.

wgpu/src/api/texture_view.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ use crate::*;
1212
#[derive(Debug, Clone)]
1313
pub struct TextureView {
1414
pub(crate) inner: dispatch::DispatchTextureView,
15+
pub(crate) texture: Texture,
1516
}
1617
#[cfg(send_sync)]
1718
static_assertions::assert_impl_all!(TextureView: Send, Sync);
1819

1920
crate::cmp::impl_eq_ord_hash_proxy!(TextureView => .inner);
2021

2122
impl TextureView {
23+
/// Returns the [`Texture`] that this `TextureView` refers to.
24+
///
25+
/// All wgpu resources are refcounted, so you can own the returned [`Texture`]
26+
/// by cloning it.
27+
pub fn texture(&self) -> &Texture {
28+
&self.texture
29+
}
30+
2231
/// Returns the inner hal `TextureView` using a callback. The hal texture will be `None` if the
2332
/// backend type argument does not match with this wgpu Texture
2433
///

0 commit comments

Comments
 (0)