From b9e1ca16f84016f1d40efa9bfee89db48a7702b4 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Fri, 15 Dec 2017 13:47:53 -0800 Subject: [PATCH] anv/cmd_buffer: Add a helper for binding descriptor sets MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This lets us unify some code between push descriptors and regular descriptors. It doesn't do much for us yet but it will. Tested-by: Józef Kucia Reviewed-by: Topi Pohjolainen Cc: "18.0" --- src/intel/vulkan/anv_cmd_buffer.c | 70 ++++++++++++++++++------------- 1 file changed, 42 insertions(+), 28 deletions(-) diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index e5366fd95c0..636f5150f22 100644 --- a/src/intel/vulkan/anv_cmd_buffer.c +++ b/src/intel/vulkan/anv_cmd_buffer.c @@ -493,6 +493,40 @@ void anv_CmdSetStencilReference( cmd_buffer->state.dirty |= ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE; } +static void +anv_cmd_buffer_bind_descriptor_set(struct anv_cmd_buffer *cmd_buffer, + struct anv_pipeline_layout *layout, + uint32_t set_index, + struct anv_descriptor_set *set, + uint32_t *dynamic_offset_count, + const uint32_t **dynamic_offsets) +{ + struct anv_descriptor_set_layout *set_layout = + layout->set[set_index].layout; + + cmd_buffer->state.descriptors[set_index] = set; + + if (dynamic_offsets) { + if (set_layout->dynamic_offset_count > 0) { + uint32_t dynamic_offset_start = + layout->set[set_index].dynamic_offset_start; + + /* Assert that everything is in range */ + assert(set_layout->dynamic_offset_count <= *dynamic_offset_count); + assert(dynamic_offset_start + set_layout->dynamic_offset_count <= + ARRAY_SIZE(cmd_buffer->state.dynamic_offsets)); + + typed_memcpy(&cmd_buffer->state.dynamic_offsets[dynamic_offset_start], + *dynamic_offsets, set_layout->dynamic_offset_count); + + *dynamic_offsets += set_layout->dynamic_offset_count; + *dynamic_offset_count -= set_layout->dynamic_offset_count; + } + } + + cmd_buffer->state.descriptors_dirty |= set_layout->shader_stages; +} + void anv_CmdBindDescriptorSets( VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint, @@ -505,35 +539,15 @@ void anv_CmdBindDescriptorSets( { ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, commandBuffer); ANV_FROM_HANDLE(anv_pipeline_layout, layout, _layout); - struct anv_descriptor_set_layout *set_layout; assert(firstSet + descriptorSetCount < MAX_SETS); - uint32_t dynamic_slot = 0; for (uint32_t i = 0; i < descriptorSetCount; i++) { ANV_FROM_HANDLE(anv_descriptor_set, set, pDescriptorSets[i]); - set_layout = layout->set[firstSet + i].layout; - - cmd_buffer->state.descriptors[firstSet + i] = set; - - if (set_layout->dynamic_offset_count > 0) { - uint32_t dynamic_offset_start = - layout->set[firstSet + i].dynamic_offset_start; - - /* Assert that everything is in range */ - assert(dynamic_offset_start + set_layout->dynamic_offset_count <= - ARRAY_SIZE(cmd_buffer->state.dynamic_offsets)); - assert(dynamic_slot + set_layout->dynamic_offset_count <= - dynamicOffsetCount); - - typed_memcpy(&cmd_buffer->state.dynamic_offsets[dynamic_offset_start], - &pDynamicOffsets[dynamic_slot], - set_layout->dynamic_offset_count); - - dynamic_slot += set_layout->dynamic_offset_count; - } - - cmd_buffer->state.descriptors_dirty |= set_layout->shader_stages; + anv_cmd_buffer_bind_descriptor_set(cmd_buffer, layout, + firstSet + i, set, + &dynamicOffsetCount, + &pDynamicOffsets); } } @@ -944,8 +958,8 @@ void anv_CmdPushDescriptorSetKHR( } } - cmd_buffer->state.descriptors[_set] = set; - cmd_buffer->state.descriptors_dirty |= set_layout->shader_stages; + anv_cmd_buffer_bind_descriptor_set(cmd_buffer, layout, _set, + set, NULL, NULL); } void anv_CmdPushDescriptorSetWithTemplateKHR( @@ -983,6 +997,6 @@ void anv_CmdPushDescriptorSetWithTemplateKHR( template, pData); - cmd_buffer->state.descriptors[_set] = set; - cmd_buffer->state.descriptors_dirty |= set_layout->shader_stages; + anv_cmd_buffer_bind_descriptor_set(cmd_buffer, layout, _set, + set, NULL, NULL); } -- 2.30.2