• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "glsl/GrGLSLProgramDataManager.h"
12 #include "GrMtlUniformHandler.h"
13 #include "SkAutoMalloc.h"
14 
15 class GrMtlBuffer;
16 class GrMtlGpu;
17 
18 class GrMtlPipelineStateDataManager : public GrGLSLProgramDataManager {
19 public:
20     typedef GrMtlUniformHandler::UniformInfoArray UniformInfoArray;
21 
22     GrMtlPipelineStateDataManager(const UniformInfoArray&,
23                                   uint32_t geometryUniformSize,
24                                   uint32_t fragmentUniformSize);
25 
26     void set1i(UniformHandle, int32_t) const override;
27     void set1iv(UniformHandle, int arrayCount, const int32_t v[]) const override;
28     void set1f(UniformHandle, float v0) const override;
29     void set1fv(UniformHandle, int arrayCount, const float v[]) const override;
30     void set2i(UniformHandle, int32_t, int32_t) const override;
31     void set2iv(UniformHandle, int arrayCount, const int32_t v[]) const override;
32     void set2f(UniformHandle, float, float) const override;
33     void set2fv(UniformHandle, int arrayCount, const float v[]) const override;
34     void set3i(UniformHandle, int32_t, int32_t, int32_t) const override;
35     void set3iv(UniformHandle, int arrayCount, const int32_t v[]) const override;
36     void set3f(UniformHandle, float, float, float) const override;
37     void set3fv(UniformHandle, int arrayCount, const float v[]) const override;
38     void set4i(UniformHandle, int32_t, int32_t, int32_t, int32_t) const override;
39     void set4iv(UniformHandle, int arrayCount, const int32_t v[]) const override;
40     void set4f(UniformHandle, float, float, float, float) const override;
41     void set4fv(UniformHandle, int arrayCount, const float v[]) const override;
42     // matrices are column-major, the first two upload a single matrix, the latter two upload
43     // arrayCount matrices into a uniform array.
44     void setMatrix2f(UniformHandle, const float matrix[]) const override;
45     void setMatrix3f(UniformHandle, const float matrix[]) const override;
46     void setMatrix4f(UniformHandle, const float matrix[]) const override;
47     void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override;
48     void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override;
49     void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override;
50 
51     // for nvpr only
setPathFragmentInputTransform(VaryingHandle u,int components,const SkMatrix & matrix)52     void setPathFragmentInputTransform(VaryingHandle u, int components,
53                                        const SkMatrix& matrix) const override {
54         SK_ABORT("Only supported in NVPR, which is not in Metal");
55     }
56 
57     void uploadUniformBuffers(GrMtlGpu* gpu,
58                               GrMtlBuffer* geometryBuffer,
59                               GrMtlBuffer* fragmentBuffer) const;
60 
61 private:
62     struct Uniform {
63         uint32_t fBinding;
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 fGeometryUniformSize;
77     uint32_t fFragmentUniformSize;
78 
79     SkTArray<Uniform, true> fUniforms;
80 
81     mutable SkAutoMalloc fGeometryUniformData;
82     mutable SkAutoMalloc fFragmentUniformData;
83     mutable bool         fGeometryUniformsDirty;
84     mutable bool         fFragmentUniformsDirty;
85 };
86 
87 #endif
88