Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -107,6 +107,7 @@ Bottom level categories:

#### 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).
- Stop passing an un-waited fence to `vkAcquireNextImageKHR` on non-Windows platforms, which triggered `VUID-vkAcquireNextImageKHR-fence-10066` validation errors every frame since v30.0.0. By @ErichDonGubler in [#9855](https://github.com/gfx-rs/wgpu/issues/9855).

Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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, features = ["trace"] }
wgpu-hal = { workspace = true, features = ["validation_canary"] }
wgpu-types.workspace = true
Expand Down
63 changes: 63 additions & 0 deletions tests/tests/wgpu-gpu/internal_counters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//! Tests that the hal internal counters stay balanced across resource
//! creation and destruction.

use wgpu_test::{
apply, gpu_test, FailureCase, GpuTestConfiguration, GpuTestInitializer, TestParameters,
};

pub fn all_tests(vec: &mut Vec<GpuTestInitializer>) {
vec.push(TEXTURE_COUNTERS_BALANCED);
}

/// Regression test for the Vulkan backend never incrementing
/// `HalCounters::textures` in `create_texture` while still decrementing it in
/// `destroy_texture`, which made the reported texture count drift negative.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This is a regression test, so let's move it over to regressions/ for the issue I just filed for this PR (#10038). I don't think we have appetite for a general suite of tests for counters right now, so let's not try to tackle that right this second.

#[apply(gpu_test!)]
static TEXTURE_COUNTERS_BALANCED: GpuTestConfiguration = GpuTestConfiguration::new()
.parameters(
TestParameters::default()
// The webgpu backend does not implement internal counters.
.skip(FailureCase::backend(wgpu::Backends::BROWSER_WEBGPU)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Isn't this also not implemented on the WebGL backend?

)
.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,
"hal.textures should count the live 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(),
"hal.textures should return to its baseline once the texture is destroyed",
);
assert_eq!(
after.texture_memory.read(),
before.texture_memory.read(),
"hal.texture_memory should return to its baseline once the texture is destroyed",
);
});
2 changes: 2 additions & 0 deletions tests/tests/wgpu-gpu/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod float32_filterable;
mod image_atomics;
mod immediates;
mod instance;
mod internal_counters;
mod life_cycle;
mod mem_leaks;
mod mesh_shader;
Expand Down Expand Up @@ -116,6 +117,7 @@ fn all_tests() -> Vec<wgpu_test::GpuTestInitializer> {
float32_filterable::all_tests(&mut tests);
image_atomics::all_tests(&mut tests);
instance::all_tests(&mut tests);
internal_counters::all_tests(&mut tests);
life_cycle::all_tests(&mut tests);
mem_leaks::all_tests(&mut tests);
mesh_shader::all_tests(&mut tests);
Expand Down
5 changes: 3 additions & 2 deletions wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,8 +1207,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);

Comment on lines -1210 to -1211

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Ugh, good catch on needing to put this after the last fallible operation.

unsafe {
self.shared
.raw
Expand All @@ -1219,6 +1217,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,
Expand Down
Loading