Flutter Impeller
impeller::PipelineBuilder< VertexShader_, FragmentShader_ > Struct Template Reference

An optional (but highly recommended) utility for creating pipelines from reflected shader information. More...

#include <pipeline_builder.h>

Public Types

using VertexShader = VertexShader_
 
using FragmentShader = FragmentShader_
 

Static Public Member Functions

static std::optional< PipelineDescriptorMakeDefaultPipelineDescriptor (const Context &context, const std::vector< Scalar > &constants={})
 Create a default pipeline descriptor using the combination reflected shader information. The descriptor can be configured further before a pipeline state object is created using it. More...
 
static bool InitializePipelineDescriptorDefaults (const Context &context, PipelineDescriptor &desc)
 

Static Public Attributes

static constexpr size_t kVertexBufferIndex
 

Detailed Description

template<class VertexShader_, class FragmentShader_>
struct impeller::PipelineBuilder< VertexShader_, FragmentShader_ >

An optional (but highly recommended) utility for creating pipelines from reflected shader information.

Template Parameters
VertexShader_The reflected vertex shader information. Found in a generated header file called <shader_name>.vert.h.
FragmentShader_The reflected fragment shader information. Found in a generated header file called <shader_name>.frag.h.

Definition at line 31 of file pipeline_builder.h.

Member Typedef Documentation

◆ FragmentShader

template<class VertexShader_ , class FragmentShader_ >
using impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::FragmentShader = FragmentShader_

Definition at line 34 of file pipeline_builder.h.

◆ VertexShader

template<class VertexShader_ , class FragmentShader_ >
using impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::VertexShader = VertexShader_

Definition at line 33 of file pipeline_builder.h.

Member Function Documentation

◆ InitializePipelineDescriptorDefaults()

template<class VertexShader_ , class FragmentShader_ >
static bool impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::InitializePipelineDescriptorDefaults ( const Context context,
PipelineDescriptor desc 
)
inlinestatic

Definition at line 61 of file pipeline_builder.h.

63  {
64  // Setup debug instrumentation.
65  desc.SetLabel(std::format("{} Pipeline", FragmentShader::kLabel));
66 
67  // Resolve pipeline entrypoints.
68  {
69  auto vertex_function = context.GetShaderLibrary()->GetFunction(
70  VertexShader::kEntrypointName, ShaderStage::kVertex);
71  auto fragment_function = context.GetShaderLibrary()->GetFunction(
72  FragmentShader::kEntrypointName, ShaderStage::kFragment);
73 
74  if (!vertex_function || !fragment_function) {
75  VALIDATION_LOG << "Could not resolve pipeline entrypoint(s) '"
76  << VertexShader::kEntrypointName << "' and '"
77  << FragmentShader::kEntrypointName
78  << "' for pipeline named '" << VertexShader::kLabel
79  << "'.";
80  return false;
81  }
82 
83  desc.AddStageEntrypoint(std::move(vertex_function));
84  desc.AddStageEntrypoint(std::move(fragment_function));
85  }
86 
87  // Setup the vertex descriptor from reflected information.
88  {
89  auto vertex_descriptor = std::make_shared<VertexDescriptor>();
90  vertex_descriptor->SetStageInputs(VertexShader::kAllShaderStageInputs,
91  VertexShader::kInterleavedBufferLayout);
92  vertex_descriptor->RegisterDescriptorSetLayouts(
93  VertexShader::kDescriptorSetLayouts);
94  vertex_descriptor->RegisterDescriptorSetLayouts(
95  FragmentShader::kDescriptorSetLayouts);
96  desc.SetVertexDescriptor(std::move(vertex_descriptor));
97  }
98 
99  // Setup fragment shader output descriptions.
100  {
101  // Configure the sole color attachments pixel format. This is by
102  // convention.
103  ColorAttachmentDescriptor color0;
104  color0.format = context.GetCapabilities()->GetDefaultColorFormat();
105  color0.blending_enabled = true;
106  desc.SetColorAttachmentDescriptor(0u, color0);
107  }
108 
109  // Setup default depth buffer descriptions.
110  {
111  DepthAttachmentDescriptor depth0;
112  depth0.depth_compare = CompareFunction::kAlways;
113  desc.SetDepthStencilAttachmentDescriptor(depth0);
114  desc.SetDepthPixelFormat(
115  context.GetCapabilities()->GetDefaultDepthStencilFormat());
116  }
117 
118  // Setup default stencil buffer descriptions.
119  {
120  StencilAttachmentDescriptor stencil0;
121  stencil0.stencil_compare = CompareFunction::kEqual;
122  desc.SetStencilAttachmentDescriptors(stencil0);
123  desc.SetStencilPixelFormat(
124  context.GetCapabilities()->GetDefaultDepthStencilFormat());
125  }
126 
127  return true;
128  }
@ kEqual
Comparison test passes if new_value == current_value.
@ kAlways
Comparison test passes always passes.
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::PipelineDescriptor::AddStageEntrypoint(), impeller::ColorAttachmentDescriptor::blending_enabled, impeller::DepthAttachmentDescriptor::depth_compare, impeller::ColorAttachmentDescriptor::format, impeller::Context::GetCapabilities(), impeller::Context::GetShaderLibrary(), impeller::kAlways, impeller::kEqual, impeller::kFragment, impeller::kVertex, impeller::PipelineDescriptor::SetColorAttachmentDescriptor(), impeller::PipelineDescriptor::SetDepthPixelFormat(), impeller::PipelineDescriptor::SetDepthStencilAttachmentDescriptor(), impeller::PipelineDescriptor::SetLabel(), impeller::PipelineDescriptor::SetStencilAttachmentDescriptors(), impeller::PipelineDescriptor::SetStencilPixelFormat(), impeller::PipelineDescriptor::SetVertexDescriptor(), impeller::StencilAttachmentDescriptor::stencil_compare, and VALIDATION_LOG.

◆ MakeDefaultPipelineDescriptor()

template<class VertexShader_ , class FragmentShader_ >
static std::optional<PipelineDescriptor> impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor ( const Context context,
const std::vector< Scalar > &  constants = {} 
)
inlinestatic

Create a default pipeline descriptor using the combination reflected shader information. The descriptor can be configured further before a pipeline state object is created using it.

Parameters
[in]contextThe context
Returns
If the combination of reflected shader information is compatible and the requisite functions can be found in the context, a pipeline descriptor.

Definition at line 50 of file pipeline_builder.h.

52  {}) {
53  PipelineDescriptor desc;
54  desc.SetSpecializationConstants(constants);
55  if (InitializePipelineDescriptorDefaults(context, desc)) {
56  return {std::move(desc)};
57  }
58  return std::nullopt;
59  }
static bool InitializePipelineDescriptorDefaults(const Context &context, PipelineDescriptor &desc)

Referenced by impeller::ContentContext::ContentContext(), and impeller::testing::TEST_P().

Member Data Documentation

◆ kVertexBufferIndex

template<class VertexShader_ , class FragmentShader_ >
constexpr size_t impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::kVertexBufferIndex
staticconstexpr
Initial value:

Definition at line 36 of file pipeline_builder.h.


The documentation for this struct was generated from the following file: