94 Commits
Author SHA1 Message Date
Bo Hu 46da8f3e27 [vulkan snapshot]: simplify vk update descriptor
Currently, we save all the vkUpdateDescriptorSets commands
and replay then during loading.

This leads to very large amount of commands and it is
slowing down both the saving and loading, when the emulator
has run a longer period of time.

Prior work worked around this problem by saving only the
active descriptors, but it only works with VulkanBatchedDescriptorSetUpdate
feature.

This cl improves prior work to make it work without
VulkanBatchedDescriptorSetUpdate feature.

Bug: 417788798

Change-Id: I5b83566db3723135b9d8dd2df56ad1d7f2a751ed
2025-09-11 08:25:45 +00:00
Jason Macnak 81e9cb0616 Add a vkTraceAsyncGOOGLE
... to allow sharing perfetto global flow ids between guest and host
so that combined traces can have an arrow between the guest and host
render threads to aid debugging.

Bug: b/440065361
Test: Capture guest and host trace and inspect in perfetto UI
Change-Id: Id1c34dbee40c8febc9730479d1daed37722fcd09
2025-09-04 19:31:59 +00:00
Serdar Kocdemir 515f98416c Remove unnecessary parentheses in codegen
Improve readability of the code by removing some of the
unnecessary parentheses in the generated code.
(regen auto generated code)

Bug: 329094533
Test: CI
Change-Id: I8c29b49cb58310c70820421e1fd3abea8bd00a92
2025-06-30 20:27:46 +00:00
Jason Macnak 80b5dd9788 Update snapshot decoder to handle imageless framebuffer
When `VkFramebufferCreateInfo::flags` has
`VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT`,
`VkFramebufferCreateInfo::pAttachments` should be ignored.

Bug: b/424862032
Test: cvd create \
    --gpu_mode=gfxstream_guest_angle_host_swiftshader \
    --gpu_renderer_features="VulkanSnapshots:enabled"
Change-Id: Icb5641ee31a1d155a92931c1b91777cfc54ffeca
2025-06-17 21:04:07 +00:00
Jason Macnak 39330aa245 Use VkSnapshotApiCallHandle outside of VkReconstruction
... as VkSnapshotApiCallInfo* is a pointer into a
std::vector<VkSnapshotApiCallInfo> which can be invalidated during
multi threaded VK usage when the std::vector<> is resized.

Bug: b/422483825
Test: bazel test common/end2end:gfxstream_end2end_tests \
      --graphics_drivers=gles_angle_vulkan_swiftshader \
      --test_arg="--gtest_filter=*MultiThreadedResetCommandBuffer*VulkanSnapshots*" \
      --test_arg="--gtest_repeat=100" \
      --test_output=streamed
Change-Id: I8ea16eea8792b11056d6d7f17e370f9aa045406c
2025-06-05 17:26:09 +00:00
Bo Hu 08e2c1a222 [vulkan snapshot]: handle vkUpdateDescriptorSetWithTemplateSized variants
vkUpdateDescriptorSetWithTemplateSizedGOOGLE and
vkUpdateDescriptorSetWithTemplateSized2GOOGLE

They both are treated similar to vkUpdateDescriptorSets.

Bug: 418814845
Change-Id: Idcb5639e88e7dd148d089af3c960a3beb4a7deb7
2025-05-19 18:39:08 -07:00
Bo Hu f65421571c [vulkan snapshot]: skip snapshot when api call fails
When this fails, there is no vulkan handle created, but the snapshot
saves it anyway, leading to subsequent load failures, as the saved
invalid handle (0x0) shifted the handle order.

Bug: 417788798

Change-Id: I1c19ab67dc23e01d43cccc6dae5c28d52870da23
2025-05-19 09:07:50 -07:00
Bo Hu b95fecc746 [vulkan snapshot]: handle vkCmdCopyBuffer
Bug: 417788798

Change-Id: I84c202cf82a0bfa94b265304d02b07854f5cd676
2025-05-15 11:43:08 -07:00
Bo Hu d5714e957d Merge "[vulkan snapshot]: add dependency to VkPipeline" into main 2025-05-14 16:29:25 -07:00
Bo Hu 6483057b40 [vulkan snapshot]: add dependency to VkPipeline
command buffer need this pipeline to be saved.

