20 Commits
Author SHA1 Message Date
Bo Hu b2887ea2b9 [vulkan snapshot]: save and load semaphore signal state
The semaphore's signal state should be tracked and saved,
and later re-signaled if necessary during load, so that
any subsequent wait on the same semaphore could go ahead
instead of hanging.

Bug: 417788798

Change-Id: I15bd28be70e0582f049fd6cd281290fb37a5d694
2025-07-25 22:20:02 +00:00
Bo Hu 6b340cf804 [vulkan snapshot]: handle event save and load
There is currently a problem of missed setevent
and that leads to wait event hangs, or queue becomes
not able to idle, no matter how long it is waited upon.

To solve this problem, this cl follows each event's set,
reset, and save the set status into snapshot.
Later one, during loading, it recovers their set status,
so that subsequent cmd event wait can continue.

specifically, the following steps are taken:
1, set and reset operations from host or
in the queue are tracked.
2, if an event is set, that status will be saved
into snapshot; later during loadiing, the set operation
will be set again from the host or in the same queue
before snapshot.

This is not complete, but it is a first step
to resolve some of the timeout issue.

TODO:
event2

Test: xr should not hang during save due to
queue gets blocked (vkQueueSubmit does not return,
or wait for fence times out)

Bug: 417788798

Change-Id: I991cccfb2f34c6189f6c0759b8abbb365b695719
2025-07-10 23:58:52 +00:00
Jason Macnak 70caa04e57 Cleanup vkutils
Bug: b/416342919
Test: bazel build ...
Change-Id: Ic7405553b578050cc3e00829f69a6398aff5741e
2025-05-30 10:33:21 -07:00
Bo Hu bf29459da5 [vulkan snapshot]: support VK_FORMAT_R16_UNORM format
And
VK_FORMAT_R32_SFLOAT
VK_FORMAT_R5G6B5_UNORM_PACK16

some unity games seem to use such formats

Bug: 418814845
Change-Id: Id0eec8cd0e920cfc60a2b3575b1e3640c502d5ac
2025-05-20 14:53:54 -07:00
Bo Hu fc11e82431 [vulkan snapshot]: support more color formats
If the format is not recognizable, it is ok to skip it;
so that the subsequent saving and loading can continue.

Bug: 417788798

Change-Id: Iac3281db82ae3b261ed6b9286841cae5a4012979
2025-05-16 09:46:20 -07: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 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
Serdar Kocdemir 35db18236b Enable warnings as errors on cmake builds
And fix various compilation warnings.

Bug: N/A
Test: rebuild
Change-Id: Ife3489b29b1f2822f69d77ce4305b6b31b19d1cf
2025-03-14 14:01:26 +00:00
Yahan Zhou 1da3f99ea6 Fix Vulkan snapshot with -guest-angle
We did a few things here.

1. Update VkBindImageMemoryInfo in vkBindImageMemory2 for snapshot. In
   its implementation, vkBindImageMemory2 sometimes replaces an unboxed
   VkImage handle with a new one, which breaks snapshot. We update its
   value so that it can map to the proper one when calling snapshot
   functions. Note that there is a const cast which we might want to fix
   later.
2. Lock it properly when calling createExtraHandlesForNextApi.
3. Add support for more VkImage format. Fix mipmap extend calculation.

Now it works with -guest-angle but fails with VVL, not sure why.

Bug: 346415931
Test: manual
Change-Id: I0b3153bede12ea95e7462ddaa411d6e2fed6410b
2024-06-28 15:35:44 -07:00
Yahan Zhou f72839fde7 Do not try to add transfer src/dst for all buffers
It seems that adding transfer src/dst usages to uniform buffers will
make Chrome less stable. Remove them and rely on memory snapshot to
snapshot buffer contents.

Bug: 342414479
Test: GfxstreamEnd2EndVkSnapshotPipelineTest
Change-Id: Ie9572a7e8f015378f89f106ec628647836513d8e
2024-06-04 15:23:02 -07:00
Yahan Zhou 681b75310c Add snapshot for command buffer
Record all vkCmd* commands. Also clear them on vkResetCommandBuffer.

Also use VK_IMAGE_ASPECT_STENCIL_BIT when snapshotting stencil
images.

Bug: 330763497
Test: CanSnapshotCommandBuffer
Change-Id: I71e1d80e59cb3321f3bb120f520e633aedf182d9
2024-05-22 15:11:53 -07:00
Yahan Zhou 10f93665eb Snapshot descriptor set contents
This commmit snapshots vulkan descriptor sets. Please refer to
go/aemu-vulkan-snapshot-testing for detailed design.

