Pipeline state objects pass validation.
This commit is contained in:
@@ -11,6 +11,8 @@ constexpr std::string_view kReflectionHeaderTemplate = R"~~(
|
||||
// THIS FILE IS GENERATED BY impellerc.
|
||||
// DO NOT EDIT OR CHECK THIS INTO SOURCE CONTROL
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shader_types.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace impeller {
|
||||
|
||||
enum class PixelFormat {
|
||||
kUnknown,
|
||||
kPixelFormat_B8G8R8A8_UNormInt_SRGB,
|
||||
kPixelFormat_D32_Float_S8_UNormInt,
|
||||
};
|
||||
|
||||
enum class BlendFactor {
|
||||
|
||||
@@ -20,6 +20,10 @@ constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) {
|
||||
switch (format) {
|
||||
case PixelFormat::kUnknown:
|
||||
return MTLPixelFormatInvalid;
|
||||
case PixelFormat::kPixelFormat_B8G8R8A8_UNormInt_SRGB:
|
||||
return MTLPixelFormatBGRA8Unorm_sRGB;
|
||||
case PixelFormat::kPixelFormat_D32_Float_S8_UNormInt:
|
||||
return MTLPixelFormatDepth32Float_Stencil8;
|
||||
}
|
||||
return MTLPixelFormatInvalid;
|
||||
};
|
||||
|
||||
@@ -26,11 +26,11 @@ class HostBuffer final : public std::enable_shared_from_this<HostBuffer>,
|
||||
|
||||
private:
|
||||
mutable std::shared_ptr<DeviceBuffer> device_buffer_;
|
||||
mutable size_t device_buffer_generation_ = 0u;
|
||||
uint8_t* buffer_ = nullptr;
|
||||
size_t length_ = 0;
|
||||
size_t reserved_ = 0;
|
||||
size_t generation_ = 1u;
|
||||
mutable size_t device_buffer_generation_ = 0u;
|
||||
|
||||
// |Buffer|
|
||||
std::shared_ptr<const DeviceBuffer> GetDeviceBuffer(
|
||||
|
||||
@@ -54,7 +54,9 @@ class PipelineDescriptor : public Comparable<PipelineDescriptor> {
|
||||
StencilAttachmentDescriptor front,
|
||||
StencilAttachmentDescriptor back);
|
||||
|
||||
PipelineDescriptor& SetDepthStencilPixelFormat(PixelFormat format);
|
||||
PipelineDescriptor& SetDepthPixelFormat(PixelFormat format);
|
||||
|
||||
PipelineDescriptor& SetStencilPixelFormat(PixelFormat format);
|
||||
|
||||
MTLRenderPipelineDescriptor* GetMTLRenderPipelineDescriptor() const;
|
||||
|
||||
@@ -73,7 +75,8 @@ class PipelineDescriptor : public Comparable<PipelineDescriptor> {
|
||||
std::map<ShaderStage, std::shared_ptr<const ShaderFunction>> entrypoints_;
|
||||
std::map<size_t, ColorAttachmentDescriptor> color_attachment_descriptors_;
|
||||
std::shared_ptr<VertexDescriptor> vertex_descriptor_;
|
||||
PixelFormat depth_stencil_pixel_format_ = PixelFormat::kUnknown;
|
||||
PixelFormat depth_pixel_format_ = PixelFormat::kUnknown;
|
||||
PixelFormat stencil_pixel_format_ = PixelFormat::kUnknown;
|
||||
std::optional<DepthAttachmentDescriptor> depth_attachment_descriptor_;
|
||||
std::optional<StencilAttachmentDescriptor>
|
||||
front_stencil_attachment_descriptor_;
|
||||
|
||||
@@ -32,7 +32,8 @@ std::size_t PipelineDescriptor::GetHash() const {
|
||||
if (vertex_descriptor_) {
|
||||
fml::HashCombineSeed(seed, vertex_descriptor_->GetHash());
|
||||
}
|
||||
fml::HashCombineSeed(seed, depth_stencil_pixel_format_);
|
||||
fml::HashCombineSeed(seed, depth_pixel_format_);
|
||||
fml::HashCombineSeed(seed, stencil_pixel_format_);
|
||||
fml::HashCombineSeed(seed, depth_attachment_descriptor_);
|
||||
fml::HashCombineSeed(seed, front_stencil_attachment_descriptor_);
|
||||
fml::HashCombineSeed(seed, back_stencil_attachment_descriptor_);
|
||||
@@ -45,7 +46,8 @@ bool PipelineDescriptor::IsEqual(const PipelineDescriptor& other) const {
|
||||
DeepCompareMap(entrypoints_, other.entrypoints_) &&
|
||||
color_attachment_descriptors_ == other.color_attachment_descriptors_ &&
|
||||
DeepComparePointer(vertex_descriptor_, other.vertex_descriptor_) &&
|
||||
depth_stencil_pixel_format_ == other.depth_stencil_pixel_format_ &&
|
||||
stencil_pixel_format_ == other.stencil_pixel_format_ &&
|
||||
depth_pixel_format_ == other.depth_pixel_format_ &&
|
||||
depth_attachment_descriptor_ == other.depth_attachment_descriptor_ &&
|
||||
front_stencil_attachment_descriptor_ ==
|
||||
other.front_stencil_attachment_descriptor_ &&
|
||||
@@ -92,9 +94,15 @@ PipelineDescriptor& PipelineDescriptor::SetColorAttachmentDescriptor(
|
||||
return *this;
|
||||
}
|
||||
|
||||
PipelineDescriptor& PipelineDescriptor::SetDepthStencilPixelFormat(
|
||||
PipelineDescriptor& PipelineDescriptor::SetDepthPixelFormat(
|
||||
PixelFormat format) {
|
||||
depth_stencil_pixel_format_ = format;
|
||||
depth_pixel_format_ = format;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PipelineDescriptor& PipelineDescriptor::SetStencilPixelFormat(
|
||||
PixelFormat format) {
|
||||
stencil_pixel_format_ = format;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -141,10 +149,9 @@ PipelineDescriptor::GetMTLRenderPipelineDescriptor() const {
|
||||
ToMTLRenderPipelineColorAttachmentDescriptor(item.second);
|
||||
}
|
||||
|
||||
descriptor.depthAttachmentPixelFormat =
|
||||
ToMTLPixelFormat(depth_stencil_pixel_format_);
|
||||
descriptor.depthAttachmentPixelFormat = ToMTLPixelFormat(depth_pixel_format_);
|
||||
descriptor.stencilAttachmentPixelFormat =
|
||||
ToMTLPixelFormat(depth_stencil_pixel_format_);
|
||||
ToMTLPixelFormat(stencil_pixel_format_);
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@@ -70,9 +70,9 @@ class RenderPass {
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool Record(Command command);
|
||||
bool RecordCommand(Command command);
|
||||
|
||||
bool Encode(Allocator& transients_allocator) const;
|
||||
bool FinishEncoding(Allocator& transients_allocator) const;
|
||||
|
||||
private:
|
||||
friend class CommandBuffer;
|
||||
|
||||
@@ -131,7 +131,7 @@ bool RenderPass::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
bool RenderPass::Encode(Allocator& transients_allocator) const {
|
||||
bool RenderPass::FinishEncoding(Allocator& transients_allocator) const {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
@@ -234,7 +234,7 @@ bool RenderPass::EncodeCommands(Allocator& allocator,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderPass::Record(Command command) {
|
||||
bool RenderPass::RecordCommand(Command command) {
|
||||
if (!command) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
namespace impeller {
|
||||
|
||||
class Surface;
|
||||
class RenderPass;
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
@@ -29,12 +30,13 @@ class Renderer {
|
||||
protected:
|
||||
Renderer(std::string shaders_directory);
|
||||
|
||||
virtual bool OnRender() = 0;
|
||||
virtual bool OnIsValid() const = 0;
|
||||
|
||||
virtual bool OnRender(RenderPass& pass) = 0;
|
||||
|
||||
private:
|
||||
dispatch_semaphore_t frames_in_flight_sema_ = nullptr;
|
||||
std::shared_ptr<Context> context_;
|
||||
Size size_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Renderer);
|
||||
|
||||
@@ -25,7 +25,7 @@ Renderer::Renderer(std::string shaders_directory)
|
||||
Renderer::~Renderer() = default;
|
||||
|
||||
bool Renderer::IsValid() const {
|
||||
return is_valid_;
|
||||
return is_valid_ && OnIsValid();
|
||||
}
|
||||
|
||||
bool Renderer::Render(const Surface& surface) {
|
||||
@@ -48,7 +48,12 @@ bool Renderer::Render(const Surface& surface) {
|
||||
if (!render_pass) {
|
||||
return false;
|
||||
}
|
||||
render_pass->Encode(*context_->GetTransientsAllocator());
|
||||
|
||||
if (!OnRender(*render_pass)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
render_pass->FinishEncoding(*GetContext()->GetTransientsAllocator());
|
||||
|
||||
::dispatch_semaphore_wait(frames_in_flight_sema_, DISPATCH_TIME_FOREVER);
|
||||
|
||||
@@ -56,6 +61,7 @@ bool Renderer::Render(const Surface& surface) {
|
||||
[sema = frames_in_flight_sema_](CommandBuffer::CommitResult) {
|
||||
::dispatch_semaphore_signal(sema);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,5 +15,6 @@ impeller_component("entity") {
|
||||
public_deps = [
|
||||
"../compositor",
|
||||
"../image",
|
||||
"../primitives",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/compositor/renderer.h"
|
||||
#include "impeller/entity/entity.h"
|
||||
#include "impeller/primitives/box_primitive.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -18,8 +19,14 @@ class EntityRenderer final : public Renderer {
|
||||
|
||||
private:
|
||||
std::shared_ptr<Entity> root_;
|
||||
std::shared_ptr<BoxPrimitive> box_primitive_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
bool OnRender() override;
|
||||
// |Renderer|
|
||||
bool OnIsValid() const override;
|
||||
|
||||
// |Renderer|
|
||||
bool OnRender(RenderPass& pass) override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(EntityRenderer);
|
||||
};
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "impeller/entity/entity_renderer.h"
|
||||
#include "impeller/compositor/command.h"
|
||||
#include "impeller/primitives/box.frag.h"
|
||||
#include "impeller/primitives/box.vert.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -10,12 +13,32 @@ EntityRenderer::EntityRenderer(std::string shaders_directory)
|
||||
: Renderer(std::move(shaders_directory)),
|
||||
root_(std::make_shared<Entity>()) {
|
||||
root_->SetBackgroundColor(Color::DarkGray());
|
||||
|
||||
auto context = GetContext();
|
||||
|
||||
if (!context) {
|
||||
return;
|
||||
}
|
||||
|
||||
box_primitive_ = std::make_shared<BoxPrimitive>(context);
|
||||
if (!box_primitive_) {
|
||||
return;
|
||||
}
|
||||
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
EntityRenderer::~EntityRenderer() = default;
|
||||
|
||||
bool EntityRenderer::OnRender() {
|
||||
return false;
|
||||
bool EntityRenderer::OnIsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
bool EntityRenderer::OnRender(RenderPass& pass) {
|
||||
Command cmd;
|
||||
cmd.pipeline = box_primitive_->GetPipeline();
|
||||
pass.RecordCommand(std::move(cmd));
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -20,7 +20,8 @@ impeller_component("primitives") {
|
||||
"primitive.mm",
|
||||
]
|
||||
|
||||
public_deps = [ "../compositor" ]
|
||||
|
||||
deps = [ ":impeller_shaders" ]
|
||||
public_deps = [
|
||||
":impeller_shaders",
|
||||
"../compositor",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
in vec3 color;
|
||||
in vec3 color2;
|
||||
|
||||
out vec3 fragColor;
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
fragColor = color * color2;
|
||||
fragColor = vec4(color * color2, 1.0);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "impeller/compositor/context.h"
|
||||
#include "impeller/primitives/box.frag.h"
|
||||
#include "impeller/primitives/box.vert.h"
|
||||
#include "impeller/primitives/primitive.h"
|
||||
|
||||
namespace impeller {
|
||||
@@ -11,11 +15,20 @@ class BoxPrimitive final : public Primitive {
|
||||
public:
|
||||
BoxPrimitive(std::shared_ptr<Context> context);
|
||||
|
||||
// |Primitive|
|
||||
std::shared_ptr<Pipeline> GetPipeline() const override;
|
||||
|
||||
// |Primitive|
|
||||
~BoxPrimitive() override;
|
||||
|
||||
// |Primitive|
|
||||
virtual bool IsValid() const override;
|
||||
|
||||
// |Primitive|
|
||||
virtual bool Encode(RenderPass& pass) const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Pipeline> pipeline_ = 0;
|
||||
bool is_valid_ = false;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(BoxPrimitive);
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "box.frag.h"
|
||||
#include "box.vert.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "impeller/compositor/pipeline_descriptor.h"
|
||||
#include "impeller/compositor/shader_library.h"
|
||||
@@ -40,9 +38,26 @@ BoxPrimitive::BoxPrimitive(std::shared_ptr<Context> context)
|
||||
desc.SetVertexDescriptor(std::move(vertex_descriptor));
|
||||
}
|
||||
|
||||
auto pipeline =
|
||||
{
|
||||
// Configure the sole color attachments pixel format.
|
||||
ColorAttachmentDescriptor color0;
|
||||
color0.format = PixelFormat::kPixelFormat_B8G8R8A8_UNormInt_SRGB;
|
||||
desc.SetColorAttachmentDescriptor(0u, std::move(color0));
|
||||
}
|
||||
|
||||
{
|
||||
// Configure the stencil attachment.
|
||||
// TODO(wip): Make this configurable if possible as the D32 compoment is
|
||||
// wasted.
|
||||
const auto combined_depth_stencil_format =
|
||||
PixelFormat::kPixelFormat_D32_Float_S8_UNormInt;
|
||||
desc.SetDepthPixelFormat(combined_depth_stencil_format);
|
||||
desc.SetStencilPixelFormat(combined_depth_stencil_format);
|
||||
}
|
||||
|
||||
pipeline_ =
|
||||
context->GetPipelineLibrary()->GetRenderPipeline(std::move(desc)).get();
|
||||
if (!pipeline) {
|
||||
if (!pipeline_) {
|
||||
FML_LOG(ERROR) << "Could not create the render pipeline.";
|
||||
return;
|
||||
}
|
||||
@@ -52,6 +67,14 @@ BoxPrimitive::BoxPrimitive(std::shared_ptr<Context> context)
|
||||
|
||||
BoxPrimitive::~BoxPrimitive() = default;
|
||||
|
||||
std::shared_ptr<Pipeline> BoxPrimitive::GetPipeline() const {
|
||||
return pipeline_;
|
||||
}
|
||||
|
||||
bool BoxPrimitive::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
bool BoxPrimitive::Encode(RenderPass& pass) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/compositor/context.h"
|
||||
#include "impeller/compositor/pipeline.h"
|
||||
#include "impeller/compositor/render_pass.h"
|
||||
|
||||
namespace impeller {
|
||||
@@ -16,8 +17,12 @@ class Primitive {
|
||||
public:
|
||||
Primitive(std::shared_ptr<Context>);
|
||||
|
||||
virtual std::shared_ptr<Pipeline> GetPipeline() const = 0;
|
||||
|
||||
virtual ~Primitive();
|
||||
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
std::shared_ptr<Context> GetContext() const;
|
||||
|
||||
virtual bool Encode(RenderPass& pass) const = 0;
|
||||
|
||||
@@ -107,7 +107,7 @@ template("impeller_shaders") {
|
||||
]
|
||||
|
||||
depfile_path = "$target_gen_dir/{{source_file_part}}.d"
|
||||
source_path = "{{source}}"
|
||||
|
||||
metal_intermediate_path = rebase_path(metal_intermediate, root_build_dir)
|
||||
spirv_intermediate_path = rebase_path(spirv_intermediate, root_build_dir)
|
||||
depfile_intermediate_path = rebase_path(depfile_path, root_build_dir)
|
||||
@@ -121,7 +121,7 @@ template("impeller_shaders") {
|
||||
depfile = depfile_path
|
||||
|
||||
args = [
|
||||
"--input=$source_path",
|
||||
"--input={{source}}",
|
||||
"--metal=$metal_intermediate_path",
|
||||
"--spirv=$spirv_intermediate_path",
|
||||
"--reflection-json=$reflection_json_path",
|
||||
@@ -144,8 +144,15 @@ template("impeller_shaders") {
|
||||
shader_glue_config_name = "glue_config_$target_name"
|
||||
|
||||
config(shader_glue_config_name) {
|
||||
impeller_root_gen_dir = get_path_info(
|
||||
get_label_info("//flutter/impeller:impeller", "target_gen_dir"),
|
||||
"dir")
|
||||
|
||||
# Contains the generated header headers.
|
||||
include_dirs = [ target_gen_dir ]
|
||||
include_dirs = [
|
||||
target_gen_dir,
|
||||
impeller_root_gen_dir,
|
||||
]
|
||||
}
|
||||
|
||||
source_set(shader_glue_target_name) {
|
||||
@@ -158,6 +165,7 @@ template("impeller_shaders") {
|
||||
"*.h",
|
||||
"*.cc",
|
||||
])
|
||||
|
||||
deps = [
|
||||
":$impellerc_target_name",
|
||||
"//flutter/impeller/shader_glue",
|
||||
|
||||
Reference in New Issue
Block a user