| Flutter Impeller |

command.cc
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 #include "impeller/renderer/command.h"
6
7 #include <utility>
8
9 #include "impeller/base/validation.h"
10 #include "impeller/core/formats.h"
11 #include "impeller/renderer/vertex_descriptor.h"
12
13 namespace impeller {
14
15 bool Command::BindVertices(VertexBuffer buffer) {
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 }
24
25 bool Command::BindResource(ShaderStage stage,
26 DescriptorType type,
27 const ShaderUniformSlot& slot,
28 const ShaderMetadata& metadata,
29 BufferView view) {
30 return DoBindResource(stage, slot, &metadata, std::move(view));
31 }
32
33 bool Command::BindResource(
34 ShaderStage stage,
35 DescriptorType type,
36 const ShaderUniformSlot& slot,
37 const std::shared_ptr<const ShaderMetadata>& metadata,
38 BufferView view) {
39 return DoBindResource(stage, slot, metadata, std::move(view));
40 }
41
42 template <class T>
43 bool Command::DoBindResource(ShaderStage stage,
44 const ShaderUniformSlot& slot,
45 const T metadata,
46 BufferView view) {
47 FML_DCHECK(slot.ext_res_0 != VertexDescriptor::kReservedVertexBufferIndex);
48 if (!view) {
49 return false;
50 }
51
52 switch (stage) {
53 case ShaderStage::kVertex:
54 vertex_bindings.buffers.emplace_back(BufferAndUniformSlot{
55 .slot = slot, .view = BufferResource(metadata, std::move(view))});
56 return true;
57 case ShaderStage::kFragment:
58 fragment_bindings.buffers.emplace_back(BufferAndUniformSlot{
59 .slot = slot, .view = BufferResource(metadata, std::move(view))});
60 return true;
61 case ShaderStage::kCompute:
62 VALIDATION_LOG << "Use ComputeCommands for compute shader stages.";
63 case ShaderStage::kUnknown:
64 return false;
65 }
66
67 return false;
68 }
69
70 bool Command::BindResource(ShaderStage stage,
71 DescriptorType type,
72 const SampledImageSlot& slot,
73 const ShaderMetadata& metadata,
74 std::shared_ptr<const Texture> texture,
75 const std::unique_ptr<const Sampler>& sampler) {
76 if (!sampler) {
77 return false;
78 }
79 if (!texture || !texture->IsValid()) {
80 return false;
81 }
82
83 switch (stage) {
84 case ShaderStage::kVertex:
85 vertex_bindings.sampled_images.emplace_back(TextureAndSampler{
86 .slot = slot,
87 .texture = {&metadata, std::move(texture)},
88 .sampler = sampler,
89 });
90 return true;
91 case ShaderStage::kFragment:
92 fragment_bindings.sampled_images.emplace_back(TextureAndSampler{
93 .slot = slot,
94 .texture = {&metadata, std::move(texture)},
95 .sampler = sampler,
96 });
97 return true;
98 case ShaderStage::kCompute:
99 VALIDATION_LOG << "Use ComputeCommands for compute shader stages.";
100 case ShaderStage::kUnknown:
101 return false;
102 }
103
104 return false;
105 }
106
107 } // namespace impeller
impeller::VertexBuffer::index_type
IndexType index_type
Definition: vertex_buffer.h:29
impeller::ShaderUniformSlot::ext_res_0
size_t ext_res_0
ext_res_0 is the Metal binding value.
Definition: shader_types.h:86
impeller::ShaderUniformSlot
Metadata required to bind a buffer.
Definition: shader_types.h:81
impeller::ShaderStage::kUnknown
@ kUnknown
impeller::ShaderMetadata
Definition: shader_types.h:72
impeller::VertexBuffer
Definition: vertex_buffer.h:13
formats.h
impeller::Bindings::sampled_images
std::vector< TextureAndSampler > sampled_images
Definition: command.h:74
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
validation.h
vertex_descriptor.h
impeller::Command::vertex_buffer
VertexBuffer vertex_buffer
The bound per-vertex data and optional index buffer.
Definition: command.h:151
command.h
impeller::Command::vertex_bindings
Bindings vertex_bindings
Definition: command.h:101
impeller::SampledImageSlot
Metadata required to bind a combined texture and sampler.
Definition: shader_types.h:98
impeller::Command::BindVertices
bool BindVertices(VertexBuffer buffer)
Specify the vertex and index buffer to use for this command.
Definition: command.cc:15
impeller::ShaderStage::kFragment
@ kFragment
impeller::TextureAndSampler
combines the texture, sampler and sampler slot information.
Definition: command.h:61
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::Command::BindResource
bool BindResource(ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, BufferView view) override
Definition: command.cc:25
impeller::TextureAndSampler::slot
SampledImageSlot slot
Definition: command.h:62
impeller::BufferView
Definition: buffer_view.h:15
impeller::Bindings::buffers
std::vector< BufferAndUniformSlot > buffers
Definition: command.h:75
impeller::VertexDescriptor::kReservedVertexBufferIndex
static constexpr size_t kReservedVertexBufferIndex
Definition: vertex_descriptor.h:25
impeller::ShaderStage::kVertex
@ kVertex
impeller::Command::fragment_bindings
Bindings fragment_bindings
Definition: command.h:106
impeller::ShaderStage::kCompute
@ kCompute
impeller
Definition: aiks_blur_unittests.cc:20
impeller::IndexType::kUnknown
@ kUnknown
impeller::DescriptorType
DescriptorType
Definition: shader_types.h:153
impeller::BufferResource
Resource< BufferView > BufferResource
Definition: command.h:57