mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 00:11:11 +01:00
fix(hal/vulkan): count textures created by create_texture (#10022)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Erich Gubler <erichdongubler@gmail.com>
This commit is contained in:
5 files changed
+68
-3
No files matched your search
@@ -182,6 +182,7 @@ By @sagudev in [#10109](https://github.com/gfx-rs/wgpu/pull/10109).
|
||||
|
||||
#### Vulkan
|
||||
|
||||
- Fix `HalCounters::textures` drifting negative: `create_texture` never incremented it while `destroy_texture` always decremented it. By @dustyleary in [#10022](https://github.com/gfx-rs/wgpu/pull/10022).
|
||||
- Add OpenHarmony surface support via `VK_OHOS_surface`. Previously the Vulkan backend could not create a surface on OpenHarmony, leaving GLES as the only usable backend. By @ozongzi in [#9908](https://github.com/gfx-rs/wgpu/pull/9908).
|
||||
|
||||
#### Metal
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ test-build-with-profiling = ["profiling/type-check"]
|
||||
[dependencies]
|
||||
# Passthrough backend uses as_hal for the GLES backend, and there's not a great way to cfg-gate that.
|
||||
# These are all enabled for any testing on CI anyway, and won't do anything if no devices are detected.
|
||||
wgpu = { workspace = true, features = ["noop", "gles", "webgl", "angle"] }
|
||||
wgpu = { workspace = true, features = ["noop", "gles", "webgl", "angle", "counters"] }
|
||||
wgpu-core = { workspace = true, default-features = true, features = ["trace"] }
|
||||
wgpu-hal = { workspace = true, default-features = true, features = ["validation_canary"] }
|
||||
wgpu-sync.workspace = true
|
||||
|
||||
@@ -11,6 +11,8 @@ mod regression {
|
||||
pub mod issue_6467;
|
||||
pub mod issue_6827;
|
||||
pub mod issue_9115;
|
||||
|
||||
pub mod issue_10038;
|
||||
}
|
||||
|
||||
mod adapter;
|
||||
@@ -146,6 +148,7 @@ fn all_tests() -> Vec<wgpu_test::GpuTestInitializer> {
|
||||
regression::issue_6467::all_tests(&mut tests);
|
||||
regression::issue_6827::all_tests(&mut tests);
|
||||
regression::issue_9115::all_tests(&mut tests);
|
||||
regression::issue_10038::all_tests(&mut tests);
|
||||
render_pass_ownership::all_tests(&mut tests);
|
||||
render_target::all_tests(&mut tests);
|
||||
resource_descriptor_accessor::all_tests(&mut tests);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
use wgpu_test::{
|
||||
apply, gpu_test, FailureCase, GpuTestConfiguration, GpuTestInitializer, TestParameters,
|
||||
};
|
||||
|
||||
pub fn all_tests(vec: &mut Vec<GpuTestInitializer>) {
|
||||
vec.push(TEXTURE_COUNTERS_BALANCED);
|
||||
}
|
||||
|
||||
#[apply(gpu_test!)]
|
||||
static TEXTURE_COUNTERS_BALANCED: GpuTestConfiguration = GpuTestConfiguration::new()
|
||||
.parameters(
|
||||
TestParameters::default()
|
||||
// NOTE: The WebGPU backend does not implement internal counters.
|
||||
.skip(FailureCase::backend(wgpu::Backends::BROWSER_WEBGPU)),
|
||||
)
|
||||
.run_async(|ctx| async move {
|
||||
let before = ctx.device.get_internal_counters().hal;
|
||||
|
||||
let texture = ctx.device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: Some("internal counters test"),
|
||||
size: wgpu::Extent3d {
|
||||
width: 256,
|
||||
height: 256,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Rgba8Unorm,
|
||||
usage: wgpu::TextureUsages::TEXTURE_BINDING,
|
||||
view_formats: &[],
|
||||
});
|
||||
|
||||
let alive = ctx.device.get_internal_counters().hal;
|
||||
assert_eq!(
|
||||
alive.textures.read(),
|
||||
before.textures.read() + 1,
|
||||
"internal texture counter should increment with new texture",
|
||||
);
|
||||
|
||||
drop(texture);
|
||||
ctx.async_poll(wgpu::PollType::wait_indefinitely())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let after = ctx.device.get_internal_counters().hal;
|
||||
assert_eq!(
|
||||
after.textures.read(),
|
||||
before.textures.read(),
|
||||
"internal texture counter should return to baseline once texture is destroyed",
|
||||
);
|
||||
assert_eq!(
|
||||
after.texture_memory.read(),
|
||||
before.texture_memory.read(),
|
||||
concat!(
|
||||
"internal texture memory counter should return to its baseline ",
|
||||
"once the texture is destroyed"
|
||||
),
|
||||
);
|
||||
});
|
||||
@@ -1217,8 +1217,6 @@ impl crate::Device for super::Device {
|
||||
unsafe { self.shared.raw.destroy_image(image.raw, None) };
|
||||
})?;
|
||||
|
||||
self.counters.texture_memory.add(allocation.size() as isize);
|
||||
|
||||
unsafe {
|
||||
self.shared
|
||||
.raw
|
||||
@@ -1229,6 +1227,9 @@ impl crate::Device for super::Device {
|
||||
unsafe { self.shared.raw.destroy_image(image.raw, None) };
|
||||
})?;
|
||||
|
||||
self.counters.texture_memory.add(allocation.size() as isize);
|
||||
self.counters.textures.add(1);
|
||||
|
||||
Ok(unsafe {
|
||||
self.texture_from_raw(
|
||||
image.raw,
|
||||
|
||||
Reference in new issue
Block a user