Flutter Impeller
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:
impeller::ResourceBinder

Public Member Functions

bool BindVertices (const VertexBuffer &buffer)
 Specify the vertex and index buffer to use for this command. More...
 
bool BindResource (ShaderStage stage, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, const BufferView &view) override
 
bool BindResource (ShaderStage stage, const ShaderUniformSlot &slot, const std::shared_ptr< const ShaderMetadata > &metadata, const BufferView &view)
 
bool BindResource (ShaderStage stage, const SampledImageSlot &slot, const ShaderMetadata &metadata, const std::shared_ptr< const Texture > &texture, const std::shared_ptr< const Sampler > &sampler) override
 
BufferView GetVertexBuffer () const
 
constexpr operator bool () 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
 
BufferView index_buffer
 
size_t vertex_count = 0u
 
IndexType index_type = IndexType::kUnknown
 
uint32_t stencil_reference = 0u
 
uint64_t base_vertex = 0u
 
std::optional< Viewportviewport
 
std::optional< IRectscissor
 
size_t instance_count = 1u
 

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 are very lightweight objects and 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 99 of file command.h.

Member Function Documentation

◆ BindResource() [1/3]

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

Implements impeller::ResourceBinder.

Definition at line 78 of file command.cc.

82  {
83  if (!sampler || !sampler->IsValid()) {
84  return false;
85  }
86  if (!texture || !texture->IsValid()) {
87  return false;
88  }
89  if (!slot.HasSampler() || !slot.HasTexture()) {
90  return true;
91  }
92 
93  switch (stage) {
95  vertex_bindings.sampled_images[slot.sampler_index] = TextureAndSampler{
96  .slot = slot,
97  .texture = {&metadata, texture},
98  .sampler = {&metadata, sampler},
99  };
100  return true;
102  fragment_bindings.sampled_images[slot.sampler_index] = TextureAndSampler{
103  .slot = slot,
104  .texture = {&metadata, texture},
105  .sampler = {&metadata, sampler},
106  };
107  return true;
109  VALIDATION_LOG << "Use ComputeCommands for compute shader stages.";
113  return false;
114  }
115 
116  return false;
117 }

References fragment_bindings, impeller::SampledImageSlot::HasSampler(), impeller::SampledImageSlot::HasTexture(), impeller::kCompute, impeller::kFragment, impeller::kTessellationControl, impeller::kTessellationEvaluation, impeller::kUnknown, impeller::kVertex, impeller::Bindings::sampled_images, impeller::SampledImageSlot::sampler_index, impeller::TextureAndSampler::slot, VALIDATION_LOG, and vertex_bindings.

◆ BindResource() [2/3]

bool impeller::Command::BindResource ( ShaderStage  stage,
const ShaderUniformSlot slot,
const ShaderMetadata metadata,
const BufferView view 
)
overridevirtual

Implements impeller::ResourceBinder.

Definition at line 33 of file command.cc.

36  {
37  return DoBindResource(stage, slot, &metadata, view);
38 }

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

◆ BindResource() [3/3]

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

Definition at line 40 of file command.cc.

44  {
45  return DoBindResource(stage, slot, metadata, view);
46 }

◆ BindVertices()

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

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

Parameters
[in]bufferThe vertex and index buffer definition.
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 
22  BufferAndUniformSlot{.slot = {}, .view = {nullptr, buffer.vertex_buffer}};
23  index_buffer = buffer.index_buffer;
24  vertex_count = buffer.vertex_count;
25  index_type = buffer.index_type;
26  return true;
27 }

References impeller::VertexBuffer::index_buffer, index_buffer, impeller::VertexBuffer::index_type, index_type, impeller::kUnknown, impeller::BufferAndUniformSlot::slot, VALIDATION_LOG, vertex_bindings, impeller::VertexBuffer::vertex_buffer, impeller::Bindings::vertex_buffer, impeller::VertexBuffer::vertex_count, and vertex_count.

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().

◆ GetVertexBuffer()

BufferView impeller::Command::GetVertexBuffer ( ) const

◆ operator bool()

constexpr impeller::Command::operator bool ( ) const
inlineexplicitconstexpr

Definition at line 208 of file command.h.

208  {
209  return pipeline && pipeline->IsValid();
210  }

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 156 of file command.h.

Referenced by impeller::EncodeCommand(), and 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 113 of file command.h.

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

◆ index_buffer

BufferView impeller::Command::index_buffer

The index buffer binding used by the vertex shader stage. Instead of setting this directly, it usually easier to specify the vertex and index buffer bindings directly via a single call to BindVertices.

See also
BindVertices

Definition at line 121 of file command.h.

Referenced by BindVertices(), and impeller::EncodeCommand().

◆ index_type

IndexType impeller::Command::index_type = IndexType::kUnknown

The type of indices in the index buffer. The indices must be tightly packed in the index buffer.

Definition at line 136 of file command.h.

Referenced by BindVertices(), and impeller::EncodeCommand().

◆ 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 177 of file command.h.

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

◆ pipeline

◆ 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 169 of file command.h.

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

◆ stencil_reference

◆ vertex_bindings

Bindings impeller::Command::vertex_bindings

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

Definition at line 108 of file command.h.

Referenced by impeller::AllocateAndBindDescriptorSets(), BindResource(), BindVertices(), GetVertexBuffer(), and impeller::UpdateBindingLayouts().

◆ vertex_count

size_t impeller::Command::vertex_count = 0u

The number of vertices to draw.

If the index_type is IndexType::kNone, this is a count into the vertex buffer. Otherwise, it is a count into the index buffer. Set the vertex and index buffers as well as the index count using a call to BindVertices.

See also
BindVertices

Definition at line 131 of file command.h.

Referenced by BindVertices(), and impeller::EncodeCommand().

◆ 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 163 of file command.h.

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


The documentation for this struct was generated from the following files:
impeller::Command::vertex_count
size_t vertex_count
Definition: command.h:131
impeller::Resource::resource
ResourceType resource
Definition: command.h:37
impeller::Command::index_type
IndexType index_type
Definition: command.h:136
impeller::ShaderStage::kUnknown
@ kUnknown
impeller::Bindings::vertex_buffer
BufferAndUniformSlot vertex_buffer
Definition: command.h:81
impeller::Command::vertex_bindings
Bindings vertex_bindings
Definition: command.h:108
impeller::BufferAndUniformSlot::view
BufferResource view
Definition: command.h:74
impeller::Bindings::sampled_images
std::map< size_t, TextureAndSampler > sampled_images
Definition: command.h:78
impeller::ShaderStage::kTessellationEvaluation
@ kTessellationEvaluation
impeller::ShaderStage::kFragment
@ kFragment
impeller::BufferAndUniformSlot::slot
ShaderUniformSlot slot
Definition: command.h:73
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::ShaderStage::kVertex
@ kVertex
impeller::Command::fragment_bindings
Bindings fragment_bindings
Definition: command.h:113
impeller::ShaderStage::kCompute
@ kCompute
impeller::ShaderStage::kTessellationControl
@ kTessellationControl
impeller::Command::pipeline
std::shared_ptr< Pipeline< PipelineDescriptor > > pipeline
Definition: command.h:103
impeller::IndexType::kUnknown
@ kUnknown
impeller::Command::index_buffer
BufferView index_buffer
Definition: command.h:121