All creation of pipeline variants from a pipeline.
This commit is contained in:
@@ -10,6 +10,8 @@ impeller_component("base") {
|
||||
"allocation.h",
|
||||
"base.h",
|
||||
"config.h",
|
||||
"promise.cc",
|
||||
"promise.h",
|
||||
"strings.cc",
|
||||
"strings.h",
|
||||
"validation.cc",
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "impeller/base/promise.h"
|
||||
#include "impeller/base/strings.h"
|
||||
#include "impeller/base/validation.h"
|
||||
|
||||
11
engine/src/flutter/impeller/base/promise.cc
Normal file
11
engine/src/flutter/impeller/base/promise.cc
Normal file
@@ -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/base/promise.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
//
|
||||
|
||||
} // namespace impeller
|
||||
19
engine/src/flutter/impeller/base/promise.h
Normal file
19
engine/src/flutter/impeller/base/promise.h
Normal file
@@ -0,0 +1,19 @@
|
||||
// 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 <future>
|
||||
|
||||
namespace impeller {
|
||||
|
||||
template <class T>
|
||||
std::future<T> RealizedFuture(T t) {
|
||||
std::promise<T> promise;
|
||||
auto future = promise.get_future();
|
||||
promise.set_value(std::move(t));
|
||||
return future;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
@@ -81,24 +81,33 @@ std::future<std::shared_ptr<Pipeline>> PipelineLibraryMTL::GetRenderPipeline(
|
||||
// created till the first instance of the creation invokes its completion
|
||||
// callback.
|
||||
|
||||
auto thiz = shared_from_this();
|
||||
auto weak_this = weak_from_this();
|
||||
|
||||
auto completion_handler =
|
||||
^(id<MTLRenderPipelineState> _Nullable render_pipeline_state,
|
||||
NSError* _Nullable error) {
|
||||
if (error != nil) {
|
||||
FML_LOG(ERROR) << "Could not create render pipeline: "
|
||||
VALIDATION_LOG << "Could not create render pipeline: "
|
||||
<< error.localizedDescription.UTF8String;
|
||||
promise->set_value(nullptr);
|
||||
} else {
|
||||
auto new_pipeline = std::shared_ptr<PipelineMTL>(new PipelineMTL(
|
||||
descriptor, //
|
||||
render_pipeline_state, //
|
||||
CreateDepthStencilDescriptor(descriptor, device_) //
|
||||
));
|
||||
promise->set_value(new_pipeline);
|
||||
this->SavePipeline(descriptor, new_pipeline);
|
||||
return;
|
||||
}
|
||||
|
||||
auto strong_this = weak_this.lock();
|
||||
if (!strong_this) {
|
||||
VALIDATION_LOG << "Library was collected before a pending pipeline "
|
||||
"creation could finish.";
|
||||
promise->set_value(nullptr);
|
||||
return;
|
||||
}
|
||||
auto new_pipeline = std::shared_ptr<PipelineMTL>(new PipelineMTL(
|
||||
weak_this,
|
||||
descriptor, //
|
||||
render_pipeline_state, //
|
||||
CreateDepthStencilDescriptor(descriptor, device_) //
|
||||
));
|
||||
promise->set_value(new_pipeline);
|
||||
this->SavePipeline(descriptor, new_pipeline);
|
||||
};
|
||||
[device_ newRenderPipelineStateWithDescriptor:GetMTLRenderPipelineDescriptor(
|
||||
descriptor)
|
||||
|
||||
@@ -30,7 +30,8 @@ class PipelineMTL final : public Pipeline,
|
||||
id<MTLDepthStencilState> depth_stencil_state_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
PipelineMTL(PipelineDescriptor desc,
|
||||
PipelineMTL(std::weak_ptr<PipelineLibrary> library,
|
||||
PipelineDescriptor desc,
|
||||
id<MTLRenderPipelineState> state,
|
||||
id<MTLDepthStencilState> depth_stencil_state);
|
||||
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
PipelineMTL::PipelineMTL(PipelineDescriptor desc,
|
||||
PipelineMTL::PipelineMTL(std::weak_ptr<PipelineLibrary> library,
|
||||
PipelineDescriptor desc,
|
||||
id<MTLRenderPipelineState> state,
|
||||
id<MTLDepthStencilState> depth_stencil_state)
|
||||
: Pipeline(std::move(desc)),
|
||||
: Pipeline(std::move(library), std::move(desc)),
|
||||
pipeline_state_(state),
|
||||
depth_stencil_state_(depth_stencil_state) {
|
||||
if (!pipeline_state_) {
|
||||
|
||||
@@ -4,22 +4,22 @@
|
||||
|
||||
#include "impeller/renderer/pipeline.h"
|
||||
|
||||
#include "impeller/base/base.h"
|
||||
#include "impeller/renderer/context.h"
|
||||
#include "impeller/renderer/pipeline_library.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
Pipeline::Pipeline(PipelineDescriptor desc) : desc_(std::move(desc)) {}
|
||||
Pipeline::Pipeline(std::weak_ptr<PipelineLibrary> library,
|
||||
PipelineDescriptor desc)
|
||||
: library_(std::move(library)), desc_(std::move(desc)) {}
|
||||
|
||||
Pipeline::~Pipeline() = default;
|
||||
|
||||
PipelineFuture CreatePipelineFuture(const Context& context,
|
||||
std::optional<PipelineDescriptor> desc) {
|
||||
if (!context.IsValid()) {
|
||||
std::promise<std::shared_ptr<Pipeline>> promise;
|
||||
auto future = promise.get_future();
|
||||
promise.set_value(nullptr);
|
||||
return future;
|
||||
return RealizedFuture<std::shared_ptr<Pipeline>>(nullptr);
|
||||
}
|
||||
|
||||
return context.GetPipelineLibrary()->GetRenderPipeline(std::move(desc));
|
||||
@@ -29,4 +29,24 @@ const PipelineDescriptor& Pipeline::GetDescriptor() const {
|
||||
return desc_;
|
||||
}
|
||||
|
||||
PipelineFuture Pipeline::CreateVariant(
|
||||
std::function<void(PipelineDescriptor& desc)> descriptor_callback) const {
|
||||
if (!descriptor_callback) {
|
||||
return RealizedFuture<std::shared_ptr<Pipeline>>(nullptr);
|
||||
}
|
||||
|
||||
auto copied_desc = desc_;
|
||||
|
||||
descriptor_callback(copied_desc);
|
||||
|
||||
auto library = library_.lock();
|
||||
if (!library) {
|
||||
VALIDATION_LOG << "The library from which this pipeline was created was "
|
||||
"already collected.";
|
||||
return RealizedFuture<std::shared_ptr<Pipeline>>(nullptr);
|
||||
}
|
||||
|
||||
return library->GetRenderPipeline(std::move(copied_desc));
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -44,10 +44,14 @@ class Pipeline {
|
||||
|
||||
const PipelineDescriptor& GetDescriptor() const;
|
||||
|
||||
PipelineFuture CreateVariant(
|
||||
std::function<void(PipelineDescriptor& desc)> descriptor_callback) const;
|
||||
|
||||
protected:
|
||||
Pipeline(PipelineDescriptor desc);
|
||||
Pipeline(std::weak_ptr<PipelineLibrary> library, PipelineDescriptor desc);
|
||||
|
||||
private:
|
||||
const std::weak_ptr<PipelineLibrary> library_;
|
||||
const PipelineDescriptor desc_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Pipeline);
|
||||
|
||||
Reference in New Issue
Block a user