Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/base/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ else
files_lib_common_base += 'Thread_pthread.cpp'
endif

if host_machine.system() == 'darwin'
files_lib_common_base += 'system-native-mac.mm'
endif

lib_common_base = static_library(
'common_base',
files_lib_common_base,
Expand Down
28 changes: 28 additions & 0 deletions host/ColorBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
namespace gfxstream {
namespace {

#if GFXSTREAM_ENABLE_HOST_GLES
using gl::ColorBufferGl;
#endif
using vk::ColorBufferVk;

// ColorBufferVk natively supports YUV images. However, ColorBufferGl
Expand Down Expand Up @@ -116,6 +118,14 @@ class ColorBuffer::Impl : public LazySnapshotObj<ColorBuffer::Impl> {
std::unique_ptr<ColorBufferGl> mColorBufferGl;
#endif

bool hasColorBuffer() const {
#if GFXSTREAM_ENABLE_HOST_GLES
return mColorBufferGl || mColorBufferVk;
#else
return mColorBufferVk != nullptr;
#endif
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo ';'

I think this function is not being used, please remove.


// If Vk emulation is enabled.
std::unique_ptr<ColorBufferVk> mColorBufferVk;

Expand Down Expand Up @@ -161,7 +171,11 @@ std::unique_ptr<ColorBuffer::Impl> ColorBuffer::Impl::create(
#endif

if (emulationVk) {
#if GFXSTREAM_ENABLE_HOST_GLES
const bool vulkanOnly = colorBuffer->mColorBufferGl == nullptr;
#else
const bool vulkanOnly = true;
#endif
const uint32_t memoryProperty = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
const uint32_t mipLevels = 1;
colorBuffer->mColorBufferVk =
Expand Down Expand Up @@ -423,9 +437,11 @@ std::unique_ptr<BorrowedImageInfo> ColorBuffer::Impl::borrowForDisplay(UsedApi a
}

bool ColorBuffer::Impl::flushFromGl() {
#if GFXSTREAM_ENABLE_HOST_GLES
if (!(mColorBufferGl && mColorBufferVk)) {
return true;
}
#endif

if (mGlAndVkAreSharingExternalMemory) {
return true;
Expand All @@ -438,9 +454,15 @@ bool ColorBuffer::Impl::flushFromGl() {
}

bool ColorBuffer::Impl::flushFromVk() {
#if GFXSTREAM_ENABLE_HOST_GLES
if (!(mColorBufferGl && mColorBufferVk)) {
return true;
}
#else
if (!mColorBufferVk) {
return true;
}
#endif

if (mGlAndVkAreSharingExternalMemory) {
return true;
Expand All @@ -466,9 +488,11 @@ bool ColorBuffer::Impl::flushFromVk() {
}

bool ColorBuffer::Impl::flushFromVkBytes(const void* bytes, size_t bytesSize) {
#if GFXSTREAM_ENABLE_HOST_GLES
if (!(mColorBufferGl && mColorBufferVk)) {
return true;
}
#endif

if (mGlAndVkAreSharingExternalMemory) {
return true;
Expand All @@ -487,9 +511,11 @@ bool ColorBuffer::Impl::flushFromVkBytes(const void* bytes, size_t bytesSize) {
}

bool ColorBuffer::Impl::invalidateForGl() {
#if GFXSTREAM_ENABLE_HOST_GLES
if (!(mColorBufferGl && mColorBufferVk)) {
return true;
}
#endif

if (mGlAndVkAreSharingExternalMemory) {
return true;
Expand All @@ -501,9 +527,11 @@ bool ColorBuffer::Impl::invalidateForGl() {
}

bool ColorBuffer::Impl::invalidateForVk() {
#if GFXSTREAM_ENABLE_HOST_GLES
if (!(mColorBufferGl && mColorBufferVk)) {
return true;
}
#endif

if (mGlAndVkAreSharingExternalMemory) {
return true;
Expand Down
48 changes: 32 additions & 16 deletions host/FrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
#include "gl/YUVConverter.h"
#include "gl/gles2_dec/gles2_dec.h"
#include "gl/glestranslator/EGL/EglGlobalInfo.h"
#include "ContextHelper.h"
#endif

#include "ContextHelper.h"
#include "Hwc2.h"
#include "NativeSubWindow.h"
#include "RenderThreadInfo.h"
Expand Down Expand Up @@ -477,12 +477,6 @@ class FrameBuffer::Impl : public gfxstream::base::EventNotificationSupport<Frame
gl::EmulationGl& getEmulationGl();
bool hasEmulationGl() const { return m_emulationGl != nullptr; }

vk::VkEmulation& getEmulationVk();
bool hasEmulationVk() const { return m_emulationVk != nullptr; }

bool setColorBufferVulkanMode(HandleType colorBufferHandle, uint32_t mode);
int32_t mapGpaToBufferHandle(uint32_t bufferHandle, uint64_t gpa, uint64_t size);

// Return the host EGLDisplay used by this instance.
EGLDisplay getDisplay() const;
EGLSurface getWindowSurface() const;
Expand Down Expand Up @@ -579,6 +573,12 @@ class FrameBuffer::Impl : public gfxstream::base::EventNotificationSupport<Frame
const gl::GLESv2Dispatch* getGles2Dispatch();
#endif

vk::VkEmulation& getEmulationVk();
bool hasEmulationVk() const { return m_emulationVk != nullptr; }

bool setColorBufferVulkanMode(HandleType colorBufferHandle, uint32_t mode);
int32_t mapGpaToBufferHandle(uint32_t bufferHandle, uint64_t gpa, uint64_t size);

// Retrieve the vendor info strings for the GPU driver used for the emulation.
// On return, |*vendor|, |*renderer| and |*version| will point to strings
// that are owned by the instance (and must not be freed by the caller).
Expand Down Expand Up @@ -726,7 +726,9 @@ class FrameBuffer::Impl : public gfxstream::base::EventNotificationSupport<Frame
}
};
std::map<uint32_t, onPost> m_onPost;
#if GFXSTREAM_ENABLE_HOST_GLES
ReadbackWorker* m_readbackWorker = nullptr;
#endif
gfxstream::base::WorkerThread<Readback> m_readbackThread;
std::atomic_bool m_readbackThreadStarted = false;

Expand Down Expand Up @@ -1277,6 +1279,7 @@ FrameBuffer::Impl::~Impl() {

WorkerProcessingResult FrameBuffer::Impl::sendReadbackWorkerCmd(const Readback& readback) {
ensureReadbackWorker();
#if GFXSTREAM_ENABLE_HOST_GLES
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block is not directly using GL, so instead of disabling the functionality here I think we need to implement a vulkan version of the readback worker class, or a dummy one that throws errors for now, to make sure ensureReadbackWorker assigns m_readbackWorker to something and we get proper error messages for unimplemented features.

switch (readback.cmd) {
case ReadbackCmd::Init:
m_readbackWorker->init();
Expand All @@ -1293,6 +1296,7 @@ WorkerProcessingResult FrameBuffer::Impl::sendReadbackWorkerCmd(const Readback&
case ReadbackCmd::Exit:
return WorkerProcessingResult::Stop;
}
#endif
return WorkerProcessingResult::Stop;
}

Expand Down Expand Up @@ -1721,9 +1725,11 @@ HandleType FrameBuffer::Impl::genHandle_locked() {

bool FrameBuffer::Impl::isFormatSupported(GLenum format) {
bool supported = true;
#if GFXSTREAM_ENABLE_HOST_GLES
if (m_emulationGl) {
supported &= m_emulationGl->isFormatSupported(format);
}
#endif
if (m_emulationVk) {
supported &= m_emulationVk->isFormatSupported(format);
}
Expand Down Expand Up @@ -2078,8 +2084,8 @@ void FrameBuffer::Impl::cleanupProcGLObjects(uint64_t puid) {
std::vector<HandleType> FrameBuffer::Impl::cleanupProcGLObjects_locked(uint64_t puid, bool forced) {
std::vector<HandleType> colorBuffersToCleanup;
{
std::unique_ptr<RecursiveScopedContextBind> bind = nullptr;
#if GFXSTREAM_ENABLE_HOST_GLES
std::unique_ptr<RecursiveScopedContextBind> bind = nullptr;
if (m_emulationGl) {
bind = std::make_unique<RecursiveScopedContextBind>(getPbufferSurfaceContextHelper());
}
Expand Down Expand Up @@ -2438,11 +2444,13 @@ AsyncResult FrameBuffer::Impl::postImpl(HandleType p_colorbuffer, Post::Completi

if (asyncReadbackSupported()) {
ensureReadbackWorker();
#if GFXSTREAM_ENABLE_HOST_GLES
const auto status = m_readbackWorker->doNextReadback(
iter.first, cb.get(), iter.second.img, repaint, iter.second.readBgra);
if (status == ReadbackWorker::DoNextReadbackResult::OK_READY_FOR_READ) {
doPostCallback(iter.second.img, iter.first);
}
#endif
} else {
#if GFXSTREAM_ENABLE_HOST_GLES
cb->glOpReadback(iter.second.img, iter.second.readBgra);
Expand Down Expand Up @@ -2489,10 +2497,12 @@ void FrameBuffer::Impl::flushReadPipeline(int displayId) {

ensureReadbackWorker();

#if GFXSTREAM_ENABLE_HOST_GLES
const auto status = m_readbackWorker->flushPipeline(displayId);
if (status == ReadbackWorker::FlushResult::OK_READY_FOR_READ) {
doPostCallback(nullptr, displayId);
}
#endif
}

void FrameBuffer::Impl::ensureReadbackWorker() {
Expand Down Expand Up @@ -2825,8 +2835,8 @@ void FrameBuffer::Impl::onSave(Stream* stream, const ITextureSaverPtr& textureSa
// m_prevDrawSurf
AutoLock mutex(m_lock);

std::unique_ptr<RecursiveScopedContextBind> bind;
#if GFXSTREAM_ENABLE_HOST_GLES
std::unique_ptr<RecursiveScopedContextBind> bind;
if (m_emulationGl) {
// Some snapshot commands try using GL.
bind = std::make_unique<RecursiveScopedContextBind>(getPbufferSurfaceContextHelper());
Expand Down Expand Up @@ -2953,8 +2963,8 @@ bool FrameBuffer::Impl::onLoad(Stream* stream, const ITextureLoaderPtr& textureL
{
sweepColorBuffersLocked();

std::unique_ptr<RecursiveScopedContextBind> bind;
#if GFXSTREAM_ENABLE_HOST_GLES
std::unique_ptr<RecursiveScopedContextBind> bind;
if (m_emulationGl) {
// Some snapshot commands try using GL.
bind = std::make_unique<RecursiveScopedContextBind>(getPbufferSurfaceContextHelper());
Expand Down Expand Up @@ -3175,8 +3185,8 @@ bool FrameBuffer::Impl::onLoad(Stream* stream, const ITextureLoaderPtr& textureL
#endif

{
std::unique_ptr<RecursiveScopedContextBind> bind;
#if GFXSTREAM_ENABLE_HOST_GLES
std::unique_ptr<RecursiveScopedContextBind> bind;
if (m_emulationGl) {
// Some snapshot commands try using GL.
bind = std::make_unique<RecursiveScopedContextBind>(getPbufferSurfaceContextHelper());
Expand Down Expand Up @@ -4718,7 +4728,9 @@ void FrameBuffer::unlockContextStructureRead() { mImpl->unlockContextStructureRe

void FrameBuffer::createTrivialContext(HandleType shared, HandleType* contextOut,
HandleType* surfOut) {
#if GFXSTREAM_ENABLE_HOST_GLES
mImpl->createTrivialContext(shared, contextOut, surfOut);
#endif
}

void FrameBuffer::setShuttingDown() { mImpl->setShuttingDown(); }
Expand Down Expand Up @@ -4759,7 +4771,9 @@ float FrameBuffer::getPy() const { return mImpl->getPy(); }
int FrameBuffer::getZrot() const { return mImpl->getZrot(); }

void FrameBuffer::setScreenMask(int width, int height, const uint8_t* rgbaData) {
#if GFXSTREAM_ENABLE_HOST_GLES
mImpl->setScreenMask(width, height, rgbaData);
#endif
}

#ifdef CONFIG_AEMU
Expand Down Expand Up @@ -4913,7 +4927,9 @@ std::optional<BlobDescriptorInfo> FrameBuffer::exportBuffer(HandleType bufferHan
return mImpl->exportBuffer(bufferHandle);
}

#if GFXSTREAM_ENABLE_HOST_GLES
bool FrameBuffer::hasEmulationGl() const { return mImpl->hasEmulationGl(); }
#endif

bool FrameBuffer::hasEmulationVk() const { return mImpl->hasEmulationVk(); }

Expand Down Expand Up @@ -4970,11 +4986,6 @@ EGLint FrameBuffer::chooseConfig(EGLint* attribs, EGLint* configs, EGLint config
return mImpl->chooseConfig(attribs, configs, configsSize);
}

void FrameBuffer::getDeviceInfo(const char** vendor, const char** renderer,
const char** version) const {
mImpl->getDeviceInfo(vendor, renderer, version);
}

HandleType FrameBuffer::createEmulatedEglContext(int p_config, HandleType p_share,
GLESApi version) {
return mImpl->createEmulatedEglContext(p_config, p_share, version);
Expand Down Expand Up @@ -5110,6 +5121,11 @@ const void* FrameBuffer::getGles2Dispatch() { return mImpl->getGles2Dispatch();

#endif

void FrameBuffer::getDeviceInfo(const char** vendor, const char** renderer,
const char** version) const {
mImpl->getDeviceInfo(vendor, renderer, version);
}

const FeatureSet& FrameBuffer::getFeatures() const { return mImpl->getFeatures(); }

RepresentativeColorBufferMemoryTypeInfo FrameBuffer::getRepresentativeColorBufferMemoryTypeInfo()
Expand Down
2 changes: 1 addition & 1 deletion host/GlesCompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

typedef unsigned int GLenum;
typedef int32_t EGLint;
typedef unsigned int EGLNativeWindowType;
typedef void *EGLNativeWindowType;

namespace gfxstream {
namespace gl {
Expand Down
Empty file added host/iostream/dummy.c
Empty file.
1 change: 1 addition & 0 deletions host/iostream/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
inc_host_iostream = include_directories('include')

files_lib_host_iostream = files(
'dummy.c'
)

lib_host_iostream = static_library(
Expand Down
8 changes: 8 additions & 0 deletions host/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ if host_machine.system() == 'qnx'
]
endif

if host_machine.system() == 'darwin'
deps_gfxstream_backend += [
cocoa_dep,
corefoundation_dep,
iokit_dep,
]
endif

gfxstream_backend = library(
'gfxstream_backend',
files_lib_gfxstream_backend,
Expand Down
Empty file added host/snapshot/dummy.c
Empty file.
2 changes: 1 addition & 1 deletion host/snapshot/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

inc_host_snapshot = include_directories('include')

files_lib_host_snapshot = files()
files_lib_host_snapshot = files('dummy.c')

lib_host_snapshot = static_library(
'host_snapshot',
Expand Down
Loading