Hash :
e7418836
Author :
Date :
2023-08-16T14:25:52
Vulkan: Add context flushing as OOM fallback
* As a new fallback for out-of-memory errors, if an allocation results
in device OOM, the context is flushed and the allocation is retried.
* Functions related to buffer/image allocations now return a VkResult
value instead of angle::Result, which will be bubbled up to a higher
level for safer handling.
* The OOM is no longer handled at the level where the allocation
happens, but is moved up to the context.
* Added two functions to ContextVk for allocating memory for images and
buffer suballocations, which also include the fallback options.
* initBufferAllocation(): Uses BufferHelper::initSuballocation()
* initImageAllocation(): Uses ImageHelper::initMemory()
* Moved initNonZeroMemory() out of the following functions:
* BufferHelper::initSuballocation()
* Moved to ContextVk::initBufferAllocation().
* ImageHelper::initMemory()
* Moved to ContextVk::initImageAllocation().
* Also moved to new function:
ImageHelper::initMemoryAndNonZeroFillIfNeeded().
This function replaced the rest of initMemory() usages outside
initImageAllocation().
* New macros for memory allocation
* VK_RESULT_TRY()
* If the output of the command inside it is not VK_SUCCESS, it will
return with the error result from the command.
* VK_RESULT_CHECK()
* If the output of the command inside it is not VK_SUCCESS, it will
return with the input error.
* Added a test in which allocation would fail due to too much pending
garbage without the fix on some platforms. The test ends once there
has been a submission.
* New suite: UniformBufferMemoryTest
* Added a similar test for flushing texture-related pending garbage.
* New suite: Texture2DMemoryTestES3
Bug: b/280304441
Change-Id: I60248ce39eae80b5a8ffe4723d8a1c5641087f23
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4787949
Reviewed-by: Charlie Lao <cclao@google.com>
Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// vk_android_utils.cpp: Vulkan utilities for using the Android platform
#include "libANGLE/renderer/vulkan/android/vk_android_utils.h"
#include "common/android_util.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/vk_utils.h"
#if defined(ANGLE_PLATFORM_ANDROID)
# include "libANGLE/Display.h"
# include "libANGLE/renderer/vulkan/android/AHBFunctions.h"
# include "libANGLE/renderer/vulkan/android/DisplayVkAndroid.h"
#endif
namespace rx
{
namespace vk
{
angle::Result GetClientBufferMemoryRequirements(ContextVk *contextVk,
const AHardwareBuffer *hardwareBuffer,
VkMemoryRequirements &memRequirements)
{
#if defined(ANGLE_PLATFORM_ANDROID)
const AHBFunctions &ahbFunctions =
GetImplAs<DisplayVkAndroid>(contextVk->getRenderer()->getDisplay())->getAHBFunctions();
ASSERT(ahbFunctions.valid());
AHardwareBuffer_Desc aHardwareBufferDescription = {};
ahbFunctions.describe(hardwareBuffer, &aHardwareBufferDescription);
if (aHardwareBufferDescription.format != AHARDWAREBUFFER_FORMAT_BLOB)
{
ERR() << "Trying to import non-BLOB AHB as client buffer.";
return angle::Result::Stop;
}
// Get Android Buffer Properties
VkAndroidHardwareBufferPropertiesANDROID bufferProperties = {};
bufferProperties.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID;
bufferProperties.pNext = nullptr;
VkDevice device = contextVk->getRenderer()->getDevice();
ANGLE_VK_TRY(contextVk, vkGetAndroidHardwareBufferPropertiesANDROID(device, hardwareBuffer,
&bufferProperties));
memRequirements.size = bufferProperties.allocationSize;
memRequirements.alignment = 0;
memRequirements.memoryTypeBits = bufferProperties.memoryTypeBits;
return angle::Result::Continue;
#else
ANGLE_VK_UNREACHABLE(contextVk);
return angle::Result::Stop;
#endif
}
angle::Result InitAndroidExternalMemory(ContextVk *contextVk,
EGLClientBuffer clientBuffer,
VkMemoryPropertyFlags memoryProperties,
Buffer *buffer,
VkMemoryPropertyFlags *memoryPropertyFlagsOut,
uint32_t *memoryTypeIndexOut,
DeviceMemory *deviceMemoryOut,
VkDeviceSize *sizeOut)
{
#if defined(ANGLE_PLATFORM_ANDROID)
const AHBFunctions &functions =
GetImplAs<DisplayVkAndroid>(contextVk->getRenderer()->getDisplay())->getAHBFunctions();
ASSERT(functions.valid());
struct AHardwareBuffer *hardwareBuffer =
angle::android::ClientBufferToAHardwareBuffer(clientBuffer);
VkMemoryRequirements externalMemoryRequirements = {};
ANGLE_TRY(
GetClientBufferMemoryRequirements(contextVk, hardwareBuffer, externalMemoryRequirements));
// Import Vulkan DeviceMemory from Android Hardware Buffer.
VkImportAndroidHardwareBufferInfoANDROID importHardwareBufferInfo = {};
importHardwareBufferInfo.sType = VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID;
importHardwareBufferInfo.buffer = hardwareBuffer;
ANGLE_VK_TRY(contextVk, AllocateBufferMemoryWithRequirements(
contextVk, MemoryAllocationType::BufferExternal, memoryProperties,
externalMemoryRequirements, &importHardwareBufferInfo, buffer,
memoryPropertyFlagsOut, memoryTypeIndexOut, deviceMemoryOut));
*sizeOut = externalMemoryRequirements.size;
functions.acquire(hardwareBuffer);
return angle::Result::Continue;
#else
ANGLE_VK_UNREACHABLE(contextVk);
return angle::Result::Stop;
#endif
}
void ReleaseAndroidExternalMemory(RendererVk *rendererVk, EGLClientBuffer clientBuffer)
{
#if defined(ANGLE_PLATFORM_ANDROID)
const AHBFunctions &functions =
GetImplAs<DisplayVkAndroid>(rendererVk->getDisplay())->getAHBFunctions();
ASSERT(functions.valid());
struct AHardwareBuffer *hardwareBuffer =
angle::android::ClientBufferToAHardwareBuffer(clientBuffer);
functions.release(hardwareBuffer);
#endif
}
} // namespace vk
} // namespace rx