summaryrefslogtreecommitdiff
path: root/libs/hwui/renderthread/VulkanManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/renderthread/VulkanManager.cpp')
-rw-r--r--libs/hwui/renderthread/VulkanManager.cpp68
1 files changed, 38 insertions, 30 deletions
diff --git a/libs/hwui/renderthread/VulkanManager.cpp b/libs/hwui/renderthread/VulkanManager.cpp
index 5173f638068d..35abc57fbe57 100644
--- a/libs/hwui/renderthread/VulkanManager.cpp
+++ b/libs/hwui/renderthread/VulkanManager.cpp
@@ -17,7 +17,8 @@
#include "VulkanManager.h"
#include <android/sync.h>
-#include <gui/Surface.h>
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
#include "Properties.h"
#include "RenderThread.h"
@@ -137,20 +138,14 @@ void VulkanManager::setupDevice(GrVkExtensions& grExtensions, VkPhysicalDeviceFe
err = mCreateInstance(&instance_create, nullptr, &mInstance);
LOG_ALWAYS_FATAL_IF(err < 0);
+ GET_INST_PROC(CreateDevice);
GET_INST_PROC(DestroyInstance);
+ GET_INST_PROC(EnumerateDeviceExtensionProperties);
GET_INST_PROC(EnumeratePhysicalDevices);
- GET_INST_PROC(GetPhysicalDeviceProperties);
- GET_INST_PROC(GetPhysicalDeviceQueueFamilyProperties);
GET_INST_PROC(GetPhysicalDeviceFeatures2);
GET_INST_PROC(GetPhysicalDeviceImageFormatProperties2);
- GET_INST_PROC(CreateDevice);
- GET_INST_PROC(EnumerateDeviceExtensionProperties);
- GET_INST_PROC(CreateAndroidSurfaceKHR);
- GET_INST_PROC(DestroySurfaceKHR);
- GET_INST_PROC(GetPhysicalDeviceSurfaceSupportKHR);
- GET_INST_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR);
- GET_INST_PROC(GetPhysicalDeviceSurfaceFormatsKHR);
- GET_INST_PROC(GetPhysicalDeviceSurfacePresentModesKHR);
+ GET_INST_PROC(GetPhysicalDeviceProperties);
+ GET_INST_PROC(GetPhysicalDeviceQueueFamilyProperties);
uint32_t gpuCount;
LOG_ALWAYS_FATAL_IF(mEnumeratePhysicalDevices(mInstance, &gpuCount, nullptr));
@@ -317,29 +312,27 @@ void VulkanManager::setupDevice(GrVkExtensions& grExtensions, VkPhysicalDeviceFe
LOG_ALWAYS_FATAL_IF(mCreateDevice(mPhysicalDevice, &deviceInfo, nullptr, &mDevice));
- GET_DEV_PROC(GetDeviceQueue);
- GET_DEV_PROC(DeviceWaitIdle);
- GET_DEV_PROC(DestroyDevice);
- GET_DEV_PROC(CreateCommandPool);
- GET_DEV_PROC(DestroyCommandPool);
GET_DEV_PROC(AllocateCommandBuffers);
- GET_DEV_PROC(FreeCommandBuffers);
- GET_DEV_PROC(ResetCommandBuffer);
GET_DEV_PROC(BeginCommandBuffer);
- GET_DEV_PROC(EndCommandBuffer);
GET_DEV_PROC(CmdPipelineBarrier);
- GET_DEV_PROC(GetDeviceQueue);
- GET_DEV_PROC(QueueSubmit);
- GET_DEV_PROC(QueueWaitIdle);
- GET_DEV_PROC(DeviceWaitIdle);
+ GET_DEV_PROC(CreateCommandPool);
+ GET_DEV_PROC(CreateFence);
GET_DEV_PROC(CreateSemaphore);
+ GET_DEV_PROC(DestroyCommandPool);
+ GET_DEV_PROC(DestroyDevice);
+ GET_DEV_PROC(DestroyFence);
GET_DEV_PROC(DestroySemaphore);
- GET_DEV_PROC(ImportSemaphoreFdKHR);
+ GET_DEV_PROC(DeviceWaitIdle);
+ GET_DEV_PROC(EndCommandBuffer);
+ GET_DEV_PROC(FreeCommandBuffers);
+ GET_DEV_PROC(GetDeviceQueue);
GET_DEV_PROC(GetSemaphoreFdKHR);
- GET_DEV_PROC(CreateFence);
- GET_DEV_PROC(DestroyFence);
- GET_DEV_PROC(WaitForFences);
+ GET_DEV_PROC(ImportSemaphoreFdKHR);
+ GET_DEV_PROC(QueueSubmit);
+ GET_DEV_PROC(QueueWaitIdle);
+ GET_DEV_PROC(ResetCommandBuffer);
GET_DEV_PROC(ResetFences);
+ GET_DEV_PROC(WaitForFences);
}
void VulkanManager::initialize() {
@@ -480,6 +473,13 @@ struct DestroySemaphoreInfo {
PFN_vkDestroySemaphore mDestroyFunction;
VkDevice mDevice;
VkSemaphore mSemaphore;
+ // We need to make sure we don't delete the VkSemaphore until it is done being used by both Skia
+ // (including by the GPU) and inside the VulkanManager. So we always start with two refs, one
+ // owned by Skia and one owned by the VulkanManager. The refs are decremented each time
+ // destroy_semaphore is called with this object. Skia will call destroy_semaphore once it is
+ // done with the semaphore and the GPU has finished work on the semaphore. The VulkanManager
+ // calls destroy_semaphore after sending the semaphore to Skia and exporting it if need be.
+ int mRefs = 2;
DestroySemaphoreInfo(PFN_vkDestroySemaphore destroyFunction, VkDevice device,
VkSemaphore semaphore)
@@ -488,8 +488,11 @@ struct DestroySemaphoreInfo {
static void destroy_semaphore(void* context) {
DestroySemaphoreInfo* info = reinterpret_cast<DestroySemaphoreInfo*>(context);
- info->mDestroyFunction(info->mDevice, info->mSemaphore, nullptr);
- delete info;
+ --info->mRefs;
+ if (!info->mRefs) {
+ info->mDestroyFunction(info->mDevice, info->mSemaphore, nullptr);
+ delete info;
+ }
}
void VulkanManager::swapBuffers(VulkanSurface* surface, const SkRect& dirtyRect) {
@@ -540,6 +543,7 @@ void VulkanManager::swapBuffers(VulkanSurface* surface, const SkRect& dirtyRect)
ALOGE("VulkanManager::swapBuffers(): Semaphore submission failed");
mQueueWaitIdle(mGraphicsQueue);
}
+ destroy_semaphore(destroyInfo);
surface->presentCurrentBuffer(dirtyRect, fenceFd);
}
@@ -642,13 +646,16 @@ status_t VulkanManager::createReleaseFence(sp<Fence>& nativeFence, GrContext* gr
DestroySemaphoreInfo* destroyInfo = new DestroySemaphoreInfo(mDestroySemaphore, mDevice,
semaphore);
+ // Even if Skia fails to submit the semaphore, it will still call the destroy_semaphore callback
+ // which will remove its ref to the semaphore. The VulkanManager must still release its ref,
+ // when it is done with the semaphore.
GrSemaphoresSubmitted submitted =
grContext->flush(kNone_GrFlushFlags, 1, &backendSemaphore,
destroy_semaphore, destroyInfo);
if (submitted == GrSemaphoresSubmitted::kNo) {
ALOGE("VulkanManager::createReleaseFence: Failed to submit semaphore");
- mDestroySemaphore(mDevice, semaphore, nullptr);
+ destroy_semaphore(destroyInfo);
return INVALID_OPERATION;
}
@@ -661,6 +668,7 @@ status_t VulkanManager::createReleaseFence(sp<Fence>& nativeFence, GrContext* gr
int fenceFd = 0;
err = mGetSemaphoreFdKHR(mDevice, &getFdInfo, &fenceFd);
+ destroy_semaphore(destroyInfo);
if (VK_SUCCESS != err) {
ALOGE("VulkanManager::createReleaseFence: Failed to get semaphore Fd");
return INVALID_OPERATION;