From a876e0b1923fb39251d1b337dfd4481e541d530f Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Sun, 14 Jul 2024 19:07:16 +0200 Subject: [PATCH] vkd3d: Allocate temporary arrays on the stack in d3d12_command_list_update_push_descriptors(). --- libs/vkd3d/command.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/libs/vkd3d/command.c b/libs/vkd3d/command.c index 183f8e0c..a484da94 100644 --- a/libs/vkd3d/command.c +++ b/libs/vkd3d/command.c @@ -2977,30 +2977,20 @@ static void d3d12_command_list_update_push_descriptors(struct d3d12_command_list enum vkd3d_pipeline_bind_point bind_point) { struct vkd3d_pipeline_bindings *bindings = &list->pipeline_bindings[bind_point]; + VkWriteDescriptorSet descriptor_writes[ARRAY_SIZE(bindings->push_descriptors)] = {0}; + VkDescriptorBufferInfo buffer_infos[ARRAY_SIZE(bindings->push_descriptors)] = {0}; const struct d3d12_root_signature *root_signature = bindings->root_signature; - VkWriteDescriptorSet *descriptor_writes = NULL, *current_descriptor_write; const struct vkd3d_vk_device_procs *vk_procs = &list->device->vk_procs; - VkDescriptorBufferInfo *buffer_infos = NULL, *current_buffer_info; const struct d3d12_root_parameter *root_parameter; struct vkd3d_push_descriptor *push_descriptor; struct d3d12_device *device = list->device; VkDescriptorBufferInfo *vk_buffer_info; - unsigned int i, descriptor_count; + unsigned int i, descriptor_count = 0; VkBufferView *vk_buffer_view; if (!bindings->push_descriptor_dirty_mask) return; - descriptor_count = vkd3d_popcount(bindings->push_descriptor_dirty_mask); - - if (!(descriptor_writes = vkd3d_calloc(descriptor_count, sizeof(*descriptor_writes)))) - return; - if (!(buffer_infos = vkd3d_calloc(descriptor_count, sizeof(*buffer_infos)))) - goto done; - - descriptor_count = 0; - current_buffer_info = buffer_infos; - current_descriptor_write = descriptor_writes; for (i = 0; i < ARRAY_SIZE(bindings->push_descriptors); ++i) { if (!(bindings->push_descriptor_dirty_mask & (1u << i))) @@ -3012,7 +3002,7 @@ static void d3d12_command_list_update_push_descriptors(struct d3d12_command_list if (root_parameter->parameter_type == D3D12_ROOT_PARAMETER_TYPE_CBV) { vk_buffer_view = NULL; - vk_buffer_info = current_buffer_info; + vk_buffer_info = &buffer_infos[descriptor_count]; vk_buffer_info->buffer = push_descriptor->u.cbv.vk_buffer; vk_buffer_info->offset = push_descriptor->u.cbv.offset; vk_buffer_info->range = VK_WHOLE_SIZE; @@ -3023,21 +3013,15 @@ static void d3d12_command_list_update_push_descriptors(struct d3d12_command_list vk_buffer_info = NULL; } - if (!vk_write_descriptor_set_from_root_descriptor(current_descriptor_write, + if (!vk_write_descriptor_set_from_root_descriptor(&descriptor_writes[descriptor_count], root_parameter, bindings->descriptor_sets[0], vk_buffer_view, vk_buffer_info)) continue; ++descriptor_count; - ++current_descriptor_write; - ++current_buffer_info; } VK_CALL(vkUpdateDescriptorSets(device->vk_device, descriptor_count, descriptor_writes, 0, NULL)); bindings->push_descriptor_dirty_mask = 0; - -done: - vkd3d_free(descriptor_writes); - vkd3d_free(buffer_infos); } static void d3d12_command_list_update_uav_counter_descriptors(struct d3d12_command_list *list,