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

Improve vulkan capability detection on Android #72780

Merged

Conversation

m4gr3d
Copy link
Contributor

@m4gr3d m4gr3d commented Feb 6, 2023

  • Add runtime check and abort when the device doesn't meet the requirements for vulkan support
    Screenshot_20230205_173034

  • Add filters to the AndroidManifest when exporting with a vulkan renderer

Screenshot 2023-02-05 at 5 21 25 PM

@@ -252,6 +252,7 @@ static const char *APK_ASSETS_DIRECTORY = "res://android/build/assets";
static const char *AAB_ASSETS_DIRECTORY = "res://android/build/assetPacks/installTime/src/main/assets";

static const int DEFAULT_MIN_SDK_VERSION = 21; // Should match the value in 'platform/android/java/app/config.gradle#minSdk'
static const int VULKAN_MIN_SDK_VERSION = 24;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the minimum Andriod SDK version? is there a point of still supporting 21-23 through OpenGL with Godot 4 or should we just make 24 the minimum? I'm not sure of the numbers here.

Copy link
Member

Choose a reason for hiding this comment

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

We discussed this at length before and agreed that we should support as low as 21 using the OpenGL renderer.

return false;
}

return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && packageManager.hasSystemFeature(PackageManager.FEATURE_VULKAN_HARDWARE_LEVEL, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

What version are we comparing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're comparing the device SDK version, and this follows a similar logic as with the export logic:
If the device SDK version < Android N (which corresponds to API 24), we consider the device as not meeting the vulkan requirements.

Copy link
Contributor

@BastiaanOlij BastiaanOlij left a comment

Choose a reason for hiding this comment

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

Questions are mostly for my clarity in understand what we're checking.

At face value this looks great :)

- Add runtime check and abort when the device doesn't meet the requirements for vulkan support
- Add filters to the AndroidManifest when exporting with a vulkan renderer
@m4gr3d m4gr3d force-pushed the add_vulkan_filter_when_necessary branch from b8ded30 to 034fd15 Compare February 6, 2023 02:47
Comment on lines +1060 to +1062
String current_renderer = GLOBAL_GET("rendering/renderer/rendering_method.mobile");
bool has_vulkan = current_renderer == "forward_plus" || current_renderer == "mobile";
if (has_vulkan) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the better check would be to query rendering/rendering_device/driver.android, which would be "vulkan".

Currently that's the only available driver for RenderingDevice-based rendering methods (forward_plus and mobile), but in theory there could be other implementations in the future (e.g. a Metal implementation for macOS/iOS, and Direct3D 12 for Windows). For Android, it's unlikely to happen, but who knows, maybe there will be some OpenGL ES 3.2-based high end RenderingDevice API in the future. Or WebGPU-native or something.

Copy link
Member

@akien-mga akien-mga Feb 6, 2023

Choose a reason for hiding this comment

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

Though actually, you'd need to check both settings probably - rendering/rendering_device/driver.android is always defined, but only relevant if the selected rendering method is a RenderingDevice-based one... and I don't think there's an easy way to know that aside from checking whether it's "forward_plus" or "mobile".

So the "safest" way might be:

Suggested change
String current_renderer = GLOBAL_GET("rendering/renderer/rendering_method.mobile");
bool has_vulkan = current_renderer == "forward_plus" || current_renderer == "mobile";
if (has_vulkan) {
String current_renderer = GLOBAL_GET("rendering/renderer/rendering_method.mobile");
bool has_vulkan = (current_renderer == "forward_plus" || current_renderer == "mobile") && GLOBAL_GET("rendering/rendering_device/driver.android") == "vulkan";
if (has_vulkan) {

Also relevant for these checks: #71542 (CC @bruvzg).

The current code could possibly fail in situations where a user defines rendering/renderer/rendering_method.android to supersede the mobile one (not sure which one would take precedence are both are supported features). Not sure who would want to do that but in theory one could want to use a different rendering method on Android and iOS and thus go for the platform-specific overrides instead of the mobile one.

I'm not suggesting to try to handle all this now though, it's just food for thought that we might need to make this more robust in the future.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Added some comments to point out potential future issues or improvements, but for now this should be a good start.

@akien-mga akien-mga merged commit 491c8ff into godotengine:master Feb 6, 2023
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants