radv: get rid of geometry user sgpr for num entries.
[mesa.git] / src / amd / vulkan / radv_descriptor_set.c
index 382fc9330aa76a71cef0042998d1e81172163674..3d56f8c2176fbed6434e5c268aba2169526c6ddb 100644 (file)
 #include "radv_private.h"
 #include "sid.h"
 
+
+static bool has_equal_immutable_samplers(const VkSampler *samplers, uint32_t count)
+{
+       if (!samplers)
+               return false;
+       for(uint32_t i = 1; i < count; ++i) {
+               if (memcmp(radv_sampler_from_handle(samplers[0])->state,
+                          radv_sampler_from_handle(samplers[i])->state, 16)) {
+                       return false;
+               }
+       }
+       return true;
+}
+
 VkResult radv_CreateDescriptorSetLayout(
        VkDevice                                    _device,
        const VkDescriptorSetLayoutCreateInfo*      pCreateInfo,
@@ -123,7 +137,6 @@ VkResult radv_CreateDescriptorSetLayout(
                }
 
                set_layout->size = align(set_layout->size, alignment);
-               assert(binding->descriptorCount > 0);
                set_layout->binding[b].type = binding->descriptorType;
                set_layout->binding[b].array_size = binding->descriptorCount;
                set_layout->binding[b].offset = set_layout->size;
@@ -132,15 +145,13 @@ 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->binding[b].immutable_samplers_equal =
+                               has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount);
                        set_layout->has_immutable_samplers = true;
 
 
                        for (uint32_t i = 0; i < binding->descriptorCount; i++)
                                memcpy(samplers + 4 * i, &radv_sampler_from_handle(binding->pImmutableSamplers[i])->state, 16);
-                       for (uint32_t i = 1; i < binding->descriptorCount; i++)
-                               if (memcmp(samplers + 4 * i, samplers, 16) != 0)
-                                       set_layout->binding[b].immutable_samplers_equal = false;
 
                        /* Don't reserve space for the samplers if they're not accessed. */
                        if (set_layout->binding[b].immutable_samplers_equal) {
@@ -182,6 +193,69 @@ void radv_DestroyDescriptorSetLayout(
        vk_free2(&device->alloc, pAllocator, set_layout);
 }
 
+void radv_GetDescriptorSetLayoutSupport(VkDevice device,
+                                        const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
+                                        VkDescriptorSetLayoutSupport* pSupport)
+{
+       bool supported = true;
+       uint64_t size = 0;
+       for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) {
+               const VkDescriptorSetLayoutBinding *binding = &pCreateInfo->pBindings[i];
+
+               if (binding->descriptorCount == 0)
+                       continue;
+
+               uint64_t descriptor_size = 0;
+               uint64_t descriptor_alignment = 1;
+               switch (binding->descriptorType) {
+               case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
+               case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
+                       break;
+               case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
+               case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
+               case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
+               case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
+                       descriptor_size = 16;
+                       descriptor_alignment = 16;
+                       break;
+               case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
+               case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
+               case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
+                       descriptor_size = 64;
+                       descriptor_alignment = 32;
+                       break;
+               case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
+                       if (!has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount)) {
+                               descriptor_size = 64;
+                       } else {
+                               descriptor_size = 96;
+                       }
+                       descriptor_alignment = 32;
+                       break;
+               case VK_DESCRIPTOR_TYPE_SAMPLER:
+                       if (!has_equal_immutable_samplers(binding->pImmutableSamplers, binding->descriptorCount)) {
+                               descriptor_size = 16;
+                               descriptor_alignment = 16;
+                       }
+                       break;
+               default:
+                       unreachable("unknown descriptor type\n");
+                       break;
+               }
+
+               if (size && !align_u64(size, descriptor_alignment)) {
+                       supported = false;
+               }
+               size = align_u64(size, descriptor_alignment);
+               if (descriptor_size && (UINT64_MAX - size) / descriptor_size < binding->descriptorCount) {
+                       supported = false;
+               }
+               size += binding->descriptorCount * descriptor_size;
+       }
+
+       pSupport->supported = supported;
+}
+
 /*
  * Pipeline layouts.  These have nothing to do with the pipeline.  They are
  * just muttiple descriptor set layouts pasted together
@@ -228,6 +302,7 @@ VkResult radv_CreatePipelineLayout(
 
        layout->dynamic_offset_count = dynamic_offset_count;
        layout->push_constant_size = 0;
+
        for (unsigned i = 0; i < pCreateInfo->pushConstantRangeCount; ++i) {
                const VkPushConstantRange *range = pCreateInfo->pPushConstantRanges + i;
                layout->push_constant_size = MAX2(layout->push_constant_size,
@@ -451,8 +526,10 @@ VkResult radv_CreateDescriptorPool(
        }
 
        if (bo_size) {
-               pool->bo = device->ws->buffer_create(device->ws, bo_size,
-                                                       32, RADEON_DOMAIN_VRAM, RADEON_FLAG_NO_INTERPROCESS_SHARING);
+               pool->bo = device->ws->buffer_create(device->ws, bo_size, 32,
+                                                    RADEON_DOMAIN_VRAM,
+                                                    RADEON_FLAG_NO_INTERPROCESS_SHARING |
+                                                    RADEON_FLAG_READ_ONLY);
                pool->mapped_ptr = (uint8_t*)device->ws->buffer_map(pool->bo);
        }
        pool->size = bo_size;
@@ -515,7 +592,7 @@ VkResult radv_AllocateDescriptorSets(
 
        VkResult result = VK_SUCCESS;
        uint32_t i;
-       struct radv_descriptor_set *set;
+       struct radv_descriptor_set *set = NULL;
 
        /* allocate a set of buffers for each shader to contain descriptors */
        for (i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
@@ -826,10 +903,10 @@ void radv_UpdateDescriptorSets(
                                    descriptorCopyCount, pDescriptorCopies);
 }
 
