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
14
15namespace 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///
25template <class ComputeShader_>
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) {
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,
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
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_
ComputePipelineDescriptor & SetLabel(std::string_view label)
ComputePipelineDescriptor & SetStageEntrypoint(std::shared_ptr< const ShaderFunction > function)
bool RegisterDescriptorSetLayouts(const std::array< DescriptorSetLayout, Size > &inputs)
To do anything rendering related with Impeller, you need a context.
Definition context.h:65
virtual std::shared_ptr< ShaderLibrary > GetShaderLibrary() const =0
Returns the library of shaders used to specify the programmable stages of a pipeline.
An optional (but highly recommended) utility for creating pipelines from reflected shader information...
static bool InitializePipelineDescriptorDefaults(const Context &context, ComputePipelineDescriptor &desc)
static std::optional< ComputePipelineDescriptor > MakeDefaultPipelineDescriptor(const Context &context)
Create a default pipeline descriptor using the combination reflected shader information....
#define VALIDATION_LOG
Definition validation.h:91