Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Bottom level categories:
- Support the `wasm64-unknown-unknown` target for the web backend. Building for wasm64 requires a nightly toolchain with `-Z build-std=std,panic_abort`. By @nickbabcock in [#9836](https://github.com/gfx-rs/wgpu/pull/9836).
- Many types now offer `pub const fn default()` in addition to implementing the `Default` trait, allowing constants to make use of default values. By @kpreid in [#9929](https://github.com/gfx-rs/wgpu/pull/9929).
- `wgpu-core` now exposes `validate_device_descriptor` and `validate_texture_descriptor` functions that perform the same descriptor validation the corresponding resource creation APIs would, without actually creating a resource. This may be useful in conjunction with hal raw APIs. By @andyleiserson in [#9967](https://github.com/gfx-rs/wgpu/pull/9967) and [#9979](https://github.com/gfx-rs/wgpu/pull/9979).
- Added `TextureDescriptor::theoretical_memory_footprint` to estimate memory footprint of a texture. By @sagudev in [#10032](https://github.com/gfx-rs/wgpu/pull/10032).

#### Hal

Expand Down
15 changes: 15 additions & 0 deletions wgpu-types/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,21 @@ impl<L, V> TextureDescriptor<L, V> {
TextureDimension::D2 => self.size.depth_or_array_layers,
}
}

/// Returns the theoretical memory footprint of a texture.
///
/// Actual memory usage may greatly exceed this value due to alignment and padding.
#[must_use]
pub fn theoretical_memory_footprint(&self) -> u64 {
(0..self.mip_level_count).fold(0, |acc, level| {
acc.saturating_add(
self.format.theoretical_memory_footprint(
self.mip_level_size(level)
.expect("mipmap level should be inbounds"),
),
)
})
}
}

/// Describes a `Sampler`.
Expand Down