39 Commits
Author SHA1 Message Date
Serdar Kocdemir 32b99c2f08 Some logging cleanup
Remove printf usages. Also reduces the severity of error for unimplemented
displayvk::clear call.

Bug: 389637419
Test: CI
Change-Id: If3de85fc910d1c7e1e10a1292bf02d26be0b8801
2025-09-16 16:06:52 +00:00
Serdar Kocdemir 6378aa2a62 Enable running emulator without emulationGl
Do not initialize emulationGl when vulkan composition is used and
handle usages of it by reporting errors to the logs with the function
name when possible, rather than doing a fatal crash.
Calls to createEmulatedEglFenceSync are still being made frequently
in GuestAngle mode, probably due to a separate bug, so the error
message is logged only once.
Also changes the return type of EmulatedEglImage::destroy to a regular
bool to limit usages of EGL structures.

Bug: 389646068
Test: -feature GuestAngle,VulkanNativeSwapchain,GuestUsesAngle
Change-Id: Ib9f7f1b98fe91aa2fcd47bd98f4494eb947d00b7
2025-09-11 08:25:45 +00:00
Serdar Kocdemir d8bd31204e Adjustments to some log messages
Reduce usages of stderr printing and use gfxstream logging
functions instead.

Bug: 389637419
Bug: 433496880
Test: CI
Change-Id: I52ad2fe9953cffa1b028b9a388e7f90c7141a9c0
2025-09-04 19:31:59 +00:00
Jason Macnak e531eb6ccc Use std::memcpy to inspect packet len in RenderThread 2025-06-11 23:10:29 +00:00
Jason Macnak c2b159afd1 Move logging to common
and add Android support which uses __android_log_print to
the default callback. This will allow us to eventually build
and run the guest libs in a standalone bazel environment without
Android libs (no "liblog", "libcutils", etc).

Misc notes:

 * Updates some cases of ANDROID vs __ANDROID__. The former is
   set when building with Soong (either host or guest) while the
   latter is set specifically when targeting the Android platform.
   Some places that were using ANDROID needed to be fixed to use
   __ANDROID__ to properly detect when to use ANativeWindow.

 * Updates the EGL platform header to address something similar
   to the above where we may want to use X11 display when building
   host binaries with Soong where ANDROID may still be defined.

Bug: b/416342919

Test: cd hardware/google/gfxstream
      bazel build ...
      bazel test ...

Test: cd hardware/google/gfxstream
      mma

Test: cd hardware/google/gfxstream
      mkdir build && cd build
      cmake .. -G Ninja
      ninja

Test: meson setup \
        -Ddefault_library=static \
        -Dgfxstream-build=host \
        build

      meson compile -C build

Test: cd <emu main dev repo>
      cd external/qemu
      python android/build/python/cmake.py --gfxstream

Test: cd <emu main next repo>
      prebuilts/bazel/linux-x86_64/bazel test \
      --platforms=@//build/bazel/platforms:linux_x64 \
     @gfxstream//...
Change-Id: I4db669047f3900392d50509c470ea350d94a64ba
2025-05-14 16:51:19 -07:00
Jason Macnak af353cc3ad Split utils in host/decoder_common and host/renderdoc
Bug: b/416342919
Test: cd hardware/google/gfxstream
      mma

Test: cd hardware/google/gfxstream
      mkdir build && cd build
      cmake .. -G Ninja
      ninja

Test: meson setup \
        -Ddefault_library=static \
        -Dgfxstream-build=host \
        build

      meson compile -C build

Test: cd <emu main dev repo>
      cd external/qemu
      python android/build/python/cmake.py --gfxstream

Test: cd <emu main next repo>
      prebuilts/bazel/linux-x86_64/bazel test \
      --platforms=@//build/bazel/platforms:linux_x64 \
     @gfxstream//...
Change-Id: I69d93e21e21a53b6f82e336d54bc27381b778ddd
2025-05-13 04:06:40 +00:00
Jason Macnak d4ffa9a5bc Normalize some directory names and includes
Bug: b/403363880

Test: cd hardware/google/gfxstream
      mma

Test: cd hardware/google/gfxstream
      mkdir build && cd build
      cmake .. -G Ninja
      ninja

Test: meson setup \
        -Ddefault_library=static \
        -Dgfxstream-build=host \
        build

      meson compile -C build

Test: cd <emu main dev repo>
      cd external/qemu
      python android/build/python/cmake.py --gfxstream

