anv/apply_pipeline_layout: Add to the bind map instead of replacing it
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 7 Aug 2018 22:29:43 +0000 (15:29 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 17 Aug 2018 15:50:28 +0000 (10:50 -0500)
This commit makes three changes.  One is to only walk the descriptors once
and set bind map sizes at the same time as filling out the entries.  The
second is to make the pass additive so that we can put stuff in the bind
map before applying the pipeline layout.  Third, we switch to using
designated initializers.

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/intel/vulkan/anv_descriptor_set.c
src/intel/vulkan/anv_nir_apply_pipeline_layout.c
src/intel/vulkan/anv_private.h

index 66ed28292b01897fc1d1315ca5e112a5ab49d009..2bd1d86f4d4f18266e84b97b6d73538acea416e8 100644 (file)
@@ -491,19 +491,6 @@ anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout *layout)
       layout->buffer_count * sizeof(struct anv_buffer_view);
 }
 
-size_t
-anv_descriptor_set_binding_layout_get_hw_size(const struct anv_descriptor_set_binding_layout *binding)
-{
-   if (!binding->immutable_samplers)
-      return binding->array_size;
-
-   uint32_t total_plane_count = 0;
-   for (uint32_t i = 0; i < binding->array_size; i++)
-      total_plane_count += binding->immutable_samplers[i]->n_planes;
-
-   return total_plane_count;
-}
-
 struct surface_state_free_list_entry {
    void *next;
    struct anv_state state;
index c287a005bd695f87a42f9234cd8666aa41b32808..67ebaa6ce6cb1e4537e097138aea73a6ed5d9394 100644 (file)
@@ -379,37 +379,11 @@ anv_nir_apply_pipeline_layout(struct anv_pipeline *pipeline,
          get_used_bindings_block(block, &state);
    }
 
-   if (state.uses_constants)
-      map->surface_count++;
-
-   for (uint32_t set = 0; set < layout->num_sets; set++) {
-      struct anv_descriptor_set_layout *set_layout = layout->set[set].layout;
-
-      BITSET_WORD b, _tmp;
-      BITSET_FOREACH_SET(b, _tmp, state.set[set].used,
-                         set_layout->binding_count) {
-         if (set_layout->binding[b].stage[stage].surface_index >= 0) {
-            map->surface_count +=
-               anv_descriptor_set_binding_layout_get_hw_size(&set_layout->binding[b]);
-         }
-         if (set_layout->binding[b].stage[stage].sampler_index >= 0) {
-            map->sampler_count +=
-               anv_descriptor_set_binding_layout_get_hw_size(&set_layout->binding[b]);
-         }
-         if (set_layout->binding[b].stage[stage].image_index >= 0)
-            map->image_count += set_layout->binding[b].array_size;
-      }
-   }
-
-   unsigned surface = 0;
-   unsigned sampler = 0;
-   unsigned image = 0;
-
    if (state.uses_constants) {
-      state.constants_offset = surface;
-      map->surface_to_descriptor[surface].set =
+      state.constants_offset = map->surface_count;
+      map->surface_to_descriptor[map->surface_count].set =
          ANV_DESCRIPTOR_SET_SHADER_CONSTANTS;
-      surface++;
+      map->surface_count++;
    }
 
    for (uint32_t set = 0; set < layout->num_sets; set++) {
@@ -422,38 +396,42 @@ anv_nir_apply_pipeline_layout(struct anv_pipeline *pipeline,
             &set_layout->binding[b];
 
          if (binding->stage[stage].surface_index >= 0) {
-            state.set[set].surface_offsets[b] = surface;
+            state.set[set].surface_offsets[b] = map->surface_count;
             struct anv_sampler **samplers = binding->immutable_samplers;
             for (unsigned i = 0; i < binding->array_size; i++) {
                uint8_t planes = samplers ? samplers[i]->n_planes : 1;
                for (uint8_t p = 0; p < planes; p++) {
-                  map->surface_to_descriptor[surface].set = set;
-                  map->surface_to_descriptor[surface].binding = b;
-                  map->surface_to_descriptor[surface].index = i;
-                  map->surface_to_descriptor[surface].plane = p;
-                  surface++;
+                  map->surface_to_descriptor[map->surface_count++] =
+                     (struct anv_pipeline_binding) {
+                        .set = set,
+                        .binding = b,
+                        .index = i,
+                        .plane = p,
+                     };
                }
             }
          }
 
          if (binding->stage[stage].sampler_index >= 0) {
-            state.set[set].sampler_offsets[b] = sampler;
+            state.set[set].sampler_offsets[b] = map->sampler_count;
             struct anv_sampler **samplers = binding->immutable_samplers;
             for (unsigned i = 0; i < binding->array_size; i++) {
                uint8_t planes = samplers ? samplers[i]->n_planes : 1;
                for (uint8_t p = 0; p < planes; p++) {
-                  map->sampler_to_descriptor[sampler].set = set;
-                  map->sampler_to_descriptor[sampler].binding = b;
-                  map->sampler_to_descriptor[sampler].index = i;
-                  map->sampler_to_descriptor[sampler].plane = p;
-                  sampler++;
+                  map->sampler_to_descriptor[map->sampler_count++] =
+                     (struct anv_pipeline_binding) {
+                        .set = set,
+                        .binding = b,
+                        .index = i,
+                        .plane = p,
+                     };
                }
             }
          }
 
          if (binding->stage[stage].image_index >= 0) {
-            state.set[set].image_offsets[b] = image;
-            image += binding->array_size;
+            state.set[set].image_offsets[b] = map->image_count;
+            map->image_count += binding->array_size;
          }
       }
    }
index 410a148e42391c417ff5ca5c98dab8e8207ff6ce..2ced8afcabef762594de4266c20f93db25ed0861 100644 (file)
@@ -1541,9 +1541,6 @@ struct anv_descriptor_update_template {
    struct anv_descriptor_template_entry entries[0];
 };
 
-size_t
-anv_descriptor_set_binding_layout_get_hw_size(const struct anv_descriptor_set_binding_layout *binding);
-
 size_t
 anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout *layout);