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%
10.0 KB · 235 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// QuartzCore/CAMetalDrawable.hpp4//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 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//-------------------------------------------------------------------------------------------------------------------------------------------------------------2425#include "../Metal/MTLPixelFormat.hpp"26#include "../Metal/MTLTexture.hpp"27#include "../Metal/MTLResidencySet.hpp"28#include "../Foundation/NSTypes.hpp"29#include <CoreGraphics/CGGeometry.h>30#include <CoreGraphics/CGColorSpace.h>3132#include "CADefines.hpp"33#include "CAMetalDrawable.hpp"34#include "CAPrivate.hpp"3536//-------------------------------------------------------------------------------------------------------------------------------------------------------------3738namespace CA39{4041class MetalLayer : public NS::Referencing<MetalLayer>42{43public:44    static class MetalLayer* layer();4546    MTL::Device*             device() const;47    void                     setDevice(MTL::Device* device);4849    MTL::PixelFormat         pixelFormat() const;50    void                     setPixelFormat(MTL::PixelFormat pixelFormat);5152    bool                     framebufferOnly() const;53    void                     setFramebufferOnly(bool framebufferOnly);5455    CGSize                   drawableSize() const;56    void                     setDrawableSize(CGSize drawableSize);5758    class MetalDrawable*     nextDrawable();5960    NS::UInteger             maximumDrawableCount() const;61    void                     setMaximumDrawableCount(NS::UInteger maximumDrawableCount);6263    bool                     displaySyncEnabled() const;64    void                     setDisplaySyncEnabled(bool displaySyncEnabled);6566    CGColorSpaceRef          colorspace() const;67    void                     setColorspace(CGColorSpaceRef colorspace);6869    bool                     allowsNextDrawableTimeout() const;70    void                     setAllowsNextDrawableTimeout(bool allowsNextDrawableTimeout);7172    bool                     wantsExtendedDynamicRangeContent() const;73    void                     setWantsExtendedDynamicRangeContent(bool wantsExtendedDynamicRangeContent);7475    MTL::ResidencySet*       residencySet() const;76};77} // namespace CA7879//-------------------------------------------------------------------------------------------------------------------------------------------------------------80_CA_INLINE CA::MetalLayer* CA::MetalLayer::layer()81{82    return Object::sendMessage<CA::MetalLayer*>(_CA_PRIVATE_CLS(CAMetalLayer), _CA_PRIVATE_SEL(layer));83}84//-------------------------------------------------------------------------------------------------------------------------------------------------------------8586//-------------------------------------------------------------------------------------------------------------------------------------------------------------8788_CA_INLINE MTL::Device* CA::MetalLayer::device() const89{90    return Object::sendMessage<MTL::Device*>(this, _CA_PRIVATE_SEL(device));91}92//-------------------------------------------------------------------------------------------------------------------------------------------------------------9394_CA_INLINE void CA::MetalLayer::setDevice(MTL::Device* device)95{96    return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setDevice_), device);97}9899//-------------------------------------------------------------------------------------------------------------------------------------------------------------100101_CA_INLINE MTL::PixelFormat CA::MetalLayer::pixelFormat() const102{103    return Object::sendMessage<MTL::PixelFormat>(this,104        _CA_PRIVATE_SEL(pixelFormat));105}106107//-------------------------------------------------------------------------------------------------------------------------------------------------------------108109_CA_INLINE void CA::MetalLayer::setPixelFormat(MTL::PixelFormat pixelFormat)110{111    return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setPixelFormat_),112        pixelFormat);113}114115//-------------------------------------------------------------------------------------------------------------------------------------------------------------116117_CA_INLINE bool CA::MetalLayer::framebufferOnly() const118{119    return Object::sendMessage<bool>(this, _CA_PRIVATE_SEL(framebufferOnly));120}121122//-------------------------------------------------------------------------------------------------------------------------------------------------------------123124_CA_INLINE void CA::MetalLayer::setFramebufferOnly(bool framebufferOnly)125{126    return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setFramebufferOnly_),127        framebufferOnly);128}129130//-------------------------------------------------------------------------------------------------------------------------------------------------------------131132_CA_INLINE CGSize CA::MetalLayer::drawableSize() const133{134    return Object::sendMessage<CGSize>(this, _CA_PRIVATE_SEL(drawableSize));135}136137//-------------------------------------------------------------------------------------------------------------------------------------------------------------138139_CA_INLINE void CA::MetalLayer::setDrawableSize(CGSize drawableSize)140{141    return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setDrawableSize_),142        drawableSize);143}144145//-------------------------------------------------------------------------------------------------------------------------------------------------------------146147_CA_INLINE CA::MetalDrawable* CA::MetalLayer::nextDrawable()148{149    return Object::sendMessage<MetalDrawable*>(this,150        _CA_PRIVATE_SEL(nextDrawable));151}152153//-------------------------------------------------------------------------------------------------------------------------------------------------------------154155_CA_INLINE NS::UInteger CA::MetalLayer::maximumDrawableCount() const156{157    return Object::sendMessage<NS::UInteger>(this,158        _CA_PRIVATE_SEL(maximumDrawableCount));159}160161//-------------------------------------------------------------------------------------------------------------------------------------------------------------162163_CA_INLINE void CA::MetalLayer::setMaximumDrawableCount(NS::UInteger maximumDrawableCount)164{165    return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setMaximumDrawableCount_),166        maximumDrawableCount);167}168169//-------------------------------------------------------------------------------------------------------------------------------------------------------------170171_CA_INLINE bool CA::MetalLayer::displaySyncEnabled() const172{173    return Object::sendMessage<bool>(this, _CA_PRIVATE_SEL(displaySyncEnabled));174}175176//-------------------------------------------------------------------------------------------------------------------------------------------------------------177178_CA_INLINE void CA::MetalLayer::setDisplaySyncEnabled(bool displaySyncEnabled)179{180    return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setDisplaySyncEnabled_),181        displaySyncEnabled);182}183184//-------------------------------------------------------------------------------------------------------------------------------------------------------------185186_CA_INLINE CGColorSpaceRef CA::MetalLayer::colorspace() const187{188    return Object::sendMessage<CGColorSpaceRef>(this, _CA_PRIVATE_SEL(colorspace));189}190191//-------------------------------------------------------------------------------------------------------------------------------------------------------------192193_CA_INLINE void CA::MetalLayer::setColorspace(CGColorSpaceRef colorspace)194{195    return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setColorspace_),196        colorspace);197}198199//-------------------------------------------------------------------------------------------------------------------------------------------------------------200201_CA_INLINE bool CA::MetalLayer::allowsNextDrawableTimeout() const202{203    return Object::sendMessage<bool>(this, _CA_PRIVATE_SEL(allowsNextDrawableTimeout));204}205206//-------------------------------------------------------------------------------------------------------------------------------------------------------------207208_CA_INLINE void CA::MetalLayer::setAllowsNextDrawableTimeout(bool allowsNextDrawableTimeout)209{210    return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setAllowsNextDrawableTimeout_),211    allowsNextDrawableTimeout);212}213214//-------------------------------------------------------------------------------------------------------------------------------------------------------------215216_CA_INLINE bool CA::MetalLayer::wantsExtendedDynamicRangeContent() const217{218    return Object::sendMessage<bool>(this, _CA_PRIVATE_SEL(wantsExtendedDynamicRangeContent));219}220221//-------------------------------------------------------------------------------------------------------------------------------------------------------------222223_CA_INLINE void CA::MetalLayer::setWantsExtendedDynamicRangeContent(bool wantsExtendedDynamicRangeContent)224{225    return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setWantsExtendedDynamicRangeContent_),226        wantsExtendedDynamicRangeContent);227}228229//-------------------------------------------------------------------------------------------------------------------------------------------------------------230231_CA_INLINE MTL::ResidencySet* CA::MetalLayer::residencySet() const232{233    return Object::sendMessage<MTL::ResidencySet*>(this, _CA_PRIVATE_SEL(residencySet) );234}235