| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <Metal/Metal.h> |
| 7 |
|
| 8 |
#include "VideoBackends/Metal/MRCHelpers.h" |
| 9 |
#include "VideoBackends/Metal/MTLObjectCache.h" |
| 10 |
#include "VideoBackends/Metal/MTLShader.h" |
| 11 |
|
| 12 |
#include "VideoCommon/AbstractPipeline.h" |
| 13 |
#include "VideoCommon/AbstractShader.h" |
| 14 |
|
| 15 |
namespace Metal |
| 16 |
{ |
| 17 |
struct PipelineReflection |
| 18 |
{ |
| 19 |
u32 textures = 0; |
| 20 |
u32 samplers = 0; |
| 21 |
u32 vertex_buffers = 0; |
| 22 |
u32 fragment_buffers = 0; |
| 23 |
PipelineReflection() = default; |
| 24 |
explicit PipelineReflection(MTLRenderPipelineReflection* reflection); |
| 25 |
}; |
| 26 |
|
| 27 |
class Pipeline final : public AbstractPipeline |
| 28 |
{ |
| 29 |
public: |
| 30 |
explicit Pipeline(const AbstractPipelineConfig& config, |
| 31 |
MRCOwned<id<MTLRenderPipelineState>> pipeline, |
| 32 |
const PipelineReflection& reflection, MTLPrimitiveType prim, MTLCullMode cull, |
| 33 |
DepthState depth, AbstractPipelineUsage usage); |
| 34 |
|
| 35 |
id<MTLRenderPipelineState> Get() const { return m_pipeline; } |
| 36 |
MTLPrimitiveType Prim() const { return m_prim; } |
| 37 |
MTLCullMode Cull() const { return m_cull; } |
| 38 |
DepthStencilSelector DepthStencil() const { return m_depth_stencil; } |
| 39 |
AbstractPipelineUsage Usage() const { return m_usage; } |
| 40 |
u32 GetTextures() const { return m_reflection.textures; } |
| 41 |
u32 GetSamplers() const { return m_reflection.samplers; } |
| 42 |
u32 GetVertexBuffers() const { return m_reflection.vertex_buffers; } |
| 43 |
u32 GetFragmentBuffers() const { return m_reflection.fragment_buffers; } |
| 44 |
bool UsesVertexBuffer(u32 index) const { return m_reflection.vertex_buffers & (1 << index); } |
| 45 |
bool UsesFragmentBuffer(u32 index) const { return m_reflection.fragment_buffers & (1 << index); } |
| 46 |
|
| 47 |
private: |
| 48 |
MRCOwned<id<MTLRenderPipelineState>> m_pipeline; |
| 49 |
MTLPrimitiveType m_prim; |
| 50 |
MTLCullMode m_cull; |
| 51 |
DepthStencilSelector m_depth_stencil; |
| 52 |
AbstractPipelineUsage m_usage; |
| 53 |
PipelineReflection m_reflection; |
| 54 |
}; |
| 55 |
|
| 56 |
class ComputePipeline : public Shader |
| 57 |
{ |
| 58 |
public: |
| 59 |
explicit ComputePipeline(ShaderStage stage, MTLComputePipelineReflection* reflection, |
| 60 |
std::string msl, MRCOwned<id<MTLFunction>> shader, |
| 61 |
MRCOwned<id<MTLComputePipelineState>> pipeline); |
| 62 |
|
| 63 |
id<MTLComputePipelineState> GetComputePipeline() const { return m_compute_pipeline; } |
| 64 |
u32 GetTextures() const { return m_textures; } |
| 65 |
u32 GetSamplers() const { return m_samplers; } |
| 66 |
bool UsesBuffer(u32 index) const { return m_buffers & (1 << index); } |
| 67 |
|
| 68 |
private: |
| 69 |
MRCOwned<id<MTLComputePipelineState>> m_compute_pipeline; |
| 70 |
u32 m_textures = 0; |
| 71 |
u32 m_samplers = 0; |
| 72 |
u32 m_buffers = 0; |
| 73 |
}; |
| 74 |
} |