Bug: 417788798
Change-Id: I5e3736b292a43edf1242fa43487db9ef3ca57e5e
2025-05-14 14:27:52 -07:00
Treehugger Robot 620d727c5b Merge "Regerenate autogenerated code" into main 2025-05-14 08:39:30 -07:00
Jason Macnak d7f63e64e3 Merge "Split utils in host/decoder_common and host/renderdoc" into main 2025-05-14 08:04:02 -07:00
Serdar Kocdemir f29650f7f5 Regerenate autogenerated code
.. after recent changes on the build script due to xml file
location change.

Bug: 417150515
Test: CI
Change-Id: I04b2e40778fc8f2c832a4c9204a411fe9895dd08
2025-05-14 14:58:34 +01:00
Serdar Kocdemir 60beb01f14 Update vulkan headers to v313
Includes a small change to keep using MTLResource_id
which actually didn't make it into the spec.
A typo fix in vulkansc_raii.hpp
Fixes on end2end tests for vulkanhpp changes.
Change to enable comparison operators on handles even when
the spaceship operator is available, to avoid errors on
old compilers where they are not generated.

Bug: 417150515
Test: CI
Test: dEQP-VK.api.info.vulkan1p2
Test: atest GfxstreamEnd2EndTests
Change-Id: Ic9b9256541dde50b77c4d6d63d277bc222a64157
2025-05-14 12:36:42 +01:00
Bo Hu 50f2d42ca0 Merge "[vulkan snapshot]: handle vkResetCommandPool" into main 2025-05-13 10:41:53 -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
Serdar Kocdemir 1f77d6a2b8 Mark VK_KHR_ray_tracing_pipeline dispatch only
Bug: 417150515
Test: build
Change-Id: I543e9a24e719700a706a45f3174b8a9b74516beb
2025-05-12 23:55:50 +01:00
Bo Hu f1a77f537f [vulkan snapshot]: handle vkResetCommandPool
When this is called, the command buffers allocated
from this command pool should all reset their recording.

This call is equivalent to ask each command buffer from
this pool to do vkResetCommandBuffer.

Bug: 415349936
Change-Id: I7a9c76ab16463c16f48336fcef34f532410aac41
2025-05-07 14:41:34 -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
Bo Hu 8a413ae915 [vulkan snapshot]: save command recording
In common cases, command buffer is recorded
right before submission. re-submission of pre-recorded
command buffer multiple times is uncommon.

However, it is still a valid case that should be properly
handled by snapshot save and load.

This cl adds code inside SubDecoder to track the dependency
of each Cmd, and also snapshot save and load vkQueueFlushCommandsGOOGLE.

Bug: 415349936

Change-Id: I11b462203722518ea82609613c0874d07bf5be53
2025-05-05 16:46:19 -07:00
Jason Macnak e107241c14 Update codegen after many aemu -> gfxstream changes
Mostly just formatting changes.

Bug: b/403363880
Test: m
Change-Id: I2c114274ce81a3affda72bd732742679f2a25892
2025-05-02 14:52:58 +00: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 d76ee5f372 [vulkan snapshot] simplify dependency graph
This is an effort to simplify the dependency handling
in VkReconstruct.

A new DepGraph class is used to just record the
vk object dependency.

The save and load order is based on the time stamp,
not by topo order from dep graph anymore.

Bug: 407856927

Change-Id: Ibeb89dc01d9f1d007c3221b2dc1ce93957165df1
2025-04-08 12:47:31 -07:00
Jason Macnak 5c415a358b Remove duplicated boxed handle func declarations
... and fix up include paths.

Bug: b/369615058
Test: cvd create --gpu_mode=gfxstream_guest_angle_host_swiftshader
Change-Id: Ia407b250ae10ff1d9dc99fff32099aca61219d09
2025-02-25 08:08:39 -08:00
Jason Macnak 263fcb6348 Move the handle replay buffer into BoxedHandleManager
... since `BoxedHandleManager` should, well, manager the handles.

This simplifies `VkDecoderGlobalState` a little bit and should also
allow us to remove a bunch of functions that no longer need to
depend on `VkDecoderGlobalState`.

