gfxstream: host: add external sync feature

Only enabled in the meson build for now, likely to
only work on certain Linux hosts + guest setups in
the future.

BUG=350965057
TEST=compile

Change-Id: I021014a744bc7c569eefe4d5fb6944f38b8552bc
diff --git a/host/features/include/gfxstream/host/Features.h b/host/features/include/gfxstream/host/Features.h
index c17fac4..cbaa5e9 100644
--- a/host/features/include/gfxstream/host/Features.h
+++ b/host/features/include/gfxstream/host/Features.h
@@ -67,6 +67,12 @@
         "memory and will be exportable via file descriptors.",
         &map,
     };
+    FeatureInfo VulkanExternalSync = {
+        "VulkanExternalSync",
+        "If enabled, Vulkan fences/semaphores will be allocated with external "
+        "create info and will be exportable via fence handles.",
+        &map,
+    };
     FeatureInfo SystemBlob = {
         "SystemBlob",
         "If enabled, virtio gpu blob resources will be allocated with shmem and "
diff --git a/host/include/gfxstream/virtio-gpu-gfxstream-renderer.h b/host/include/gfxstream/virtio-gpu-gfxstream-renderer.h
index 9a97be8..ce43ca1 100644
--- a/host/include/gfxstream/virtio-gpu-gfxstream-renderer.h
+++ b/host/include/gfxstream/virtio-gpu-gfxstream-renderer.h
@@ -255,6 +255,8 @@
     STREAM_RENDERER_FLAGS_USE_EXTERNAL_BLOB = 1 << 6,
     STREAM_RENDERER_FLAGS_USE_SYSTEM_BLOB = 1 << 7,
     STREAM_RENDERER_FLAGS_VULKAN_NATIVE_SWAPCHAIN_BIT = 1 << 8,
+    // Unstable: do not use until a release greater than 0.1.2
+    STREAM_RENDERER_FLAGS_VULKAN_EXTERNAL_SYNC = 1 << 31,
 };
 
 #endif
diff --git a/host/meson.build b/host/meson.build
index 01df94b..f807f3e 100644
--- a/host/meson.build
+++ b/host/meson.build
@@ -76,6 +76,7 @@
   aemu_snapshot_dep = dependency('aemu_snapshot')
   dl_dep = dependency('dl')
   thread_dep = dependency('threads')
+  gfxstream_host_args += '-DGFXSTREAM_UNSTABLE_VULKAN_EXTERNAL_SYNC=1'
 endif
 
 if log_level == 'error'
diff --git a/host/virtio-gpu-gfxstream-renderer.cpp b/host/virtio-gpu-gfxstream-renderer.cpp
index 7e46427..5ff4904 100644
--- a/host/virtio-gpu-gfxstream-renderer.cpp
+++ b/host/virtio-gpu-gfxstream-renderer.cpp
@@ -2502,6 +2502,8 @@
     GFXSTREAM_SET_FEATURE_ON_CONDITION(
         &features, ExternalBlob,
         renderer_flags & STREAM_RENDERER_FLAGS_USE_EXTERNAL_BLOB);
+    GFXSTREAM_SET_FEATURE_ON_CONDITION(&features, VulkanExternalSync,
+                                       renderer_flags & STREAM_RENDERER_FLAGS_VULKAN_EXTERNAL_SYNC);
     GFXSTREAM_SET_FEATURE_ON_CONDITION(
         &features, GlAsyncSwap, false);
     GFXSTREAM_SET_FEATURE_ON_CONDITION(
@@ -2779,6 +2781,10 @@
         return -EINVAL;
     }
 
+#if GFXSTREAM_UNSTABLE_VULKAN_EXTERNAL_SYNC
+    renderer_flags |= STREAM_RENDERER_FLAGS_VULKAN_EXTERNAL_SYNC;
+#endif
+
     gfxstream::host::FeatureSet features;
     int ret = parseGfxstreamFeatures(renderer_flags, renderer_features_str, features);
     if (ret) {