For descriptors, API playback does not work because it does not provide
enough granularity. To address this issue, we shadow the states of
descriptors and rebuild a descriptor update command on snapshot load.

Currently it only works with VulkanBatchedDescriptorSetUpdate.

Bug: 332770507
Test: CanSnapshotDescriptors
Change-Id: I01bd51cd03072da9357eba2404d408e6995ffc7a
2024-05-20 14:44:31 -07:00
Yahan Zhou a6956742e0 Snapshot VkBuffer
Bug: 332770189
Test: GfxstreamEnd2EndVkSnapshotBufferTest
Change-Id: I6240d4fd872846efc31f98260139f0574def571f
2024-04-29 13:05:27 -07:00
Yahan Zhou 88df7cff15 Fix ColorBufferVk layout on snapshot load again
We have a situation that the color buffer vulkan images are transformed
into the wrong layout after snapshot load. Fix it by memorizing the
layout in snapshot.

We don't have a test for it yet as we don't really understand how to
trigger this behavior at unittest level.

Also recover layout for multi-sample images after snapshot loads. But we
still don't snapshot its content yet.

Bug: 332775761
Test: CanSubmitQueue
Change-Id: I8007f504d055041b11c3af3425cfbdbfac0553dd
2024-04-19 14:59:58 -07:00
Yahan Zhou 77d8411781 Skip snapshotting multi-sample images
Bug: 333936705
Test: GfxstreamEnd2EndVkSnapshotImageTest::MultiSampleImage
Change-Id: I8d326c8482560f586164166f1de1e257755513ba
2024-04-11 16:07:02 -07:00
Yahan Zhou 825d1290f4 Add stencil format support in snapshot
Bug: 333118418
Test: manual
Change-Id: I4dafabc083a2ebf6d44d23b6d1f25047428785ad
2024-04-05 21:25:39 +00:00
Jason Macnak 244fd722aa Adds feature for using an emulated memory type for AHBs
Adds a phyiscal device memory helper for organizing all of the
various physical memory changes and moves some of the existing
changes into the helper to avoid duplication.

Adds some tests for some of the existing physical memory changes.

Bug: b/283005889
Test: gfxstream_vkemulatedphysicaldevicememory_tests
Test: cvd start --gpu_mode=gfxstream_guest_angle_host_swiftshader
      cts -m CtsNativeHardwareTestCases
Test: GfxstreamEnd2EndTests
Test: GfxstreamEnd2EndTests on SwiftShader
Change-Id: Ieb45fad253df27e483b8a04444bd3abb5c87d1ab
2024-04-03 10:18:43 -07:00
Yahan Zhou 505f0290f9 Make it not crash during vk snapshot load
We are trying to make vk snapshot load the google Chrome home page
without crashing. With this CL it does not crash during load but would
crash with a device lost after submitting a queue (which is
unsurprising because everything is missing to snapshot vk queue).

Content of this commit includes:

 - Add dependencies for VkImageView, VkGraphicsPipelines, VkFramebuffer.
   They are necessary to tell the snapshot module the order of vk object
   creation.
 - Add vkBindImageMemory into the loading sequencey of VkImage, so that
   it would be executed before vkCreateImageView.
 - Delay the destruction of VkShaderModule. This is because other
   objects can still refer to it after it is destroyed.
 - Initialize VK backend for color buffer properly on snapshot load.
 - Save and load vk images in the same order by sorting them according
   to their boxed handle.
 - Record all the placeholder handles for vkCreateDescriptorPool. For
   performance purpose this function creates a lot of extra handles
   without real contents. We need to snapshot those handles as well.

Bug: 329506242
Test: GfxstreamEnd2EndVkSnapshotImageTest, GfxstreamEnd2EndVkSnapshotPipelineTest

Change-Id: I999c3477f861cec51ae743f11c3031be438b3ddf
2024-03-21 13:52:57 -07:00
Yahan Zhou d6daa4bb6b Snapshot vk image content in common situation
This commit snapshots vk image content by allocating a staging buffer
and copying the bytes on snapshot. It only works in the simplest setup.
Many situations are not considered in this commit, they include:

(1) the image does not support VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
layout;
(2) the image does not support VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
layout;
(3) the queue is dirty.

Also there is no performance optimization.

Implementation-wise, snapshot happens in VkDecoderGlobalState after
recording / playing back all create / bind commands. It borrows an
existing queue to run the extra vk copy commands. A temporary staging
buffer is also created for copying. Later we could optimize the code
by reusing most of the temporary objects.

Bug: 294277842
Test: GfxstreamEnd2EndVkSnapshotImageTest.ImageContent
Change-Id: I44e58c2a4edabc7ea56f97ba8789c9e43e3baa68
2024-02-02 14:22:06 -08:00