Bug: b/369615058
Test: cvd create --gpu_mode=gfxstream_guest_angle_host_swiftshader
Test: cvd snapshot_take --force \
                        --auto_suspend \
                        --snapshot_path=/tmp/snapshot1
Test: cvd reset -y
Test: cvd create --snapshot_path=/tmp/snapshot1
Change-Id: I9d52a12a2fe1e7394259fff0c25075fd50c7cfca
2025-02-25 08:08:38 -08:00
Jason Macnak 7cdfa7aa99 Move snapshot decoder replay into VkDecoderGlobalState
... to break the recursive behavior of the snapshot load having a callstack with
VkDecoderSnapshot -> VkReoncstruction -> VkDecoder -> VkDecoderSnapshot so that
locking and thread safety annotations can be preserved in VkDecoderSnapshot.

Follow up to aosp/3412302.

Bug: b/383139165
Test: cvd create --gpu_mode=gfxstream_guest_angle_host_swiftshader
Test: cvd snapshot_take --snapshot_path=<>
Test: cvd create --snapshot_path=<>
Change-Id: I5a914e2e81574b937d6f684fba43acc1af311c3f
2025-01-27 13:31:14 -08:00
Bo Hu d26e6581c3 [vulkan snapshot]: avoid locking mReconstructionMutex in load call
As the mReconstructionMutex will be acuquired repeatedly in the
following decoder thread, locking it at the beginning of load call
will prevent decoder from acquiring it and stall the loader.

note: this is auto-generated code, it adds back the mReconstructionMutex
back into save; but remove it from load: partially undo aosp/3412302

Bug: 370344466
Change-Id: I72735494d41456c06d44c25c8e652bad9dd75ac6
2025-01-07 10:19:13 -08:00
Bo Hu 9b589a31c4 [Vulkan Snapshot]: do not lock in save load call
The lock is too broad and can lead to double lock
later on.

Bug: 370344466

Change-Id: I9ddc97c93df8aa69db692189be290c6a71c8dd65
2024-12-13 09:20:18 -08:00
Jason Macnak c87e78861b Update VkDecoderSnapshot locking
Replace tryLock / unlock with regular scoped lock now that the
"extra handles" have been moved out of VkReconstruction and into
the VkSnapshotApiCallInfo.

Switch to regular std::mutex and std::lock_guard.

Annotate mReconstruction with GUARDED_BY to start to get more
thread safety analysis.

Bug: b/383139165
Test: m
Change-Id: I3b017887418466d3ced9119bed0ba7279ee55bdd
2024-12-12 12:00:00 -08:00
Jason Macnak 5d86d48212 Pass VkSnapshotApiCallInfo-s through VkDecoderGlobalState
... so that `VkDecoderGlobalState` can append additional information
needed for snapshotting. Specifically, `VkDecoderGlobalState` may create
additional boxed handles that are not visible directly in the API surface.
For example, `vkCreateDevice()` creates boxed handles for the `VkQueue`-s
and `vkCreateDescriptorPool()` creates boxed handles for pre-allocated
`VkDescriptorSets`. These boxed handles are not recoverable from the API
for `vkCreateDevice()` nor `vkCreateDescriptorPool()` directly. This was
previously worked around by just sticking the extra boxed handles in
`VkReconstruction::mExtraHandlesForNextApi` but this is not thread safe.
Instead, let's give `VkDecoderGlobalState` and `VkDecoderSnapshot` exclusive
access to individual `VkSnapshotApiCallInfo` objects.

Bug: b/383139165
Test: cvd create --gpu_mode=gfxstream_guest_angle_host_swiftshader
Change-Id: I158b12d38584ca964af841e77d1d58a9f6901613
2024-12-12 08:49:24 -08:00
Jason Macnak 201e206613 Simplify ApiInfo
Removes the additional saving of opcode and packet len as this is
all available from within the packet itself.

Removes the "trace" position from `VulkanMemReadingStream` as these
seemed to only be used for getting the packet start and packet size
but these are already available.