Test: cd <emu main next repo>
      prebuilts/bazel/linux-x86_64/bazel test \
      --platforms=@//build/bazel/platforms:linux_x64 \
     @gfxstream//...
Change-Id: I0d4aa852da43ed3b2a411181689876c8b78f5367
2025-05-07 12:35:39 -07:00
Jason Macnak d4ae528b16 Hide ASG internals from the consumer interface
Refactors Gfxstream's ASG to hide ASG internals (context init, ring
buffer, ring config, etc) from external use. The ASG consumer interface
is updated to only take the shared memory pointers as arguments and then
all of the internal ASG context / ring initialization should happen
inside of `RingStream`. This requires a little bit of refactoring
around `onUnavailableRead()` to move the unavailable read count and
to move the setting of the `asg_context::host_state` into `RingStream`.

Bug: b/403363880

Test: cd hardware/google/gfxstream
      mma

Test: cd hardware/google/gfxstream
      mkdir build && cd build
      cmake .. -G Ninja
      ninja

Test: meson setup \
        -Ddefault_library=static \
        -Dgfxstream-build=host \
        build

      meson compile -C build

Test: cd <emu main dev repo>
      cd external/qemu
      python android/build/python/cmake.py --gfxstream

Test: cd <emu main next repo>
      prebuilts/bazel/linux-x86_64/bazel test \
      --platforms=@//build/bazel/platforms:linux_x64 \
     @gfxstream//...
Change-Id: I43cc8e55ec4ded3071c22e2cfce6fab930262a17
2025-05-07 12:35:25 -07:00
Jason Macnak 453d39675a Use Gfxstream's Stream for save/load interface
Moves several of the "common/base" classes to host/backend as these
classes all used `Stream` which is a host only interface.

Bug: b/403363880

Test: cd hardware/google/gfxstream
      mma

Test: cd hardware/google/gfxstream
      mkdir build && cd build
      cmake .. -G Ninja
      ninja

Test: meson setup \
        -Ddefault_library=static \
        -Dgfxstream-build=host \
        build

      meson compile -C build

Test: cd <emu main dev repo>
      cd external/qemu
      python android/build/python/cmake.py --gfxstream

Test: cd <emu main next repo>
      prebuilts/bazel/linux-x86_64/bazel test \
      --platforms=@//build/bazel/platforms:linux_x64 \
     @gfxstream//...

Change-Id: Ia664776c2322b310614f632e4926bb3b031f3bc1
2025-05-07 12:35:25 -07:00
Jason Macnak b001c743d3 Update non interface parts of Gfxstream to use new base lib
NO_IFTTT=existing field covered with type change

Bug: b/403363880

Test: cd hardware/google/gfxstream
      mma

Test: cd hardware/google/gfxstream
      mkdir build && cd build
      cmake .. -G Ninja
      ninja

Test: meson setup \
        -Ddefault_library=static \
        -Dgfxstream-build=host \
        build

      meson compile -C build

Test: cd <emu master dev repo>
      cd external/qemu
      python android/build/python/cmake.py --gfxstream

Test: cd <emu main next repo>
      prebuilts/bazel/linux-x86_64/bazel test \
      --platforms=@//build/bazel/platforms:linux_x64 \
     @gfxstream//...
Change-Id: I6bfb2c4ef8368799d9f99f6293d9762b7dcb4c7f
2025-05-01 16:29:17 +00:00
Bo Hu eb219f2031 Merge "[vulkan snapshot]: save and restore context id for VkInstance" into main 2025-04-28 20:13:26 -07:00
Bo Hu 665f46d920 [vulkan snapshot]: save and restore context id for VkInstance
When a guest process died, e.g., during adb reboot,
it's vk instance will be cleaned up automatically on
the host. However, this does not happen after loading
vulkan snapshot, as there is no context id information saved
for each vk instance.

This cl fixes that problem by remembering the context id
associated with each VkInstance, save them during
snapshot save and restore them during load.

Test: save snapshot, load, adb reboot, save and load again
it should not crash during loading.

Bug: 413670220

Change-Id: I0cc7db41efc61d596ba64903cada27d9cb6348f3
2025-04-28 15:45:27 -07:00
Jason Macnak 4b4e852b36 Cleanup references to host-common
Bug: b/403363880

Test: cd hardware/google/gfxstream
      mma

Test: cd hardware/google/gfxstream
      mkdir build && cd build
      cmake .. -G Ninja
      ninja

