Hash :
48e40ef6
Author :
Date :
2023-01-06T13:35:21
Add per-heap memory allocation trackers * For each member of MemoryAllocationType, we now have a per-heap counter to keep track of the allocation size in each available heap. * mActivePerHeapMemoryAllocationsSize * mActivePerHeapMemoryAllocationsCount (debug mode only) * Added the memory type index to onMemoryAlloc() and onMemoryDealloc() as an input. It can then be used to determine the used memory heap index for that allocation using the memory properties defined in the renderer. * checkForCurrentMemoryAllocations() will now log the heap index of the current memory allocations in debug mode and during an OOM crash. * logPendingMemoryAllocation() will now log the heap index of the pending allocation during an OOM crash. * Renamed constexpr values used for tracking for more consistency. * kTrackMemoryAllocation -> kTrackMemoryAllocationSizes * kDebugMemoryAllocationLogs -> kTrackMemoryAllocationDebug Bug: b/262029018 Change-Id: I178a3556b3107edc0c72c6b23ea2f2d6b12da947 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4149431 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Charlie Lao <cclao@google.com> Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com> Reviewed-by: Ivan Neulander <ineula@google.com>
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
//
// 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)
ASSERT(GetImplAs<DisplayVkAndroid>(contextVk->getRenderer()->getDisplay())
->getAHBFunctions()
.valid());
// Get Android Buffer Properties
VkAndroidHardwareBufferFormatPropertiesANDROID bufferFormatProperties = {};
bufferFormatProperties.sType =
VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_FORMAT_PROPERTIES_ANDROID;
VkAndroidHardwareBufferPropertiesANDROID bufferProperties = {};
bufferProperties.sType = VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID;
bufferProperties.pNext = &bufferFormatProperties;
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_TRY(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