Timothy Liang | 44636e9 | 2018-08-08 10:50:21 -0400 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/core/SkAutoMalloc.h" |
| 12 | #include "src/gpu/glsl/GrGLSLProgramDataManager.h" |
| 13 | #include "src/gpu/mtl/GrMtlUniformHandler.h" |
Timothy Liang | 44636e9 | 2018-08-08 10:50:21 -0400 | [diff] [blame] | 14 | |
Jim Van Verth | dd15d69 | 2019-04-22 15:29:53 -0400 | [diff] [blame] | 15 | #import <Metal/Metal.h> |
| 16 | |
Timothy Liang | 44636e9 | 2018-08-08 10:50:21 -0400 | [diff] [blame] | 17 | class GrMtlBuffer; |
| 18 | class GrMtlGpu; |
| 19 | |
| 20 | class GrMtlPipelineStateDataManager : public GrGLSLProgramDataManager { |
| 21 | public: |
| 22 | typedef GrMtlUniformHandler::UniformInfoArray UniformInfoArray; |
| 23 | |
| 24 | GrMtlPipelineStateDataManager(const UniformInfoArray&, |
Ethan Nicholas | e5dc1eb | 2019-08-13 17:02:25 -0400 | [diff] [blame^] | 25 | uint32_t uniformSize); |
Timothy Liang | 44636e9 | 2018-08-08 10:50:21 -0400 | [diff] [blame] | 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; |
Michael Ludwig | 779ed02 | 2018-08-28 17:20:07 -0400 | [diff] [blame] | 31 | void set2i(UniformHandle, int32_t, int32_t) const override; |
| 32 | void set2iv(UniformHandle, int arrayCount, const int32_t v[]) const override; |
Timothy Liang | 44636e9 | 2018-08-08 10:50:21 -0400 | [diff] [blame] | 33 | void set2f(UniformHandle, float, float) const override; |
| 34 | void set2fv(UniformHandle, int arrayCount, const float v[]) const override; |
Michael Ludwig | 779ed02 | 2018-08-28 17:20:07 -0400 | [diff] [blame] | 35 | void set3i(UniformHandle, int32_t, int32_t, int32_t) const override; |
| 36 | void set3iv(UniformHandle, int arrayCount, const int32_t v[]) const override; |
Timothy Liang | 44636e9 | 2018-08-08 10:50:21 -0400 | [diff] [blame] | 37 | void set3f(UniformHandle, float, float, float) const override; |
| 38 | void set3fv(UniformHandle, int arrayCount, const float v[]) const override; |
Michael Ludwig | 779ed02 | 2018-08-28 17:20:07 -0400 | [diff] [blame] | 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; |
Timothy Liang | 44636e9 | 2018-08-08 10:50:21 -0400 | [diff] [blame] | 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 |
| 53 | void setPathFragmentInputTransform(VaryingHandle u, int components, |
| 54 | const SkMatrix& matrix) const override { |
| 55 | SK_ABORT("Only supported in NVPR, which is not in Metal"); |
| 56 | } |
| 57 | |
Jim Van Verth | dd15d69 | 2019-04-22 15:29:53 -0400 | [diff] [blame] | 58 | void uploadAndBindUniformBuffers(GrMtlGpu* gpu, |
| 59 | id<MTLRenderCommandEncoder> renderCmdEncoder) const; |
| 60 | void resetDirtyBits(); |
Timothy Liang | 44636e9 | 2018-08-08 10:50:21 -0400 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | struct Uniform { |
Timothy Liang | 44636e9 | 2018-08-08 10:50:21 -0400 | [diff] [blame] | 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 | |
Ethan Nicholas | e5dc1eb | 2019-08-13 17:02:25 -0400 | [diff] [blame^] | 76 | uint32_t fUniformSize; |
Timothy Liang | 44636e9 | 2018-08-08 10:50:21 -0400 | [diff] [blame] | 77 | |
| 78 | SkTArray<Uniform, true> fUniforms; |
| 79 | |
Ethan Nicholas | e5dc1eb | 2019-08-13 17:02:25 -0400 | [diff] [blame^] | 80 | mutable SkAutoMalloc fUniformData; |
| 81 | mutable bool fUniformsDirty; |
Timothy Liang | 44636e9 | 2018-08-08 10:50:21 -0400 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | #endif |