-VkResult radv_CreateDescriptorUpdateTemplateKHR(VkDevice _device,
-                                                const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo,
-                                                const VkAllocationCallbacks *pAllocator,
-                                                VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate)
+VkResult radv_CreateDescriptorUpdateTemplate(VkDevice _device,
+                                             const VkDescriptorUpdateTemplateCreateInfoKHR *pCreateInfo,
+                                             const VkAllocationCallbacks *pAllocator,
+                                             VkDescriptorUpdateTemplateKHR *pDescriptorUpdateTemplate)
 {
        RADV_FROM_HANDLE(radv_device, device, _device);
        RADV_FROM_HANDLE(radv_descriptor_set_layout, set_layout, pCreateInfo->descriptorSetLayout);
@@ -844,6 +921,7 @@ VkResult radv_CreateDescriptorUpdateTemplateKHR(VkDevice _device,
                return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
        templ->entry_count = entry_count;
+       templ->bind_point = pCreateInfo->pipelineBindPoint;
 
        for (i = 0; i < entry_count; i++) {
                const VkDescriptorUpdateTemplateEntryKHR *entry = &pCreateInfo->pDescriptorUpdateEntries[i];
@@ -898,9 +976,9 @@ VkResult radv_CreateDescriptorUpdateTemplateKHR(VkDevice _device,
        return VK_SUCCESS;
 }
 
-void radv_DestroyDescriptorUpdateTemplateKHR(VkDevice _device,
-                                             VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
-                                             const VkAllocationCallbacks *pAllocator)
+void radv_DestroyDescriptorUpdateTemplate(VkDevice _device,
+                                          VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
+                                          const VkAllocationCallbacks *pAllocator)
 {
        RADV_FROM_HANDLE(radv_device, device, _device);
        RADV_FROM_HANDLE(radv_descriptor_update_template, templ, descriptorUpdateTemplate);
@@ -979,13 +1057,31 @@ void radv_update_descriptor_set_with_template(struct radv_device *device,
        }
 }
 
-void radv_UpdateDescriptorSetWithTemplateKHR(VkDevice _device,
-                                             VkDescriptorSet descriptorSet,
-                                             VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
-                                             const void *pData)
+void radv_UpdateDescriptorSetWithTemplate(VkDevice _device,
+                                          VkDescriptorSet descriptorSet,
+                                          VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
+                                          const void *pData)
 {
        RADV_FROM_HANDLE(radv_device, device, _device);
        RADV_FROM_HANDLE(radv_descriptor_set, set, descriptorSet);
 
        radv_update_descriptor_set_with_template(device, NULL, set, descriptorUpdateTemplate, pData);
 }
+
+
+VkResult radv_CreateSamplerYcbcrConversion(VkDevice device,
+                                          const VkSamplerYcbcrConversionCreateInfo* pCreateInfo,
+                                          const VkAllocationCallbacks* pAllocator,
+                                          VkSamplerYcbcrConversion* pYcbcrConversion)
+{
+       *pYcbcrConversion = VK_NULL_HANDLE;
+       return VK_SUCCESS;
+}
+
+
+void radv_DestroySamplerYcbcrConversion(VkDevice device,
+                                       VkSamplerYcbcrConversion ycbcrConversion,
+                                       const VkAllocationCallbacks* pAllocator)
+{
+       /* Do nothing. */
+}