radv: fix null memcpy and zero-sized malloc
[mesa.git] / src / amd / vulkan / radv_descriptor_set.c
index 4e9c73c94d0ac70fb7a010281ea8e75a9b34dd66..e4634eed6635251f31844c5c742566f7ed4d14b0 100644 (file)
@@ -57,13 +57,14 @@ static int binding_compare(const void* av, const void *bv)
 
 static VkDescriptorSetLayoutBinding *
 create_sorted_bindings(const VkDescriptorSetLayoutBinding *bindings, unsigned count) {
-       VkDescriptorSetLayoutBinding *sorted_bindings = malloc(count * sizeof(VkDescriptorSetLayoutBinding));
+       VkDescriptorSetLayoutBinding *sorted_bindings = malloc(MAX2(count * sizeof(VkDescriptorSetLayoutBinding), 1));
        if (!sorted_bindings)
                return NULL;
 
-       memcpy(sorted_bindings, bindings, count * sizeof(VkDescriptorSetLayoutBinding));
-
-       qsort(sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding), binding_compare);
+       if (count) {
+               memcpy(sorted_bindings, bindings, count * sizeof(VkDescriptorSetLayoutBinding));
+               qsort(sorted_bindings, count, sizeof(VkDescriptorSetLayoutBinding), binding_compare);
+       }
 
        return sorted_bindings;
 }
@@ -78,8 +79,8 @@ VkResult radv_CreateDescriptorSetLayout(
        struct radv_descriptor_set_layout *set_layout;
 
        assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);
-       const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT *variable_flags =
-               vk_find_struct_const(pCreateInfo->pNext, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT);
+       const VkDescriptorSetLayoutBindingFlagsCreateInfo *variable_flags =
+               vk_find_struct_const(pCreateInfo->pNext, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO);
 
        uint32_t max_binding = 0;
        uint32_t immutable_sampler_count = 0;
@@ -102,18 +103,21 @@ VkResult radv_CreateDescriptorSetLayout(
                }
        }
 
-       uint32_t samplers_offset = sizeof(struct radv_descriptor_set_layout) +
-               (max_binding + 1) * sizeof(set_layout->binding[0]);
+       uint32_t samplers_offset =
+                       offsetof(struct radv_descriptor_set_layout, binding[max_binding + 1]);
        size_t size = samplers_offset + immutable_sampler_count * 4 * sizeof(uint32_t);
        if (ycbcr_sampler_count > 0) {
                size += ycbcr_sampler_count * sizeof(struct radv_sampler_ycbcr_conversion) + (max_binding + 1) * sizeof(uint32_t);
        }
 
