[Impeller] Rename blobcat to shader_archive(r). (flutter/engine#47247)
Rather confusingly, shader library were named after the tool that concatenated shader blobs. This changes the name to be less confusing. In the future, I am reworking this to create libraries for multiple backends. No functional change. I just changed the names of classes and variables.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 <array>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#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<fml::Mapping> 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<fml::NonOwnedMapping>(
|
||||
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<fml::Mapping> 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<bool(BlobShaderType type,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<fml::Mapping>& 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
|
||||
@@ -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 <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<fml::Mapping> mapping);
|
||||
|
||||
std::shared_ptr<fml::Mapping> CreateMapping() const;
|
||||
|
||||
private:
|
||||
struct BlobDescription {
|
||||
BlobShaderType type;
|
||||
std::string name;
|
||||
std::shared_ptr<fml::Mapping> mapping;
|
||||
};
|
||||
|
||||
std::vector<BlobDescription> blob_descriptions_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(BlobWriter);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
@@ -93,7 +93,7 @@ impeller_component("gles") {
|
||||
|
||||
public_deps = [
|
||||
"../../:renderer",
|
||||
"../../../blobcat:blobcat_lib",
|
||||
"../../../shader_archive",
|
||||
"//flutter/fml",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
102
engine/src/flutter/impeller/shader_archive/shader_archive.cc
Normal file
102
engine/src/flutter/impeller/shader_archive/shader_archive.cc
Normal file
@@ -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 <array>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#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<fml::Mapping> 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<fml::NonOwnedMapping>(
|
||||
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<fml::Mapping> 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<bool(ArchiveShaderType type,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<fml::Mapping>& 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
|
||||
@@ -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";
|
||||
@@ -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<fml::Mapping> payload);
|
||||
explicit ShaderArchive(std::shared_ptr<fml::Mapping> payload);
|
||||
|
||||
BlobLibrary(BlobLibrary&&);
|
||||
ShaderArchive(ShaderArchive&&);
|
||||
|
||||
~BlobLibrary();
|
||||
~ShaderArchive();
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
size_t GetShaderCount() const;
|
||||
|
||||
std::shared_ptr<fml::Mapping> GetMapping(BlobShaderType type,
|
||||
std::shared_ptr<fml::Mapping> GetMapping(ArchiveShaderType type,
|
||||
std::string name) const;
|
||||
|
||||
size_t IterateAllBlobs(
|
||||
const std::function<bool(BlobShaderType type,
|
||||
size_t IterateAllShaders(
|
||||
const std::function<bool(ArchiveShaderType type,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<fml::Mapping>& 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<std::underlying_type_t<decltype(key.type)>>(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,
|
||||
std::shared_ptr<fml::Mapping>,
|
||||
BlobKey::Hash,
|
||||
BlobKey::Equal>;
|
||||
using Shaders = std::unordered_map<ShaderKey,
|
||||
std::shared_ptr<fml::Mapping>,
|
||||
ShaderKey::Hash,
|
||||
ShaderKey::Equal>;
|
||||
|
||||
std::shared_ptr<fml::Mapping> payload_;
|
||||
Blobs blobs_;
|
||||
Shaders shaders_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(BlobLibrary);
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ShaderArchive);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
@@ -6,12 +6,12 @@
|
||||
#include <iostream>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
enum class BlobShaderType {
|
||||
enum class ArchiveShaderType {
|
||||
kVertex,
|
||||
kFragment,
|
||||
kCompute,
|
||||
@@ -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");
|
||||
}
|
||||
@@ -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 <array>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
|
||||
#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<BlobShaderType> InferShaderTypefromFileExtension(
|
||||
std::optional<ArchiveShaderType> 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<fml::Mapping> mapping) {
|
||||
bool ShaderArchiveWriter::AddShader(ArchiveShaderType type,
|
||||
std::string name,
|
||||
std::shared_ptr<fml::Mapping> 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<fml::Mapping> BlobWriter::CreateMapping() const {
|
||||
fb::BlobLibraryT blobs;
|
||||
for (const auto& blob_description : blob_descriptions_) {
|
||||
auto mapping = blob_description.mapping;
|
||||
std::shared_ptr<fml::Mapping> 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<fb::BlobT>();
|
||||
desc->name = blob_description.name;
|
||||
desc->stage = ToStage(blob_description.type);
|
||||
auto desc = std::make_unique<fb::ShaderBlobT>();
|
||||
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<flatbuffers::FlatBufferBuilder>();
|
||||
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<fml::NonOwnedMapping>(builder->GetBufferPointer(),
|
||||
builder->GetSize(),
|
||||
[builder](auto, auto) {});
|
||||
@@ -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 <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<fml::Mapping> mapping);
|
||||
|
||||
std::shared_ptr<fml::Mapping> CreateMapping() const;
|
||||
|
||||
private:
|
||||
struct ShaderDescription {
|
||||
ArchiveShaderType type;
|
||||
std::string name;
|
||||
std::shared_ptr<fml::Mapping> mapping;
|
||||
};
|
||||
|
||||
std::vector<ShaderDescription> shader_descriptions_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ShaderArchiveWriter);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
@@ -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" ]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user