anv/descriptor_set: Add support for storage images in layouts
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 17 Nov 2015 06:26:03 +0000 (22:26 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 8 Dec 2015 05:08:26 +0000 (21:08 -0800)
src/vulkan/anv_descriptor_set.c
src/vulkan/anv_private.h

index e1cfd788b7314c6f2ee86a1b1321bffc4280f00b..9c4210025e3d1b5487e958f1f05a5a2584f87c6a 100644 (file)
@@ -79,6 +79,7 @@ VkResult anv_CreateDescriptorSetLayout(
 
    uint32_t sampler_count[MESA_SHADER_STAGES] = { 0, };
    uint32_t surface_count[MESA_SHADER_STAGES] = { 0, };
+   uint32_t image_count[MESA_SHADER_STAGES] = { 0, };
    uint32_t dynamic_offset_count = 0;
 
    for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) {
@@ -132,6 +133,13 @@ VkResult anv_CreateDescriptorSetLayout(
          break;
       }
 
+      if (binding->descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) {
+         for_each_bit(s, binding->stageFlags) {
+            set_layout->binding[b].stage[s].image_index = image_count[s];
+            image_count[s] += binding->descriptorCount;
+         }
+      }
+
       if (binding->pImmutableSamplers) {
          set_layout->binding[b].immutable_samplers = samplers;
          samplers += binding->descriptorCount;
@@ -199,6 +207,7 @@ VkResult anv_CreatePipelineLayout(
       for (gl_shader_stage s = 0; s < MESA_SHADER_STAGES; s++) {
          l.set[set].stage[s].surface_start = l.stage[s].surface_count;
          l.set[set].stage[s].sampler_start = l.stage[s].sampler_count;
+         l.set[set].stage[s].image_start = l.stage[s].image_count;
 
          for (uint32_t b = 0; b < set_layout->binding_count; b++) {
             unsigned array_size = set_layout->binding[b].array_size;
@@ -212,13 +221,19 @@ VkResult anv_CreatePipelineLayout(
 
             if (set_layout->binding[b].stage[s].sampler_index >= 0)
                l.stage[s].sampler_count += array_size;
+
+            if (set_layout->binding[b].stage[s].image_index >= 0)
+               l.stage[s].image_count += array_size;
          }
       }
    }
 
    unsigned num_bindings = 0;
-   for (gl_shader_stage s = 0; s < MESA_SHADER_STAGES; s++)
-      num_bindings += l.stage[s].surface_count + l.stage[s].sampler_count;
+   for (gl_shader_stage s = 0; s < MESA_SHADER_STAGES; s++) {
+      num_bindings += l.stage[s].surface_count +
+                      l.stage[s].sampler_count +
+                      l.stage[s].image_count;
+   }
 
    size_t size = sizeof(*layout) + num_bindings * sizeof(layout->entries[0]);
 
@@ -234,6 +249,7 @@ VkResult anv_CreatePipelineLayout(
       entry += l.stage[s].surface_count;
       l.stage[s].sampler_to_descriptor = entry;
       entry += l.stage[s].sampler_count;
+      entry += l.stage[s].image_count;
 
       int surface = 0;
       int sampler = 0;
index a6db547e5e3ce8124222467ec000c38589ae769b..b3829216dd447d243aa30b36c47a49b80bf59b12 100644 (file)
@@ -814,6 +814,9 @@ struct anv_descriptor_set_binding_layout {
 
       /* Index into the sampler table for the associated sampler */
       int16_t sampler_index;
+
+      /* Index into the image table for the associated image */
+      int16_t image_index;
    } stage[MESA_SHADER_STAGES];
 
    /* Immutable samplers (or NULL if no immutable samplers) */
@@ -894,6 +897,7 @@ struct anv_pipeline_layout {
       struct {
          uint32_t surface_start;
          uint32_t sampler_start;
+         uint32_t image_start;
       } stage[MESA_SHADER_STAGES];
    } set[MAX_SETS];
 
@@ -905,6 +909,7 @@ struct anv_pipeline_layout {
       struct anv_pipeline_binding *surface_to_descriptor;
       uint32_t sampler_count;
       struct anv_pipeline_binding *sampler_to_descriptor;
+      uint32_t image_count;
    } stage[MESA_SHADER_STAGES];
 
    struct anv_pipeline_binding entries[0];