Allow render passes to record commands.

This commit is contained in:
Chinmay Garde
2021-06-07 12:30:14 -07:00
committed by Dan Field
parent be69b42bf9
commit 51f5e759ee
6 changed files with 29 additions and 4 deletions

View File

@@ -28,6 +28,8 @@ class BufferView final : public BufferBase {
// |BufferBase|
~BufferView() = default;
const BufferBase* GetBuffer() const { return parent_.get(); }
// |BufferBase|
uint8_t* GetMapping() const override {
return parent_->GetMapping() + range_in_parent_.offset;
@@ -44,8 +46,6 @@ class BufferView final : public BufferBase {
BufferView(std::shared_ptr<BufferBase> parent, Range range_in_parent)
: parent_(std::move(parent)), range_in_parent_(range_in_parent) {}
FML_DISALLOW_COPY_AND_ASSIGN(BufferView);
};
class Buffer {

View File

@@ -27,6 +27,8 @@ struct Command {
Bindings vertex_bindings;
Bindings fragment_bindings;
BufferView index_buffer;
constexpr operator bool() const { return pipeline && pipeline->IsValid(); }
};
} // namespace impeller

View File

@@ -21,12 +21,15 @@ class Pipeline {
~Pipeline();
bool IsValid() const;
private:
friend class PipelineLibrary;
Type type_ = Type::kUnknown;
id<MTLRenderPipelineState> state_;
id<MTLDepthStencilState> depth_stencil_state_;
bool is_valid_ = false;
Pipeline(id<MTLRenderPipelineState> state,
id<MTLDepthStencilState> depth_stencil_state);

View File

@@ -9,11 +9,17 @@ namespace impeller {
Pipeline::Pipeline(id<MTLRenderPipelineState> state,
id<MTLDepthStencilState> depth_stencil_state)
: state_(state), depth_stencil_state_(depth_stencil_state) {
if (state_ != nil) {
type_ = Type::kRender;
if (!state_) {
return;
}
type_ = Type::kRender;
is_valid_ = true;
}
Pipeline::~Pipeline() = default;
bool Pipeline::IsValid() const {
return is_valid_;
}
} // namespace impeller

View File

@@ -7,8 +7,10 @@
#include <Metal/Metal.h>
#include <map>
#include <vector>
#include "flutter/fml/macros.h"
#include "impeller/compositor/command.h"
#include "impeller/compositor/formats.h"
#include "impeller/compositor/texture.h"
#include "impeller/geometry/color.h"
@@ -68,6 +70,8 @@ class RenderPass {
bool IsValid() const;
bool Record(Command command);
bool Encode() const;
private:
@@ -75,6 +79,7 @@ class RenderPass {
id<MTLCommandBuffer> buffer_ = nil;
MTLRenderPassDescriptor* desc_ = nil;
std::vector<Command> commands_;
bool is_valid_ = false;
RenderPass(id<MTLCommandBuffer> buffer, const RenderPassDescriptor& desc);

View File

@@ -140,4 +140,13 @@ bool RenderPass::Encode() const {
return true;
}
bool RenderPass::Record(Command command) {
if (!command) {
return false;
}
commands_.emplace_back(std::move(command));
return true;
}
} // namespace impeller