Test: meson setup \
        -Ddefault_library=static \
        -Dgfxstream-build=host \
        build

      meson compile -C build

Test: cd <emu main dev repo>
      cd external/qemu
      python android/build/python/cmake.py --gfxstream

Test: cd <emu main next repo>
      prebuilts/bazel/linux-x86_64/bazel test \
      --platforms=@//build/bazel/platforms:linux_x64 \
     @gfxstream//...
Change-Id: I6765726663c333cd8dbbf3223e8960bec5d224d9
2025-04-28 13:06:02 +00:00
Joshua Duong f53f263e18 Notify RenderThreads when guest puid dies.
VkDecoder's seqno logic may get stuck if a guest process dies and
some vk commands don't make it over to the host.

Bug: 410069267
Test: CtsGraphicsTestCases
Change-Id: Ibcf3996ca6a681e1f734c943281b112506bab7ad
2025-04-21 13:36:09 -07:00
Jason Macnak a43dfa9f3c Add gfxstream host logging lib
... to eventually replace the existing host-common/logging. This
is needed to break up the circular dependency between aemu-base and
aemu-host-common, so that we can move parts of aemu-base and
aemu-host-common into hardware/google/gfxstream, in order to make
Gfxstream a self contained library for building.

Hooks up the existing host-common/logging via the
RenderLibImpl::setLogger() call.

Bug: b/403363880

Test: cd hardware/google/gfxstream
      mma

Test: cd hardware/google/gfxstream
      mkdir build && cd build
      cmake .. -G Ninja
      ninja

Test: meson setup \
        -Ddefault_library=static \
        -Dgfxstream-build=host \
        build
      meson compile -C build

Test: cd <emu master dev repo>
      cd external/qemu
      python android/build/python/cmake.py --gfxstream

Test: cd <emu main next repo>
      prebuilts/bazel/linux-x86_64/bazel test \
      --platforms=@//build/bazel/platforms:linux_x64 \
     @gfxstream//...

Change-Id: Id52c6f756f85d0a5fb948601228234d7a84a14c2
2025-04-09 13:11:08 -07:00
Gurchetan Singh 47dd9bdaf2 gfxstream: nuke Magma on the host
See:

https://crosvm.dev/book/appendix/rutabaga_gfx.html#magma

for new plan.

BUG=406071091
TEST=compile

Change-Id: Ib82c38ff2d2ea08c8be69eaef9f8e4366384f4ca
2025-04-04 09:56:46 -07:00
Jason Macnak 4e379d810e Remove the global VkEmulation variable
... and move into FrameBuffer.

Bug: b/383139165
Test: cvd create --gpu_mode=gfxstream_guest_angle_host_swiftshader
Change-Id: Iab139a0793564b21126a66946031caab8a8a6456
2025-03-04 13:03:38 -08:00
Jason Macnak 17b4107260 Make VkEmulation a class w/ VkCommonOperations funcs
... so that members can start to be protected with GUARDED_BY
annotations and potentially can start to eliminate having a
global `sVkEmulation`.

Bug: b/383139165
Test: cvd create --gpu_mode=gfxstream_guest_angle_host_swiftshader
Change-Id: Iae4dd859991015e386fcc30ef091ccdb7ed1aeb6
2025-03-04 12:56:10 -08:00
Jason Macnak 0334ecf991 Ensure resume waits for the RenderThreads to resume
Without waiting for the `RenderThread`s to complete,
`RenderThread::resume()` might destroy `mStream` before
or during use `RenderThread::loadSnapshot()`.

Setting the `waitForSave` to false was a carry over from
aosp/2824962 where some allowances were made for the end2end that
did fake snapshoting. The snapshot end2end tests were removed
to do fundamental limitations with faking VM functionality
so this `waitForSave` is no longer needed and can be completely
removed.

Bug: b/397503985
Test: snapshot with Cuttlefish
Change-Id: If252466e677a985e9ee3bde2b35d53ac2ebda759
2025-02-18 15:16:36 -08:00
Bo Hu 0be3975608 Fix deadlock on RenderThread exit.
We expose the global egl lock to synchronize the followiing
scenarios where we have observed deadlocks:

- Nvidia seems to have registered some cleanup code
(pthread_key_create) that has a race condition against other
threads calling vkDestroyDevice. So this workaround synchronizes
the RenderThread exit with vkDestroyDevice calls.

- Nvidia also seems to have a deadlock between vkDestroyDevice
and eglMakeCurrent.

