Quantcast
Jump to content

Vulkan Mobile Best Practice: How To Configure Your Vulkan Swapchain


STF News
 Share

Recommended Posts

At GDC 2019, Arm and Samsung were joined on stage in the “All-in-One Guide to Vulkan on Mobile” talk to share their learning from helping numerous developers and studios in optimizing their Vulkan mobile games. In tandem, Arm released Vulkan Best Practices for Mobile Developers to address some of the most common challenges faced when coding Vulkan applications on mobile. It includes an expansive list of runnable samples with full source code available online.

This blog series delves in detail into each sample, investigates individual Vulkan features, and demonstrates best practices of how to use them.

Overview

Setting up a Vulkan swapchain involves picking between options that don’t have a straightforward connection to performance. The default options might not be the most efficient ones, and what works best on a desktop may be different from what works on mobile.

Looking at the VkSwapchainCreateInfoKHR struct, we identified three options that need a more detailed analysis:

  • presentMode: what does each present mode imply in terms of performance?
  • minImageCount: which is the best number of images?
  • preTransform: what does it mean, and what do we need to do about it?

This blog post covers the first two points, as they are both tied to the concept of buffering swapchain images. Surface transform is quite a complex topic that we’ll cover in a future post on the Arm community.

Choosing a present mode

Vulkan has several present modes, but mobile GPUs only support a subset of them. In general, presenting an image directly to the screen (immediate mode) is not supported.

The application will render an image, then pass it to the presentation engine via vkQueuePresentKHR. The presentation engine will display the image for the next VSync cycle, and then it will make it available to the application again.

The only present modes which support VSync are:

  • FIFO: VK_PRESENT_MODE_FIFO_KHR
  • MAILBOX: VK_PRESENT_MODE_MAILBOX_KHR

We will now each of these in more detail to understand which one is better for mobile.

Screen-Shot-2019-07-26-at-3.09.02-PM.png

Figure 1 shows an outline of how the FIFO present mode works. The presentation engine has a queue (or “FIFO”) of images, in this case, three of them. At each VSync signal, the image in front of the queue displays on screen and is then released. The application will acquire one of the available ones, draw to it and then hand it over to the presentation engine, which will push it to the back of the queue. You may be used to this behavior from other graphics APIs, double or triple buffering – more on that later!

An interesting property of the FIFO present mode is that if the GPU can process images really fast, the queue can become full at some point. When this happens, the CPU and the GPU will idle until an image finishes its time on screen and is available again. The framerate will be capped at a stable 60 fps, corresponding to VSync.

This idling behavior works well on mobile because it means that no unnecessary work is performed. The extra CPU and GPU budget will be detected by the DVFS (Dynamic Voltage and Frequency Scaling) system, which reduces their frequencies to save power at no performance cost. This limits overheating and saves battery life – even a small detail such as the present mode can have a significant impact on your users’ experience!

Let us take a look at MAILBOX now. The main difference, as you can see from Figure 2 below, is that there is no queue anymore. The presentation engine will now hold a single image that will be presented at each VSync signal.

Screen-Shot-2019-07-26-at-3.09.16-PM.png

The app can acquire a new image straight away, render to it, and present it. If an image is queued for presentation, it will be discarded. Mobile demands efficiency; hence, the word “discarded” should be a big red flag when developing on mobile – the aim should always be to avoid unnecessary work.

Since an image was queued for presentation, the framerate will not improve. What is the advantage of MAILBOX then? Being able to keep submitting frames lets you ensure you have the latest user input, so input latency can be lower versus FIFO.

The price you pay for MAILBOX can be very steep. If you don’t throttle your CPU and GPU at all, one of them may be fully utilized, resulting in higher power consumption. Unless you need low-input latency, our recommendation is to use FIFO.

Screen-Shot-2019-07-26-at-3.09.30-PM.png

Choosing the number of images

It is now clear that FIFO is the most efficient present mode for mobile, but what about minImageCount? In the context of FIFO, minImageCount differentiates between double and triple buffering, which can have an impact on performance.

The number of images you ask for needs to be bound within the minimum and maximum images supported by the surface (you can query these values via surface capabilities). You will typically ask for 2 or 3 images, but the presentation engine can decide to allocate more.

