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 "src/gpu/glsl/GrGLSLProgramDataManager.h"
12 
13 #include "include/gpu/vk/GrVkTypes.h"
14 #include "src/core/SkAutoMalloc.h"
15 #include "src/gpu/vk/GrVkUniformHandler.h"
16 
17 class GrVkGpu;
18 class GrVkUniformBuffer;
19 
20 class GrVkPipelineStateDataManager : public GrGLSLProgramDataManager {
21 public:
22     typedef GrVkUniformHandler::UniformInfoArray UniformInfoArray;
23 
24     GrVkPipelineStateDataManager(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 vulkan");
56     }
57 
58     // Returns true if either the geometry or fragment buffers needed to generate a new underlying
59     // VkBuffer object in order upload data. If true is returned, this is a signal to the caller
60     // that they will need to update the descriptor set that is using these buffers.
61     bool uploadUniformBuffers(GrVkGpu* gpu,
62                               GrVkUniformBuffer* buffer) const;
63 private:
64     struct Uniform {
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 fUniformSize;
78 
79     SkTArray<Uniform, true> fUniforms;
80 
81     mutable SkAutoMalloc fUniformData;
82     mutable bool         fUniformsDirty;
83 };
84 
85 #endif
86