Flutter Engine
Loading...
Searching...
No Matches
compute_pipeline_builder.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_COMPUTE_PIPELINE_BUILDER_H_
6
#define FLUTTER_IMPELLER_RENDERER_COMPUTE_PIPELINE_BUILDER_H_
7
8
#include <format>
9
10
#include "
impeller/base/validation.h
"
11
#include "
impeller/renderer/compute_pipeline_descriptor.h
"
12
#include "
impeller/renderer/context.h
"
13
#include "
impeller/renderer/shader_library.h
"
14
15
namespace
impeller
{
16
17
//------------------------------------------------------------------------------
18
/// @brief An optional (but highly recommended) utility for creating
19
/// pipelines from reflected shader information.
20
///
21
/// @tparam Compute_Shader The reflected compute shader information. Found
22
/// in a generated header file called
23
/// <shader_name>.comp.h.
24
///
25
template
<
class
ComputeShader_>
26
struct
ComputePipelineBuilder
{
27
public
:
28
using
ComputeShader
= ComputeShader_;
29
30
//----------------------------------------------------------------------------
31
/// @brief Create a default pipeline descriptor using the combination
32
/// reflected shader information. The descriptor can be configured
33
/// further before a pipeline state object is created using it.
34
///
35
/// @param[in] context The context
36
///
37
/// @return If the combination of reflected shader information is
38
/// compatible and the requisite functions can be found in the
39
/// context, a pipeline descriptor.
40
///
41
static
std::optional<ComputePipelineDescriptor>
MakeDefaultPipelineDescriptor
(
42
const
Context
& context) {
43
ComputePipelineDescriptor
desc;
44
if
(
InitializePipelineDescriptorDefaults
(context, desc)) {
45
return
{std::move(desc)};
46
}
47
return
std::nullopt;
48
}
49
50
[[nodiscard]]
static
bool
InitializePipelineDescriptorDefaults
(
51
const
Context
& context,
52
ComputePipelineDescriptor
& desc) {
53
// Setup debug instrumentation.
54
desc.
SetLabel
(std::format(
"{} Pipeline"
, ComputeShader::kLabel));
55
56
// Resolve pipeline entrypoints.
57
{
58
auto
compute_function = context.
GetShaderLibrary
()->GetFunction(
59
ComputeShader::kEntrypointName,
ShaderStage::kCompute
);
60
61
if
(!compute_function) {
62
VALIDATION_LOG
<<
"Could not resolve compute pipeline entrypoint '"
63
<< ComputeShader::kEntrypointName
64
<<
"' for pipeline named '"
<< ComputeShader::kLabel
65
<<
"'."
;
66
return
false
;
67
}
68
69
if
(!desc.
RegisterDescriptorSetLayouts
(
70
ComputeShader::kDescriptorSetLayouts)) {
71
VALIDATION_LOG
<<
"Could not configure compute descriptor set layout "
72
"for pipeline named '"
73
<< ComputeShader::kLabel <<
"'."
;
74
return
false
;
75
}
76
77
desc.
SetStageEntrypoint
(std::move(compute_function));
78
}
79
return
true
;
80
}
81
};
82
83
}
// namespace impeller
84
85
#endif
// FLUTTER_IMPELLER_RENDERER_COMPUTE_PIPELINE_BUILDER_H_
impeller::ComputePipelineDescriptor
Definition
compute_pipeline_descriptor.h:21
impeller::ComputePipelineDescriptor::SetLabel
ComputePipelineDescriptor & SetLabel(std::string_view label)
Definition
compute_pipeline_descriptor.cc:35
impeller::ComputePipelineDescriptor::SetStageEntrypoint
ComputePipelineDescriptor & SetStageEntrypoint(std::shared_ptr< const ShaderFunction > function)
Definition
compute_pipeline_descriptor.cc:41
impeller::ComputePipelineDescriptor::RegisterDescriptorSetLayouts
bool RegisterDescriptorSetLayouts(const std::array< DescriptorSetLayout, Size > &inputs)
Definition
compute_pipeline_descriptor.h:43
impeller::Context
To do anything rendering related with Impeller, you need a context.
Definition
context.h:65
impeller::Context::GetShaderLibrary
virtual std::shared_ptr< ShaderLibrary > GetShaderLibrary() const =0
Returns the library of shaders used to specify the programmable stages of a pipeline.
compute_pipeline_descriptor.h
context.h
shader_library.h
impeller
Definition
texture.h:16
impeller::ShaderStage::kCompute
@ kCompute
impeller::ComputePipelineBuilder
An optional (but highly recommended) utility for creating pipelines from reflected shader information...
Definition
compute_pipeline_builder.h:26
impeller::ComputePipelineBuilder::InitializePipelineDescriptorDefaults
static bool InitializePipelineDescriptorDefaults(const Context &context, ComputePipelineDescriptor &desc)
Definition
compute_pipeline_builder.h:50
impeller::ComputePipelineBuilder::MakeDefaultPipelineDescriptor
static std::optional< ComputePipelineDescriptor > MakeDefaultPipelineDescriptor(const Context &context)
Create a default pipeline descriptor using the combination reflected shader information....
Definition
compute_pipeline_builder.h:41
impeller::ComputePipelineBuilder::ComputeShader
ComputeShader_ ComputeShader
Definition
compute_pipeline_builder.h:28
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition
validation.h:91
impeller
renderer
compute_pipeline_builder.h
Generated on Thu Nov 6 2025 16:11:24 for Flutter Engine by
1.9.8