[Mesa-dev] [PATCH 12/15] anv: add descriptor support for multiplanar image/sampler

Lionel Landwerlin lionel.g.landwerlin at intel.com
Mon Sep 25 17:39:03 UTC 2017


On 15/09/17 23:54, Jason Ekstrand wrote:
>
>
> On Fri, Sep 15, 2017 at 7:11 AM, Lionel Landwerlin 
> <lionel.g.landwerlin at intel.com <mailto:lionel.g.landwerlin at intel.com>> 
> wrote:
>
>     Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com
>     <mailto:lionel.g.landwerlin at intel.com>>
>     ---
>      src/intel/vulkan/anv_descriptor_set.c            | 107
>     +++++++++++++++++------
>      src/intel/vulkan/anv_nir_apply_pipeline_layout.c | 44 +++++-----
>      src/intel/vulkan/anv_private.h                   |  24 ++++-
>      src/intel/vulkan/genX_cmd_buffer.c               | 14 ++-
>      src/intel/vulkan/genX_state.c                    |  81
>     +++++++++--------
>      5 files changed, 178 insertions(+), 92 deletions(-)
>
>     diff --git a/src/intel/vulkan/anv_descriptor_set.c
>     b/src/intel/vulkan/anv_descriptor_set.c
>     index 91387c065e4..4e29310f5fa 100644
>     --- a/src/intel/vulkan/anv_descriptor_set.c
>     +++ b/src/intel/vulkan/anv_descriptor_set.c
>     @@ -35,6 +35,21 @@
>       * Descriptor set layouts.
>       */
>
>     +static uint32_t
>     +layout_binding_get_descriptor_count(const
>     VkDescriptorSetLayoutBinding *binding)
>     +{
>     +   if (binding->pImmutableSamplers == NULL)
>     +      return binding->descriptorCount;
>     +
>     +   uint32_t immutable_sampler_count = 0;
>     +   for (uint32_t i = 0; i < binding->descriptorCount; i++) {
>     +      ANV_FROM_HANDLE(anv_sampler, sampler,
>     binding->pImmutableSamplers[i]);
>     +      immutable_sampler_count += sampler->nb_planes;
>     +   }
>     +
>     +   return immutable_sampler_count;
>     +}
>     +
>      VkResult anv_CreateDescriptorSetLayout(
>          VkDevice                                    _device,
>          const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
>     @@ -49,13 +64,13 @@ VkResult anv_CreateDescriptorSetLayout(
>         uint32_t immutable_sampler_count = 0;
>         for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) {
>            max_binding = MAX2(max_binding,
>     pCreateInfo->pBindings[j].binding);
>     -      if (pCreateInfo->pBindings[j].pImmutableSamplers)
>     -         immutable_sampler_count +=
>     pCreateInfo->pBindings[j].descriptorCount;
>     +      immutable_sampler_count +=
>     +       
>      layout_binding_get_descriptor_count(&pCreateInfo->pBindings[j]);
>         }
>
>         struct anv_descriptor_set_layout *set_layout;
>         struct anv_descriptor_set_binding_layout *bindings;
>     -   struct anv_sampler **samplers;
>     +   struct anv_descriptor_set_immutable_sampler *samplers;
>
>         ANV_MULTIALLOC(ma);
>         anv_multialloc_add(&ma, &set_layout, 1);
>     @@ -74,6 +89,7 @@ VkResult anv_CreateDescriptorSetLayout(
>            memset(&set_layout->binding[b], -1,
>     sizeof(set_layout->binding[b]));
>
>            set_layout->binding[b].array_size = 0;
>     +      set_layout->binding[b].descriptor_size = 0;
>            set_layout->binding[b].immutable_samplers = NULL;
>         }
>
>     @@ -108,17 +124,20 @@ VkResult anv_CreateDescriptorSetLayout(
>            set_layout->binding[b].type = binding->descriptorType;
>      #endif
>            set_layout->binding[b].array_size = binding->descriptorCount;
>     +      set_layout->binding[b].descriptor_size =
>     +         layout_binding_get_descriptor_count(binding);
>            set_layout->binding[b].descriptor_index = set_layout->size;
>     -      set_layout->size += binding->descriptorCount;
>     +      set_layout->size += set_layout->binding[b].descriptor_size;
>
>            switch (binding->descriptorType) {
>            case VK_DESCRIPTOR_TYPE_SAMPLER:
>     -      case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
>     +      case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
>               anv_foreach_stage(s, binding->stageFlags) {
>                  set_layout->binding[b].stage[s].sampler_index =
>     sampler_count[s];
>     -            sampler_count[s] += binding->descriptorCount;
>     +            sampler_count[s] +=
>     set_layout->binding[b].descriptor_size;
>               }
>               break;
>     +      }
>            default:
>               break;
>            }
>     @@ -140,7 +159,7 @@ VkResult anv_CreateDescriptorSetLayout(
>            case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
>               anv_foreach_stage(s, binding->stageFlags) {
>                  set_layout->binding[b].stage[s].surface_index =
>     surface_count[s];
>     -            surface_count[s] += binding->descriptorCount;
>     +            surface_count[s] +=
>     set_layout->binding[b].descriptor_size;
>               }
>               break;
>            default:
>     @@ -151,7 +170,7 @@ VkResult anv_CreateDescriptorSetLayout(
>            case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
>            case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
>               set_layout->binding[b].dynamic_offset_index =
>     dynamic_offset_count;
>     -         dynamic_offset_count += binding->descriptorCount;
>     +         dynamic_offset_count +=
>     set_layout->binding[b].descriptor_size;
>
>
> Are you sure about adjusting dynamic_offset_count here?
>
>               break;
>            default:
>               break;
>     @@ -162,7 +181,7 @@ VkResult anv_CreateDescriptorSetLayout(
>            case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
>               anv_foreach_stage(s, binding->stageFlags) {
>                  set_layout->binding[b].stage[s].image_index =
>     image_count[s];
>     -            image_count[s] += binding->descriptorCount;
>     +            image_count[s] += set_layout->binding[b].descriptor_size;
>               }
>               break;
>            default:
>     @@ -171,11 +190,18 @@ VkResult anv_CreateDescriptorSetLayout(
>
>            if (binding->pImmutableSamplers) {
>               set_layout->binding[b].immutable_samplers = samplers;
>     -         samplers += binding->descriptorCount;
>
>     -         for (uint32_t i = 0; i < binding->descriptorCount; i++)
>     -            set_layout->binding[b].immutable_samplers[i] =
>     -             
>      anv_sampler_from_handle(binding->pImmutableSamplers[i]);
>     +         uint32_t sampler_offset = 0;
>     +         for (uint32_t i = 0; i < binding->descriptorCount; i++) {
>     +            ANV_FROM_HANDLE(anv_sampler, sampler,
>     binding->pImmutableSamplers[i]);
>     +
>     +            set_layout->binding[b].immutable_samplers[i].sampler
>     = sampler;
>     +           
>     set_layout->binding[b].immutable_samplers[i].descriptor_index_offset =
>     +               sampler_offset;
>     +            sampler_offset += sampler->nb_planes;
>     +         }
>     +
>     +         samplers += sampler_offset;
>            } else {
>               set_layout->binding[b].immutable_samplers = NULL;
>            }
>     @@ -250,7 +276,7 @@ VkResult anv_CreatePipelineLayout(
>               if (set_layout->binding[b].dynamic_offset_index < 0)
>                  continue;
>
>     -         dynamic_offset_count += set_layout->binding[b].array_size;
>     +         dynamic_offset_count +=
>     set_layout->binding[b].descriptor_size;
>               for (gl_shader_stage s = 0; s < MESA_SHADER_STAGES; s++) {
>                  if (set_layout->binding[b].stage[s].surface_index >= 0)
>                     layout->stage[s].has_dynamic_offsets = true;
>     @@ -318,11 +344,24 @@ VkResult anv_CreateDescriptorPool(
>         uint32_t buffer_count = 0;
>         for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; i++) {
>            switch (pCreateInfo->pPoolSizes[i].type) {
>     +      case VK_DESCRIPTOR_TYPE_SAMPLER:
>     +      case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
>     +         /* We have to account that some descriptor layouts might
>     have
>     +          * multiplanar images (atm up to 3 through the conversion
>     +          * VK_KHR_sampler_ycbcr_conversion extension). Therefor
>     take the
>     +          * maximum amount of space that can be occupied by a
>     single of those
>     +          * entries.
>     +          */
>     +         descriptor_count += 3 *
>     pCreateInfo->pPoolSizes[i].descriptorCount;
>
>
> 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.
>
>     +         break;
>     +
>            case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
>            case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
>            case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
>            case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
>               buffer_count += pCreateInfo->pPoolSizes[i].descriptorCount;
>     +         /* Fallthrough */
>     +
>            default:
>               descriptor_count +=
>     pCreateInfo->pPoolSizes[i].descriptorCount;
>               break;
>     @@ -461,13 +500,18 @@ anv_descriptor_set_create(struct anv_device
>     *device,
>                   * set has an immutable sampler, UpdateDescriptorSets
>     may never
>                   * touch it, so we need to make sure it's 100% valid now.
>                   */
>     -            desc[i] = (struct anv_descriptor) {
>     -               .type = VK_DESCRIPTOR_TYPE_SAMPLER,
>     -               .sampler = layout->binding[b].immutable_samplers[i],
>     -            };
>     +            struct anv_descriptor_set_immutable_sampler *sampler =
>     +               &layout->binding[b].immutable_samplers[i];
>     +            for (uint32_t p = 0; p < sampler->sampler->nb_planes;
>     p++) {
>     +               desc[sampler->descriptor_index_offset + p] =
>     (struct anv_descriptor) {
>     +                  .type = VK_DESCRIPTOR_TYPE_SAMPLER,
>     +                  .sampler = sampler->sampler,
>     +                  .plane = p,
>     +               };
>     +            }
>               }
>            }
>     -      desc += layout->binding[b].array_size;
>     +      desc += layout->binding[b].descriptor_size;
>         }
>
>         /* Allocate surface state for the buffer views. */
>     @@ -579,8 +623,13 @@ anv_descriptor_set_write_image_view(struct
>     anv_descriptor_set *set,
>      {
>         const struct anv_descriptor_set_binding_layout *bind_layout =
>            &set->layout->binding[binding];
>     +   const struct anv_descriptor_set_immutable_sampler
>     *immutable_sampler =
>     +      bind_layout->immutable_samplers ?
>     +      &bind_layout->immutable_samplers[element] : NULL;
>     +   uint32_t descriptor_index_offset =
>     +      immutable_sampler ?
>     immutable_sampler->descriptor_index_offset : element;
>         struct anv_descriptor *desc =
>     -      &set->descriptors[bind_layout->descriptor_index + element];
>     +      &set->descriptors[bind_layout->descriptor_index +
>     descriptor_index_offset];
>         struct anv_image_view *image_view = NULL;
>         struct anv_sampler *sampler = NULL;
>
>     @@ -610,15 +659,19 @@ anv_descriptor_set_write_image_view(struct
>     anv_descriptor_set *set,
>          * it.
>          */
>         sampler = bind_layout->immutable_samplers ?
>     -             bind_layout->immutable_samplers[element] :
>     +             bind_layout->immutable_samplers[element].sampler :
>                   sampler;
>
>     -   *desc = (struct anv_descriptor) {
>     -      .type = type,
>     -      .layout = info->imageLayout,
>     -      .image_view = image_view,
>     -      .sampler = sampler,
>     -   };
>     +   uint32_t nb_planes = sampler != NULL ? sampler->nb_planes : 1;
>     +   for (uint32_t p = 0; p < nb_planes; p++) {
>     +      desc[p] = (struct anv_descriptor) {
>     +         .type = type,
>     +         .layout = info->imageLayout,
>     +         .image_view = image_view,
>     +         .sampler = sampler,
>     +         .plane = p,
>     +      };
>     +   }
>      }
>
>      void
>     diff --git a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c
>     b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c
>     index 67bcf5e29ef..83d4c4ea30d 100644
>     --- a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c
>     +++ b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c
>     @@ -130,7 +130,7 @@ lower_res_index_intrinsic(nir_intrinsic_instr
>     *intrin,
>
>      static void
>      lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref,
>     -                unsigned *const_index, unsigned array_size,
>     +                unsigned *const_index, unsigned descriptor_size,
>                      nir_tex_src_type src_type,
>                      struct apply_pipeline_layout_state *state)
>      {
>     @@ -146,7 +146,7 @@ lower_tex_deref(nir_tex_instr *tex,
>     nir_deref_var *deref,
>                              nir_ssa_for_src(b, deref_array->indirect,
>     1));
>
>               if (state->add_bounds_checks)
>     -            index = nir_umin(b, index, nir_imm_int(b, array_size
>     - 1));
>     +            index = nir_umin(b, index, nir_imm_int(b,
>     descriptor_size - 1));
>
>               nir_tex_src *new_srcs = rzalloc_array(tex, nir_tex_src,
>     tex->num_srcs + 1);
>     @@ -167,7 +167,7 @@ lower_tex_deref(nir_tex_instr *tex,
>     nir_deref_var *deref,
>                                     nir_src_for_ssa(index));
>               tex->num_srcs++;
>            } else {
>     -         *const_index += MIN2(deref_array->base_offset,
>     array_size - 1);
>     +         *const_index += MIN2(deref_array->base_offset,
>     descriptor_size - 1);
>            }
>         }
>      }
>     @@ -196,19 +196,18 @@ lower_tex(nir_tex_instr *tex, struct
>     apply_pipeline_layout_state *state)
>
>         unsigned set = tex->texture->var->data.descriptor_set;
>         unsigned binding = tex->texture->var->data.binding;
>     -   unsigned array_size =
>     -      state->layout->set[set].layout->binding[binding].array_size;
>     +   unsigned descriptor_size =
>     +     
>     state->layout->set[set].layout->binding[binding].descriptor_size;
>         tex->texture_index = state->set[set].surface_offsets[binding];
>     -   lower_tex_deref(tex, tex->texture, &tex->texture_index,
>     array_size,
>     +   lower_tex_deref(tex, tex->texture, &tex->texture_index,
>     descriptor_size,
>                         nir_tex_src_texture_offset, state);
>
>         if (tex->sampler) {
>            unsigned set = tex->sampler->var->data.descriptor_set;
>            unsigned binding = tex->sampler->var->data.binding;
>     -      unsigned array_size =
>     -         state->layout->set[set].layout->binding[binding].array_size;
>     -      tex->sampler_index = state->set[set].sampler_offsets[binding];
>     -      lower_tex_deref(tex, tex->sampler, &tex->sampler_index,
>     array_size,
>     +      unsigned descriptor_size =
>     +       
>      state->layout->set[set].layout->binding[binding].descriptor_size;
>     +      lower_tex_deref(tex, tex->sampler, &tex->sampler_index,
>     descriptor_size,
>                            nir_tex_src_sampler_offset, state);
>         }
>
>     @@ -300,9 +299,9 @@ anv_nir_apply_pipeline_layout(struct
>     anv_pipeline *pipeline,
>            BITSET_FOREACH_SET(b, _tmp, state.set[set].used,
>                               set_layout->binding_count) {
>               if
>     (set_layout->binding[b].stage[shader->stage].surface_index >= 0)
>     -            map->surface_count += set_layout->binding[b].array_size;
>     +            map->surface_count +=
>     set_layout->binding[b].descriptor_size;
>               if
>     (set_layout->binding[b].stage[shader->stage].sampler_index >= 0)
>     -            map->sampler_count += set_layout->binding[b].array_size;
>     +            map->sampler_count +=
>     set_layout->binding[b].descriptor_size;
>               if
>     (set_layout->binding[b].stage[shader->stage].image_index >= 0)
>                  map->image_count += set_layout->binding[b].array_size;
>            }
>     @@ -317,31 +316,34 @@ anv_nir_apply_pipeline_layout(struct
>     anv_pipeline *pipeline,
>            BITSET_WORD b, _tmp;
>            BITSET_FOREACH_SET(b, _tmp, state.set[set].used,
>                               set_layout->binding_count) {
>     -         unsigned array_size = set_layout->binding[b].array_size;
>     +         struct anv_descriptor_set_binding_layout *binding =
>     +            &set_layout->binding[b];
>     +         /* unsigned array_size =
>     set_layout->binding[b].array_size; */
>     +         /* unsigned descriptor_size =
>     set_layout->binding[b].descriptor_size; */
>
>     -         if
>     (set_layout->binding[b].stage[shader->stage].surface_index >= 0) {
>     +         if (binding->stage[shader->stage].surface_index >= 0) {
>                  state.set[set].surface_offsets[b] = surface;
>     -            for (unsigned i = 0; i < array_size; i++) {
>     +            for (unsigned i = 0; i < binding->descriptor_size; i++) {
>                     map->surface_to_descriptor[surface + i].set = set;
>                     map->surface_to_descriptor[surface + i].binding = b;
>                     map->surface_to_descriptor[surface + i].index = i;
>                  }
>     -            surface += array_size;
>     +            surface += binding->descriptor_size;
>               }
>
>     -         if
>     (set_layout->binding[b].stage[shader->stage].sampler_index >= 0) {
>     +         if (binding->stage[shader->stage].sampler_index >= 0) {
>                  state.set[set].sampler_offsets[b] = sampler;
>     -            for (unsigned i = 0; i < array_size; i++) {
>     +            for (unsigned i = 0; i < binding->descriptor_size; i++) {
>                     map->sampler_to_descriptor[sampler + i].set = set;
>                     map->sampler_to_descriptor[sampler + i].binding = b;
>                     map->sampler_to_descriptor[sampler + i].index = i;
>                  }
>     -            sampler += array_size;
>     +            sampler += binding->descriptor_size;
>               }
>
>     -         if
>     (set_layout->binding[b].stage[shader->stage].image_index >= 0) {
>     +         if (binding->stage[shader->stage].image_index >= 0) {
>                  state.set[set].image_offsets[b] = image;
>     -            image += array_size;
>     +            image += binding->descriptor_size;
>               }
>            }
>         }
>     diff --git a/src/intel/vulkan/anv_private.h
>     b/src/intel/vulkan/anv_private.h
>     index a4b263cea5e..41f01192aa6 100644
>     --- a/src/intel/vulkan/anv_private.h
>     +++ b/src/intel/vulkan/anv_private.h
>     @@ -1168,6 +1168,18 @@ struct anv_vue_header {
>         float PointWidth;
>      };
>
>     +struct anv_descriptor_set_immutable_sampler {
>     +   /* Immutable sampler */
>     +   struct anv_sampler *sampler;
>     +
>     +   /* Offset to add to
>     +    * anv_descriptor_set_binding_layout.stage[s].sampler_index or
>     +    * anv_descriptor_set_binding_layout.descriptor_index to
>     compute the offset
>     +    * in the descriptor table.
>     +    */
>     +   uint16_t descriptor_index_offset;
>     +};
>     +
>      struct anv_descriptor_set_binding_layout {
>      #ifndef NDEBUG
>         /* The type of the descriptors in this binding */
>     @@ -1177,6 +1189,9 @@ struct anv_descriptor_set_binding_layout {
>         /* Number of array elements in this binding */
>         uint16_t array_size;
>
>     +   /* Number of descriptors used in this binding */
>     +   uint16_t descriptor_size;
>     +
>         /* Index into the flattend descriptor set */
>         uint16_t descriptor_index;
>
>     @@ -1198,7 +1213,7 @@ struct anv_descriptor_set_binding_layout {
>         } stage[MESA_SHADER_STAGES];
>
>         /* Immutable samplers (or NULL if no immutable samplers) */
>     -   struct anv_sampler **immutable_samplers;
>     +   struct anv_descriptor_set_immutable_sampler *immutable_samplers;
>      };
>
>      struct anv_descriptor_set_layout {
>     @@ -1229,6 +1244,10 @@ struct anv_descriptor {
>               VkImageLayout layout;
>               struct anv_image_view *image_view;
>               struct anv_sampler *sampler;
>     +
>     +         /* Used to dertermine what plane of the sampler/image we
>     need
>     +          * program. */
>     +         uint32_t plane;
>            };
>
>            struct {
>     @@ -2504,7 +2523,8 @@ void anv_fill_buffer_surface_state(struct
>     anv_device *device,
>                                         uint32_t stride);
>
>      struct anv_sampler {
>     -   uint32_t state[4];
>     +   uint32_t                     state[3][4];
>     +   uint8_t                      nb_planes;
>      };
>
>      struct anv_framebuffer {
>     diff --git a/src/intel/vulkan/genX_cmd_buffer.c
>     b/src/intel/vulkan/genX_cmd_buffer.c
>     index a16f67b108c..bea73dfb504 100644
>     --- a/src/intel/vulkan/genX_cmd_buffer.c
>     +++ b/src/intel/vulkan/genX_cmd_buffer.c
>     @@ -1736,7 +1736,8 @@ emit_samplers(struct anv_cmd_buffer *cmd_buffer,
>         if (state->map == NULL)
>            return VK_ERROR_OUT_OF_DEVICE_MEMORY;
>
>     -   for (uint32_t s = 0; s < map->sampler_count; s++) {
>     +   uint32_t s = 0;
>     +   while (s < map->sampler_count) {
>            struct anv_pipeline_binding *binding =
>     &map->sampler_to_descriptor[s];
>            struct anv_descriptor_set *set =
>               cmd_buffer->state.descriptors[binding->set];
>     @@ -1744,19 +1745,24 @@ emit_samplers(struct anv_cmd_buffer
>     *cmd_buffer,
>            struct anv_descriptor *desc = &set->descriptors[offset +
>     binding->index];
>
>            if (desc->type != VK_DESCRIPTOR_TYPE_SAMPLER &&
>     -          desc->type != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
>     +          desc->type != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) {
>     +         s += 1;
>               continue;
>     +      }
>
>            struct anv_sampler *sampler = desc->sampler;
>
>            /* This can happen if we have an unfilled slot since
>     TYPE_SAMPLER
>             * happens to be zero.
>             */
>     -      if (sampler == NULL)
>     +      if (sampler == NULL) {
>     +         s += 1;
>               continue;
>     +      }
>
>            memcpy(state->map + (s * 16),
>     -             sampler->state, sizeof(sampler->state));
>     +             sampler->state, sampler->nb_planes *
>     sizeof(sampler->state[0]));
>     +      s += sampler->nb_planes;
>         }
>
>         anv_state_flush(cmd_buffer->device, *state);
>     diff --git a/src/intel/vulkan/genX_state.c
>     b/src/intel/vulkan/genX_state.c
>     index d016aff4a54..91e180bc7e4 100644
>     --- a/src/intel/vulkan/genX_state.c
>     +++ b/src/intel/vulkan/genX_state.c
>     @@ -171,6 +171,9 @@ VkResult genX(CreateSampler)(
>         if (!sampler)
>            return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
>
>     +   memset(sampler, 0, sizeof(*sampler));
>
>
> We have vk_zalloc for this.
>
>     +   sampler->nb_planes = 1;
>     +
>         uint32_t border_color_offset = device->border_colors.offset +
>      pCreateInfo->borderColor * 64;
>
>     @@ -179,55 +182,57 @@ VkResult genX(CreateSampler)(
>         bool enable_mag_filter_addr_rounding =
>            pCreateInfo->magFilter != VK_FILTER_NEAREST;
>
>     -   struct GENX(SAMPLER_STATE) sampler_state = {
>     -      .SamplerDisable = false,
>     -      .TextureBorderColorMode = DX10OGL,
>     +   for (unsigned p = 0; p < sampler->nb_planes; p++) {
>
>
> What's the difference between the N samplers you're creating here.  I 
> don't see any from my immediate reading of the diff but mayabe that's 
> just because there's too much churn or maybe it's just in a different 
> patch...

I guess I could take all of this genX_* stuff into its own patch.

>     +      struct GENX(SAMPLER_STATE) sampler_state = {
>     +         .SamplerDisable = false,
>     +         .TextureBorderColorMode = DX10OGL,
>
>      #if GEN_GEN >= 8
>     -      .LODPreClampMode = CLAMP_MODE_OGL,
>     +         .LODPreClampMode = CLAMP_MODE_OGL,
>      #else
>     -      .LODPreClampEnable = CLAMP_ENABLE_OGL,
>     +         .LODPreClampEnable = CLAMP_ENABLE_OGL,
>      #endif
>
>      #if GEN_GEN == 8
>     -      .BaseMipLevel = 0.0,
>     +         .BaseMipLevel = 0.0,
>      #endif
>     -      .MipModeFilter =
>     vk_to_gen_mipmap_mode[pCreateInfo->mipmapMode],
>     -      .MagModeFilter = vk_to_gen_tex_filter(pCreateInfo->magFilter,
>     - pCreateInfo->anisotropyEnable),
>     -      .MinModeFilter = vk_to_gen_tex_filter(pCreateInfo->minFilter,
>     - pCreateInfo->anisotropyEnable),
>     -      .TextureLODBias = anv_clamp_f(pCreateInfo->mipLodBias, -16,
>     15.996),
>     -      .AnisotropicAlgorithm = EWAApproximation,
>     -      .MinLOD = anv_clamp_f(pCreateInfo->minLod, 0, 14),
>     -      .MaxLOD = anv_clamp_f(pCreateInfo->maxLod, 0, 14),
>     -      .ChromaKeyEnable = 0,
>     -      .ChromaKeyIndex = 0,
>     -      .ChromaKeyMode = 0,
>     -      .ShadowFunction =
>     vk_to_gen_shadow_compare_op[pCreateInfo->compareOp],
>     -      .CubeSurfaceControlMode = OVERRIDE,
>     -
>     -      .BorderColorPointer = border_color_offset,
>     +         .MipModeFilter =
>     vk_to_gen_mipmap_mode[pCreateInfo->mipmapMode],
>     +         .MagModeFilter =
>     vk_to_gen_tex_filter(pCreateInfo->magFilter,
>     +  pCreateInfo->anisotropyEnable),
>     +         .MinModeFilter =
>     vk_to_gen_tex_filter(pCreateInfo->minFilter,
>     +  pCreateInfo->anisotropyEnable),
>     +         .TextureLODBias = anv_clamp_f(pCreateInfo->mipLodBias,
>     -16, 15.996),
>     +         .AnisotropicAlgorithm = EWAApproximation,
>     +         .MinLOD = anv_clamp_f(pCreateInfo->minLod, 0, 14),
>     +         .MaxLOD = anv_clamp_f(pCreateInfo->maxLod, 0, 14),
>     +         .ChromaKeyEnable = 0,
>     +         .ChromaKeyIndex = 0,
>     +         .ChromaKeyMode = 0,
>     +         .ShadowFunction =
>     vk_to_gen_shadow_compare_op[pCreateInfo->compareOp],
>     +         .CubeSurfaceControlMode = OVERRIDE,
>     +
>     +         .BorderColorPointer = border_color_offset,
>
>      #if GEN_GEN >= 8
>     -      .LODClampMagnificationMode = MIPNONE,
>     +         .LODClampMagnificationMode = MIPNONE,
>      #endif
>
>     -      .MaximumAnisotropy =
>     vk_to_gen_max_anisotropy(pCreateInfo->maxAnisotropy),
>     -      .RAddressMinFilterRoundingEnable =
>     enable_min_filter_addr_rounding,
>     -      .RAddressMagFilterRoundingEnable =
>     enable_mag_filter_addr_rounding,
>     -      .VAddressMinFilterRoundingEnable =
>     enable_min_filter_addr_rounding,
>     -      .VAddressMagFilterRoundingEnable =
>     enable_mag_filter_addr_rounding,
>     -      .UAddressMinFilterRoundingEnable =
>     enable_min_filter_addr_rounding,
>     -      .UAddressMagFilterRoundingEnable =
>     enable_mag_filter_addr_rounding,
>     -      .TrilinearFilterQuality = 0,
>     -      .NonnormalizedCoordinateEnable =
>     pCreateInfo->unnormalizedCoordinates,
>     -      .TCXAddressControlMode =
>     vk_to_gen_tex_address[pCreateInfo->addressModeU],
>     -      .TCYAddressControlMode =
>     vk_to_gen_tex_address[pCreateInfo->addressModeV],
>     -      .TCZAddressControlMode =
>     vk_to_gen_tex_address[pCreateInfo->addressModeW],
>     -   };
>     -
>     -   GENX(SAMPLER_STATE_pack)(NULL, sampler->state, &sampler_state);
>     +         .MaximumAnisotropy =
>     vk_to_gen_max_anisotropy(pCreateInfo->maxAnisotropy),
>     +         .RAddressMinFilterRoundingEnable =
>     enable_min_filter_addr_rounding,
>     +         .RAddressMagFilterRoundingEnable =
>     enable_mag_filter_addr_rounding,
>     +         .VAddressMinFilterRoundingEnable =
>     enable_min_filter_addr_rounding,
>     +         .VAddressMagFilterRoundingEnable =
>     enable_mag_filter_addr_rounding,
>     +         .UAddressMinFilterRoundingEnable =
>     enable_min_filter_addr_rounding,
>     +         .UAddressMagFilterRoundingEnable =
>     enable_mag_filter_addr_rounding,
>     +         .TrilinearFilterQuality = 0,
>     +         .NonnormalizedCoordinateEnable =
>     pCreateInfo->unnormalizedCoordinates,
>     +         .TCXAddressControlMode =
>     vk_to_gen_tex_address[pCreateInfo->addressModeU],
>     +         .TCYAddressControlMode =
>     vk_to_gen_tex_address[pCreateInfo->addressModeV],
>     +         .TCZAddressControlMode =
>     vk_to_gen_tex_address[pCreateInfo->addressModeW],
>     +      };
>     +
>     +      GENX(SAMPLER_STATE_pack)(NULL, sampler->state[p],
>     &sampler_state);
>     +   }
>
>         *pSampler = anv_sampler_to_handle(sampler);
>
>     --
>     2.14.1
>
>     _______________________________________________
>     mesa-dev mailing list
>     mesa-dev at lists.freedesktop.org <mailto:mesa-dev at lists.freedesktop.org>
>     https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>     <https://lists.freedesktop.org/mailman/listinfo/mesa-dev>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170925/9370832d/attachment-0001.html>


More information about the mesa-dev mailing list