| Flutter Impeller |

Public Member Functions | Public Attributes | List of all members
impeller::Command Struct Reference

An object used to specify work to the GPU along with references to resources the GPU will used when doing said work. More...

`#include <command.h>`

Inheritance diagram for impeller::Command:

## Public Member Functions
bool | BindVertices (VertexBuffer buffer)
| Specify the vertex and index buffer to use for this command. More...
bool | BindResource (ShaderStage stage, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, BufferView view) override
bool | BindResource (ShaderStage stage, const ShaderUniformSlot &slot, const std::shared_ptr< const ShaderMetadata > &metadata, BufferView view)
bool | BindResource (ShaderStage stage, const SampledImageSlot &slot, const ShaderMetadata &metadata, std::shared_ptr< const Texture > texture, std::shared_ptr< const Sampler > sampler) override
bool | IsValid () const
Public Member Functions inherited from impeller::ResourceBinder
virtual | ~ResourceBinder ()=default

## Public Attributes
std::shared_ptr< Pipeline< PipelineDescriptor > > | pipeline
Bindings | vertex_bindings
Bindings | fragment_bindings
uint32_t | stencil_reference = 0u
uint64_t | base_vertex = 0u
std::optional< Viewport > | viewport
std::optional< IRect > | scissor
size_t | instance_count = 1u
VertexBuffer | vertex_buffer
| The bound per-vertex data and optional index buffer. More...

## Detailed Description

An object used to specify work to the GPU along with references to resources the GPU will used when doing said work.

To construct a valid command, follow these steps:

- Specify a valid pipeline.
- Specify vertex information via a call `BindVertices`
- Specify any stage bindings.
- (Optional) Specify a debug label.

Command can be created frequently and on demand. The resources referenced in commands views into buffers managed by other allocators and resource managers.

Definition at line 92 of file command.h.

## Member Function Documentation

## ◆ BindResource() [1/3]

bool impeller::Command::BindResource | ( | ShaderStage | stage,
|  | const SampledImageSlot & | slot,
|  | const ShaderMetadata & | metadata,
|  | std::shared_ptr< const Texture > | texture,
|  | std::shared_ptr< const Sampler > | sampler
| ) |  |
| override virtual

Implements impeller::ResourceBinder.

Definition at line 68 of file command.cc.

72 {
73 if (!sampler || !sampler->IsValid()) {
74 return false;
75 }
76 if (!texture || !texture->IsValid()) {
77 return false;
78 }
79
80 switch (stage) {
81 case ShaderStage::kVertex:
82 vertex_bindings.sampled_images.emplace_back(TextureAndSampler{
83 .slot = slot,
84 .texture = {&metadata, std::move(texture)},
85 .sampler = std::move(sampler),
86 });
87 return true;
88 case ShaderStage::kFragment:
89 fragment_bindings.sampled_images.emplace_back(TextureAndSampler{
90 .slot = slot,
91 .texture = {&metadata, std::move(texture)},
92 .sampler = std::move(sampler),
93 });
94 return true;
95 case ShaderStage::kCompute:
96 VALIDATION_LOG << "Use ComputeCommands for compute shader stages.";
97 case ShaderStage::kUnknown:
98 return false;
99 }
100
101 return false;
102 }

References fragment_bindings, impeller::kCompute, impeller::kFragment, impeller::kUnknown, impeller::kVertex, impeller::Bindings::sampled_images, impeller::TextureAndSampler::slot, VALIDATION_LOG, and vertex_bindings.

## ◆ BindResource() [2/3]

bool impeller::Command::BindResource | ( | ShaderStage | stage,
|  | const ShaderUniformSlot & | slot,
|  | const ShaderMetadata & | metadata,
|  | BufferView | view
| ) |  |
| override virtual

Implements impeller::ResourceBinder.

Definition at line 25 of file command.cc.

28 {
29 return DoBindResource(stage, slot, &metadata, std::move(view));
30 }

Referenced by impeller::RuntimeEffectContents::Render().

## ◆ BindResource() [3/3]

bool impeller::Command::BindResource | ( | ShaderStage | stage,
|  | const ShaderUniformSlot & | slot,
|  | const std::shared_ptr< const ShaderMetadata > & | metadata,
|  | BufferView | view
| ) |  |

Definition at line 32 of file command.cc.

36 {
37 return DoBindResource(stage, slot, metadata, std::move(view));
38 }

## ◆ BindVertices()

bool impeller::Command::BindVertices | ( | VertexBuffer | buffer | ) |

Specify the vertex and index buffer to use for this command.

Parameters

  [in] | buffer | The vertex and index buffer definition. If possible, this value should be moved and not copied.

Returns
  returns if the binding was updated.

Definition at line 15 of file command.cc.

15 {
16 if (buffer.index_type == IndexType::kUnknown) {
17 VALIDATION_LOG << "Cannot bind vertex buffer with an unknown index type.";
18 return false;
19 }
20
21 vertex_buffer = std::move(buffer);
22 return true;
23 }

References impeller::VertexBuffer::index_type, impeller::kUnknown, VALIDATION_LOG, and vertex_buffer.

