| 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)
| 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
| ) |  |
| inline static

Definition at line 59 of file pipeline_builder.h.

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

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

Referenced by impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor().

## ◆ MakeDefaultPipelineDescriptor()

template<class VertexShader_ , class FragmentShader_ >

static std::optional<PipelineDescriptor> impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::MakeDefaultPipelineDescriptor | ( | const Context & | context | ) |
| 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 50 of file pipeline_builder.h.

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

References impeller::PipelineBuilder< VertexShader_, FragmentShader_ >::InitializePipelineDescriptorDefaults().

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

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

- impeller/renderer/pipeline_builder.h

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