Better disambiguate attachment descriptors for pipelines and stencils.
This commit is contained in:
@@ -126,7 +126,7 @@ constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) {
|
||||
return 0u;
|
||||
}
|
||||
|
||||
struct ColorAttachmentDescriptor {
|
||||
struct PipelineColorAttachment {
|
||||
PixelFormat format = PixelFormat::kUnknown;
|
||||
bool blending_enabled = false;
|
||||
|
||||
@@ -159,7 +159,7 @@ struct ColorAttachmentDescriptor {
|
||||
std::underlying_type_t<ColorWriteMask> write_mask =
|
||||
static_cast<uint64_t>(ColorWriteMask::kAll);
|
||||
|
||||
constexpr bool operator==(const ColorAttachmentDescriptor& o) const {
|
||||
constexpr bool operator==(const PipelineColorAttachment& o) const {
|
||||
return format == o.format && //
|
||||
blending_enabled == o.blending_enabled && //
|
||||
src_color_blend_factor == o.src_color_blend_factor && //
|
||||
@@ -217,7 +217,7 @@ enum class StencilOperation {
|
||||
kDecrementWrap,
|
||||
};
|
||||
|
||||
struct DepthAttachmentDescriptor {
|
||||
struct PipelineDepthAttachment {
|
||||
//----------------------------------------------------------------------------
|
||||
/// Indicates how to compare the value with that in the depth buffer.
|
||||
///
|
||||
@@ -227,7 +227,7 @@ struct DepthAttachmentDescriptor {
|
||||
///
|
||||
bool depth_write_enabled = false;
|
||||
|
||||
constexpr bool operator==(const DepthAttachmentDescriptor& o) const {
|
||||
constexpr bool operator==(const PipelineDepthAttachment& o) const {
|
||||
return depth_compare == o.depth_compare &&
|
||||
depth_write_enabled == o.depth_write_enabled;
|
||||
}
|
||||
@@ -237,7 +237,7 @@ struct DepthAttachmentDescriptor {
|
||||
}
|
||||
};
|
||||
|
||||
struct StencilAttachmentDescriptor {
|
||||
struct PipelineStencilAttachment {
|
||||
//----------------------------------------------------------------------------
|
||||
/// Indicates the operation to perform between the reference value and the
|
||||
/// value in the stencil buffer. Both values have the read_mask applied to
|
||||
@@ -268,7 +268,7 @@ struct StencilAttachmentDescriptor {
|
||||
///
|
||||
uint32_t write_mask = ~0;
|
||||
|
||||
constexpr bool operator==(const StencilAttachmentDescriptor& o) const {
|
||||
constexpr bool operator==(const PipelineStencilAttachment& o) const {
|
||||
return stencil_compare == o.stencil_compare &&
|
||||
stencil_failure == o.stencil_failure &&
|
||||
depth_failure == o.depth_failure &&
|
||||
@@ -307,17 +307,17 @@ struct RenderPassStencilAttachment : public RenderPassAttachment {
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<impeller::DepthAttachmentDescriptor> {
|
||||
struct hash<impeller::PipelineDepthAttachment> {
|
||||
constexpr std::size_t operator()(
|
||||
const impeller::DepthAttachmentDescriptor& des) const {
|
||||
const impeller::PipelineDepthAttachment& des) const {
|
||||
return des.GetHash();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<impeller::StencilAttachmentDescriptor> {
|
||||
struct hash<impeller::PipelineStencilAttachment> {
|
||||
constexpr std::size_t operator()(
|
||||
const impeller::StencilAttachmentDescriptor& des) const {
|
||||
const impeller::PipelineStencilAttachment& des) const {
|
||||
return des.GetHash();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -251,12 +251,12 @@ constexpr MTLClearColor ToMTLClearColor(const Color& color) {
|
||||
|
||||
MTLRenderPipelineColorAttachmentDescriptor*
|
||||
ToMTLRenderPipelineColorAttachmentDescriptor(
|
||||
ColorAttachmentDescriptor descriptor);
|
||||
PipelineColorAttachment descriptor);
|
||||
|
||||
MTLDepthStencilDescriptor* ToMTLDepthStencilDescriptor(
|
||||
std::optional<DepthAttachmentDescriptor> depth,
|
||||
std::optional<StencilAttachmentDescriptor> front,
|
||||
std::optional<StencilAttachmentDescriptor> back);
|
||||
std::optional<PipelineDepthAttachment> depth,
|
||||
std::optional<PipelineStencilAttachment> front,
|
||||
std::optional<PipelineStencilAttachment> back);
|
||||
|
||||
MTLTextureDescriptor* ToMTLTextureDescriptor(const TextureDescriptor& desc);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace impeller {
|
||||
|
||||
MTLRenderPipelineColorAttachmentDescriptor*
|
||||
ToMTLRenderPipelineColorAttachmentDescriptor(
|
||||
ColorAttachmentDescriptor descriptor) {
|
||||
PipelineColorAttachment descriptor) {
|
||||
auto des = [[MTLRenderPipelineColorAttachmentDescriptor alloc] init];
|
||||
des.pixelFormat = ToMTLPixelFormat(descriptor.format);
|
||||
|
||||
@@ -35,7 +35,7 @@ ToMTLRenderPipelineColorAttachmentDescriptor(
|
||||
}
|
||||
|
||||
MTLStencilDescriptor* ToMTLStencilDescriptor(
|
||||
const StencilAttachmentDescriptor& descriptor) {
|
||||
const PipelineStencilAttachment& descriptor) {
|
||||
auto des = [[MTLStencilDescriptor alloc] init];
|
||||
des.stencilCompareFunction = ToMTLCompareFunction(descriptor.stencil_compare);
|
||||
des.stencilFailureOperation =
|
||||
@@ -51,11 +51,11 @@ MTLStencilDescriptor* ToMTLStencilDescriptor(
|
||||
}
|
||||
|
||||
MTLDepthStencilDescriptor* ToMTLDepthStencilDescriptor(
|
||||
std::optional<DepthAttachmentDescriptor> depth,
|
||||
std::optional<StencilAttachmentDescriptor> front,
|
||||
std::optional<StencilAttachmentDescriptor> back) {
|
||||
std::optional<PipelineDepthAttachment> depth,
|
||||
std::optional<PipelineStencilAttachment> front,
|
||||
std::optional<PipelineStencilAttachment> back) {
|
||||
if (!depth) {
|
||||
depth = DepthAttachmentDescriptor{
|
||||
depth = PipelineDepthAttachment{
|
||||
// Always pass the depth test.
|
||||
.depth_compare = CompareFunction::kAlways,
|
||||
.depth_write_enabled = false,
|
||||
|
||||
@@ -84,7 +84,7 @@ struct PipelineBuilder {
|
||||
// Configure the sole color attachments pixel format.
|
||||
// TODO(csg): This can be easily reflected but we are sticking to the
|
||||
// convention that the first stage output is the color output.
|
||||
ColorAttachmentDescriptor color0;
|
||||
PipelineColorAttachment color0;
|
||||
color0.format = PixelFormat::kB8G8R8A8_UNormInt;
|
||||
desc.SetColorAttachmentDescriptor(0u, std::move(color0));
|
||||
}
|
||||
|
||||
@@ -42,20 +42,20 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
|
||||
|
||||
PipelineDescriptor& SetColorAttachmentDescriptor(
|
||||
size_t index,
|
||||
ColorAttachmentDescriptor desc);
|
||||
PipelineColorAttachment desc);
|
||||
|
||||
const ColorAttachmentDescriptor* GetColorAttachmentDescriptor(
|
||||
const PipelineColorAttachment* GetColorAttachmentDescriptor(
|
||||
size_t index) const;
|
||||
|
||||
PipelineDescriptor& SetDepthStencilAttachmentDescriptor(
|
||||
DepthAttachmentDescriptor desc);
|
||||
PipelineDepthAttachment desc);
|
||||
|
||||
PipelineDescriptor& SetStencilAttachmentDescriptors(
|
||||
StencilAttachmentDescriptor front_and_back);
|
||||
PipelineStencilAttachment front_and_back);
|
||||
|
||||
PipelineDescriptor& SetStencilAttachmentDescriptors(
|
||||
StencilAttachmentDescriptor front,
|
||||
StencilAttachmentDescriptor back);
|
||||
PipelineStencilAttachment front,
|
||||
PipelineStencilAttachment back);
|
||||
|
||||
PipelineDescriptor& SetDepthPixelFormat(PixelFormat format);
|
||||
|
||||
@@ -76,15 +76,13 @@ class PipelineDescriptor final : public Comparable<PipelineDescriptor> {
|
||||
std::string label_;
|
||||
size_t sample_count_ = 1;
|
||||
std::map<ShaderStage, std::shared_ptr<const ShaderFunction>> entrypoints_;
|
||||
std::map<size_t, ColorAttachmentDescriptor> color_attachment_descriptors_;
|
||||
std::map<size_t, PipelineColorAttachment> color_attachment_descriptors_;
|
||||
std::shared_ptr<VertexDescriptor> vertex_descriptor_;
|
||||
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_;
|
||||
std::optional<StencilAttachmentDescriptor>
|
||||
back_stencil_attachment_descriptor_;
|
||||
std::optional<PipelineDepthAttachment> depth_attachment_descriptor_;
|
||||
std::optional<PipelineStencilAttachment> front_stencil_attachment_descriptor_;
|
||||
std::optional<PipelineStencilAttachment> back_stencil_attachment_descriptor_;
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -89,13 +89,13 @@ PipelineDescriptor& PipelineDescriptor::SetVertexDescriptor(
|
||||
|
||||
PipelineDescriptor& PipelineDescriptor::SetColorAttachmentDescriptor(
|
||||
size_t index,
|
||||
ColorAttachmentDescriptor desc) {
|
||||
PipelineColorAttachment desc) {
|
||||
color_attachment_descriptors_[index] = std::move(desc);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const ColorAttachmentDescriptor*
|
||||
PipelineDescriptor::GetColorAttachmentDescriptor(size_t index) const {
|
||||
const PipelineColorAttachment* PipelineDescriptor::GetColorAttachmentDescriptor(
|
||||
size_t index) const {
|
||||
auto found = color_attachment_descriptors_.find(index);
|
||||
return found == color_attachment_descriptors_.end() ? nullptr
|
||||
: &found->second;
|
||||
@@ -114,19 +114,19 @@ PipelineDescriptor& PipelineDescriptor::SetStencilPixelFormat(
|
||||
}
|
||||
|
||||
PipelineDescriptor& PipelineDescriptor::SetDepthStencilAttachmentDescriptor(
|
||||
DepthAttachmentDescriptor desc) {
|
||||
PipelineDepthAttachment desc) {
|
||||
depth_attachment_descriptor_ = desc;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PipelineDescriptor& PipelineDescriptor::SetStencilAttachmentDescriptors(
|
||||
StencilAttachmentDescriptor front_and_back) {
|
||||
PipelineStencilAttachment front_and_back) {
|
||||
return SetStencilAttachmentDescriptors(front_and_back, front_and_back);
|
||||
}
|
||||
|
||||
PipelineDescriptor& PipelineDescriptor::SetStencilAttachmentDescriptors(
|
||||
StencilAttachmentDescriptor front,
|
||||
StencilAttachmentDescriptor back) {
|
||||
PipelineStencilAttachment front,
|
||||
PipelineStencilAttachment back) {
|
||||
front_stencil_attachment_descriptor_ = front;
|
||||
back_stencil_attachment_descriptor_ = back;
|
||||
return *this;
|
||||
|
||||
Reference in New Issue
Block a user