Skip to content

Commit

Permalink
Shorten names of the render target attachment descriptors.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and dnfield committed Apr 27, 2022
1 parent 08f00cd commit e95252f
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 61 deletions.
4 changes: 2 additions & 2 deletions impeller/playground/playground.mm
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ static void PlaygroundKeyCallback(GLFWwindow* window,
static_cast<ISize::Type>(current_drawable.texture.width),
static_cast<ISize::Type>(current_drawable.texture.height)};

RenderPassColorAttachment color0;
ColorAttachment color0;
color0.texture =
std::make_shared<TextureMTL>(color0_desc, current_drawable.texture);
color0.clear_color = Color::SkyBlue();
color0.load_action = LoadAction::kClear;
color0.store_action = StoreAction::kStore;

RenderPassDescriptor desc;
RenderTarget desc;
desc.SetColorAttachment(color0, 0u);

Surface surface(desc);
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/metal/command_buffer_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CommandBufferMTL final : public CommandBuffer {

// |CommandBuffer|
std::shared_ptr<RenderPass> CreateRenderPass(
const RenderPassDescriptor& desc) const override;
const RenderTarget& desc) const override;

FML_DISALLOW_COPY_AND_ASSIGN(CommandBufferMTL);
};
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/metal/command_buffer_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}

