Added VkResult arg to VK_EMU_INIT_RETURN_ON_ERROR macro

This is for downstream branches to make use of the VkResult
without having to define a new macro.

Test: Built and ran emulator
Change-Id: Ie2705898538d04baa6efc11e15866ed611ca7d06
diff --git a/stream-servers/vulkan/VkCommonOperations.cpp b/stream-servers/vulkan/VkCommonOperations.cpp
index 6f5808a..31add1c 100644
--- a/stream-servers/vulkan/VkCommonOperations.cpp
+++ b/stream-servers/vulkan/VkCommonOperations.cpp
@@ -471,10 +471,12 @@
 }
 
 VkEmulation* createGlobalVkEmulation(VulkanDispatch* vk) {
-#define VK_EMU_INIT_RETURN_ON_ERROR(...) \
-    do {                                 \
-        ERR(__VA_ARGS__);                \
-        return nullptr;                  \
+// Downstream branches can provide abort logic or otherwise use result without a new macro
+#define VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(res, ...) \
+    do {                                               \
+        (void)res; /* no-op of unused param*/          \
+        ERR(__VA_ARGS__);                              \
+        return nullptr;                                \
     } while (0)
 
     AutoLock lock(sVkEmulationLock);
@@ -482,7 +484,7 @@
     if (sVkEmulation) return sVkEmulation;
 
     if (!emugl::vkDispatchValid(vk)) {
-        VK_EMU_INIT_RETURN_ON_ERROR("Dispatch is invalid.");
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(ABORT_REASON_OTHER, "Dispatch is invalid.");
     }
 
     sVkEmulation = new VkEmulation;
@@ -570,8 +572,8 @@
     VkResult res = gvk->vkCreateInstance(&instCi, nullptr, &sVkEmulation->instance);
 
     if (res != VK_SUCCESS) {
-        VK_EMU_INIT_RETURN_ON_ERROR("Failed to create Vulkan instance. Error %s.",
-                                    string_VkResult(res));
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(res, "Failed to create Vulkan instance. Error %s.",
+                                             string_VkResult(res));
     }
 
     // Create instance level dispatch.
@@ -604,8 +606,8 @@
             VkResult res = gvk->vkCreateInstance(&instCi, nullptr, &sVkEmulation->instance);
 
             if (res != VK_SUCCESS) {
-                VK_EMU_INIT_RETURN_ON_ERROR("Failed to create Vulkan 1.1 instance. Error %s.",
-                                            string_VkResult(res));
+                VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(
+                    res, "Failed to create Vulkan 1.1 instance. Error %s.", string_VkResult(res));
             }
 
             init_vulkan_dispatch_from_instance(vk, sVkEmulation->instance, sVkEmulation->ivk);
@@ -641,12 +643,14 @@
             vk->vkGetInstanceProcAddr(sVkEmulation->instance, "vkSetMTLTextureMVK"));
 
         if (!sVkEmulation->setMTLTextureFunc) {
-            VK_EMU_INIT_RETURN_ON_ERROR("Cannot find vkSetMTLTextureMVK.");
+            VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(ABORT_REASON_OTHER,
+                                                 "Cannot find vkSetMTLTextureMVK.");
         }
         sVkEmulation->getMTLTextureFunc = reinterpret_cast<PFN_vkGetMTLTextureMVK>(
             vk->vkGetInstanceProcAddr(sVkEmulation->instance, "vkGetMTLTextureMVK"));
         if (!sVkEmulation->getMTLTextureFunc) {
-            VK_EMU_INIT_RETURN_ON_ERROR("Cannot find vkGetMTLTextureMVK.");
+            VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(ABORT_REASON_OTHER,
+                                                 "Cannot find vkGetMTLTextureMVK.");
         }
         // LOG(VERBOSE) << "Instance supports VK_MVK_moltenvk.";
     }
@@ -659,7 +663,7 @@
     // LOG(VERBOSE) << "Found " << physdevCount << " Vulkan physical devices.";
 
     if (physdevCount == 0) {
-        VK_EMU_INIT_RETURN_ON_ERROR("No physical devices available.");
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(ABORT_REASON_OTHER, "No physical devices available.");
     }
 
     std::vector<VkEmulation::DeviceSupportInfo> deviceInfos(physdevCount);
@@ -872,7 +876,8 @@
     }
 
     if (!sVkEmulation->deviceInfo.hasGraphicsQueueFamily) {
-        VK_EMU_INIT_RETURN_ON_ERROR("No Vulkan devices with graphics queues found.");
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(ABORT_REASON_OTHER,
+                                             "No Vulkan devices with graphics queues found.");
     }
 
     auto deviceVersion = sVkEmulation->deviceInfo.physdevProps.apiVersion;
@@ -942,8 +947,8 @@
     ivk->vkCreateDevice(sVkEmulation->physdev, &dCi, nullptr, &sVkEmulation->device);
 
     if (res != VK_SUCCESS) {
-        VK_EMU_INIT_RETURN_ON_ERROR("Failed to create Vulkan device. Error %s.",
-                                    string_VkResult(res));
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(res, "Failed to create Vulkan device. Error %s.",
+                                             string_VkResult(res));
     }
 
     // device created; populate dispatch table
