• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright 2016 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 GrVkPipelineStateDataManager_DEFINED
9 #define GrVkPipelineStateDataManager_DEFINED
10 
11 #include "glsl/GrGLSLProgramDataManager.h"
12 
13 #include "SkAutoMalloc.h"
14 #include "vk/GrVkUniformHandler.h"
15 
16 class GrVkGpu;
17 class GrVkUniformBuffer;
18 
19 class GrVkPipelineStateDataManager : public GrGLSLProgramDataManager {
20 public:
21     typedef GrVkUniformHandler::UniformInfoArray UniformInfoArray;
22 
23     GrVkPipelineStateDataManager(const UniformInfoArray&,
24                                  uint32_t geometryUniformSize,
25                                  uint32_t fragmentUniformSize);
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 set2f(UniformHandle, float, float) const override;
32     void set2fv(UniformHandle, int arrayCount, const float v[]) const override;
33     void set3f(UniformHandle, float, float, float) const override;
34     void set3fv(UniformHandle, int arrayCount, const float v[]) const override;
35     void set4f(UniformHandle, float, float, float, float) const override;
36     void set4fv(UniformHandle, int arrayCount, const float v[]) const override;
37     // matrices are column-major, the first two upload a single matrix, the latter two upload
38     // arrayCount matrices into a uniform array.
39     void setMatrix2f(UniformHandle, const float matrix[]) const override;
40     void setMatrix3f(UniformHandle, const float matrix[]) const override;
41     void setMatrix4f(UniformHandle, const float matrix[]) const override;
42     void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override;
43     void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override;
44     void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override;
45 
46     // for nvpr only
setPathFragmentInputTransform(VaryingHandle u,int components,const SkMatrix & matrix)47     void setPathFragmentInputTransform(VaryingHandle u, int components,
48                                        const SkMatrix& matrix) const override {
49         SkFAIL("Only supported in NVPR, which is not in vulkan");
50     }
51 
52     // Returns true if either the geometry or fragment buffers needed to generate a new underlying
53     // VkBuffer object in order upload data. If true is returned, this is a signal to the caller
54     // that they will need to update the descriptor set that is using these buffers.
55     bool uploadUniformBuffers(GrVkGpu* gpu,
56                               GrVkUniformBuffer* geometryBuffer,
57                               GrVkUniformBuffer* fragmentBuffer) const;
58 private:
59     struct Uniform {
60         uint32_t fBinding;
61         uint32_t fOffset;
62         SkDEBUGCODE(
63             GrSLType    fType;
64             int         fArrayCount;
65         );
66     };
67 
68     template<int N> inline void setMatrices(UniformHandle, int arrayCount,
69                                             const float matrices[]) const;
70 
71     void* getBufferPtrAndMarkDirty(const Uniform& uni) const;
72 
73     uint32_t fGeometryUniformSize;
74     uint32_t fFragmentUniformSize;
75 
76     SkTArray<Uniform, true> fUniforms;
77 
78     mutable SkAutoMalloc fGeometryUniformData;
79     mutable SkAutoMalloc fFragmentUniformData;
80     mutable bool         fGeometryUniformsDirty;
81     mutable bool         fFragmentUniformsDirty;
82 };
83 
84 #endif
85