Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62573f2d authored by John Reck's avatar John Reck Committed by Automerger Merge Worker
Browse files

Merge "Have GrContext hold a strong ref to VulkanManager" into udc-dev am:...

Merge "Have GrContext hold a strong ref to VulkanManager" into udc-dev am: 2a3fda26 am: 3259050c am: c9334d1f

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22958359



Change-Id: I61d1c2dc6030791909ed69bb7bc33cef5afa42d0
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 23a26c6d c9334d1f
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include "Layer.h"
#include "Properties.h"
#include "RenderThread.h"
#include "VulkanManager.h"
#include "pipeline/skia/ATraceMemoryDump.h"
#include "pipeline/skia/ShaderCache.h"
#include "pipeline/skia/SkiaMemoryTracer.h"
@@ -182,8 +183,14 @@ void CacheManager::dumpMemoryUsage(String8& log, const RenderState* renderState)
    }
    log.appendFormat("Contexts: %zu (stopped = %zu)\n", mCanvasContexts.size(), stoppedContexts);

    auto vkInstance = VulkanManager::peekInstance();
    if (!mGrContext) {
        if (!vkInstance) {
            log.appendFormat("No GPU context.\n");
        } else {
            log.appendFormat("No GrContext; however %d remaining Vulkan refs",
                             vkInstance->getStrongCount() - 1);
        }
        return;
    }
    std::vector<skiapipeline::ResourcePair> cpuResourceMap = {
+20 −6
Original line number Diff line number Diff line
@@ -107,11 +107,11 @@ GrVkGetProc VulkanManager::sSkiaGetProp = [](const char* proc_name, VkInstance i
#define GET_INST_PROC(F) m##F = (PFN_vk##F)vkGetInstanceProcAddr(mInstance, "vk" #F)
#define GET_DEV_PROC(F) m##F = (PFN_vk##F)vkGetDeviceProcAddr(mDevice, "vk" #F)

sp<VulkanManager> VulkanManager::getInstance() {
// cache a weakptr to the context to enable a second thread to share the same vulkan state
static wp<VulkanManager> sWeakInstance = nullptr;
static std::mutex sLock;

sp<VulkanManager> VulkanManager::getInstance() {
    std::lock_guard _lock{sLock};
    sp<VulkanManager> vulkanManager = sWeakInstance.promote();
    if (!vulkanManager.get()) {
@@ -122,6 +122,11 @@ sp<VulkanManager> VulkanManager::getInstance() {
    return vulkanManager;
}

sp<VulkanManager> VulkanManager::peekInstance() {
    std::lock_guard _lock{sLock};
    return sWeakInstance.promote();
}

VulkanManager::~VulkanManager() {
    if (mDevice != VK_NULL_HANDLE) {
        mDeviceWaitIdle(mDevice);
@@ -404,9 +409,13 @@ void VulkanManager::initialize() {
    }
}

sk_sp<GrDirectContext> VulkanManager::createContext(const GrContextOptions& options,
                                                    ContextType contextType) {
static void onGrContextReleased(void* context) {
    VulkanManager* manager = (VulkanManager*)context;
    manager->decStrong((void*)onGrContextReleased);
}

sk_sp<GrDirectContext> VulkanManager::createContext(GrContextOptions& options,
                                                    ContextType contextType) {
    GrVkBackendContext backendContext;
    backendContext.fInstance = mInstance;
    backendContext.fPhysicalDevice = mPhysicalDevice;
@@ -418,6 +427,11 @@ sk_sp<GrDirectContext> VulkanManager::createContext(const GrContextOptions& opti
    backendContext.fDeviceFeatures2 = &mPhysicalDeviceFeatures2;
    backendContext.fGetProc = sSkiaGetProp;

    LOG_ALWAYS_FATAL_IF(options.fContextDeleteProc != nullptr, "Conflicting fContextDeleteProcs!");
    this->incStrong((void*)onGrContextReleased);
    options.fContextDeleteContext = this;
    options.fContextDeleteProc = onGrContextReleased;

    return GrDirectContext::MakeVulkan(backendContext, options);
}

+2 −1
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ class RenderThread;
class VulkanManager final : public RefBase {
public:
    static sp<VulkanManager> getInstance();
    static sp<VulkanManager> peekInstance();

    // Sets up the vulkan context that is shared amonst all clients of the VulkanManager. This must
    // be call once before use of the VulkanManager. Multiple calls after the first will simiply
@@ -109,7 +110,7 @@ public:
    };

    // returns a Skia graphic context used to draw content on the specified thread
    sk_sp<GrDirectContext> createContext(const GrContextOptions& options,
    sk_sp<GrDirectContext> createContext(GrContextOptions& options,
                                         ContextType contextType = ContextType::kRenderThread);

    uint32_t getDriverVersion() const { return mDriverVersion; }