lvp: use common descriptor update templates

this is now at parity with what we did. this gets rid of all divergence between
us and common vk enqueue.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28682>
This commit is contained in:
Alyssa Rosenzweig
2024-06-19 13:21:36 -04:00
committed by Marge Bot
parent 8270ece6c0
commit 97ebe52ee3
4 changed files with 18 additions and 186 deletions
@@ -93,76 +93,3 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_EndCommandBuffer(
return vk_command_buffer_end(&cmd_buffer->vk);
}
static void
lvp_free_CmdPushDescriptorSetWithTemplate2KHR(struct vk_cmd_queue *queue, struct vk_cmd_queue_entry *cmd)
{
struct lvp_device *device = cmd->driver_data;
LVP_FROM_HANDLE(lvp_descriptor_update_template, templ, cmd->u.push_descriptor_set_with_template2_khr.push_descriptor_set_with_template_info->descriptorUpdateTemplate);
lvp_descriptor_template_templ_unref(device, templ);
}
VKAPI_ATTR void VKAPI_CALL lvp_CmdPushDescriptorSetWithTemplate2KHR(
VkCommandBuffer commandBuffer,
const VkPushDescriptorSetWithTemplateInfoKHR* pPushDescriptorSetWithTemplateInfo)
{
LVP_FROM_HANDLE(lvp_cmd_buffer, cmd_buffer, commandBuffer);
LVP_FROM_HANDLE(lvp_descriptor_update_template, templ, pPushDescriptorSetWithTemplateInfo->descriptorUpdateTemplate);
size_t info_size = 0;
struct vk_cmd_queue_entry *cmd = vk_zalloc(cmd_buffer->vk.cmd_queue.alloc,
vk_cmd_queue_type_sizes[VK_CMD_PUSH_DESCRIPTOR_SET_WITH_TEMPLATE2_KHR], 8,
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (!cmd)
return;
cmd->type = VK_CMD_PUSH_DESCRIPTOR_SET_WITH_TEMPLATE2_KHR;
list_addtail(&cmd->cmd_link, &cmd_buffer->vk.cmd_queue.cmds);
cmd->driver_free_cb = lvp_free_CmdPushDescriptorSetWithTemplate2KHR;
cmd->driver_data = cmd_buffer->device;
lvp_descriptor_template_templ_ref(templ);
cmd->u.push_descriptor_set_with_template2_khr.push_descriptor_set_with_template_info = vk_zalloc(cmd_buffer->vk.cmd_queue.alloc, sizeof(VkPushDescriptorSetWithTemplateInfoKHR), 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
memcpy(cmd->u.push_descriptor_set_with_template2_khr.push_descriptor_set_with_template_info, pPushDescriptorSetWithTemplateInfo, sizeof(VkPushDescriptorSetWithTemplateInfoKHR));
for (unsigned i = 0; i < templ->entry_count; i++) {
VkDescriptorUpdateTemplateEntry *entry = &templ->entry[i];
switch (entry->descriptorType) {
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:
info_size += sizeof(VkDescriptorImageInfo) * entry->descriptorCount;
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
info_size += sizeof(VkBufferView) * entry->descriptorCount;
break;
case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
info_size += sizeof(VkAccelerationStructureKHR) * entry->descriptorCount;
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:
default:
info_size += sizeof(VkDescriptorBufferInfo) * entry->descriptorCount;
break;
}
}
cmd->u.push_descriptor_set_with_template2_khr.push_descriptor_set_with_template_info->pData = vk_zalloc(cmd_buffer->vk.cmd_queue.alloc, info_size, 8, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
uint64_t offset = 0;
for (unsigned i = 0; i < templ->entry_count; i++) {
VkDescriptorUpdateTemplateEntry *entry = &templ->entry[i];
unsigned size = lvp_descriptor_update_template_entry_size(entry->descriptorType);
for (unsigned i = 0; i < entry->descriptorCount; i++) {
memcpy((uint8_t*)cmd->u.push_descriptor_set_with_template2_khr.push_descriptor_set_with_template_info->pData + offset, (const uint8_t*)pPushDescriptorSetWithTemplateInfo->pData + entry->offset + i * entry->stride, size);
offset += size;
}
}
}
@@ -23,6 +23,7 @@
#include "lvp_private.h"
#include "vk_acceleration_structure.h"
#include "vk_descriptor_update_template.h"
#include "vk_descriptors.h"
#include "vk_util.h"
#include "util/u_math.h"
@@ -743,64 +744,6 @@ VKAPI_ATTR void VKAPI_CALL lvp_GetDescriptorSetLayoutSupport(VkDevice device,
pSupport->supported = true;
}
VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDescriptorUpdateTemplate(VkDevice _device,
const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate)
{
LVP_FROM_HANDLE(lvp_device, device, _device);
const uint32_t entry_count = pCreateInfo->descriptorUpdateEntryCount;
const size_t size = sizeof(struct lvp_descriptor_update_template) +
sizeof(VkDescriptorUpdateTemplateEntry) * entry_count;
struct lvp_descriptor_update_template *templ;
templ = vk_alloc(&device->vk.alloc, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!templ)
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
vk_object_base_init(&device->vk, &templ->base,
VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE);
templ->ref_cnt = 1;
templ->type = pCreateInfo->templateType;
templ->bind_point = pCreateInfo->pipelineBindPoint;
templ->set = pCreateInfo->set;
/* This parameter is ignored if templateType is not VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR */
if (pCreateInfo->templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR)
templ->pipeline_layout = lvp_pipeline_layout_from_handle(pCreateInfo->pipelineLayout);
else
templ->pipeline_layout = NULL;
templ->entry_count = entry_count;
VkDescriptorUpdateTemplateEntry *entries = (VkDescriptorUpdateTemplateEntry *)(templ + 1);
for (unsigned i = 0; i < entry_count; i++) {
entries[i] = pCreateInfo->pDescriptorUpdateEntries[i];
}
*pDescriptorUpdateTemplate = lvp_descriptor_update_template_to_handle(templ);
return VK_SUCCESS;
}
void
lvp_descriptor_template_destroy(struct lvp_device *device, struct lvp_descriptor_update_template *templ)
{
if (!templ)
return;
vk_object_base_finish(&templ->base);
vk_free(&device->vk.alloc, templ);
}
VKAPI_ATTR void VKAPI_CALL lvp_DestroyDescriptorUpdateTemplate(VkDevice _device,
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
const VkAllocationCallbacks *pAllocator)
{
LVP_FROM_HANDLE(lvp_device, device, _device);
LVP_FROM_HANDLE(lvp_descriptor_update_template, templ, descriptorUpdateTemplate);
lvp_descriptor_template_templ_unref(device, templ);
}
uint32_t
lvp_descriptor_update_template_entry_size(VkDescriptorType type)
{
@@ -828,37 +771,34 @@ lvp_descriptor_update_template_entry_size(VkDescriptorType type)
void
lvp_descriptor_set_update_with_template(VkDevice _device, VkDescriptorSet descriptorSet,
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
const void *pData, bool push)
const void *pData)
{
LVP_FROM_HANDLE(lvp_device, device, _device);
LVP_FROM_HANDLE(lvp_descriptor_set, set, descriptorSet);
LVP_FROM_HANDLE(lvp_descriptor_update_template, templ, descriptorUpdateTemplate);
LVP_FROM_HANDLE(vk_descriptor_update_template, templ, descriptorUpdateTemplate);
uint32_t i, j;
const uint8_t *pSrc = pData;
for (i = 0; i < templ->entry_count; ++i) {
VkDescriptorUpdateTemplateEntry *entry = &templ->entry[i];
struct vk_descriptor_template_entry *entry = &templ->entries[i];
if (!push)
pSrc = ((const uint8_t *) pData) + entry->offset;
const uint8_t *pSrc = ((const uint8_t *) pData) + entry->offset;
const struct lvp_descriptor_set_binding_layout *bind_layout =
&set->layout->binding[entry->dstBinding];
&set->layout->binding[entry->binding];
if (entry->descriptorType == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK) {
memcpy((uint8_t *)set->map + bind_layout->uniform_block_offset + entry->dstArrayElement, pSrc, entry->descriptorCount);
if (entry->type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK) {
memcpy((uint8_t *)set->map + bind_layout->uniform_block_offset + entry->array_element, pSrc, entry->array_count);
continue;
}
struct lp_descriptor *desc = set->map;
desc += bind_layout->descriptor_index;
for (j = 0; j < entry->descriptorCount; ++j) {
unsigned idx = j + entry->dstArrayElement;
for (j = 0; j < entry->array_count; ++j) {
unsigned idx = j + entry->array_element;
idx *= bind_layout->stride;
switch (entry->descriptorType) {
switch (entry->type) {
case VK_DESCRIPTOR_TYPE_SAMPLER: {
VkDescriptorImageInfo *info = (VkDescriptorImageInfo *)pSrc;
LVP_FROM_HANDLE(lvp_sampler, sampler, info->sampler);
@@ -1010,10 +950,7 @@ lvp_descriptor_set_update_with_template(VkDevice _device, VkDescriptorSet descri
break;
}
if (push)
pSrc += lvp_descriptor_update_template_entry_size(entry->descriptorType);
else
pSrc += entry->stride;
pSrc += entry->stride;
}
}
}
@@ -1023,7 +960,7 @@ lvp_UpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorS
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
const void *pData)
{
lvp_descriptor_set_update_with_template(device, descriptorSet, descriptorUpdateTemplate, pData, false);
lvp_descriptor_set_update_with_template(device, descriptorSet, descriptorUpdateTemplate, pData);
}
VKAPI_ATTR void VKAPI_CALL lvp_GetDescriptorSetLayoutSizeEXT(
+4 -2
View File
@@ -48,6 +48,7 @@
#include "vk_blend.h"
#include "vk_cmd_enqueue_entrypoints.h"
#include "vk_descriptor_update_template.h"
#include "vk_util.h"
#define VK_PROTOTYPES
@@ -3313,7 +3314,7 @@ static void handle_push_descriptor_set_with_template(struct vk_cmd_queue_entry *
struct rendering_state *state)
{
VkPushDescriptorSetWithTemplateInfoKHR *pds = cmd->u.push_descriptor_set_with_template2_khr.push_descriptor_set_with_template_info;
LVP_FROM_HANDLE(lvp_descriptor_update_template, templ, pds->descriptorUpdateTemplate);
LVP_FROM_HANDLE(vk_descriptor_update_template, templ, pds->descriptorUpdateTemplate);
LVP_FROM_HANDLE(lvp_pipeline_layout, layout, pds->layout);
struct lvp_descriptor_set_layout *set_layout = (struct lvp_descriptor_set_layout *)layout->vk.set_layouts[pds->set];
@@ -3328,7 +3329,7 @@ static void handle_push_descriptor_set_with_template(struct vk_cmd_queue_entry *
VkDescriptorSet set_handle = lvp_descriptor_set_to_handle(set);
lvp_descriptor_set_update_with_template(lvp_device_to_handle(state->device), set_handle,
pds->descriptorUpdateTemplate, pds->pData, true);
pds->descriptorUpdateTemplate, pds->pData);
VkBindDescriptorSetsInfoKHR bind_cmd = {
.stageFlags = vk_shader_stages_from_bind_point(templ->bind_point),
@@ -4740,6 +4741,7 @@ void lvp_add_enqueue_cmd_entrypoints(struct vk_device_dispatch_table *disp)
ENQUEUE_CMD(CmdWriteTimestamp2)
ENQUEUE_CMD(CmdPushConstants2KHR)
ENQUEUE_CMD(CmdPushDescriptorSet2KHR)
ENQUEUE_CMD(CmdPushDescriptorSetWithTemplate2KHR)
ENQUEUE_CMD(CmdBindDescriptorBuffersEXT)
ENQUEUE_CMD(CmdSetDescriptorBufferOffsets2EXT)
ENQUEUE_CMD(CmdBindDescriptorBufferEmbeddedSamplers2EXT)
+1 -35
View File
@@ -376,40 +376,8 @@ struct lvp_descriptor_pool {
struct list_head sets;
};
struct lvp_descriptor_update_template {
struct vk_object_base base;
unsigned ref_cnt;
uint32_t entry_count;
uint32_t set;
VkDescriptorUpdateTemplateType type;
VkPipelineBindPoint bind_point;
struct lvp_pipeline_layout *pipeline_layout;
VkDescriptorUpdateTemplateEntry entry[0];
};
uint32_t lvp_descriptor_update_template_entry_size(VkDescriptorType type);
static inline void
lvp_descriptor_template_templ_ref(struct lvp_descriptor_update_template *templ)
{
assert(templ && templ->ref_cnt >= 1);
p_atomic_inc(&templ->ref_cnt);
}
void
lvp_descriptor_template_destroy(struct lvp_device *device, struct lvp_descriptor_update_template *templ);
static inline void
lvp_descriptor_template_templ_unref(struct lvp_device *device,
struct lvp_descriptor_update_template *templ)
{
if (!templ)
return;
assert(templ->ref_cnt >= 1);
if (p_atomic_dec_zero(&templ->ref_cnt))
lvp_descriptor_template_destroy(device, templ);
}
VkResult
lvp_descriptor_set_create(struct lvp_device *device,
struct lvp_descriptor_set_layout *layout,
@@ -422,7 +390,7 @@ lvp_descriptor_set_destroy(struct lvp_device *device,
void
lvp_descriptor_set_update_with_template(VkDevice _device, VkDescriptorSet descriptorSet,
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
const void *pData, bool push);
const void *pData);
struct lvp_pipeline_layout {
struct vk_pipeline_layout vk;
@@ -697,8 +665,6 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(lvp_descriptor_set, base, VkDescriptorSet,
VK_OBJECT_TYPE_DESCRIPTOR_SET)
VK_DEFINE_NONDISP_HANDLE_CASTS(lvp_descriptor_set_layout, vk.base, VkDescriptorSetLayout,
VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
VK_DEFINE_NONDISP_HANDLE_CASTS(lvp_descriptor_update_template, base, VkDescriptorUpdateTemplate,
VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE)
VK_DEFINE_NONDISP_HANDLE_CASTS(lvp_device_memory, base, VkDeviceMemory,
VK_OBJECT_TYPE_DEVICE_MEMORY)
VK_DEFINE_NONDISP_HANDLE_CASTS(lvp_event, base, VkEvent, VK_OBJECT_TYPE_EVENT)