68 impeller::fb::shaderbundle::InputDataType input_type) {
70 case impeller::fb::shaderbundle::InputDataType::kBoolean:
72 case impeller::fb::shaderbundle::InputDataType::kSignedByte:
74 case impeller::fb::shaderbundle::InputDataType::kUnsignedByte:
76 case impeller::fb::shaderbundle::InputDataType::kSignedShort:
78 case impeller::fb::shaderbundle::InputDataType::kUnsignedShort:
80 case impeller::fb::shaderbundle::InputDataType::kSignedInt:
82 case impeller::fb::shaderbundle::InputDataType::kUnsignedInt:
84 case impeller::fb::shaderbundle::InputDataType::kSignedInt64:
86 case impeller::fb::shaderbundle::InputDataType::kUnsignedInt64:
88 case impeller::fb::shaderbundle::InputDataType::kFloat:
90 case impeller::fb::shaderbundle::InputDataType::kDouble:
96 impeller::fb::shaderbundle::UniformDataType uniform_type) {
97 switch (uniform_type) {
98 case impeller::fb::shaderbundle::UniformDataType::kBoolean:
100 case impeller::fb::shaderbundle::UniformDataType::kSignedByte:
102 case impeller::fb::shaderbundle::UniformDataType::kUnsignedByte:
104 case impeller::fb::shaderbundle::UniformDataType::kSignedShort:
106 case impeller::fb::shaderbundle::UniformDataType::kUnsignedShort:
108 case impeller::fb::shaderbundle::UniformDataType::kSignedInt:
110 case impeller::fb::shaderbundle::UniformDataType::kUnsignedInt:
112 case impeller::fb::shaderbundle::UniformDataType::kSignedInt64:
114 case impeller::fb::shaderbundle::UniformDataType::kUnsignedInt64:
116 case impeller::fb::shaderbundle::UniformDataType::kFloat:
118 case impeller::fb::shaderbundle::UniformDataType::kDouble:
120 case impeller::fb::shaderbundle::UniformDataType::kHalfFloat:
122 case impeller::fb::shaderbundle::UniformDataType::kSampledImage:
128 impeller::fb::shaderbundle::InputDataType input_type) {
129 switch (input_type) {
130 case impeller::fb::shaderbundle::InputDataType::kBoolean:
132 case impeller::fb::shaderbundle::InputDataType::kSignedByte:
134 case impeller::fb::shaderbundle::InputDataType::kUnsignedByte:
136 case impeller::fb::shaderbundle::InputDataType::kSignedShort:
138 case impeller::fb::shaderbundle::InputDataType::kUnsignedShort:
140 case impeller::fb::shaderbundle::InputDataType::kSignedInt:
142 case impeller::fb::shaderbundle::InputDataType::kUnsignedInt:
144 case impeller::fb::shaderbundle::InputDataType::kSignedInt64:
146 case impeller::fb::shaderbundle::InputDataType::kUnsignedInt64:
148 case impeller::fb::shaderbundle::InputDataType::kFloat:
150 case impeller::fb::shaderbundle::InputDataType::kDouble:
174 std::shared_ptr<fml::Mapping> payload) {
175 if (payload ==
nullptr || !payload->GetMapping()) {
178 if (!impeller::fb::shaderbundle::ShaderBundleBufferHasIdentifier(
179 payload->GetMapping())) {
183 impeller::fb::shaderbundle::GetShaderBundle(payload->GetMapping());
190 for (
const auto* bundled_shader : *bundle->shaders()) {
191 const impeller::fb::shaderbundle::BackendShader* backend_shader =
193 if (!backend_shader) {
195 << bundled_shader->name()->c_str() <<
"\" from bundle.";
199 auto code_mapping = std::make_shared<fml::NonOwnedMapping>(
200 backend_shader->shader()->data(),
201 backend_shader->shader()->size(),
202 [payload = payload](
auto,
auto) {}
205 std::vector<impeller::DescriptorSetLayout> descriptor_set_layouts;
207 std::unordered_map<std::string, Shader::UniformBinding> uniform_structs;
208 if (backend_shader->uniform_structs() !=
nullptr) {
209 for (
const auto& uniform : *backend_shader->uniform_structs()) {
210 std::vector<impeller::ShaderStructMemberMetadata> members;
211 if (uniform->fields() !=
nullptr) {
212 for (
const auto& struct_member : *uniform->fields()) {
215 .name = struct_member->name()->c_str(),
216 .offset =
static_cast<size_t>(struct_member->offset_in_bytes()),
218 static_cast<size_t>(struct_member->element_size_in_bytes()),
220 static_cast<size_t>(struct_member->total_size_in_bytes()),
222 struct_member->array_elements() == 0
223 ? std::optional<size_t>(std::nullopt)
224 :
static_cast<size_t>(struct_member->array_elements()),
232 .
name = uniform->name()->c_str(),
233 .ext_res_0 =
static_cast<size_t>(uniform->ext_res_0()),
234 .
set =
static_cast<size_t>(uniform->set()),
235 .binding =
static_cast<size_t>(uniform->binding()),
239 .
name = uniform->name()->c_str(),
242 .size_in_bytes =
static_cast<size_t>(uniform->size_in_bytes()),
246 static_cast<uint32_t
>(uniform->binding()),
253 std::unordered_map<std::string, Shader::TextureBinding> uniform_textures;
254 if (backend_shader->uniform_textures() !=
nullptr) {
255 for (
const auto& uniform : *backend_shader->uniform_textures()) {
258 .
name = uniform->name()->c_str(),
259 .texture_index =
static_cast<size_t>(uniform->ext_res_0()),
260 .
set =
static_cast<size_t>(uniform->set()),
261 .binding =
static_cast<size_t>(uniform->binding()),
264 .
name = uniform->name()->c_str(),
268 uniform_textures[uniform->name()->str()] = texture_binding;
271 static_cast<uint32_t
>(uniform->binding()),
278 std::vector<impeller::ShaderStageIOSlot> inputs;
279 std::vector<impeller::ShaderStageBufferLayout> layouts;
280 if (backend_shader->stage() ==
281 impeller::fb::shaderbundle::ShaderStage::kVertex) {
282 auto inputs_fb = backend_shader->inputs();
284 inputs.reserve(inputs_fb->size());
285 size_t default_stride = 0;
286 for (
const auto&
input : *inputs_fb) {
297 inputs.emplace_back(slot);
309 backend_shader->entrypoint()->str(),
310 ToShaderStage(backend_shader->stage()), std::move(code_mapping),
311 std::move(inputs), std::move(layouts), std::move(uniform_structs),
312 std::move(uniform_textures), std::move(descriptor_set_layouts));
313 shader_map[bundled_shader->name()->str()] = std::move(shader);
316 return fml::MakeRefCounted<flutter::gpu::ShaderLibrary>(
317 std::move(payload), std::move(shader_map));
static std::shared_ptr< impeller::Context > GetDefaultContext(std::optional< std::string > &out_error)
static fml::RefPtr< Shader > Make(std::string entrypoint, impeller::ShaderStage stage, std::shared_ptr< fml::Mapping > code_mapping, std::vector< impeller::ShaderStageIOSlot > inputs, std::vector< impeller::ShaderStageBufferLayout > layouts, std::unordered_map< std::string, UniformBinding > uniform_structs, std::unordered_map< std::string, TextureBinding > uniform_textures, std::vector< impeller::DescriptorSetLayout > descriptor_set_layouts)
const uint8_t uint32_t uint32_t GError ** error
impeller::SampledImageSlot slot
impeller::ShaderMetadata metadata