@@ -967,13 +972,15 @@
             reinterpret_cast<PFN_vkGetImageMemoryRequirements2KHR>(
                 dvk->vkGetDeviceProcAddr(sVkEmulation->device, "vkGetImageMemoryRequirements2KHR"));
         if (!sVkEmulation->deviceInfo.getImageMemoryRequirements2Func) {
-            VK_EMU_INIT_RETURN_ON_ERROR("Cannot find vkGetImageMemoryRequirements2KHR.");
+            VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(ABORT_REASON_OTHER,
+                                                 "Cannot find vkGetImageMemoryRequirements2KHR.");
         }
         sVkEmulation->deviceInfo.getBufferMemoryRequirements2Func =
             reinterpret_cast<PFN_vkGetBufferMemoryRequirements2KHR>(dvk->vkGetDeviceProcAddr(
                 sVkEmulation->device, "vkGetBufferMemoryRequirements2KHR"));
         if (!sVkEmulation->deviceInfo.getBufferMemoryRequirements2Func) {
-            VK_EMU_INIT_RETURN_ON_ERROR("Cannot find vkGetBufferMemoryRequirements2KHR");
+            VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(ABORT_REASON_OTHER,
+                                                 "Cannot find vkGetBufferMemoryRequirements2KHR");
         }
 #ifdef _WIN32
         sVkEmulation->deviceInfo.getMemoryHandleFunc =
@@ -984,7 +991,8 @@
             dvk->vkGetDeviceProcAddr(sVkEmulation->device, "vkGetMemoryFdKHR"));
 #endif
         if (!sVkEmulation->deviceInfo.getMemoryHandleFunc) {
-            VK_EMU_INIT_RETURN_ON_ERROR("Cannot find vkGetMemory(Fd|Win32Handle)KHR");
+            VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(ABORT_REASON_OTHER,
+                                                 "Cannot find vkGetMemory(Fd|Win32Handle)KHR");
         }
     }
 
@@ -1013,8 +1021,9 @@
                                                       &sVkEmulation->commandPool);
 
     if (poolCreateRes != VK_SUCCESS) {
-        VK_EMU_INIT_RETURN_ON_ERROR("Failed to create command pool. Error: %s.",
-                                    string_VkResult(poolCreateRes));
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(poolCreateRes,
+                                             "Failed to create command pool. Error: %s.",
+                                             string_VkResult(poolCreateRes));
     }
 
     VkCommandBufferAllocateInfo cbAi = {
@@ -1029,8 +1038,9 @@
         dvk->vkAllocateCommandBuffers(sVkEmulation->device, &cbAi, &sVkEmulation->commandBuffer);
 
     if (cbAllocRes != VK_SUCCESS) {
-        VK_EMU_INIT_RETURN_ON_ERROR("Failed to allocate command buffer. Error: %s.",
-                                    string_VkResult(cbAllocRes));
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(cbAllocRes,
+                                             "Failed to allocate command buffer. Error: %s.",
+                                             string_VkResult(cbAllocRes));
     }
 
     VkFenceCreateInfo fenceCi = {
@@ -1043,8 +1053,9 @@
                                                  &sVkEmulation->commandBufferFence);
 
     if (fenceCreateRes != VK_SUCCESS) {
-        VK_EMU_INIT_RETURN_ON_ERROR("Failed to create fence for command buffer. Error: %s.",
-                                    string_VkResult(fenceCreateRes));
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(
+            fenceCreateRes, "Failed to create fence for command buffer. Error: %s.",
+            string_VkResult(fenceCreateRes));
     }
 
     // At this point, the global emulation state's logical device can alloc
@@ -1068,8 +1079,9 @@
         dvk->vkCreateBuffer(sVkEmulation->device, &bufCi, nullptr, &sVkEmulation->staging.buffer);
 
     if (bufCreateRes != VK_SUCCESS) {
-        VK_EMU_INIT_RETURN_ON_ERROR("Failed to create staging buffer index. Error: %s.",
-                                    string_VkResult(bufCreateRes));
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(bufCreateRes,
+                                             "Failed to create staging buffer index. Error: %s.",
+                                             string_VkResult(bufCreateRes));
     }
 
     VkMemoryRequirements memReqs;
@@ -1083,24 +1095,29 @@
                                   &sVkEmulation->staging.memory.typeIndex);
 
     if (!gotStagingTypeIndex) {
-        VK_EMU_INIT_RETURN_ON_ERROR("Failed to determine staging memory type index.");
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(ABORT_REASON_OTHER,
+                                             "Failed to determine staging memory type index.");
     }
 
     if (!((1 << sVkEmulation->staging.memory.typeIndex) & memReqs.memoryTypeBits)) {
-        VK_EMU_INIT_RETURN_ON_ERROR(
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(
+            ABORT_REASON_OTHER,
             "Failed: Inconsistent determination of memory type index for staging buffer");
     }
 
     if (!allocExternalMemory(dvk, &sVkEmulation->staging.memory, false /* not external */,
                              kNullopt /* deviceAlignment */)) {
-        VK_EMU_INIT_RETURN_ON_ERROR("Failed to allocate memory for staging buffer.");
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(ABORT_REASON_OTHER,
+                                             "Failed to allocate memory for staging buffer.");
     }
 
     VkResult stagingBufferBindRes = dvk->vkBindBufferMemory(
         sVkEmulation->device, sVkEmulation->staging.buffer, sVkEmulation->staging.memory.memory, 0);
 
     if (stagingBufferBindRes != VK_SUCCESS) {
-        VK_EMU_INIT_RETURN_ON_ERROR("Failed to bind memory for staging buffer.");
+        VK_EMU_INIT_RETURN_OR_ABORT_ON_ERROR(stagingBufferBindRes,
+                                             "Failed to bind memory for staging buffer. Error %s.",
+                                             string_VkResult(stagingBufferBindRes));
     }
 
     // LOG(VERBOSE) << "Vulkan global emulation state successfully initialized.";