| Flutter Impeller |

Public Types | Static Public Member Functions | Static Public Attributes | List of all members
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< PipelineDescriptor > | MakeDefaultPipelineDescriptor (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 32 of file pipeline_builder.h.

## Member Typedef Documentation

## ◆ FragmentShader

template<class VertexShader_ , class FragmentShader_ >

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

Definition at line 35 of file pipeline_builder.h.

## ◆ VertexShader

template<class VertexShader_ , class FragmentShader_ >

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

Definition at line 34 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
| ) |  |
| inline static

Definition at line 62 of file pipeline_builder.h.

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

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::SPrintF(), 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 = `{}`
| ) |  |
| inline static

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] | context | The 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 51 of file pipeline_builder.h.

53 {}) {
54 PipelineDescriptor desc;
55 desc.SetSpecializationConstants(constants);
56 if (InitializePipelineDescriptorDefaults(context, desc)) {
57 return {std::move(desc)};
58 }
59 return std::nullopt;
60 }

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
| static constexpr

Initial value:
=
VertexDescriptor::kReservedVertexBufferIndex

Definition at line 37 of file pipeline_builder.h.

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

- impeller/renderer/pipeline_builder.h

impeller::CompareFunction::kEqual
@ kEqual
Comparison test passes if new_value == current_value.
impeller::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
impeller::ShaderStage::kFragment
@ kFragment
impeller::CompareFunction::kAlways
@ kAlways
Comparison test passes always passes.
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::VertexDescriptor::kReservedVertexBufferIndex
static constexpr size_t kReservedVertexBufferIndex
Definition: vertex_descriptor.h:25
impeller::ShaderStage::kVertex
@ kVertex
impeller::PipelineBuilder::InitializePipelineDescriptorDefaults
static bool InitializePipelineDescriptorDefaults(const Context &context, PipelineDescriptor &desc)
Definition: pipeline_builder.h:62