forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompute_command.cc
More file actions
87 lines (73 loc) · 2.33 KB
/
compute_command.cc
File metadata and controls
87 lines (73 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "impeller/renderer/compute_command.h"
#include <utility>
#include "impeller/base/validation.h"
#include "impeller/renderer/formats.h"
#include "impeller/renderer/vertex_descriptor.h"
namespace impeller {
bool ComputeCommand::BindResource(ShaderStage stage,
const ShaderUniformSlot& slot,
const ShaderMetadata& metadata,
const BufferView& view) {
if (stage != ShaderStage::kCompute) {
VALIDATION_LOG << "Use Command for non-compute shader stages.";
return false;
}
if (!view) {
return false;
}
bindings.buffers[slot.ext_res_0] = {&metadata, view};
return true;
}
bool ComputeCommand::BindResource(
ShaderStage stage,
const SampledImageSlot& slot,
const ShaderMetadata& metadata,
const std::shared_ptr<const Texture>& texture) {
if (stage != ShaderStage::kCompute) {
VALIDATION_LOG << "Use Command for non-compute shader stages.";
return false;
}
if (!texture || !texture->IsValid()) {
return false;
}
if (!slot.HasTexture()) {
return true;
}
bindings.textures[slot.texture_index] = {&metadata, texture};
return true;
}
bool ComputeCommand::BindResource(
ShaderStage stage,
const SampledImageSlot& slot,
const ShaderMetadata& metadata,
const std::shared_ptr<const Sampler>& sampler) {
if (stage != ShaderStage::kCompute) {
VALIDATION_LOG << "Use Command for non-compute shader stages.";
return false;
}
if (!sampler || !sampler->IsValid()) {
return false;
}
if (!slot.HasSampler()) {
return true;
}
bindings.samplers[slot.sampler_index] = {&metadata, sampler};
return true;
}
bool ComputeCommand::BindResource(
ShaderStage stage,
const SampledImageSlot& slot,
const ShaderMetadata& metadata,
const std::shared_ptr<const Texture>& texture,
const std::shared_ptr<const Sampler>& sampler) {
if (stage != ShaderStage::kCompute) {
VALIDATION_LOG << "Use Command for non-compute shader stages.";
return false;
}
return BindResource(stage, slot, metadata, texture) &&
BindResource(stage, slot, metadata, sampler);
}
} // namespace impeller