Skip to content

Fix rotated Vulkan output on Android - #119

Merged
Try merged 2 commits into
Try:masterfrom
Solessfir:android-orientation
Oct 3, 2026
Merged

Try merged 2 commits into
Try:masterfrom
Solessfir:android-orientation

Conversation

@Solessfir

@Solessfir Solessfir commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

OpenGothic's main menu renders rotated 90 degrees on Android. The swapchain uses currentTransform even though the application renders an unrotated frame.

Prefer VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR when supported on any platform, letting the presentation engine handle rotation. Otherwise, use currentTransform.

Verified upright rendering with OpenGothic on a Galaxy S24.

Related: Try/OpenGothic#1001

#ifdef __ANDROID__
// Applications render in window coordinates, so let Android rotate the presentation.
if(swapChainSupport.capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR)
createInfo.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

should it be just VkSurfaceTransformFlagBitsKHR(0) in all cases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

0 isn’t valid here; identity is VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR (1). We can remove the Android guard and prefer identity on all platforms, while retaining the supported-transform check and fallback.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Base on this guide here: https://docs.vulkan.org/samples/latest/samples/performance/surface_rotation/README.html
0 allowed.

Or more exact wording:

Ignore the preTransform field in VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR. This will not match the value returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR and therefore the Android Compositor will rotate the scene before presenting it to the display

Basically, as long as we letting composer do it's job we good.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed on letting the compositor handle rotation. The linked sample uses VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR, not 0. I can remove the Android guard and use that selection across platforms, keeping the supported-transform check.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I can remove the Android guard and use that selection across platforms, keeping the supported-transform check.

Sounds good: VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR by default, if possible and currentTransform otherwise

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated as suggested: prefer VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR when supported, otherwise use currentTransform. Removed the Android guard.

@Try
Try merged commit b9b4e3b into Try:master Oct 3, 2026
4 checks passed
@Try

Try commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Merged, thanks!

@Solessfir
Solessfir deleted the android-orientation branch October 3, 2026 21:45
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.

2 participants