Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.
HarmonyOS
Since version 6.0.0(20), the High-Performance GPU Sorting feature is supported.
The High Performance Sorting (HPS) feature of XEngine Kit provides the high-performance GPU sorting capability. Compared with other sorting capabilities, this capability relies on the hardware-software co-optimization of the Maleoon GPU.
You can check whether the relevant extension is supported as follows:
For Vulkan, use the extension query API HMS_XEG_EnumerateDeviceExtensionProperties. If the query result contains XEG_HPS_RADIX_SORT_EXTENSION_NAME, the extension is supported. Otherwise, the extension is not supported.
The following APIs are required for high-performance GPU sorting. For details about these APIs, please refer to API Reference.
| API | Description |
|---|---|
| VKAPI_ATTR VkResult VKAPI_CALL HMS_XEG_CreateHPS (VkDevice device, const XEG_HPSCreateInfo *pCreateInfo, XEG_HPS *pHps) | Creates an XEG_HPS object. |
| VKAPI_ATTR void VKAPI_CALL HMS_XEG_DestroyHPS (XEG_HPS hps) | Destroys an XEG_HPS object. |
| VKAPI_ATTR VkResult VKAPI_CALL HMS_XEG_CmdRadixSortHPS (VkCommandBuffer commandBuffer, XEG_HPS hps, const XEG_HPSRadixSortDescription *pDescription) | Records the HPS sorting command. Before using this API, you need to call HMS_XEG_EnumerateDeviceExtensionProperties to check whether the XEG_HPS_RADIX_SORT_EXTENSION_NAME extension is supported. |
This section uses Vulkan app rendering as an example to describe how to develop high-performance GPU sorting.
During HAP compilation, the native .so files depend on related libraries and header files of XEngine Kit in the NDK.
Header file reference
- #include <algorithm>
- #include <vector>
- #include <string>
- #include <xengine/xeg_vulkan_hps.h>
- #include <xengine/xeg_vulkan_extension.h>
- #include <xengine/xeg_extension_defs.h>
Adding library dependencies to CMakeLists.txt
Add the following code to CMakeLists.txt to add the dependency on the dynamic link library of XEngine Kit:
- find_library(
- # Set the name of the path variable.
- xengine-lib
- # Specify the name of the NDK library that you want CMake to locate.
- xengine
- )
- target_link_libraries(nativerender PUBLIC
- // Other library files
- // ...
- ${xengine-lib})
High-performance GPU sorting of XEngine Kit can be used independently. The related code is implemented at the native layer.
Before calling extension APIs of XEngine Kit, you need to use SysCap to check whether your target device supports the SystemCapability.Graphic.XEngine system capability.
Call HMS_XEG_EnumerateDeviceExtensionProperties to obtain the extensions supported by XEngine Kit. The high-performance GPU sorting APIs can be used only when the XEG_HPS_RADIX_SORT_EXTENSION_NAME extension is supported.
- VkPhysicalDevice physicalDevice;
- std::vector<std::string> supportedExtensions;
- uint32_t propertyCount;
- HMS_XEG_EnumerateDeviceExtensionProperties(physicalDevice, &propertyCount, nullptr);
- if (propertyCount > 0) {
- std::vector<XEG_ExtensionProperties> properties(propertyCount);
- if (HMS_XEG_EnumerateDeviceExtensionProperties(physicalDevice, &propertyCount, &properties.front()) ==
- VK_SUCCESS) {
- for (auto ext : properties) {
- supportedExtensions.push_back(ext.extensionName);
- }
- }
- }
- if (std::find(supportedExtensions.begin(), supportedExtensions.end(), XEG_HPS_RADIX_SORT_EXTENSION_NAME) ==
- supportedExtensions.end()) {
- exit(1);
- }
Prepare HPS resources.
- VkDevice device;
- VkCommandBuffer cmdBuffer;
- VkQueue queue;
- // Key to be sorted.
- VkBuffer keyBuffer;
- // Value corresponding to the key.
- VkBuffer indexBuffer;
- // Sorting amount.
- VkBuffer sortCount;
Declare the instance handle.
- XEG_HPS xegHPS { VK_NULL_HANDLE };
Call HMS_XEG_CreateHPS to instantiate the handle.
- // Construct the input descriptor.
- XEG_HPSRadixSort sorInfo{
- XEG_STRUCTURE_TYPE_HPS_RADIX_SORT,
- nullptr
- };
-
- XEG_HPSCreateInfo info {
- XEG_STRUCTURE_TYPE_HPS_CREATE_INFO,
- &sorInfo
- };
- // Instantiate the handle.
- HMS_XEG_CreateHPS(device, &info, &xegHPS);
Construct the sorting descriptor and call the HMS_XEG_CmdRadixSortHPS API to record the sorting command.
- VkCommandBufferBeginInfo cmdBufferBeginInfo {};
- cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
-
- // Record the sorting command.
- vkBeginCommandBuffer(cmdBuffer, &cmdBufferBeginInfo);
- XEG_HPSRadixSortDescription sortDescription{
- XEG_STRUCTURE_TYPE_HPS_RADIX_SORT_DESCRIPTION,
- nullptr,
- sortCount,
- keyBuffer,
- indexBuffer
- };
- HMS_XEG_CmdRadixSortHPS(cmdBuffer, xegHPS, &sortDescription);
- vkEndCommandBuffer(cmdBuffer);
Submit the sorting command.
- // Submit the command buffer.
- VkResult res;
- {
- VkSubmitInfo submitInfo{};
- submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
- submitInfo.waitSemaphoreCount = 0;
- submitInfo.signalSemaphoreCount = 0;
- submitInfo.pSignalSemaphores = nullptr;
- submitInfo.commandBufferCount = 1;
- submitInfo.pCommandBuffers = &cmdBuffer;
- submitInfo.pWaitSemaphores = nullptr;
- res = vkQueueSubmit(queue, 1, &submitInfo, nullptr);
- }
- // Wait until the operation is complete.
- vkDeviceWaitIdle(device);
Destroy the HPS object.
- if(xegHPS){
- HMS_XEG_DestroyHPS(xegHPS);
- }
Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
Quick start
Helps you find desired resources with ease.