Let us start with double buffering. Figure 4 outlines the expected double-buffering behavior.

Screen-Shot-2019-07-26-at-3.09.45-PM.png

Double buffering works well if frames can be processed within 16.6ms, which is the interval between VSync signals at a rate of 60 fps. The rendered image is presented to the swapchain, and the previously presented one is made available to the application again.

What happens if the GPU cannot process frames within 16.6ms?

Screen-Shot-2019-07-26-at-3.09.59-PM.png

Double buffering breaks! As you can see from Figure 5, if no images are ready when the VSync signal arrives, the only option for the presentation engine is to keep the current image on screen. The app has to wait for another whole VSync cycle before it acquires a new image, which effectively limits the framerate to 30 fps. A much higher rate could be achieved if the GPU could keep processing frames. This may be ok for you if you are happy to limit framerate to 30 fps, but if you’re aiming for 60 fps, you should consider triple buffering.

Even if your app can achieve 60 fps most of the time, with double buffering the tiniest slowdown below 60 fps results in an immediate drop to 30 fps.

Screen-Shot-2019-07-26-at-3.10.12-PM.png

Figure 6 shows triple buffering in action. Even if the GPU has not finished rendering when VSync arrives, a previous frame is queued for presentation. This means that the presentation engine can release the currently displayed image and the GPU can acquire it as soon as it is ready.

In the example shown, triple buffering results in ~50 fps versus 30 fps with double buffering.

The sample

Our Vulkan Best Practice for Mobile Developers project on Github has a sample on swapchain images, that specifically compares double and triple buffering. You can check out the tutorial for the Swapchain Images sample.

Screen-Shot-2019-07-26-at-3.10.38-PM.png

 

Screen-Shot-2019-07-26-at-3.10.52-PM.png

As you can see from Figures 7 and 8, triple buffering lets the app achieve a stable 60 fps (16.6 ms frame time), providing x2 higher frame rate. When switching to double buffering the framerate drops.

We encourage you to check out the project on the Vulkan Mobile Best Practice GitHub page and try this or other samples for yourself! The sample code gives developers on-screen control to demonstrate multiple ways of using the feature. It also shows the performance impact of the different approaches through real-time hardware counters on the display. You are also warmly invited to contribute to the project by providing feedback and fixes and creating additional samples.

Please also visit the Arm Community for more in-depth blogs on the other Vulkan samples.

