-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(hal/vulkan): count textures created by create_texture #10022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dustyleary
wants to merge
2
commits into
gfx-rs:trunk
Choose a base branch
from
dustyleary:fix-vulkan-texture-counter
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+68
−3
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| #[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)), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.