std::shared_ptr<RenderPass> CommandBufferMTL::CreateRenderPass(
const RenderPassDescriptor& desc) const {
const RenderTarget& desc) const {
if (!buffer_) {
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/metal/formats_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace impeller {

class RenderPassDescriptor;
class RenderTarget;

constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) {
switch (format) {
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/metal/render_pass_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RenderPassMTL final : public RenderPass {
std::string label_;
bool is_valid_ = false;

RenderPassMTL(id<MTLCommandBuffer> buffer, const RenderPassDescriptor& desc);
RenderPassMTL(id<MTLCommandBuffer> buffer, const RenderTarget& desc);

// |RenderPass|
bool IsValid() const override;
Expand Down
12 changes: 6 additions & 6 deletions impeller/renderer/backend/metal/render_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace impeller {

static bool ConfigureAttachment(const RenderPassAttachment& desc,
static bool ConfigureAttachment(const Attachment& desc,
MTLRenderPassAttachmentDescriptor* attachment) {
if (!desc.texture) {
return false;
Expand All @@ -30,7 +30,7 @@ static bool ConfigureAttachment(const RenderPassAttachment& desc,
}

static bool ConfigureColorAttachment(
const RenderPassColorAttachment& desc,
const ColorAttachment& desc,
MTLRenderPassColorAttachmentDescriptor* attachment) {
if (!ConfigureAttachment(desc, attachment)) {
return false;
Expand All @@ -40,7 +40,7 @@ static bool ConfigureColorAttachment(
}

static bool ConfigureDepthAttachment(
const RenderPassDepthAttachment& desc,
const DepthAttachment& desc,
MTLRenderPassDepthAttachmentDescriptor* attachment) {
if (!ConfigureAttachment(desc, attachment)) {
return false;
Expand All @@ -50,7 +50,7 @@ static bool ConfigureDepthAttachment(
}

static bool ConfigureStencilAttachment(
const RenderPassStencilAttachment& desc,
const StencilAttachment& desc,
MTLRenderPassStencilAttachmentDescriptor* attachment) {
if (!ConfigureAttachment(desc, attachment)) {
return false;
Expand All @@ -61,7 +61,7 @@ static bool ConfigureStencilAttachment(

// TODO(csg): Move this to formats_mtl.h
static MTLRenderPassDescriptor* ToMTLRenderPassDescriptor(
const RenderPassDescriptor& desc) {
const RenderTarget& desc) {
auto result = [MTLRenderPassDescriptor renderPassDescriptor];

const auto& colors = desc.GetColorAttachments();
Expand Down Expand Up @@ -93,7 +93,7 @@ static bool ConfigureStencilAttachment(
}

RenderPassMTL::RenderPassMTL(id<MTLCommandBuffer> buffer,
const RenderPassDescriptor& desc)
const RenderTarget& desc)
: buffer_(buffer),
desc_(ToMTLRenderPassDescriptor(desc)),
transients_buffer_(HostBuffer::Create()) {
Expand Down
4 changes: 2 additions & 2 deletions impeller/renderer/command_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace impeller {

class Context;
class RenderPass;
class RenderPassDescriptor;
class RenderTarget;

//------------------------------------------------------------------------------
/// @brief A collection of encoded commands to be submitted to the GPU for
Expand Down Expand Up @@ -59,7 +59,7 @@ class CommandBuffer {
/// @return A valid render pass or null.
///
virtual std::shared_ptr<RenderPass> CreateRenderPass(
const RenderPassDescriptor& desc) const = 0;
const RenderTarget& desc) const = 0;

protected:
CommandBuffer();
Expand Down
8 changes: 4 additions & 4 deletions impeller/renderer/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,23 +319,23 @@ struct PipelineStencilAttachment {
}
};

struct RenderPassAttachment {
struct Attachment {
std::shared_ptr<Texture> texture = nullptr;
LoadAction load_action = LoadAction::kDontCare;
StoreAction store_action = StoreAction::kStore;

constexpr operator bool() const { return static_cast<bool>(texture); }
};

struct RenderPassColorAttachment : public RenderPassAttachment {
struct ColorAttachment : public Attachment {
Color clear_color = Color::BlackTransparent();
};

struct RenderPassDepthAttachment : public RenderPassAttachment {
struct DepthAttachment : public Attachment {
double clear_depth = 0.0;
};

struct RenderPassStencilAttachment : public RenderPassAttachment {
struct StencilAttachment : public Attachment {
uint32_t clear_stencil = 0;
};

Expand Down
7 changes: 7 additions & 0 deletions impeller/renderer/render_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ namespace impeller {
class HostBuffer;
class Allocator;

//------------------------------------------------------------------------------
/// @brief Render passes encode render commands directed as one specific
/// render target into an underlying command buffer.
///
/// Render passes can be obtained from the command buffer in which
/// the pass is meant to encode commands into.
///
class RenderPass {
public:
virtual ~RenderPass();
Expand Down
31 changes: 13 additions & 18 deletions impeller/renderer/render_pass_descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@

namespace impeller {

RenderPassDescriptor::RenderPassDescriptor() = default;
RenderTarget::RenderTarget() = default;

RenderPassDescriptor::~RenderPassDescriptor() = default;
RenderTarget::~RenderTarget() = default;

bool RenderPassDescriptor::HasColorAttachment(size_t index) const {
bool RenderTarget::HasColorAttachment(size_t index) const {
if (auto found = colors_.find(index); found != colors_.end()) {
return true;
}
return false;
}

std::optional<ISize> RenderPassDescriptor::GetColorAttachmentSize(
size_t index) const {
std::optional<ISize> RenderTarget::GetColorAttachmentSize(size_t index) const {
auto found = colors_.find(index);

if (found == colors_.end()) {
Expand All @@ -30,43 +29,39 @@ std::optional<ISize> RenderPassDescriptor::GetColorAttachmentSize(
return found->second.texture->GetSize();
}

RenderPassDescriptor& RenderPassDescriptor::SetColorAttachment(
RenderPassColorAttachment attachment,
size_t index) {
RenderTarget& RenderTarget::SetColorAttachment(ColorAttachment attachment,
size_t index) {
if (attachment) {
colors_[index] = attachment;
}
return *this;
}

RenderPassDescriptor& RenderPassDescriptor::SetDepthAttachment(
RenderPassDepthAttachment attachment) {
RenderTarget& RenderTarget::SetDepthAttachment(DepthAttachment attachment) {
if (attachment) {
depth_ = std::move(attachment);
}
return *this;
}

RenderPassDescriptor& RenderPassDescriptor::SetStencilAttachment(
RenderPassStencilAttachment attachment) {
RenderTarget& RenderTarget::SetStencilAttachment(StencilAttachment attachment) {
if (attachment) {
stencil_ = std::move(attachment);
}
return *this;
}

const std::map<size_t, RenderPassColorAttachment>&
RenderPassDescriptor::GetColorAttachments() const {
const std::map<size_t, ColorAttachment>& RenderTarget::GetColorAttachments()
const {
return colors_;
}

const std::optional<RenderPassDepthAttachment>&
RenderPassDescriptor::GetDepthAttachment() const {
const std::optional<DepthAttachment>& RenderTarget::GetDepthAttachment() const {
return depth_;
}

const std::optional<RenderPassStencilAttachment>&
RenderPassDescriptor::GetStencilAttachment() const {
const std::optional<StencilAttachment>& RenderTarget::GetStencilAttachment()
const {
return stencil_;
}

Expand Down
29 changes: 12 additions & 17 deletions impeller/renderer/render_pass_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,32 @@

namespace impeller {

class RenderPassDescriptor {
class RenderTarget {
public:
RenderPassDescriptor();
RenderTarget();

~RenderPassDescriptor();
~RenderTarget();

bool HasColorAttachment(size_t index) const;

std::optional<ISize> GetColorAttachmentSize(size_t index) const;

RenderPassDescriptor& SetColorAttachment(RenderPassColorAttachment attachment,
size_t index);
RenderTarget& SetColorAttachment(ColorAttachment attachment, size_t index);

RenderPassDescriptor& SetDepthAttachment(
RenderPassDepthAttachment attachment);
RenderTarget& SetDepthAttachment(DepthAttachment attachment);

RenderPassDescriptor& SetStencilAttachment(
RenderPassStencilAttachment attachment);
RenderTarget& SetStencilAttachment(StencilAttachment attachment);

const std::map<size_t, RenderPassColorAttachment>& GetColorAttachments()
const;
const std::map<size_t, ColorAttachment>& GetColorAttachments() const;

const std::optional<RenderPassDepthAttachment>& GetDepthAttachment() const;
const std::optional<DepthAttachment>& GetDepthAttachment() const;

const std::optional<RenderPassStencilAttachment>& GetStencilAttachment()
const;
const std::optional<StencilAttachment>& GetStencilAttachment() const;

private:
std::map<size_t, RenderPassColorAttachment> colors_;
std::optional<RenderPassDepthAttachment> depth_;
std::optional<RenderPassStencilAttachment> stencil_;
std::map<size_t, ColorAttachment> colors_;
std::optional<DepthAttachment> depth_;
std::optional<StencilAttachment> stencil_;
};

} // namespace impeller
4 changes: 2 additions & 2 deletions impeller/renderer/renderer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ TEST_F(RendererTest, CanRenderToTexture) {
std::shared_ptr<RenderPass> r2t_pass;

{
RenderPassColorAttachment color0;
ColorAttachment color0;
color0.load_action = LoadAction::kClear;
color0.store_action = StoreAction::kStore;

Expand All @@ -218,7 +218,7 @@ TEST_F(RendererTest, CanRenderToTexture) {

color0.texture->SetLabel("r2t_target");

RenderPassDescriptor r2t_desc;
RenderTarget r2t_desc;
r2t_desc.SetColorAttachment(color0, 0u);
auto cmd_buffer = context->CreateRenderCommandBuffer();
r2t_pass = cmd_buffer->CreateRenderPass(r2t_desc);
Expand Down
5 changes: 2 additions & 3 deletions impeller/renderer/surface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

namespace impeller {

Surface::Surface(RenderPassDescriptor target_desc)
: desc_(std::move(target_desc)) {
Surface::Surface(RenderTarget target_desc) : desc_(std::move(target_desc)) {
if (auto size = desc_.GetColorAttachmentSize(0u); size.has_value()) {
size_ = size.value();
} else {
Expand All @@ -29,7 +28,7 @@ bool Surface::IsValid() const {
return is_valid_;
}

const RenderPassDescriptor& Surface::GetTargetRenderPassDescriptor() const {
const RenderTarget& Surface::GetTargetRenderPassDescriptor() const {
return desc_;
}

Expand Down
6 changes: 3 additions & 3 deletions impeller/renderer/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ namespace impeller {

class Surface {
public:
Surface(RenderPassDescriptor target_desc);
Surface(RenderTarget target_desc);

~Surface();

const ISize& GetSize() const;

bool IsValid() const;

const RenderPassDescriptor& GetTargetRenderPassDescriptor() const;
const RenderTarget& GetTargetRenderPassDescriptor() const;

private:
RenderPassDescriptor desc_;
RenderTarget desc_;
ISize size_;

bool is_valid_ = false;
Expand Down

0 comments on commit e95252f

Please sign in to comment.