• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google LLC
3  * SPDX-License-Identifier: MIT
4  *
5  * based in part on anv and radv which are:
6  * Copyright © 2015 Intel Corporation
7  * Copyright © 2016 Red Hat.
8  * Copyright © 2016 Bas Nieuwenhuizen
9  */
10 
11 #ifndef VN_COMMAND_BUFFER_H
12 #define VN_COMMAND_BUFFER_H
13 
14 #include "vn_common.h"
15 
16 #include "vn_cs.h"
17 #include "vn_feedback.h"
18 
19 struct vn_command_pool {
20    struct vn_object_base base;
21 
22    VkAllocationCallbacks allocator;
23    struct vn_device *device;
24    uint32_t queue_family_index;
25 
26    struct list_head command_buffers;
27 
28    /* This list of free query batches has dual usage depending if
29     * the command pool is a vn_feedback_pool. The usage is exclusive
30     * and the list only contains recycled query batches allocated
31     * from the cmd pool itself so no locking is needed between the two
32     * usages.
33     *
34     * For feedback cmd pool, batch alloc and free with the free list is
35     * during queue submissions. Thus proper locking is needed since
36     * submissions with different queues are not externally synchronized.
37     *
38     * For a normal cmd pool, it recycles query batches used for
39     * injecting query copies/resets and merging batches for secondary
40     * command buffers during recording. No additional locking is needed
41     * as those commands are already protected by external synchronization.
42     */
43    struct list_head free_query_batches;
44 
45    /* for scrubbing VK_IMAGE_LAYOUT_PRESENT_SRC_KHR */
46    struct vn_cached_storage storage;
47 };
48 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_command_pool,
49                                base.base,
50                                VkCommandPool,
51                                VK_OBJECT_TYPE_COMMAND_POOL)
52 
53 enum vn_command_buffer_state {
54    VN_COMMAND_BUFFER_STATE_INITIAL,
55    VN_COMMAND_BUFFER_STATE_RECORDING,
56    VN_COMMAND_BUFFER_STATE_EXECUTABLE,
57    VN_COMMAND_BUFFER_STATE_INVALID,
58 };
59 
60 /* command buffer builder to:
61  * - fix wsi image ownership and layout transitions
62  * - scrub ignored bits in VkCommandBufferBeginInfo
63  * - support asynchronization query optimization (query feedback)
64  */
65 struct vn_command_buffer_builder {
66    /* track the active legacy render pass */
67    const struct vn_render_pass *render_pass;
68    /* track the wsi images requiring layout fixes */
69    const struct vn_image **present_src_images;
70    /* track if inside a render pass instance */
71    bool in_render_pass;
72    /* track the active subpass for view mask used in the subpass */
73    uint32_t subpass_index;
74    /* track the active view mask inside a render pass instance */
75    uint32_t view_mask;
76    /* track if VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT was set */
77    bool is_simultaneous;
78    /* track the query feedbacks deferred outside the render pass instance */
79    struct list_head query_batches;
80 };
81 
82 struct vn_command_buffer {
83    struct vn_object_base base;
84 
85    struct vn_command_pool *pool;
86    VkCommandBufferLevel level;
87    enum vn_command_buffer_state state;
88    struct vn_cs_encoder cs;
89 
90    uint32_t draw_cmd_batched;
91 
92    struct vn_command_buffer_builder builder;
93 
94    struct vn_query_feedback_cmd *linked_qfb_cmd;
95 
96    struct list_head head;
97 };
98 VK_DEFINE_HANDLE_CASTS(vn_command_buffer,
99                        base.base,
100                        VkCommandBuffer,
101                        VK_OBJECT_TYPE_COMMAND_BUFFER)
102 
103 struct vn_feedback_query_batch *
104 vn_cmd_query_batch_alloc(struct vn_command_pool *pool,
105                          struct vn_query_pool *query_pool,
106                          uint32_t query,
107                          uint32_t query_count,
108                          bool copy);
109 #endif /* VN_COMMAND_BUFFER_H */
110