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%
13.7 KB · 338 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTLRasterizationRate.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 "MTLDevice.hpp"26#include "MTLHeaderBridge.hpp"27#include "MTLPrivate.hpp"28#include "MTLTypes.hpp"2930namespace MTL31{32class Buffer;33class Device;34class RasterizationRateLayerArray;35class RasterizationRateLayerDescriptor;36class RasterizationRateMapDescriptor;37class RasterizationRateSampleArray;3839class RasterizationRateSampleArray : public NS::Referencing<RasterizationRateSampleArray>40{41public:42    static RasterizationRateSampleArray* alloc();4344    RasterizationRateSampleArray*        init();4546    NS::Number*                          object(NS::UInteger index);47    void                                 setObject(const NS::Number* value, NS::UInteger index);48};49class RasterizationRateLayerDescriptor : public NS::Copying<RasterizationRateLayerDescriptor>50{51public:52    static RasterizationRateLayerDescriptor* alloc();5354    RasterizationRateSampleArray*            horizontal() const;55    float*                                   horizontalSampleStorage() const;5657    RasterizationRateLayerDescriptor*        init();58    RasterizationRateLayerDescriptor*        init(MTL::Size sampleCount);59    RasterizationRateLayerDescriptor*        init(MTL::Size sampleCount, const float* horizontal, const float* vertical);6061    Size                                     maxSampleCount() const;62    Size                                     sampleCount() const;63    void                                     setSampleCount(MTL::Size sampleCount);6465    RasterizationRateSampleArray*            vertical() const;66    float*                                   verticalSampleStorage() const;67};68class RasterizationRateLayerArray : public NS::Referencing<RasterizationRateLayerArray>69{70public:71    static RasterizationRateLayerArray* alloc();7273    RasterizationRateLayerArray*        init();7475    RasterizationRateLayerDescriptor*   object(NS::UInteger layerIndex);76    void                                setObject(const MTL::RasterizationRateLayerDescriptor* layer, NS::UInteger layerIndex);77};78class RasterizationRateMapDescriptor : public NS::Copying<RasterizationRateMapDescriptor>79{80public:81    static RasterizationRateMapDescriptor* alloc();8283    RasterizationRateMapDescriptor*        init();8485    NS::String*                            label() const;8687    RasterizationRateLayerDescriptor*      layer(NS::UInteger layerIndex);88    NS::UInteger                           layerCount() const;8990    RasterizationRateLayerArray*           layers() const;9192    static RasterizationRateMapDescriptor* rasterizationRateMapDescriptor(MTL::Size screenSize);93    static RasterizationRateMapDescriptor* rasterizationRateMapDescriptor(MTL::Size screenSize, const MTL::RasterizationRateLayerDescriptor* layer);94    static RasterizationRateMapDescriptor* rasterizationRateMapDescriptor(MTL::Size screenSize, NS::UInteger layerCount, const MTL::RasterizationRateLayerDescriptor* const* layers);9596    Size                                   screenSize() const;9798    void                                   setLabel(const NS::String* label);99100    void                                   setLayer(const MTL::RasterizationRateLayerDescriptor* layer, NS::UInteger layerIndex);101102    void                                   setScreenSize(MTL::Size screenSize);103};104class RasterizationRateMap : public NS::Referencing<RasterizationRateMap>105{106public:107    void         copyParameterDataToBuffer(const MTL::Buffer* buffer, NS::UInteger offset);108109    Device*      device() const;110111    NS::String*  label() const;112113    NS::UInteger layerCount() const;114115    Coordinate2D mapPhysicalToScreenCoordinates(MTL::Coordinate2D physicalCoordinates, NS::UInteger layerIndex);116117    Coordinate2D mapScreenToPhysicalCoordinates(MTL::Coordinate2D screenCoordinates, NS::UInteger layerIndex);118119    SizeAndAlign parameterBufferSizeAndAlign() const;120121    Size         physicalGranularity() const;122123    Size         physicalSize(NS::UInteger layerIndex);124125    Size         screenSize() const;126};127128}129_MTL_INLINE MTL::RasterizationRateSampleArray* MTL::RasterizationRateSampleArray::alloc()130{131    return NS::Object::alloc<MTL::RasterizationRateSampleArray>(_MTL_PRIVATE_CLS(MTLRasterizationRateSampleArray));132}133134_MTL_INLINE MTL::RasterizationRateSampleArray* MTL::RasterizationRateSampleArray::init()135{136    return NS::Object::init<MTL::RasterizationRateSampleArray>();137}138139_MTL_INLINE NS::Number* MTL::RasterizationRateSampleArray::object(NS::UInteger index)140{141    return Object::sendMessage<NS::Number*>(this, _MTL_PRIVATE_SEL(objectAtIndexedSubscript_), index);142}143144_MTL_INLINE void MTL::RasterizationRateSampleArray::setObject(const NS::Number* value, NS::UInteger index)145{146    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setObject_atIndexedSubscript_), value, index);147}148149_MTL_INLINE MTL::RasterizationRateLayerDescriptor* MTL::RasterizationRateLayerDescriptor::alloc()150{151    return NS::Object::alloc<MTL::RasterizationRateLayerDescriptor>(_MTL_PRIVATE_CLS(MTLRasterizationRateLayerDescriptor));152}153154_MTL_INLINE MTL::RasterizationRateSampleArray* MTL::RasterizationRateLayerDescriptor::horizontal() const155{156    return Object::sendMessage<MTL::RasterizationRateSampleArray*>(this, _MTL_PRIVATE_SEL(horizontal));157}158159_MTL_INLINE float* MTL::RasterizationRateLayerDescriptor::horizontalSampleStorage() const160{161    return Object::sendMessage<float*>(this, _MTL_PRIVATE_SEL(horizontalSampleStorage));162}163164_MTL_INLINE MTL::RasterizationRateLayerDescriptor* MTL::RasterizationRateLayerDescriptor::init()165{166    return NS::Object::init<MTL::RasterizationRateLayerDescriptor>();167}168169_MTL_INLINE MTL::RasterizationRateLayerDescriptor* MTL::RasterizationRateLayerDescriptor::init(MTL::Size sampleCount)170{171    return Object::sendMessage<MTL::RasterizationRateLayerDescriptor*>(this, _MTL_PRIVATE_SEL(initWithSampleCount_), sampleCount);172}173174_MTL_INLINE MTL::RasterizationRateLayerDescriptor* MTL::RasterizationRateLayerDescriptor::init(MTL::Size sampleCount, const float* horizontal, const float* vertical)175{176    return Object::sendMessage<MTL::RasterizationRateLayerDescriptor*>(this, _MTL_PRIVATE_SEL(initWithSampleCount_horizontal_vertical_), sampleCount, horizontal, vertical);177}178179_MTL_INLINE MTL::Size MTL::RasterizationRateLayerDescriptor::maxSampleCount() const180{181    return Object::sendMessage<MTL::Size>(this, _MTL_PRIVATE_SEL(maxSampleCount));182}183184_MTL_INLINE MTL::Size MTL::RasterizationRateLayerDescriptor::sampleCount() const185{186    return Object::sendMessage<MTL::Size>(this, _MTL_PRIVATE_SEL(sampleCount));187}188189_MTL_INLINE void MTL::RasterizationRateLayerDescriptor::setSampleCount(MTL::Size sampleCount)190{191    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSampleCount_), sampleCount);192}193194_MTL_INLINE MTL::RasterizationRateSampleArray* MTL::RasterizationRateLayerDescriptor::vertical() const195{196    return Object::sendMessage<MTL::RasterizationRateSampleArray*>(this, _MTL_PRIVATE_SEL(vertical));197}198199_MTL_INLINE float* MTL::RasterizationRateLayerDescriptor::verticalSampleStorage() const200{201    return Object::sendMessage<float*>(this, _MTL_PRIVATE_SEL(verticalSampleStorage));202}203204_MTL_INLINE MTL::RasterizationRateLayerArray* MTL::RasterizationRateLayerArray::alloc()205{206    return NS::Object::alloc<MTL::RasterizationRateLayerArray>(_MTL_PRIVATE_CLS(MTLRasterizationRateLayerArray));207}208209_MTL_INLINE MTL::RasterizationRateLayerArray* MTL::RasterizationRateLayerArray::init()210{211    return NS::Object::init<MTL::RasterizationRateLayerArray>();212}213214_MTL_INLINE MTL::RasterizationRateLayerDescriptor* MTL::RasterizationRateLayerArray::object(NS::UInteger layerIndex)215{216    return Object::sendMessage<MTL::RasterizationRateLayerDescriptor*>(this, _MTL_PRIVATE_SEL(objectAtIndexedSubscript_), layerIndex);217}218219_MTL_INLINE void MTL::RasterizationRateLayerArray::setObject(const MTL::RasterizationRateLayerDescriptor* layer, NS::UInteger layerIndex)220{221    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setObject_atIndexedSubscript_), layer, layerIndex);222}223224_MTL_INLINE MTL::RasterizationRateMapDescriptor* MTL::RasterizationRateMapDescriptor::alloc()225{226    return NS::Object::alloc<MTL::RasterizationRateMapDescriptor>(_MTL_PRIVATE_CLS(MTLRasterizationRateMapDescriptor));227}228229_MTL_INLINE MTL::RasterizationRateMapDescriptor* MTL::RasterizationRateMapDescriptor::init()230{231    return NS::Object::init<MTL::RasterizationRateMapDescriptor>();232}233234_MTL_INLINE NS::String* MTL::RasterizationRateMapDescriptor::label() const235{236    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));237}238239_MTL_INLINE MTL::RasterizationRateLayerDescriptor* MTL::RasterizationRateMapDescriptor::layer(NS::UInteger layerIndex)240{241    return Object::sendMessage<MTL::RasterizationRateLayerDescriptor*>(this, _MTL_PRIVATE_SEL(layerAtIndex_), layerIndex);242}243244_MTL_INLINE NS::UInteger MTL::RasterizationRateMapDescriptor::layerCount() const245{246    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(layerCount));247}248249_MTL_INLINE MTL::RasterizationRateLayerArray* MTL::RasterizationRateMapDescriptor::layers() const250{251    return Object::sendMessage<MTL::RasterizationRateLayerArray*>(this, _MTL_PRIVATE_SEL(layers));252}253254_MTL_INLINE MTL::RasterizationRateMapDescriptor* MTL::RasterizationRateMapDescriptor::rasterizationRateMapDescriptor(MTL::Size screenSize)255{256    return Object::sendMessage<MTL::RasterizationRateMapDescriptor*>(_MTL_PRIVATE_CLS(MTLRasterizationRateMapDescriptor), _MTL_PRIVATE_SEL(rasterizationRateMapDescriptorWithScreenSize_), screenSize);257}258259_MTL_INLINE MTL::RasterizationRateMapDescriptor* MTL::RasterizationRateMapDescriptor::rasterizationRateMapDescriptor(MTL::Size screenSize, const MTL::RasterizationRateLayerDescriptor* layer)260{261    return Object::sendMessage<MTL::RasterizationRateMapDescriptor*>(_MTL_PRIVATE_CLS(MTLRasterizationRateMapDescriptor), _MTL_PRIVATE_SEL(rasterizationRateMapDescriptorWithScreenSize_layer_), screenSize, layer);262}263264_MTL_INLINE MTL::RasterizationRateMapDescriptor* MTL::RasterizationRateMapDescriptor::rasterizationRateMapDescriptor(MTL::Size screenSize, NS::UInteger layerCount, const MTL::RasterizationRateLayerDescriptor* const* layers)265{266    return Object::sendMessage<MTL::RasterizationRateMapDescriptor*>(_MTL_PRIVATE_CLS(MTLRasterizationRateMapDescriptor), _MTL_PRIVATE_SEL(rasterizationRateMapDescriptorWithScreenSize_layerCount_layers_), screenSize, layerCount, layers);267}268269_MTL_INLINE MTL::Size MTL::RasterizationRateMapDescriptor::screenSize() const270{271    return Object::sendMessage<MTL::Size>(this, _MTL_PRIVATE_SEL(screenSize));272}273274_MTL_INLINE void MTL::RasterizationRateMapDescriptor::setLabel(const NS::String* label)275{276    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);277}278279_MTL_INLINE void MTL::RasterizationRateMapDescriptor::setLayer(const MTL::RasterizationRateLayerDescriptor* layer, NS::UInteger layerIndex)280{281    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLayer_atIndex_), layer, layerIndex);282}283284_MTL_INLINE void MTL::RasterizationRateMapDescriptor::setScreenSize(MTL::Size screenSize)285{286    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setScreenSize_), screenSize);287}288289_MTL_INLINE void MTL::RasterizationRateMap::copyParameterDataToBuffer(const MTL::Buffer* buffer, NS::UInteger offset)290{291    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(copyParameterDataToBuffer_offset_), buffer, offset);292}293294_MTL_INLINE MTL::Device* MTL::RasterizationRateMap::device() const295{296    return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));297}298299_MTL_INLINE NS::String* MTL::RasterizationRateMap::label() const300{301    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));302}303304_MTL_INLINE NS::UInteger MTL::RasterizationRateMap::layerCount() const305{306    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(layerCount));307}308309_MTL_INLINE MTL::Coordinate2D MTL::RasterizationRateMap::mapPhysicalToScreenCoordinates(MTL::Coordinate2D physicalCoordinates, NS::UInteger layerIndex)310{311    return Object::sendMessage<MTL::Coordinate2D>(this, _MTL_PRIVATE_SEL(mapPhysicalToScreenCoordinates_forLayer_), physicalCoordinates, layerIndex);312}313314_MTL_INLINE MTL::Coordinate2D MTL::RasterizationRateMap::mapScreenToPhysicalCoordinates(MTL::Coordinate2D screenCoordinates, NS::UInteger layerIndex)315{316    return Object::sendMessage<MTL::Coordinate2D>(this, _MTL_PRIVATE_SEL(mapScreenToPhysicalCoordinates_forLayer_), screenCoordinates, layerIndex);317}318319_MTL_INLINE MTL::SizeAndAlign MTL::RasterizationRateMap::parameterBufferSizeAndAlign() const320{321    return Object::sendMessage<MTL::SizeAndAlign>(this, _MTL_PRIVATE_SEL(parameterBufferSizeAndAlign));322}323324_MTL_INLINE MTL::Size MTL::RasterizationRateMap::physicalGranularity() const325{326    return Object::sendMessage<MTL::Size>(this, _MTL_PRIVATE_SEL(physicalGranularity));327}328329_MTL_INLINE MTL::Size MTL::RasterizationRateMap::physicalSize(NS::UInteger layerIndex)330{331    return Object::sendMessage<MTL::Size>(this, _MTL_PRIVATE_SEL(physicalSizeForLayer_), layerIndex);332}333334_MTL_INLINE MTL::Size MTL::RasterizationRateMap::screenSize() const335{336    return Object::sendMessage<MTL::Size>(this, _MTL_PRIVATE_SEL(screenSize));337}338