Bug: b/383139165
Test: cvd create --gpu_mode=gfxstream_guest_angle_host_swiftshader
Change-Id: I2842c866a0bf10d117a8908fa6a0a94c4b83ac53
2024-12-11 15:30:36 -08:00
Bo Hu 8f8cdf6755 Merge "[Vulkan Snapshot]: handle DescriptorSet allocate and update" into main 2024-11-12 16:59:10 +00:00
Treehugger Robot 0926921d23 Merge "Update auto-generated comments." into main 2024-11-11 17:37:37 +00:00
Joshua Duong 3e073ad037 Update auto-generated comments.
codegen was moved from gfxstream-protocols to mesa3d.

Bug: 377677250
Test: N/A
Change-Id: I56674e2fb312a9faf6f6e42391b08f514f638ec0
2024-11-11 08:15:29 -08:00
Bo Hu b32fb06f07 [Vulkan Snapshot]: handle DescriptorSet allocate and update
1, This will make sure we property save and load DescriptorSet
when VulkanBatchedDescriptorSetUpdate feature is turned off.

2, also introduce generic vk handle to represent action api
such as vkUpddateDescriptorSets, vkCmd***, so they can fit
into the dependency graph to make save and load easier

Bug: 370344466
Change-Id: I3fbeeb46c88dd2f397dafc95f5c1eb143fb75062
2024-11-10 21:43:37 -08:00
Bo Hu 699158abd4 [Vulkan Snapshot]: avoid double boxing commandBuffer
They are already boxed when passed to snapshoter.

Bug: 370344466

Change-Id: I4b37496a699c6a1d5f9dc1c161a8a2d287a0cc31
2024-11-08 14:32:06 -08:00
Serdar Kocdemir 4d94b08137 Fix vkCmdSetLineStippleKHR decoding
Add missing alias for the vkCmd function to the vk.xml to be
able to use it correctly at the host side decoder and subdecoder.

Bug: 357829977
Test: dEQP-VK.dynamic_state.monolithic.line_width.
Change-Id: If81e932ae9527eab8d0b09e2c3446f2f4c526bc6
2024-10-28 19:50:35 +00:00
Serdar Kocdemir 8751452348 Keep VK_EXT_line_rasterization in codegen
Adding the generated code back for the EXT version of the extension.

Bug: 357829977
Test: deqp
Change-Id: Ibe853ace8234fac725c2653805fce48a21d93784
2024-10-28 18:18:27 +00:00
Gurchetan Singh 838dd1d614 gfxstream: rerun codegen from external/mesa3d
With Mesa in the Emulator manifest, all Google projects
can just run codegen from that directory.

It has a deeper Git history, but the biggest win of the
dual upstream strategy is it only implies two levels
of synchronization:

1) mesa -> AOSP mesa (doable via Skia autorollers, other teams do
		      it)
2) AOSP main -> mesa (doable by a rotation of even long-term Gitlab
                      CI bot)

(2) depends on the volume of commits, which data indicates is
5/per month maybe.

BUG=374306378
TEST=CI

Change-Id: I667e2b4518837326c13cbac4af6d6d2ea7402112
2024-10-21 14:22:42 -07:00
Serdar Kocdemir d41a3b97b5 Update autogen for VK_KHR_line_rasterization
With recent mesa related changes, we started using a recent version of
vk.xml and this promoted extension was being used as EXT in our codegen
scripts. This resulted in some code loss, skips on pNext chain of
commands sent from the guest side and eventually CTS/dEQP failures.

Updating vulkan headers partially with this change to accomodate KHR
version of the extension correctly.

Bug: b/357832421
Test: dEQP-VK.api.info.vulkan1p2_limits_validation*
Change-Id: I53fbb2742a846dbce55080deb46f5e4fd46e6c11
2024-10-10 10:57:01 +01:00
Gurchetan Singh 4943dccf17 gfxstream: modify script to point to gfxstream version of codgen
We have two versions of the same code, and we keep it
in sync via batch updates.

BUG=369906368
TEST=CI

Change-Id: I6852092fdd9e8a72d9921e693870722337c376cb
2024-09-30 21:27:30 +00:00
Gurchetan Singh 08f5c21ebc gfxstream: fix scripts/generate-gfxstream-vulkan.sh
Mostly just change the locations of directories.

One exception is aosp/3271678, which needs to land in the
Mesa codegen directory.