View the full blog at its source

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Similar Topics

    • By Alex
      It’s that time of year again. You’ve got the biggest game in the NFL, and you’ve got your Samsung TV. All you need now is to know how to watch Super Bowl 2022 on your Samsung TV.
      If you’ve done any searching for a new big-screen to ring in Super Bowl 2022, one brand that we’re sure is dominating the ads of your browser is Samsung. Nestled comfortably in the top-five brands, Samsung Smart TVs are one of the best ways to experience any sporting event. Packed with industry-leading picture features and an intuitive streaming portal, you’ll be hard-pressed to beat the way the Super Bowl looks and feels on a Samsung set.
      If you’re all about the big game and want to know how you can watch it on that Samsung set you’re close to buying (or already own), we’ve put together this explainer to show you where and how you can catch Super Bowl 2022 through Samsung, and what settings you can use to maximize game. from the kickoff to the post-game celebration.
      This year’s Super Bowl takes place on February 13, 2022, with an expected kickoff time of 6:30 p.m. ET/3:30 p.m. PT. The annual event is taking place at SoFi Stadium in Los Angeles, with NBC holding the exclusive rights to all Super Bowl 2022 live and streamable coverage.
      How to watch Super Bowl 2022 on a Samsung TV
      Year to year, coverage rights to the Super Bowl are handled by the four main network-TV broadcasters — NBC, ABC, FOX, and CBS. In 2022, the golden contract rests in the hands of everyone’s rainbow-colored station, NBC. So what does this mean when it comes time to stream the game on your Samsung set? Well, you’ll need to do your Super Bowl watching through some kind of NBC-supported streaming app. And not to worry, there are plenty of paths to take.
      For starters, there’s Peacock, NBC’s go-to streaming service. While the basic version of Peacock is actually free, you’ll need to be subscribed to the service’s Premium ($5/month) or Plus plans ($9/month) to be able to watch Super Bowl 2022. Similar to other NBC-hosted sporting events, Super Bowl 2022 streams live through Peacock while being broadcast at the same time on NBC stations.
      Another great gateway to Super Bowl 2022 is through a Hulu + Live TV subscription. The cord-cutter’s dream, Hulu’s Live TV add-on runs $70 per month and will net you a big bounty of paid-cable channels and major network stations, including NBC and your local NBC affiliates. Best of all, before and after the big Bowl, you’ll be able to experience the many other benefits of your Hulu + Live TV subscription. This includes access to Disney+, ESPN+, Hulu’s entire library of movies and shows. Hate ads? For only another $5/month, you can bump that Live TV subscription up to an ad-free package.
      NBC affiliate access is also available through FuboTV, whic is an excellent sports-streaming service, YouTubeTV, both Sling TV packages, and DirecTV Stream.
      How to watch Super Bowl for free on a Samsung Smart TV
      Without getting into the nitty-gritty of mirroring web browsers to your TV (which can have mixed results for live events), the-tried and-true means of getting Super Bowl 2022 for free is through an over-the-air (OTA) antenna.
      Available in a number of shapes, sizes, and applications (primarily indoor/outdoor use), an OTA antenna is manually connected to the coaxial input on the back of your TV. Once plugged in, you’ll run a channel-scan that  will pick up whatever TV stations are being broadcast within a certain mile-cap. Basic indoor antennas can typically grab stations within about a 25-mile range, while more advanced outdoor models can often muster up to about 75 miles or more.
      Source: https://www.digitaltrends.com/home-theater/how-to-watch-super-bowl-2022-on-samsung-smart-tv/
    • By Alex
      Samsung TV Plus offers free tv channels to all Samsung TV owners., over 190! How do you like it? Do you use it? What channels do you like most?
      What is Samsung TV Plus?
      Your Samsung devices come with Samsung TV Plus – Samsung’s free ad-supported Smart TV video service, delivering instant access to news, sports, entertainment, and more. No subscription, additional device, or credit card needed.
      Samsung TV Plus is 100% free. When we say no strings attached, we mean it. No subscriptions, no new fees, no credit card, just free TV.
       

       


    • By Alex
      I have been using Sling TV for the $35 blue bundle here in the US. I tried FuboTV but dropped it because there wasn't enough to make up teh price difference from Sling TV. I have not tried Youtube TV, Hulu Live, or philo. I'm curiuous what you are using for live tv and how you like it as a Samsung TV Tizen app. Not throuh Roku, FireTV or Apple TV.
      How do you like the app mostly, channel surfing, loading ,etc. There's a significant price difference between Sling, Philo, and the others.

    • By Autoguy
      I recently signed up to sling tv streaming and have to say its better on apple tv. On my samsung tv it seems to be slower loading between channels. Apple tv the channels change as if its cable.  If I'm in the guide and click on a channel, I have to then click the "watch" button. I wish they would just remove that park, ON apple tv you click right into the channel for immediate streaming. I think its the way its designed, they should tweak it. Amazon Fire tv is not bad but the samsung Sling TV app needs some updating.
    • By regenitin
      Hello everyone.
      I recently purchased Samsung The Frame 2020 (QA55LS03TAKXXL) in India 2 very important observations from my end.
      I am planning to purchase the Samsung Q600A Soundbar to pair with my TV and wanted to know if my TV supports Q-Symphony. I reached out the support team and they confirmed me that the Q-Symphony function is not a feature of my TV. I wanted to know if Samsung plans to update the operating System to support Q Symphony as this feature is present in Samsung The Frame 2021 which has exact same hardware as Samsung The Frame 2020. Since the support did not have any idea i thought of reaching out to folks on this forum. I am not able to find Amazon Prime Music & Youtube Music apps on the Samsung App Store. These are supposed to be pretty necessary and widely used apps and I am not able to figure out the reason they are not in the store. I would like to know if there are any plans to launch these apps soon. Also let me know if there is any work around to get the apps installed. Thanks in advance for your inputs.
      Best Regards
      Nitin

×
×
  • Create New...