File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
src/main/java/net/vulkanmod/vulkan Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -258,13 +258,13 @@ public void beginFrame() {
258258 int vkResult = vkAcquireNextImageKHR (device , swapChain .getId (), VUtil .UINT64_MAX ,
259259 imageAvailableSemaphores .get (currentFrame ), VK_NULL_HANDLE , pImageIndex );
260260
261- if (vkResult == VK_SUBOPTIMAL_KHR || vkResult == VK_ERROR_OUT_OF_DATE_KHR || swapChainUpdate ) {
261+ if (swapChain . isActuallySuboptimal ( vkResult ) || vkResult == VK_ERROR_OUT_OF_DATE_KHR || swapChainUpdate ) {
262262 swapChainUpdate = true ;
263263 skipRendering = true ;
264264 beginFrame ();
265265
266266 return ;
267- } else if (vkResult != VK_SUCCESS ) {
267+ } else if (vkResult != VK_SUCCESS && vkResult != VK_SUBOPTIMAL_KHR ) {
268268 throw new RuntimeException ("Cannot acquire next swap chain image: %s" .formatted (VkResult .decode (vkResult )));
269269 }
270270
@@ -347,10 +347,10 @@ private void submitFrame() {
347347
348348 vkResult = vkQueuePresentKHR (DeviceManager .getPresentQueue ().queue (), presentInfo );
349349
350- if (vkResult == VK_ERROR_OUT_OF_DATE_KHR || vkResult == VK_SUBOPTIMAL_KHR || swapChainUpdate ) {
350+ if (vkResult == VK_ERROR_OUT_OF_DATE_KHR || swapChain . isActuallySuboptimal ( vkResult ) || swapChainUpdate ) {
351351 swapChainUpdate = true ;
352352 return ;
353- } else if (vkResult != VK_SUCCESS ) {
353+ } else if (vkResult != VK_SUCCESS && vkResult != VK_SUBOPTIMAL_KHR ) {
354354 throw new RuntimeException ("Failed to present rendered frame: %s" .formatted (VkResult .decode (vkResult )));
355355 }
356356
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ public class SwapChain extends Framebuffer {
4040 private VkExtent2D extent2D ;
4141 public boolean isBGRAformat ;
4242 private boolean vsync = false ;
43+ private boolean shouldPreRotate = false ;
4344
4445 private int [] glIds ;
4546
@@ -120,7 +121,11 @@ private void createSwapChain() {
120121 createInfo .imageSharingMode (VK_SHARING_MODE_EXCLUSIVE );
121122 }
122123
123- createInfo .preTransform (surfaceProperties .capabilities .currentTransform ());
124+ int surfaceTransform = surfaceProperties .capabilities .currentTransform ();
125+ shouldPreRotate = (surfaceTransform &
126+ (VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR |VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR | VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR )) != 0 ;
127+
128+ createInfo .preTransform (VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR );
124129
125130 int supportedCompositeAlpha = surfaceProperties .capabilities .supportedCompositeAlpha ();
126131 if ((supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR ) != 0 ) {
@@ -352,6 +357,11 @@ private static int checkPresentMode(int... requestedModes) {
352357 }
353358 }
354359
360+ public boolean isActuallySuboptimal (int result ) {
361+ // Make android shut the fuck up about the stupid pre-rotation
362+ return result == VK_SUBOPTIMAL_KHR && !shouldPreRotate ;
363+ }
364+
355365 public boolean isVsync () {
356366 return this .vsync ;
357367 }
You can’t perform that action at this time.
0 commit comments