Snap for 7506386 from 57caf0895f596a617fd1d9b56068e7fc08e70476 to sc-release

Change-Id: Icc342cd8a3d9dd6533f486c6520c24ed426a56b1
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index 44c26c2..df9c0fb 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -147,6 +147,18 @@
     // Returns true if it supports ycbcr conversion for samplers
     bool supportsYcbcrConversion() const { return fSupportsYcbcrConversion; }
 
+    // Returns the number of descriptor slots used by immutable ycbcr VkImages.
+    //
+    // TODO: We should update this to return a count for a specific format or external format. We
+    // can use vkGetPhysicalDeviceImageFormatProperties2 with a
+    // VkSamplerYcbcrConversionImageFormatProperties to query this. However, right now that call
+    // does not support external android formats which is where the majority of ycbcr images are
+    // coming from. So for now we stay safe and always return 3 here which is the max value that the
+    // count could be for any format.
+    uint32_t ycbcrCombinedImageSamplerDescriptorCount() const {
+        return 3;
+    }
+
     // Returns true if the device supports protected memory.
     bool supportsProtectedMemory() const { return fSupportsProtectedMemory; }
 
diff --git a/src/gpu/vk/GrVkDescriptorSetManager.cpp b/src/gpu/vk/GrVkDescriptorSetManager.cpp
index ae99342..14cb1b0 100644
--- a/src/gpu/vk/GrVkDescriptorSetManager.cpp
+++ b/src/gpu/vk/GrVkDescriptorSetManager.cpp
@@ -78,6 +78,7 @@
         uint32_t numBindings = visibilities.count();
         std::unique_ptr<VkDescriptorSetLayoutBinding[]> dsSamplerBindings(
                 new VkDescriptorSetLayoutBinding[numBindings]);
+        *descCountPerSet = 0;
         for (uint32_t i = 0; i < numBindings; ++i) {
             uint32_t visibility = visibilities[i];
             dsSamplerBindings[i].binding = i;
@@ -86,8 +87,10 @@
             dsSamplerBindings[i].stageFlags = visibility_to_vk_stage_flags(visibility);
             if (VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER == type) {
                 if (immutableSamplers[i]) {
+                    (*descCountPerSet) += gpu->vkCaps().ycbcrCombinedImageSamplerDescriptorCount();
                     dsSamplerBindings[i].pImmutableSamplers = immutableSamplers[i]->samplerPtr();
                 } else {
+                    (*descCountPerSet)++;
                     dsSamplerBindings[i].pImmutableSamplers = nullptr;
                 }
             }
@@ -117,8 +120,6 @@
         if (result != VK_SUCCESS) {
             return false;
         }
-
-        *descCountPerSet = visibilities.count();
     } else if (type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) {
         static constexpr int kUniformDescPerSet = 1;
         SkASSERT(kUniformDescPerSet == visibilities.count());