radv: Only enter the immutable samplers init loop when we have some.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sun, 17 Sep 2017 10:59:24 +0000 (12:59 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Wed, 20 Sep 2017 20:04:25 +0000 (22:04 +0200)
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/vulkan/radv_descriptor_set.c
src/amd/vulkan/radv_descriptor_set.h

index 314ab5a96d04bdde12747e7c5d74d22713446095..5b9cfe66331102ec714d27959c50cb5efdb28c55 100644 (file)
@@ -67,6 +67,7 @@ VkResult radv_CreateDescriptorSetLayout(
        set_layout->binding_count = max_binding + 1;
        set_layout->shader_stages = 0;
        set_layout->dynamic_shader_stages = 0;
+       set_layout->has_immutable_samplers = false;
        set_layout->size = 0;
 
        memset(set_layout->binding, 0, size - sizeof(struct radv_descriptor_set_layout));
@@ -132,6 +133,7 @@ VkResult radv_CreateDescriptorSetLayout(
                if (binding->pImmutableSamplers) {
                        set_layout->binding[b].immutable_samplers_offset = samplers_offset;
                        set_layout->binding[b].immutable_samplers_equal = true;
+                       set_layout->has_immutable_samplers = true;
 
 
                        for (uint32_t i = 0; i < binding->descriptorCount; i++)
@@ -329,21 +331,23 @@ radv_descriptor_set_create(struct radv_device *device,
                        return vk_error(VK_ERROR_OUT_OF_POOL_MEMORY_KHR);
        }
 
-       for (unsigned i = 0; i < layout->binding_count; ++i) {
-               if (!layout->binding[i].immutable_samplers_offset ||
-                   layout->binding[i].immutable_samplers_equal)
-                       continue;
+       if (layout->has_immutable_samplers) {
+               for (unsigned i = 0; i < layout->binding_count; ++i) {
+                       if (!layout->binding[i].immutable_samplers_offset ||
+                       layout->binding[i].immutable_samplers_equal)
+                               continue;
 
-               unsigned offset = layout->binding[i].offset / 4;
-               if (layout->binding[i].type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
-                       offset += 16;
+                       unsigned offset = layout->binding[i].offset / 4;
+                       if (layout->binding[i].type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
+                               offset += 16;
 
-               const uint32_t *samplers = (const uint32_t*)((const char*)layout + layout->binding[i].immutable_samplers_offset);
-               for (unsigned j = 0; j < layout->binding[i].array_size; ++j) {
-                       memcpy(set->mapped_ptr + offset, samplers + 4 * j, 16);
-                       offset += layout->binding[i].size / 4;
-               }
+                       const uint32_t *samplers = (const uint32_t*)((const char*)layout + layout->binding[i].immutable_samplers_offset);
+                       for (unsigned j = 0; j < layout->binding[i].array_size; ++j) {
+                               memcpy(set->mapped_ptr + offset, samplers + 4 * j, 16);
+                               offset += layout->binding[i].size / 4;
+                       }
 
+               }
        }
        *out_set = set;
        return VK_SUCCESS;
index 4b63992b2bb038b2e36777fe9b3b08cfc2dc8538..7fa79186a17197da2b752e6060f3df8d8afd44dc 100644 (file)
@@ -68,6 +68,8 @@ struct radv_descriptor_set_layout {
    /* Number of dynamic offsets used by this descriptor set */
    uint16_t dynamic_offset_count;
 
+   bool has_immutable_samplers;
+
    /* Bindings in this descriptor set */
    struct radv_descriptor_set_binding_layout binding[0];
 };