Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/metal-cpp/Metal/MTLCounters.hpp
21066 views
1
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
2
//
3
// Metal/MTLCounters.hpp
4
//
5
// Copyright 2020-2025 Apple Inc.
6
//
7
// Licensed under the Apache License, Version 2.0 (the "License");
8
// you may not use this file except in compliance with the License.
9
// You may obtain a copy of the License at
10
//
11
// http://www.apache.org/licenses/LICENSE-2.0
12
//
13
// Unless required by applicable law or agreed to in writing, software
14
// distributed under the License is distributed on an "AS IS" BASIS,
15
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
// See the License for the specific language governing permissions and
17
// limitations under the License.
18
//
19
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
20
21
#pragma once
22
23
#include "../Foundation/Foundation.hpp"
24
#include "MTLDefines.hpp"
25
#include "MTLHeaderBridge.hpp"
26
#include "MTLPrivate.hpp"
27
#include "MTLResource.hpp"
28
#include <cstdint>
29
30
namespace MTL
31
{
32
class CounterSampleBufferDescriptor;
33
class CounterSet;
34
class Device;
35
_MTL_ENUM(NS::Integer, CounterSampleBufferError) {
36
CounterSampleBufferErrorOutOfMemory = 0,
37
CounterSampleBufferErrorInvalid = 1,
38
CounterSampleBufferErrorInternal = 2,
39
};
40
41
using CommonCounter = NS::String*;
42
using CommonCounterSet = NS::String*;
43
44
static const NS::UInteger CounterErrorValue = static_cast<NS::UInteger>(~0ULL);
45
static const NS::UInteger CounterDontSample = static_cast<NS::UInteger>(-1);
46
_MTL_CONST(NS::ErrorDomain, CounterErrorDomain);
47
_MTL_CONST(CommonCounter, CommonCounterTimestamp);
48
_MTL_CONST(CommonCounter, CommonCounterTessellationInputPatches);
49
_MTL_CONST(CommonCounter, CommonCounterVertexInvocations);
50
_MTL_CONST(CommonCounter, CommonCounterPostTessellationVertexInvocations);
51
_MTL_CONST(CommonCounter, CommonCounterClipperInvocations);
52
_MTL_CONST(CommonCounter, CommonCounterClipperPrimitivesOut);
53
_MTL_CONST(CommonCounter, CommonCounterFragmentInvocations);
54
_MTL_CONST(CommonCounter, CommonCounterFragmentsPassed);
55
_MTL_CONST(CommonCounter, CommonCounterComputeKernelInvocations);
56
_MTL_CONST(CommonCounter, CommonCounterTotalCycles);
57
_MTL_CONST(CommonCounter, CommonCounterVertexCycles);
58
_MTL_CONST(CommonCounter, CommonCounterTessellationCycles);
59
_MTL_CONST(CommonCounter, CommonCounterPostTessellationVertexCycles);
60
_MTL_CONST(CommonCounter, CommonCounterFragmentCycles);
61
_MTL_CONST(CommonCounter, CommonCounterRenderTargetWriteCycles);
62
_MTL_CONST(CommonCounterSet, CommonCounterSetTimestamp);
63
_MTL_CONST(CommonCounterSet, CommonCounterSetStageUtilization);
64
_MTL_CONST(CommonCounterSet, CommonCounterSetStatistic);
65
struct CounterResultTimestamp
66
{
67
uint64_t timestamp;
68
} _MTL_PACKED;
69
70
struct CounterResultStageUtilization
71
{
72
uint64_t totalCycles;
73
uint64_t vertexCycles;
74
uint64_t tessellationCycles;
75
uint64_t postTessellationVertexCycles;
76
uint64_t fragmentCycles;
77
uint64_t renderTargetCycles;
78
} _MTL_PACKED;
79
80
struct CounterResultStatistic
81
{
82
uint64_t tessellationInputPatches;
83
uint64_t vertexInvocations;
84
uint64_t postTessellationVertexInvocations;
85
uint64_t clipperInvocations;
86
uint64_t clipperPrimitivesOut;
87
uint64_t fragmentInvocations;
88
uint64_t fragmentsPassed;
89
uint64_t computeKernelInvocations;
90
} _MTL_PACKED;
91
92
class Counter : public NS::Referencing<Counter>
93
{
94
public:
95
NS::String* name() const;
96
};
97
class CounterSet : public NS::Referencing<CounterSet>
98
{
99
public:
100
NS::Array* counters() const;
101
102
NS::String* name() const;
103
};
104
class CounterSampleBufferDescriptor : public NS::Copying<CounterSampleBufferDescriptor>
105
{
106
public:
107
static CounterSampleBufferDescriptor* alloc();
108
109
CounterSet* counterSet() const;
110
111
CounterSampleBufferDescriptor* init();
112
113
NS::String* label() const;
114
115
NS::UInteger sampleCount() const;
116
117
void setCounterSet(const MTL::CounterSet* counterSet);
118
119
void setLabel(const NS::String* label);
120
121
void setSampleCount(NS::UInteger sampleCount);
122
123
void setStorageMode(MTL::StorageMode storageMode);
124
StorageMode storageMode() const;
125
};
126
class CounterSampleBuffer : public NS::Referencing<CounterSampleBuffer>
127
{
128
public:
129
Device* device() const;
130
131
NS::String* label() const;
132
133
NS::Data* resolveCounterRange(NS::Range range);
134
135
NS::UInteger sampleCount() const;
136
};
137
138
}
139
140
_MTL_PRIVATE_DEF_CONST(NS::ErrorDomain, CounterErrorDomain);
141
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterTimestamp);
142
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterTessellationInputPatches);
143
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterVertexInvocations);
144
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterPostTessellationVertexInvocations);
145
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterClipperInvocations);
146
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterClipperPrimitivesOut);
147
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterFragmentInvocations);
148
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterFragmentsPassed);
149
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterComputeKernelInvocations);
150
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterTotalCycles);
151
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterVertexCycles);
152
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterTessellationCycles);
153
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterPostTessellationVertexCycles);
154
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterFragmentCycles);
155
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterRenderTargetWriteCycles);
156
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounterSet, CommonCounterSetTimestamp);
157
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounterSet, CommonCounterSetStageUtilization);
158
_MTL_PRIVATE_DEF_CONST(MTL::CommonCounterSet, CommonCounterSetStatistic);
159
160
_MTL_INLINE NS::String* MTL::Counter::name() const
161
{
162
return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(name));
163
}
164
165
_MTL_INLINE NS::Array* MTL::CounterSet::counters() const
166
{
167
return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(counters));
168
}
169
170
_MTL_INLINE NS::String* MTL::CounterSet::name() const
171
{
172
return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(name));
173
}
174
175
_MTL_INLINE MTL::CounterSampleBufferDescriptor* MTL::CounterSampleBufferDescriptor::alloc()
176
{
177
return NS::Object::alloc<MTL::CounterSampleBufferDescriptor>(_MTL_PRIVATE_CLS(MTLCounterSampleBufferDescriptor));
178
}
179
180
_MTL_INLINE MTL::CounterSet* MTL::CounterSampleBufferDescriptor::counterSet() const
181
{
182
return Object::sendMessage<MTL::CounterSet*>(this, _MTL_PRIVATE_SEL(counterSet));
183
}
184
185
_MTL_INLINE MTL::CounterSampleBufferDescriptor* MTL::CounterSampleBufferDescriptor::init()
186
{
187
return NS::Object::init<MTL::CounterSampleBufferDescriptor>();
188
}
189
190
_MTL_INLINE NS::String* MTL::CounterSampleBufferDescriptor::label() const
191
{
192
return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));
193
}
194
195
_MTL_INLINE NS::UInteger MTL::CounterSampleBufferDescriptor::sampleCount() const
196
{
197
return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(sampleCount));
198
}
199
200
_MTL_INLINE void MTL::CounterSampleBufferDescriptor::setCounterSet(const MTL::CounterSet* counterSet)
201
{
202
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setCounterSet_), counterSet);
203
}
204
205
_MTL_INLINE void MTL::CounterSampleBufferDescriptor::setLabel(const NS::String* label)
206
{
207
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);
208
}
209
210
_MTL_INLINE void MTL::CounterSampleBufferDescriptor::setSampleCount(NS::UInteger sampleCount)
211
{
212
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSampleCount_), sampleCount);
213
}
214
215
_MTL_INLINE void MTL::CounterSampleBufferDescriptor::setStorageMode(MTL::StorageMode storageMode)
216
{
217
Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setStorageMode_), storageMode);
218
}
219
220
_MTL_INLINE MTL::StorageMode MTL::CounterSampleBufferDescriptor::storageMode() const
221
{
222
return Object::sendMessage<MTL::StorageMode>(this, _MTL_PRIVATE_SEL(storageMode));
223
}
224
225
_MTL_INLINE MTL::Device* MTL::CounterSampleBuffer::device() const
226
{
227
return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));
228
}
229
230
_MTL_INLINE NS::String* MTL::CounterSampleBuffer::label() const
231
{
232
return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));
233
}
234
235
_MTL_INLINE NS::Data* MTL::CounterSampleBuffer::resolveCounterRange(NS::Range range)
236
{
237
return Object::sendMessage<NS::Data*>(this, _MTL_PRIVATE_SEL(resolveCounterRange_), range);
238
}
239
240
_MTL_INLINE NS::UInteger MTL::CounterSampleBuffer::sampleCount() const
241
{
242
return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(sampleCount));
243
}
244
245