1 /*
2  * Copyright © 2021 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef VK_QUEUE_H
25 #define VK_QUEUE_H
26 
27 #include "vk_object.h"
28 
29 #include "util/list.h"
30 #include "util/u_dynarray.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 struct vk_queue {
37    struct vk_object_base base;
38 
39    /* Link in vk_device::queues */
40    struct list_head link;
41 
42    /* VkDeviceQueueCreateInfo::flags */
43    VkDeviceQueueCreateFlags flags;
44 
45    /* VkDeviceQueueCreateInfo::queueFamilyIndex */
46    uint32_t queue_family_index;
47 
48    /* Which queue this is within the queue family */
49    uint32_t index_in_family;
50 
51    /**
52     * VK_EXT_debug_utils
53     *
54     * The next two fields represent debug labels storage.
55     *
56     * VK_EXT_debug_utils spec requires that upon triggering a debug message
57     * with a queue attached to it, all "active" labels will also be provided
58     * to the callback. The spec describes two distinct ways of attaching a
59     * debug label to the queue: opening a label region and inserting a single
60     * label.
61     *
62     * Label region is active between the corresponding `*BeginDebugUtilsLabel`
63     * and `*EndDebugUtilsLabel` calls. The spec doesn't mention any limits on
64     * nestedness of label regions. This implementation assumes that there
65     * aren't any.
66     *
67     * The spec, however, doesn't explain the lifetime of a label submitted by
68     * an `*InsertDebugUtilsLabel` call. The LunarG whitepaper [1] (pp 12-15)
69     * provides a more detailed explanation along with some examples. According
70     * to those, such label remains active until the next `*DebugUtilsLabel`
71     * call. This means that there can be no more than one such label at a
72     * time.
73     *
74     * \c labels contains all active labels at this point in order of submission
75     * \c region_begin denotes whether the most recent label opens a new region
76     * If \t labels is empty \t region_begin must be true.
77     *
78     * Anytime we modify labels, we first check for \c region_begin. If it's
79     * false, it means that the most recent label was submitted by
80     * `*InsertDebugUtilsLabel` and we need to remove it before doing anything
81     * else.
82     *
83     * See the discussion here:
84     * https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10318#note_1061317
85     *
86     * [1] https://www.lunarg.com/wp-content/uploads/2018/05/Vulkan-Debug-Utils_05_18_v1.pdf
87     */
88    struct util_dynarray labels;
89    bool region_begin;
90 };
91 
92 VK_DEFINE_HANDLE_CASTS(vk_queue, base, VkQueue, VK_OBJECT_TYPE_QUEUE)
93 
94 VkResult MUST_CHECK
95 vk_queue_init(struct vk_queue *queue, struct vk_device *device,
96               const VkDeviceQueueCreateInfo *pCreateInfo,
97               uint32_t index_in_family);
98 
99 void
100 vk_queue_finish(struct vk_queue *queue);
101 
102 #define vk_foreach_queue(queue, device) \
103    list_for_each_entry(struct vk_queue, queue, &(device)->queues, link)
104 
105 #define vk_foreach_queue_safe(queue, device) \
106    list_for_each_entry_safe(struct vk_queue, queue, &(device)->queues, link)
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif  /* VK_QUEUE_H */
113