blob: f6060b05327518ef294b14716df0f0ffcd5a7e5b [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"
egdaniel09aa1fc2016-04-20 07:09:46 -070014#include "GrVkGLSLSampler.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050015#include "glsl/GrGLSLShaderVar.h"
16
Greg Daniel164a9f02016-02-22 09:56:40 -050017class GrVkUniformHandler : public GrGLSLUniformHandler {
18public:
jvanverth633b3562016-03-23 11:01:22 -070019 static const int kUniformsPerBlock = 8;
20
Greg Daniel164a9f02016-02-22 09:56:40 -050021 enum {
egdanielb4aa3622016-04-06 13:47:08 -070022 kUniformBufferDescSet = 0,
23 kSamplerDescSet = 1,
Greg Daniel164a9f02016-02-22 09:56:40 -050024 };
25 enum {
26 kVertexBinding = 0,
27 kFragBinding = 1,
28 };
29
30 // fUBOffset is only valid if the GrSLType of the fVariable is not a sampler
31 struct UniformInfo {
32 GrGLSLShaderVar fVariable;
33 uint32_t fVisibility;
Greg Daniel164a9f02016-02-22 09:56:40 -050034 uint32_t fUBOffset;
35 };
36 typedef GrTAllocator<UniformInfo> UniformInfoArray;
37
38 const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const override {
39 return fUniforms[u.toIndex()].fVariable;
40 }
41
42 const char* getUniformCStr(UniformHandle u) const override {
43 return this->getUniformVariable(u).c_str();
44 }
45
46private:
47 explicit GrVkUniformHandler(GrGLSLProgramBuilder* program)
48 : INHERITED(program)
49 , fUniforms(kUniformsPerBlock)
50 , fCurrentVertexUBOOffset(0)
51 , fCurrentFragmentUBOOffset(0)
52 , fCurrentSamplerBinding(0) {
53 }
54
55 UniformHandle internalAddUniformArray(uint32_t visibility,
56 GrSLType type,
57 GrSLPrecision precision,
58 const char* name,
59 bool mangleName,
60 int arrayCount,
61 const char** outName) override;
62
egdaniel09aa1fc2016-04-20 07:09:46 -070063 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
Greg Daniel164a9f02016-02-22 09:56:40 -050074 void appendUniformDecls(GrShaderFlags, SkString*) const override;
75
76 bool hasVertexUniforms() const { return fCurrentVertexUBOOffset > 0; }
77 bool hasFragmentUniforms() const { return fCurrentFragmentUBOOffset > 0; }
78
79
80 const UniformInfo& getUniformInfo(UniformHandle u) const {
81 return fUniforms[u.toIndex()];
82 }
83
84
85 UniformInfoArray fUniforms;
egdaniel09aa1fc2016-04-20 07:09:46 -070086 SkTArray<GrVkGLSLSampler> fSamplers;
87
Greg Daniel164a9f02016-02-22 09:56:40 -050088 uint32_t fCurrentVertexUBOOffset;
89 uint32_t fCurrentFragmentUBOOffset;
90 uint32_t fCurrentSamplerBinding;
91
egdaniel22281c12016-03-23 13:49:40 -070092 friend class GrVkPipelineStateBuilder;
Greg Daniel164a9f02016-02-22 09:56:40 -050093
94 typedef GrGLSLUniformHandler INHERITED;
95};
96
jvanverth633b3562016-03-23 11:01:22 -070097#endif