Flutter Engine
The Flutter Engine
GrMtlUniformHandler.h
Go to the documentation of this file.
1/*
2* Copyright 2018 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 GrMtlUniformHandler_DEFINED
9#define GrMtlUniformHandler_DEFINED
10
15
16#include <vector>
17
18// TODO: this class is basically copy and pasted from GrVkUniformHandler so that we can have
19// some shaders working. The SkSL Metal code generator was written to work with GLSL generated for
20// the Ganesh Vulkan backend, so it should all work. There might be better ways to do things in
21// Metal and/or some Vulkan GLSLisms left in.
23public:
24 static const int kUniformsPerBlock = 8;
25
26 enum {
29 };
30 static constexpr int kUniformBindingCount = kLastUniformBinding + 1;
31
32 // fUBOffset is only valid if the SkSLType of the fVariable is not a sampler
33 struct MtlUniformInfo : public UniformInfo {
34 uint32_t fUBOffset;
35 };
37
38 const GrShaderVar& getUniformVariable(UniformHandle u) const override {
39 return fUniforms.item(u.toIndex()).fVariable;
40 }
41
42 const char* getUniformCStr(UniformHandle u) const override {
43 return this->getUniformVariable(u).c_str();
44 }
45
46 int numUniforms() const override {
47 return fUniforms.count();
48 }
49
50 UniformInfo& uniform(int idx) override {
51 return fUniforms.item(idx);
52 }
53 const UniformInfo& uniform(int idx) const override {
54 return fUniforms.item(idx);
55 }
56
57private:
59 : INHERITED(program)
60 , fUniforms(kUniformsPerBlock)
61 , fSamplers(kUniformsPerBlock)
62 , fCurrentUBOOffset(0)
63 , fCurrentUBOMaxAlignment(0x0) {
64 }
65
66 UniformHandle internalAddUniformArray(const GrProcessor* owner,
67 uint32_t visibility,
69 const char* name,
70 bool mangleName,
71 int arrayCount,
72 const char** outName) override;
73
74 SamplerHandle addSampler(const GrBackendFormat&,
76 const skgpu::Swizzle&,
77 const char* name,
78 const GrShaderCaps*) override;
79
80 int numSamplers() const { return fSamplers.count(); }
81 const char* samplerVariable(SamplerHandle handle) const override {
82 return fSamplers.item(handle.toIndex()).fVariable.c_str();
83 }
84 skgpu::Swizzle samplerSwizzle(SamplerHandle handle) const override {
85 return fSamplerSwizzles[handle.toIndex()];
86 }
87 uint32_t samplerVisibility(SamplerHandle handle) const {
88 return fSamplers.item(handle.toIndex()).fVisibility;
89 }
90
91 void appendUniformDecls(GrShaderFlags, SkString*) const override;
92
93 const UniformInfo& getUniformInfo(UniformHandle u) const {
94 return fUniforms.item(u.toIndex());
95 }
96
97 UniformInfoArray fUniforms;
98 UniformInfoArray fSamplers;
100
101 uint32_t fCurrentUBOOffset;
102 uint32_t fCurrentUBOMaxAlignment;
103
105
107};
108
109#endif
GrShaderFlags
Definition: GrTypesPriv.h:284
SkSLType
GLenum type
GrGLSLUniformHandler(GrGLSLProgramBuilder *program)
GrGLSLProgramDataManager::UniformHandle UniformHandle
const GrShaderVar & getUniformVariable(UniformHandle u) const override
SkTBlockList< MtlUniformInfo > UniformInfoArray
const UniformInfo & uniform(int idx) const override
const char * getUniformCStr(UniformHandle u) const override
int numUniforms() const override
static const int kUniformsPerBlock
static constexpr int kUniformBindingCount
UniformInfo & uniform(int idx) override
const char * c_str() const
Definition: GrShaderVar.h:94
T & item(int i)
Definition: SkTBlockList.h:217
int count() const
Definition: SkTBlockList.h:167
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32