Path: blob/master/thirdparty/metal-cpp/Metal/MTLCounters.hpp
21066 views
//-------------------------------------------------------------------------------------------------------------------------------------------------------------1//2// Metal/MTLCounters.hpp3//4// Copyright 2020-2025 Apple Inc.5//6// Licensed under the Apache License, Version 2.0 (the "License");7// you may not use this file except in compliance with the License.8// You may obtain a copy of the License at9//10// http://www.apache.org/licenses/LICENSE-2.011//12// Unless required by applicable law or agreed to in writing, software13// distributed under the License is distributed on an "AS IS" BASIS,14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15// See the License for the specific language governing permissions and16// limitations under the License.17//18//-------------------------------------------------------------------------------------------------------------------------------------------------------------1920#pragma once2122#include "../Foundation/Foundation.hpp"23#include "MTLDefines.hpp"24#include "MTLHeaderBridge.hpp"25#include "MTLPrivate.hpp"26#include "MTLResource.hpp"27#include <cstdint>2829namespace MTL30{31class CounterSampleBufferDescriptor;32class CounterSet;33class Device;34_MTL_ENUM(NS::Integer, CounterSampleBufferError) {35CounterSampleBufferErrorOutOfMemory = 0,36CounterSampleBufferErrorInvalid = 1,37CounterSampleBufferErrorInternal = 2,38};3940using CommonCounter = NS::String*;41using CommonCounterSet = NS::String*;4243static const NS::UInteger CounterErrorValue = static_cast<NS::UInteger>(~0ULL);44static const NS::UInteger CounterDontSample = static_cast<NS::UInteger>(-1);45_MTL_CONST(NS::ErrorDomain, CounterErrorDomain);46_MTL_CONST(CommonCounter, CommonCounterTimestamp);47_MTL_CONST(CommonCounter, CommonCounterTessellationInputPatches);48_MTL_CONST(CommonCounter, CommonCounterVertexInvocations);49_MTL_CONST(CommonCounter, CommonCounterPostTessellationVertexInvocations);50_MTL_CONST(CommonCounter, CommonCounterClipperInvocations);51_MTL_CONST(CommonCounter, CommonCounterClipperPrimitivesOut);52_MTL_CONST(CommonCounter, CommonCounterFragmentInvocations);53_MTL_CONST(CommonCounter, CommonCounterFragmentsPassed);54_MTL_CONST(CommonCounter, CommonCounterComputeKernelInvocations);55_MTL_CONST(CommonCounter, CommonCounterTotalCycles);56_MTL_CONST(CommonCounter, CommonCounterVertexCycles);57_MTL_CONST(CommonCounter, CommonCounterTessellationCycles);58_MTL_CONST(CommonCounter, CommonCounterPostTessellationVertexCycles);59_MTL_CONST(CommonCounter, CommonCounterFragmentCycles);60_MTL_CONST(CommonCounter, CommonCounterRenderTargetWriteCycles);61_MTL_CONST(CommonCounterSet, CommonCounterSetTimestamp);62_MTL_CONST(CommonCounterSet, CommonCounterSetStageUtilization);63_MTL_CONST(CommonCounterSet, CommonCounterSetStatistic);64struct CounterResultTimestamp65{66uint64_t timestamp;67} _MTL_PACKED;6869struct CounterResultStageUtilization70{71uint64_t totalCycles;72uint64_t vertexCycles;73uint64_t tessellationCycles;74uint64_t postTessellationVertexCycles;75uint64_t fragmentCycles;76uint64_t renderTargetCycles;77} _MTL_PACKED;7879struct CounterResultStatistic80{81uint64_t tessellationInputPatches;82uint64_t vertexInvocations;83uint64_t postTessellationVertexInvocations;84uint64_t clipperInvocations;85uint64_t clipperPrimitivesOut;86uint64_t fragmentInvocations;87uint64_t fragmentsPassed;88uint64_t computeKernelInvocations;89} _MTL_PACKED;9091class Counter : public NS::Referencing<Counter>92{93public:94NS::String* name() const;95};96class CounterSet : public NS::Referencing<CounterSet>97{98public:99NS::Array* counters() const;100101NS::String* name() const;102};103class CounterSampleBufferDescriptor : public NS::Copying<CounterSampleBufferDescriptor>104{105public:106static CounterSampleBufferDescriptor* alloc();107108CounterSet* counterSet() const;109110CounterSampleBufferDescriptor* init();111112NS::String* label() const;113114NS::UInteger sampleCount() const;115116void setCounterSet(const MTL::CounterSet* counterSet);117118void setLabel(const NS::String* label);119120void setSampleCount(NS::UInteger sampleCount);121122void setStorageMode(MTL::StorageMode storageMode);123StorageMode storageMode() const;124};125class CounterSampleBuffer : public NS::Referencing<CounterSampleBuffer>126{127public:128Device* device() const;129130NS::String* label() const;131132NS::Data* resolveCounterRange(NS::Range range);133134NS::UInteger sampleCount() const;135};136137}138139_MTL_PRIVATE_DEF_CONST(NS::ErrorDomain, CounterErrorDomain);140_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterTimestamp);141_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterTessellationInputPatches);142_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterVertexInvocations);143_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterPostTessellationVertexInvocations);144_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterClipperInvocations);145_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterClipperPrimitivesOut);146_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterFragmentInvocations);147_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterFragmentsPassed);148_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterComputeKernelInvocations);149_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterTotalCycles);150_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterVertexCycles);151_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterTessellationCycles);152_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterPostTessellationVertexCycles);153_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterFragmentCycles);154_MTL_PRIVATE_DEF_CONST(MTL::CommonCounter, CommonCounterRenderTargetWriteCycles);155_MTL_PRIVATE_DEF_CONST(MTL::CommonCounterSet, CommonCounterSetTimestamp);156_MTL_PRIVATE_DEF_CONST(MTL::CommonCounterSet, CommonCounterSetStageUtilization);157_MTL_PRIVATE_DEF_CONST(MTL::CommonCounterSet, CommonCounterSetStatistic);158159_MTL_INLINE NS::String* MTL::Counter::name() const160{161return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(name));162}163164_MTL_INLINE NS::Array* MTL::CounterSet::counters() const165{166return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(counters));167}168169_MTL_INLINE NS::String* MTL::CounterSet::name() const170{171return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(name));172}173174_MTL_INLINE MTL::CounterSampleBufferDescriptor* MTL::CounterSampleBufferDescriptor::alloc()175{176return NS::Object::alloc<MTL::CounterSampleBufferDescriptor>(_MTL_PRIVATE_CLS(MTLCounterSampleBufferDescriptor));177}178179_MTL_INLINE MTL::CounterSet* MTL::CounterSampleBufferDescriptor::counterSet() const180{181return Object::sendMessage<MTL::CounterSet*>(this, _MTL_PRIVATE_SEL(counterSet));182}183184_MTL_INLINE MTL::CounterSampleBufferDescriptor* MTL::CounterSampleBufferDescriptor::init()185{186return NS::Object::init<MTL::CounterSampleBufferDescriptor>();187}188189_MTL_INLINE NS::String* MTL::CounterSampleBufferDescriptor::label() const190{191return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));192}193194_MTL_INLINE NS::UInteger MTL::CounterSampleBufferDescriptor::sampleCount() const195{196return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(sampleCount));197}198199_MTL_INLINE void MTL::CounterSampleBufferDescriptor::setCounterSet(const MTL::CounterSet* counterSet)200{201Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setCounterSet_), counterSet);202}203204_MTL_INLINE void MTL::CounterSampleBufferDescriptor::setLabel(const NS::String* label)205{206Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);207}208209_MTL_INLINE void MTL::CounterSampleBufferDescriptor::setSampleCount(NS::UInteger sampleCount)210{211Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSampleCount_), sampleCount);212}213214_MTL_INLINE void MTL::CounterSampleBufferDescriptor::setStorageMode(MTL::StorageMode storageMode)215{216Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setStorageMode_), storageMode);217}218219_MTL_INLINE MTL::StorageMode MTL::CounterSampleBufferDescriptor::storageMode() const220{221return Object::sendMessage<MTL::StorageMode>(this, _MTL_PRIVATE_SEL(storageMode));222}223224_MTL_INLINE MTL::Device* MTL::CounterSampleBuffer::device() const225{226return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));227}228229_MTL_INLINE NS::String* MTL::CounterSampleBuffer::label() const230{231return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));232}233234_MTL_INLINE NS::Data* MTL::CounterSampleBuffer::resolveCounterRange(NS::Range range)235{236return Object::sendMessage<NS::Data*>(this, _MTL_PRIVATE_SEL(resolveCounterRange_), range);237}238239_MTL_INLINE NS::UInteger MTL::CounterSampleBuffer::sampleCount() const240{241return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(sampleCount));242}243244245