Hash :
7263989e
Author :
Date :
2025-02-06T13:20:14
Vulkan: Fix VUID-vkBindBufferMemory-buffer-01444 Some platforms issue a VVL error regarding memory allocation for an external buffer. It seems to be due to the fact that the memory is not allocated as a dedicated memory for the buffer, whereas the buffer requirements (as reported in vkGetBufferMemoryRequirements2()) show that it requires a dedicated memory. This causes an issue when binding the buffer to the memory. This change explicitly sets the dedicated memory information for the external buffer, so the memory is regarded as dedicated and be able to be bound to the buffer without errors. * Added VkMemoryDedicatedAllocateInfo when calling to allocate memory for the external buffer (InitAndroidExternalMemory()). * Appended this structure to the extra allocation info via pNext. * Unsuppressed VUID-vkBindBufferMemory-buffer-01444. Bug: angleproject:394598758 Change-Id: I0d952cea204e528c23859c74909dbbb0751d0b65 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6239029 Reviewed-by: Cody Northrop <cnorthrop@google.com> Reviewed-by: Roman Lavrov <romanl@google.com> Commit-Queue: Amirali Abdolrashidi <abdolrashidi@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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
//
// 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/vk_renderer.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
{
namespace
{
#if defined(ANGLE_PLATFORM_ANDROID)
DisplayVkAndroid *GetDisplayVkAndroid(Renderer *renderer)
{
DisplayVk *displayVk = static_cast<DisplayVk *>(renderer->getGlobalOps());
return static_cast<DisplayVkAndroid *>(displayVk);
}
#endif
} // anonymous namespace
angle::Result GetClientBufferMemoryRequirements(ErrorContext *context,
const AHardwareBuffer *hardwareBuffer,
VkMemoryRequirements &memRequirements)
{
#if defined(ANGLE_PLATFORM_ANDROID)
const AHBFunctions &ahbFunctions =
GetDisplayVkAndroid(context->getRenderer())->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 = context->getRenderer()->getDevice();
ANGLE_VK_TRY(context, vkGetAndroidHardwareBufferPropertiesANDROID(device, hardwareBuffer,
&bufferProperties));
memRequirements.size = bufferProperties.allocationSize;
memRequirements.alignment = 0;
memRequirements.memoryTypeBits = bufferProperties.memoryTypeBits;
return angle::Result::Continue;
#else
ANGLE_VK_UNREACHABLE(context);
return angle::Result::Stop;
#endif
}
angle::Result InitAndroidExternalMemory(ErrorContext *context,
EGLClientBuffer clientBuffer,
VkMemoryPropertyFlags memoryProperties,
Buffer *buffer,
VkMemoryPropertyFlags *memoryPropertyFlagsOut,
uint32_t *memoryTypeIndexOut,
DeviceMemory *deviceMemoryOut,
VkDeviceSize *sizeOut)
{
#if defined(ANGLE_PLATFORM_ANDROID)
const AHBFunctions &functions = GetDisplayVkAndroid(context->getRenderer())->getAHBFunctions();
ASSERT(functions.valid());
struct AHardwareBuffer *hardwareBuffer =
angle::android::ClientBufferToAHardwareBuffer(clientBuffer);
VkMemoryRequirements externalMemoryRequirements = {};
ANGLE_TRY(
GetClientBufferMemoryRequirements(context, 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;
// Configure dedicated memory allocation for the external buffer and append it to the AHB info.
VkMemoryDedicatedAllocateInfo dedicatedAllocateInfo = {};
dedicatedAllocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO;
dedicatedAllocateInfo.buffer = buffer->getHandle();
importHardwareBufferInfo.pNext = &dedicatedAllocateInfo;
ANGLE_VK_TRY(context, AllocateBufferMemoryWithRequirements(
context, MemoryAllocationType::BufferExternal, memoryProperties,
externalMemoryRequirements, &importHardwareBufferInfo, buffer,
memoryPropertyFlagsOut, memoryTypeIndexOut, deviceMemoryOut));
*sizeOut = externalMemoryRequirements.size;
functions.acquire(hardwareBuffer);
return angle::Result::Continue;
#else
ANGLE_VK_UNREACHABLE(context);
return angle::Result::Stop;
#endif
}
void ReleaseAndroidExternalMemory(Renderer *renderer, EGLClientBuffer clientBuffer)
{
#if defined(ANGLE_PLATFORM_ANDROID)
const AHBFunctions &functions = GetDisplayVkAndroid(renderer)->getAHBFunctions();
ASSERT(functions.valid());
struct AHardwareBuffer *hardwareBuffer =
angle::android::ClientBufferToAHardwareBuffer(clientBuffer);
functions.release(hardwareBuffer);
#endif
}
} // namespace vk
} // namespace rx