| Flutter Impeller |

multi_arch_shader_archive_writer.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/shader_archive/multi_arch_shader_archive_writer.h"
6
7 #include "impeller/base/validation.h"
8 #include "impeller/shader_archive/multi_arch_shader_archive_flatbuffers.h"
9
10 namespace impeller {
11
12 MultiArchShaderArchiveWriter::MultiArchShaderArchiveWriter() = default;
13
14 MultiArchShaderArchiveWriter::~MultiArchShaderArchiveWriter() = default;
15
16 bool MultiArchShaderArchiveWriter::RegisterShaderArchive(
17 ArchiveRenderingBackend backend,
18 std::shared_ptr<const fml::Mapping> mapping) {
19 if (!mapping || mapping->GetMapping() == nullptr) {
20 return false;
21 }
22 if (archives_.find(backend) != archives_.end()) {
23 VALIDATION_LOG << "Multi-archive already has a shader library registered "
24 "for that backend.";
25 return false;
26 }
27 archives_[backend] = std::move(mapping);
28 return true;
29 }
30
31 constexpr fb::RenderingBackend ToRenderingBackend(
32 ArchiveRenderingBackend backend) {
33 switch (backend) {
34 case ArchiveRenderingBackend::kMetal:
35 return fb::RenderingBackend::kMetal;
36 case ArchiveRenderingBackend::kVulkan:
37 return fb::RenderingBackend::kVulkan;
38 case ArchiveRenderingBackend::kOpenGLES:
39 return fb::RenderingBackend::kOpenGLES;
40 }
41 FML_UNREACHABLE();
42 }
43
44 std::shared_ptr<fml::Mapping> MultiArchShaderArchiveWriter::CreateMapping()
45 const {
46 fb::MultiArchShaderArchiveT multi_archive;
47 for (const auto& archive : archives_) {
48 auto archive_blob = std::make_unique<fb::ShaderArchiveBlobT>();
49 archive_blob->rendering_backend = ToRenderingBackend(archive.first);
50 archive_blob->mapping = {
51 archive.second->GetMapping(),
52 archive.second->GetMapping() + archive.second->GetSize()};
53 multi_archive.items.emplace_back(std::move(archive_blob));
54 }
55 auto builder = std::make_shared<flatbuffers::FlatBufferBuilder>();
56 builder->Finish(
57 fb::MultiArchShaderArchive::Pack(*builder.get(), &multi_archive),
58 fb::MultiArchShaderArchiveIdentifier());
59 return std::make_shared<fml::NonOwnedMapping>(builder->GetBufferPointer(),
60 builder->GetSize(),
61 [builder](auto, auto) {});
62 }
63
64 } // namespace impeller
multi_arch_shader_archive_writer.h
impeller::ToRenderingBackend
constexpr fb::RenderingBackend ToRenderingBackend(ArchiveRenderingBackend backend)
Definition: multi_arch_shader_archive_writer.cc:31
impeller::ArchiveRenderingBackend::kVulkan
@ kVulkan
impeller::MultiArchShaderArchiveWriter::CreateMapping
std::shared_ptr< fml::Mapping > CreateMapping() const
Definition: multi_arch_shader_archive_writer.cc:44
validation.h
impeller::MultiArchShaderArchiveWriter::RegisterShaderArchive
bool RegisterShaderArchive(ArchiveRenderingBackend backend, std::shared_ptr< const fml::Mapping > mapping)
Definition: multi_arch_shader_archive_writer.cc:16
impeller::MultiArchShaderArchiveWriter::~MultiArchShaderArchiveWriter
~MultiArchShaderArchiveWriter()
impeller::ArchiveRenderingBackend::kOpenGLES
@ kOpenGLES
impeller::MultiArchShaderArchiveWriter::MultiArchShaderArchiveWriter
MultiArchShaderArchiveWriter()
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::ArchiveRenderingBackend::kMetal
@ kMetal
impeller::ArchiveRenderingBackend
ArchiveRenderingBackend
Definition: shader_archive_types.h:16
impeller
Definition: aiks_blur_unittests.cc:20