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