forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_state.h
141 lines (116 loc) · 4.54 KB
/
queue_state.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* Copyright (c) 2015-2021 The Khronos Group Inc.
* Copyright (c) 2015-2021 Valve Corporation
* Copyright (c) 2015-2021 LunarG, Inc.
* Copyright (C) 2015-2021 Google Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: Courtney Goeltzenleuchter <[email protected]>
* Author: Tobin Ehlis <[email protected]>
* Author: Chris Forbes <[email protected]>
* Author: Mark Lobodzinski <[email protected]>
* Author: Dave Houlton <[email protected]>
* Author: John Zulauf <[email protected]>
* Author: Tobias Hector <[email protected]>
*/
#pragma once
#include "base_node.h"
#include <vector>
#include <deque>
class CMD_BUFFER_STATE;
class QUEUE_STATE;
enum SyncScope {
kSyncScopeInternal,
kSyncScopeExternalTemporary,
kSyncScopeExternalPermanent,
};
enum FENCE_STATUS { FENCE_UNSIGNALED, FENCE_INFLIGHT, FENCE_RETIRED };
struct QUEUE_SIGNALER {
QUEUE_STATE *queue{nullptr};
uint64_t seq{0};
};
class FENCE_STATE : public REFCOUNTED_NODE {
public:
const VkFenceCreateInfo createInfo;
QUEUE_SIGNALER signaler;
FENCE_STATUS state;
SyncScope scope{kSyncScopeInternal};
// Default constructor
FENCE_STATE(VkFence f, const VkFenceCreateInfo *pCreateInfo)
: REFCOUNTED_NODE(f, kVulkanObjectTypeFence),
createInfo(*pCreateInfo),
state((pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT) ? FENCE_RETIRED : FENCE_UNSIGNALED),
scope(kSyncScopeInternal) {}
VkFence fence() const { return handle_.Cast<VkFence>(); }
void Retire();
};
class SEMAPHORE_STATE : public REFCOUNTED_NODE {
public:
QUEUE_SIGNALER signaler;
bool signaled{false};
SyncScope scope{kSyncScopeInternal};
const VkSemaphoreType type;
uint64_t payload;
SEMAPHORE_STATE(VkSemaphore sem, const VkSemaphoreTypeCreateInfo *type_create_info)
: REFCOUNTED_NODE(sem, kVulkanObjectTypeSemaphore),
type(type_create_info ? type_create_info->semaphoreType : VK_SEMAPHORE_TYPE_BINARY),
payload(type_create_info ? type_create_info->initialValue : 0) {}
VkSemaphore semaphore() const { return handle_.Cast<VkSemaphore>(); }
void Retire(uint64_t next_seq);
};
struct SEMAPHORE_WAIT {
std::shared_ptr<SEMAPHORE_STATE> semaphore;
uint64_t payload{0};
uint64_t seq{0};
};
struct SEMAPHORE_SIGNAL {
std::shared_ptr<SEMAPHORE_STATE> semaphore;
uint64_t payload{0};
uint64_t seq{0};
};
struct CB_SUBMISSION {
std::vector<std::shared_ptr<CMD_BUFFER_STATE>> cbs;
std::vector<SEMAPHORE_WAIT> wait_semaphores;
std::vector<SEMAPHORE_SIGNAL> signal_semaphores;
std::shared_ptr<FENCE_STATE> fence;
uint32_t perf_submit_pass{0};
void AddCommandBuffer(std::shared_ptr<CMD_BUFFER_STATE> &&cb_node) { cbs.emplace_back(std::move(cb_node)); }
void AddSignalSemaphore(std::shared_ptr<SEMAPHORE_STATE> &&semaphore_state, uint64_t value) {
SEMAPHORE_SIGNAL signal;
signal.semaphore = std::move(semaphore_state);
signal.payload = value;
signal.seq = 0;
signal_semaphores.emplace_back(std::move(signal));
}
void AddWaitSemaphore(std::shared_ptr<SEMAPHORE_STATE> &&semaphore_state, uint64_t value) {
SEMAPHORE_WAIT wait;
wait.semaphore = std::move(semaphore_state);
wait.payload = value;
wait_semaphores.emplace_back(std::move(wait));
}
void AddFence(std::shared_ptr<FENCE_STATE> &&fence_state) { fence = std::move(fence_state); }
};
class QUEUE_STATE : public BASE_NODE {
public:
const uint32_t queueFamilyIndex;
const VkDeviceQueueCreateFlags flags;
uint64_t seq;
std::deque<CB_SUBMISSION> submissions;
QUEUE_STATE(VkQueue q, uint32_t index, VkDeviceQueueCreateFlags flags)
: BASE_NODE(q, kVulkanObjectTypeQueue), queueFamilyIndex(index), flags(flags), seq(0) {}
VkQueue Queue() const { return handle_.Cast<VkQueue>(); }
uint64_t Submit(CB_SUBMISSION &&submission);
void Retire(uint64_t next_seq);
void Retire() { Retire(seq + submissions.size()); }
};