aboutsummaryrefslogtreecommitdiff
path: root/src/queue_context.cc
blob: dbae4c046ccde60f18522a15ef7405a0a83b64fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "queue_context.hh"

namespace low_latency {

static VkCommandPool make_command_pool(const VkDevice& device,
                                       const std::uint32_t& queue_family_index,
                                       const VkuDeviceDispatchTable& vtable) {

    const auto cpci = VkCommandPoolCreateInfo{
        .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
        .flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT |
                 VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
        .queueFamilyIndex = queue_family_index,
    };

    auto command_pool = VkCommandPool{};
    vtable.CreateCommandPool(device, &cpci, nullptr, &command_pool);
    return command_pool;
}

QueueContext::QueueContext(const VkDevice& device, const VkQueue queue,
                           const std::uint32_t& queue_family_index,
                           const VkuDeviceDispatchTable& vtable)
    : device(device), queue(queue), queue_family_index(queue_family_index),
      vtable(vtable),
      // Important we make the command pool before the timestamp pool, because it's a dependency.
      command_pool(make_command_pool(device, queue_family_index, vtable)),
      timestamp_pool(device, vtable, command_pool) {

    this->semaphore = [&]() -> VkSemaphore {
        const auto stci = VkSemaphoreTypeCreateInfo{
            .sType = VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO,
            .semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE,
            .initialValue = 0,
        };

        const auto sci = VkSemaphoreCreateInfo{
            .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
            .pNext = &stci,
        };

        auto semaphore = VkSemaphore{};
        vtable.CreateSemaphore(device, &sci, nullptr, &semaphore);
        return semaphore;
    }();
}

QueueContext::~QueueContext() {
}

} // namespace low_latency