Skip to content
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

Acquire texture: Option<std::time::Duration> timeouts #2724

Merged
merged 2 commits into from
Jun 4, 2022

Conversation

rib
Copy link
Contributor

@rib rib commented Jun 3, 2022

Description

The Vulkan backend wasn't correctly interpreting the u32 timeout value for Surface acquire_texture considering the special meaning for u32::MAX that should mean 'no timeout'.

The Vulkan vkAcquireNextImageKHR API takes a 64bit timeout in nanoseconds and u32::MAX timeout in milliseconds should have been converted to a u64::MAX.

Prior to Android 11 then Android's vkAcquireNextImageKHR implementation is also non-conformant and doesn't support timeouts (and will also output verbose log messages if timeouts are given).

To make the intent clearer, this updates the acquire_texture API to take a std::time::Duration that allows the caller to use whatever units are convenient. Additionally the duration is wrapped in an Option so it's clearer to see when no timeout is wanted without needing to reserve a special value to indicate this.

On Android < 11 then any given timeout is now ignored (as with the egl / web / metal backends) and u64::MAX is always passed to vkAcquireNextImageKHR

For reference this version of AcquireNextImageKHR doesn't support timeouts: https://android.googlesource.com/platform/frameworks/native/+/refs/tags/android-mainline-10.0.0_r13/vulkan/libvulkan/swapchain.cpp#1426 and this version does: https://android.googlesource.com/platform/frameworks/native/+/refs/tags/android-mainline-11.0.0_r45/vulkan/libvulkan/swapchain.cpp#1438 (i.e. timeout support was added in Android 11)

Testing
I have tested this via an egui Android application I have been working on recently, and this can also be tested with this minimal winit + wgpu Android application: https://github.com/rib/agdk-rust/tree/main/examples/na-winit-wgpu and these same patches based on the 0.12 branch of wgpu: https://github.com/rib/wgpu/tree/acquire_texture_duration_timeouts_v0.12

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

This is great! One nit, but otherwise LGTM

wgpu-hal/src/vulkan/instance.rs Outdated Show resolved Hide resolved
@rib rib force-pushed the acquire_texture_duration_timeouts branch from 9105c39 to abd6f05 Compare June 4, 2022 07:22
Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Sorry two more nits I missed on the first pass

wgpu-core/src/present.rs Outdated Show resolved Hide resolved
wgpu-hal/src/lib.rs Show resolved Hide resolved
@rib rib force-pushed the acquire_texture_duration_timeouts branch from abd6f05 to e982fd4 Compare June 4, 2022 10:28
Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Third times the charm

wgpu-hal/src/vulkan/instance.rs Show resolved Hide resolved
wgpu-hal/src/lib.rs Outdated Show resolved Hide resolved
wgpu-hal/src/vulkan/instance.rs Outdated Show resolved Hide resolved
@rib
Copy link
Contributor Author

rib commented Jun 4, 2022

ah, oops I also missed removing the the expect() from parsing the sdk version. I'll also switch to using val.parse::<u32>() as suggested by clippy / CI.

A std::time::Duration allows for timeouts to be specified more clearly in
Rust using whatever units are convenient for the caller, and an Option also
makes it clearer in case no timeout is wanted, as opposed to passing a
bitwise !0 as special timeout value.

Notably there was an impedance mismatch with the Vulkan backend that
takes a 64bit timeout in nanoseconds and uses u64::MAX to indicate no
timeout and the backend was not mapping a given u32::MAX into a u64::MAX
@rib rib force-pushed the acquire_texture_duration_timeouts branch from e982fd4 to b60aaf1 Compare June 4, 2022 12:23
Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Thanks!

Prior to Android 11 then Android's vkAcquireNextImageKHR implementation was
non-conformant and didn't support timeouts and additionally would log a
verbose warning if a timeout was requested.

For reference this version of AcquireNextImageKHR doesn't support timeouts:
https://android.googlesource.com/platform/frameworks/native/+/refs/tags/android-mainline-10.0.0_r13/vulkan/libvulkan/swapchain.cpp#1426
and this version does:
https://android.googlesource.com/platform/frameworks/native/+/refs/tags/android-mainline-11.0.0_r45/vulkan/libvulkan/swapchain.cpp#1438
(i.e. timeout support was added in Android 11)

This patch adds a dependency on the `android-properties` crate that provides
a simple wrapper for the `__system_property_set` syscall so that the
platform version can be read via the `ro.build.version.sdk` property
and then for versions < 30 (corresponds to Android 11) any timeout
given to `acquire_texture` will be ignored (and `u64::MAX` will be
passed to Vulkan)
@cwfitzgerald cwfitzgerald enabled auto-merge (squash) June 4, 2022 12:26
auto-merge was automatically disabled June 4, 2022 12:26

Head branch was pushed to by a user without write access

@rib rib force-pushed the acquire_texture_duration_timeouts branch from b60aaf1 to ea233d2 Compare June 4, 2022 12:26
@rib
Copy link
Contributor Author

rib commented Jun 4, 2022

btw just pushed a last second tweak to include the value of the property in the log message in case of parse failure, as suggested

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Thanks!

@cwfitzgerald cwfitzgerald enabled auto-merge (squash) June 4, 2022 15:54
@cwfitzgerald cwfitzgerald merged commit 444836f into gfx-rs:master Jun 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants