<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Sep 15, 2017 at 3:54 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On Fri, Sep 15, 2017 at 7:11 AM, Lionel Landwerlin <span dir="ltr"><<a href="mailto:lionel.g.landwerlin@intel.com" target="_blank">lionel.g.landwerlin@intel.com</a><wbr>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Signed-off-by: Lionel Landwerlin <<a href="mailto:lionel.g.landwerlin@intel.com" target="_blank">lionel.g.landwerlin@intel.com</a><wbr>><br>
---<br>
 src/intel/vulkan/anv_descript<wbr>or_set.c            | 107 +++++++++++++++++------<br>
 src/intel/vulkan/anv_nir_appl<wbr>y_pipeline_layout.c |  44 +++++-----<br>
 src/intel/vulkan/anv_private.<wbr>h                   |  24 ++++-<br>
 src/intel/vulkan/genX_cmd_buf<wbr>fer.c               |  14 ++-<br>
 src/intel/vulkan/genX_state.<wbr>c                    |  81 +++++++++--------<br>
 5 files changed, 178 insertions(+), 92 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_descrip<wbr>tor_set.c b/src/intel/vulkan/anv_descrip<wbr>tor_set.c<br>
index 91387c065e4..4e29310f5fa 100644<br>
--- a/src/intel/vulkan/anv_descrip<wbr>tor_set.c<br>
+++ b/src/intel/vulkan/anv_descrip<wbr>tor_set.c<br>
@@ -35,6 +35,21 @@<br>
  * Descriptor set layouts.<br>
  */<br>
<br>
+static uint32_t<br>
+layout_binding_get_descriptor<wbr>_count(const VkDescriptorSetLayoutBinding *binding)<br>
+{<br>
+   if (binding->pImmutableSamplers == NULL)<br>
+      return binding->descriptorCount;<br>
+<br>
+   uint32_t immutable_sampler_count = 0;<br>
+   for (uint32_t i = 0; i < binding->descriptorCount; i++) {<br>
+      ANV_FROM_HANDLE(anv_sampler, sampler, binding->pImmutableSamplers[i]<wbr>);<br>
+      immutable_sampler_count += sampler->nb_planes;<br>
+   }<br>
+<br>
+   return immutable_sampler_count;<br>
+}<br>
+<br>
 VkResult anv_CreateDescriptorSetLayout(<br>
     VkDevice                                    _device,<br>
     const VkDescriptorSetLayoutCreateInf<wbr>o*      pCreateInfo,<br>
@@ -49,13 +64,13 @@ VkResult anv_CreateDescriptorSetLayout(<br>
    uint32_t immutable_sampler_count = 0;<br>
    for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) {<br>
       max_binding = MAX2(max_binding, pCreateInfo->pBindings[j].bind<wbr>ing);<br>
-      if (pCreateInfo->pBindings[j].pIm<wbr>mutableSamplers)<br>
-         immutable_sampler_count += pCreateInfo->pBindings[j].desc<wbr>riptorCount;<br>
+      immutable_sampler_count +=<br>
+         layout_binding_get_<wbr>descriptor_count(&pCreateInfo-<wbr>>pBindings[j]);<br>
    }<br>
<br>
    struct anv_descriptor_set_layout *set_layout;<br>
    struct anv_descriptor_set_binding_lay<wbr>out *bindings;<br>
-   struct anv_sampler **samplers;<br>
+   struct anv_descriptor_set_immutable_s<wbr>ampler *samplers;<br>
<br>
    ANV_MULTIALLOC(ma);<br>
    anv_multialloc_add(&ma, &set_layout, 1);<br>
@@ -74,6 +89,7 @@ VkResult anv_CreateDescriptorSetLayout(<br>
       memset(&set_layout->binding[<wbr>b], -1, sizeof(set_layout->binding[b])<wbr>);<br>
<br>
       set_layout->binding[b].array_<wbr>size = 0;<br>
+      set_layout->binding[b].descrip<wbr>tor_size = 0;<br>
       set_layout->binding[b].immuta<wbr>ble_samplers = NULL;<br>
    }<br>
<br>
@@ -108,17 +124,20 @@ VkResult anv_CreateDescriptorSetLayout(<br>
       set_layout->binding[b].type = binding->descriptorType;<br>
 #endif<br>
       set_layout->binding[b].array_<wbr>size = binding->descriptorCount;<br>
+      set_layout->binding[b].descrip<wbr>tor_size =<br>
+         layout_binding_get_<wbr>descriptor_count(binding);<br>
       set_layout->binding[b].descri<wbr>ptor_index = set_layout->size;<br>
-      set_layout->size += binding->descriptorCount;<br>
+      set_layout->size += set_layout->binding[b].descrip<wbr>tor_size;<br>
<br>
       switch (binding->descriptorType) {<br>
       case VK_DESCRIPTOR_TYPE_SAMPLER:<br>
-      case VK_DESCRIPTOR_TYPE_COMBINED_IM<wbr>AGE_SAMPLER:<br>
+      case VK_DESCRIPTOR_TYPE_COMBINED_IM<wbr>AGE_SAMPLER: {<br>
          anv_foreach_stage(s, binding->stageFlags) {<br>
             set_layout->binding[b].stage[<wbr>s].sampler_index = sampler_count[s];<br>
-            sampler_count[s] += binding->descriptorCount;<br>
+            sampler_count[s] += set_layout->binding[b].descrip<wbr>tor_size;<br>
          }<br>
          break;<br>
+      }<br>
       default:<br>
          break;<br>
       }<br>
@@ -140,7 +159,7 @@ VkResult anv_CreateDescriptorSetLayout(<br>
       case VK_DESCRIPTOR_TYPE_INPUT_ATTAC<wbr>HMENT:<br>
          anv_foreach_stage(s, binding->stageFlags) {<br>
             set_layout->binding[b].stage[<wbr>s].surface_index = surface_count[s];<br>
-            surface_count[s] += binding->descriptorCount;<br>
+            surface_count[s] += set_layout->binding[b].descrip<wbr>tor_size;<br>
          }<br>
          break;<br>
       default:<br>
@@ -151,7 +170,7 @@ VkResult anv_CreateDescriptorSetLayout(<br>
       case VK_DESCRIPTOR_TYPE_UNIFORM_BUF<wbr>FER_DYNAMIC:<br>
       case VK_DESCRIPTOR_TYPE_STORAGE_BUF<wbr>FER_DYNAMIC:<br>
          set_layout->binding[b].dynamic<wbr>_offset_index = dynamic_offset_count;<br>
-         dynamic_offset_count += binding->descriptorCount;<br>
+         dynamic_offset_count += set_layout->binding[b].descrip<wbr>tor_size;<br></blockquote><div><br></div></div></div><div>Are you sure about adjusting dynamic_offset_count here?<br></div><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
          break;<br>
       default:<br>
          break;<br>
@@ -162,7 +181,7 @@ VkResult anv_CreateDescriptorSetLayout(<br>
       case VK_DESCRIPTOR_TYPE_STORAGE_TEX<wbr>EL_BUFFER:<br>
          anv_foreach_stage(s, binding->stageFlags) {<br>
             set_layout->binding[b].stage[<wbr>s].image_index = image_count[s];<br>
-            image_count[s] += binding->descriptorCount;<br>
+            image_count[s] += set_layout->binding[b].descrip<wbr>tor_size;<br>
          }<br>
          break;<br>
       default:<br>
@@ -171,11 +190,18 @@ VkResult anv_CreateDescriptorSetLayout(<br>
<br>
       if (binding->pImmutableSamplers) {<br>
          set_layout->binding[b].immutab<wbr>le_samplers = samplers;<br>
-         samplers += binding->descriptorCount;<br>
<br>
-         for (uint32_t i = 0; i < binding->descriptorCount; i++)<br>
-            set_layout->binding[b].immutab<wbr>le_samplers[i] =<br>
-               anv_sampler_from_handle(bindi<wbr>ng->pImmutableSamplers[i]);<br>
+         uint32_t sampler_offset = 0;<br>
+         for (uint32_t i = 0; i < binding->descriptorCount; i++) {<br>
+            ANV_FROM_HANDLE(anv_sampler, sampler, binding->pImmutableSamplers[i]<wbr>);<br>
+<br>
+            set_layout->binding[b].immutab<wbr>le_samplers[i].sampler = sampler;<br>
+            set_layout->binding[b].immutab<wbr>le_samplers[i].descriptor_<wbr>index_offset =<br>
+               sampler_offset;<br>
+            sampler_offset += sampler->nb_planes;<br>
+         }<br>
+<br>
+         samplers += sampler_offset;<br>
       } else {<br>
          set_layout->binding[b].immutab<wbr>le_samplers = NULL;<br>
       }<br>
@@ -250,7 +276,7 @@ VkResult anv_CreatePipelineLayout(<br>
          if (set_layout->binding[b].dynami<wbr>c_offset_index < 0)<br>
             continue;<br>
<br>
-         dynamic_offset_count += set_layout->binding[b].array_s<wbr>ize;<br>
+         dynamic_offset_count += set_layout->binding[b].descrip<wbr>tor_size;<br>
          for (gl_shader_stage s = 0; s < MESA_SHADER_STAGES; s++) {<br>
             if (set_layout->binding[b].stage[<wbr>s].surface_index >= 0)<br>
                layout->stage[s].has_dynamic_o<wbr>ffsets = true;<br>
@@ -318,11 +344,24 @@ VkResult anv_CreateDescriptorPool(<br>
    uint32_t buffer_count = 0;<br>
    for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; i++) {<br>
       switch (pCreateInfo->pPoolSizes[i].ty<wbr>pe) {<br>
+      case VK_DESCRIPTOR_TYPE_SAMPLER:<br>
+      case VK_DESCRIPTOR_TYPE_COMBINED_IM<wbr>AGE_SAMPLER:<br>
+         /* We have to account that some descriptor layouts might have<br>
+          * multiplanar images (atm up to 3 through the conversion<br>
+          * VK_KHR_sampler_ycbcr_conversio<wbr>n extension). Therefor take the<br>
+          * maximum amount of space that can be occupied by a single of those<br>
+          * entries.<br>
+          */<br>
+         descriptor_count += 3 * pCreateInfo->pPoolSizes[i].des<wbr>criptorCount;<br></blockquote><div><br></div></div></div><div>I'm not quite sure how I expected you to solve the multi-descriptor problem but it wasn't like this. :)  An alternate solution would be to keep each image_view and sampler a single descriptor in the descriptor set and expand it out to multiple descriptors as-needed in anv_nir_apply_pipeline_layout by adding a "plane" entry to anv_pipeline_binding.  I'm honestly not sure which one would work out better in the end.<br></div></div></div></div>
</blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">If you don't mind too badly, I'd like it if you at least took a crack at my alternate solution.  There's some things that this method requires us to add to descriptor set layouts that make me a bit uncomfortable.  At some point, I intend to do something of an overhaul of descriptor sets and we will probably end up going sort-of in the direction here but the current code I think would work better if we maintained one descriptor per image.</div><div class="gmail_extra"><br></div><div class="gmail_extra">--Jason<br></div></div>