| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrVkUniformHandler_DEFINED | 8 #ifndef GrVkUniformHandler_DEFINED |
| 9 #define GrVkUniformHandler_DEFINED | 9 #define GrVkUniformHandler_DEFINED |
| 10 | 10 |
| 11 #include "glsl/GrGLSLUniformHandler.h" | 11 #include "glsl/GrGLSLUniformHandler.h" |
| 12 | 12 |
| 13 #include "GrAllocator.h" | 13 #include "GrAllocator.h" |
| 14 #include "GrVkGLSLSampler.h" | |
| 15 #include "glsl/GrGLSLShaderVar.h" | 14 #include "glsl/GrGLSLShaderVar.h" |
| 16 | 15 |
| 17 class GrVkUniformHandler : public GrGLSLUniformHandler { | 16 class GrVkUniformHandler : public GrGLSLUniformHandler { |
| 18 public: | 17 public: |
| 19 static const int kUniformsPerBlock = 8; | 18 static const int kUniformsPerBlock = 8; |
| 20 | 19 |
| 21 enum { | 20 enum { |
| 22 kUniformBufferDescSet = 0, | 21 kUniformBufferDescSet = 0, |
| 23 kSamplerDescSet = 1, | 22 kSamplerDescSet = 1, |
| 24 }; | 23 }; |
| 25 enum { | 24 enum { |
| 26 kVertexBinding = 0, | 25 kVertexBinding = 0, |
| 27 kFragBinding = 1, | 26 kFragBinding = 1, |
| 28 }; | 27 }; |
| 29 | 28 |
| 30 // fUBOffset is only valid if the GrSLType of the fVariable is not a sampler | 29 // fUBOffset is only valid if the GrSLType of the fVariable is not a sampler |
| 31 struct UniformInfo { | 30 struct UniformInfo { |
| 32 GrGLSLShaderVar fVariable; | 31 GrGLSLShaderVar fVariable; |
| 33 uint32_t fVisibility; | 32 uint32_t fVisibility; |
| 33 uint32_t fSetNumber; |
| 34 uint32_t fBinding; |
| 34 uint32_t fUBOffset; | 35 uint32_t fUBOffset; |
| 35 }; | 36 }; |
| 36 typedef GrTAllocator<UniformInfo> UniformInfoArray; | 37 typedef GrTAllocator<UniformInfo> UniformInfoArray; |
| 37 | 38 |
| 38 const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const override { | 39 const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const override { |
| 39 return fUniforms[u.toIndex()].fVariable; | 40 return fUniforms[u.toIndex()].fVariable; |
| 40 } | 41 } |
| 41 | 42 |
| 42 const char* getUniformCStr(UniformHandle u) const override { | 43 const char* getUniformCStr(UniformHandle u) const override { |
| 43 return this->getUniformVariable(u).c_str(); | 44 return this->getUniformVariable(u).c_str(); |
| 44 } | 45 } |
| 45 | 46 |
| 46 private: | 47 private: |
| 47 explicit GrVkUniformHandler(GrGLSLProgramBuilder* program) | 48 explicit GrVkUniformHandler(GrGLSLProgramBuilder* program) |
| 48 : INHERITED(program) | 49 : INHERITED(program) |
| 49 , fUniforms(kUniformsPerBlock) | 50 , fUniforms(kUniformsPerBlock) |
| 50 , fCurrentVertexUBOOffset(0) | 51 , fCurrentVertexUBOOffset(0) |
| 51 , fCurrentFragmentUBOOffset(0) | 52 , fCurrentFragmentUBOOffset(0) |
| 52 , fCurrentSamplerBinding(0) { | 53 , fCurrentSamplerBinding(0) { |
| 53 } | 54 } |
| 54 | 55 |
| 55 UniformHandle internalAddUniformArray(uint32_t visibility, | 56 UniformHandle internalAddUniformArray(uint32_t visibility, |
| 56 GrSLType type, | 57 GrSLType type, |
| 57 GrSLPrecision precision, | 58 GrSLPrecision precision, |
| 58 const char* name, | 59 const char* name, |
| 59 bool mangleName, | 60 bool mangleName, |
| 60 int arrayCount, | 61 int arrayCount, |
| 61 const char** outName) override; | 62 const char** outName) override; |
| 62 | 63 |
| 63 SamplerHandle internalAddSampler(uint32_t visibility, | |
| 64 GrPixelConfig config, | |
| 65 GrSLType type, | |
| 66 GrSLPrecision precision, | |
| 67 const char* name) override; | |
| 68 | |
| 69 int numSamplers() const override { return fSamplers.count(); } | |
| 70 const GrGLSLSampler& getSampler(SamplerHandle handle) const override { | |
| 71 return fSamplers[handle.toIndex()]; | |
| 72 } | |
| 73 | |
| 74 void appendUniformDecls(GrShaderFlags, SkString*) const override; | 64 void appendUniformDecls(GrShaderFlags, SkString*) const override; |
| 75 | 65 |
| 76 bool hasVertexUniforms() const { return fCurrentVertexUBOOffset > 0; } | 66 bool hasVertexUniforms() const { return fCurrentVertexUBOOffset > 0; } |
| 77 bool hasFragmentUniforms() const { return fCurrentFragmentUBOOffset > 0; } | 67 bool hasFragmentUniforms() const { return fCurrentFragmentUBOOffset > 0; } |
| 78 | 68 |
| 79 | 69 |
| 80 const UniformInfo& getUniformInfo(UniformHandle u) const { | 70 const UniformInfo& getUniformInfo(UniformHandle u) const { |
| 81 return fUniforms[u.toIndex()]; | 71 return fUniforms[u.toIndex()]; |
| 82 } | 72 } |
| 83 | 73 |
| 84 | 74 |
| 85 UniformInfoArray fUniforms; | 75 UniformInfoArray fUniforms; |
| 86 SkTArray<GrVkGLSLSampler> fSamplers; | |
| 87 | |
| 88 uint32_t fCurrentVertexUBOOffset; | 76 uint32_t fCurrentVertexUBOOffset; |
| 89 uint32_t fCurrentFragmentUBOOffset; | 77 uint32_t fCurrentFragmentUBOOffset; |
| 90 uint32_t fCurrentSamplerBinding; | 78 uint32_t fCurrentSamplerBinding; |
| 91 | 79 |
| 92 friend class GrVkPipelineStateBuilder; | 80 friend class GrVkPipelineStateBuilder; |
| 93 | 81 |
| 94 typedef GrGLSLUniformHandler INHERITED; | 82 typedef GrGLSLUniformHandler INHERITED; |
| 95 }; | 83 }; |
| 96 | 84 |
| 97 #endif | 85 #endif |
| OLD | NEW |