| Flutter Impeller |

shader_bundle_data.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_SHADER_BUNDLE_DATA_H_
6 #define FLUTTER_IMPELLER_COMPILER_SHADER_BUNDLE_DATA_H_
7
8 #include <memory>
9 #include <vector>
10
11 #include "flutter/fml/mapping.h"
12 #include "impeller/compiler/types.h"
13 #include "impeller/shader_bundle/shader_bundle_flatbuffers.h"
14
15 namespace impeller {
16 namespace compiler {
17
18 class ShaderBundleData {
19 public:
20 struct ShaderUniformStructField {
21 std::string name;
22 spirv_cross::SPIRType::BaseType type =
23 spirv_cross::SPIRType::BaseType::Float;
24 size_t offset_in_bytes = 0u;
25 size_t element_size_in_bytes = 0u;
26 size_t total_size_in_bytes = 0u;
27 std::optional<size_t> array_elements = std::nullopt;
28 };
29
30 struct ShaderUniformStruct {
31 std::string name;
32 size_t ext_res_0 = 0u;
33 size_t set = 0u;
34 size_t binding = 0u;
35 size_t size_in_bytes = 0u;
36 std::vector<ShaderUniformStructField> fields;
37 };
38
39 struct ShaderUniformTexture {
40 std::string name;
41 size_t ext_res_0 = 0u;
42 size_t set = 0u;
43 size_t binding = 0u;
44 };
45
46 ShaderBundleData(std::string entrypoint,
47 spv::ExecutionModel stage,
48 TargetPlatform target_platform);
49
50 ~ShaderBundleData();
51
52 void AddUniformStruct(ShaderUniformStruct uniform_struct);
53
54 void AddUniformTexture(ShaderUniformTexture uniform_texture);
55
56 void AddInputDescription(InputDescription input);
57
58 void SetShaderData(std::shared_ptr<fml::Mapping> shader);
59
60 void SetSkSLData(std::shared_ptr<fml::Mapping> sksl);
61
62 std::unique_ptr<fb::shaderbundle::BackendShaderT> CreateFlatbuffer() const;
63
64 private:
65 const std::string entrypoint_;
66 const spv::ExecutionModel stage_;
67 const TargetPlatform target_platform_;
68 std::vector<ShaderUniformStruct> uniform_structs_;
69 std::vector<ShaderUniformTexture> uniform_textures_;
70 std::vector<InputDescription> inputs_;
71 std::shared_ptr<fml::Mapping> shader_;
72 std::shared_ptr<fml::Mapping> sksl_;
73
74 ShaderBundleData(const ShaderBundleData&) = delete;
75
76 ShaderBundleData& operator=(const ShaderBundleData&) = delete;
77 };
78
79 } // namespace compiler
80 } // namespace impeller
81
82 #endif // FLUTTER_IMPELLER_COMPILER_SHADER_BUNDLE_DATA_H_
impeller::compiler::ShaderBundleData
Definition: shader_bundle_data.h:18
impeller::compiler::ShaderBundleData::AddInputDescription
void AddInputDescription(InputDescription input)
Definition: shader_bundle_data.cc:33
impeller::compiler::ShaderBundleData::ShaderBundleData
ShaderBundleData(std::string entrypoint, spv::ExecutionModel stage, TargetPlatform target_platform)
Definition: shader_bundle_data.cc:16
impeller::compiler::ShaderBundleData::CreateFlatbuffer
std::unique_ptr< fb::shaderbundle::BackendShaderT > CreateFlatbuffer() const
Definition: shader_bundle_data.cc:144
impeller::compiler::ShaderBundleData::AddUniformStruct
void AddUniformStruct(ShaderUniformStruct uniform_struct)
Definition: shader_bundle_data.cc:25
impeller::compiler::ShaderBundleData::~ShaderBundleData
~ShaderBundleData()
impeller::compiler::ShaderBundleData::SetShaderData
void SetShaderData(std::shared_ptr< fml::Mapping > shader)
Definition: shader_bundle_data.cc:37
impeller::compiler::ShaderBundleData::SetSkSLData
void SetSkSLData(std::shared_ptr< fml::Mapping > sksl)
impeller::compiler::ShaderBundleData::AddUniformTexture
void AddUniformTexture(ShaderUniformTexture uniform_texture)
Definition: shader_bundle_data.cc:29
types.h
impeller::compiler::TargetPlatform
TargetPlatform
Definition: types.h:29
impeller
Definition: allocation.cc:12
impeller::compiler::InputDescription
Definition: types.h:62
impeller::compiler::ShaderBundleData::ShaderUniformStructField
Definition: shader_bundle_data.h:20
impeller::compiler::ShaderBundleData::ShaderUniformStructField::total_size_in_bytes
size_t total_size_in_bytes
Definition: shader_bundle_data.h:26
impeller::compiler::ShaderBundleData::ShaderUniformStructField::name
std::string name
Definition: shader_bundle_data.h:21
impeller::compiler::ShaderBundleData::ShaderUniformStructField::array_elements
std::optional< size_t > array_elements
Definition: shader_bundle_data.h:27
impeller::compiler::ShaderBundleData::ShaderUniformStructField::element_size_in_bytes
size_t element_size_in_bytes
Definition: shader_bundle_data.h:25
impeller::compiler::ShaderBundleData::ShaderUniformStructField::offset_in_bytes
size_t offset_in_bytes
Definition: shader_bundle_data.h:24
impeller::compiler::ShaderBundleData::ShaderUniformStructField::type
spirv_cross::SPIRType::BaseType type
Definition: shader_bundle_data.h:22
impeller::compiler::ShaderBundleData::ShaderUniformStruct
Definition: shader_bundle_data.h:30
impeller::compiler::ShaderBundleData::ShaderUniformStruct::set
size_t set
Definition: shader_bundle_data.h:33
impeller::compiler::ShaderBundleData::ShaderUniformStruct::name
std::string name
Definition: shader_bundle_data.h:31
impeller::compiler::ShaderBundleData::ShaderUniformStruct::binding
size_t binding
Definition: shader_bundle_data.h:34
impeller::compiler::ShaderBundleData::ShaderUniformStruct::ext_res_0
size_t ext_res_0
Definition: shader_bundle_data.h:32
impeller::compiler::ShaderBundleData::ShaderUniformStruct::fields
std::vector< ShaderUniformStructField > fields
Definition: shader_bundle_data.h:36
impeller::compiler::ShaderBundleData::ShaderUniformStruct::size_in_bytes
size_t size_in_bytes
Definition: shader_bundle_data.h:35
impeller::compiler::ShaderBundleData::ShaderUniformTexture
Definition: shader_bundle_data.h:39
impeller::compiler::ShaderBundleData::ShaderUniformTexture::ext_res_0
size_t ext_res_0
Definition: shader_bundle_data.h:41
impeller::compiler::ShaderBundleData::ShaderUniformTexture::set
size_t set
Definition: shader_bundle_data.h:42
impeller::compiler::ShaderBundleData::ShaderUniformTexture::binding
size_t binding
Definition: shader_bundle_data.h:43
impeller::compiler::ShaderBundleData::ShaderUniformTexture::name
std::string name
Definition: shader_bundle_data.h:40