From 60a9705e0040a0962b82ec5363c14503d8a96d42 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sun, 5 Nov 2017 23:37:47 +0000 Subject: [PATCH] radv: move descriptor sets out of cmd_state. Instead of storing all the pointers and zeroing them all out, just store a valid bitmask in the state. This also moves the CmdBindPipeline path down the cpu usage path for the multithreading demo as it no longer has to traverse MAX_SETS to find the active descriptor sets. Reviewed-by: Bas Nieuwenhuizen Signed-off-by: Dave Airlie --- src/amd/vulkan/radv_cmd_buffer.c | 29 ++++++++++++++--------------- src/amd/vulkan/radv_meta.c | 5 ++++- src/amd/vulkan/radv_private.h | 3 ++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/amd/vulkan/radv_cmd_buffer.c b/src/amd/vulkan/radv_cmd_buffer.c index 8d1f5fe48e3..6f5d4441ef6 100644 --- a/src/amd/vulkan/radv_cmd_buffer.c +++ b/src/amd/vulkan/radv_cmd_buffer.c @@ -480,8 +480,13 @@ void radv_set_descriptor_set(struct radv_cmd_buffer *cmd_buffer, struct radv_descriptor_set *set, unsigned idx) { - cmd_buffer->state.descriptors[idx] = set; + cmd_buffer->descriptors[idx] = set; + if (set) + cmd_buffer->state.valid_descriptors |= (1u << idx); + else + cmd_buffer->state.valid_descriptors &= ~(1u << idx); cmd_buffer->state.descriptors_dirty |= (1u << idx); + } static void @@ -491,17 +496,14 @@ radv_save_descriptors(struct radv_cmd_buffer *cmd_buffer) struct radeon_winsys_cs *cs = cmd_buffer->cs; uint32_t data[MAX_SETS * 2] = {}; uint64_t va; - + unsigned i; va = radv_buffer_get_va(device->trace_bo) + 24; MAYBE_UNUSED unsigned cdw_max = radeon_check_space(device->ws, cmd_buffer->cs, 4 + MAX_SETS * 2); - for (int i = 0; i < MAX_SETS; i++) { - struct radv_descriptor_set *set = cmd_buffer->state.descriptors[i]; - if (!set) - continue; - + for_each_bit(i, cmd_buffer->state.valid_descriptors) { + struct radv_descriptor_set *set = cmd_buffer->descriptors[i]; data[i * 2] = (uintptr_t)set; data[i * 2 + 1] = (uintptr_t)set >> 32; } @@ -1660,8 +1662,8 @@ radv_flush_indirect_descriptor_sets(struct radv_cmd_buffer *cmd_buffer) for (unsigned i = 0; i < MAX_SETS; i++) { uint32_t *uptr = ((uint32_t *)ptr) + i * 2; uint64_t set_va = 0; - struct radv_descriptor_set *set = cmd_buffer->state.descriptors[i]; - if (set) + struct radv_descriptor_set *set = cmd_buffer->descriptors[i]; + if (cmd_buffer->state.valid_descriptors & (1u << i)) set_va = set->va; uptr[0] = set_va & 0xffffffff; uptr[1] = set_va >> 32; @@ -1719,8 +1721,8 @@ radv_flush_descriptors(struct radv_cmd_buffer *cmd_buffer, MAX_SETS * MESA_SHADER_STAGES * 4); for_each_bit(i, cmd_buffer->state.descriptors_dirty) { - struct radv_descriptor_set *set = cmd_buffer->state.descriptors[i]; - if (!set) + struct radv_descriptor_set *set = cmd_buffer->descriptors[i]; + if (!(cmd_buffer->state.valid_descriptors & (1u << i))) continue; radv_emit_descriptor_set_userdata(cmd_buffer, stages, set, i); @@ -2571,10 +2573,7 @@ radv_emit_compute_pipeline(struct radv_cmd_buffer *cmd_buffer) static void radv_mark_descriptor_sets_dirty(struct radv_cmd_buffer *cmd_buffer) { - for (unsigned i = 0; i < MAX_SETS; i++) { - if (cmd_buffer->state.descriptors[i]) - cmd_buffer->state.descriptors_dirty |= (1u << i); - } + cmd_buffer->state.descriptors_dirty |= cmd_buffer->state.valid_descriptors; } void radv_CmdBindPipeline( diff --git a/src/amd/vulkan/radv_meta.c b/src/amd/vulkan/radv_meta.c index 80c5eb28cbe..2bfaeb33930 100644 --- a/src/amd/vulkan/radv_meta.c +++ b/src/amd/vulkan/radv_meta.c @@ -73,7 +73,10 @@ radv_meta_save(struct radv_meta_saved_state *state, } if (state->flags & RADV_META_SAVE_DESCRIPTORS) { - state->old_descriptor_set0 = cmd_buffer->state.descriptors[0]; + if (cmd_buffer->state.valid_descriptors & (1 << 0)) + state->old_descriptor_set0 = cmd_buffer->descriptors[0]; + else + state->old_descriptor_set0 = NULL; } if (state->flags & RADV_META_SAVE_CONSTANTS) { diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 8fb34962713..cfbdfeb9909 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -822,7 +822,6 @@ struct radv_cmd_state { struct radv_render_pass * pass; const struct radv_subpass * subpass; struct radv_dynamic_state dynamic; - struct radv_descriptor_set * descriptors[MAX_SETS]; struct radv_attachment_state * attachments; VkRect2D render_area; @@ -839,6 +838,7 @@ struct radv_cmd_state { unsigned active_occlusion_queries; float offset_scale; uint32_t descriptors_dirty; + uint32_t valid_descriptors; uint32_t trace_id; uint32_t last_ia_multi_vgt_param; }; @@ -878,6 +878,7 @@ struct radv_cmd_buffer { VkShaderStageFlags push_constant_stages; struct radv_push_descriptor_set push_descriptors; struct radv_descriptor_set meta_push_descriptors; + struct radv_descriptor_set *descriptors[MAX_SETS]; struct radv_cmd_buffer_upload upload; -- 2.30.2