forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_state.h
135 lines (122 loc) · 5.05 KB
/
query_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
/* 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 "hash_vk_types.h"
class QUERY_POOL_STATE : public BASE_NODE {
public:
VkQueryPoolCreateInfo createInfo;
bool has_perf_scope_command_buffer;
bool has_perf_scope_render_pass;
uint32_t n_performance_passes;
uint32_t perf_counter_index_count;
QUERY_POOL_STATE(VkQueryPool qp, const VkQueryPoolCreateInfo *pCreateInfo, uint32_t index_count, uint32_t n_perf_pass,
bool has_cb, bool has_rb)
: BASE_NODE(qp, kVulkanObjectTypeQueryPool),
createInfo(*pCreateInfo),
has_perf_scope_command_buffer(has_cb),
has_perf_scope_render_pass(has_rb),
n_performance_passes(n_perf_pass),
perf_counter_index_count(index_count) {}
VkQueryPool pool() const { return handle_.Cast<VkQueryPool>(); }
};
struct QueryObject {
VkQueryPool pool;
uint32_t query;
// These next two fields are *not* used in hash or comparison, they are effectively a data payload
uint32_t index; // must be zero if !indexed
uint32_t perf_pass;
bool indexed;
// Command index in the command buffer where the end of the query was
// recorded (equal to the number of commands in the command buffer before
// the end of the query).
uint64_t endCommandIndex;
QueryObject(VkQueryPool pool_, uint32_t query_)
: pool(pool_), query(query_), index(0), perf_pass(0), indexed(false), endCommandIndex(0) {}
QueryObject(VkQueryPool pool_, uint32_t query_, uint32_t index_)
: pool(pool_), query(query_), index(index_), perf_pass(0), indexed(true), endCommandIndex(0) {}
QueryObject(const QueryObject &obj)
: pool(obj.pool),
query(obj.query),
index(obj.index),
perf_pass(obj.perf_pass),
indexed(obj.indexed),
endCommandIndex(obj.endCommandIndex) {}
QueryObject(const QueryObject &obj, uint32_t perf_pass_)
: pool(obj.pool),
query(obj.query),
index(obj.index),
perf_pass(perf_pass_),
indexed(obj.indexed),
endCommandIndex(obj.endCommandIndex) {}
bool operator<(const QueryObject &rhs) const {
return (pool == rhs.pool) ? ((query == rhs.query) ? (perf_pass < rhs.perf_pass) : (query < rhs.query)) : pool < rhs.pool;
}
};
inline bool operator==(const QueryObject &query1, const QueryObject &query2) {
return ((query1.pool == query2.pool) && (query1.query == query2.query) && (query1.perf_pass == query2.perf_pass));
}
enum QueryState {
QUERYSTATE_UNKNOWN, // Initial state.
QUERYSTATE_RESET, // After resetting.
QUERYSTATE_RUNNING, // Query running.
QUERYSTATE_ENDED, // Query ended but results may not be available.
QUERYSTATE_AVAILABLE, // Results available.
};
typedef std::map<QueryObject, QueryState> QueryMap;
enum QueryResultType {
QUERYRESULT_UNKNOWN,
QUERYRESULT_NO_DATA,
QUERYRESULT_SOME_DATA,
QUERYRESULT_WAIT_ON_RESET,
QUERYRESULT_WAIT_ON_RUNNING,
};
inline const char *string_QueryResultType(QueryResultType result_type) {
switch (result_type) {
case QUERYRESULT_UNKNOWN:
return "query may be in an unknown state";
case QUERYRESULT_NO_DATA:
return "query may return no data";
case QUERYRESULT_SOME_DATA:
return "query will return some data or availability bit";
case QUERYRESULT_WAIT_ON_RESET:
return "waiting on a query that has been reset and not issued yet";
case QUERYRESULT_WAIT_ON_RUNNING:
return "waiting on a query that has not ended yet";
}
assert(false);
return "UNKNOWN QUERY STATE"; // Unreachable.
}
namespace std {
template <>
struct hash<QueryObject> {
size_t operator()(QueryObject query) const throw() {
return hash<uint64_t>()((uint64_t)(query.pool)) ^
hash<uint64_t>()(static_cast<uint64_t>(query.query) | (static_cast<uint64_t>(query.perf_pass) << 32));
}
};
} // namespace std