• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 GrDawnProgramDataManager_DEFINED
9 #define GrDawnProgramDataManager_DEFINED
10 
11 #include "src/gpu/dawn/GrDawnUniformHandler.h"
12 #include "src/gpu/glsl/GrGLSLProgramDataManager.h"
13 #include "dawn/dawncpp.h"
14 
15 #include "src/core/SkAutoMalloc.h"
16 
17 class GrDawnGpu;
18 class GrDawnUniformBuffer;
19 
20 class GrDawnProgramDataManager : public GrGLSLProgramDataManager {
21 public:
22     typedef GrDawnUniformHandler::UniformInfoArray UniformInfoArray;
23 
24     GrDawnProgramDataManager(const UniformInfoArray&,
25                              uint32_t geometryUniformSize,
26                              uint32_t fragmentUniformSize);
27 
28     void set1i(UniformHandle, int32_t) const override;
29     void set1iv(UniformHandle, int arrayCount, const int32_t 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 set3i(UniformHandle, int32_t, int32_t, int32_t) const override;
33     void set3iv(UniformHandle, int arrayCount, const int32_t v[]) const override;
34     void set4i(UniformHandle, int32_t, int32_t, int32_t, int32_t) const override;
35     void set4iv(UniformHandle, int arrayCount, const int32_t v[]) const override;
36 
37     void set1f(UniformHandle, float v0) const override;
38     void set1fv(UniformHandle, int arrayCount, const float v[]) const override;
39     void set2f(UniformHandle, float, float) const override;
40     void set2fv(UniformHandle, int arrayCount, const float v[]) const override;
41     void set3f(UniformHandle, float, float, float) const override;
42     void set3fv(UniformHandle, int arrayCount, const float v[]) const override;
43     void set4f(UniformHandle, float, float, float, float) const override;
44     void set4fv(UniformHandle, int arrayCount, const float v[]) const override;
45     // matrices are column-major, the first two upload a single matrix, the latter two upload
46     // arrayCount matrices into a uniform array.
47     void setMatrix2f(UniformHandle, const float matrix[]) const override;
48     void setMatrix3f(UniformHandle, const float matrix[]) const override;
49     void setMatrix4f(UniformHandle, const float matrix[]) const override;
50     void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override;
51     void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override;
52     void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override;
53 
54     // for nvpr only
setPathFragmentInputTransform(VaryingHandle u,int components,const SkMatrix & matrix)55     void setPathFragmentInputTransform(VaryingHandle u, int components,
56                                        const SkMatrix& matrix) const override {
57         SK_ABORT("Only supported in NVPR, which is not in Dawn");
58     }
59 
60     void uploadUniformBuffers(dawn::Buffer geometryBuffer, dawn::Buffer fragmentBuffer) const;
61 
62 private:
63     struct Uniform {
64         uint32_t fBinding;
65         uint32_t fOffset;
66         SkDEBUGCODE(
67             GrSLType    fType;
68             int         fArrayCount;
69         );
70     };
71 
72     template<int N> inline void setMatrices(UniformHandle, int arrayCount,
73                                             const float matrices[]) const;
74 
75     void* getBufferPtrAndMarkDirty(const Uniform& uni) const;
76 
77     uint32_t fGeometryUniformSize;
78     uint32_t fFragmentUniformSize;
79 
80     SkTArray<Uniform, true> fUniforms;
81 
82     mutable SkAutoMalloc fGeometryUniformData;
83     mutable SkAutoMalloc fFragmentUniformData;
84     mutable bool         fGeometryUniformsDirty;
85     mutable bool         fFragmentUniformsDirty;
86 };
87 
88 #endif
89