1 /* 2 * Copyright 2018 Google Inc. 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 GrMtlPipelineStateDataManager_DEFINED 9 #define GrMtlPipelineStateDataManager_DEFINED 10 11 #include "src/core/SkAutoMalloc.h" 12 #include "src/gpu/glsl/GrGLSLProgramDataManager.h" 13 #include "src/gpu/mtl/GrMtlUniformHandler.h" 14 15 #import <Metal/Metal.h> 16 17 class GrMtlBuffer; 18 class GrMtlGpu; 19 20 class GrMtlPipelineStateDataManager : public GrGLSLProgramDataManager { 21 public: 22 typedef GrMtlUniformHandler::UniformInfoArray UniformInfoArray; 23 24 GrMtlPipelineStateDataManager(const UniformInfoArray&, 25 uint32_t uniformSize); 26 27 void set1i(UniformHandle, int32_t) const override; 28 void set1iv(UniformHandle, int arrayCount, const int32_t v[]) const override; 29 void set1f(UniformHandle, float v0) const override; 30 void set1fv(UniformHandle, int arrayCount, const float v[]) const override; 31 void set2i(UniformHandle, int32_t, int32_t) const override; 32 void set2iv(UniformHandle, int arrayCount, const int32_t v[]) const override; 33 void set2f(UniformHandle, float, float) const override; 34 void set2fv(UniformHandle, int arrayCount, const float v[]) const override; 35 void set3i(UniformHandle, int32_t, int32_t, int32_t) const override; 36 void set3iv(UniformHandle, int arrayCount, const int32_t v[]) const override; 37 void set3f(UniformHandle, float, float, float) const override; 38 void set3fv(UniformHandle, int arrayCount, const float v[]) const override; 39 void set4i(UniformHandle, int32_t, int32_t, int32_t, int32_t) const override; 40 void set4iv(UniformHandle, int arrayCount, const int32_t v[]) const override; 41 void set4f(UniformHandle, float, float, float, float) const override; 42 void set4fv(UniformHandle, int arrayCount, const float v[]) const override; 43 // matrices are column-major, the first two upload a single matrix, the latter two upload 44 // arrayCount matrices into a uniform array. 45 void setMatrix2f(UniformHandle, const float matrix[]) const override; 46 void setMatrix3f(UniformHandle, const float matrix[]) const override; 47 void setMatrix4f(UniformHandle, const float matrix[]) const override; 48 void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override; 49 void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override; 50 void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override; 51 52 // for nvpr only setPathFragmentInputTransform(VaryingHandle u,int components,const SkMatrix & matrix)53 void setPathFragmentInputTransform(VaryingHandle u, int components, 54 const SkMatrix& matrix) const override { 55 SK_ABORT("Only supported in NVPR, which is not in Metal"); 56 } 57 58 void uploadAndBindUniformBuffers(GrMtlGpu* gpu, 59 id<MTLRenderCommandEncoder> renderCmdEncoder) const; 60 void resetDirtyBits(); 61 62 private: 63 struct Uniform { 64 uint32_t fOffset; 65 SkDEBUGCODE( 66 GrSLType fType; 67 int fArrayCount; 68 ); 69 }; 70 71 template<int N> inline void setMatrices(UniformHandle, int arrayCount, 72 const float matrices[]) const; 73 74 void* getBufferPtrAndMarkDirty(const Uniform& uni) const; 75 76 uint32_t fUniformSize; 77 78 SkTArray<Uniform, true> fUniforms; 79 80 mutable SkAutoMalloc fUniformData; 81 mutable bool fUniformsDirty; 82 }; 83 84 #endif 85