For workflows without an AOSP tree, one can just pass in
the path to Mesa tree.

Mesa uses a newer version of vk.xml than the host does,
so some changes are observed.

BUG=369200554
TEST=generate-gfxstream-vulkan.sh in AOSP

or

cd ~/
git clone https://gitlab.freedesktop.org/mesa/mesa.git
cd ${gfxstream_dir}
./scripts/generate-gfxstream-vulkan.sh ~/mesa

Change-Id: I5a023ed4d8788a31f352d017f321656c7b7a7410
2024-09-25 08:56:30 -07:00
Serdar Kocdemir 9d85314d53 Add VkPrivateDataSlot handle type for codegen
Private data slot types are required to support VK_EXT_private_data
extension. dEQP tests require some additional changes for handle
remapping over uint64_t types, which will be submitted later.

Bug: 368009403
Test: codegen & build & presubmit
Change-Id: If97478293fd8009a4279861fcbd780069708ab0f
2024-09-23 10:26:26 +00:00
Yahan Zhou f4551c0011 [Vulkan Snapshot] Add dependency graphics pipeline -> render pass
Bug: 333460261
Test: manual
Change-Id: Ia2b891a001743a836f21d9fb683cd3ab12073cbc
2024-09-18 15:09:15 -07:00
Treehugger Robot b672c0000c Merge changes from topic "gfxstream-drm-modifier" into main
* changes:
  vkCreateInfo: support VkImageDrmFormatModifierListCreateInfoEXT
  vkGetPhysicalDeviceImageFormatProperties2: support drm modifiers
  vkAllocateMemory: support DRM format modifiers for dmabuf memory
  Force request VK_EXT_image_drm_format_modifier in vkCreateDevice
  Enable VK_EXT_image_drm_format_modifier on Linux guests
  Enable VK_EXT_image_drm_format_modifier in cerealgenerator.py
  Revert "HACK: gfxstream: guest: mesa: force non-modifier path"
  Add missing includes
2024-08-08 15:06:26 +00:00
Marcin Radomski 245f455a56 Enable VK_EXT_image_drm_format_modifier in cerealgenerator.py
Add the extension to list in cerealgenerator.py, rerun
scripts/generate-gfxstream-vulkan.sh

Bug: 328011003
Test: vkvcube-wayland + kumquat on the entire CL chain
Change-Id: If5cf2b04e9fb03e2f484fee12bbe13572c945b8b
2024-08-08 10:22:21 +02:00
Yahan Zhou 5fa84090ee [Vulkan Snapshot] tryLock when an API might create extra handles
We acquire the lock when createExtraHandlecsForNextApi is called. But
depending on config, vkCreateDescriptorPool may or may not call
createExtraHandlesForNextApi, which results in inconsistency of the lock
state when calling snapshot()->vkCreateDescriptorPool.

We add a tryLock so that it always acquires the lock before modifying
mReconstruction.

Bug: 349648408
Test: VulkanBatchedDescriptorSetUpdate
Change-Id: I8f582580e01916edce042db192c497c8dd7a32d2
2024-08-07 14:59:12 -07:00
sergiuferentz 4023855ed3 Adding support for VK_EXT_external_memory_host extension
Supports querying supported memory indexes for host allocations.

Bug: 354139765
Test: N/A
Change-Id: I92bddd3a21c509c1dbcd04aa92591460f553f841
2024-07-23 16:16:32 +00:00
Serdar Kocdemir eae7f2acf9 Add extensions used in test applications
Add VK_KHR_ray_tracing_pipeline and VK_KHR_pipeline_library
extensions support which are used by some test applications.

Bug: 351729443
Test: run benchmark tests on MacOS
Change-Id: Ice76fbc1b431b6ee74b8df587719fe4f13f457a8
2024-07-12 10:33:25 +00:00
Gurchetan Singh 4bd2f4b291 gfxstream: host: introduce vkGetSemaphoreGOOGLE
New protocol which instructs the host to share sync descriptor
with ExternalObjectManager.

BUG=350965057
TEST=compile

Change-Id: Ia009c0278a02d631ff2f8edd18bee85bbaa030f3
2024-07-10 07:59:48 -07:00