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/GrVkTypes.h" 15 #include "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 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 set1f(UniformHandle, float v0) const override; 31 void set1fv(UniformHandle, int arrayCount, const float v[]) const override; 32 void set2i(UniformHandle, int32_t, int32_t) const override; 33 void set2iv(UniformHandle, int arrayCount, const int32_t v[]) const override; 34 void set2f(UniformHandle, float, float) const override; 35 void set2fv(UniformHandle, int arrayCount, const float v[]) const override; 36 void set3i(UniformHandle, int32_t, int32_t, int32_t) const override; 37 void set3iv(UniformHandle, int arrayCount, const int32_t v[]) const override; 38 void set3f(UniformHandle, float, float, float) const override; 39 void set3fv(UniformHandle, int arrayCount, const float v[]) const override; 40 void set4i(UniformHandle, int32_t, int32_t, int32_t, int32_t) const override; 41 void set4iv(UniformHandle, int arrayCount, const int32_t v[]) const override; 42 void set4f(UniformHandle, float, float, float, float) const override; 43 void set4fv(UniformHandle, int arrayCount, const float v[]) const override; 44 // matrices are column-major, the first two upload a single matrix, the latter two upload 45 // arrayCount matrices into a uniform array. 46 void setMatrix2f(UniformHandle, const float matrix[]) const override; 47 void setMatrix3f(UniformHandle, const float matrix[]) const override; 48 void setMatrix4f(UniformHandle, const float matrix[]) const override; 49 void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const override; 50 void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override; 51 void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override; 52 53 // for nvpr only setPathFragmentInputTransform(VaryingHandle u,int components,const SkMatrix & matrix)54 void setPathFragmentInputTransform(VaryingHandle u, int components, 55 const SkMatrix& matrix) const override { 56 SK_ABORT("Only supported in NVPR, which is not in vulkan"); 57 } 58 59 // Returns true if either the geometry or fragment buffers needed to generate a new underlying 60 // VkBuffer object in order upload data. If true is returned, this is a signal to the caller 61 // that they will need to update the descriptor set that is using these buffers. 62 bool uploadUniformBuffers(GrVkGpu* gpu, 63 GrVkUniformBuffer* geometryBuffer, 64 GrVkUniformBuffer* fragmentBuffer) const; 65 private: 66 struct Uniform { 67 uint32_t fBinding; 68 uint32_t fOffset; 69 SkDEBUGCODE( 70 GrSLType fType; 71 int fArrayCount; 72 ); 73 }; 74 75 template<int N> inline void setMatrices(UniformHandle, int arrayCount, 76 const float matrices[]) const; 77 78 void* getBufferPtrAndMarkDirty(const Uniform& uni) const; 79 80 uint32_t fGeometryUniformSize; 81 uint32_t fFragmentUniformSize; 82 83 SkTArray<Uniform, true> fUniforms; 84 85 mutable SkAutoMalloc fGeometryUniformData; 86 mutable SkAutoMalloc fFragmentUniformData; 87 mutable bool fGeometryUniformsDirty; 88 mutable bool fFragmentUniformsDirty; 89 }; 90 91 #endif 92