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