Quantcast
Jump to content


New Game Changing Vulkan Extensions for Mobile: Buffer Device Address


Recommended Posts

2021-07-06-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.

Android R is enabling a host of useful Vulkan extensions for mobile, with three being key 'game changers'. These are set to improve the state of graphics APIs for modern applications, enabling new use cases and changing how developers can design graphics renderers going forward. You can expect to see these features across a variety of Android smartphones, such as the new Samsung Galaxy S21, and existing Samsung Galaxy S models like the Samsung Galaxy S20. The first blog explored the first game changer extension for Vulkan – ‘Descriptor Indexing'. This blog explores the second game changer extension – ‘Buffer Device Address.’

VK_KHR_buffer_device_address

VK_KHR_buffer_device_address is a monumental extension that adds a unique feature to Vulkan that none of the competing graphics APIs support.

Pointer support is something that has always been limited in graphics APIs, for good reason. Pointers complicate a lot of things, especially for shader compilers. It is also near impossible to deal with plain pointers in legacy graphics APIs, which rely on implicit synchronization.

There are two key aspects to buffer_device_address (BDA). First, it is possible to query a GPU virtual address from a VkBuffer. This is a plain uint64_t. This address can be written anywhere you like, in uniform buffers, push constants, or storage buffers, to name a few.

The key aspect which makes this extension unique is that a SPIR-V shader can load an address from a buffer and treat it as a pointer to storage buffer memory immediately. Pointer casting, pointer arithmetic and all sorts of clever trickery can be done inside the shader. There are many use cases for this feature. Some are performance-related, and some are new use cases that have not been possible before.

Getting the GPU virtual address (VA)

There are some hoops to jump through here. First, when allocating VkDeviceMemory, we must flag that the memory supports BDA:

VkMemoryAllocateInfo info = {…};
VkMemoryAllocateFlagsInfo flags = {…};
flags.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT_KHR;
vkAllocateMemory(device, &info, NULL, &memory);

Similarly, when creating a VkBuffer, we add the VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_KHR usage flag. Once we have created a buffer, we can query the VA:

VkBufferDeviceAddressInfoKHR info = {…};
info.buffer = buffer;
VkDeviceSize va = vkGetBufferDeviceAddressKHR(device, &info);

From here, this 64-bit value can be placed in a buffer. You can of course offset this VA. Alignment is never an issue as shaders specify explicit alignment later.

A note on debugging

When using BDA, there are some extra features that drivers must support. Since a pointer does not necessarily exist when replaying an application capture in a debug tool, the driver must be able to guarantee that virtual addresses returned by the driver remain stable across runs. To that end, debug tools supply the expected VA and the driver allocates that VA range. Applications do not care that much about this, but it is important to note that even if you can use BDA, you might not be able to debug with it.

typedef struct VkPhysicalDeviceBufferDeviceAddressFeatures {
    VkStructureType  sType;
    void*                     pNext;
    VkBool32              bufferDeviceAddress;
    VkBool32              bufferDeviceAddressCaptureReplay;
    VkBool32              bufferDeviceAddressMultiDevice;
} VkPhysicalDeviceBufferDeviceAddressFeatures;

If bufferDeviceAddressCaptureReplay is supported, tools like RenderDoc can support BDA.

Using a pointer in a shader

In Vulkan GLSL, there is the GL_EXT_buffer_reference extension which allows us to declare a pointer type. A pointer like this can be placed in a buffer, or we can convert to and from integers:

#version 450
#extension GL_EXT_buffer_reference : require
#extension GL_EXT_buffer_reference_uvec2 : require
layout(local_size_x = 64) in;

 // These define pointer types.
layout(buffer_reference, std430, buffer_reference_align = 16) readonly buffer ReadVec4
{
    vec4 values[];
};

 layout(buffer_reference, std430, buffer_reference_align = 16) writeonly buffer WriteVec4
{
    vec4 values[];
};

 layout(buffer_reference, std430, buffer_reference_align = 4) readonly buffer UnalignedVec4
{
    vec4 value;
};

 layout(push_constant, std430) uniform Registers
{
     ReadVec4 src;
    WriteVec4 dst;
} registers;

Placing raw pointers in push constants avoids all indirection for getting to a buffer. If the driver allows it, the pointers can be placed directly in GPU registers before the shader begins executing.

Not all devices support 64-bit integers, but it is possible to cast uvec2 <-> pointer. Doing address computation like this is fine.

uvec2 uadd_64_32(uvec2 addr, uint offset)
{
    uint carry;
    addr.x = uaddCarry(addr.x, offset, carry);
    addr.y += carry;
    return addr;
}