Also add addtional protection around eglSwapBuffers.

Bug: 377677250
Test: Run dEQP with Nvidia GPU. Observe no hang/crash.

Change-Id: I570c14671cb8cdc79f8a1b3b1077a1f7c13d28fe
2025-01-21 10:57:40 -08:00
Joshua Duong e65ab797bf Set thread name of RenderThread.
Useful for debugging.

Bug: 377677250
Test: Attach debugger, see RenderThread name
Change-Id: Ic1f5a4751a9c1469b0f0d62c98f9092164598ee3
2025-01-13 10:19:36 -08:00
Jason Macnak 89fa204e69 Restructure RenderThread snapshot funcs for thread safety
... to make thread safety analysis happy.

Bug: b/383139165
Test: m
Change-Id: Ia15200903987112d9b8f50e301e4b5c6d52069be
2024-12-12 11:59:55 -08:00
Aaron Ruby 52cef357e8 gfxstream: Replace GuestUsesAngle nomenclature with GuestVulkanOnly.
As this flag now applies with Linux+Zink as the GL translation as well.

Change-Id: I8f648ebe845a251f7c32479ad7bf87ee02a14ce3
2024-07-02 13:31:23 -04:00
Joshua Duong 6f6b803ae3 Formalize definition of invalid context ids.
RenderThread guest puids are assumed to be invalid if it is 0, but
it seems we were using -1 as an invalid virtio-gpu context id. So
Let's check for both in RenderThread.

Bug: 339461355
Bug: 300146030
Test: Boot emulator, observe no logspam
Change-Id: I01d5bda6b48cf5f71c42f7234609b372e5612dd4
2024-05-31 11:27:56 -07:00
Jason Macnak 2687212e49 Introduce Gfxstream Features to decouple Gfxstream from AEMU
... which will allow building Gfxstream from a fixed version of
AEMU for the purposes of packaging.

Bug: b/326648397
Test: cvd start --gpu_mode=gfxstream
Test: cvd start --gpu_mode=gfxstream_guest_angle
Change-Id: I8ac1622428f0194997597868bef49118bcc3ea90
2024-03-18 15:50:46 -07:00
Gurchetan Singh 95b30dc862 Reland "gfxstream: introduce GFXSTREAM_ENABLE_HOST_GLES compiler flag"
Same as before, but added extra GFXSTREAM_ENABLE_HOST_GLES
to keep MacOS builders happy.

Change-Id: I333503ecb6e67840326ce248428fa097eb152e92
2024-01-18 18:34:08 -08:00
Gurchetan Singh 6ed12e9d66 Revert "gfxstream: introduce GFXSTREAM_ENABLE_HOST_GLES compiler flag"
This reverts commit 4675a9d4ef.

Reason for revert: I suppose it breaks MacOS

Change-Id: I91bef5c2fa0e8726b6e77e6678540b808ad26316
2024-01-19 02:19:50 +00:00
Gurchetan Singh 4675a9d4ef gfxstream: introduce GFXSTREAM_ENABLE_HOST_GLES compiler flag
This allows:

meson -Ddecoders=vulkan

to build without errors.  This is useful for enviroments where
GLES does not exist (Fuchsia) or where importing the entire
gfxstream GLES decoder is undesirable.

BUG=31148679
TEST=compile

Change-Id: I59e385c205588a4dbbe472fac1681ebe261127dc
2024-01-17 18:13:22 -08:00
Gurchetan Singh fccd048a30 gfxstream: USE_MAGMA --> GFXSTREAM_ENABLE_HOST_MAGMA
Name change to be consistent with subsequent commit.

BUG=311486792
TEST=compile

Change-Id: If0f62c9d81ad16128f2b1a3c9b032e841d6fa28b
2024-01-17 18:13:22 -08:00
Jason Macnak 1220d96124 Ensure EmuglPipe RenderThread-s have a virtio gpu context id
... and avoid setting invalid PUIDs in rcSetPuid() to avoid lots of
"Failed to find process owned resources fpr puid" errors.

After aosp/2752873, the host GlProcessPipe stopped initializing a unique
id for the process pipe. However, it continued to communicate the value
of the `m_uniqueId` back to the guest. The guest still uses PUID for
rcSetPuid commands in the guest EGL/GL implementations. This would
result in garbage PUIDs being used by RenderThreads for
getProcessResources() calls. Further, if a guest process used both
EGL/GL and Vulkan, getProcessResources() would return nullptr and then
the host would crash when the VkDecoder tried to read the seqnoPtr in
the process resources.

