Quantcast
Jump to content


Vulkan Mobile Best Practice: How To Configure Your Vulkan Swapchain


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...
  • Similar Topics

    • By Samsung Newsroom
      Samsung Electronics today announced that Lucid Group, Inc., has installed The Wall at its design studio to enhance the collaborative design process for their future electric vehicle models. With cutting-edge MicroLED technology, The Wall offers exceptional visual capabilities, providing Lucid with additional tools to meet the surging demand for sustainable electric vehicles, while elevating the luxury experience for drivers.
       
      “At Lucid, we’re on a mission to inspire the adoption of sustainable energy with a focus on the human experience. With The Wall, we’re able to take this mission to new heights,” said Jenny Ha, Exterior Design Manager at Lucid Motors. “While designing the Lucid Air Sapphire, from concept sketches all the way to final adjustments, Samsung enabled us to visualize the future of our vehicles in high resolution at all stages of development. No detail was left unnoticed, and we’re thrilled for our customers to experience the results of the new design process.”
       
      “The Wall installation in the Lucid Motors design studio is another great example of how Samsung innovations are helping our partners and customers unlock their own exciting innovations to drive their business in exciting new ways,” said James Fishler, Senior Vice President of the Home Entertainment & Display Divisions at Samsung Electronics America. “Supporting Lucid in its mission to deliver sustainable luxury vehicles – and the stunning design of the new Lucid Sapphire made possible with our 255-inch class high resolution display — has been both inspiring and rewarding.”
       
      ▲ Simon Tovey, Exterior Design Director at Lucid Motors, and Jiyeon Jenny Ha, Exterior Design Manager, discuss the exterior design for the Lucid Air Sapphire using The Wall with MicroLED technology
       
       
      High-Definition Image Quality Delivered at Full-Sized Scale for Seamless Collaboration
      Powered by superior MicroLED technology, the 255-inch display empowers Lucid’s designers to view and review their designs in true-to-life color at a 1:1 scale. Not only does the true-life color produce a realistic rendering of the design, but the high-resolution display accurately reproduces the reflection of light off complex 3D surfaces.
       
      The authentic image rendition allows for increased collaboration between engineering and design teams, resulting in accelerated decision making processes that save the company time and money.
       
      ▲ Simon Tovey, Exterior Design Director at Lucid Motors, reviews details of the Lucid Air Sapphire in front of The Wall with MicroLED technology
       
      “The Wall has revolutionized the way our design and engineering teams work together,” added Ha. “With this technology, we can effortlessly visualize design data that incorporates engineering feedback and simulation results, allowing us to promptly assess the effects of any alteration on the overall design. In other words, development teams now operate more efficiently, and drivers can enjoy enhanced luxury aesthetics without compromising superior vehicle performance. It can be a tricky sweet spot to balance, but The Wall helps us pinpoint it seamlessly.”
       
      ▲ Jiyeon Jenny Ha, Exterior Design Manager at Lucid Motors, presents the design for Lucid Air Sapphire on The Wall with MicroLED technology
       
      The Wall’s flexible-yet-compact design also saves valuable studio floor space at Lucid’s headquarters. This allows multidisciplinary teams to use the space for collaborative design workshops to perfectly refine every detail of the vehicles to deliver the premiere quality drivers deserve.
       
      To learn more about how The Wall is revolutionizing automotive design, please visit: https://www.samsung.com/us/business/displays/direct-view-led/the-wall/.
      View the full article
    • By Samsung Newsroom
      Throughout their years of collaboration, Samsung Art Store and Tate have worked together to make art more accessible to consumers worldwide. As a result, users of The Frame can put works from Tate’s extensive collection on display within their own homes. The two have worked together since 2018 to leverage the Art Store platform to bring culture into the homes of users around the world, and to enrich users’ lives.
       
      ▲ Tate Britain
       
      Samsung Newsroom sat down with Rosey Blackmore, Licensing and Merchandise Director at Tate, to discuss technology’s impact on our art experiences and on art accessibility, among other topics. Read on to find out more.
       
       
      Years of Collaboration Bringing Art Into the Home
      Q: Tell us a bit about your role at Tate and your experience working with Samsung Art Store.
       
      I’m responsible for our licensing and merchandise at Tate, where our team creates and licenses products featuring art from Tate’s collection. Our gallery spaces are free to visit, and all income that we generate helps make that possible, so it’s a very satisfying role.
      We’ve been really delighted to work with Samsung on their Art Store. Our mission at Tate is to enable the public to enjoy art, so this project contributes to that. As the Art Store has grown in popularity, we have been really interested to see which images are the most viewed, and to refresh and add new art to the selection available in light of those trends we see.
       
       
      Q: How are pieces from the Tate’s expansive collection chosen for The Frame?
       
      It’s difficult, as we have so many to choose from! There are more than 80,000 works in Tate’s collection, but we try and select those that we feel people will enjoy living with, as well as some that are very familiar.
       
       
      Q: Have you noticed any interesting trends over the years in what pieces users are most attracted to in Samsung’s Art Store?
       
      Yes, we really have. For example, one of the most popular works is Arenig, North Wales by James Dickson Innes, who isn’t a very well- known artist, but this is a particularly gorgeous work of a mountain viewed from across a lake and has beautiful violet hues. So, I imagine it brings a sense of calm to those who choose to display it on The Frame.
       
      ▲ Arenig, North Wales by James Dickson Innes
       
       
      Engaging a Diverse Audience Through Art
      Q: What work has Tate done recently to build upon its vision to engage diverse audiences and help develop individual creative potential? Why is this part of Tate’s mission?
       
      Engaging a more diverse audience is absolutely at the heart of the work that we are doing at Tate. It’s something that we are passionate about because it reflects our belief that art enriches lives, and that everyone has the right to that experience. For many years now, we have been ensuring that the art we collect and exhibit represents as diverse a range of backgrounds and experiences as possible. At Tate Modern, 50% of our program features art created by women, and at Tate Britain the same is true of our contemporary displays and exhibitions.
      Because of our fundamental belief that art enriches lives, Tate also offers an extensive range of free family programs throughout the year, aimed at encouraging children to be creative
       
      Q: In your opinion, how has Tate leveraged The Frame and Art Store to further support its mission for engaging an inclusive and diverse audience?
       
      We love that Samsung’s Art Store enables more people to access our collection and broadens the number of people enjoying art. And, perhaps some will become curious about the artworks they are seeing and choose to find out more about them too. That directly supports our mission to encourage both the enjoyment and understanding of art across diverse audiences.
       
       
      Q: Out of the works of art selected for the Art Store, which three would you recommend users display on The Frame?
       
      My first suggestion of the three artworks from the Art Store would be the very beautiful Abstract Composition by Jessica Dismorr, for its subtle and calm color palette.
       
      ▲ Abstract Composition by Jessica Dismorr
       
      The second would be Blue House on the Shore by Paul Nash, as it’s a wonderfully enigmatic and romantic image.
       
      ▲ Blue House on the Shore by Paul Nash
       
      And finally, a very personal choice which is Carnation, Lily, Lily, Rose by John Singer Sargent, as this is a painting that I’ve loved since I first visited Tate as a teenager, and I still find it as extraordinary now as I did then. When you walk into the gallery where the picture hangs, the painted lanterns somehow seem to light the room, and The Frame would recreate that magical experience.
       
      ▲ Carnation, Lily, Lily, Rose by John Singer Sargent
       
       
      Leveraging Technology To Enhance Human Experiences
      Q: In what ways has Tate leveraged technology to provide an enhanced visitor experience at the museum?
       
      A good example is ‘Tate Draw’ where children can use special software and screens in the galleries to create their own artworks inspired by Tate’s collection, with their finished designs projected on the walls. Technology is expanding the ways in which we can all be creative.
       
       
      Q: Do you anticipate any implications that technology will have on the art world?
       
      Technology is undoubtedly affecting all aspects of our lives, and we need to embrace it.
       
      There’s no doubt that technological advancements will have profound effects on the way that we access and experience art. Tate is always considering how we can reduce the carbon footprint of our activities— technology may offer interesting opportunities for this in the future, such as digital experiences of art rather than shipping the original artworks.
       
       
      Q: Are there any upcoming events or special activities Tate has planned that you can tell us about?
       
      Tate’s exhibition programme always strives to offer a diverse range of content and this autumn is no exception! At Tate Britain, women are taking centre-stage with a major survey exhibition of the humorous and irreverent work of Sarah Lucas as well as a group show exploring the radical work of feminist artists working in Britain during the 1970s and 80s.
       
      ▲ Tate Modern
       
      At Tate Modern, artists from across the African continent are a key focus, with this year’s annual new commission for the gallery’s iconic Turbine Hall being created by Ghanian artist El Anatsui. A major survey of contemporary photography by artists working across Africa and its diaspora remains on show until the new year, joined by a retrospective of Philip Guston, one of the most influential and important American painters of the 20th century.
       
      ▲ Tate Liverpool
       
      Down at Tate St Ives, visitors can continue to enjoy a revelatory group exhibition exploring the experimental paintings made by artists working in Casablanca during the 1960s and 70s, while Tate Liverpool will embark on an exciting new program in collaboration with the Royal Institute of British Architects (RIBA). The partnership will see a range of new exhibitions and events staged at RIBA’s building at Mann Island in Liverpool during the gallery’s temporary closure period for redevelopment, due to be completed in autumn 2025.
       
      ▲ Tate St. Ives
       
      Visit Samsung Art Store in The Frame to see more of Tate’s collection.
      View the full article





×
×
  • Create New...