| 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
5 #include "impeller/renderer/backend/metal/compute_pass_bindings_cache_mtl.h"
6
7 namespace impeller {
8
9 void ComputePassBindingsCacheMTL::SetComputePipelineState(
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
22 void ComputePassBindingsCacheMTL::SetEncoder(
23 id<MTLComputeCommandEncoder> encoder) {
24 encoder_ = encoder;
25 }
26
27 void ComputePassBindingsCacheMTL::SetBuffer(uint64_t index,
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
49 void ComputePassBindingsCacheMTL::SetTexture(uint64_t index,
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
61 void ComputePassBindingsCacheMTL::SetSampler(uint64_t index,
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
impeller::ComputePassBindingsCacheMTL::SetTexture
void SetTexture(uint64_t index, id< MTLTexture > texture)
Definition: compute_pass_bindings_cache_mtl.mm:49
impeller::ComputePassBindingsCacheMTL::SetBuffer
void SetBuffer(uint64_t index, uint64_t offset, id< MTLBuffer > buffer)
Definition: compute_pass_bindings_cache_mtl.mm:27
offset
SeparatedVector2 offset
Definition: stroke_path_geometry.cc:311
impeller::ComputePassBindingsCacheMTL::SetComputePipelineState
void SetComputePipelineState(id< MTLComputePipelineState > pipeline)
Definition: compute_pass_bindings_cache_mtl.mm:9
compute_pass_bindings_cache_mtl.h
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
impeller
Definition: aiks_blend_unittests.cc:18
impeller::ComputePassBindingsCacheMTL::GetPipeline
id< MTLComputePipelineState > GetPipeline() const
Definition: compute_pass_bindings_cache_mtl.mm:18