1 /* 2 * Copyright 2021 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef skgpu_MtlGraphicsPipeline_DEFINED 9 #define skgpu_MtlGraphicsPipeline_DEFINED 10 11 #include "experimental/graphite/src/GraphicsPipeline.h" 12 13 #include "include/ports/SkCFObject.h" 14 #include <memory> 15 16 #import <Metal/Metal.h> 17 18 namespace skgpu { 19 class GraphicsPipelineDesc; 20 } // namespace skgpu 21 22 namespace skgpu::mtl { 23 class Gpu; 24 25 class GraphicsPipeline final : public skgpu::GraphicsPipeline { 26 public: 27 inline static constexpr unsigned int kUniformBufferIndex = 0; 28 inline static constexpr unsigned int kVertexBufferIndex = 1; 29 inline static constexpr unsigned int kInstanceBufferIndex = 2; 30 31 static sk_sp<GraphicsPipeline> Make(const Gpu*, const skgpu::GraphicsPipelineDesc&); ~GraphicsPipeline()32 ~GraphicsPipeline() override {} 33 mtlPipelineState()34 id<MTLRenderPipelineState> mtlPipelineState() const { return fPipelineState.get(); } vertexStride()35 size_t vertexStride() const { return fVertexStride; } instanceStride()36 size_t instanceStride() const { return fInstanceStride; } 37 38 private: GraphicsPipeline(sk_cfp<id<MTLRenderPipelineState>> pso,size_t vertexStride,size_t instanceStride)39 GraphicsPipeline(sk_cfp<id<MTLRenderPipelineState>> pso, 40 size_t vertexStride, 41 size_t instanceStride) 42 : fPipelineState(std::move(pso)) 43 , fVertexStride(vertexStride) 44 , fInstanceStride(instanceStride) {} 45 46 sk_cfp<id<MTLRenderPipelineState>> fPipelineState; 47 size_t fVertexStride = 0; 48 size_t fInstanceStride = 0; 49 }; 50 51 } // namespace skgpu::mtl 52 53 #endif // skgpu_MtlGraphicsPipeline_DEFINED 54