Flutter Impeller
compiler_backend.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_IMPELLER_COMPILER_COMPILER_BACKEND_H_
6 #define FLUTTER_IMPELLER_COMPILER_COMPILER_BACKEND_H_
7 
8 #include <cstdint>
9 #include <memory>
10 #include <variant>
11 
12 #include "spirv_glsl.hpp"
13 #include "spirv_msl.hpp"
14 #include "spirv_sksl.h"
15 
16 namespace impeller {
17 namespace compiler {
18 
20  using MSLCompiler = std::shared_ptr<spirv_cross::CompilerMSL>;
21  using GLSLCompiler = std::shared_ptr<spirv_cross::CompilerGLSL>;
22  using SkSLCompiler = std::shared_ptr<CompilerSkSL>;
23  using Compiler = std::variant<MSLCompiler, GLSLCompiler, SkSLCompiler>;
24 
25  enum class Type {
26  kMSL,
27  kGLSL,
29  kSkSL,
30  };
31 
32  explicit CompilerBackend(MSLCompiler compiler);
33 
34  explicit CompilerBackend(GLSLCompiler compiler);
35 
36  explicit CompilerBackend(SkSLCompiler compiler);
37 
38  CompilerBackend(Type type, Compiler compiler);
39 
41 
43 
44  Type GetType() const;
45 
46  const spirv_cross::Compiler* operator->() const;
47 
48  spirv_cross::Compiler* GetCompiler();
49 
50  explicit operator bool() const;
51 
52  enum class ExtendedResourceIndex {
53  kPrimary,
54  kSecondary,
55  };
57  spirv_cross::ID id) const;
58 
59  const spirv_cross::Compiler* GetCompiler() const;
60 
61  private:
62  Type type_ = Type::kMSL;
63  Compiler compiler_;
64 
65  const spirv_cross::CompilerMSL* GetMSLCompiler() const;
66 
67  const spirv_cross::CompilerGLSL* GetGLSLCompiler() const;
68 
69  const CompilerSkSL* GetSkSLCompiler() const;
70 };
71 
72 } // namespace compiler
73 } // namespace impeller
74 
75 #endif // FLUTTER_IMPELLER_COMPILER_COMPILER_BACKEND_H_
GLenum type
std::shared_ptr< CompilerSkSL > SkSLCompiler
const spirv_cross::Compiler * operator->() const
spirv_cross::Compiler * GetCompiler()
std::shared_ptr< spirv_cross::CompilerGLSL > GLSLCompiler
std::shared_ptr< spirv_cross::CompilerMSL > MSLCompiler
uint32_t GetExtendedMSLResourceBinding(ExtendedResourceIndex index, spirv_cross::ID id) const
std::variant< MSLCompiler, GLSLCompiler, SkSLCompiler > Compiler