venus: use STACK_ARRAY to simplify descriptor set update and push
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28563>
This commit is contained in:
@@ -2201,26 +2201,23 @@ vn_CmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
|
|||||||
uint32_t descriptorWriteCount,
|
uint32_t descriptorWriteCount,
|
||||||
const VkWriteDescriptorSet *pDescriptorWrites)
|
const VkWriteDescriptorSet *pDescriptorWrites)
|
||||||
{
|
{
|
||||||
struct vn_command_buffer *cmd =
|
|
||||||
vn_command_buffer_from_handle(commandBuffer);
|
|
||||||
|
|
||||||
const uint32_t img_info_count = vn_descriptor_set_count_write_images(
|
const uint32_t img_info_count = vn_descriptor_set_count_write_images(
|
||||||
descriptorWriteCount, pDescriptorWrites);
|
descriptorWriteCount, pDescriptorWrites);
|
||||||
struct vn_update_descriptor_sets *update = vn_update_descriptor_sets_alloc(
|
|
||||||
descriptorWriteCount, img_info_count, 0, 0, 0, &cmd->pool->allocator,
|
|
||||||
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
|
|
||||||
if (!update) {
|
|
||||||
cmd->state = VN_COMMAND_BUFFER_STATE_INVALID;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
vn_update_descriptor_sets_parse_writes(update, descriptorWriteCount,
|
STACK_ARRAY(VkWriteDescriptorSet, writes, descriptorWriteCount);
|
||||||
pDescriptorWrites, layout);
|
STACK_ARRAY(VkDescriptorImageInfo, img_infos, img_info_count);
|
||||||
|
struct vn_descriptor_set_writes local = {
|
||||||
|
.writes = writes,
|
||||||
|
.img_infos = img_infos,
|
||||||
|
};
|
||||||
|
pDescriptorWrites = vn_descriptor_set_get_writes(
|
||||||
|
descriptorWriteCount, pDescriptorWrites, layout, &local);
|
||||||
|
|
||||||
VN_CMD_ENQUEUE(vkCmdPushDescriptorSetKHR, commandBuffer, pipelineBindPoint,
|
VN_CMD_ENQUEUE(vkCmdPushDescriptorSetKHR, commandBuffer, pipelineBindPoint,
|
||||||
layout, set, update->write_count, update->writes);
|
layout, set, descriptorWriteCount, pDescriptorWrites);
|
||||||
|
|
||||||
vk_free(&cmd->pool->allocator, update);
|
STACK_ARRAY_FINISH(writes);
|
||||||
|
STACK_ARRAY_FINISH(img_infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -727,7 +727,7 @@ vn_FreeDescriptorSets(VkDevice device,
|
|||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vn_update_descriptor_sets *
|
static struct vn_update_descriptor_sets *
|
||||||
vn_update_descriptor_sets_alloc(uint32_t write_count,
|
vn_update_descriptor_sets_alloc(uint32_t write_count,
|
||||||
uint32_t image_count,
|
uint32_t image_count,
|
||||||
uint32_t buffer_count,
|
uint32_t buffer_count,
|
||||||
@@ -786,19 +786,18 @@ vn_descriptor_set_count_write_images(uint32_t write_count,
|
|||||||
return img_info_count;
|
return img_info_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
const VkWriteDescriptorSet *
|
||||||
vn_update_descriptor_sets_parse_writes(
|
vn_descriptor_set_get_writes(uint32_t write_count,
|
||||||
struct vn_update_descriptor_sets *update,
|
const VkWriteDescriptorSet *writes,
|
||||||
uint32_t write_count,
|
VkPipelineLayout pipeline_layout_handle,
|
||||||
const VkWriteDescriptorSet *writes,
|
struct vn_descriptor_set_writes *local)
|
||||||
VkPipelineLayout pipeline_layout_handle)
|
|
||||||
{
|
{
|
||||||
const struct vn_pipeline_layout *pipeline_layout =
|
const struct vn_pipeline_layout *pipeline_layout =
|
||||||
vn_pipeline_layout_from_handle(pipeline_layout_handle);
|
vn_pipeline_layout_from_handle(pipeline_layout_handle);
|
||||||
|
|
||||||
typed_memcpy(update->writes, writes, write_count);
|
typed_memcpy(local->writes, writes, write_count);
|
||||||
|
|
||||||
uint32_t img_count = 0;
|
uint32_t img_info_count = 0;
|
||||||
for (uint32_t i = 0; i < write_count; i++) {
|
for (uint32_t i = 0; i < write_count; i++) {
|
||||||
const struct vn_descriptor_set_layout *set_layout =
|
const struct vn_descriptor_set_layout *set_layout =
|
||||||
pipeline_layout
|
pipeline_layout
|
||||||
@@ -806,8 +805,8 @@ vn_update_descriptor_sets_parse_writes(
|
|||||||
: vn_descriptor_set_from_handle(writes[i].dstSet)->layout;
|
: vn_descriptor_set_from_handle(writes[i].dstSet)->layout;
|
||||||
const struct vn_descriptor_set_layout_binding *binding =
|
const struct vn_descriptor_set_layout_binding *binding =
|
||||||
&set_layout->bindings[writes[i].dstBinding];
|
&set_layout->bindings[writes[i].dstBinding];
|
||||||
VkWriteDescriptorSet *write = &update->writes[i];
|
VkWriteDescriptorSet *write = &local->writes[i];
|
||||||
VkDescriptorImageInfo *imgs = &update->images[img_count];
|
VkDescriptorImageInfo *img_infos = &local->img_infos[img_info_count];
|
||||||
|
|
||||||
switch (write->descriptorType) {
|
switch (write->descriptorType) {
|
||||||
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
||||||
@@ -815,29 +814,29 @@ vn_update_descriptor_sets_parse_writes(
|
|||||||
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
||||||
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
||||||
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
||||||
typed_memcpy(imgs, write->pImageInfo, write->descriptorCount);
|
typed_memcpy(img_infos, write->pImageInfo, write->descriptorCount);
|
||||||
img_count += write->descriptorCount;
|
img_info_count += write->descriptorCount;
|
||||||
|
|
||||||
for (uint32_t j = 0; j < write->descriptorCount; j++) {
|
for (uint32_t j = 0; j < write->descriptorCount; j++) {
|
||||||
switch (write->descriptorType) {
|
switch (write->descriptorType) {
|
||||||
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
case VK_DESCRIPTOR_TYPE_SAMPLER:
|
||||||
imgs[j].imageView = VK_NULL_HANDLE;
|
img_infos[j].imageView = VK_NULL_HANDLE;
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
||||||
if (binding->has_immutable_samplers)
|
if (binding->has_immutable_samplers)
|
||||||
imgs[j].sampler = VK_NULL_HANDLE;
|
img_infos[j].sampler = VK_NULL_HANDLE;
|
||||||
break;
|
break;
|
||||||
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
||||||
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
||||||
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
||||||
imgs[j].sampler = VK_NULL_HANDLE;
|
img_infos[j].sampler = VK_NULL_HANDLE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
write->pImageInfo = imgs;
|
write->pImageInfo = img_infos;
|
||||||
write->pBufferInfo = NULL;
|
write->pBufferInfo = NULL;
|
||||||
write->pTexelBufferView = NULL;
|
write->pTexelBufferView = NULL;
|
||||||
break;
|
break;
|
||||||
@@ -862,6 +861,7 @@ vn_update_descriptor_sets_parse_writes(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return local->writes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -872,24 +872,24 @@ vn_UpdateDescriptorSets(VkDevice device,
|
|||||||
const VkCopyDescriptorSet *pDescriptorCopies)
|
const VkCopyDescriptorSet *pDescriptorCopies)
|
||||||
{
|
{
|
||||||
struct vn_device *dev = vn_device_from_handle(device);
|
struct vn_device *dev = vn_device_from_handle(device);
|
||||||
const VkAllocationCallbacks *alloc = &dev->base.base.alloc;
|
|
||||||
|
|
||||||
const uint32_t img_info_count = vn_descriptor_set_count_write_images(
|
const uint32_t img_info_count = vn_descriptor_set_count_write_images(
|
||||||
descriptorWriteCount, pDescriptorWrites);
|
descriptorWriteCount, pDescriptorWrites);
|
||||||
struct vn_update_descriptor_sets *update = vn_update_descriptor_sets_alloc(
|
|
||||||
descriptorWriteCount, img_info_count, 0, 0, 0, alloc,
|
|
||||||
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
|
|
||||||
if (!update)
|
|
||||||
return;
|
|
||||||
|
|
||||||
vn_update_descriptor_sets_parse_writes(update, descriptorWriteCount,
|
STACK_ARRAY(VkWriteDescriptorSet, writes, descriptorWriteCount);
|
||||||
pDescriptorWrites, VK_NULL_HANDLE);
|
STACK_ARRAY(VkDescriptorImageInfo, img_infos, img_info_count);
|
||||||
|
struct vn_descriptor_set_writes local = {
|
||||||
|
.writes = writes,
|
||||||
|
.img_infos = img_infos,
|
||||||
|
};
|
||||||
|
pDescriptorWrites = vn_descriptor_set_get_writes(
|
||||||
|
descriptorWriteCount, pDescriptorWrites, VK_NULL_HANDLE, &local);
|
||||||
|
|
||||||
vn_async_vkUpdateDescriptorSets(dev->primary_ring, device,
|
vn_async_vkUpdateDescriptorSets(dev->primary_ring, device,
|
||||||
update->write_count, update->writes,
|
descriptorWriteCount, pDescriptorWrites,
|
||||||
descriptorCopyCount, pDescriptorCopies);
|
descriptorCopyCount, pDescriptorCopies);
|
||||||
|
|
||||||
vk_free(alloc, update);
|
STACK_ARRAY_FINISH(writes);
|
||||||
|
STACK_ARRAY_FINISH(img_infos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* descriptor update template commands */
|
/* descriptor update template commands */
|
||||||
|
@@ -130,25 +130,20 @@ VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_update_template,
|
|||||||
VkDescriptorUpdateTemplate,
|
VkDescriptorUpdateTemplate,
|
||||||
VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE)
|
VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE)
|
||||||
|
|
||||||
|
struct vn_descriptor_set_writes {
|
||||||
|
VkWriteDescriptorSet *writes;
|
||||||
|
VkDescriptorImageInfo *img_infos;
|
||||||
|
};
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
vn_descriptor_set_count_write_images(uint32_t write_count,
|
vn_descriptor_set_count_write_images(uint32_t write_count,
|
||||||
const VkWriteDescriptorSet *writes);
|
const VkWriteDescriptorSet *writes);
|
||||||
|
|
||||||
void
|
const VkWriteDescriptorSet *
|
||||||
vn_update_descriptor_sets_parse_writes(
|
vn_descriptor_set_get_writes(uint32_t write_count,
|
||||||
struct vn_update_descriptor_sets *update,
|
const VkWriteDescriptorSet *writes,
|
||||||
uint32_t write_count,
|
VkPipelineLayout pipeline_layout_handle,
|
||||||
const VkWriteDescriptorSet *writes,
|
struct vn_descriptor_set_writes *local);
|
||||||
VkPipelineLayout pipeline_layout_handle);
|
|
||||||
|
|
||||||
struct vn_update_descriptor_sets *
|
|
||||||
vn_update_descriptor_sets_alloc(uint32_t write_count,
|
|
||||||
uint32_t image_count,
|
|
||||||
uint32_t buffer_count,
|
|
||||||
uint32_t view_count,
|
|
||||||
uint32_t iub_count,
|
|
||||||
const VkAllocationCallbacks *alloc,
|
|
||||||
VkSystemAllocationScope scope);
|
|
||||||
|
|
||||||
struct vn_update_descriptor_sets *
|
struct vn_update_descriptor_sets *
|
||||||
vn_update_descriptor_set_with_template_locked(
|
vn_update_descriptor_set_with_template_locked(
|
||||||
|
Reference in New Issue
Block a user