add missing fuchsia ICD code

This allows the full goldfish vulkan ICD to be built outside the
fuchsia tree.

Test: none
Bug: 111137294
Change-Id: I02fe24617e114e0c07dc010bb7268ec6124af48e
Merged-In: I62065020349dfc3e34f93380abcab22c31a7e856
diff --git a/BUILD.gn b/BUILD.gn
index 5e63b19..385ae8d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1,4 +1,4 @@
-source_set("goldfish_vulkan") {
+shared_library("vulkan_goldfish") {
   sources = [
     "android-emu/android/base/AlignedBuf.cpp",
     "android-emu/android/base/AlignedBuf.h",
@@ -84,6 +84,8 @@
     "-Wno-missing-field-initializers",
   ]
 
+  ldflags = [ "-static-libstdc++" ]
+
   if (target_os == "fuchsia") {
     sources += [ "fuchsia/port.cc" ]
 
diff --git a/system/vulkan/goldfish_vulkan.cpp b/system/vulkan/goldfish_vulkan.cpp
index 18a9424..3b38994 100644
--- a/system/vulkan/goldfish_vulkan.cpp
+++ b/system/vulkan/goldfish_vulkan.cpp
@@ -208,6 +208,8 @@
 
 namespace {
 
+#ifdef VK_USE_PLATFORM_ANDROID_KHR
+
 int OpenDevice(const hw_module_t* module, const char* id, hw_device_t** device);
 
 hw_module_methods_t goldfish_vulkan_module_methods = {
@@ -232,6 +234,8 @@
     return 0;
 }
 
+#endif
+
 #define VK_HOST_CONNECTION(ret) \
     HostConnection *hostCon = HostConnection::get(); \
     if (!hostCon) { \
@@ -498,6 +502,8 @@
     return (PFN_vkVoidFunction)(goldfish_vk::goldfish_vulkan_get_instance_proc_address(instance, name));
 }
 
+#ifdef VK_USE_PLATFORM_ANDROID_KHR
+
 hwvulkan_device_t goldfish_vulkan_device = {
     .common = {
         .tag = HARDWARE_DEVICE_TAG,
@@ -517,7 +523,19 @@
 
     if (strcmp(id, HWVULKAN_DEVICE_0) == 0) {
         *device = &goldfish_vulkan_device.common;
+        goldfish_vk::ResourceTracker::get();
+        return 0;
+    }
+    return -ENOENT;
+}
+
+#endif
+
 #ifdef VK_USE_PLATFORM_FUCHSIA
+
+class VulkanDevice {
+public:
+    VulkanDevice() {
         goldfish_vk::ResourceTracker::get()->setColorBufferFunctions(
             [](uint32_t width, uint32_t height, uint32_t format) {
                 VK_HOST_CONNECTION((uint32_t)0)
@@ -532,12 +550,29 @@
                 VK_HOST_CONNECTION()
                 rcEnc->rcCloseColorBuffer(rcEnc, id);
             });
-#else
-        goldfish_vk::ResourceTracker::get();
-#endif
-        return 0;
     }
-    return -ENOENT;
+
+    static VulkanDevice& GetInstance() {
+        static VulkanDevice g_instance;
+        return g_instance;
+    }
+
+    PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name) {
+        return ::GetInstanceProcAddr(instance, name);
+    }
+};
+
+extern "C" __attribute__((visibility("default"))) PFN_vkVoidFunction
+vk_icdGetInstanceProcAddr(VkInstance instance, const char* name) {
+    return VulkanDevice::GetInstance().GetInstanceProcAddr(instance, name);
 }
 
+extern "C" __attribute__((visibility("default"))) VkResult
+vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion) {
+    *pSupportedVersion = std::min(*pSupportedVersion, 3u);
+    return VK_SUCCESS;
+}
+
+#endif
+
 } // namespace