blob: 1d11b127520f790b9380a9e9cd372f14ad7f172d (
plain) (
blame)
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
142
143
144
145
146
147
148
149
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <deque>
#include <optional>
#include <vector>
#include "common/assert.h"
#include "common/common_types.h"
#include "video_core/query_cache/bank_base.h"
#include "video_core/query_cache/query_base.h"
namespace VideoCommon {
class StreamerInterface {
public:
explicit StreamerInterface(size_t id_) : id{id_}, dependence_mask{}, dependent_mask{} {}
virtual ~StreamerInterface() = default;
virtual QueryBase* GetQuery(size_t id) = 0;
virtual void StartCounter() {
/* Do Nothing */
}
virtual void PauseCounter() {
/* Do Nothing */
}
virtual void ResetCounter() {
/* Do Nothing */
}
virtual void CloseCounter() {
/* Do Nothing */
}
virtual bool HasPendingSync() const {
return false;
}
virtual void PresyncWrites() {
/* Do Nothing */
}
virtual void SyncWrites() {
/* Do Nothing */
}
virtual size_t WriteCounter(VAddr address, bool has_timestamp, u32 value,
std::optional<u32> subreport = std::nullopt) = 0;
virtual bool HasUnsyncedQueries() const {
return false;
}
virtual void PushUnsyncedQueries() {
/* Do Nothing */
}
virtual void PopUnsyncedQueries() {
/* Do Nothing */
}
virtual void Free(size_t query_id) = 0;
size_t GetId() const {
return id;
}
u64 GetDependenceMask() const {
return dependence_mask;
}
u64 GetDependentMask() const {
return dependence_mask;
}
u64 GetAmendValue() const {
return amend_value;
}
void SetAccumulationValue(u64 new_value) {
accumulation_value = new_value;
}
protected:
void MakeDependent(StreamerInterface* depend_on) {
dependence_mask |= 1ULL << depend_on->id;
depend_on->dependent_mask |= 1ULL << id;
}
const size_t id;
u64 dependence_mask;
u64 dependent_mask;
u64 amend_value{};
u64 accumulation_value{};
};
template <typename QueryType>
class SimpleStreamer : public StreamerInterface {
public:
explicit SimpleStreamer(size_t id_) : StreamerInterface{id_} {}
virtual ~SimpleStreamer() = default;
protected:
virtual QueryType* GetQuery(size_t query_id) override {
if (query_id < slot_queries.size()) {
return &slot_queries[query_id];
}
return nullptr;
}
virtual void Free(size_t query_id) override {
std::scoped_lock lk(guard);
ReleaseQuery(query_id);
}
template <typename... Args, typename = decltype(QueryType(std::declval<Args>()...))>
size_t BuildQuery(Args&&... args) {
std::scoped_lock lk(guard);
if (!old_queries.empty()) {
size_t new_id = old_queries.front();
old_queries.pop_front();
new (&slot_queries[new_id]) QueryType(std::forward<Args>(args)...);
return new_id;
}
size_t new_id = slot_queries.size();
slot_queries.emplace_back(std::forward<Args>(args)...);
return new_id;
}
void ReleaseQuery(size_t query_id) {
if (query_id < slot_queries.size()) {
old_queries.push_back(query_id);
return;
}
UNREACHABLE();
}
std::mutex guard;
std::deque<QueryType> slot_queries;
std::deque<size_t> old_queries;
};
} // namespace VideoCommon
|