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