Shader function quality.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
//
|
||||
static std::atomic_size_t sLastID;
|
||||
UniqueID::UniqueID() : id(++sLastID) {}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -15,6 +15,16 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
struct UniqueID {
|
||||
size_t id;
|
||||
|
||||
UniqueID();
|
||||
|
||||
constexpr bool operator==(const UniqueID& other) const {
|
||||
return id == other.id;
|
||||
}
|
||||
};
|
||||
|
||||
class ComparableBase {};
|
||||
|
||||
template <class Type>
|
||||
@@ -83,3 +93,14 @@ bool DeepCompareMap(const std::map<Key, std::shared_ptr<ComparableType>>& lhs,
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<impeller::UniqueID> {
|
||||
constexpr std::size_t operator()(const impeller::UniqueID& id) {
|
||||
return id.id;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <Metal/Metal.h>
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
@@ -15,10 +16,8 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
class PipelineLibrary {
|
||||
class PipelineLibrary : public std::enable_shared_from_this<PipelineLibrary> {
|
||||
public:
|
||||
PipelineLibrary(id<MTLDevice> device);
|
||||
|
||||
~PipelineLibrary();
|
||||
|
||||
std::future<std::shared_ptr<Pipeline>> GetRenderPipeline(
|
||||
@@ -32,6 +31,11 @@ class PipelineLibrary {
|
||||
id<MTLDevice> device_;
|
||||
Pipelines pipelines_;
|
||||
|
||||
PipelineLibrary(id<MTLDevice> device);
|
||||
|
||||
void SavePipeline(PipelineDescriptor descriptor,
|
||||
std::shared_ptr<const Pipeline> pipeline);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(PipelineLibrary);
|
||||
};
|
||||
|
||||
|
||||
@@ -23,9 +23,7 @@ std::future<std::shared_ptr<Pipeline>> PipelineLibrary::GetRenderPipeline(
|
||||
return future;
|
||||
}
|
||||
|
||||
// WIP Pipeline is not saved.
|
||||
|
||||
pipelines_[descriptor] = nullptr;
|
||||
auto thiz = shared_from_this();
|
||||
|
||||
auto completion_handler =
|
||||
^(id<MTLRenderPipelineState> _Nullable render_pipeline_state,
|
||||
@@ -35,8 +33,10 @@ std::future<std::shared_ptr<Pipeline>> PipelineLibrary::GetRenderPipeline(
|
||||
<< error.localizedDescription.UTF8String;
|
||||
promise->set_value(nullptr);
|
||||
} else {
|
||||
promise->set_value(
|
||||
std::shared_ptr<Pipeline>(new Pipeline(render_pipeline_state)));
|
||||
auto new_pipeline =
|
||||
std::shared_ptr<Pipeline>(new Pipeline(render_pipeline_state));
|
||||
promise->set_value(new_pipeline);
|
||||
this->SavePipeline(descriptor, new_pipeline);
|
||||
}
|
||||
};
|
||||
[device_
|
||||
@@ -46,4 +46,9 @@ std::future<std::shared_ptr<Pipeline>> PipelineLibrary::GetRenderPipeline(
|
||||
return future;
|
||||
}
|
||||
|
||||
void PipelineLibrary::SavePipeline(PipelineDescriptor descriptor,
|
||||
std::shared_ptr<const Pipeline> pipeline) {
|
||||
pipelines_[descriptor] = std::move(pipeline);
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -21,19 +21,24 @@ class ShaderFunction : public Comparable<ShaderFunction> {
|
||||
|
||||
id<MTLFunction> GetMTLFunction() const;
|
||||
|
||||
// Comparable<ShaderFunction>
|
||||
// |Comparable<ShaderFunction>|
|
||||
std::size_t GetHash() const override;
|
||||
|
||||
// Comparable<ShaderFunction>
|
||||
// |Comparable<ShaderFunction>|
|
||||
bool IsEqual(const ShaderFunction& other) const override;
|
||||
|
||||
private:
|
||||
friend class ShaderLibrary;
|
||||
|
||||
UniqueID parent_library_id_;
|
||||
id<MTLFunction> function_ = nullptr;
|
||||
std::string name_;
|
||||
ShaderStage stage_;
|
||||
|
||||
ShaderFunction(id<MTLFunction> function, ShaderStage stage);
|
||||
ShaderFunction(UniqueID parent_library_id,
|
||||
id<MTLFunction> function,
|
||||
std::string name,
|
||||
ShaderStage stage);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ShaderFunction);
|
||||
};
|
||||
|
||||
@@ -6,8 +6,14 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
ShaderFunction::ShaderFunction(id<MTLFunction> function, ShaderStage stage)
|
||||
: function_(function), stage_(stage) {}
|
||||
ShaderFunction::ShaderFunction(UniqueID parent_library_id,
|
||||
id<MTLFunction> function,
|
||||
std::string name,
|
||||
ShaderStage stage)
|
||||
: parent_library_id_(parent_library_id),
|
||||
function_(function),
|
||||
name_(std::move(name)),
|
||||
stage_(stage) {}
|
||||
|
||||
ShaderFunction::~ShaderFunction() = default;
|
||||
|
||||
@@ -19,4 +25,15 @@ ShaderStage ShaderFunction::GetStage() const {
|
||||
return stage_;
|
||||
}
|
||||
|
||||
// |Comparable<ShaderFunction>|
|
||||
std::size_t ShaderFunction::GetHash() const {
|
||||
return fml::HashCombine(parent_library_id_, name_, stage_);
|
||||
}
|
||||
|
||||
// |Comparable<ShaderFunction>|
|
||||
bool ShaderFunction::IsEqual(const ShaderFunction& other) const {
|
||||
return parent_library_id_ == other.parent_library_id_ &&
|
||||
name_ == other.name_ && stage_ == other.stage_;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/compositor/comparable.h"
|
||||
#include "impeller/compositor/shader_function.h"
|
||||
|
||||
namespace impeller {
|
||||
@@ -50,11 +51,13 @@ class ShaderLibrary {
|
||||
};
|
||||
};
|
||||
|
||||
id<MTLLibrary> library_ = nullptr;
|
||||
using Functions = std::unordered_map<ShaderKey,
|
||||
std::shared_ptr<const ShaderFunction>,
|
||||
ShaderKey::Hash,
|
||||
ShaderKey::Equal>;
|
||||
|
||||
UniqueID library_id_;
|
||||
id<MTLLibrary> library_ = nullptr;
|
||||
Functions functions_;
|
||||
|
||||
ShaderLibrary(id<MTLLibrary> library);
|
||||
|
||||
@@ -24,8 +24,8 @@ std::shared_ptr<const ShaderFunction> ShaderLibrary::GetFunction(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto func =
|
||||
std::shared_ptr<ShaderFunction>(new ShaderFunction(function, stage));
|
||||
auto func = std::shared_ptr<ShaderFunction>(new ShaderFunction(
|
||||
library_id_, function, {name.data(), name.size()}, stage));
|
||||
functions_[key] = func;
|
||||
return func;
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ class VertexDescriptor : public Comparable<VertexDescriptor> {
|
||||
|
||||
virtual ~VertexDescriptor();
|
||||
|
||||
// Comparable<VertexDescriptor>
|
||||
//| Comparable<VertexDescriptor>|
|
||||
std::size_t GetHash() const override;
|
||||
|
||||
// Comparable<VertexDescriptor>
|
||||
// |Comparable<VertexDescriptor>|
|
||||
bool IsEqual(const VertexDescriptor& other) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -4,10 +4,24 @@
|
||||
|
||||
#include "impeller/compositor/vertex_descriptor.h"
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
VertexDescriptor::VertexDescriptor() = default;
|
||||
|
||||
VertexDescriptor::~VertexDescriptor() = default;
|
||||
|
||||
//| Comparable<VertexDescriptor>|
|
||||
std::size_t VertexDescriptor::GetHash() const {
|
||||
FML_CHECK(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// |Comparable<VertexDescriptor>|
|
||||
bool VertexDescriptor::IsEqual(const VertexDescriptor& other) const {
|
||||
FML_CHECK(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
Reference in New Issue
Block a user