axmol/core/renderer/backend/metal/DriverMTL.mm

572 lines
20 KiB
Plaintext
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
2019-11-23 20:27:39 +08:00
2022-10-01 16:24:52 +08:00
https://axmolengine.github.io/
2019-11-23 20:27:39 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "DriverMTL.h"
#include "CommandBufferMTL.h"
#include "BufferMTL.h"
#include "RenderPipelineMTL.h"
#include "ShaderModuleMTL.h"
#include "DepthStencilStateMTL.h"
#include "TextureMTL.h"
#include "ProgramMTL.h"
#include "RenderTargetMTL.h"
#include "UtilsMTL.h"
#include "base/Macros.h"
#include "renderer/backend/ProgramManager.h"
NS_AX_BACKEND_BEGIN
2019-11-23 20:27:39 +08:00
inline FeatureSet operator--(FeatureSet& x)
{
return x = (FeatureSet)(std::underlying_type<FeatureSet>::type(x) - 1);
}
namespace
{
int getMaxVertexAttributes(FeatureSet featureSet)
{
int maxAttributes = 0;
switch (featureSet)
2019-11-23 20:27:39 +08:00
{
case FeatureSet::FeatureSet_iOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v2:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_macOS_ReadWriteTextureTier2:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_macOS_GPUFamily2_v1:
maxAttributes = 31;
break;
default:
break;
2019-11-23 20:27:39 +08:00
}
return maxAttributes;
}
int getMaxTextureEntries(FeatureSet featureSet)
{
int maxTextureEntries = 0;
switch (featureSet)
2019-11-23 20:27:39 +08:00
{
case FeatureSet::FeatureSet_iOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v2:
maxTextureEntries = 31;
break;
case FeatureSet::FeatureSet_macOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_macOS_ReadWriteTextureTier2:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_macOS_GPUFamily2_v1:
maxTextureEntries = 128;
break;
default:
break;
2019-11-23 20:27:39 +08:00
}
return maxTextureEntries;
}
int getMaxSamplerEntries(FeatureSet featureSet)
{
int maxSamplerEntries = 0;
switch (featureSet)
2019-11-23 20:27:39 +08:00
{
case FeatureSet::FeatureSet_iOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v2:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_macOS_ReadWriteTextureTier2:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_macOS_GPUFamily2_v1:
maxSamplerEntries = 16;
break;
default:
break;
2019-11-23 20:27:39 +08:00
}
return maxSamplerEntries;
}
int getMaxTextureWidthHeight(FeatureSet featureSet)
{
int maxTextureSize = 0;
switch (featureSet)
2019-11-23 20:27:39 +08:00
{
case FeatureSet::FeatureSet_iOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v1:
maxTextureSize = 4096;
break;
case FeatureSet::FeatureSet_iOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v5:
maxTextureSize = 8192;
break;
case FeatureSet::FeatureSet_iOS_GPUFamily3_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v2:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_macOS_ReadWriteTextureTier2:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_macOS_GPUFamily2_v1:
maxTextureSize = 16384;
break;
default:
break;
2019-11-23 20:27:39 +08:00
}
return maxTextureSize;
}
const char* featureSetToString(FeatureSet featureSet)
{
switch (featureSet)
2019-11-23 20:27:39 +08:00
{
case FeatureSet::FeatureSet_iOS_GPUFamily1_v1:
return "iOS_GPUFamily1_v1";
case FeatureSet::FeatureSet_iOS_GPUFamily2_v1:
return "iOS_GPUFamily2_v1";
case FeatureSet::FeatureSet_iOS_GPUFamily1_v2:
return "iOS_GPUFamily1_v2";
case FeatureSet::FeatureSet_iOS_GPUFamily2_v2:
return "iOS_GPUFamily2_v2";
case FeatureSet::FeatureSet_iOS_GPUFamily1_v3:
return "iOS_GPUFamily1_v3";
case FeatureSet::FeatureSet_iOS_GPUFamily2_v3:
return "iOS_GPUFamily2_v3";
case FeatureSet::FeatureSet_iOS_GPUFamily1_v4:
return "iOS_GPUFamily1_v4";
case FeatureSet::FeatureSet_iOS_GPUFamily2_v4:
return "iOS_GPUFamily2_v4";
case FeatureSet::FeatureSet_iOS_GPUFamily1_v5:
return "iOS_GPUFamily1_v5";
case FeatureSet::FeatureSet_iOS_GPUFamily2_v5:
return "iOS_GPUFamily2_v5";
case FeatureSet::FeatureSet_iOS_GPUFamily3_v1:
return "iOS_GPUFamily3_v1";
case FeatureSet::FeatureSet_iOS_GPUFamily3_v2:
return "iOS_GPUFamily3_v2";
case FeatureSet::FeatureSet_iOS_GPUFamily3_v3:
return "iOS_GPUFamily3_v3";
case FeatureSet::FeatureSet_iOS_GPUFamily4_v1:
return "iOS_GPUFamily4_v1";
case FeatureSet::FeatureSet_iOS_GPUFamily3_v4:
return "iOS_GPUFamily3_v4";
case FeatureSet::FeatureSet_iOS_GPUFamily4_v2:
return "iOS_GPUFamily4_v2";
case FeatureSet::FeatureSet_macOS_GPUFamily1_v1:
return "macOS_GPUFamily1_v1";
case FeatureSet::FeatureSet_macOS_GPUFamily1_v2:
return "macOS_GPUFamily1_v2";
case FeatureSet::FeatureSet_macOS_ReadWriteTextureTier2:
return "macOS_ReadWriteTextureTier2";
case FeatureSet::FeatureSet_macOS_GPUFamily1_v3:
return "macOS_GPUFamily1_v3";
case FeatureSet::FeatureSet_macOS_GPUFamily1_v4:
return "macOS_GPUFamily1_v4";
case FeatureSet::FeatureSet_macOS_GPUFamily2_v1:
return "macOS_GPUFamily2_v1";
default:
break;
2019-11-23 20:27:39 +08:00
}
return "";
}
bool supportPVRTC(FeatureSet featureSet)
{
switch (featureSet)
2019-11-23 20:27:39 +08:00
{
case FeatureSet::FeatureSet_iOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v2:
return true;
case FeatureSet::FeatureSet_macOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_macOS_ReadWriteTextureTier2:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_macOS_GPUFamily2_v1:
2019-11-23 20:27:39 +08:00
return false;
default:
break;
2019-11-23 20:27:39 +08:00
}
return false;
}
bool supportEACETC(FeatureSet featureSet)
{
switch (featureSet)
2019-11-23 20:27:39 +08:00
{
case FeatureSet::FeatureSet_iOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v2:
return true;
case FeatureSet::FeatureSet_macOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_macOS_ReadWriteTextureTier2:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_macOS_GPUFamily2_v1:
2019-11-23 20:27:39 +08:00
return false;
default:
break;
2019-11-23 20:27:39 +08:00
}
return false;
}
bool supportASTC(FeatureSet featureSet)
{
switch (featureSet)
2019-11-23 20:27:39 +08:00
{
case FeatureSet::FeatureSet_iOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v5:
return false;
case FeatureSet::FeatureSet_iOS_GPUFamily2_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v2:
return true;
case FeatureSet::FeatureSet_macOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_macOS_ReadWriteTextureTier2:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_macOS_GPUFamily2_v1:
2019-11-23 20:27:39 +08:00
return false;
default:
break;
2019-11-23 20:27:39 +08:00
}
return false;
}
bool supportS3TC(FeatureSet featureSet)
{
switch (featureSet)
2019-11-23 20:27:39 +08:00
{
case FeatureSet::FeatureSet_iOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily1_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily2_v5:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v2:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v3:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v1:
case FeatureSet::FeatureSet_iOS_GPUFamily3_v4:
case FeatureSet::FeatureSet_iOS_GPUFamily4_v2:
2019-11-23 20:27:39 +08:00
return false;
case FeatureSet::FeatureSet_macOS_GPUFamily1_v1:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v2:
case FeatureSet::FeatureSet_macOS_ReadWriteTextureTier2:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v3:
case FeatureSet::FeatureSet_macOS_GPUFamily1_v4:
case FeatureSet::FeatureSet_macOS_GPUFamily2_v1:
return true;
default:
break;
2019-11-23 20:27:39 +08:00
}
return false;
}
2019-11-23 20:27:39 +08:00
}
bool DriverMTL::_isDepth24Stencil8PixelFormatSupported = false;
CAMetalLayer* DriverMTL::_metalLayer = nil;
id<CAMetalDrawable> DriverMTL::_currentDrawable = nil;
DriverBase* DriverBase::getInstance()
{
if (!DriverBase::_instance)
DriverBase::_instance = new DriverMTL();
return DriverBase::_instance;
}
void DriverMTL::setCAMetalLayer(CAMetalLayer* metalLayer)
{
DriverMTL::_metalLayer = metalLayer;
}
id<CAMetalDrawable> DriverMTL::getCurrentDrawable()
{
if (!DriverMTL::_currentDrawable)
DriverMTL::_currentDrawable = [DriverMTL::_metalLayer nextDrawable];
return DriverMTL::_currentDrawable;
}
void DriverMTL::resetCurrentDrawable()
{
DriverMTL::_currentDrawable = nil;
}
DriverMTL::DriverMTL()
2019-11-23 20:27:39 +08:00
{
_mtlDevice = DriverMTL::_metalLayer.device;
_mtlCommandQueue = [_mtlDevice newCommandQueue];
_deviceName = [_mtlDevice.name UTF8String];
2022-07-16 10:43:05 +08:00
#if (AX_TARGET_PLATFORM == AX_PLATFORM_IOS)
2019-11-23 20:27:39 +08:00
const FeatureSet minRequiredFeatureSet = FeatureSet::FeatureSet_iOS_GPUFamily1_v1;
const FeatureSet maxKnownFeatureSet = FeatureSet::FeatureSet_iOS_GPUFamily4_v2;
2019-11-23 20:27:39 +08:00
#else
const FeatureSet minRequiredFeatureSet = FeatureSet::FeatureSet_macOS_GPUFamily1_v1;
const FeatureSet maxKnownFeatureSet = FeatureSet::FeatureSet_macOS_GPUFamily2_v1;
_isDepth24Stencil8PixelFormatSupported = [_mtlDevice isDepth24Stencil8PixelFormatSupported];
2019-11-23 20:27:39 +08:00
#endif
2019-11-23 20:27:39 +08:00
for (auto featureSet = maxKnownFeatureSet; featureSet >= minRequiredFeatureSet; --featureSet)
{
if ([_mtlDevice supportsFeatureSet:MTLFeatureSet(featureSet)])
2019-11-23 20:27:39 +08:00
{
_featureSet = featureSet;
break;
}
}
UtilsMTL::initGPUTextureFormats();
2019-11-23 20:27:39 +08:00
_maxAttributes = getMaxVertexAttributes(_featureSet);
2019-11-23 20:27:39 +08:00
_maxSamplesAllowed = getMaxSamplerEntries(_featureSet);
_maxTextureUnits = getMaxTextureEntries(_featureSet);
_maxTextureSize = getMaxTextureWidthHeight(_featureSet);
}
DriverMTL::~DriverMTL()
{
ProgramManager::destroyInstance();
}
CommandBuffer* DriverMTL::newCommandBuffer()
{
return new CommandBufferMTL(this);
}
Buffer* DriverMTL::newBuffer(std::size_t size, BufferType type, BufferUsage usage)
{
return new BufferMTL(_mtlDevice, size, type, usage);
}
TextureBackend* DriverMTL::newTexture(const TextureDescriptor& descriptor)
{
switch (descriptor.textureType)
{
case TextureType::TEXTURE_2D:
return new TextureMTL(_mtlDevice, descriptor);
case TextureType::TEXTURE_CUBE:
return new TextureCubeMTL(_mtlDevice, descriptor);
default:
AXASSERT(false, "invalidate texture type");
return nullptr;
}
}
RenderTarget* DriverMTL::newDefaultRenderTarget(TargetBufferFlags rtf)
{
auto rtGL = new RenderTargetMTL(true);
rtGL->setTargetFlags(rtf);
return rtGL;
}
RenderTarget* DriverMTL::newRenderTarget(TargetBufferFlags rtf,
TextureBackend* colorAttachment,
TextureBackend* depthAttachment,
TextureBackend* stencilAttachhment)
{
auto rtMTL = new RenderTargetMTL(false);
rtMTL->setTargetFlags(rtf);
RenderTarget::ColorAttachment colors{{colorAttachment, 0}};
rtMTL->setColorAttachment(colors);
rtMTL->setDepthAttachment(depthAttachment);
rtMTL->setStencilAttachment(stencilAttachhment);
return rtMTL;
}
ShaderModule* DriverMTL::newShaderModule(ShaderStage stage, std::string_view source)
{
return new ShaderModuleMTL(_mtlDevice, stage, source);
}
DepthStencilState* DriverMTL::newDepthStencilState()
{
return new DepthStencilStateMTL(_mtlDevice);
}
RenderPipeline* DriverMTL::newRenderPipeline()
{
return new RenderPipelineMTL(_mtlDevice);
}
Program* DriverMTL::newProgram(std::string_view vertexShader, std::string_view fragmentShader)
{
return new ProgramMTL(vertexShader, fragmentShader);
}
void DriverMTL::setFrameBufferOnly(bool frameBufferOnly)
{
[DriverMTL::_metalLayer setFramebufferOnly:frameBufferOnly];
2019-11-23 20:27:39 +08:00
}
const char* DriverMTL::getVendor() const
2019-11-23 20:27:39 +08:00
{
return "";
}
const char* DriverMTL::getRenderer() const
2019-11-23 20:27:39 +08:00
{
return _deviceName.c_str();
}
const char* DriverMTL::getVersion() const
2019-11-23 20:27:39 +08:00
{
return featureSetToString(_featureSet);
}
bool DriverMTL::checkForFeatureSupported(FeatureType feature)
2019-11-23 20:27:39 +08:00
{
bool featureSupported = false;
switch (feature)
{
case FeatureType::PVRTC:
featureSupported = supportPVRTC(_featureSet);
break;
case FeatureType::ETC1:
2020-09-01 00:03:49 +08:00
case FeatureType::ETC2:
2019-11-23 20:27:39 +08:00
featureSupported = supportEACETC(_featureSet);
break;
case FeatureType::S3TC:
featureSupported = supportS3TC(_featureSet);
break;
case FeatureType::IMG_FORMAT_BGRA8888:
featureSupported = true;
break;
case FeatureType::PACKED_DEPTH_STENCIL:
featureSupported = _isDepth24Stencil8PixelFormatSupported;
break;
case FeatureType::ASTC:
featureSupported = supportASTC(_featureSet);
break;
default:
break;
}
return featureSupported;
}
NS_AX_BACKEND_END