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
(
const
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_bindings
.
vertex_buffer
=
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
}
28
29
BufferView
Command::GetVertexBuffer
()
const
{
30
return
vertex_bindings
.
vertex_buffer
.
view
.
resource
;
31
}
32
33
bool
Command::BindResource
(
ShaderStage
stage,
34
const
ShaderUniformSlot
& slot,
35
const
ShaderMetadata
& metadata,
36
const
BufferView
& view) {
37
return
DoBindResource(stage, slot, &metadata, view);
38
}
39
40
bool
Command::BindResource
(
41
ShaderStage
stage,
42
const
ShaderUniformSlot
& slot,
43
const
std::shared_ptr<const ShaderMetadata>& metadata,
44
const
BufferView
& view) {
45
return
DoBindResource(stage, slot, metadata, view);
46
}
47
48
template
<
class
T>
49
bool
Command::DoBindResource(
ShaderStage
stage,
50
const
ShaderUniformSlot
& slot,
51
const
T metadata,
52
const
BufferView
& view) {
53
FML_DCHECK(slot.
ext_res_0
!=
VertexDescriptor::kReservedVertexBufferIndex
);
54
if
(!view) {
55
return
false
;
56
}
57
58
switch
(stage) {
59
case
ShaderStage::kVertex
:
60
vertex_bindings
.
buffers
[slot.
ext_res_0
] = {
61
.slot = slot, .view =
BufferResource
(metadata, view)};
62
return
true
;
63
case
ShaderStage::kFragment
:
64
fragment_bindings
.
buffers
[slot.
ext_res_0
] = {
65
.slot = slot, .view =
BufferResource
(metadata, view)};
66
return
true
;
67
case
ShaderStage::kCompute
:
68
VALIDATION_LOG
<<
"Use ComputeCommands for compute shader stages."
;
69
case
ShaderStage::kTessellationControl
:
70
case
ShaderStage::kTessellationEvaluation
:
71
case
ShaderStage::kUnknown
:
72
return
false
;
73
}
74
75
return
false
;
76
}
77
78
bool
Command::BindResource
(
ShaderStage
stage,
79
const
SampledImageSlot
& slot,
80
const
ShaderMetadata
& metadata,
81
const
std::shared_ptr<const Texture>& texture,
82
const
std::shared_ptr<const Sampler>& sampler) {
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) {
94
case
ShaderStage::kVertex
:
95
vertex_bindings
.
sampled_images
[slot.
sampler_index
] =
TextureAndSampler
{
96
.
slot
= slot,
97
.texture = {&metadata, texture},
98
.sampler = {&metadata, sampler},
99
};
100
return
true
;
101
case
ShaderStage::kFragment
:
102
fragment_bindings
.
sampled_images
[slot.
sampler_index
] =
TextureAndSampler
{
103
.
slot
= slot,
104
.texture = {&metadata, texture},
105
.sampler = {&metadata, sampler},
106
};
107
return
true
;
108
case
ShaderStage::kCompute
:
109
VALIDATION_LOG
<<
"Use ComputeCommands for compute shader stages."
;
110
case
ShaderStage::kUnknown
:
111
case
ShaderStage::kTessellationControl
:
112
case
ShaderStage::kTessellationEvaluation
:
113
return
false
;
114
}
115
116
return
false
;
117
}
118
119
}
// namespace impeller
impeller::Command::vertex_count
size_t vertex_count
Definition:
command.h:131
impeller::VertexBuffer::index_type
IndexType index_type
Definition:
vertex_buffer.h:18
impeller::ShaderUniformSlot::ext_res_0
size_t ext_res_0
Definition:
shader_types.h:83
impeller::ShaderUniformSlot
Definition:
shader_types.h:81
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::ShaderMetadata
Definition:
shader_types.h:76
impeller::VertexBuffer
Definition:
vertex_buffer.h:12
formats.h
impeller::ShaderStage
ShaderStage
Definition:
shader_types.h:20
impeller::Bindings::buffers
std::map< size_t, BufferAndUniformSlot > buffers
Definition:
command.h:79
impeller::VertexBuffer::vertex_buffer
BufferView vertex_buffer
Definition:
vertex_buffer.h:13
impeller::Bindings::vertex_buffer
BufferAndUniformSlot vertex_buffer
Definition:
command.h:81
impeller::VertexBuffer::vertex_count
size_t vertex_count
Definition:
vertex_buffer.h:17
validation.h
impeller::Command::GetVertexBuffer
BufferView GetVertexBuffer() const
Definition:
command.cc:29
vertex_descriptor.h
command.h
impeller::Command::vertex_bindings
Bindings vertex_bindings
Definition:
command.h:108
impeller::SampledImageSlot
Definition:
shader_types.h:129
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::Command::BindResource
bool BindResource(ShaderStage stage, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, const BufferView &view) override
Definition:
command.cc:33
impeller::ShaderStage::kFragment
@ kFragment
impeller::SampledImageSlot::HasSampler
constexpr bool HasSampler() const
Definition:
shader_types.h:138
impeller::TextureAndSampler
combines the texture, sampler and sampler slot information.
Definition:
command.h:65
impeller::VertexBuffer::index_buffer
BufferView index_buffer
Definition:
vertex_buffer.h:14
impeller::BufferAndUniformSlot::slot
ShaderUniformSlot slot
Definition:
command.h:73
VALIDATION_LOG
#define VALIDATION_LOG
Definition:
validation.h:60
impeller::TextureAndSampler::slot
SampledImageSlot slot
Definition:
command.h:66
impeller::BufferView
Definition:
buffer_view.h:13
impeller::SampledImageSlot::sampler_index
size_t sampler_index
Definition:
shader_types.h:132
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:113
impeller::SampledImageSlot::HasTexture
constexpr bool HasTexture() const
Definition:
shader_types.h:136
impeller::ShaderStage::kCompute
@ kCompute
impeller::ShaderStage::kTessellationControl
@ kTessellationControl
impeller::Command::BindVertices
bool BindVertices(const VertexBuffer &buffer)
Specify the vertex and index buffer to use for this command.
Definition:
command.cc:15
impeller
Definition:
aiks_context.cc:10
impeller::BufferAndUniformSlot
combines the buffer resource and its uniform slot information.
Definition:
command.h:72
impeller::IndexType::kUnknown
@ kUnknown
impeller::Command::index_buffer
BufferView index_buffer
Definition:
command.h:121
impeller::BufferResource
Resource< BufferView > BufferResource
Definition:
command.h:60
impeller
renderer
command.cc
Generated by
1.8.17