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