vk: Unionize anv_desciptor
authorChad Versace <chad.versace@intel.com>
Mon, 5 Oct 2015 21:43:23 +0000 (14:43 -0700)
committerChad Versace <chad.versace@intel.com>
Tue, 6 Oct 2015 00:46:04 +0000 (17:46 -0700)
For a given struct anv_descriptor, all members are NULL (in which case
the descriptor is empty) or exactly one member is non-NULL.
To make struct anv_descriptor better reflect its set of valid states,
convert the struct into a tagged union.

src/vulkan/anv_cmd_buffer.c
src/vulkan/anv_device.c
src/vulkan/anv_private.h

index 419405204d5b2a10d7110a5eb3f9c6b697c7ff5c..5a00ce24bd2f8e9fe05d33e547672823df03c38f 100644 (file)
@@ -456,12 +456,14 @@ anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
       uint32_t start = bias + layout->set[set].stage[stage].surface_start;
 
       for (uint32_t b = 0; b < set_layout->stage[stage].surface_count; b++) {
-         struct anv_surface_view *view =
-            d->set->descriptors[surface_slots[b].index].view;
+         struct anv_descriptor *desc =
+            &d->set->descriptors[surface_slots[b].index];
 
-         if (!view)
+         if (desc->type != ANV_DESCRIPTOR_TYPE_SURFACE_VIEW)
             continue;
 
+         struct anv_surface_view *view = desc->surface_view;
+
          bt_map[start + b] = view->surface_state.offset + state_offset;
          add_surface_state_reloc(cmd_buffer, view->surface_state,
                                  view->bo, view->offset);
@@ -502,12 +504,14 @@ anv_cmd_buffer_emit_samplers(struct anv_cmd_buffer *cmd_buffer,
       uint32_t start = layout->set[set].stage[stage].sampler_start;
 
       for (uint32_t b = 0; b < set_layout->stage[stage].sampler_count; b++) {
-         struct anv_sampler *sampler =
-            d->set->descriptors[sampler_slots[b].index].sampler;
+         struct anv_descriptor *desc =
+            &d->set->descriptors[sampler_slots[b].index];
 
-         if (!sampler)
+         if (desc->type != ANV_DESCRIPTOR_TYPE_SAMPLER)
             continue;
 
+         struct anv_sampler *sampler = desc->sampler;
+
          memcpy(state->map + (start + b) * 16,
                 sampler->state, sizeof(sampler->state));
       }
index dd9b08ce075eb1aad80d6565ecb1a434d1c969fd..7889c61ba5bc6ffa259949d3504467568579dd4d 100644 (file)
@@ -1733,8 +1733,13 @@ VkResult anv_UpdateDescriptorSets(
       case VK_DESCRIPTOR_TYPE_SAMPLER:
       case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
          for (uint32_t j = 0; j < write->count; j++) {
-            set->descriptors[write->destBinding + j].sampler =
-               anv_sampler_from_handle(write->pDescriptors[j].sampler);
+            ANV_FROM_HANDLE(anv_sampler, sampler,
+                            write->pDescriptors[j].sampler);
+
+            set->descriptors[write->destBinding + j] = (struct anv_descriptor) {
+               .type = ANV_DESCRIPTOR_TYPE_SAMPLER,
+               .sampler = sampler,
+            };
          }
 
          if (write->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER)
@@ -1747,7 +1752,11 @@ VkResult anv_UpdateDescriptorSets(
          for (uint32_t j = 0; j < write->count; j++) {
             ANV_FROM_HANDLE(anv_image_view, iview,
                             write->pDescriptors[j].imageView);
-            set->descriptors[write->destBinding + j].view = &iview->view;
+
+            set->descriptors[write->destBinding + j] = (struct anv_descriptor) {
+               .type = ANV_DESCRIPTOR_TYPE_SURFACE_VIEW,
+               .surface_view = &iview->view,
+            };
          }
          break;
 
@@ -1767,7 +1776,11 @@ VkResult anv_UpdateDescriptorSets(
          for (uint32_t j = 0; j < write->count; j++) {
             ANV_FROM_HANDLE(anv_buffer_view, bview,
                             write->pDescriptors[j].bufferView);
-            set->descriptors[write->destBinding + j].view = &bview->view;
+
+            set->descriptors[write->destBinding + j] = (struct anv_descriptor) {
+               .type = ANV_DESCRIPTOR_TYPE_SURFACE_VIEW,
+               .surface_view = &bview->view,
+            };
          }
 
       default:
index bc747fcd27c8d29f275ba292110f44deb4a838d9..6ce5db209cb7b21bf44ed3775602a9b180640922 100644 (file)
@@ -728,9 +728,19 @@ struct anv_descriptor_set_layout {
    struct anv_descriptor_slot entries[0];
 };
 
+enum anv_descriptor_type {
+   ANV_DESCRIPTOR_TYPE_EMPTY = 0,
+   ANV_DESCRIPTOR_TYPE_SAMPLER,
+   ANV_DESCRIPTOR_TYPE_SURFACE_VIEW,
+};
+
 struct anv_descriptor {
-   struct anv_sampler *sampler;
-   struct anv_surface_view *view;
+   union {
+      struct anv_sampler *sampler;
+      struct anv_surface_view *surface_view;
+   };
+
+   enum anv_descriptor_type type;
 };
 
 struct anv_descriptor_set {