/ include / Metal / MTLCounters.hpp
MTLCounters.hpp
  1  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
  2  //
  3  // Metal/MTLCounters.hpp
  4  //
  5  // Copyright 2020-2024 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 "MTLDefines.hpp"
 24  #include "MTLHeaderBridge.hpp"
 25  #include "MTLPrivate.hpp"
 26  
 27  #include <Foundation/Foundation.hpp>
 28  
 29  #include "MTLResource.hpp"
 30  
 31  namespace MTL
 32  {
 33  struct CounterResultTimestamp
 34  {
 35      uint64_t timestamp;
 36  } _MTL_PACKED;
 37  
 38  struct CounterResultStageUtilization
 39  {
 40      uint64_t totalCycles;
 41      uint64_t vertexCycles;
 42      uint64_t tessellationCycles;
 43      uint64_t postTessellationVertexCycles;
 44      uint64_t fragmentCycles;
 45      uint64_t renderTargetCycles;
 46  } _MTL_PACKED;
 47  
 48  struct CounterResultStatistic
 49  {
 50      uint64_t tessellationInputPatches;
 51      uint64_t vertexInvocations;
 52      uint64_t postTessellationVertexInvocations;
 53      uint64_t clipperInvocations;
 54      uint64_t clipperPrimitivesOut;
 55      uint64_t fragmentInvocations;
 56      uint64_t fragmentsPassed;
 57      uint64_t computeKernelInvocations;
 58  } _MTL_PACKED;
 59  
 60  _MTL_CONST(NS::ErrorDomain, CounterErrorDomain);
 61  
 62  using CommonCounter = NS::String*;
 63  
 64  _MTL_CONST(CommonCounter, CommonCounterTimestamp);
 65  _MTL_CONST(CommonCounter, CommonCounterTessellationInputPatches);
 66  _MTL_CONST(CommonCounter, CommonCounterVertexInvocations);
 67  _MTL_CONST(CommonCounter, CommonCounterPostTessellationVertexInvocations);
 68  _MTL_CONST(CommonCounter, CommonCounterClipperInvocations);
 69  _MTL_CONST(CommonCounter, CommonCounterClipperPrimitivesOut);
 70  _MTL_CONST(CommonCounter, CommonCounterFragmentInvocations);
 71  _MTL_CONST(CommonCounter, CommonCounterFragmentsPassed);
 72  _MTL_CONST(CommonCounter, CommonCounterComputeKernelInvocations);
 73  _MTL_CONST(CommonCounter, CommonCounterTotalCycles);
 74  _MTL_CONST(CommonCounter, CommonCounterVertexCycles);
 75  _MTL_CONST(CommonCounter, CommonCounterTessellationCycles);
 76  _MTL_CONST(CommonCounter, CommonCounterPostTessellationVertexCycles);
 77  _MTL_CONST(CommonCounter, CommonCounterFragmentCycles);
 78  _MTL_CONST(CommonCounter, CommonCounterRenderTargetWriteCycles);
 79  
 80  using CommonCounterSet = NS::String*;
 81  
 82  _MTL_CONST(CommonCounterSet, CommonCounterSetTimestamp);
 83  _MTL_CONST(CommonCounterSet, CommonCounterSetStageUtilization);
 84  _MTL_CONST(CommonCounterSet, CommonCounterSetStatistic);
 85  
 86  class Counter : public NS::Referencing<Counter>
 87  {
 88  public:
 89      NS::String* name() const;
 90  };
 91  
 92  class CounterSet : public NS::Referencing<CounterSet>
 93  {
 94  public:
 95      NS::String* name() const;
 96  
 97      NS::Array*  counters() const;
 98  };
 99  
100  class CounterSampleBufferDescriptor : public NS::Copying<CounterSampleBufferDescriptor>
101  {
102  public:
103      static class CounterSampleBufferDescriptor* alloc();
104  
105      class CounterSampleBufferDescriptor*        init();
106  
107      class CounterSet*                           counterSet() const;
108      void                                        setCounterSet(const class CounterSet* counterSet);
109  
110      NS::String*                                 label() const;
111      void                                        setLabel(const NS::String* label);
112  
113      MTL::StorageMode                            storageMode() const;
114      void                                        setStorageMode(MTL::StorageMode storageMode);
115  
116      NS::UInteger                                sampleCount() const;
117      void                                        setSampleCount(NS::UInteger sampleCount);
118  };
119  
120  class CounterSampleBuffer : public NS::Referencing<CounterSampleBuffer>
121  {
122  public:
123      class Device* device() const;
124  
125      NS::String*   label() const;
126  
127      NS::UInteger  sampleCount() const;
128  
129      NS::Data*     resolveCounterRange(NS::Range range);
130  };
131  
132  _MTL_ENUM(NS::Integer, CounterSampleBufferError) {
133      CounterSampleBufferErrorOutOfMemory = 0,
134      CounterSampleBufferErrorInvalid = 1,
135      CounterSampleBufferErrorInternal = 2,
136  };
137  
138  static const NS::UInteger CounterErrorValue = ((uint64_t)~0ULL);
139  static const NS::UInteger CounterDontSample = ((uint64_t)-1);
140  
141  }
142  
143  _MTL_PRIVATE_DEF_STR(NS::ErrorDomain, CounterErrorDomain);
144  
145  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterTimestamp);
146  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterTessellationInputPatches);
147  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterVertexInvocations);
148  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterPostTessellationVertexInvocations);
149  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterClipperInvocations);
150  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterClipperPrimitivesOut);
151  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterFragmentInvocations);
152  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterFragmentsPassed);
153  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterComputeKernelInvocations);
154  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterTotalCycles);
155  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterVertexCycles);
156  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterTessellationCycles);
157  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterPostTessellationVertexCycles);
158  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterFragmentCycles);
159  _MTL_PRIVATE_DEF_STR(MTL::CommonCounter, CommonCounterRenderTargetWriteCycles);
160  
161  _MTL_PRIVATE_DEF_STR(MTL::CommonCounterSet, CommonCounterSetTimestamp);
162  _MTL_PRIVATE_DEF_STR(MTL::CommonCounterSet, CommonCounterSetStageUtilization);
163  _MTL_PRIVATE_DEF_STR(MTL::CommonCounterSet, CommonCounterSetStatistic);
164  
165  // property: name
166  _MTL_INLINE NS::String* MTL::Counter::name() const
167  {
168      return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(name));
169  }
170  
171  // property: name
172  _MTL_INLINE NS::String* MTL::CounterSet::name() const
173  {
174      return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(name));
175  }
176  
177  // property: counters
178  _MTL_INLINE NS::Array* MTL::CounterSet::counters() const
179  {
180      return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(counters));
181  }
182  
183  // static method: alloc
184  _MTL_INLINE MTL::CounterSampleBufferDescriptor* MTL::CounterSampleBufferDescriptor::alloc()
185  {
186      return NS::Object::alloc<MTL::CounterSampleBufferDescriptor>(_MTL_PRIVATE_CLS(MTLCounterSampleBufferDescriptor));
187  }
188  
189  // method: init
190  _MTL_INLINE MTL::CounterSampleBufferDescriptor* MTL::CounterSampleBufferDescriptor::init()
191  {
192      return NS::Object::init<MTL::CounterSampleBufferDescriptor>();
193  }
194  
195  // property: counterSet
196  _MTL_INLINE MTL::CounterSet* MTL::CounterSampleBufferDescriptor::counterSet() const
197  {
198      return Object::sendMessage<MTL::CounterSet*>(this, _MTL_PRIVATE_SEL(counterSet));
199  }
200  
201  _MTL_INLINE void MTL::CounterSampleBufferDescriptor::setCounterSet(const MTL::CounterSet* counterSet)
202  {
203      Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setCounterSet_), counterSet);
204  }
205  
206  // property: label
207  _MTL_INLINE NS::String* MTL::CounterSampleBufferDescriptor::label() const
208  {
209      return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));
210  }
211  
212  _MTL_INLINE void MTL::CounterSampleBufferDescriptor::setLabel(const NS::String* label)
213  {
214      Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);
215  }
216  
217  // property: storageMode
218  _MTL_INLINE MTL::StorageMode MTL::CounterSampleBufferDescriptor::storageMode() const
219  {
220      return Object::sendMessage<MTL::StorageMode>(this, _MTL_PRIVATE_SEL(storageMode));
221  }
222  
223  _MTL_INLINE void MTL::CounterSampleBufferDescriptor::setStorageMode(MTL::StorageMode storageMode)
224  {
225      Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setStorageMode_), storageMode);
226  }
227  
228  // property: sampleCount
229  _MTL_INLINE NS::UInteger MTL::CounterSampleBufferDescriptor::sampleCount() const
230  {
231      return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(sampleCount));
232  }
233  
234  _MTL_INLINE void MTL::CounterSampleBufferDescriptor::setSampleCount(NS::UInteger sampleCount)
235  {
236      Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSampleCount_), sampleCount);
237  }
238  
239  // property: device
240  _MTL_INLINE MTL::Device* MTL::CounterSampleBuffer::device() const
241  {
242      return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));
243  }
244  
245  // property: label
246  _MTL_INLINE NS::String* MTL::CounterSampleBuffer::label() const
247  {
248      return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));
249  }
250  
251  // property: sampleCount
252  _MTL_INLINE NS::UInteger MTL::CounterSampleBuffer::sampleCount() const
253  {
254      return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(sampleCount));
255  }
256  
257  // method: resolveCounterRange:
258  _MTL_INLINE NS::Data* MTL::CounterSampleBuffer::resolveCounterRange(NS::Range range)
259  {
260      return Object::sendMessage<NS::Data*>(this, _MTL_PRIVATE_SEL(resolveCounterRange_), range);
261  }