Referenced by impeller::AdvancedBlend(), impeller::scene::CuboidGeometry::BindToCommand(), impeller::scene::UnskinnedVertexBufferGeometry::BindToCommand(), impeller::scene::SkinnedVertexBufferGeometry::BindToCommand(), ImGui_ImplImpeller_RenderDrawData(), impeller::PipelineBlend(), impeller::CheckerboardContents::Render(), impeller::RuntimeEffectContents::Render(), impeller::TiledTextureContents::Render(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::SolidColorContents::Render(), impeller::TextContents::Render(), impeller::TextureContents::Render(), impeller::VerticesColorContents::Render(), impeller::AtlasContents::Render(), impeller::ClipRestoreContents::Render(), impeller::VerticesUVContents::Render(), impeller::AtlasTextureContents::Render(), impeller::AtlasColorContents::Render(), and impeller::testing::TEST_P().

## ◆ IsValid()

bool impeller::Command::IsValid | ( |  | ) | const
| inline

Definition at line 181 of file command.h.

181 { return pipeline && pipeline->IsValid(); }

References pipeline.

## Member Data Documentation

## ◆ base_vertex

uint64_t impeller::Command::base_vertex = 0u

The offset used when indexing into the vertex buffer.

Definition at line 126 of file command.h.

Referenced by ImGui_ImplImpeller_RenderDrawData().

## ◆ fragment_bindings

Bindings impeller::Command::fragment_bindings

The buffer, texture, and sampler bindings used by the fragment pipeline stage.

Definition at line 106 of file command.h.

Referenced by BindResource(), and impeller::UpdateBindingLayouts().

## ◆ instance_count

size_t impeller::Command::instance_count = 1u

The number of instances of the given set of vertices to render. Not all backends support rendering more than one instance at a time.

Warning
  Setting this to more than one will limit the availability of backends to use with this command.

Definition at line 147 of file command.h.

Referenced by impeller::testing::TEST_P().

## ◆ pipeline

std::shared_ptr<Pipeline<PipelineDescriptor> > impeller::Command::pipeline

The pipeline to use for this command.

Definition at line 96 of file command.h.

Referenced by impeller::AdvancedBlend(), impeller::scene::EncodeCommand(), impeller::EncodeCommand(), ImGui_ImplImpeller_RenderDrawData(), IsValid(), impeller::PipelineBlend(), impeller::CheckerboardContents::Render(), impeller::RuntimeEffectContents::Render(), impeller::TiledTextureContents::Render(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::SolidColorContents::Render(), impeller::TextContents::Render(), impeller::TextureContents::Render(), impeller::VerticesColorContents::Render(), impeller::AtlasContents::Render(), impeller::ClipRestoreContents::Render(), impeller::VerticesUVContents::Render(), impeller::AtlasTextureContents::Render(), impeller::AtlasColorContents::Render(), and impeller::testing::TEST_P().

## ◆ scissor

std::optional<IRect> impeller::Command::scissor

The scissor rect to use for clipping writes to the render target. The scissor rect must lie entirely within the render target. If unset, no scissor is applied.

Definition at line 139 of file command.h.

Referenced by ImGui_ImplImpeller_RenderDrawData(), and impeller::SetViewportAndScissor().

## ◆ stencil_reference

uint32_t impeller::Command::stencil_reference = 0u

The reference value to use in stenciling operations. Stencil configuration is part of pipeline setup and can be read from the pipelines descriptor.

See also
  `Pipeline`
  `PipelineDescriptor`

Definition at line 122 of file command.h.

Referenced by impeller::scene::EncodeCommand(), impeller::RuntimeEffectContents::Render(), impeller::TiledTextureContents::Render(), impeller::ClipContents::Render(), impeller::SolidRRectBlurContents::Render(), impeller::SolidColorContents::Render(), impeller::TextContents::Render(), impeller::TextureContents::Render(), impeller::VerticesColorContents::Render(), impeller::AtlasContents::Render(), impeller::ClipRestoreContents::Render(), impeller::VerticesUVContents::Render(), impeller::AtlasTextureContents::Render(), impeller::AtlasColorContents::Render(), and impeller::testing::TEST_P().

## ◆ vertex_bindings

Bindings impeller::Command::vertex_bindings

The buffer, texture, and sampler bindings used by the vertex pipeline stage.

Definition at line 101 of file command.h.

Referenced by BindResource(), and impeller::UpdateBindingLayouts().

## ◆ vertex_buffer

VertexBuffer impeller::Command::vertex_buffer

The bound per-vertex data and optional index buffer.

Definition at line 151 of file command.h.

Referenced by BindVertices().

## ◆ viewport

std::optional<Viewport> impeller::Command::viewport

The viewport coordinates that the rasterizer linearly maps normalized device coordinates to. If unset, the viewport is the size of the render target with a zero origin, znear=0, and zfar=1.

Definition at line 133 of file command.h.

Referenced by ImGui_ImplImpeller_RenderDrawData(), and impeller::SetViewportAndScissor().

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

- impeller/renderer/command.h
- impeller/renderer/command.cc

impeller::ShaderStage::kUnknown
@ kUnknown
impeller::Bindings::sampled_images
std::vector< TextureAndSampler > sampled_images
Definition: command.h:74
impeller::Command::vertex_buffer
VertexBuffer vertex_buffer
The bound per-vertex data and optional index buffer.
Definition: command.h:151
impeller::Command::vertex_bindings
Bindings vertex_bindings
Definition: command.h:101
impeller::ShaderStage::kFragment
@ kFragment
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
impeller::ShaderStage::kVertex
@ kVertex
impeller::Command::fragment_bindings
Bindings fragment_bindings
Definition: command.h:106
impeller::ShaderStage::kCompute
@ kCompute
impeller::Command::pipeline
std::shared_ptr< Pipeline< PipelineDescriptor > > pipeline
Definition: command.h:96
impeller::IndexType::kUnknown
@ kUnknown