Route gl<->vk ColorBuffer syncs through FrameBuffer

RenderControl functions such as rcBindTexture(),
rcFlushWindowColorBuffer(), etc act as a kind of boundary between
ColorBuffer usage across APIs (GL/EGL, Vulkan, and Gralloc) and need
to sync the state of the ColorBuffer between the various host APIs
that back ColorBuffers. For example, rcBindTexture() needs to sync
the state of GL texture backing ColorBuffers for GL usage and does
so by reading the state from the VK image.

Upcoming ColorBuffer refactoring, to enable running without host GL,
needs to make the ColorBuffer VK setup path not depend on the
ColorBuffer GL path. With this, setup of the VK backing will no
longer be deferred until the first VK usage and ColorBuffer::create()
is updated to perform both ColorBufferGl::create() and
ColorBufferVk::create() immediately.

However, this can lead to a potential deadlock because of the order
of locks acquired during the ColorBuffer creation flow and the
RenderControl sync'ing flows.

* The RenderControl functions use goldfish_vk::readColorBufferToGl()
  and goldfish_vk::updateColorBufferFromGl() to perform downloads and
  uploads for both GL and VK. These calls lock sVkEmulationLock first
  and then lock FrameBuffer::m_lock second.

* The virtio-gpu resource_create_3d() path calls into
  FrameBuffer::createColorBuffer() which then calls into
  ColorBufferGl::create() and ColorBufferVk::create(). These calls lock
  FrameBuffer::m_lock first and then sVkEmulationLock second.

This change updates the RenderControl functions to go through the
FrameBuffer lock first so that it is kind-of always a top-down locking
approach.

Bug: b/233939967
Test: android build
Test: cmake build
Test: cvd start --gpu_mode=gfxstream
Test: gfxstream unit tests
Change-Id: I3d4aa41c1bad0028077ceb85700b401996e01e86
6 files changed
tree: 8076220c324f3677add34bf34509a7c43b5968aa
  1. cmake/
  2. fake-android-guest/
  3. gl-host-common/
  4. include/
  5. protocols/
  6. scripts/
  7. stream-servers/
  8. testenvs/
  9. third-party/
  10. utils/
  11. .clang-format
  12. .gitignore
  13. Android.bp
  14. android.cmake
  15. build-host.sh
  16. BUILD.gn
  17. CMakeLists.txt
  18. LICENSE
  19. METADATA
  20. README.md
README.md

Graphics Streaming Kit (formerly: Vulkan Cereal)

Graphics Streaming Kit is a code generator that makes it easier to serialize and forward graphics API calls from one place to another:

  • From a virtual machine guest to host for virtualized graphics
  • From one process to another for IPC graphics
  • From one computer to another via network sockets

Build: Linux

Make sure the latest CMake is installed. Make sure the opengl lib is installed. Otherwise, sudo apt-get install libglu1-mesa-dev freeglut3-dev mesa-common-dev Make sure you are using Clang as your CC and clang++ as yourCXX. Then

mkdir build
cd build
cmake . ../
make -j24

Unit tests:

make test

Build: Windows

Make sure the latest CMake is installed. Make sure Visual Studio 2019 is installed on your system along with all the Clang C++ toolchain components. Then

mkdir build
cd build
cmake . ../ -A x64 -T ClangCL

A solution file should be generated. Then open the solution file in Visual studio and build the gfxstream_backend target.

Build: Android for host

Be in the Android build system. Then

m libgfxstream_backend

It then ends up in out/host

This also builds for Android on-device.

Output artifacts

libgfxstream_backend.(dll|so|dylib)

Regenerating Vulkan code

Check out the gfxstream-protocols repo at ../../../external/gfxstream-protocols relative to the root directory of this repo, and run the scripts/generate-vulkan-sources.sh script in the gfxstream-protocols root folder.

If you're in an AOSP checkout, this will also modify contents of the guest Vulkan encoder in ../goldfish-opengl.

Regenerating GLES/RenderControl code

First, build build/gfxstream-generic-apigen. Then run

scripts/generate-apigen-source.sh

Tests

Linux Tests

There are a bunch of test executables generated. They require libEGL.so and libGLESv2.so and libvulkan.so to be available, possibly from your GPU vendor or ANGLE, in the $LD_LIBRARY_PATH.

Windows Tests

There are a bunch of test executables generated. They require libEGL.dll and libGLESv2.dll and vulkan-1.dll to be available, possibly from your GPU vendor or ANGLE, in the %PATH%.

Android Host Tests

These are currently not built due to the dependency on system libEGL/libvulkan to run correctly.

Structure

  • CMakeLists.txt: specifies all host-side build targets. This includes all backends along with client/server setups that live only on the host. Some
    • Backend implementations
    • Implementations of the host side of various transports
    • Frontends used for host-side testing with a mock implementation of guest graphics stack (mainly Android)
    • Frontends that result in actual Linux/macOS/Windows gles/vk libraries (isolation / fault tolerance use case)
  • Android.bp: specifies all guest-side build targets for Android:
    • Implementations of the guest side of various transports (above the kernel)
    • Frontends
  • BUILD.gn: specifies all guest-side build targets for Fuchsia
    • Implementations of the guest side of various transports (above the kernel)
    • Frontends
  • base/: common libraries that are built for both the guest and host. Contains utility code related to synchronization, threading, and suballocation.
  • protocols/: implementations of protocols for various graphics APIs. May contain code generators to make it easy to regen the protocol based on certain things.
  • host-common/: implementations of host-side support code that makes it easier to run the server in a variety of virtual device environments. Contains concrete implementations of auxiliary virtual devices such as Address Space Device and Goldfish Pipe.
  • stream-servers/: implementations of various backends for various graphics APIs that consume protocol. gfxstream-virtio-gpu-renderer.cpp contains a virtio-gpu backend implementation.