diff --git a/ci/licenses_golden/excluded_files b/ci/licenses_golden/excluded_files index 36119e952ad9b..bf79f33db0adb 100644 --- a/ci/licenses_golden/excluded_files +++ b/ci/licenses_golden/excluded_files @@ -127,7 +127,6 @@ ../../../flutter/impeller/archivist/archivist_unittests.cc ../../../flutter/impeller/base/README.md ../../../flutter/impeller/base/base_unittests.cc -../../../flutter/impeller/blobcat/blobcat_unittests.cc ../../../flutter/impeller/compiler/README.md ../../../flutter/impeller/compiler/compiler_unittests.cc ../../../flutter/impeller/compiler/switches_unittests.cc @@ -175,6 +174,7 @@ ../../../flutter/impeller/scene/README.md ../../../flutter/impeller/scene/importer/importer_unittests.cc ../../../flutter/impeller/scene/scene_unittests.cc +../../../flutter/impeller/shader_archive/shader_archive_unittests.cc ../../../flutter/impeller/tessellator/dart/.dart_tool ../../../flutter/impeller/tessellator/dart/pubspec.lock ../../../flutter/impeller/tessellator/dart/pubspec.yaml diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index c01aba892418a..de0914ad3189b 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -1719,13 +1719,6 @@ ORIGIN: ../../../flutter/impeller/base/validation.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/base/validation.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/base/version.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/base/version.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/blobcat/blob.fbs + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/blobcat/blob_library.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/blobcat/blob_library.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/blobcat/blob_types.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/blobcat/blob_writer.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/blobcat/blob_writer.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/blobcat/blobcat_main.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/compiler/code_gen_template.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/compiler/compiler.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/compiler/compiler.h + ../../../flutter/LICENSE @@ -2338,6 +2331,13 @@ ORIGIN: ../../../flutter/impeller/scene/shaders/unlit.frag + ../../../flutter/LI ORIGIN: ../../../flutter/impeller/scene/shaders/unskinned.vert + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/scene/skin.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/scene/skin.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/shader_archive/shader_archive.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/shader_archive/shader_archive.fbs + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/shader_archive/shader_archive.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/shader_archive/shader_archive_main.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/shader_archive/shader_archive_types.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/shader_archive/shader_archive_writer.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/shader_archive/shader_archive_writer.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/tessellator/c/tessellator.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/tessellator/c/tessellator.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/tessellator/dart/lib/tessellator.dart + ../../../flutter/LICENSE @@ -4491,13 +4491,6 @@ FILE: ../../../flutter/impeller/base/validation.cc FILE: ../../../flutter/impeller/base/validation.h FILE: ../../../flutter/impeller/base/version.cc FILE: ../../../flutter/impeller/base/version.h -FILE: ../../../flutter/impeller/blobcat/blob.fbs -FILE: ../../../flutter/impeller/blobcat/blob_library.cc -FILE: ../../../flutter/impeller/blobcat/blob_library.h -FILE: ../../../flutter/impeller/blobcat/blob_types.h -FILE: ../../../flutter/impeller/blobcat/blob_writer.cc -FILE: ../../../flutter/impeller/blobcat/blob_writer.h -FILE: ../../../flutter/impeller/blobcat/blobcat_main.cc FILE: ../../../flutter/impeller/compiler/code_gen_template.h FILE: ../../../flutter/impeller/compiler/compiler.cc FILE: ../../../flutter/impeller/compiler/compiler.h @@ -5111,6 +5104,13 @@ FILE: ../../../flutter/impeller/scene/shaders/unlit.frag FILE: ../../../flutter/impeller/scene/shaders/unskinned.vert FILE: ../../../flutter/impeller/scene/skin.cc FILE: ../../../flutter/impeller/scene/skin.h +FILE: ../../../flutter/impeller/shader_archive/shader_archive.cc +FILE: ../../../flutter/impeller/shader_archive/shader_archive.fbs +FILE: ../../../flutter/impeller/shader_archive/shader_archive.h +FILE: ../../../flutter/impeller/shader_archive/shader_archive_main.cc +FILE: ../../../flutter/impeller/shader_archive/shader_archive_types.h +FILE: ../../../flutter/impeller/shader_archive/shader_archive_writer.cc +FILE: ../../../flutter/impeller/shader_archive/shader_archive_writer.h FILE: ../../../flutter/impeller/tessellator/c/tessellator.cc FILE: ../../../flutter/impeller/tessellator/c/tessellator.h FILE: ../../../flutter/impeller/tessellator/dart/lib/tessellator.dart diff --git a/impeller/BUILD.gn b/impeller/BUILD.gn index c02ccd0558455..3df283d93de75 100644 --- a/impeller/BUILD.gn +++ b/impeller/BUILD.gn @@ -83,13 +83,13 @@ impeller_component("impeller_unittests") { deps = [ "archivist:archivist_unittests", "base:base_unittests", - "blobcat:blobcat_unittests", "compiler:compiler_unittests", "core:allocator_unittests", "display_list:skia_conversions_unittests", "geometry:geometry_unittests", "runtime_stage:runtime_stage_unittests", "scene/importer:importer_unittests", + "shader_archive:shader_archive_unittests", "tessellator:tessellator_unittests", ] diff --git a/impeller/README.md b/impeller/README.md index fceb8575ab2af..6ae2f8f3b9950 100644 --- a/impeller/README.md +++ b/impeller/README.md @@ -100,8 +100,15 @@ states of completion: package agnosticism in the Impeller interface. This sub-framework primarily provides a custom implementation of the `flutter::DisplayListDispatcher` that forwards Flutter rendering intent to Impeller. -* **`//impeller/typographer`**: Contains a backend agnostic interface for rendering typefaces. While Impeller does **not** do any text layout or shaping, it does render shaped glyph runs. The application specifies these glyph runs to Impeller using the Typographer subsystem. - * **`//impeller/typographer/backend`**: Contains code that interfaces with an underlying (usually platform-specific) library or toolkit to render glyphs in typefaces into texture atlases. Impeller will then reference these glyphs when rendering shaped glyph runs. No Impeller sub-frameworks may depend on these targets. There may be multiple typographer backends. +* **`//impeller/typographer`**: Contains a backend agnostic interface for + rendering typefaces. While Impeller does **not** do any text layout or + shaping, it does render shaped glyph runs. The application specifies these + glyph runs to Impeller using the Typographer subsystem. + * **`//impeller/typographer/backend`**: Contains code that interfaces with an + underlying (usually platform-specific) library or toolkit to render glyphs + in typefaces into texture atlases. Impeller will then reference these glyphs + when rendering shaped glyph runs. No Impeller sub-frameworks may depend on + these targets. There may be multiple typographer backends. * **`//impeller/base`**: Contains C++ utilities that are used throughout the Impeller family of frameworks. Ideally, these should go in `//flutter/fml` but their use is probably not widespread enough to at this time. @@ -114,14 +121,25 @@ states of completion: removal and must not be used outside of tests. * **`//fixtures`**: Contains test fixtures used by the various test harnesses. This depends on `//flutter/testing`. -* **`//impeller/tools`**: Contains all GN rules and python scripts for working with - Impeller. These include GN rules processing GLSL shaders, including reflected - shader information as source set targets, and, including compiled shader - intermediate representations into the final executable as binary blobs for - easier packaging. -* **`//impeller/toolkit`**: Contains Impeller agnostic toolkits that provide more ergonomic wrappers around certain APIs like EGL. Toolkits must be dependency free so that an external component using a toolkit doesn't have to pull in a significant portion of Impeller itself. -* **`//impeller/blobcat`**: Concatenates shader blobs. This is primarily used by rendering backends that don't have the notion of a shader library. In Impeller, all shaders are packaged into a single library that contains a manifest of the shaders in the library along with the pre-compiled shaders themselves. Unlike Metal, backends like OpenGL ES and Vulkan don't have such a concept. For these backends, `//impeller/blobcat` is used to create a single shader library to be packaged with the engine. -* **`//impeller/scene`**: Contains an experimental 3D model renderer. This is currently only exposed via [a special build of the Flutter Engine](https://github.com/flutter/flutter/wiki/Impeller-Scene). +* **`//impeller/tools`**: Contains all GN rules and python scripts for working + with Impeller. These include GN rules processing GLSL shaders, including + reflected shader information as source set targets, and, including compiled + shader intermediate representations into the final executable as binary blobs + for easier packaging. +* **`//impeller/toolkit`**: Contains Impeller agnostic toolkits that provide + more ergonomic wrappers around certain APIs like EGL. Toolkits must be + dependency free so that an external component using a toolkit doesn't have to + pull in a significant portion of Impeller itself. +* **`//impeller/shader_archive`**: Create a persistent library of shader blobs. + This is primarily used by rendering backends that don't have the notion of a + shader library. In Impeller, all shaders are packaged into a single library + that contains a manifest of the shaders in the library along with the + pre-compiled shaders themselves. Unlike Metal, backends like OpenGL ES and + Vulkan don't have such a concept. For these backends, `//impeller/blobcat` is + used to create a single shader library to be packaged with the engine. +* **`//impeller/scene`**: Contains an experimental 3D model renderer. This is + currently only exposed via [a special build of the Flutter + Engine](https://github.com/flutter/flutter/wiki/Impeller-Scene). ## The Offline Shader Compilation Pipeline diff --git a/impeller/blobcat/blob_library.cc b/impeller/blobcat/blob_library.cc deleted file mode 100644 index 5377fc236d3b8..0000000000000 --- a/impeller/blobcat/blob_library.cc +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "impeller/blobcat/blob_library.h" - -#include -#include -#include - -#include "impeller/base/validation.h" -#include "impeller/blobcat/blob_flatbuffers.h" - -namespace impeller { - -constexpr BlobShaderType ToShaderType(fb::Stage stage) { - switch (stage) { - case fb::Stage::kVertex: - return BlobShaderType::kVertex; - case fb::Stage::kFragment: - return BlobShaderType::kFragment; - case fb::Stage::kCompute: - return BlobShaderType::kCompute; - } - FML_UNREACHABLE(); -} - -BlobLibrary::BlobLibrary(std::shared_ptr payload) - : payload_(std::move(payload)) { - if (!payload_ || payload_->GetMapping() == nullptr) { - VALIDATION_LOG << "Blob mapping was absent."; - return; - } - - if (!fb::BlobLibraryBufferHasIdentifier(payload_->GetMapping())) { - VALIDATION_LOG << "Invalid blob magic."; - return; - } - - auto blob_library = fb::GetBlobLibrary(payload_->GetMapping()); - if (!blob_library) { - return; - } - - if (auto items = blob_library->items()) { - for (auto i = items->begin(), end = items->end(); i != end; i++) { - BlobKey key; - key.name = i->name()->str(); - key.type = ToShaderType(i->stage()); - blobs_[key] = std::make_shared( - i->mapping()->Data(), i->mapping()->size(), - [payload = payload_](auto, auto) { - // The pointers are into the base payload. Instead of copying the - // data, just hold onto the payload. - }); - } - } - - is_valid_ = true; -} - -BlobLibrary::BlobLibrary(BlobLibrary&&) = default; - -BlobLibrary::~BlobLibrary() = default; - -bool BlobLibrary::IsValid() const { - return is_valid_; -} - -size_t BlobLibrary::GetShaderCount() const { - return blobs_.size(); -} - -std::shared_ptr BlobLibrary::GetMapping(BlobShaderType type, - std::string name) const { - BlobKey key; - key.type = type; - key.name = std::move(name); - auto found = blobs_.find(key); - return found == blobs_.end() ? nullptr : found->second; -} - -size_t BlobLibrary::IterateAllBlobs( - const std::function& mapping)>& - callback) const { - if (!IsValid() || !callback) { - return 0u; - } - size_t count = 0u; - for (const auto& blob : blobs_) { - count++; - if (!callback(blob.first.type, blob.first.name, blob.second)) { - break; - } - } - return count; -} - -} // namespace impeller diff --git a/impeller/blobcat/blob_writer.h b/impeller/blobcat/blob_writer.h deleted file mode 100644 index eb2f80c3e4a17..0000000000000 --- a/impeller/blobcat/blob_writer.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#pragma once - -#include -#include -#include - -#include "flutter/fml/macros.h" -#include "flutter/fml/mapping.h" -#include "impeller/blobcat/blob_types.h" - -namespace impeller { - -class BlobWriter { - public: - BlobWriter(); - - ~BlobWriter(); - - [[nodiscard]] bool AddBlobAtPath(const std::string& path); - - [[nodiscard]] bool AddBlob(BlobShaderType type, - std::string name, - std::shared_ptr mapping); - - std::shared_ptr CreateMapping() const; - - private: - struct BlobDescription { - BlobShaderType type; - std::string name; - std::shared_ptr mapping; - }; - - std::vector blob_descriptions_; - - FML_DISALLOW_COPY_AND_ASSIGN(BlobWriter); -}; - -} // namespace impeller diff --git a/impeller/renderer/backend/gles/BUILD.gn b/impeller/renderer/backend/gles/BUILD.gn index 4188d25478250..f9db5b0313901 100644 --- a/impeller/renderer/backend/gles/BUILD.gn +++ b/impeller/renderer/backend/gles/BUILD.gn @@ -93,7 +93,7 @@ impeller_component("gles") { public_deps = [ "../../:renderer", - "../../../blobcat:blobcat_lib", + "../../../shader_archive", "//flutter/fml", ] } diff --git a/impeller/renderer/backend/gles/shader_library_gles.cc b/impeller/renderer/backend/gles/shader_library_gles.cc index f3c273c63e913..c26c62bc8f183 100644 --- a/impeller/renderer/backend/gles/shader_library_gles.cc +++ b/impeller/renderer/backend/gles/shader_library_gles.cc @@ -9,18 +9,18 @@ #include "flutter/fml/closure.h" #include "impeller/base/config.h" #include "impeller/base/validation.h" -#include "impeller/blobcat/blob_library.h" #include "impeller/renderer/backend/gles/shader_function_gles.h" +#include "impeller/shader_archive/shader_archive.h" namespace impeller { -static ShaderStage ToShaderStage(BlobShaderType type) { +static ShaderStage ToShaderStage(ArchiveShaderType type) { switch (type) { - case BlobShaderType::kVertex: + case ArchiveShaderType::kVertex: return ShaderStage::kVertex; - case BlobShaderType::kFragment: + case ArchiveShaderType::kFragment: return ShaderStage::kFragment; - case BlobShaderType::kCompute: + case ArchiveShaderType::kCompute: return ShaderStage::kCompute; } FML_UNREACHABLE(); @@ -74,12 +74,12 @@ ShaderLibraryGLES::ShaderLibraryGLES( return true; }; for (auto library : shader_libraries) { - auto blob_library = BlobLibrary{std::move(library)}; + auto blob_library = ShaderArchive{std::move(library)}; if (!blob_library.IsValid()) { VALIDATION_LOG << "Could not construct blob library for shaders."; return; } - blob_library.IterateAllBlobs(iterator); + blob_library.IterateAllShaders(iterator); } functions_ = functions; diff --git a/impeller/renderer/backend/vulkan/BUILD.gn b/impeller/renderer/backend/vulkan/BUILD.gn index 6de8fff0b13c5..26e788b8fabbb 100644 --- a/impeller/renderer/backend/vulkan/BUILD.gn +++ b/impeller/renderer/backend/vulkan/BUILD.gn @@ -112,7 +112,7 @@ impeller_component("vulkan") { public_deps = [ "../../:renderer", - "../../../blobcat:blobcat_lib", + "../../../shader_archive", "//flutter/flutter_vma", "//flutter/fml", "//third_party/vulkan-deps/vulkan-headers/src:vulkan_headers", diff --git a/impeller/renderer/backend/vulkan/shader_library_vk.cc b/impeller/renderer/backend/vulkan/shader_library_vk.cc index ea92c36258b94..cf25348d26dc1 100644 --- a/impeller/renderer/backend/vulkan/shader_library_vk.cc +++ b/impeller/renderer/backend/vulkan/shader_library_vk.cc @@ -6,19 +6,19 @@ #include "flutter/fml/logging.h" #include "flutter/fml/trace_event.h" -#include "impeller/blobcat/blob_library.h" #include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/shader_function_vk.h" +#include "impeller/shader_archive/shader_archive.h" namespace impeller { -static ShaderStage ToShaderStage(BlobShaderType type) { +static ShaderStage ToShaderStage(ArchiveShaderType type) { switch (type) { - case BlobShaderType::kVertex: + case ArchiveShaderType::kVertex: return ShaderStage::kVertex; - case BlobShaderType::kFragment: + case ArchiveShaderType::kFragment: return ShaderStage::kFragment; - case BlobShaderType::kCompute: + case ArchiveShaderType::kCompute: return ShaderStage::kCompute; } FML_UNREACHABLE(); @@ -69,12 +69,12 @@ ShaderLibraryVK::ShaderLibraryVK( return true; }; for (const auto& library_data : shader_libraries_data) { - auto blob_library = BlobLibrary{library_data}; + auto blob_library = ShaderArchive{library_data}; if (!blob_library.IsValid()) { VALIDATION_LOG << "Could not construct shader blob library."; return; } - blob_library.IterateAllBlobs(iterator); + blob_library.IterateAllShaders(iterator); } if (!success) { diff --git a/impeller/blobcat/BUILD.gn b/impeller/shader_archive/BUILD.gn similarity index 51% rename from impeller/blobcat/BUILD.gn rename to impeller/shader_archive/BUILD.gn index a70f4a4ec10ff..62bc99912f9d4 100644 --- a/impeller/blobcat/BUILD.gn +++ b/impeller/shader_archive/BUILD.gn @@ -5,51 +5,52 @@ import("//third_party/flatbuffers/flatbuffers.gni") import("../tools/impeller.gni") -config("blobcat_config") { +config("shader_archive_config") { configs = [ "//flutter/impeller:impeller_public_config" ] include_dirs = [ "$root_gen_dir/flutter" ] } -flatbuffers("blobcat_flatbuffers") { - flatbuffers = [ "blob.fbs" ] - public_configs = [ ":blobcat_config" ] +flatbuffers("shader_archive_flatbuffers") { + flatbuffers = [ "shader_archive.fbs" ] + public_configs = [ ":shader_archive_config" ] public_deps = [ "//third_party/flatbuffers" ] } -impeller_component("blobcat_lib") { +impeller_component("shader_archive") { sources = [ - "blob_library.cc", - "blob_library.h", - "blob_writer.cc", - "blob_writer.h", + "shader_archive.cc", + "shader_archive.h", + "shader_archive_types.h", + "shader_archive_writer.cc", + "shader_archive_writer.h", ] public_deps = [ - ":blobcat_flatbuffers", + ":shader_archive_flatbuffers", "../base", "//flutter/fml", ] } -impeller_component("blobcat") { +impeller_component("shader_archiver") { target_type = "executable" - sources = [ "blobcat_main.cc" ] + sources = [ "shader_archive_main.cc" ] deps = [ - ":blobcat_lib", + ":shader_archive", "../base", "//flutter/fml", ] } -impeller_component("blobcat_unittests") { +impeller_component("shader_archive_unittests") { testonly = true - sources = [ "blobcat_unittests.cc" ] + sources = [ "shader_archive_unittests.cc" ] deps = [ - ":blobcat_lib", + ":shader_archive", "//flutter/fml", "//flutter/testing", ] diff --git a/impeller/shader_archive/shader_archive.cc b/impeller/shader_archive/shader_archive.cc new file mode 100644 index 0000000000000..4cf2d3e1b564f --- /dev/null +++ b/impeller/shader_archive/shader_archive.cc @@ -0,0 +1,102 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/shader_archive/shader_archive.h" + +#include +#include +#include + +#include "impeller/base/validation.h" +#include "impeller/shader_archive/shader_archive_flatbuffers.h" + +namespace impeller { + +constexpr ArchiveShaderType ToShaderType(fb::Stage stage) { + switch (stage) { + case fb::Stage::kVertex: + return ArchiveShaderType::kVertex; + case fb::Stage::kFragment: + return ArchiveShaderType::kFragment; + case fb::Stage::kCompute: + return ArchiveShaderType::kCompute; + } + FML_UNREACHABLE(); +} + +ShaderArchive::ShaderArchive(std::shared_ptr payload) + : payload_(std::move(payload)) { + if (!payload_ || payload_->GetMapping() == nullptr) { + VALIDATION_LOG << "Shader mapping was absent."; + return; + } + + if (!fb::ShaderArchiveBufferHasIdentifier(payload_->GetMapping())) { + VALIDATION_LOG << "Invalid shader magic."; + return; + } + + auto shader_archive = fb::GetShaderArchive(payload_->GetMapping()); + if (!shader_archive) { + return; + } + + if (auto items = shader_archive->items()) { + for (auto i = items->begin(), end = items->end(); i != end; i++) { + ShaderKey key; + key.name = i->name()->str(); + key.type = ToShaderType(i->stage()); + shaders_[key] = std::make_shared( + i->mapping()->Data(), i->mapping()->size(), + [payload = payload_](auto, auto) { + // The pointers are into the base payload. Instead of copying the + // data, just hold onto the payload. + }); + } + } + + is_valid_ = true; +} + +ShaderArchive::ShaderArchive(ShaderArchive&&) = default; + +ShaderArchive::~ShaderArchive() = default; + +bool ShaderArchive::IsValid() const { + return is_valid_; +} + +size_t ShaderArchive::GetShaderCount() const { + return shaders_.size(); +} + +std::shared_ptr ShaderArchive::GetMapping( + ArchiveShaderType type, + std::string name) const { + ShaderKey key; + key.type = type; + key.name = std::move(name); + auto found = shaders_.find(key); + return found == shaders_.end() ? nullptr : found->second; +} + +size_t ShaderArchive::IterateAllShaders( + const std::function& mapping)>& + callback) const { + if (!IsValid() || !callback) { + return 0u; + } + size_t count = 0u; + for (const auto& shader : shaders_) { + count++; + if (!callback(shader.first.type, shader.first.name, shader.second)) { + break; + } + } + return count; +} + +} // namespace impeller diff --git a/impeller/blobcat/blob.fbs b/impeller/shader_archive/shader_archive.fbs similarity index 72% rename from impeller/blobcat/blob.fbs rename to impeller/shader_archive/shader_archive.fbs index 715dd70ccbaef..0077f54a3535b 100644 --- a/impeller/blobcat/blob.fbs +++ b/impeller/shader_archive/shader_archive.fbs @@ -10,15 +10,15 @@ enum Stage:byte { kCompute, } -table Blob { +table ShaderBlob { stage: Stage; name: string; mapping: [ubyte]; } -table BlobLibrary { - items: [Blob]; +table ShaderArchive { + items: [ShaderBlob]; } -root_type BlobLibrary; -file_identifier "BCAT"; +root_type ShaderArchive; +file_identifier "SHAR"; diff --git a/impeller/blobcat/blob_library.h b/impeller/shader_archive/shader_archive.h similarity index 55% rename from impeller/blobcat/blob_library.h rename to impeller/shader_archive/shader_archive.h index 4a8809590fb79..4a56b2412347d 100644 --- a/impeller/blobcat/blob_library.h +++ b/impeller/shader_archive/shader_archive.h @@ -11,38 +11,38 @@ #include "flutter/fml/hash_combine.h" #include "flutter/fml/macros.h" #include "flutter/fml/mapping.h" -#include "impeller/blobcat/blob_types.h" +#include "impeller/shader_archive/shader_archive_types.h" namespace impeller { -class BlobLibrary { +class ShaderArchive { public: - explicit BlobLibrary(std::shared_ptr payload); + explicit ShaderArchive(std::shared_ptr payload); - BlobLibrary(BlobLibrary&&); + ShaderArchive(ShaderArchive&&); - ~BlobLibrary(); + ~ShaderArchive(); bool IsValid() const; size_t GetShaderCount() const; - std::shared_ptr GetMapping(BlobShaderType type, + std::shared_ptr GetMapping(ArchiveShaderType type, std::string name) const; - size_t IterateAllBlobs( - const std::function& mapping)>&) const; private: - struct BlobKey { - BlobShaderType type = BlobShaderType::kFragment; + struct ShaderKey { + ArchiveShaderType type = ArchiveShaderType::kFragment; std::string name; struct Hash { - size_t operator()(const BlobKey& key) const { + size_t operator()(const ShaderKey& key) const { return fml::HashCombine( static_cast>(key.type), key.name); @@ -50,22 +50,22 @@ class BlobLibrary { }; struct Equal { - bool operator()(const BlobKey& lhs, const BlobKey& rhs) const { + bool operator()(const ShaderKey& lhs, const ShaderKey& rhs) const { return lhs.type == rhs.type && lhs.name == rhs.name; } }; }; - using Blobs = std::unordered_map, - BlobKey::Hash, - BlobKey::Equal>; + using Shaders = std::unordered_map, + ShaderKey::Hash, + ShaderKey::Equal>; std::shared_ptr payload_; - Blobs blobs_; + Shaders shaders_; bool is_valid_ = false; - FML_DISALLOW_COPY_AND_ASSIGN(BlobLibrary); + FML_DISALLOW_COPY_AND_ASSIGN(ShaderArchive); }; } // namespace impeller diff --git a/impeller/blobcat/blobcat_main.cc b/impeller/shader_archive/shader_archive_main.cc similarity index 71% rename from impeller/blobcat/blobcat_main.cc rename to impeller/shader_archive/shader_archive_main.cc index 16a128a01d23a..7220a8596021d 100644 --- a/impeller/blobcat/blobcat_main.cc +++ b/impeller/shader_archive/shader_archive_main.cc @@ -6,12 +6,12 @@ #include #include "flutter/fml/command_line.h" -#include "impeller/blobcat/blob_writer.h" +#include "impeller/shader_archive/shader_archive_writer.h" namespace impeller { bool Main(const fml::CommandLine& command_line) { - BlobWriter writer; + ShaderArchiveWriter writer; std::string output; if (!command_line.GetOptionValue("output", &output)) { @@ -20,15 +20,15 @@ bool Main(const fml::CommandLine& command_line) { } for (const auto& input : command_line.GetOptionValues("input")) { - if (!writer.AddBlobAtPath(std::string{input})) { - std::cerr << "Could not add blob at path: " << input << std::endl; + if (!writer.AddShaderAtPath(std::string{input})) { + std::cerr << "Could not add shader at path: " << input << std::endl; return false; } } - auto blob = writer.CreateMapping(); - if (!blob) { - std::cerr << "Could not create combined shader blob." << std::endl; + auto archive = writer.CreateMapping(); + if (!archive) { + std::cerr << "Could not create shader archive." << std::endl; return false; } @@ -38,8 +38,9 @@ bool Main(const fml::CommandLine& command_line) { auto output_path = std::filesystem::absolute(std::filesystem::current_path() / output); if (!fml::WriteAtomically(current_directory, output_path.string().c_str(), - *blob)) { - std::cerr << "Could not write shader blob to path " << output << std::endl; + *archive)) { + std::cerr << "Could not write shader archive to path " << output + << std::endl; return false; } diff --git a/impeller/blobcat/blob_types.h b/impeller/shader_archive/shader_archive_types.h similarity index 89% rename from impeller/blobcat/blob_types.h rename to impeller/shader_archive/shader_archive_types.h index 37dea53998664..1c3e4b6f60de8 100644 --- a/impeller/blobcat/blob_types.h +++ b/impeller/shader_archive/shader_archive_types.h @@ -6,7 +6,7 @@ namespace impeller { -enum class BlobShaderType { +enum class ArchiveShaderType { kVertex, kFragment, kCompute, diff --git a/impeller/blobcat/blobcat_unittests.cc b/impeller/shader_archive/shader_archive_unittests.cc similarity index 51% rename from impeller/blobcat/blobcat_unittests.cc rename to impeller/shader_archive/shader_archive_unittests.cc index 6fc8783f652bd..ba4a3072c91b7 100644 --- a/impeller/blobcat/blobcat_unittests.cc +++ b/impeller/shader_archive/shader_archive_unittests.cc @@ -6,8 +6,8 @@ #include "flutter/fml/mapping.h" #include "flutter/testing/testing.h" -#include "impeller/blobcat/blob_library.h" -#include "impeller/blobcat/blob_writer.h" +#include "impeller/shader_archive/shader_archive.h" +#include "impeller/shader_archive/shader_archive_writer.h" namespace impeller { namespace testing { @@ -25,30 +25,30 @@ const std::string CreateStringFromMapping(const fml::Mapping& mapping) { mapping.GetSize()}; } -TEST(BlobTest, CanReadAndWriteBlobs) { - BlobWriter writer; - ASSERT_TRUE(writer.AddBlob(BlobShaderType::kVertex, "Hello", - CreateMappingFromString("World"))); - ASSERT_TRUE(writer.AddBlob(BlobShaderType::kFragment, "Foo", - CreateMappingFromString("Bar"))); - ASSERT_TRUE(writer.AddBlob(BlobShaderType::kVertex, "Baz", - CreateMappingFromString("Bang"))); - ASSERT_TRUE(writer.AddBlob(BlobShaderType::kVertex, "Ping", - CreateMappingFromString("Pong"))); - ASSERT_TRUE(writer.AddBlob(BlobShaderType::kFragment, "Pang", - CreateMappingFromString("World"))); +TEST(ShaderArchiveTest, CanReadAndWriteBlobs) { + ShaderArchiveWriter writer; + ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kVertex, "Hello", + CreateMappingFromString("World"))); + ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kFragment, "Foo", + CreateMappingFromString("Bar"))); + ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kVertex, "Baz", + CreateMappingFromString("Bang"))); + ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kVertex, "Ping", + CreateMappingFromString("Pong"))); + ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kFragment, "Pang", + CreateMappingFromString("World"))); auto mapping = writer.CreateMapping(); ASSERT_NE(mapping, nullptr); - BlobLibrary library(mapping); + ShaderArchive library(mapping); ASSERT_TRUE(library.IsValid()); ASSERT_EQ(library.GetShaderCount(), 5u); // Wrong type. - ASSERT_EQ(library.GetMapping(BlobShaderType::kFragment, "Hello"), nullptr); + ASSERT_EQ(library.GetMapping(ArchiveShaderType::kFragment, "Hello"), nullptr); - auto hello_vtx = library.GetMapping(BlobShaderType::kVertex, "Hello"); + auto hello_vtx = library.GetMapping(ArchiveShaderType::kVertex, "Hello"); ASSERT_NE(hello_vtx, nullptr); ASSERT_EQ(CreateStringFromMapping(*hello_vtx), "World"); } diff --git a/impeller/blobcat/blob_writer.cc b/impeller/shader_archive/shader_archive_writer.cc similarity index 58% rename from impeller/blobcat/blob_writer.cc rename to impeller/shader_archive/shader_archive_writer.cc index bafebbec2b8ff..83c0459f34ebe 100644 --- a/impeller/blobcat/blob_writer.cc +++ b/impeller/shader_archive/shader_archive_writer.cc @@ -2,33 +2,33 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "impeller/blobcat/blob_writer.h" +#include "impeller/shader_archive/shader_archive_writer.h" #include #include #include -#include "impeller/blobcat/blob_flatbuffers.h" +#include "impeller/shader_archive/shader_archive_flatbuffers.h" namespace impeller { -BlobWriter::BlobWriter() = default; +ShaderArchiveWriter::ShaderArchiveWriter() = default; -BlobWriter::~BlobWriter() = default; +ShaderArchiveWriter::~ShaderArchiveWriter() = default; -std::optional InferShaderTypefromFileExtension( +std::optional InferShaderTypefromFileExtension( const std::filesystem::path& path) { if (path == ".vert") { - return BlobShaderType::kVertex; + return ArchiveShaderType::kVertex; } else if (path == ".frag") { - return BlobShaderType::kFragment; + return ArchiveShaderType::kFragment; } else if (path == ".comp") { - return BlobShaderType::kCompute; + return ArchiveShaderType::kCompute; } return std::nullopt; } -bool BlobWriter::AddBlobAtPath(const std::string& std_path) { +bool ShaderArchiveWriter::AddShaderAtPath(const std::string& std_path) { std::filesystem::path path(std_path); if (path.stem().empty()) { @@ -68,50 +68,50 @@ bool BlobWriter::AddBlobAtPath(const std::string& std_path) { return false; } - return AddBlob(shader_type.value(), shader_name, std::move(file_mapping)); + return AddShader(shader_type.value(), shader_name, std::move(file_mapping)); } -bool BlobWriter::AddBlob(BlobShaderType type, - std::string name, - std::shared_ptr mapping) { +bool ShaderArchiveWriter::AddShader(ArchiveShaderType type, + std::string name, + std::shared_ptr mapping) { if (name.empty() || !mapping || mapping->GetMapping() == nullptr) { return false; } - blob_descriptions_.emplace_back( - BlobDescription{type, std::move(name), std::move(mapping)}); + shader_descriptions_.emplace_back( + ShaderDescription{type, std::move(name), std::move(mapping)}); return true; } -constexpr fb::Stage ToStage(BlobShaderType type) { +constexpr fb::Stage ToStage(ArchiveShaderType type) { switch (type) { - case BlobShaderType::kVertex: + case ArchiveShaderType::kVertex: return fb::Stage::kVertex; - case BlobShaderType::kFragment: + case ArchiveShaderType::kFragment: return fb::Stage::kFragment; - case BlobShaderType::kCompute: + case ArchiveShaderType::kCompute: return fb::Stage::kCompute; } FML_UNREACHABLE(); } -std::shared_ptr BlobWriter::CreateMapping() const { - fb::BlobLibraryT blobs; - for (const auto& blob_description : blob_descriptions_) { - auto mapping = blob_description.mapping; +std::shared_ptr ShaderArchiveWriter::CreateMapping() const { + fb::ShaderArchiveT shader_archive; + for (const auto& shader_description : shader_descriptions_) { + auto mapping = shader_description.mapping; if (!mapping) { return nullptr; } - auto desc = std::make_unique(); - desc->name = blob_description.name; - desc->stage = ToStage(blob_description.type); + auto desc = std::make_unique(); + desc->name = shader_description.name; + desc->stage = ToStage(shader_description.type); desc->mapping = {mapping->GetMapping(), mapping->GetMapping() + mapping->GetSize()}; - blobs.items.emplace_back(std::move(desc)); + shader_archive.items.emplace_back(std::move(desc)); } auto builder = std::make_shared(); - builder->Finish(fb::BlobLibrary::Pack(*builder.get(), &blobs), - fb::BlobLibraryIdentifier()); + builder->Finish(fb::ShaderArchive::Pack(*builder.get(), &shader_archive), + fb::ShaderArchiveIdentifier()); return std::make_shared(builder->GetBufferPointer(), builder->GetSize(), [builder](auto, auto) {}); diff --git a/impeller/shader_archive/shader_archive_writer.h b/impeller/shader_archive/shader_archive_writer.h new file mode 100644 index 0000000000000..1b54f1e9931dc --- /dev/null +++ b/impeller/shader_archive/shader_archive_writer.h @@ -0,0 +1,43 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include +#include +#include + +#include "flutter/fml/macros.h" +#include "flutter/fml/mapping.h" +#include "impeller/shader_archive/shader_archive_types.h" + +namespace impeller { + +class ShaderArchiveWriter { + public: + ShaderArchiveWriter(); + + ~ShaderArchiveWriter(); + + [[nodiscard]] bool AddShaderAtPath(const std::string& path); + + [[nodiscard]] bool AddShader(ArchiveShaderType type, + std::string name, + std::shared_ptr mapping); + + std::shared_ptr CreateMapping() const; + + private: + struct ShaderDescription { + ArchiveShaderType type; + std::string name; + std::shared_ptr mapping; + }; + + std::vector shader_descriptions_; + + FML_DISALLOW_COPY_AND_ASSIGN(ShaderArchiveWriter); +}; + +} // namespace impeller diff --git a/impeller/tools/impeller.gni b/impeller/tools/impeller.gni index 15caa5631c472..69bd645da1dfd 100644 --- a/impeller/tools/impeller.gni +++ b/impeller/tools/impeller.gni @@ -492,14 +492,14 @@ template("_impeller_shaders_metal") { } } -template("blobcat_library") { +template("shader_archive") { assert(defined(invoker.shaders), "The shaders to build the library from must be specified.") assert(defined(invoker.deps), "Target dependencies must be specified.") - output_file = "$target_gen_dir/$target_name.shaderblob" + output_file = "$target_gen_dir/$target_name.shar" compiled_action(target_name) { - tool = "//flutter/impeller/blobcat" + tool = "//flutter/impeller/shader_archive:shader_archiver" inputs = invoker.shaders outputs = [ output_file ] output_path_rebased = rebase_path(output_file, root_build_dir) @@ -565,7 +565,7 @@ template("_impeller_shaders_gles") { } gles_lib = "genlib_$target_name" - blobcat_library(gles_lib) { + shader_archive(gles_lib) { shaders = gles_shaders deps = [ ":$impellerc_gles" ] } @@ -641,7 +641,7 @@ template("_impeller_shaders_vk") { } vk_lib = "genlib_$target_name" - blobcat_library(vk_lib) { + shader_archive(vk_lib) { shaders = vk_shaders deps = [ ":$impellerc_vk" ] }