metal: initial support

This commit is contained in:
Samuliak 2024-07-02 08:28:41 +02:00
parent 29d9ed7224
commit f0547d1a71
167 changed files with 28839 additions and 1271 deletions

View file

@ -0,0 +1,41 @@
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// QuartzCore/CADefines.hpp
//
// Copyright 2020-2023 Apple Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "../Foundation/NSDefines.hpp"
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#define _CA_EXPORT _NS_EXPORT
#define _CA_EXTERN _NS_EXTERN
#define _CA_INLINE _NS_INLINE
#define _CA_PACKED _NS_PACKED
#define _CA_CONST(type, name) _NS_CONST(type, name)
#define _CA_ENUM(type, name) _NS_ENUM(type, name)
#define _CA_OPTIONS(type, name) _NS_OPTIONS(type, name)
#define _CA_VALIDATE_SIZE(ns, name) _NS_VALIDATE_SIZE(ns, name)
#define _CA_VALIDATE_ENUM(ns, name) _NS_VALIDATE_ENUM(ns, name)
//-------------------------------------------------------------------------------------------------------------------------------------------------------------

View file

@ -0,0 +1,57 @@
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// QuartzCore/CAMetalDrawable.hpp
//
// Copyright 2020-2023 Apple Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "../Metal/MTLDrawable.hpp"
#include "../Metal/MTLTexture.hpp"
#include "CADefines.hpp"
#include "CAPrivate.hpp"
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
namespace CA
{
class MetalDrawable : public NS::Referencing<MetalDrawable, MTL::Drawable>
{
public:
class MetalLayer* layer() const;
MTL::Texture* texture() const;
};
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE CA::MetalLayer* CA::MetalDrawable::layer() const
{
return Object::sendMessage<MetalLayer*>(this, _CA_PRIVATE_SEL(layer));
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE MTL::Texture* CA::MetalDrawable::texture() const
{
return Object::sendMessage<MTL::Texture*>(this, _CA_PRIVATE_SEL(texture));
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------

View file

@ -0,0 +1,131 @@
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// QuartzCore/CAMetalDrawable.hpp
//
// Copyright 2020-2023 Apple Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "../Metal/MTLPixelFormat.hpp"
#include "../Metal/MTLTexture.hpp"
#include <CoreGraphics/CGGeometry.h>
#include "CADefines.hpp"
#include "CAMetalDrawable.hpp"
#include "CAPrivate.hpp"
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
namespace CA
{
class MetalLayer : public NS::Referencing<MetalLayer>
{
public:
static class MetalLayer* layer();
MTL::Device* device() const;
void setDevice(MTL::Device* device);
MTL::PixelFormat pixelFormat() const;
void setPixelFormat(MTL::PixelFormat pixelFormat);
bool framebufferOnly() const;
void setFramebufferOnly(bool framebufferOnly);
CGSize drawableSize() const;
void setDrawableSize(CGSize drawableSize);
class MetalDrawable* nextDrawable();
};
} // namespace CA
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE CA::MetalLayer* CA::MetalLayer::layer()
{
return Object::sendMessage<CA::MetalLayer*>(_CA_PRIVATE_CLS(CAMetalLayer), _CA_PRIVATE_SEL(layer));
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE MTL::Device* CA::MetalLayer::device() const
{
return Object::sendMessage<MTL::Device*>(this, _CA_PRIVATE_SEL(device));
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE void CA::MetalLayer::setDevice(MTL::Device* device)
{
return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setDevice_), device);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE MTL::PixelFormat CA::MetalLayer::pixelFormat() const
{
return Object::sendMessage<MTL::PixelFormat>(this,
_CA_PRIVATE_SEL(pixelFormat));
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE void CA::MetalLayer::setPixelFormat(MTL::PixelFormat pixelFormat)
{
return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setPixelFormat_),
pixelFormat);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE bool CA::MetalLayer::framebufferOnly() const
{
return Object::sendMessage<bool>(this, _CA_PRIVATE_SEL(framebufferOnly));
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE void CA::MetalLayer::setFramebufferOnly(bool framebufferOnly)
{
return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setFramebufferOnly_),
framebufferOnly);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE CGSize CA::MetalLayer::drawableSize() const
{
return Object::sendMessage<CGSize>(this, _CA_PRIVATE_SEL(drawableSize));
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE void CA::MetalLayer::setDrawableSize(CGSize drawableSize)
{
return Object::sendMessage<void>(this, _CA_PRIVATE_SEL(setDrawableSize_),
drawableSize);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
_CA_INLINE CA::MetalDrawable* CA::MetalLayer::nextDrawable()
{
return Object::sendMessage<MetalDrawable*>(this,
_CA_PRIVATE_SEL(nextDrawable));
}

View file

@ -0,0 +1,132 @@
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// QuartzCore/CAPrivate.hpp
//
// Copyright 2020-2023 Apple Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "CADefines.hpp"
#include <objc/runtime.h>
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#define _CA_PRIVATE_CLS(symbol) (Private::Class::s_k##symbol)
#define _CA_PRIVATE_SEL(accessor) (Private::Selector::s_k##accessor)
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#if defined(CA_PRIVATE_IMPLEMENTATION)
#ifdef METALCPP_SYMBOL_VISIBILITY_HIDDEN
#define _CA_PRIVATE_VISIBILITY __attribute__((visibility("hidden")))
#else
#define _CA_PRIVATE_VISIBILITY __attribute__((visibility("default")))
#endif // METALCPP_SYMBOL_VISIBILITY_HIDDEN
#define _CA_PRIVATE_IMPORT __attribute__((weak_import))
#ifdef __OBJC__
#define _CA_PRIVATE_OBJC_LOOKUP_CLASS(symbol) ((__bridge void*)objc_lookUpClass(#symbol))
#define _CA_PRIVATE_OBJC_GET_PROTOCOL(symbol) ((__bridge void*)objc_getProtocol(#symbol))
#else
#define _CA_PRIVATE_OBJC_LOOKUP_CLASS(symbol) objc_lookUpClass(#symbol)
#define _CA_PRIVATE_OBJC_GET_PROTOCOL(symbol) objc_getProtocol(#symbol)
#endif // __OBJC__
#define _CA_PRIVATE_DEF_CLS(symbol) void* s_k##symbol _CA_PRIVATE_VISIBILITY = _CA_PRIVATE_OBJC_LOOKUP_CLASS(symbol)
#define _CA_PRIVATE_DEF_PRO(symbol) void* s_k##symbol _CA_PRIVATE_VISIBILITY = _CA_PRIVATE_OBJC_GET_PROTOCOL(symbol)
#define _CA_PRIVATE_DEF_SEL(accessor, symbol) SEL s_k##accessor _CA_PRIVATE_VISIBILITY = sel_registerName(symbol)
#define _CA_PRIVATE_DEF_STR(type, symbol) \
_CA_EXTERN type const CA##symbol _CA_PRIVATE_IMPORT; \
type const CA::symbol = (nullptr != &CA##symbol) ? CA##symbol : nullptr
#else
#define _CA_PRIVATE_DEF_CLS(symbol) extern void* s_k##symbol
#define _CA_PRIVATE_DEF_PRO(symbol) extern void* s_k##symbol
#define _CA_PRIVATE_DEF_SEL(accessor, symbol) extern SEL s_k##accessor
#define _CA_PRIVATE_DEF_STR(type, symbol) extern type const CA::symbol
#endif // CA_PRIVATE_IMPLEMENTATION
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
namespace CA
{
namespace Private
{
namespace Class
{
_CA_PRIVATE_DEF_CLS(CAMetalLayer);
} // Class
} // Private
} // CA
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
namespace CA
{
namespace Private
{
namespace Protocol
{
_CA_PRIVATE_DEF_PRO(CAMetalDrawable);
} // Protocol
} // Private
} // CA
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
namespace CA
{
namespace Private
{
namespace Selector
{
_CA_PRIVATE_DEF_SEL(device,
"device");
_CA_PRIVATE_DEF_SEL(drawableSize,
"drawableSize");
_CA_PRIVATE_DEF_SEL(framebufferOnly,
"framebufferOnly");
_CA_PRIVATE_DEF_SEL(layer,
"layer");
_CA_PRIVATE_DEF_SEL(nextDrawable,
"nextDrawable");
_CA_PRIVATE_DEF_SEL(pixelFormat,
"pixelFormat");
_CA_PRIVATE_DEF_SEL(setDevice_,
"setDevice:");
_CA_PRIVATE_DEF_SEL(setDrawableSize_,
"setDrawableSize:");
_CA_PRIVATE_DEF_SEL(setFramebufferOnly_,
"setFramebufferOnly:");
_CA_PRIVATE_DEF_SEL(setPixelFormat_,
"setPixelFormat:");
_CA_PRIVATE_DEF_SEL(texture,
"texture");
} // Class
} // Private
} // CA
//-------------------------------------------------------------------------------------------------------------------------------------------------------------

View file

@ -0,0 +1,28 @@
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
//
// QuartzCore/QuartzCore.hpp
//
// Copyright 2020-2023 Apple Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "CAMetalDrawable.hpp"
#include "CAMetalLayer.hpp"
//-------------------------------------------------------------------------------------------------------------------------------------------------------------