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 Art Store is today welcoming the arrival of 12 of Jean-Michel Basquiat’s most striking works, in partnership with Artestar and The Estate of Jean-Michel Basquiat. This is the first time the iconic artist’s work has been officially released for digital display, and joins works from leading museums, collections and artists around the world available from Samsung Art Store.
       
      ▲ Pez Dispenser (1984), one of Basquiat’s most recognizable artworks, displayed on The Frame
       
      Samsung Art Store is a subscription service that enables owners of The Frame to continuously transform any space with over 2,500 pieces of digital art, including works from the most renowned artists, museums and industry tastemakers.
       
      Jean-Michel Basquiat was a beacon of innovation and social commentary, with his work not only featured in galleries and museums worldwide, but also igniting a powerful conversation on cultural complexities. Artestar and The Estate of Jean-Michel Basquiat continue to honor his prolific legacy by showcasing his art and its underlying messages, striving to engage with audiences worldwide to ensure his visionary work remains accessible and influential.
       
      “The ability to bring Basquiat’s iconic artwork directly into your home with Samsung Art Store is an exciting opportunity for global audiences to experience his work in a new and powerful way,” said David Stark, Founder and President of Artestar, the international brand licensing and consulting agency representing the Estate of Jean-Michel Basquiat. “Basquiat’s work continues to spark important conversations and encourages us to look at our worlds differently. This partnership on The Frame’s digital canvas allows his pieces to be experienced in anyone’s home, helping to share his work and honor his legacy.”
       
      The new collection features unique pieces from throughout Basquiat’s career. Among the works available to Art Store subscribers are Bird on Money (1982), a stunning tribute to Charlie Parker. Also included is Boy and Dog in a Johnnypump (1982), King Zulu (1986), which offers a large color block of blue in his more refined late style; and a dual portrait with Andy Warhol, Dos Cabezas (1982), which like many of his works pulls inspiration from his Puerto Rican heritage.
       
      This body of work was curated specifically for Samsung Art Store, adapted for a 16×9 format and were chosen based on their ability to be reproduced accurately, in keeping with Basquiat’s legacy.
       
      Jean-Michel Basquiat emerged as one of the most significant artists of the 20th century, his work rich with themes of heritage, identity and the human experience. Beginning his career as a graffiti artist in New York City under the pseudonym SAMO, Basquiat later transitioned to canvas to express his unique blend of symbolic, abstract and figurative styles. His art, characterized by intense colors, dynamic figures and cryptic texts, delves into topics such as societal power structures, racial inequality and the quest for identity. Basquiat’s impact was monumental, leaving a lasting legacy in the art world that explores social issues through his interest in pop culture and his own deeply refined neo-expressionist style.
       
      ▲ Mitchell Crew (1983), shown on The Frame via Samsung Art Store
       
      Since its founding in 2019, Samsung Art Store has been committed to bringing art from the world’s most renowned museums and important artists into homes across the world. The addition of the Basquiat collection significantly broadens the range of contemporary American artists whose works are now globally accessible for display.
       
      “Jean-Michel Basquiat’s work stands completely alone in the history of contemporary art, which is why it was essential that some of his most brilliant pieces were represented in Samsung Art Store,” said Daria Greene, Global Curator at Samsung Art Store. “Basquiat’s preeminent place in our culture and unique message to the world is as necessary today as it ever was, and we’re so proud to help share that message and expand on his legacy.”
       
      Basquiat’s work has been celebrated with numerous retrospectives and is held in prestigious collections globally, including those of the Museum of Modern Art, New York; The Metropolitan Museum of Art, New York; The Whitney Museum of American Art, New York; The Menil Collection, Houston; and the Museum of Contemporary Art, Los Angeles. His work continues to inspire new generations, embodying a bridge between street art and high art and challenging societal norms.
       
       
      Explore Thousands of Works From Artists and Institutions Around the World
      Alongside these new Basquiat pieces, viewers can explore thousands of additional artworks from masters such as Dalí and Van Gogh in Samsung Art Store,1 available for instant display on The Frame. Additionally, in Samsung’s Art Store you will find work from major global institutions including The Metropolitan Museum of Art, Tate Collection, the National Palace Museum in Taiwan, the Prado Museum in Madrid and the Belvedere Museum in Vienna.
       
      Samsung also recently refreshed The Frame line-up, with the new series now available for purchase. The 2024 line-up offers Pantone Art Validated Colors, so that every piece of art appears even more realistic, plus new Samsung Art Store – Streams, a complimentary set of regularly curated artworks sampled from Samsung Art Store. The Frame is even more energy efficient when in Art Mode, automatically adjusting the refresh rate so you can enjoy high-quality art, while conserving energy.2
       
       
      ABOUT JEAN-MICHEL BASQUIAT
      Jean-Michel Basquiat is one of the best-known artists of his generation and is widely considered one of the most important artists of the 20th century. His career in art spanned the last 1970s through the 1980s until his death in 1988 at the age of 27. Basquiat’s works are edgy and raw, and through a bold sense of color and composition, he maintains a fine balance between seemingly contradictory forces such as control and spontaneity, menace and wit, urban imagery, and primitivism.
       
      ABOUT ARTESTAR
      This partnership was done in collaboration with Artestar, a global licensing agency and creative consultancy representing high-profile artists, photographers, designers and creatives. Artestar connects brands with artists — curating and managing some of the world’s most recognizable creative collaborations. Learn more at artestar.com.
       
       
      1 A single user subscription for Art Store costs $4.99/month or $49.90/year.
      2 This feature applies to the 55’’ display and above.
      View the full article
    • By Samsung Newsroom
      Samsung Electronics today announced that it has been named the number one signage manufacturer for the fifteenth consecutive year by market research firm Omdia, once again demonstrating its leadership in the global digital signage market.1
       
      According to Omdia, in 2023 Samsung not only led the global signage market with a 33% market share, but also sold over 2 million units — a record-breaking number for the company.2
       
      “Achieving first place in the global display signage market for 15 consecutive years reflects our commitment to innovation and our ability to adapt to evolving market conditions and the needs of our customers,” said Hoon Chung, Executive Vice President of Visual Display Business at Samsung Electronics. “We will continue to provide the highest value to our customers by offering specialized devices, solutions and services that address their diverse needs.”
       
      Samsung Electronics is regularly introducing differentiated signage products that meet various business environment needs.
       
      The Wall, the world’s first modular display with micro LED technology. Thanks to its modular format, The Wall allows customers to adjust the sign’s size, ratio and shape based on preference and use case. Smart Signage, which provides an excellent sense of immersion with its ultra-slim profile and uniform bezel design. Outdoor Signage tailored for sports, landmark markets, and electric vehicle charging stations. The screens in the Outdoor Signage portfolio are designed for clear visibility in any weather environment. Samsung Interactive Display, an e-board optimized for the education market that puts educational tools at the fingertips of educators and students.  
      The expansion of The Wall lineup is a clear indication of Samsung’s innovations and leading technology. Products like The Wall All-in-One and The Wall for Virtual Production were chosen by customers for their exceptional convenience and unique use cases, while The Wall has been selected as the display of choice for luxury hotels like Atlantis The Royal in Dubai and Hilton Waikiki Beach in Hawaii.
       
      Samsung’s leadership in the digital signage industry can be attributed to the company’s commitment to product and service innovation. For example, the introduction of the world’s first transparent Micro LED display in January was noted by industry experts as the next generation of commercial display, earning accolades such as “Most Mind-Blowing LED” and “Best Transparent Display” from the North American AV news outlet, rAVe.
       

       
      The recent introduction of the Samsung Visual eXperience Transformation (VXT) platform further demonstrates Samsung’s commitment to display innovation. This cloud-native platform combines content and remote signage operations on a single, secure platform, offering services and solutions that go beyond just hardware while ensuring seamless operation and management for users.
       
      Looking ahead, the global display signage market is poised for rapid growth, with an expected annual increase of 8% leading to a projected market size of $24.6 billion by 2027, up from $14 billion in 2020.3
       
       
      1 Omdia Q4 2023 Public Display Report; Based on sales volume. Note: consumer TVs are excluded.
      2 Omdia Q4 2023 Public Display Report; Based on sales volume. Note: consumer TVs are excluded.
      3 According to the combined LCD and LED signage sales revenue. Omdia Q4 2023 Public Displays Market Tracker (excluding Consumer TV), Omdia Q4 LED Video Displays Market Tracker.
      View the full article
    • By Samsung Newsroom
      Samsung Electronics cemented its position as the global leader of the commercial display market, defending marking the largest global share for 15 consecutive years.1
       
      Having entered the commercial display market with a full B2B signage in 2008, Samsung continues to make history of digital signage with consistent technological innovation, differentiated solutions, and market leadership.
       
      Samsung started by achieving first place in global market share of digital signage in 2009. Then in 2012, Samsung opened the LCD renaissance by introducing two transparent LCD models. In 2017, the world’s first cinema LED, Onyx, was unveiled, presenting a new standard for theater screens with unbelievable picture quality and infinite contrast ratio.
       
      Over a decade and a half of “firsts” has led to myriad breakthroughs in digital signage. The world’s first modular display “The Wall,” introduced in 2018, has freely adjustable screen size and shape, expanding the scope of digital signage to various spaces, like art museums and department stores.
       
      As demand for immersive content increased, Samsung created a new version of “The Wall” exclusively for virtual production studios in 2023. With ultimate picture quality, it overcomes the challenges of physical on-site sets and leads to a reduction in production time and cost. The Wall for Virtual Production continues to change the landscape of the content production with a top-tier customizable solution.
       
      Here’s a look at the footsteps of Samsung Signage, which has been solidifying its #1 position globally for 15 consecutive years2 with innovative display technology.
       

       
       
      1, 2 Omdia Q4 2023 Public Display Report; Based on sales volume. Note: consumer TVs are excluded.
      View the full article
    • By Samsung Newsroom
      Samsung Electronics has held its ground as the leader in the global soundbar market for ten consecutive years, from 2014 through 2023, according to the annual report from FutureSource Consulting. The latest data, released on February 28, highlights Samsung’s continuous market leadership, with a 20.3% market share and an 18.8% contribution to the industry’s sales volume in 2023.
       

       
      Samsung has continuously raised the bar for home entertainment systems over the years, earning its soundbars a reputation for superior sound quality and groundbreaking innovation. Signature features such as Q-Symphony and SpaceFit Sound have revolutionized the listening experience, offering users a deeply immersive soundscape that is finely tuned to their listening environments.
       
      This standard of excellence has been recognized by industry experts and reviewers, with T3 awarding the HW-Q990C “Best Soundbar” title for its immersive audio and “exceptional object-based sonics,” and HomeTheaterReview giving the soundbar an “Editor’s Choice” distinction and commenting: “It sounds excellent, regardless of what type of content you send its way.”
       
      This year, Samsung continues to push the boundaries with its soundbar lineup, introducing enhanced AI audio features and connectivity options to captivate consumers and home theater enthusiasts alike.
       
      ▲ Samsung Electronics’ 2024 flagship Q-series soundbar HW-Q990D further pushes the boundaries of immersive home audio experience
       
      The flagship Q-series soundbar, HW-Q990D, offers impressive 11.1.4-channel surround sound and an upgraded Q-Symphony feature. Powered by AI, the device analyzes and synchronizes voice channels for clear dialogues and immersive soundscape across all speakers. Paired with SpaceFit Sound Pro for customized audio calibration, the soundbar also ensures an immersive experience in any space, while HDMI 2.1 and 4K/120Hz passthrough provides connectivity options that meets the demands of modern home entertainment systems.
       
      “We are thrilled to once again be acknowledged as the market leader in soundbars, a milestone that reflects the positive feedback from our customers over the years,” said Cheolgi Kim, EVP of Visual Display Business at Samsung Electronics. “Building on this success, we will continue to push the boundaries of home entertainment with superior sound quality and advanced connectivity features, leveraging AI-based sound technology to strengthen the consumer experience and Samsung’s position in the global market.”
       
      For more information, visit https://www.samsung.com.
      View the full article





×
×
  • Create New...