| Flutter Impeller |

compiler_backend.cc
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 #include "impeller/compiler/compiler_backend.h"
6
7 #include "impeller/base/comparable.h"
8
9 namespace impeller {
10 namespace compiler {
11
12 CompilerBackend::CompilerBackend(MSLCompiler compiler)
13 : CompilerBackend(Type::kMSL, compiler) {}
14
15 CompilerBackend::CompilerBackend(GLSLCompiler compiler)
16 : CompilerBackend(Type::kGLSL, compiler) {}
17
18 CompilerBackend::CompilerBackend(SkSLCompiler compiler)
19 : CompilerBackend(Type::kSkSL, compiler) {}
20
21 CompilerBackend::CompilerBackend() = default;
22
23 CompilerBackend::CompilerBackend(Type type, Compiler compiler)
24 : type_(type), compiler_(std::move(compiler)){};
25
26 CompilerBackend::~CompilerBackend() = default;
27
28 const spirv_cross::Compiler* CompilerBackend::operator->() const {
29 return GetCompiler();
30 }
31
32 uint32_t CompilerBackend::GetExtendedMSLResourceBinding(
33 ExtendedResourceIndex index,
34 spirv_cross::ID id) const {
35 if (auto compiler = GetMSLCompiler()) {
36 switch (index) {
37 case ExtendedResourceIndex::kPrimary:
38 return compiler->get_automatic_msl_resource_binding(id);
39 case ExtendedResourceIndex::kSecondary:
40 return compiler->get_automatic_msl_resource_binding_secondary(id);
41 break;
42 }
43 }
44 if (auto compiler = GetGLSLCompiler()) {
45 return compiler->get_decoration(id, spv::Decoration::DecorationBinding);
46 }
47 const auto kOOBIndex = static_cast<uint32_t>(-1);
48 return kOOBIndex;
49 }
50
51 const spirv_cross::Compiler* CompilerBackend::GetCompiler() const {
52 if (auto compiler = GetGLSLCompiler()) {
53 return compiler;
54 }
55
56 if (auto compiler = GetMSLCompiler()) {
57 return compiler;
58 }
59
60 if (auto compiler = GetSkSLCompiler()) {
61 return compiler;
62 }
63
64 return nullptr;
65 }
66
67 spirv_cross::Compiler* CompilerBackend::GetCompiler() {
68 if (auto* msl = std::get_if<MSLCompiler>(&compiler_)) {
69 return msl->get();
70 }
71 if (auto* glsl = std::get_if<GLSLCompiler>(&compiler_)) {
72 return glsl->get();
73 }
74 if (auto* sksl = std::get_if<SkSLCompiler>(&compiler_)) {
75 return sksl->get();
76 }
77 return nullptr;
78 }
79
80 const spirv_cross::CompilerMSL* CompilerBackend::GetMSLCompiler() const {
81 if (auto* msl = std::get_if<MSLCompiler>(&compiler_)) {
82 return msl->get();
83 }
84 return nullptr;
85 }
86
87 const spirv_cross::CompilerGLSL* CompilerBackend::GetGLSLCompiler() const {
88 if (auto* glsl = std::get_if<GLSLCompiler>(&compiler_)) {
89 return glsl->get();
90 }
91 return nullptr;
92 }
93
94 const CompilerSkSL* CompilerBackend::GetSkSLCompiler() const {
95 if (auto* sksl = std::get_if<SkSLCompiler>(&compiler_)) {
96 return sksl->get();
97 }
98 return nullptr;
99 }
100
101 CompilerBackend::operator bool() const {
102 return !!GetCompiler();
103 }
104
105 CompilerBackend::Type CompilerBackend::GetType() const {
106 return type_;
107 }
108
109 } // namespace compiler
110 } // namespace impeller
impeller::compiler::CompilerBackend
Definition: compiler_backend.h:19
impeller::compiler::SourceLanguage::kGLSL
@ kGLSL
impeller::compiler::CompilerBackend::Compiler
std::variant< MSLCompiler, GLSLCompiler, SkSLCompiler > Compiler
Definition: compiler_backend.h:23
impeller::compiler::CompilerBackend::Type
Type
Definition: compiler_backend.h:25
impeller::compiler::CompilerBackend::MSLCompiler
std::shared_ptr< spirv_cross::CompilerMSL > MSLCompiler
Definition: compiler_backend.h:20
impeller::compiler::CompilerBackend::ExtendedResourceIndex::kSecondary
@ kSecondary
impeller::compiler::CompilerBackend::GetExtendedMSLResourceBinding
uint32_t GetExtendedMSLResourceBinding(ExtendedResourceIndex index, spirv_cross::ID id) const
Definition: compiler_backend.cc:32
impeller::compiler::CompilerBackend::GetType
Type GetType() const
Definition: compiler_backend.cc:105
impeller::compiler::CompilerBackend::ExtendedResourceIndex
ExtendedResourceIndex
Definition: compiler_backend.h:51
compiler_backend.h
impeller::compiler::CompilerBackend::GetCompiler
spirv_cross::Compiler * GetCompiler()
Definition: compiler_backend.cc:51
impeller::compiler::CompilerBackend::SkSLCompiler
std::shared_ptr< CompilerSkSL > SkSLCompiler
Definition: compiler_backend.h:22
impeller::compiler::CompilerBackend::GLSLCompiler
std::shared_ptr< spirv_cross::CompilerGLSL > GLSLCompiler
Definition: compiler_backend.h:21
impeller::compiler::CompilerBackend::CompilerBackend
CompilerBackend()
comparable.h
std
Definition: comparable.h:98
impeller::compiler::CompilerBackend::~CompilerBackend
~CompilerBackend()
impeller::compiler::CompilerBackend::ExtendedResourceIndex::kPrimary
@ kPrimary
impeller::compiler::CompilerBackend::operator->
const spirv_cross::Compiler * operator->() const
Definition: compiler_backend.cc:28
impeller
Definition: aiks_context.cc:10
impeller::compiler::TargetPlatform::kSkSL
@ kSkSL