| Flutter Impeller |

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