cmd_buffer->state.descriptors[_set] = set;
cmd_buffer->state.descriptors_dirty |= set_layout->shader_stages;
}
+
+void anv_CmdPushDescriptorSetWithTemplateKHR(
+ VkCommandBuffer commandBuffer,
+ VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
+ VkPipelineLayout _layout,
+ uint32_t _set,
+ const void* pData)
+{
+ ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer);
+ ANV_FROM_HANDLE(anv_descriptor_update_template, template,
+ descriptorUpdateTemplate);
+ ANV_FROM_HANDLE(anv_pipeline_layout, layout, _layout);
+
+ assert(_set < MAX_PUSH_DESCRIPTORS);
+
+ const struct anv_descriptor_set_layout *set_layout =
+ layout->set[_set].layout;
+ struct anv_descriptor_set *set = &cmd_buffer->state.push_descriptor.set;
+
+ set->layout = set_layout;
+ set->size = anv_descriptor_set_layout_size(set_layout);
+ set->buffer_count = set_layout->buffer_count;
+ set->buffer_views = cmd_buffer->state.push_descriptor.buffer_views;
+
+ anv_descriptor_set_write_template(set,
+ cmd_buffer->device,
+ &cmd_buffer->surface_state_stream,
+ template,
+ pData);
+
+ cmd_buffer->state.descriptors[_set] = set;
+ cmd_buffer->state.descriptors_dirty |= set_layout->shader_stages;
+}
dst_desc[j] = src_desc[j];
}
}
+
+/*
+ * Descriptor update templates.
+ */
+
+void
+anv_descriptor_set_write_template(struct anv_descriptor_set *set,
+ struct anv_device *device,
+ struct anv_state_stream *alloc_stream,
+ const struct anv_descriptor_update_template *template,
+ const void *data)
+{
+ const struct anv_descriptor_set_layout *layout = set->layout;
+
+ for (uint32_t i = 0; i < template->entry_count; i++) {
+ const struct anv_descriptor_template_entry *entry =
+ &template->entries[i];
+ const struct anv_descriptor_set_binding_layout *bind_layout =
+ &layout->binding[entry->binding];
+ struct anv_descriptor *desc = &set->descriptors[bind_layout->descriptor_index];
+ desc += entry->array_element;
+
+ switch (entry->type) {
+ case VK_DESCRIPTOR_TYPE_SAMPLER:
+ case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
+ case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
+ case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
+ case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
+ for (uint32_t j = 0; j < entry->array_count; j++) {
+ const VkDescriptorImageInfo *info =
+ data + entry->offset + j * entry->stride;
+ anv_descriptor_set_write_image_view(set,
+ entry->type,
+ info->imageView,
+ info->sampler,
+ entry->binding,
+ entry->array_element + j);
+ }
+ break;
+
+ case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
+ case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
+ for (uint32_t j = 0; j < entry->array_count; j++) {
+ const VkBufferView *_bview =
+ data + entry->offset + j * entry->stride;
+ ANV_FROM_HANDLE(anv_buffer_view, bview, *_bview);
+
+ anv_descriptor_set_write_buffer_view(set,
+ entry->type,
+ bview,
+ entry->binding,
+ entry->array_element + j);
+ }
+ 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:
+ for (uint32_t j = 0; j < entry->array_count; j++) {
+ const VkDescriptorBufferInfo *info =
+ data + entry->offset + j * entry->stride;
+ ANV_FROM_HANDLE(anv_buffer, buffer, info->buffer);
+
+ anv_descriptor_set_write_buffer(set,
+ device,
+ alloc_stream,
+ entry->type,
+ buffer,
+ entry->binding,
+ entry->array_element + j,
+ info->offset, info->range);
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+}
+
+VkResult anv_CreateDescriptorUpdateTemplateKHR(
+ VkDevice _device,
+ const VkDescriptorUpdateTemplateCreateInfoKHR* pCreateInfo,
+ const VkAllocationCallbacks* pAllocator,
+ VkDescriptorUpdateTemplateKHR* pDescriptorUpdateTemplate)
+{
+ ANV_FROM_HANDLE(anv_device, device, _device);
+ struct anv_descriptor_update_template *template;
+
+ size_t size = sizeof(*template) +
+ pCreateInfo->descriptorUpdateEntryCount * sizeof(template->entries[0]);
+ template = vk_alloc2(&device->alloc, pAllocator, size, 8,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ if (template == NULL)
+ return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+ if (pCreateInfo->templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR)
+ template->set = pCreateInfo->set;
+
+ template->entry_count = pCreateInfo->descriptorUpdateEntryCount;
+ for (uint32_t i = 0; i < template->entry_count; i++) {
+ const VkDescriptorUpdateTemplateEntryKHR *pEntry =
+ &pCreateInfo->pDescriptorUpdateEntries[i];
+
+ template->entries[i] = (struct anv_descriptor_template_entry) {
+ .type = pEntry->descriptorType,
+ .binding = pEntry->dstBinding,
+ .array_element = pEntry->dstArrayElement,
+ .array_count = pEntry->descriptorCount,
+ .offset = pEntry->offset,
+ .stride = pEntry->stride,
+ };
+ }
+
+ *pDescriptorUpdateTemplate =
+ anv_descriptor_update_template_to_handle(template);
+
+ return VK_SUCCESS;
+}
+
+void anv_DestroyDescriptorUpdateTemplateKHR(
+ VkDevice _device,
+ VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
+ const VkAllocationCallbacks* pAllocator)
+{
+ ANV_FROM_HANDLE(anv_device, device, _device);
+ ANV_FROM_HANDLE(anv_descriptor_update_template, template,
+ descriptorUpdateTemplate);
+
+ vk_free2(&device->alloc, pAllocator, template);
+}
+
+void anv_UpdateDescriptorSetWithTemplateKHR(
+ VkDevice _device,
+ VkDescriptorSet descriptorSet,
+ VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
+ const void* pData)
+{
+ ANV_FROM_HANDLE(anv_device, device, _device);
+ ANV_FROM_HANDLE(anv_descriptor_set, set, descriptorSet);
+ ANV_FROM_HANDLE(anv_descriptor_update_template, template,
+ descriptorUpdateTemplate);
+
+ anv_descriptor_set_write_template(set, device, NULL, template, pData);
+}
char data[0];
};
+enum anv_descriptor_template_entry_type {
+ ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_IMAGE,
+ ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER,
+ ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER_VIEW
+};
+
+struct anv_descriptor_template_entry {
+ /* The type of descriptor in this entry */
+ VkDescriptorType type;
+
+ /* Binding in the descriptor set */
+ uint32_t binding;
+
+ /* Offset at which to write into the descriptor set binding */
+ uint32_t array_element;
+
+ /* Number of elements to write into the descriptor set binding */
+ uint32_t array_count;
+
+ /* Offset into the user provided data */
+ size_t offset;
+
+ /* Stride between elements into the user provided data */
+ size_t stride;
+};
+
+struct anv_descriptor_update_template {
+ /* The descriptor set this template corresponds to. This value is only
+ * valid if the template was created with the templateType
+ * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR.
+ */
+ uint8_t set;
+
+ /* Number of entries in this template */
+ uint32_t entry_count;
+
+ /* Entries of the template */
+ struct anv_descriptor_template_entry entries[0];
+};
+
size_t
anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout *layout);
VkDeviceSize offset,
VkDeviceSize range);
+void
+anv_descriptor_set_write_template(struct anv_descriptor_set *set,
+ struct anv_device *device,
+ struct anv_state_stream *alloc_stream,
+ const struct anv_descriptor_update_template *template,
+ const void *data);
+
VkResult
anv_descriptor_set_create(struct anv_device *device,
struct anv_descriptor_pool *pool,
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool, VkDescriptorPool)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout)
+ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_update_template, VkDescriptorUpdateTemplateKHR)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence, VkFence)
ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event, VkEvent)