Flutter Impeller
command.h
Go to the documentation of this file.
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#ifndef FLUTTER_IMPELLER_RENDERER_COMMAND_H_
6
#define FLUTTER_IMPELLER_RENDERER_COMMAND_H_
7
8
#include <cstdint>
9
#include <memory>
10
#include <optional>
11
#include <string>
12
13
#include "
impeller/core/buffer_view.h
"
14
#include "
impeller/core/formats.h
"
15
#include "
impeller/core/sampler.h
"
16
#include "
impeller/core/shader_types.h
"
17
#include "
impeller/core/texture.h
"
18
#include "
impeller/geometry/rect.h
"
19
#include "
impeller/renderer/pipeline.h
"
20
21
namespace
impeller
{
22
23
template
<
class
T>
24
class
Resource
{
25
public
:
26
using
ResourceType
= T;
27
ResourceType
resource
;
28
29
Resource
() {}
30
31
Resource
(
const
ShaderMetadata
* metadata,
ResourceType
p_resource)
32
:
resource
(p_resource), metadata_(metadata) {}
33
34
const
ShaderMetadata
*
GetMetadata
()
const
{
35
return
dynamic_metadata_ ? dynamic_metadata_.get() : metadata_;
36
}
37
38
static
Resource
MakeDynamic
(std::unique_ptr<ShaderMetadata> metadata,
39
ResourceType
p_resource) {
40
return
Resource
(std::move(metadata), p_resource);
41
}
42
43
private
:
44
Resource
(std::unique_ptr<ShaderMetadata> metadata,
ResourceType
p_resource)
45
:
resource
(p_resource), dynamic_metadata_(
std
::move(metadata)) {}
46
47
// Static shader metadata (typically generated by ImpellerC).
48
const
ShaderMetadata* metadata_ =
nullptr
;
49
50
// Dynamically generated shader metadata.
51
std::unique_ptr<const ShaderMetadata> dynamic_metadata_ =
nullptr
;
52
};
53
54
using
BufferResource
=
Resource<BufferView>
;
55
using
TextureResource
=
Resource<std::shared_ptr<const Texture>
>;
56
57
/// @brief combines the texture, sampler and sampler slot information.
58
struct
TextureAndSampler
{
59
SampledImageSlot
slot
;
60
ShaderStage
stage
;
61
TextureResource
texture
;
62
raw_ptr<const Sampler>
sampler
;
63
};
64
65
//------------------------------------------------------------------------------
66
/// @brief An object used to specify work to the GPU along with references
67
/// to resources the GPU will used when doing said work.
68
///
69
/// To construct a valid command, follow these steps:
70
/// * Specify a valid pipeline.
71
/// * Specify vertex information via a call `BindVertices`
72
/// * Specify any stage bindings.
73
/// * (Optional) Specify a debug label.
74
///
75
/// Command can be created frequently and on demand. The resources
76
/// referenced in commands views into buffers managed by other
77
/// allocators and resource managers.
78
///
79
struct
Command
{
80
//----------------------------------------------------------------------------
81
/// The pipeline to use for this command.
82
///
83
PipelineRef
pipeline
;
84
85
/// An offset into render pass storage where bound buffers/texture metadata is
86
/// stored.
87
Range
bound_buffers
=
Range
{0, 0};
88
Range
bound_textures
=
Range
{0, 0};
89
90
#ifdef IMPELLER_DEBUG
91
//----------------------------------------------------------------------------
92
/// The debugging label to use for the command.
93
///
94
std::string label;
95
#endif
// IMPELLER_DEBUG
96
97
//----------------------------------------------------------------------------
98
/// The reference value to use in stenciling operations. Stencil configuration
99
/// is part of pipeline setup and can be read from the pipelines descriptor.
100
///
101
/// @see `Pipeline`
102
/// @see `PipelineDescriptor`
103
///
104
uint32_t
stencil_reference
= 0u;
105
//----------------------------------------------------------------------------
106
/// The offset used when indexing into the vertex buffer.
107
///
108
uint64_t
base_vertex
= 0u;
109
//----------------------------------------------------------------------------
110
/// The viewport coordinates that the rasterizer linearly maps normalized
111
/// device coordinates to.
112
/// If unset, the viewport is the size of the render target with a zero
113
/// origin, znear=0, and zfar=1.
114
///
115
std::optional<Viewport>
viewport
;
116
//----------------------------------------------------------------------------
117
/// The scissor rect to use for clipping writes to the render target. The
118
/// scissor rect must lie entirely within the render target.
119
/// If unset, no scissor is applied.
120
///
121
std::optional<IRect>
scissor
;
122
//----------------------------------------------------------------------------
123
/// The number of instances of the given set of vertices to render. Not all
124
/// backends support rendering more than one instance at a time.
125
///
126
/// @warning Setting this to more than one will limit the availability of
127
/// backends to use with this command.
128
///
129
size_t
instance_count
= 1u;
130
131
//----------------------------------------------------------------------------
132
/// An offset and range of vertex buffers bound for this draw call.
133
///
134
/// The vertex buffers are stored on the render pass object.
135
Range
vertex_buffers
;
136
137
//----------------------------------------------------------------------------
138
/// The index buffer binding used by the vertex shader stage.
139
BufferView
index_buffer
;
140
141
//----------------------------------------------------------------------------
142
/// The number of elements to draw. When only a vertex buffer is set, this is
143
/// the vertex count. When an index buffer is set, this is the index count.
144
size_t
element_count
= 0u;
145
146
//----------------------------------------------------------------------------
147
/// The type of indices in the index buffer. The indices must be tightly
148
/// packed in the index buffer.
149
IndexType
index_type
=
IndexType::kUnknown
;
150
151
bool
IsValid
()
const
{
return
pipeline
&&
pipeline
->
IsValid
(); }
152
};
153
154
}
// namespace impeller
155
156
#endif
// FLUTTER_IMPELLER_RENDERER_COMMAND_H_
buffer_view.h
impeller::Pipeline::IsValid
virtual bool IsValid() const =0
impeller::Resource
Definition:
command.h:24
impeller::Resource::MakeDynamic
static Resource MakeDynamic(std::unique_ptr< ShaderMetadata > metadata, ResourceType p_resource)
Definition:
command.h:38
impeller::Resource::ResourceType
T ResourceType
Definition:
command.h:26
impeller::Resource::Resource
Resource()
Definition:
command.h:29
impeller::Resource::GetMetadata
const ShaderMetadata * GetMetadata() const
Definition:
command.h:34
impeller::Resource::Resource
Resource(const ShaderMetadata *metadata, ResourceType p_resource)
Definition:
command.h:31
impeller::Resource::resource
ResourceType resource
Definition:
command.h:27
impeller::raw_ptr
A wrapper around a raw ptr that adds additional unopt mode only checks.
Definition:
raw_ptr.h:15
formats.h
texture.h
impeller
Definition:
allocation.cc:12
impeller::IndexType
IndexType
Definition:
formats.h:343
impeller::IndexType::kUnknown
@ kUnknown
impeller::ShaderStage
ShaderStage
Definition:
shader_types.h:22
std
Definition:
comparable.h:95
pipeline.h
rect.h
sampler.h
shader_types.h
impeller::BufferView
Definition:
buffer_view.h:19
impeller::Command
An object used to specify work to the GPU along with references to resources the GPU will used when d...
Definition:
command.h:79
impeller::Command::bound_textures
Range bound_textures
Definition:
command.h:88
impeller::Command::base_vertex
uint64_t base_vertex
Definition:
command.h:108
impeller::Command::stencil_reference
uint32_t stencil_reference
Definition:
command.h:104
impeller::Command::index_buffer
BufferView index_buffer
The index buffer binding used by the vertex shader stage.
Definition:
command.h:139
impeller::Command::viewport
std::optional< Viewport > viewport
Definition:
command.h:115
impeller::Command::vertex_buffers
Range vertex_buffers
Definition:
command.h:135
impeller::Command::bound_buffers
Range bound_buffers
Definition:
command.h:87
impeller::Command::pipeline
PipelineRef pipeline
Definition:
command.h:83
impeller::Command::scissor
std::optional< IRect > scissor
Definition:
command.h:121
impeller::Command::index_type
IndexType index_type
Definition:
command.h:149
impeller::Command::element_count
size_t element_count
Definition:
command.h:144
impeller::Command::IsValid
bool IsValid() const
Definition:
command.h:151
impeller::Command::instance_count
size_t instance_count
Definition:
command.h:129
impeller::Range
Definition:
range.h:13
impeller::SampledImageSlot
Metadata required to bind a combined texture and sampler.
Definition:
shader_types.h:98
impeller::ShaderMetadata
Definition:
shader_types.h:72
impeller::TextureAndSampler
combines the texture, sampler and sampler slot information.
Definition:
command.h:58
impeller::TextureAndSampler::sampler
raw_ptr< const Sampler > sampler
Definition:
command.h:62
impeller::TextureAndSampler::slot
SampledImageSlot slot
Definition:
command.h:59
impeller::TextureAndSampler::texture
TextureResource texture
Definition:
command.h:61
impeller::TextureAndSampler::stage
ShaderStage stage
Definition:
command.h:60
impeller
renderer
command.h
Generated by
1.9.1