2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.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.
|
|
|
|
****************************************************************************/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../RenderPipeline.h"
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
2020-09-22 16:32:17 +08:00
|
|
|
#include "tsl/robin_map.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#import <Metal/Metal.h>
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BACKEND_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup _metal
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and compile a new MTLRenderPipelineState object synchronously.
|
|
|
|
*/
|
|
|
|
class RenderPipelineMTL : public RenderPipeline
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @param mtlDevice The device for which MTLRenderPipelineState object was created.
|
|
|
|
* @param descriptor Specify the render pipeline description.
|
|
|
|
*/
|
|
|
|
RenderPipelineMTL(id<MTLDevice> mtlDevice);
|
|
|
|
~RenderPipelineMTL();
|
2020-09-22 16:32:17 +08:00
|
|
|
virtual void update(const RenderTarget* renderTarget, const PipelineDescriptor&) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* Get a MTLRenderPipelineState object.
|
|
|
|
* @return A MTLRenderPipelineState object.
|
|
|
|
*/
|
|
|
|
inline id<MTLRenderPipelineState> getMTLRenderPipelineState() const { return _mtlRenderPipelineState; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
private:
|
|
|
|
void setVertexLayout(MTLRenderPipelineDescriptor*, const PipelineDescriptor&);
|
|
|
|
void setBlendState(MTLRenderPipelineColorAttachmentDescriptor*, const BlendDescriptor&);
|
|
|
|
void setShaderModules(const PipelineDescriptor&);
|
2020-09-21 22:10:50 +08:00
|
|
|
void setBlendStateAndFormat(const BlendDescriptor&);
|
2021-12-25 10:04:45 +08:00
|
|
|
void chooseAttachmentFormat(const RenderTarget* renderTarget,
|
|
|
|
PixelFormat colorAttachmentsFormat[MAX_COLOR_ATTCHMENT],
|
|
|
|
PixelFormat&,
|
|
|
|
PixelFormat&);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
id<MTLRenderPipelineState> _mtlRenderPipelineState = nil;
|
2021-12-25 10:04:45 +08:00
|
|
|
id<MTLDevice> _mtlDevice = nil;
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
MTLRenderPipelineDescriptor* _mtlRenderPipelineDescriptor = nil;
|
2021-12-25 10:04:45 +08:00
|
|
|
PixelFormat _colorAttachmentsFormat[MAX_COLOR_ATTCHMENT] = {PixelFormat::NONE};
|
|
|
|
PixelFormat _depthAttachmentFormat = PixelFormat::NONE;
|
|
|
|
PixelFormat _stencilAttachmentFormat = PixelFormat::NONE;
|
|
|
|
|
2020-09-22 16:32:17 +08:00
|
|
|
tsl::robin_map<uint32_t, id<MTLRenderPipelineState>> _mtlStateCache;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// end of _metal group
|
|
|
|
/// @}
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BACKEND_END
|