| Flutter Impeller |

spirv_compiler.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_SPIRV_COMPILER_H_
6 #define FLUTTER_IMPELLER_COMPILER_SPIRV_COMPILER_H_
7
8 #include <cstdint>
9 #include <vector>
10
11 #include "flutter/fml/mapping.h"
12 #include "impeller/compiler/includer.h"
13 #include "impeller/compiler/source_options.h"
14 #include "shaderc/shaderc.hpp"
15
16 namespace impeller {
17 namespace compiler {
18
19 struct SPIRVCompilerSourceProfile {
20 shaderc_profile profile = shaderc_profile_core;
21 uint32_t version = 460;
22 };
23
24 struct SPIRVCompilerTargetEnv {
25 shaderc_target_env env = shaderc_target_env::shaderc_target_env_vulkan;
26 shaderc_env_version version =
27 shaderc_env_version::shaderc_env_version_vulkan_1_1;
28 shaderc_spirv_version spirv_version =
29 shaderc_spirv_version::shaderc_spirv_version_1_3;
30 };
31
32 struct SPIRVCompilerOptions {
33 bool generate_debug_info = true;
34 //----------------------------------------------------------------------------
35 // Source Options.
36 //----------------------------------------------------------------------------
37 std::optional<shaderc_source_language> source_langauge;
38 std::optional<SPIRVCompilerSourceProfile> source_profile;
39
40 shaderc_optimization_level optimization_level =
41 shaderc_optimization_level::shaderc_optimization_level_performance;
42
43 //----------------------------------------------------------------------------
44 // Target Options.
45 //----------------------------------------------------------------------------
46 std::optional<SPIRVCompilerTargetEnv> target;
47
48 std::vector<std::string> macro_definitions;
49
50 std::shared_ptr<Includer> includer;
51
52 bool relaxed_vulkan_rules = false;
53
54 shaderc::CompileOptions BuildShadercOptions() const;
55 };
56
57 class SPIRVCompiler {
58 public:
59 SPIRVCompiler(const SourceOptions& options,
60 std::shared_ptr<const fml::Mapping> sources);
61
62 ~SPIRVCompiler();
63
64 std::shared_ptr<fml::Mapping> CompileToSPV(
65 std::stringstream& error_stream,
66 const shaderc::CompileOptions& spirv_options) const;
67
68 private:
69 SourceOptions options_;
70 const std::shared_ptr<const fml::Mapping> sources_;
71
72 std::string GetSourcePrefix() const;
73
74 SPIRVCompiler(const SPIRVCompiler&) = delete;
75
76 SPIRVCompiler& operator=(const SPIRVCompiler&) = delete;
77 };
78
79 } // namespace compiler
80 } // namespace impeller
81
82 #endif // FLUTTER_IMPELLER_COMPILER_SPIRV_COMPILER_H_
impeller::compiler::SPIRVCompiler::~SPIRVCompiler
~SPIRVCompiler()
impeller::compiler::SPIRVCompiler::CompileToSPV
std::shared_ptr< fml::Mapping > CompileToSPV(std::stringstream &error_stream, const shaderc::CompileOptions &spirv_options) const
Definition: spirv_compiler.cc:21
impeller::compiler::SPIRVCompilerOptions::generate_debug_info
bool generate_debug_info
Definition: spirv_compiler.h:33
impeller::compiler::SPIRVCompiler::SPIRVCompiler
SPIRVCompiler(const SourceOptions &options, std::shared_ptr< const fml::Mapping > sources)
Definition: spirv_compiler.cc:15
impeller::compiler::SourceOptions
Definition: source_options.h:20
impeller::compiler::SPIRVCompilerOptions::includer
std::shared_ptr< Includer > includer
Definition: spirv_compiler.h:50
impeller::compiler::SPIRVCompilerOptions::relaxed_vulkan_rules
bool relaxed_vulkan_rules
Definition: spirv_compiler.h:52
impeller::compiler::SPIRVCompilerOptions::source_profile
std::optional< SPIRVCompilerSourceProfile > source_profile
Definition: spirv_compiler.h:38
impeller::compiler::SPIRVCompilerTargetEnv::env
shaderc_target_env env
Definition: spirv_compiler.h:25
includer.h
impeller::compiler::SPIRVCompilerOptions::target
std::optional< SPIRVCompilerTargetEnv > target
Definition: spirv_compiler.h:46
source_options.h
impeller::compiler::SPIRVCompilerOptions
Definition: spirv_compiler.h:32
impeller::compiler::SPIRVCompilerSourceProfile
Definition: spirv_compiler.h:19
impeller::compiler::SPIRVCompilerTargetEnv::version
shaderc_env_version version
Definition: spirv_compiler.h:26
impeller::compiler::SPIRVCompilerOptions::source_langauge
std::optional< shaderc_source_language > source_langauge
Definition: spirv_compiler.h:37
impeller::compiler::SPIRVCompilerSourceProfile::profile
shaderc_profile profile
Definition: spirv_compiler.h:20
impeller::compiler::SPIRVCompilerTargetEnv::spirv_version
shaderc_spirv_version spirv_version
Definition: spirv_compiler.h:28
impeller::compiler::SPIRVCompilerOptions::macro_definitions
std::vector< std::string > macro_definitions
Definition: spirv_compiler.h:48
impeller::compiler::SPIRVCompilerOptions::BuildShadercOptions
shaderc::CompileOptions BuildShadercOptions() const
Definition: spirv_compiler.cc:276
impeller::compiler::SPIRVCompilerSourceProfile::version
uint32_t version
Definition: spirv_compiler.h:21
impeller::compiler::SPIRVCompiler
Definition: spirv_compiler.h:57
impeller
Definition: aiks_blur_unittests.cc:20
impeller::compiler::SPIRVCompilerOptions::optimization_level
shaderc_optimization_level optimization_level
Definition: spirv_compiler.h:40
impeller::compiler::SPIRVCompilerTargetEnv
Definition: spirv_compiler.h:24