Bug: b/312560224
Test: cvd start --gpu_mode=gfxstream
Change-Id: Ie3697a7588a8d2180ccc9e7f02f38ed6d9f1bd12
2023-11-22 10:52:54 -08:00
Yahan Zhou d1c7e1e700 Add basic vulkan snapshot test
The test creates an instance, saves and loads it, to make sure it does
not crash.

In end2end snapshot tests, we do not have a real guest system. Thus
snapshot can only test the host part. To make it work we will need to
skip render thread and stream snapshots, and reuse all render channels
created before snapshots.

We also added APIs to ask render thread not to wait for snapshots, and
sync up with FrameBuffer after snapshot loads.

It runs with cuttlefish.

Bug: 294277842
Test: GfxstreamEnd2EndVkSnapshotBasicTest
Change-Id: Ibea5d9830f0e927e7dbe3552ed31ad901b5397ab
2023-11-14 10:23:34 -08:00
Gurchetan Singh 6072076f87 Merge changes I29ae8e34,I71db5ff9,I98b30a88,I14e086d2,Ide0f668a into main
* changes:
  gfxstream: advertise noRenderControlEnc
  gfxstream: destroy/create process resources on virtio-gpu context create/destroy
  gfxstream: don't use renderControlEnc for Vulkan
  gfxstream: refactor process pipe logic
  gfxstream: simplify VK_HOST_CONNECTION macro
2023-09-20 16:29:55 +00:00
Gurchetan Singh 1958794d29 gfxstream: destroy/create process resources on virtio-gpu context create/destroy
This allows to deprecate the process pipe logic, and associated
pipe services infra.  In the virtio-gpu world, a "context" more
or less corresponds to a process.

BUG=297245651
TEST=launch_cvd --gpu_mode=gfxstream_guest_angle
     launch_cvd --gpu_mode=gfxstream

Change-Id: I71db5ff9a71786e89a04876a2a00b9e1fd754787
2023-09-19 14:49:14 -07:00
Yahan Zhou 4b64931d8e Reduce logspam
Test: boot
Bug: 300146030
Change-Id: I2778eb52733b0db5e4e5ff2f489cf2dced7a8cdc
2023-09-15 18:41:19 +00:00
Gurchetan Singh a8df2a3eb0 gfxstream: conditionally compile magma in Meson build
libdrm doesn't exist on all platforms. Fix this and conditionally
compile Magma until multi-platform Magma can be achieved.

BUG=299991018
TEST=meson -Ddecoders=gles,vulkan,composer amd64-build/
     ninja -C amd64-build/

Change-Id: I08d17ef20bd3fed021fe32df9222db941f5485a4
2023-09-13 12:09:03 -07:00
Gurchetan Singh f8706459b1 gfxstream: use process name based virtio-gpu protocol
The virtio-gpu protocol already provides a way to name
a process (known as a "context" in it's nomenclature").
Use that.  That'll allow use to delete the extra
renderControl side channel in the VK encoder while
still retaining this functionality.

BUG=297245651
TEST=launch_cvd --gpu_mode=gfxstream_guest_angle

Change-Id: I3cc4f4a497c438ed1c8bdea83a1c1180bb20f5ed
2023-09-06 19:43:55 -07:00
C Stout d47e46e2b0 gfxstream: set tInfo.m_puid to mContextId
Needed if the guest doesn't implement "pipe process init".

BUG=297245651
TEST=launch_cvd

Change-Id: Ie63a8e690b42b1d7a752f6848be8a502d4f35fb6
2023-09-01 08:46:49 -07:00
Andrew Woloszyn 1a5e3972ee Fix for an issue in the encoder when using m_state->usingDirectMapping();
This only shows up when we use MoltenVk with the emulator on Macos.
The encoder is not setting the packetlength properly.

Fixing this in the encoder would mean re-spinning all images
that enable Vulkan.

BUG: 297588622
Test: Running vulkan_test_applications/cube
Change-Id: Ifc8dc0c3ce2a21f57bc7acd69d9d0ff967138279
2023-08-28 13:55:41 -04:00
Jason Macnak 648a9edc06 Rename stream-servers to host
Bug: b/271464937
Test: m
Change-Id: I89553dfe2e27170e1e968e234b364f13e76b2f88
2023-05-19 15:09:46 -07:00