Snap for 11034692 from a6aeac644e337188b5e0d6f4b79cbee16a75ab7b to mainline-conscrypt-release

Change-Id: I28687f93dfd069cceef46dd243aad41ca6728a35
diff --git a/android-emu/aemu/base/threads/AndroidWorkPool.cpp b/android-emu/aemu/base/threads/AndroidWorkPool.cpp
index b5baa41..f4e9cde 100644
--- a/android-emu/aemu/base/threads/AndroidWorkPool.cpp
+++ b/android-emu/aemu/base/threads/AndroidWorkPool.cpp
@@ -131,7 +131,7 @@
 
         while (conditionFunc()) {
             doWait(currTimeout);
-            if (!conditionFunc()) {
+            if (conditionFunc()) {
                 // Decrement timeout for wakeups
                 uint64_t nextTime = currTimeUs();
                 WorkPool::TimeoutUs waited = 
diff --git a/system/vulkan_enc/ResourceTracker.cpp b/system/vulkan_enc/ResourceTracker.cpp
index 906da0f..d5ae1d3 100644
--- a/system/vulkan_enc/ResourceTracker.cpp
+++ b/system/vulkan_enc/ResourceTracker.cpp
@@ -1677,7 +1677,7 @@
             .usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |  VK_IMAGE_USAGE_TRANSFER_DST_BIT |
                         VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
                         VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT,
-            .initialLayout = VK_IMAGE_LAYOUT_MAX_ENUM,
+            .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
         };
         VkImage image = VK_NULL_HANDLE;
         VkResult res = enc->vkCreateImage(device, &createInfo, nullptr, &image, true /* do lock */);
@@ -4109,6 +4109,11 @@
         VkEncoder* enc = (VkEncoder*)context;
 
         VkImageCreateInfo localCreateInfo = vk_make_orphan_copy(*pCreateInfo);
+        if (localCreateInfo.sharingMode != VK_SHARING_MODE_CONCURRENT) {
+            localCreateInfo.queueFamilyIndexCount = 0;
+            localCreateInfo.pQueueFamilyIndices = nullptr;
+        }
+
         vk_struct_chain_iterator structChainIter = vk_make_chain_iterator(&localCreateInfo);
         VkExternalMemoryImageCreateInfo localExtImgCi;
 
@@ -6876,7 +6881,16 @@
                 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT;
         }
 #else
-        if (pExternalSemaphoreInfo->handleType ==
+        const VkSemaphoreTypeCreateInfo* semaphoreTypeCi =
+            vk_find_struct<VkSemaphoreTypeCreateInfo>(pExternalSemaphoreInfo);
+        bool isSemaphoreTimeline = semaphoreTypeCi != nullptr && semaphoreTypeCi->semaphoreType == VK_SEMAPHORE_TYPE_TIMELINE;
+        if (isSemaphoreTimeline) {
+            // b/304373623
+            // dEQP-VK.api.external.semaphore.sync_fd#info_timeline
+            pExternalSemaphoreProperties->compatibleHandleTypes = 0;
+            pExternalSemaphoreProperties->exportFromImportedHandleTypes = 0;
+            pExternalSemaphoreProperties->externalSemaphoreFeatures = 0;
+        } else if (pExternalSemaphoreInfo->handleType ==
             VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT) {
             pExternalSemaphoreProperties->compatibleHandleTypes |=
                 VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
diff --git a/system/vulkan_enc/goldfish_vk_counting_guest.cpp b/system/vulkan_enc/goldfish_vk_counting_guest.cpp
index ed2e230..e9529d8 100644
--- a/system/vulkan_enc/goldfish_vk_counting_guest.cpp
+++ b/system/vulkan_enc/goldfish_vk_counting_guest.cpp
@@ -1558,10 +1558,16 @@
     (void)count;
     uint32_t hasRasterization = 1;
     if (featureBits & VULKAN_STREAM_FEATURE_IGNORED_HANDLES_BIT) {
-        hasRasterization = (((0 == toCount->pRasterizationState))
-                                ? (0)
-                                : (!((*(toCount->pRasterizationState)).rasterizerDiscardEnable)));
-        *count += 4;
+        hasRasterization =
+            ((((0 == toCount->pRasterizationState))
+                  ? (0)
+                  : (!((*(toCount->pRasterizationState)).rasterizerDiscardEnable))) ||
+             (((0 == toCount->pDynamicState))
+                  ? (0)
+                  : (arrayany((*(toCount->pDynamicState)).pDynamicStates, 0,
+                              (*(toCount->pDynamicState)).dynamicStateCount, [](VkDynamicState s) {
+                                  return (s == VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE);
+                              }))));
     }
     uint32_t hasTessellation = 1;
     if (featureBits & VULKAN_STREAM_FEATURE_IGNORED_HANDLES_BIT) {
diff --git a/system/vulkan_enc/goldfish_vk_marshaling_guest.cpp b/system/vulkan_enc/goldfish_vk_marshaling_guest.cpp
index ac43880..730b8ee 100644
--- a/system/vulkan_enc/goldfish_vk_marshaling_guest.cpp
+++ b/system/vulkan_enc/goldfish_vk_marshaling_guest.cpp
@@ -2808,9 +2808,16 @@
     uint32_t hasRasterization = 1;
     if (vkStream->getFeatureBits() & VULKAN_STREAM_FEATURE_IGNORED_HANDLES_BIT) {
         hasRasterization =
-            (((0 == forMarshaling->pRasterizationState))
-                 ? (0)
-                 : (!((*(forMarshaling->pRasterizationState)).rasterizerDiscardEnable)));
+            ((((0 == forMarshaling->pRasterizationState))
+                  ? (0)
+                  : (!((*(forMarshaling->pRasterizationState)).rasterizerDiscardEnable))) ||
+             (((0 == forMarshaling->pDynamicState))
+                  ? (0)
+                  : (arrayany((*(forMarshaling->pDynamicState)).pDynamicStates, 0,
+                              (*(forMarshaling->pDynamicState)).dynamicStateCount,
+                              [](VkDynamicState s) {
+                                  return (s == VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE);
+                              }))));
         uint32_t cgen_var_0 = (uint32_t)hasRasterization;
         vkStream->putBe32(cgen_var_0);
     }
diff --git a/system/vulkan_enc/goldfish_vk_reserved_marshaling_guest.cpp b/system/vulkan_enc/goldfish_vk_reserved_marshaling_guest.cpp
index d06ebd9..1676c86 100644
--- a/system/vulkan_enc/goldfish_vk_reserved_marshaling_guest.cpp
+++ b/system/vulkan_enc/goldfish_vk_reserved_marshaling_guest.cpp
@@ -2117,9 +2117,16 @@
     uint32_t hasRasterization = 1;
     if (vkStream->getFeatureBits() & VULKAN_STREAM_FEATURE_IGNORED_HANDLES_BIT) {
         hasRasterization =
-            (((0 == forMarshaling->pRasterizationState))
-                 ? (0)
-                 : (!((*(forMarshaling->pRasterizationState)).rasterizerDiscardEnable)));
+            ((((0 == forMarshaling->pRasterizationState))
+                  ? (0)
+                  : (!((*(forMarshaling->pRasterizationState)).rasterizerDiscardEnable))) ||
+             (((0 == forMarshaling->pDynamicState))
+                  ? (0)
+                  : (arrayany((*(forMarshaling->pDynamicState)).pDynamicStates, 0,
+                              (*(forMarshaling->pDynamicState)).dynamicStateCount,
+                              [](VkDynamicState s) {
+                                  return (s == VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE);
+                              }))));
         uint32_t cgen_var_0 = (uint32_t)hasRasterization;
         memcpy((*ptr), &cgen_var_0, 4);
         android::base::Stream::toBe32((uint8_t*)(*ptr));
diff --git a/system/vulkan_enc/vk_struct_id.h b/system/vulkan_enc/vk_struct_id.h
index 7fc535c..355b07f 100644
--- a/system/vulkan_enc/vk_struct_id.h
+++ b/system/vulkan_enc/vk_struct_id.h
@@ -81,6 +81,7 @@
 REGISTER_VK_STRUCT_ID(VkBufferDeviceAddressCreateInfoEXT, VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_CREATE_INFO_EXT);
 REGISTER_VK_STRUCT_ID(VkGraphicsPipelineCreateInfo, VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO);
 REGISTER_VK_STRUCT_ID(VkPipelineRenderingCreateInfo, VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO);
+REGISTER_VK_STRUCT_ID(VkPhysicalDeviceExternalSemaphoreInfo, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO);
 
 #undef REGISTER_VK_STRUCT_ID