vkd3d: Allocate temporary arrays on the stack in d3d12_command_list_update_push_descriptors().

This commit is contained in:
Giovanni Mascellani 2024-07-14 19:07:16 +02:00 committed by Henri Verbeet
parent ae0faf4500
commit a876e0b192
Notes: Henri Verbeet 2024-07-17 15:59:55 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/945

View File

@ -2977,30 +2977,20 @@ static void d3d12_command_list_update_push_descriptors(struct d3d12_command_list
enum vkd3d_pipeline_bind_point bind_point) enum vkd3d_pipeline_bind_point bind_point)
{ {
struct vkd3d_pipeline_bindings *bindings = &list->pipeline_bindings[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; 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; 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; const struct d3d12_root_parameter *root_parameter;
struct vkd3d_push_descriptor *push_descriptor; struct vkd3d_push_descriptor *push_descriptor;
struct d3d12_device *device = list->device; struct d3d12_device *device = list->device;
VkDescriptorBufferInfo *vk_buffer_info; VkDescriptorBufferInfo *vk_buffer_info;
unsigned int i, descriptor_count; unsigned int i, descriptor_count = 0;
VkBufferView *vk_buffer_view; VkBufferView *vk_buffer_view;
if (!bindings->push_descriptor_dirty_mask) if (!bindings->push_descriptor_dirty_mask)
return; 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) for (i = 0; i < ARRAY_SIZE(bindings->push_descriptors); ++i)
{ {
if (!(bindings->push_descriptor_dirty_mask & (1u << 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) if (root_parameter->parameter_type == D3D12_ROOT_PARAMETER_TYPE_CBV)
{ {
vk_buffer_view = NULL; 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->buffer = push_descriptor->u.cbv.vk_buffer;
vk_buffer_info->offset = push_descriptor->u.cbv.offset; vk_buffer_info->offset = push_descriptor->u.cbv.offset;
vk_buffer_info->range = VK_WHOLE_SIZE; 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; 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)) root_parameter, bindings->descriptor_sets[0], vk_buffer_view, vk_buffer_info))
continue; continue;
++descriptor_count; ++descriptor_count;
++current_descriptor_write;
++current_buffer_info;
} }
VK_CALL(vkUpdateDescriptorSets(device->vk_device, descriptor_count, descriptor_writes, 0, NULL)); VK_CALL(vkUpdateDescriptorSets(device->vk_device, descriptor_count, descriptor_writes, 0, NULL));
bindings->push_descriptor_dirty_mask = 0; 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, static void d3d12_command_list_update_uav_counter_descriptors(struct d3d12_command_list *list,