godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 68 forks source link

Add pre-rotation optimization for Vulkan rendering on Android #1515

Open The-O-King opened 3 years ago

The-O-King commented 3 years ago

Describe the project you are working on: Any Vulkan-based Android project

Describe the problem or limitation you are having in your project: Previously with OpenGL, the driver was responsible for handling the relationship between the Android compositor and the app's rendering surface with regards to the device's orientation - but with Vulkan, this responsibility is placed on the app developer. If not handled properly, the Android compositor is left to make the rotation of the rendered surface to match the device's orientation, which can be very costly performance wise.

Describe the feature / enhancement and how it helps to overcome the problem or limitation: Recreating the swapchain properly and applying a rotation to the final projection matrix used to render to the surface will handle device orientation changes properly and avoid overhead from usage of the Android compositor

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams: Using the method described in this blog post we will need to detect the android device's "identity" orientation/screen resolution on startup, and when an orientation change occurs, swapchain recreation will have to set the preTransform flag properly and then use the devices current orientation to apply a rotation matrix to the projection matrix used to render the final image onscreen - as we will be keeping the swapchain at the device's original identity orientation's screen resolution

An initial look at the renderer's code - we may want to implement the rotation of the projection matrix in the render_camera functions found in rendering_server_scene.cpp

create_swap_chain/_update_swap_chain in vulkan_context.cpp will also need to be updated for this - would using ifdef guards be a suitable solution? Or do we want a more object-oriented abstraction with a new implementation of vulkan_context.cpp for android devices?

As mentioned in the article, we need to discuss implementations for pre-android 10 and android 10+ devices, also have to take into consideration viewport/scissor adjustments and the usage of derivatives in shaders when compiling for android

If this enhancement will not be used often, can it be worked around with a few lines of script?: No, this is a rendering-engine level optimization

Is there a reason why this should be core and not an add-on in the asset library?: This is a fundamental optimization that is recommended for all Android applications to implement

m4gr3d commented 1 week ago

Fixed in the TheForge's PR - https://github.com/godotengine/godot/pull/90284

Calinou commented 6 days ago

Reopening, as https://github.com/godotengine/godot/pull/90284 hasn't been merged yet.