| 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 30 of file pipeline_builder.h.

## Member Typedef Documentation

## ◆ FragmentShader

template<class VertexShader_ , class FragmentShader_ >

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

Definition at line 33 of file pipeline_builder.h.

## ◆ VertexShader

template<class VertexShader_ , class FragmentShader_ >

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

Definition at line 32 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 60 of file pipeline_builder.h.

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

References impeller::PipelineDescriptor::AddStageEntrypoint(), impeller::ColorAttachmentDescriptor::blending_enabled, data, 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 49 of file pipeline_builder.h.

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

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 35 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.
data
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
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:91
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:60