Flutter Impeller
compute_pass_bindings_cache_mtl.mm
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 
6 
7 namespace impeller {
8 
10  id<MTLComputePipelineState> pipeline) {
11  if (pipeline == pipeline_) {
12  return;
13  }
14  pipeline_ = pipeline;
15  [encoder_ setComputePipelineState:pipeline_];
16 }
17 
18 id<MTLComputePipelineState> ComputePassBindingsCacheMTL::GetPipeline() const {
19  return pipeline_;
20 }
21 
23  id<MTLComputeCommandEncoder> encoder) {
24  encoder_ = encoder;
25 }
26 
28  uint64_t offset,
29  id<MTLBuffer> buffer) {
30  auto found = buffers_.find(index);
31  if (found != buffers_.end() && found->second.buffer == buffer) {
32  // The right buffer is bound. Check if its offset needs to be updated.
33  if (found->second.offset == offset) {
34  // Buffer and its offset is identical. Nothing to do.
35  return;
36  }
37 
38  // Only the offset needs to be updated.
39  found->second.offset = offset;
40 
41  [encoder_ setBufferOffset:offset atIndex:index];
42  return;
43  }
44 
45  buffers_[index] = {buffer, static_cast<size_t>(offset)};
46  [encoder_ setBuffer:buffer offset:offset atIndex:index];
47 }
48 
50  id<MTLTexture> texture) {
51  auto found = textures_.find(index);
52  if (found != textures_.end() && found->second == texture) {
53  // Already bound.
54  return;
55  }
56  textures_[index] = texture;
57  [encoder_ setTexture:texture atIndex:index];
58  return;
59 }
60 
62  id<MTLSamplerState> sampler) {
63  auto found = samplers_.find(index);
64  if (found != samplers_.end() && found->second == sampler) {
65  // Already bound.
66  return;
67  }
68  samplers_[index] = sampler;
69  [encoder_ setSamplerState:sampler atIndex:index];
70  return;
71 }
72 
73 } // namespace impeller
void SetEncoder(id< MTLComputeCommandEncoder > encoder)
void SetComputePipelineState(id< MTLComputePipelineState > pipeline)
void SetBuffer(uint64_t index, uint64_t offset, id< MTLBuffer > buffer)
void SetSampler(uint64_t index, id< MTLSamplerState > sampler)
id< MTLComputePipelineState > GetPipeline() const
void SetTexture(uint64_t index, id< MTLTexture > texture)