Quantcast
Jump to content


New Game Changing Vulkan Extensions for Mobile: Timeline Semaphores


Recommended Posts

2021-06-28-01-banner.jpg

The Samsung Developers team works with many companies in the mobile and gaming ecosystems. We're excited to support our partner, Arm, as they bring timely and relevant content to developers looking to build games and high-performance experiences. This Vulkan Extensions series will help developers get the most out of the new and game-changing Vulkan extensions on Samsung mobile devices.

In previous blogs, we have already explored two key Vulkan extension game changers that will be enabled by Android R. These are Descriptor Indexing and Buffer Device Address. In this blog, we explore the third and final game changer, which is 'Timeline Semaphores'.

The introduction of timeline semaphores is a large improvement to the synchronization model of Vulkan and is a required feature in Vulkan 1.2. It solves some fundamental grievances with the existing synchronization APIs in Vulkan.

The problems with VkFence and VkSemaphore

In earlier Vulkan extensions, there are two distinct synchronization objects for dealing with CPU <-> GPU synchronization and GPU queue <-> GPU queue synchronization.

The VkFence object only deals with GPU -> CPU synchronization. Due to the explicit nature of Vulkan, you must keep track of when the GPU completes the work you submit to it.

vkQueueSubmit(queue, …, fence);

The previous code is the way we would use a fence, and later this fence can be waited on. When the fence signals, we know it is safe to free resources, read back data written by GPU, and so on. Overall, the VkFence interface was never a real problem in practice, except that it feels strange to have two entirely different API objects which essentially do the same thing.

VkSemaphore on the other hand has some quirks which makes it difficult to use properly in sophisticated applications. VkSemaphore by default is a binary semaphore. The fundamental problem with binary semaphores is that we can only wait for a semaphore once. After we have waited for it, it automatically becomes unsignaled again. This binary nature is very annoying to deal with when we use multiple queues. For example, consider a scenario where we perform some work in the graphics queue, and want to synchronize that work with two different compute queues. If we know this scenario is coming up, we will then have to allocate two VkSemaphore objects, signal both objects, and wait for each of them in the different compute queues. This works, but we might not have the knowledge up front that this scenario will play out. Often where we are dealing with multiple queues, we have to be somewhat conservative and signal semaphore objects we never end up waiting for. This leads to another problem …

A signaled semaphore, which is never waited for, is basically a dead and useless semaphore and should be destroyed. We cannot reset a VkSemaphore object on the CPU, so we cannot ever signal it again if we want to recycle VkSemaphore objects. A workaround would be to wait for the semaphore on the GPU in a random queue just to unsignal it, but this feels like a gross hack. It could also potentially cause performance issues, as waiting for a semaphore is a full GPU memory barrier.

Object bloat is another considerable pitfall of the existing APIs. For every synchronization point we need, we require a new object. All these objects must be managed, and their lifetimes must be considered. This creates a lot of annoying “bloat” for engines.

The timeline – fixing object bloat – fixing multiple waits

The first observation we can make of a Vulkan queue is that submissions should generally complete in-order. To signal a synchronization object in vkQueueSubmit, the GPU waits for all previously submitted work to the queue, which includes the signaling operation of previous synchronization objects. Rather than assigning one object per submission, we synchronize in terms of number of submissions. A plain uint64_t counter can be used for each queue. When a submission completes, the number is monotonically increased, usually by one each time. This counter is contained inside a single timeline semaphore object. Rather than waiting for a specific synchronization object which matches a particular submission, we could wait for a single object and specify “wait until graphics queue submission #157 completes.”

We can wait for any value multiple times as we wish, so there is no binary semaphore problem. Essentially, for each VkQueue we can create a single timeline semaphore on startup and leave it alone (uint64_t will not overflow until the heat death of the sun, do not worry about it). This is extremely convenient and makes it so much easier to implement complicated dependency management schemes.

Unifying VkFence and VkSemaphore

Timeline semaphores can be used very effectively on CPU as well:

VkSemaphoreWaitInfoKHR info = { VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO_KHR };
info.semaphoreCount = 1;
info.pSemaphores = &semaphore;
info.pValues = &value;
vkWaitSemaphoresKHR(device, &info, timeout);

This completely removes the need to use VkFence. Another advantage of this method is that multiple threads can wait for a timeline semaphore. With VkFence, only one thread could access a VkFence at any one time.

