forked from firka/flutter
Pipeline descriptor comparators.
This commit is contained in:
@@ -6,6 +6,8 @@ import("//flutter/impeller/tools/impeller.gni")
|
||||
|
||||
impeller_component("compositor") {
|
||||
sources = [
|
||||
"comparable.cc",
|
||||
"comparable.h",
|
||||
"context.h",
|
||||
"context.mm",
|
||||
"pipeline.h",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// 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/compositor/comparable.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
//
|
||||
|
||||
} // namespace impeller
|
||||
85
engine/src/flutter/impeller/impeller/compositor/comparable.h
Normal file
85
engine/src/flutter/impeller/impeller/compositor/comparable.h
Normal file
@@ -0,0 +1,85 @@
|
||||
// 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 <cstddef>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "flutter/fml/hash_combine.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class ComparableBase {};
|
||||
|
||||
template <class Type>
|
||||
class Comparable : ComparableBase {
|
||||
public:
|
||||
virtual std::size_t GetHash() const = 0;
|
||||
|
||||
virtual bool IsEqual(const Type& other) const = 0;
|
||||
};
|
||||
|
||||
template <
|
||||
class ComparableType,
|
||||
class = std::enable_if_t<std::is_base_of_v<ComparableBase, ComparableType>>>
|
||||
struct ComparableHash {
|
||||
std::size_t operator()(const ComparableType& object) const {
|
||||
return object.GetHash();
|
||||
}
|
||||
};
|
||||
|
||||
template <
|
||||
class ComparableType,
|
||||
class = std::enable_if_t<std::is_base_of_v<ComparableBase, ComparableType>>>
|
||||
struct ComparableEqual {
|
||||
bool operator()(const ComparableType& lhs, const ComparableType& rhs) const {
|
||||
return lhs.IsEqual(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
template <
|
||||
class ComparableType,
|
||||
class = std::enable_if_t<std::is_base_of_v<ComparableBase, ComparableType>>>
|
||||
bool DeepComparePointer(const std::shared_ptr<ComparableType>& lhs,
|
||||
const std::shared_ptr<ComparableType>& rhs) {
|
||||
if (lhs == rhs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lhs && rhs) {
|
||||
return lhs->IsEqual(*rhs);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <
|
||||
class Key,
|
||||
class ComparableType,
|
||||
class = std::enable_if_t<std::is_base_of_v<ComparableBase, ComparableType>>>
|
||||
bool DeepCompareMap(const std::map<Key, std::shared_ptr<ComparableType>>& lhs,
|
||||
const std::map<Key, std::shared_ptr<ComparableType>>& rhs) {
|
||||
if (lhs.size() != rhs.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto i = lhs.begin(), j = rhs.begin(); i != lhs.end(); i++, j++) {
|
||||
if (i->first != j->first) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DeepComparePointer(i->second, j->second)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <type_traits>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/compositor/comparable.h"
|
||||
#include "impeller/shader_glue/shader_types.h"
|
||||
|
||||
namespace impeller {
|
||||
@@ -21,14 +22,8 @@ namespace impeller {
|
||||
class ShaderFunction;
|
||||
class VertexDescriptor;
|
||||
|
||||
class PipelineDescriptor {
|
||||
class PipelineDescriptor : public Comparable<PipelineDescriptor> {
|
||||
public:
|
||||
struct HashEqual {
|
||||
std::size_t operator()(const PipelineDescriptor& des) const;
|
||||
bool operator()(const PipelineDescriptor& d1,
|
||||
const PipelineDescriptor& d2) const;
|
||||
};
|
||||
|
||||
PipelineDescriptor();
|
||||
|
||||
~PipelineDescriptor();
|
||||
@@ -45,13 +40,17 @@ class PipelineDescriptor {
|
||||
|
||||
MTLRenderPipelineDescriptor* GetMTLRenderPipelineDescriptor() const;
|
||||
|
||||
// Comparable<PipelineDescriptor>
|
||||
std::size_t GetHash() const override;
|
||||
|
||||
// Comparable<PipelineDescriptor>
|
||||
bool IsEqual(const PipelineDescriptor& other) const override;
|
||||
|
||||
private:
|
||||
std::string label_;
|
||||
size_t sample_count_ = 1;
|
||||
std::map<ShaderStage, std::shared_ptr<const ShaderFunction>> entrypoints_;
|
||||
std::shared_ptr<VertexDescriptor> vertex_descriptor_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(PipelineDescriptor);
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#include "impeller/compositor/pipeline_descriptor.h"
|
||||
|
||||
#include "flutter/fml/hash_combine.h"
|
||||
#include "impeller/compositor/shader_library.h"
|
||||
#include "impeller/compositor/vertex_descriptor.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -13,18 +13,29 @@ PipelineDescriptor::PipelineDescriptor() = default;
|
||||
|
||||
PipelineDescriptor::~PipelineDescriptor() = default;
|
||||
|
||||
std::size_t PipelineDescriptor::HashEqual::operator()(
|
||||
const PipelineDescriptor& des) const {
|
||||
// Comparable<PipelineDescriptor>
|
||||
std::size_t PipelineDescriptor::GetHash() const {
|
||||
auto seed = fml::HashCombine();
|
||||
fml::HashCombineSeed(seed, des.label_);
|
||||
for (const auto& entry : des.entrypoints_) {
|
||||
fml::HashCombineSeed(seed, entry)
|
||||
fml::HashCombineSeed(seed, label_);
|
||||
fml::HashCombineSeed(seed, sample_count_);
|
||||
for (const auto& entry : entrypoints_) {
|
||||
fml::HashCombineSeed(seed, entry.first);
|
||||
if (auto second = entry.second) {
|
||||
fml::HashCombineSeed(seed, second->GetHash());
|
||||
}
|
||||
}
|
||||
if (vertex_descriptor_) {
|
||||
fml::HashCombineSeed(seed, vertex_descriptor_->GetHash());
|
||||
}
|
||||
return seed;
|
||||
}
|
||||
|
||||
bool PipelineDescriptor::HashEqual::operator()(
|
||||
const PipelineDescriptor& d1,
|
||||
const PipelineDescriptor& d2) const {}
|
||||
// Comparable<PipelineDescriptor>
|
||||
bool PipelineDescriptor::IsEqual(const PipelineDescriptor& other) const {
|
||||
return label_ == other.label_ && sample_count_ == other.sample_count_ &&
|
||||
DeepCompareMap(entrypoints_, other.entrypoints_) &&
|
||||
DeepComparePointer(vertex_descriptor_, other.vertex_descriptor_);
|
||||
}
|
||||
|
||||
PipelineDescriptor& PipelineDescriptor::SetLabel(
|
||||
const std::string_view& label) {
|
||||
|
||||
@@ -27,8 +27,8 @@ class PipelineLibrary {
|
||||
private:
|
||||
using Pipelines = std::unordered_map<PipelineDescriptor,
|
||||
std::shared_ptr<const Pipeline>,
|
||||
PipelineDescriptor::HashEqual,
|
||||
PipelineDescriptor::HashEqual>;
|
||||
ComparableHash<PipelineDescriptor>,
|
||||
ComparableEqual<PipelineDescriptor>>;
|
||||
id<MTLDevice> device_;
|
||||
Pipelines pipelines_;
|
||||
|
||||
|
||||
@@ -23,6 +23,10 @@ std::future<std::shared_ptr<Pipeline>> PipelineLibrary::GetRenderPipeline(
|
||||
return future;
|
||||
}
|
||||
|
||||
// WIP Pipeline is not saved.
|
||||
|
||||
pipelines_[descriptor] = nullptr;
|
||||
|
||||
auto completion_handler =
|
||||
^(id<MTLRenderPipelineState> _Nullable render_pipeline_state,
|
||||
NSError* _Nullable error) {
|
||||
|
||||
@@ -13,20 +13,27 @@
|
||||
|
||||
#include "flutter/fml/hash_combine.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/compositor/comparable.h"
|
||||
#include "impeller/shader_glue/shader_types.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class Context;
|
||||
|
||||
class ShaderFunction {
|
||||
class ShaderFunction : public Comparable<ShaderFunction> {
|
||||
public:
|
||||
~ShaderFunction();
|
||||
virtual ~ShaderFunction();
|
||||
|
||||
ShaderStage GetStage() const;
|
||||
|
||||
id<MTLFunction> GetMTLFunction() const;
|
||||
|
||||
// Comparable<ShaderFunction>
|
||||
std::size_t GetHash() const override;
|
||||
|
||||
// Comparable<ShaderFunction>
|
||||
bool IsEqual(const ShaderFunction& other) const override;
|
||||
|
||||
private:
|
||||
friend class ShaderLibrary;
|
||||
|
||||
|
||||
@@ -5,14 +5,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/compositor/comparable.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class VertexDescriptor {
|
||||
class VertexDescriptor : public Comparable<VertexDescriptor> {
|
||||
public:
|
||||
VertexDescriptor();
|
||||
|
||||
~VertexDescriptor();
|
||||
virtual ~VertexDescriptor();
|
||||
|
||||
// Comparable<VertexDescriptor>
|
||||
std::size_t GetHash() const override;
|
||||
|
||||
// Comparable<VertexDescriptor>
|
||||
bool IsEqual(const VertexDescriptor& other) const override;
|
||||
|
||||
private:
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(VertexDescriptor);
|
||||
|
||||
Reference in New Issue
Block a user