Overview
A simple demo is provided to make HUAWEI GPU Extensions more accessible to developers. You need to:
- Register as a developer in AppGallery Connect, create an app on the developer management platform, configure app information, and download the GPU Extensions demo.
- Use the GPU Extensions demo and debug according to GPU Extensions Development Guide.
What You Will Create
In this codelab, you will use the demo project to call GPU Extensionss APIs. Through the demo project, you will:
- Witness memory access acceleration brought by moving the memory to Smart Cache.
- Witness the benefits of Vulkan pre-rotation.
What You Will Learn
- Query the supported extensions.
- Define the flag bit of Smart Cache.
- Allocate memory in Smart Cache for textures and the frame buffer objects (FBOs).
- Apply the pre-rotation function to a Vulkan app.
Hardware Requirements
- A computer (desktop or laptop)
- Huawei P40 series or later smartphones powered by Kirin 990 or later (with USB connection support)
Software Requirements
- NDK
- Android Studio 3.5 or later
- SDK Platform 26 or later
Required Knowledge
- Android basics
- Android multithreading
Smart Cache for GLES
- Check if Smart Cache is supported by calling glGetstring. If GL_HUAWEI_smart_cache is returned, GLES supports Smart Cache. Otherwise, Smart Cache is not supported.
const char* extensions = (const char*) glGetString(GL_EXTENSIONS);
if (strstr(extensions, "GL_HUAWEI_smart_cache")) {
gSmartCache = true;
}
- Define the flag bit of Smart Cache.
#define GL_SMART_CACHE_TEXTURE 0x40000
#define GL_SMART_CACHE_FBO 0x80000
- Bit-wise OR the macros in step 2 based on the memory type to obtain memory for the corresponding attribute.
glTexImage2D(GL_TEXTURE_2D | GL_TEXTURE_SMART_CACHE_xxx, …)
glTexStorage2D(GL_TEXTURE_2D | GL_TEXTURE_SMART_CACHE_xxx, …)
Smart Cache for Vulkan
- Call the vkEnumerateDeviceExtensionProperties function to query the extensions provided by the platform. If VK_HUAWEI_smart_cache is among the returns, Vulkan-based Smart Cache is supported.
vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &extCount, &extensions.front())
- Add VK_HUAWEI_smart_cache to the extension list when you create a device using vkCreateDevice.
supportedExtensions.push_back(ext.extensionName);
- Set memoryTypeIndex to 3, 4, or 5 based on the memory type. The three values indicate corresponding purposes of memory allocation: frame buffer attachment, normal textures, and textures.
//Memory type is FBO.
if(smartCacheSupported) {
memAllloc.memoryTypeIndex = 3;
}
Pre-rotation
- Call the vkEnumerateDeviceExtensionProperties function to check if pre-rotation is supported.
vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &extCount, &extensions.front())
- Add VK_ HUAWEI _prerotation to the extension list when you create a device using vkCreateDevice. Add the extension name VK_HUAWEI _prerotation to VkDeviceCreateInfo.ppEnabledExtensionNames.
supportedExtensions.push_back(ext.extensionName);
Well done. You have successfully completed this codelab and learned how to:
- Query the supported extensions.
- Define the flag bit of Smart Cache.
- Allocate memory in Smart Cache for textures and the frame buffer objects (FBOs).
- Apply the pre-rotation function to a Vulkan app.
For more information, please click the following link:
Related documents
Download the demo source code used in this codelab from the following address:
Download source code