radv: move descriptor sets out of cmd_state.
authorDave Airlie <airlied@redhat.com>
Sun, 5 Nov 2017 23:37:47 +0000 (23:37 +0000)
committerDave Airlie <airlied@redhat.com>
Mon, 6 Nov 2017 01:11:03 +0000 (01:11 +0000)
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 <bas@basnieuwenhuizen.nl>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_cmd_buffer.c
src/amd/vulkan/radv_meta.c
src/amd/vulkan/radv_private.h

index 8d1f5fe48e385221a04e9e74bcd086d8089f7956..6f5d4441ef6b151ca61b38e82a804f8bd05f1b12 100644 (file)
@@ -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(
index 80c5eb28cbe6cff6a36a66f0b7296d2120b9ae0f..2bfaeb33930d38e4d32c68dc5ce9faeea9a4342c 100644 (file)
@@ -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) {
index 8fb3496271362f871804872c1712d51fef783bce..cfbdfeb99093c2e9655773bd58b7d8dd6b1a9d1a 100644 (file)
@@ -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;