-       set_layout = vk_zalloc2(&device->alloc, pAllocator, size, 8,
+       set_layout = vk_zalloc2(&device->vk.alloc, pAllocator, size, 8,
                                VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
        if (!set_layout)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       vk_object_base_init(&device->vk, &set_layout->base,
+                           VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT);
+
        set_layout->flags = pCreateInfo->flags;
        set_layout->layout_size = size;
 
@@ -132,7 +136,8 @@ VkResult radv_CreateDescriptorSetLayout(
        VkDescriptorSetLayoutBinding *bindings = create_sorted_bindings(pCreateInfo->pBindings,
                                                                        pCreateInfo->bindingCount);
        if (!bindings) {
-               vk_free2(&device->alloc, pAllocator, set_layout);
+               vk_object_base_finish(&set_layout->base);
+               vk_free2(&device->vk.alloc, pAllocator, set_layout);
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
        }
 
@@ -142,15 +147,13 @@ VkResult radv_CreateDescriptorSetLayout(
        set_layout->has_immutable_samplers = false;
        set_layout->size = 0;
 
-       memset(set_layout->binding, 0, size - sizeof(struct radv_descriptor_set_layout));
-
        uint32_t buffer_count = 0;
        uint32_t dynamic_offset_count = 0;
 
        for (uint32_t j = 0; j < pCreateInfo->bindingCount; j++) {
                const VkDescriptorSetLayoutBinding *binding = bindings + j;
                uint32_t b = binding->binding;
-               uint32_t alignment;
+               uint32_t alignment = 0;
                unsigned binding_buffer_count = 0;
                uint32_t descriptor_count = binding->descriptorCount;
                bool has_ycbcr_sampler = false;
@@ -200,7 +203,7 @@ VkResult radv_CreateDescriptorSetLayout(
                        break;
                case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
                        /* main descriptor + fmask descriptor + sampler */
-                       set_layout->binding[b].size = 32 + 32 * max_sampled_image_descriptors;
+                       set_layout->binding[b].size = 96;
                        binding_buffer_count = 1;
                        alignment = 32;
                        break;
@@ -214,7 +217,6 @@ VkResult radv_CreateDescriptorSetLayout(
                        descriptor_count = 1;
                        break;
                default:
-                       unreachable("unknown descriptor type\n");
                        break;
                }
 
@@ -247,7 +249,8 @@ VkResult radv_CreateDescriptorSetLayout(
 
                        /* Don't reserve space for the samplers if they're not accessed. */
                        if (set_layout->binding[b].immutable_samplers_equal) {
-                               if (binding->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
+                               if (binding->descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER &&
+                                   max_sampled_image_descriptors <= 2)
                                        set_layout->binding[b].size -= 32;
                                else if (binding->descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER)
                                        set_layout->binding[b].size -= 16;
@@ -295,7 +298,8 @@ void radv_DestroyDescriptorSetLayout(
        if (!set_layout)
                return;
 
-       vk_free2(&device->alloc, pAllocator, set_layout);
+       vk_object_base_finish(&set_layout->base);
+       vk_free2(&device->vk.alloc, pAllocator, set_layout);
 }
 
 void radv_GetDescriptorSetLayoutSupport(VkDevice device,
@@ -309,10 +313,10 @@ void radv_GetDescriptorSetLayoutSupport(VkDevice device,
                return;
        }
 
-       const VkDescriptorSetLayoutBindingFlagsCreateInfoEXT *variable_flags =
-               vk_find_struct_const(pCreateInfo->pNext, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT);
-       VkDescriptorSetVariableDescriptorCountLayoutSupportEXT *variable_count =
-               vk_find_struct((void*)pCreateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT_EXT);
+       const VkDescriptorSetLayoutBindingFlagsCreateInfo *variable_flags =
+               vk_find_struct_const(pCreateInfo->pNext, DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO);
+       VkDescriptorSetVariableDescriptorCountLayoutSupport *variable_count =
+               vk_find_struct((void*)pCreateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_LAYOUT_SUPPORT);
        if (variable_count) {
                variable_count->maxVariableDescriptorCount = 0;
        }
@@ -362,7 +366,6 @@ void radv_GetDescriptorSetLayoutSupport(VkDevice device,
                        descriptor_count = 1;
                        break;
                default:
-                       unreachable("unknown descriptor type\n");
                        break;
                }
 
@@ -409,11 +412,14 @@ VkResult radv_CreatePipelineLayout(
 
        assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO);
 
-       layout = vk_alloc2(&device->alloc, pAllocator, sizeof(*layout), 8,
+       layout = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*layout), 8,
                             VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
        if (layout == NULL)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       vk_object_base_init(&device->vk, &layout->base,
+                           VK_OBJECT_TYPE_PIPELINE_LAYOUT);
+
        layout->num_sets = pCreateInfo->setLayoutCount;
 
        unsigned dynamic_offset_count = 0;
@@ -463,7 +469,9 @@ void radv_DestroyPipelineLayout(
 
        if (!pipeline_layout)
                return;
-       vk_free2(&device->alloc, pAllocator, pipeline_layout);
+
+       vk_object_base_finish(&pipeline_layout->base);
+       vk_free2(&device->vk.alloc, pAllocator, pipeline_layout);
 }
 
 #define EMPTY 1
@@ -476,8 +484,17 @@ radv_descriptor_set_create(struct radv_device *device,
                           struct radv_descriptor_set **out_set)
 {
        struct radv_descriptor_set *set;
+       uint32_t buffer_count = layout->buffer_count;
+       if (variable_count) {
+               unsigned stride = 1;
+               if (layout->binding[layout->binding_count - 1].type == VK_DESCRIPTOR_TYPE_SAMPLER ||
+                   layout->binding[layout->binding_count - 1].type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT)
+                       stride = 0;
+               buffer_count = layout->binding[layout->binding_count - 1].buffer_offset +
+                              *variable_count * stride;
+       }
        unsigned range_offset = sizeof(struct radv_descriptor_set) +
-               sizeof(struct radeon_winsys_bo *) * layout->buffer_count;
+               sizeof(struct radeon_winsys_bo *) * buffer_count;
        unsigned mem_size = range_offset +
                sizeof(struct radv_descriptor_range) * layout->dynamic_offset_count;
 
@@ -488,7 +505,7 @@ radv_descriptor_set_create(struct radv_device *device,
                set = (struct radv_descriptor_set*)pool->host_memory_ptr;
                pool->host_memory_ptr += mem_size;
        } else {
-               set = vk_alloc2(&device->alloc, NULL, mem_size, 8,
+               set = vk_alloc2(&device->vk.alloc, NULL, mem_size, 8,
                                VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 
                if (!set)
@@ -497,17 +514,31 @@ radv_descriptor_set_create(struct radv_device *device,
 
        memset(set, 0, mem_size);
 
+       vk_object_base_init(&device->vk, &set->base,
+                           VK_OBJECT_TYPE_DESCRIPTOR_SET);
+
        if (layout->dynamic_offset_count) {
                set->dynamic_descriptors = (struct radv_descriptor_range*)((uint8_t*)set + range_offset);
        }
 
        set->layout = layout;
-       uint32_t layout_size = align_u32(layout->size, 32);
+       set->buffer_count = buffer_count;
+       uint32_t layout_size = layout->size;
+       if (variable_count) {
+               assert(layout->has_variable_descriptors);
+               uint32_t stride = layout->binding[layout->binding_count - 1].size;
+               if (layout->binding[layout->binding_count - 1].type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT)
+                       stride = 1;
+
+               layout_size = layout->binding[layout->binding_count - 1].offset +
+                             *variable_count * stride;
+       }
+       layout_size = align_u32(layout_size, 32);
        if (layout_size) {
                set->size = layout_size;
 
                if (!pool->host_memory_base && pool->entry_count == pool->max_entry_count) {
-                       vk_free2(&device->alloc, NULL, set);
+                       vk_free2(&device->vk.alloc, NULL, set);
                        return vk_error(device->instance, VK_ERROR_OUT_OF_POOL_MEMORY);
                }
 
@@ -536,7 +567,7 @@ radv_descriptor_set_create(struct radv_device *device,
                        }
 
                        if (pool->size - offset < layout_size) {
-                               vk_free2(&device->alloc, NULL, set);
+                               vk_free2(&device->vk.alloc, NULL, set);
                                return vk_error(device->instance, VK_ERROR_OUT_OF_POOL_MEMORY);
                        }
                        set->bo = pool->bo;
@@ -593,7 +624,25 @@ radv_descriptor_set_destroy(struct radv_device *device,
                        }
                }
        }
-       vk_free2(&device->alloc, NULL, set);
+       vk_object_base_finish(&set->base);
+       vk_free2(&device->vk.alloc, NULL, set);
+}
+
+static void radv_destroy_descriptor_pool(struct radv_device *device,
+                                         const VkAllocationCallbacks *pAllocator,
+                                         struct radv_descriptor_pool *pool)
+{
+       if (!pool->host_memory_base) {
+               for(int i = 0; i < pool->entry_count; ++i) {
+                       radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
+               }
+       }
+
+       if (pool->bo)
+               device->ws->buffer_destroy(pool->bo);
+
+       vk_object_base_finish(&pool->base);
+       vk_free2(&device->vk.alloc, pAllocator, pool);
 }
 
 VkResult radv_CreateDescriptorPool(
@@ -652,7 +701,6 @@ VkResult radv_CreateDescriptorPool(
                        bo_size += pCreateInfo->pPoolSizes[i].descriptorCount;
                        break;
                default:
-                       unreachable("unknown descriptor type\n");
                        break;
                }
        }
@@ -666,13 +714,16 @@ VkResult radv_CreateDescriptorPool(
                size += sizeof(struct radv_descriptor_pool_entry) * pCreateInfo->maxSets;
        }
 
-       pool = vk_alloc2(&device->alloc, pAllocator, size, 8,
+       pool = vk_alloc2(&device->vk.alloc, pAllocator, size, 8,
                         VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
        if (!pool)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
        memset(pool, 0, sizeof(*pool));
 
+       vk_object_base_init(&device->vk, &pool->base,
+                           VK_OBJECT_TYPE_DESCRIPTOR_POOL);
+
        if (!(pCreateInfo->flags & VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT)) {
                pool->host_memory_base = (uint8_t*)pool + sizeof(struct radv_descriptor_pool);
                pool->host_memory_ptr = pool->host_memory_base;
@@ -686,7 +737,15 @@ VkResult radv_CreateDescriptorPool(
                                                     RADEON_FLAG_READ_ONLY |
                                                     RADEON_FLAG_32BIT,
                                                     RADV_BO_PRIORITY_DESCRIPTOR);
+               if (!pool->bo) {
+                       radv_destroy_descriptor_pool(device, pAllocator, pool);
+                       return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+               }
                pool->mapped_ptr = (uint8_t*)device->ws->buffer_map(pool->bo);
+               if (!pool->mapped_ptr) {
+                       radv_destroy_descriptor_pool(device, pAllocator, pool);
+                       return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+               }
        }
        pool->size = bo_size;
        pool->max_entry_count = pCreateInfo->maxSets;
@@ -706,15 +765,7 @@ void radv_DestroyDescriptorPool(
        if (!pool)
                return;
 
-       if (!pool->host_memory_base) {
-               for(int i = 0; i < pool->entry_count; ++i) {
-                       radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
-               }
-       }
-
-       if (pool->bo)
-               device->ws->buffer_destroy(pool->bo);
-       vk_free2(&device->alloc, pAllocator, pool);
+       radv_destroy_descriptor_pool(device, pAllocator, pool);
 }
 
 VkResult radv_ResetDescriptorPool(
@@ -750,8 +801,8 @@ VkResult radv_AllocateDescriptorSets(
        uint32_t i;
        struct radv_descriptor_set *set = NULL;
 
-       const VkDescriptorSetVariableDescriptorCountAllocateInfoEXT *variable_counts =
-               vk_find_struct_const(pAllocateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO_EXT);
+       const VkDescriptorSetVariableDescriptorCountAllocateInfo *variable_counts =
+               vk_find_struct_const(pAllocateInfo->pNext, DESCRIPTOR_SET_VARIABLE_DESCRIPTOR_COUNT_ALLOCATE_INFO);
        const uint32_t zero = 0;
 
        /* allocate a set of buffers for each shader to contain descriptors */
@@ -776,9 +827,13 @@ VkResult radv_AllocateDescriptorSets(
                pDescriptorSets[i] = radv_descriptor_set_to_handle(set);
        }
 
-       if (result != VK_SUCCESS)
+       if (result != VK_SUCCESS) {
                radv_FreeDescriptorSets(_device, pAllocateInfo->descriptorPool,
                                        i, pDescriptorSets);
+               for (i = 0; i < pAllocateInfo->descriptorSetCount; i++) {
+                       pDescriptorSets[i] = VK_NULL_HANDLE;
+               }
+       }
        return result;
 }
 
@@ -808,6 +863,11 @@ static void write_texel_buffer_descriptor(struct radv_device *device,
 {
        RADV_FROM_HANDLE(radv_buffer_view, buffer_view, _buffer_view);
 
+       if (!buffer_view) {
+               memset(dst, 0, 4 * 4);
+               return;
+       }
+
        memcpy(dst, buffer_view->state, 4 * 4);
 
        if (cmd_buffer)
@@ -823,22 +883,44 @@ static void write_buffer_descriptor(struct radv_device *device,
                                     const VkDescriptorBufferInfo *buffer_info)
 {
        RADV_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer);
+
+       if (!buffer) {
+               memset(dst, 0, 4 * 4);
+               return;
+       }
+
        uint64_t va = radv_buffer_get_va(buffer->bo);
        uint32_t range = buffer_info->range;
 
        if (buffer_info->range == VK_WHOLE_SIZE)
                range = buffer->size - buffer_info->offset;
 
+       /* robustBufferAccess is relaxed enough to allow this (in combination
+        * with the alignment/size we return from vkGetBufferMemoryRequirements)
+        * and this allows the shader compiler to create more efficient 8/16-bit
+        * buffer accesses. */
+       range = align(range, 4);
+
        va += buffer_info->offset + buffer->offset;
+
+       uint32_t rsrc_word3 = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
+                             S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
+                             S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
+                             S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W);
+
+       if (device->physical_device->rad_info.chip_class >= GFX10) {
+               rsrc_word3 |= S_008F0C_FORMAT(V_008F0C_IMG_FORMAT_32_FLOAT) |
+                             S_008F0C_OOB_SELECT(V_008F0C_OOB_SELECT_RAW) |
+                             S_008F0C_RESOURCE_LEVEL(1);
+       } else {
+               rsrc_word3 |= S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
+                             S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32);
+       }
+
        dst[0] = va;
        dst[1] = S_008F04_BASE_ADDRESS_HI(va >> 32);
        dst[2] = range;
-       dst[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X) |
-               S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y) |
-               S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z) |
-               S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W) |
-               S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
-               S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32);
+       dst[3] = rsrc_word3;
 
        if (cmd_buffer)
                radv_cs_add_buffer(device->ws, cmd_buffer->cs, buffer->bo);
@@ -863,12 +945,24 @@ static void write_dynamic_buffer_descriptor(struct radv_device *device,
                                             const VkDescriptorBufferInfo *buffer_info)
 {
        RADV_FROM_HANDLE(radv_buffer, buffer, buffer_info->buffer);
-       uint64_t va = radv_buffer_get_va(buffer->bo);
-       unsigned size = buffer_info->range;
+       uint64_t va;
+       unsigned size;
+
+       if (!buffer)
+               return;
+
+       va = radv_buffer_get_va(buffer->bo);
+       size = buffer_info->range;
 
        if (buffer_info->range == VK_WHOLE_SIZE)
                size = buffer->size - buffer_info->offset;
 
+       /* robustBufferAccess is relaxed enough to allow this (in combination
+        * with the alignment/size we return from vkGetBufferMemoryRequirements)
+        * and this allows the shader compiler to create more efficient 8/16-bit
+        * buffer accesses. */
+       size = align(size, 4);
+
        va += buffer_info->offset + buffer->offset;
        range->va = va;
        range->size = size;
@@ -887,6 +981,11 @@ write_image_descriptor(struct radv_device *device,
        RADV_FROM_HANDLE(radv_image_view, iview, image_info->imageView);
        union radv_descriptor *descriptor;
 
+       if (!iview) {
+               memset(dst, 0, size);
+               return;
+       }
+
        if (descriptor_type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) {
                descriptor = &iview->storage_descriptor;
        } else {
@@ -1018,7 +1117,6 @@ void radv_update_descriptor_sets(
                                }
                                break;
                        default:
-                               unreachable("unimplemented descriptor type");
                                break;
                        }
                        ptr += binding_layout->size / 4;
@@ -1045,6 +1143,14 @@ void radv_update_descriptor_sets(
                src_ptr += src_binding_layout->offset / 4;
                dst_ptr += dst_binding_layout->offset / 4;
 
+               if (src_binding_layout->type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
+                       src_ptr += copyset->srcArrayElement / 4;
+                       dst_ptr += copyset->dstArrayElement / 4;
+
+                       memcpy(dst_ptr, src_ptr, copyset->descriptorCount);
+                       continue;
+               }
+
                src_ptr += src_binding_layout->size * copyset->srcArrayElement / 4;
                dst_ptr += dst_binding_layout->size * copyset->dstArrayElement / 4;
 
@@ -1109,12 +1215,26 @@ VkResult radv_CreateDescriptorUpdateTemplate(VkDevice _device,
        struct radv_descriptor_update_template *templ;
        uint32_t i;
 
-       templ = vk_alloc2(&device->alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+       templ = vk_alloc2(&device->vk.alloc, pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
        if (!templ)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       vk_object_base_init(&device->vk, &templ->base,
+                           VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE);
+
        templ->entry_count = entry_count;
-       templ->bind_point = pCreateInfo->pipelineBindPoint;
+
+       if (pCreateInfo->templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR) {
+               RADV_FROM_HANDLE(radv_pipeline_layout, pipeline_layout, pCreateInfo->pipelineLayout);
+
+               /* descriptorSetLayout should be ignored for push descriptors
+                * and instead it refers to pipelineLayout and set.
+                */
+               assert(pCreateInfo->set < MAX_SETS);
+               set_layout = pipeline_layout->set[pCreateInfo->set].layout;
+
+               templ->bind_point = pCreateInfo->pipelineBindPoint;
+       }
 
        for (i = 0; i < entry_count; i++) {
                const VkDescriptorUpdateTemplateEntry *entry = &pCreateInfo->pDescriptorUpdateEntries[i];
@@ -1185,7 +1305,8 @@ void radv_DestroyDescriptorUpdateTemplate(VkDevice _device,
        if (!templ)
                return;
 
-       vk_free2(&device->alloc, pAllocator, templ);
+       vk_object_base_finish(&templ->base);
+       vk_free2(&device->vk.alloc, pAllocator, templ);
 }
 
 void radv_update_descriptor_set_with_template(struct radv_device *device,
@@ -1252,7 +1373,6 @@ void radv_update_descriptor_set_with_template(struct radv_device *device,
                                        memcpy(pDst, templ->entry[i].immutable_samplers + 4 * j, 16);
                                break;
                        default:
-                               unreachable("unimplemented descriptor type");
                                break;
                        }
                        pSrc += templ->entry[i].src_stride;
@@ -1282,12 +1402,15 @@ VkResult radv_CreateSamplerYcbcrConversion(VkDevice _device,
        RADV_FROM_HANDLE(radv_device, device, _device);
        struct radv_sampler_ycbcr_conversion *conversion = NULL;
 
-       conversion = vk_zalloc2(&device->alloc, pAllocator, sizeof(*conversion), 8,
+       conversion = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*conversion), 8,
                                VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 
        if (conversion == NULL)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       vk_object_base_init(&device->vk, &conversion->base,
+                           VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION);
+
        conversion->format = pCreateInfo->format;
        conversion->ycbcr_model = pCreateInfo->ycbcrModel;
        conversion->ycbcr_range = pCreateInfo->ycbcrRange;
@@ -1308,6 +1431,9 @@ void radv_DestroySamplerYcbcrConversion(VkDevice _device,
        RADV_FROM_HANDLE(radv_device, device, _device);
        RADV_FROM_HANDLE(radv_sampler_ycbcr_conversion, ycbcr_conversion, ycbcrConversion);
 
-       if (ycbcr_conversion)
-               vk_free2(&device->alloc, pAllocator, ycbcr_conversion);
+       if (!ycbcr_conversion)
+               return;
+
+       vk_object_base_finish(&ycbcr_conversion->base);
+       vk_free2(&device->vk.alloc, pAllocator, ycbcr_conversion);
 }