void main()
{
    uint index = gl_GlobalInvocationID.x;
    registers.dst.values[index] = registers.src.values[index];
     uvec2 addr = uvec2(registers.src);
    addr = uadd_64_32(addr, 20 * index);

Cast a uvec2 to address and load a vec4 from it. This address is aligned to 4 bytes.

    registers.dst.values[index + 1024] = UnalignedVec4(addr).value;
}

Pointer or offsets?

Using raw pointers is not always the best idea. A natural use case you could consider for pointers is that you have tree structures or list structures in GPU memory. With pointers, you can jump around as much as you want, and even write new pointers to buffers. However, a pointer is 64-bit and a typical performance consideration is to use 32-bit offsets (or even 16-bit offsets) if possible. Using offsets is the way to go if you can guarantee that all buffers live inside a single VkBuffer. On the other hand, the pointer approach can access any VkBuffer at any time without having to use descriptors. Therein lies the key strength of BDA.

Extreme hackery: physical pointer as specialization constants

This is a life saver in certain situations where you are desperate to debug something without any available descriptor set.

A black magic hack is to place a BDA inside a specialization constant. This allows for accessing a pointer without using any descriptors. Do note that this breaks all forms of pipeline caching and is only suitable for debug code. Do not ship this kind of code. Perform this dark sorcery at your own risk:

#version 450
#extension GL_EXT_buffer_reference : require
#extension GL_EXT_buffer_reference_uvec2 : require
layout(local_size_x = 64) in;

layout(constant_id = 0) const uint DEBUG_ADDR_LO = 0;
layout(constant_id = 1) const uint DEBUG_ADDR_HI = 0;

layout(buffer_reference, std430, buffer_reference_align = 4) buffer DebugCounter
{
    uint value;
};

void main()
{
    DebugCounter counter = DebugCounter(uvec2(DEBUG_ADDR_LO, DEBUG_ADDR_HI));
    atomicAdd(counter.value, 1u);
}

Emitting SPIR-V with buffer_device_address

In SPIR-V, there are some things to note. BDA is an especially useful feature for layering other APIs due to its extreme flexibility in how we access memory. Therefore, generating BDA code yourself is a reasonable use case to assume as well.

Enables BDA in shaders.

_OpCapability PhysicalStorageBufferAddresses
OpExtension "SPV_KHR_physical_storage_buffer"_

The memory model is PhysicalStorageBuffer64 and not logical anymore.

_OpMemoryModel PhysicalStorageBuffer64 GLSL450_

The buffer reference types are declared basically just like SSBOs.

_OpDecorate %_runtimearr_v4float ArrayStride 16
OpMemberDecorate %ReadVec4 0 NonWritable
OpMemberDecorate %ReadVec4 0 Offset 0
OpDecorate %ReadVec4 Block
OpDecorate %_runtimearr_v4float_0 ArrayStride 16
OpMemberDecorate %WriteVec4 0 NonReadable
OpMemberDecorate %WriteVec4 0 Offset 0
OpDecorate %WriteVec4 Block
OpMemberDecorate %UnalignedVec4 0 NonWritable
OpMemberDecorate %UnalignedVec4 0 Offset 0
OpDecorate %UnalignedVec4 Block_

Declare a pointer to the blocks. PhysicalStorageBuffer is the storage class to use.

OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_WriteVec4 PhysicalStorageBuffer
%_ptr_PhysicalStorageBuffer_ReadVec4 = OpTypePointer PhysicalStorageBuffer %ReadVec4
%_ptr_PhysicalStorageBuffer_WriteVec4 = OpTypePointer PhysicalStorageBuffer %WriteVec4
%_ptr_PhysicalStorageBuffer_UnalignedVec4 = OpTypePointer PhysicalStorageBuffer %UnalignedVec4

Load a physical pointer from PushConstant.

_%55 = OpAccessChain %_ptr_PushConstant__ptr_PhysicalStorageBuffer_WriteVec4 %registers %int_1    
%56 = OpLoad %_ptr_PhysicalStorageBuffer_WriteVec4 %55_

Access chain into it.

_%66 = OpAccessChain %_ptr_PhysicalStorageBuffer_v4float %56 %int_0 %40_

Aligned must be specified when dereferencing physical pointers. Pointers can have any arbitrary address and must be explicitly aligned, so the compiler knows what to do.

OpStore %66 %65 Aligned 16

For pointers, SPIR-V can bitcast between integers and pointers seamlessly, for example:

%61 = OpLoad %_ptr_PhysicalStorageBuffer_ReadVec4 %60
%70 = OpBitcast %v2uint %61

// Do math on %70
%86 = OpBitcast %_ptr_PhysicalStorageBuffer_UnalignedVec4 %some_address

Conclusion

We have already explored two key Vulkan extension game changers through this blog and the previous one. The third and final part of this game changer blog series will explore ‘Timeline Semaphores’ and how developers can use this new extension to improve the development experience and enhance their games.

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

Popular Days

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...