A timeline semaphore can even be signaled from the CPU as well, although this feature feels somewhat niche. It allows use cases where you submit work to the GPU early, but then 'kick' the submission using vkSignalSemaphoreKHR. The accompanying sample demonstrates a particular scenario where this function might be useful:

VkSemaphoreSignalInfoKHR info = { VK_STRUCTURE_TYPE_SEMAPHORE_SIGNAL_INFO_KHR };
info.semaphore = semaphore;
info.value = value;
vkSignalSemaphoreKHR(device, &info);

Creating a timeline semaphore

When creating a semaphore, you can specify the type of semaphore and give it an initial value:

VkSemaphoreCreateInfo info = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO };
VkSemaphoreTypeCreateInfoKHR type_info = { VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO_KHR };
type_info.semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE_KHR;
type_info.initialValue = 0;
info.pNext = &type_info;
vkCreateSemaphore(device, &info, NULL, &semaphore);

Signaling and waiting on timeline semaphores

When submitting work with vkQueueSubmit, you can chain another struct which provides counter values when using timeline semaphores, for example:

VkSubmitInfo submit = { VK_STRUCTURE_TYPE_SUBMIT_INFO };
submit.waitSemaphoreCount = 1;
submit.pWaitSemaphores = &compute_queue_semaphore;
submit.pWaitDstStageMask = &wait_stage;
submit.commandBufferCount = 1;
submit.pCommandBuffers = &cmd;
submit.signalSemaphoreCount = 1;
submit.pSignalSemaphores = &graphics_queue_semaphore;
 VkTimelineSemaphoreSubmitInfoKHR timeline = {
VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR };
timeline.waitSemaphoreValueCount = 1;
timeline.pWaitSemaphoreValues = &wait_value;
timeline.signalSemaphoreValueCount = 1;
timeline.pSignalSemaphoreValues = &signal_value;
submit.pNext = &timeline;
 signal_value++; // Generally, you bump the timeline value once per submission.
 vkQueueSubmit(queue, 1, &submit, VK_NULL_HANDLE);

Out of order signal and wait

A strong requirement of Vulkan binary semaphores is that signals must be submitted before a wait on a semaphore can be submitted. This makes it easy to guarantee that deadlocks do not occur on the GPU, but it is also somewhat inflexible. In an application with many Vulkan queues and a task-based architecture, it is reasonable to submit work that is somewhat out of order. However, this still uses synchronization objects to ensure the right ordering when executing on the GPU. With timeline semaphores, the application can agree on the timeline values to use ahead of time, then go ahead and build commands and submit out of order. The driver is responsible for figuring out the submission order required to make it work. However, the application gets more ways to shoot itself in the foot with this approach. This is because it is possible to create a deadlock with multiple queues where queue A waits for queue B, and queue B waits for queue A at the same time.

Ease of porting

It is no secret that timeline semaphores are inherited largely from D3D12’s fence objects. From a portability angle, timeline semaphores make it much easier to have compatibility across the APIs.

Caveats

As the specification stands right now, you cannot use timeline semaphores with swap chains. This is generally not a big problem as synchronization with the swap chain tends to be explicit operations renderers need to take care of.

Another potential caveat to consider is that the timeline semaphore might not have a direct kernel equivalent on current platforms, which means some extra emulation to handle it, especially the out-of-order submission feature. As the timeline synchronization model becomes the de-facto standard, I expect platforms to get more native support for it.

Conclusion

All three key Vulkan extension game changers improve the overall development and gaming experience through improving graphics and enabling new gaming use cases. We hope that we gave you enough samples to get you started as you try out these new Vulkan extensions to help bring your games to life

Follow Up

Thanks to Hans-Kristian Arntzen and the team at Arm for bringing this great content to the Samsung Developers community. We hope you find this information about Vulkan extensions useful for developing your upcoming mobile games.

