简介

为了使开发者更方便的使用GPU扩展能力,华为为开发者提供了一个简易的Demo,使用时,开发者需要:

您将建立什么

在这个Codelab中,你将使用已经创建好的Demo Project实现对华为GPU扩展能力的API调用,通过Demo Project你可以体验到:

您将会学到什么

硬件要求

软件要求

需要的知识点

Smart Cache for GLES

  1. 使用glGetstring查询是否支持Smart Cache,若存在GL_HUAWEI_smart_cache,表明GLES支持Smart Cache,若不存在,表明不支持Smart Cache。
    const char* extensions = (const char*) glGetString(GL_EXTENSIONS); if (strstr(extensions, "GL_HUAWEI_smart_cache")) { gSmartCache = true; }
  2. 定义Smart Cache标志位。
    #define GL_SMART_CACHE_TEXTURE 0x40000 #define GL_SMART_CACHE_FBO 0x80000
  3. 根据申请的内存类别,在申请内存时位或步骤2中的宏,以此来获得对应属性的内存。
    glTexImage2D(GL_TEXTURE_2D | GL_TEXTURE_SMART_CACHE_xxx, …) glTexStorage2D(GL_TEXTURE_2D | GL_TEXTURE_SMART_CACHE_xxx, …)

Smart Cache for Vulkan

  1. 使用vkEnumerateDeviceExtensionProperties函数查询上报的extension,如果存在VK_HUAWEI_smart_cache则说明支持该扩展。
    vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &extCount, &extensions.front())
  2. 在使用vkCreateDevice创建device时,将VK_HUAWEI_smart_cache加入扩展列表。
    supportedExtensions.push_back(ext.extensionName);
  3. 根据申请的内存类别,将memoryTypeIndex设置成3、4或5,对应表示申请内存的用途为framebuffer attachment、normal texture或texture。<
    //Memory type is FBO. if(smartCacheSupported) { memAllloc.memoryTypeIndex = 3; }

Pre-rotation

  1. 使用vkEnumerateDeviceExtensionProperties函数查询是否支持Pre-rotation。
    vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &extCount, &extensions.front())
  2. 在使用vkCreateDevice创建device时,将VK_ HUAWEI _prerotation加入扩展列表。VkDeviceCreateInfo.ppEnabledExtensionNames在原来的基础上增加一个新的扩展VK_HUAWEI _prerotation。
    supportedExtensions.push_back(ext.extensionName);

干得好,您已经成功完成了Codelab并学到了:

您可以阅读下面链接,了解更多相关的信息。

相关文档
本Codelab中所用Demo源码下载地址如下:

下载Source Code

Code copied