Skip to content

Commit ca3d76b

Browse files
committed
Add TextureView::texture
1 parent 4f15635 commit ca3d76b

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ Previously, if you wanted to get access to the wgpu-hal or underlying api types,
5151

5252
### New Features
5353

54+
#### New method `TextureView::texture`
55+
56+
You can now call `texture_view.texture()` to get access to the texture that
57+
a given texture view points to.
58+
59+
By @cwfitzgerald in [#7907](https://github.com/gfx-rs/wgpu/pull/7907).
60+
5461
#### Naga
5562

5663
- 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: 4 additions & 3 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
@@ -208,7 +209,7 @@ async fn draw_test_with_reports(
208209
assert_eq!(report.command_buffers.num_allocated, 1);
209210
assert_eq!(report.render_bundles.num_allocated, 0);
210211
assert_eq!(report.texture_views.num_allocated, 1);
211-
assert_eq!(report.textures.num_allocated, 0);
212+
assert_eq!(report.textures.num_allocated, 1);
212213

213214
function(&mut rpass);
214215

wgpu/src/api/texture.rs

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

73-
TextureView { inner: view }
73+
TextureView {
74+
inner: view,
75+
texture: self.clone(),
76+
}
7477
}
7578

7679
/// 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
@@ -15,13 +15,22 @@ use crate::*;
1515
#[derive(Debug, Clone)]
1616
pub struct TextureView {
1717
pub(crate) inner: dispatch::DispatchTextureView,
18+
pub(crate) texture: Texture,
1819
}
1920
#[cfg(send_sync)]
2021
static_assertions::assert_impl_all!(TextureView: Send, Sync);
2122

2223
crate::cmp::impl_eq_ord_hash_proxy!(TextureView => .inner);
2324

2425
impl TextureView {
26+
/// Returns the [`Texture`] that this `TextureView` refers to.
27+
///
28+
/// All wgpu resources are refcounted, so you can own the returned [`Texture`]
29+
/// by cloning it.
30+
pub fn texture(&self) -> &Texture {
31+
&self.texture
32+
}
33+
2534
/// Get the [`wgpu_hal`] texture view from this `TextureView`.
2635
///
2736
/// Find the Api struct corresponding to the active backend in [`wgpu_hal::api`],

0 commit comments

Comments
 (0)