gfxstream: guest: vulkan: use connection manager

This adds the GfxStreamVulkanConnection, and makes
libgfxstream_vulkan.so use it.  All dependencies
to HostConnection are removed.

For Android builds, dependencies to renderControl
and libOpenGlCodecCommon remain.  In the future,
these will be isolated to Goldfish-based system
images.

Reviewed-by: Aaron Ruby <aruby@blackberry.com>
Acked-by: Yonggang Luo <luoyonggang@gmail.com>
Acked-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27246>
This commit is contained in:
Gurchetan Singh
2024-08-28 14:34:22 -07:00
committed by Marge Bot
parent de7095ba5b
commit 31ceda8bdc
7 changed files with 109 additions and 36 deletions

View File

@@ -350,7 +350,6 @@ class IOStream;
functableImplInclude = """ functableImplInclude = """
#include "VkEncoder.h" #include "VkEncoder.h"
#include "../OpenglSystemCommon/HostConnection.h"
#include "ResourceTracker.h" #include "ResourceTracker.h"
#include "gfxstream_vk_entrypoints.h" #include "gfxstream_vk_entrypoints.h"
#include "gfxstream_vk_private.h" #include "gfxstream_vk_private.h"

View File

@@ -16,7 +16,9 @@
#include <string.h> #include <string.h>
#include "../vulkan_enc/vk_util.h" #include "../vulkan_enc/vk_util.h"
#include "HostConnection.h" #include "GfxStreamConnectionManager.h"
#include "GfxStreamRenderControl.h"
#include "GfxStreamVulkanConnection.h"
#include "ResourceTracker.h" #include "ResourceTracker.h"
#include "VkEncoder.h" #include "VkEncoder.h"
#include "gfxstream_vk_entrypoints.h" #include "gfxstream_vk_entrypoints.h"
@@ -27,16 +29,48 @@
#include "vk_instance.h" #include "vk_instance.h"
#include "vk_sync_dummy.h" #include "vk_sync_dummy.h"
uint32_t gSeqno = 0;
uint32_t gNoRenderControlEnc = 0;
static gfxstream::vk::VkEncoder* getVulkanEncoder(GfxStreamConnectionManager* mgr) {
if (!gNoRenderControlEnc) {
int32_t ret = renderControlInit(mgr, nullptr);
if (ret) {
mesa_loge("Failed to initialize renderControl when getting VK encoder");
return nullptr;
}
}
gfxstream::vk::VkEncoder* vkEncoder =
(gfxstream::vk::VkEncoder*)mgr->getEncoder(GFXSTREAM_CONNECTION_VULKAN);
if (vkEncoder == nullptr) {
auto stream = mgr->getStream();
int32_t ret = mgr->addConnection(GFXSTREAM_CONNECTION_VULKAN,
std::make_unique<GfxStreamVulkanConnection>(stream));
if (ret) {
return nullptr;
}
vkEncoder = (gfxstream::vk::VkEncoder*)mgr->getEncoder(GFXSTREAM_CONNECTION_VULKAN);
}
return vkEncoder;
}
static GfxStreamConnectionManager* getConnectionManager(void) {
auto transport = renderControlGetTransport();
return GfxStreamConnectionManager::getThreadLocalInstance(transport, kCapsetGfxStreamVulkan);
}
#define VK_HOST_CONNECTION(ret) \ #define VK_HOST_CONNECTION(ret) \
HostConnection* hostCon = HostConnection::getOrCreate(kCapsetGfxStreamVulkan); \ GfxStreamConnectionManager* mgr = getConnectionManager(); \
gfxstream::vk::VkEncoder* vkEnc = hostCon->vkEncoder(); \ gfxstream::vk::VkEncoder* vkEnc = getVulkanEncoder(mgr); \
if (!vkEnc) { \ if (!vkEnc) { \
mesa_loge("vulkan: Failed to get Vulkan encoder\n"); \ mesa_loge("vulkan: Failed to get Vulkan encoder\n"); \
return ret; \ return ret; \
} }
uint32_t gSeqno = 0;
namespace { namespace {
static bool instance_extension_table_initialized = false; static bool instance_extension_table_initialized = false;
@@ -58,43 +92,33 @@ static const char* const kMesaOnlyDeviceExtensions[] = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME, VK_KHR_SWAPCHAIN_EXTENSION_NAME,
}; };
static HostConnection* getConnection(void) {
auto hostCon = HostConnection::getOrCreate(kCapsetGfxStreamVulkan);
return hostCon;
}
static gfxstream::vk::VkEncoder* getVkEncoder(HostConnection* con) { return con->vkEncoder(); }
static VkResult SetupInstanceForProcess(void) { static VkResult SetupInstanceForProcess(void) {
uint32_t noRenderControlEnc = 0; auto mgr = getConnectionManager();
HostConnection* hostCon = getConnection(); if (!mgr) {
if (!hostCon) {
mesa_loge("vulkan: Failed to get host connection\n"); mesa_loge("vulkan: Failed to get host connection\n");
return VK_ERROR_DEVICE_LOST; return VK_ERROR_DEVICE_LOST;
} }
gfxstream::vk::ResourceTracker::get()->setupCaps(noRenderControlEnc); gfxstream::vk::ResourceTracker::get()->setupCaps(gNoRenderControlEnc);
gfxstream::vk::ResourceTracker::get()->setupPlatformHelpers(); gfxstream::vk::ResourceTracker::get()->setupPlatformHelpers();
// Legacy goldfish path: could be deleted once goldfish not used guest-side. // Legacy goldfish path: could be deleted once goldfish not used guest-side.
if (!noRenderControlEnc) { if (!gNoRenderControlEnc) {
// Implicitly sets up sequence number struct GfxStreamVkFeatureInfo features = {};
ExtendedRCEncoderContext* rcEnc = hostCon->rcEncoder(); int32_t ret = renderControlInit(mgr, &features);
if (!rcEnc) { if (ret) {
mesa_loge("vulkan: Failed to get renderControl encoder context\n"); mesa_loge("Failed to initialize renderControl ");
return VK_ERROR_DEVICE_LOST; return VK_ERROR_DEVICE_LOST;
} }
struct GfxStreamVkFeatureInfo features = {};
hostCon->setVulkanFeatureInfo(&features);
gfxstream::vk::ResourceTracker::get()->setupFeatures(&features); gfxstream::vk::ResourceTracker::get()->setupFeatures(&features);
} }
gfxstream::vk::ResourceTracker::get()->setThreadingCallbacks({ gfxstream::vk::ResourceTracker::get()->setThreadingCallbacks({
.hostConnectionGetFunc = getConnection, .hostConnectionGetFunc = getConnectionManager,
.vkEncoderGetFunc = getVkEncoder, .vkEncoderGetFunc = getVulkanEncoder,
}); });
gfxstream::vk::ResourceTracker::get()->setSeqnoPtr(&gSeqno); gfxstream::vk::ResourceTracker::get()->setSeqnoPtr(&gSeqno);
gfxstream::vk::VkEncoder* vkEnc = getVkEncoder(hostCon); gfxstream::vk::VkEncoder* vkEnc = getVulkanEncoder(mgr);
if (!vkEnc) { if (!vkEnc) {
mesa_loge("vulkan: Failed to get Vulkan encoder\n"); mesa_loge("vulkan: Failed to get Vulkan encoder\n");
return VK_ERROR_DEVICE_LOST; return VK_ERROR_DEVICE_LOST;
@@ -321,7 +345,6 @@ VkResult gfxstream_vk_CreateInstance(const VkInstanceCreateInfo* pCreateInfo,
VkResult result = VK_SUCCESS; VkResult result = VK_SUCCESS;
/* Encoder call */ /* Encoder call */
{ {
ALOGV("calling setup instance internally");
result = SetupInstanceForProcess(); result = SetupInstanceForProcess();
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
return vk_error(NULL, result); return vk_error(NULL, result);
@@ -385,7 +408,7 @@ void gfxstream_vk_DestroyInstance(VkInstance _instance, const VkAllocationCallba
// To make End2EndTests happy, since now the host connection is statically linked to // To make End2EndTests happy, since now the host connection is statically linked to
// libvulkan_ranchu.so [separate HostConnections now]. // libvulkan_ranchu.so [separate HostConnections now].
#if defined(END2END_TESTS) #if defined(END2END_TESTS)
hostCon->exit(); mgr->threadLocalExit();
VirtGpuDevice::resetInstance(); VirtGpuDevice::resetInstance();
gSeqno = 0; gSeqno = 0;
#endif #endif

View File

@@ -24,9 +24,9 @@ lib_vulkan_gfxstream = shared_library(
inc_android_compat, inc_opengl_system, inc_guest_iostream, inc_android_compat, inc_opengl_system, inc_guest_iostream,
inc_opengl_codec, inc_render_enc, inc_vulkan_enc, inc_platform_virtgpu, inc_opengl_codec, inc_render_enc, inc_vulkan_enc, inc_platform_virtgpu,
inc_goldfish_address_space, inc_system, inc_include, inc_src, inc_goldfish_address_space, inc_system, inc_include, inc_src,
inc_platform_virtgpu, inc_codec_common], inc_platform_virtgpu, inc_codec_common, inc_connection_manager],
link_with: [lib_android_compat, lib_emu_android_base, lib_stream, link_with: [lib_android_compat, lib_emu_android_base, lib_stream,
libvulkan_wsi, libplatform_virtgpu], libvulkan_wsi, libplatform_virtgpu, libconnection_manager],
link_args: [vulkan_icd_link_args, ld_args_bsymbolic, ld_args_gc_sections], link_args: [vulkan_icd_link_args, ld_args_bsymbolic, ld_args_gc_sections],
link_depends: vulkan_icd_link_depends, link_depends: vulkan_icd_link_depends,
dependencies: [dependency('libdrm'), idep_vulkan_wsi_headers, dependencies: [dependency('libdrm'), idep_vulkan_wsi_headers,

View File

@@ -0,0 +1,14 @@
/*
* Copyright 2024 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
#include "GfxStreamVulkanConnection.h"
GfxStreamVulkanConnection::GfxStreamVulkanConnection(gfxstream::guest::IOStream* stream) {
mVkEnc = std::make_unique<gfxstream::vk::VkEncoder>(stream);
}
GfxStreamVulkanConnection::~GfxStreamVulkanConnection() {}
void* GfxStreamVulkanConnection::getEncoder() { return mVkEnc.get(); }

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2024 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GFXSTREAM_VULKAN_CONNECTION_H
#define GFXSTREAM_VULKAN_CONNECTION_H
#include <memory>
#include "GfxStreamConnection.h"
#include "VkEncoder.h"
class GfxStreamVulkanConnection : public GfxStreamConnection {
public:
GfxStreamVulkanConnection(gfxstream::guest::IOStream* stream);
virtual ~GfxStreamVulkanConnection();
void* getEncoder() override;
private:
std::unique_ptr<gfxstream::vk::VkEncoder> mVkEnc;
};
#endif

View File

@@ -25,6 +25,7 @@
#include <unordered_map> #include <unordered_map>
#include "CommandBufferStagingStream.h" #include "CommandBufferStagingStream.h"
#include "GfxStreamConnectionManager.h"
#include "HostVisibleMemoryVirtualization.h" #include "HostVisibleMemoryVirtualization.h"
#include "Sync.h" #include "Sync.h"
#include "VirtGpu.h" #include "VirtGpu.h"
@@ -127,8 +128,8 @@ class ResourceTracker {
VulkanHandleMapping* createMapping(); VulkanHandleMapping* createMapping();
VulkanHandleMapping* destroyMapping(); VulkanHandleMapping* destroyMapping();
using HostConnectionGetFunc = HostConnection* (*)(); using HostConnectionGetFunc = GfxStreamConnectionManager* (*)();
using VkEncoderGetFunc = VkEncoder* (*)(HostConnection*); using VkEncoderGetFunc = VkEncoder* (*)(GfxStreamConnectionManager*);
using CleanupCallback = std::function<void()>; using CleanupCallback = std::function<void()>;
struct ThreadingCallbacks { struct ThreadingCallbacks {

View File

@@ -31,4 +31,7 @@ files_lib_vulkan_enc = files(
'goldfish_vk_reserved_marshaling_guest.cpp', 'goldfish_vk_reserved_marshaling_guest.cpp',
'goldfish_vk_transform_guest.cpp', 'goldfish_vk_transform_guest.cpp',
'gfxstream_vk_private.cpp', 'gfxstream_vk_private.cpp',
'gfxstream_vk_private.cpp',
'gfxstream_vk_private.cpp',
'GfxStreamVulkanConnection.cpp',
) )