blob: 8a3f314cb9beacbc45b164e2288c9c92da7d7855 [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
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
Greg Daniel164a9f02016-02-22 09:56:40 -050016class GrVkUniformHandler : public GrGLSLUniformHandler {
17public:
jvanverth633b3562016-03-23 11:01:22 -070018 static const int kUniformsPerBlock = 8;
19
Greg Daniel164a9f02016-02-22 09:56:40 -050020 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
47private:
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
egdaniel22281c12016-03-23 13:49:40 -070080 friend class GrVkPipelineStateBuilder;
Greg Daniel164a9f02016-02-22 09:56:40 -050081
82 typedef GrGLSLUniformHandler INHERITED;
83};
84
jvanverth633b3562016-03-23 11:01:22 -070085#endif