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 
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_>
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) {
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,
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 
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_
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.
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
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....
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:68
#define VALIDATION_LOG
Definition: validation.h:91