| Flutter Impeller |

compute_pass_bindings_cache_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_BINDINGS_CACHE_MTL_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_COMPUTE_PASS_BINDINGS_CACHE_MTL_H_
7
8 #include <Metal/Metal.h>
9
10 #include "flutter/fml/macros.h"
11 #include "impeller/renderer/compute_pass.h"
12 #include "impeller/renderer/pipeline_descriptor.h"
13
14 namespace impeller {
15
16 //-----------------------------------------------------------------------------
17 /// @brief Ensures that bindings on the pass are not redundantly set or
18 /// updated. Avoids making the driver do additional checks and makes
19 /// the frame insights during profiling and instrumentation not
20 /// complain about the same.
21 ///
22 /// There should be no change to rendering if this caching was
23 /// absent.
24 ///
25 struct ComputePassBindingsCacheMTL {
26 explicit ComputePassBindingsCacheMTL() {}
27
28 ComputePassBindingsCacheMTL(const ComputePassBindingsCacheMTL&) = delete;
29
30 ComputePassBindingsCacheMTL(ComputePassBindingsCacheMTL&&) = delete;
31
32 void SetComputePipelineState(id<MTLComputePipelineState> pipeline);
33
34 id<MTLComputePipelineState> GetPipeline() const;
35
36 void SetEncoder(id<MTLComputeCommandEncoder> encoder);
37
38 void SetBuffer(uint64_t index, uint64_t offset, id<MTLBuffer> buffer);
39
40 void SetTexture(uint64_t index, id<MTLTexture> texture);
41
42 void SetSampler(uint64_t index, id<MTLSamplerState> sampler);
43
44 private:
45 struct BufferOffsetPair {
46 id<MTLBuffer> buffer = nullptr;
47 size_t offset = 0u;
48 };
49 using BufferMap = std::map<uint64_t, BufferOffsetPair>;
50 using TextureMap = std::map<uint64_t, id<MTLTexture>>;
51 using SamplerMap = std::map<uint64_t, id<MTLSamplerState>>;
52
53 id<MTLComputeCommandEncoder> encoder_;
54 id<MTLComputePipelineState> pipeline_ = nullptr;
55 BufferMap buffers_;
56 TextureMap textures_;
57 SamplerMap samplers_;
58 };
59
60 } // namespace impeller
61
62 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_COMPUTE_PASS_BINDINGS_CACHE_MTL_H_
impeller::ComputePassBindingsCacheMTL::SetTexture
void SetTexture(uint64_t index, id< MTLTexture > texture)
Definition: compute_pass_bindings_cache_mtl.mm:49
impeller::ComputePassBindingsCacheMTL
Ensures that bindings on the pass are not redundantly set or updated. Avoids making the driver do add...
Definition: compute_pass_bindings_cache_mtl.h:25
impeller::ComputePassBindingsCacheMTL::SetBuffer
void SetBuffer(uint64_t index, uint64_t offset, id< MTLBuffer > buffer)
Definition: compute_pass_bindings_cache_mtl.mm:27
impeller::ComputePassBindingsCacheMTL::ComputePassBindingsCacheMTL
ComputePassBindingsCacheMTL()
Definition: compute_pass_bindings_cache_mtl.h:26
impeller::ComputePassBindingsCacheMTL::SetComputePipelineState
void SetComputePipelineState(id< MTLComputePipelineState > pipeline)
Definition: compute_pass_bindings_cache_mtl.mm:9
impeller::ComputePassBindingsCacheMTL::SetSampler
void SetSampler(uint64_t index, id< MTLSamplerState > sampler)
Definition: compute_pass_bindings_cache_mtl.mm:61
impeller::ComputePassBindingsCacheMTL::SetEncoder
void SetEncoder(id< MTLComputeCommandEncoder > encoder)
Definition: compute_pass_bindings_cache_mtl.mm:22
pipeline_descriptor.h
offset
Point offset
Definition: stroke_path_geometry.cc:300
compute_pass.h
impeller
Definition: aiks_blur_unittests.cc:20
impeller::ComputePassBindingsCacheMTL::GetPipeline
id< MTLComputePipelineState > GetPipeline() const
Definition: compute_pass_bindings_cache_mtl.mm:18