Flutter Impeller
compute_pass_mtl.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_BACKEND_METAL_COMPUTE_PASS_MTL_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_COMPUTE_PASS_MTL_H_
7 
8 #include <Metal/Metal.h>
9 
10 #include <array>
11 #include <cstdint>
12 
16 
17 namespace impeller {
18 
19 class ComputePassMTL final : public ComputePass {
20  public:
21  // |RenderPass|
22  ~ComputePassMTL() override;
23 
24  private:
25  friend class CommandBufferMTL;
26 
27  id<MTLCommandBuffer> buffer_ = nil;
28  id<MTLComputeCommandEncoder> encoder_ = nil;
29  ComputePassBindingsCacheMTL pass_bindings_cache_ =
31  // The workgroup size of the currently bound pipeline. A dimension of 0 is
32  // resolved to the device maximum at dispatch.
33  std::array<uint32_t, 3> workgroup_size_ = {0u, 0u, 0u};
34  bool is_valid_ = false;
35  bool has_label_ = false;
36 
37  ComputePassMTL(std::shared_ptr<const Context> context,
38  id<MTLCommandBuffer> buffer);
39 
40  // |ComputePass|
41  bool IsValid() const override;
42 
43  // |ComputePass|
44  fml::Status Compute(std::array<uint32_t, 3> workgroup_count) override;
45 
46  // |ComputePass|
47  void SetCommandLabel(std::string_view label) override;
48 
49  // |ComputePass|
50  void OnSetLabel(const std::string& label) override;
51 
52  // |ComputePass|
53  void SetPipeline(const std::shared_ptr<Pipeline<ComputePipelineDescriptor>>&
54  pipeline) override;
55 
56  // |ComputePass|
57  bool BindResource(ShaderStage stage,
58  DescriptorType type,
59  const ShaderUniformSlot& slot,
60  const ShaderMetadata* metadata,
61  BufferView view) override;
62 
63  // |ComputePass|
64  bool BindResource(ShaderStage stage,
65  DescriptorType type,
66  const SampledImageSlot& slot,
67  const ShaderMetadata* metadata,
68  std::shared_ptr<const Texture> texture,
69  raw_ptr<const Sampler> sampler) override;
70 
71  // |ComputePass|
72  bool EncodeCommands() const override;
73 
74  // |ComputePass|
75  void AddBufferMemoryBarrier() override;
76 
77  // |ComputePass|
78  void AddTextureMemoryBarrier() override;
79 
80  ComputePassMTL(const ComputePassMTL&) = delete;
81 
82  ComputePassMTL& operator=(const ComputePassMTL&) = delete;
83 };
84 
85 } // namespace impeller
86 
87 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_COMPUTE_PASS_MTL_H_
Compute passes encode compute shader into the underlying command buffer.
Definition: compute_pass.h:25
A wrapper around a raw ptr that adds additional unopt mode only checks.
Definition: raw_ptr.h:15
std::shared_ptr< ContextGLES > context
std::shared_ptr< PipelineGLES > pipeline
Ensures that bindings on the pass are not redundantly set or updated. Avoids making the driver do add...
Metadata required to bind a combined texture and sampler.
Definition: shader_types.h:153
Metadata required to bind a buffer.
Definition: shader_types.h:136