• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "GrAllocator.h"
12 #include "GrShaderVar.h"
13 #include "glsl/GrGLSLUniformHandler.h"
14 
15 class GrVkUniformHandler : public GrGLSLUniformHandler {
16 public:
17     static const int kUniformsPerBlock = 8;
18 
19     enum {
20         kUniformBufferDescSet = 0,
21         kSamplerDescSet = 1,
22         kTexelBufferDescSet = 2,
23     };
24     enum {
25         kGeometryBinding = 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         GrShaderVar fVariable;
32         uint32_t        fVisibility;
33         uint32_t        fUBOffset;
34     };
35     typedef GrTAllocator<UniformInfo> UniformInfoArray;
36 
getUniformVariable(UniformHandle u)37     const GrShaderVar& getUniformVariable(UniformHandle u) const override {
38         return fUniforms[u.toIndex()].fVariable;
39     }
40 
getUniformCStr(UniformHandle u)41     const char* getUniformCStr(UniformHandle u) const override {
42         return this->getUniformVariable(u).c_str();
43     }
44 
45 private:
GrVkUniformHandler(GrGLSLProgramBuilder * program)46     explicit GrVkUniformHandler(GrGLSLProgramBuilder* program)
47         : INHERITED(program)
48         , fUniforms(kUniformsPerBlock)
49         , fSamplers(kUniformsPerBlock)
50         , fTexelBuffers(kUniformsPerBlock)
51         , fCurrentGeometryUBOOffset(0)
52         , fCurrentFragmentUBOOffset(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 
63     SamplerHandle addSampler(uint32_t visibility,
64                              GrSwizzle swizzle,
65                              GrSLType type,
66                              GrSLPrecision precision,
67                              const char* name) override;
68 
numSamplers()69     int numSamplers() const { return fSamplers.count(); }
samplerVariable(SamplerHandle handle)70     const GrShaderVar& samplerVariable(SamplerHandle handle) const override {
71         return fSamplers[handle.toIndex()].fVariable;
72     }
samplerSwizzle(SamplerHandle handle)73     GrSwizzle samplerSwizzle(SamplerHandle handle) const override {
74         return fSamplerSwizzles[handle.toIndex()];
75     }
samplerVisibility(SamplerHandle handle)76     uint32_t samplerVisibility(SamplerHandle handle) const {
77         return fSamplers[handle.toIndex()].fVisibility;
78     }
79 
80     TexelBufferHandle addTexelBuffer(uint32_t visibility, GrSLPrecision,
81                                      const char* name) override;
82 
numTexelBuffers()83     int numTexelBuffers() const { return fTexelBuffers.count(); }
texelBufferVariable(TexelBufferHandle handle)84     const GrShaderVar& texelBufferVariable(TexelBufferHandle handle) const override {
85         return fTexelBuffers[handle.toIndex()].fVariable;
86     }
texelBufferVisibility(TexelBufferHandle handle)87     uint32_t texelBufferVisibility(TexelBufferHandle handle) const {
88         return fTexelBuffers[handle.toIndex()].fVisibility;
89     }
90 
addImageStorage(uint32_t visibility,GrSLType,GrImageStorageFormat,GrSLMemoryModel,GrSLRestrict,GrIOType,const char * name)91     ImageStorageHandle addImageStorage(uint32_t visibility, GrSLType,  GrImageStorageFormat,
92                                        GrSLMemoryModel, GrSLRestrict, GrIOType,
93                                        const char* name) override {
94         SkFAIL("Image storages not implemented for Vulkan.");
95         return 0;
96     }
97 
imageStorageVariable(ImageStorageHandle handle)98     const GrShaderVar& imageStorageVariable(ImageStorageHandle handle) const override {
99         SkFAIL("Image storages not implemented for Vulkan.");
100         static const GrShaderVar* gVar = nullptr;
101         return *gVar;
102     }
103 
104     void appendUniformDecls(GrShaderFlags, SkString*) const override;
105 
hasGeometryUniforms()106     bool hasGeometryUniforms() const { return fCurrentGeometryUBOOffset > 0; }
hasFragmentUniforms()107     bool hasFragmentUniforms() const { return fCurrentFragmentUBOOffset > 0; }
108 
109 
getUniformInfo(UniformHandle u)110     const UniformInfo& getUniformInfo(UniformHandle u) const {
111         return fUniforms[u.toIndex()];
112     }
113 
114 
115     UniformInfoArray    fUniforms;
116     UniformInfoArray    fSamplers;
117     SkTArray<GrSwizzle> fSamplerSwizzles;
118     UniformInfoArray    fTexelBuffers;
119 
120     uint32_t            fCurrentGeometryUBOOffset;
121     uint32_t            fCurrentFragmentUBOOffset;
122 
123     friend class GrVkPipelineStateBuilder;
124     friend class GrVkDescriptorSetManager;
125 
126     typedef GrGLSLUniformHandler INHERITED;
127 };
128 
129 #endif
130