The Samsung Developers site has many resources for developers looking to build for and integrate with Samsung devices and services. Stay in touch with the latest news by creating a free account or by subscribing to our monthly newsletter. Visit the Marketing Resources page for information on promoting and distributing your apps and games. Finally, our developer forum is an excellent way to stay up-to-date on all things related to the Galaxy ecosystem.

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 the installation of its Outdoor LED Signage XHB Series (P8) at the flagship location of Shinsegae Department Store in Seoul, South Korea. Unveiled during the “2024 Lights Up SEOUL, KOREA” event today, the installation is set to establish Myeongdong Square in Seoul as Korea’s new premier landmark, featuring a stunning media lighting display that illuminates the heart of Seoul’s iconic shopping district.
       
      “Our LED displays present unlimited possibilities for places like Myeongdong to bear new elements of cultural significance,” said Hoon Chung, Executive Vice President of the Visual Display Business at Samsung Electronics. “This installation gives us an opportunity to showcase in the biggest way possible that our outdoor digital displays are built to engage, built to deliver impactful content, and built to last.”
       
      Located within the Myeongdong Special Tourist Zone Area, Shinsegae Department Store is uniquely positioned as a free outdoor advertising zone that enables creative and expansive installations. Samsung’s massive outdoor LED signage featuring an anamorphic 8K display, wraps around the entire outer wall of the building, measuring 71.8 meters in width and 17.9 meters in height — equivalent in size to three basketball courts.
       

       
      Spanning a total area of 1,285 square meters, the display is designed for resilience in harsh weather, featuring an IP66 rating for dust and water resistance, and UL 48 and UL 746C certifications1 for year-round durability. The installation is engineered for high visibility and vibrant color accuracy, with support for HDR10+ technology to deliver sharp contrast and rich visuals. With a max brightness of 8,000 nits,2 the display ensures exceptional clarity even in direct sunlight. Its high refresh rate of 7,680Hz minimizes flicker and the moiré effect,3 ensuring a stable display that remains visually crisp, even through camera lenses.
       
      Samsung’s track record of success with digital signage spans prominent venues worldwide. In South Korea, Samsung provided the country’s largest ever high-definition LED signage to Coex SM Town, while transformative installations at New York’s Citi Field and Houston’s Minute Maid Park set new standards for in-stadium displays. At Citi Field, Samsung installed the largest scoreboard in professional baseball, featuring over 29,800 square feet of LED screens that immerse fans in the action from every angle. Similarly, at Minute Maid Park, Samsung’s high-definition LED technology redefined the fan experience with massive outdoor displays and a dynamic new main scoreboard, all designed to enhance the excitement of the game.
       

       
      In Myeongdong, the new installation will not only host engaging advertisements and dynamic video content, but also transform into a breathtaking annual Christmas media façade, creating a festive atmosphere for visitors.
       
      “Shinsegae’s media façade, beloved by global customers for the past 10 years, has now been recreated as Shinsegae Square. This transformation paves the way for it to become an iconic landmark of Seoul, making it not only a must-visit attraction but also a central hub for K-culture. We are excited to partner with Samsung to bring our customers unique experiences that blend heritage and digital technology,” Shinsegae spokesperson said.
       
      Samsung’s Outdoor LED Signage is renowned for exceptional performance in demanding environments, evidenced by award-winning deployments at iconic venues such as Inglewood, California’s SoFi Stadium, which boasts the world’s largest LED videoboard ever built for sports, and the Formula 1 Las Vegas Grand Prix, where Samsung installed a 481-foot-long rooftop LED display in the shape of the F1 logo. As Myeongdong evolves into a global tourism destination, Samsung continues to lead with solutions that inspire and engage.
       
       
       
      1 UL 48 and UL 746C certifications, issued by Underwriters Laboratories (UL), verify compliance with safety standards for electric signs and durability of materials in outdoor environments, including UV and weather resistance.
      2 Maximum brightness measured post-calibration; actual values may vary with conditions.
      3 The moiré effect is an undesirable visual phenomenon that occurs when repetitive patterns, such as lines, are captured in photographs.
      View the full article
    • By Samsung Newsroom
      Samsung Electronics today announced that its proprietary cryptography module, Samsung CryptoCore,1 has earned the prestigious FIPS 140-3 certification2 from the National Institute of Standards and Technology (NIST). This certification underscores Samsung’s commitment to providing industry-leading security and data protection for Smart TV users.
       
      “As home entertainment systems become more connected, it becomes critical for technology companies to safeguard the personal data that enables the seamless connectivity enjoyed by so many,” said Yongjae Kim, Executive Vice President and Head of the R&D Team, Visual Display Business at Samsung Electronics. “By integrating the FIPS 140-3-certified CryptoCore into our Smart TVs, Samsung is taking our commitment to secure home entertainment a step further and ensuring that our users can freely experience the value of our products.”
       
      Beginning in 2025, Samsung CryptoCore will be fully integrated into Tizen OS,3 Samsung’s Smart TV operating system, enhancing the security of key products such as TVs, monitors and digital signage. With Samsung CryptoCore embedded in Tizen OS, personal data linked to Samsung accounts will be securely encrypted, SmartThings authentication information will be protected from external hacking threats and content viewed on TVs will benefit from enhanced copyright protection.
       
      Since 2015, Samsung has equipped its Smart TVs with Samsung Knox,4 a security platform that has earned Common Criteria (CC) certification5 for 10 consecutive years. But with its newly acquired FIPS 140-3 certification, Samsung has strengthened its defenses against hacking and data breaches even further, proactively protecting personal information with advanced encryption technology.
       
      Recognized by governments in 10 countries,6 the FIPS 140-3 certification requires comprehensive testing of cryptographic modules to ensure their security, integrity and reliability. For users, this means Samsung Smart TVs offer cutting-edge protection against privacy breaches, allowing them to enjoy their content, connect smart devices and engage with IoT services securely and without concerns.
       


       
      1 Samsung CryptoCore is a software library that encrypts and decrypts data during both transmission and storage.
      2 Federal Information Processing Standard (FIPS) 140-3 covers the security requirements for cryptographic modules.
      3 Tizen OS 9.0.
      4 Samsung Knox provides privacy protection on its Smart TVs through features like Tizen OS Monitoring, Phishing Site Blocking and Knox Vault. Knox Vault is available only on the QN900D and QN800D models.
      5 Common Criteria (CC) certification is a global security standard recognized by 31 countries for IT product integrity.
      6 Recognized in the United States, Canada, UK, Germany, France, South Korea, Japan, Singapore, Australia and New Zealand.
      View the full article
    • By Samsung Newsroom
      Start Date Nov 21, 2024 - Nov 21, 2024
      Location Online
      Samsung Developer Conference Korea 2024 (SDC24 Korea) will be held online on November 21st.
      Since its inception in 2014, SDC24 Korea has been emphasizing the importance of software by expanding from open source to all areas of software development. It's now celebrating its 11th anniversary.
      This year's SDC24 Korea features a variety of exciting events including keynote speeches from our CTO and other renowned speakers as well as more than 29 technical sessions.
      Furthermore, we are excited to share that SDC24 Korea will incorporate content from the recent SDC24 conference held in the US on October 3rd (US time), providing attendees with even more opportunities to learn, connect, and engage.
      Anyone can attend SDC24 Korea through pre-registration, and keynotes and major sessions will be announced on the SDC24 Korea website. For more information, please visit the SDC24 Korea website!

      Visit SDC24 Website View the full blog at its source
    • By Alex
      Samsung goes big on smart fridges with 10 new models
      With Family Hub 2.0, you can do more on the fridges' 21.5-inch Tizen-powered screens.

      Samsung must have done alright with its crazy WiFi-connected smart fridges last year, because it's launching six more in 2017, for a total of 10. That includes both three-door, four-door and four-door "flex" models with dual freezers (shown above). It's also updated the fridge's OS to Family Hub 2.0 with a new interface that lets everyone have a profile, complete with avatar. From there, you can share photos, calendars and handwritten memos on your fridge's giant 21.5-inch LED touchscreen. Voice control and entertainment apps like Pandora are on offer as well.
      As before, the Tizen-powered fridges can take a picture of their contents each time you open the door, and let you replenish stocks using "Groceries by MasterCard." Taking a page from Amazon's Alexa, they can also read out recipes via the AllRecipes-powered app, and run apps like Spotify, GrubHub and Glympse. Using voice control, you can run apps, get the weather and update grocery lists, for instance.
      Samsung didn't say exactly which models are coming, how much they cost or even what regular refrigerator-type features they have. However, last year's Family Hub 1.0 model, when it finally came out in May, cost $6,000, so we assume it can do pretty much everything you'd want. Hopefully with 10 models in total, some will be more affordable -- naturally, we'll try to get a look during the show and ask Samsung for ourselves.
      Click here to catch up on the latest news from CES 2017. Source: https://www.engadget.com/2017/01/03/samsung-goes-big-on-smart-fridges-with-ten-new-models/ In this article: AllRecipes, ces2017, familyhub, FamilyHub2.0, food and drink, food-and-drink,foodanddrink, gear, home, HomeDelivery, MasterCard, pandora, refrigerator, samsung,SmartFridge, voicecontrol
    • By Mahesh Gadhe
      Hi 
      I have a Samsung professional digital signage display device (TV) where I manually download and install the app through the web app address. Instead, I want the app to auto-update. If I replace the previously installed file with a new one, the device should automatically detect the new version, download, and install it without any manual interaction.





×
×
  • Create New...