SPB Git

spb/forge Public MIT

Forge — LLM training from scratch in pure C++20 + Metal on Apple Silicon.

C++ 61.2% C 23% Python 7.6% TeX 7.2% CMake 1.1%
3.0 KB · 91 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTLDrawable.hpp4//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 at10//11//     http://www.apache.org/licenses/LICENSE-2.012//13// Unless required by applicable law or agreed to in writing, software14// 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 and17// limitations under the License.18//19//-------------------------------------------------------------------------------------------------------------------------------------------------------------2021#pragma once2223#include "../Foundation/Foundation.hpp"24#include "MTLDefines.hpp"25#include "MTLHeaderBridge.hpp"26#include "MTLPrivate.hpp"27#include <CoreFoundation/CoreFoundation.h>2829#include <CoreFoundation/CoreFoundation.h>30#include <functional>3132namespace MTL33{34class Drawable;3536using DrawablePresentedHandler = void (^)(MTL::Drawable*);37using DrawablePresentedHandlerFunction = std::function<void(MTL::Drawable*)>;3839class Drawable : public NS::Referencing<Drawable>40{41public:42    void           addPresentedHandler(const MTL::DrawablePresentedHandler block);43    void           addPresentedHandler(const MTL::DrawablePresentedHandlerFunction& function);4445    NS::UInteger   drawableID() const;4647    void           present();48    void           presentAfterMinimumDuration(CFTimeInterval duration);4950    void           presentAtTime(CFTimeInterval presentationTime);5152    CFTimeInterval presentedTime() const;53};5455}56_MTL_INLINE void MTL::Drawable::addPresentedHandler(const MTL::DrawablePresentedHandler block)57{58    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addPresentedHandler_), block);59}6061_MTL_INLINE void MTL::Drawable::addPresentedHandler(const MTL::DrawablePresentedHandlerFunction& function)62{63    __block DrawablePresentedHandlerFunction blockFunction = function;64    addPresentedHandler(^(Drawable* pDrawable) { blockFunction(pDrawable); });65}6667_MTL_INLINE NS::UInteger MTL::Drawable::drawableID() const68{69    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(drawableID));70}7172_MTL_INLINE void MTL::Drawable::present()73{74    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(present));75}7677_MTL_INLINE void MTL::Drawable::presentAfterMinimumDuration(CFTimeInterval duration)78{79    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(presentAfterMinimumDuration_), duration);80}8182_MTL_INLINE void MTL::Drawable::presentAtTime(CFTimeInterval presentationTime)83{84    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(presentAtTime_), presentationTime);85}8687_MTL_INLINE CFTimeInterval MTL::Drawable::presentedTime() const88{89    return Object::sendMessage<CFTimeInterval>(this, _MTL_PRIVATE_SEL(presentedTime));90}91