Flutter Impeller
impeller::ComputePassBindingsCache Struct Reference

Ensures that bindings on the pass are not redundantly set or updated. Avoids making the driver do additional checks and makes the frame insights during profiling and instrumentation not complain about the same. More...

Public Member Functions

 ComputePassBindingsCache (id< MTLComputeCommandEncoder > encoder)
 
 ComputePassBindingsCache (const ComputePassBindingsCache &)=delete
 
 ComputePassBindingsCache (ComputePassBindingsCache &&)=delete
 
void SetComputePipelineState (id< MTLComputePipelineState > pipeline)
 
id< MTLComputePipelineState > GetPipeline () const
 
void SetBuffer (uint64_t index, uint64_t offset, id< MTLBuffer > buffer)
 
void SetTexture (uint64_t index, id< MTLTexture > texture)
 
void SetSampler (uint64_t index, id< MTLSamplerState > sampler)
 

Detailed Description

Ensures that bindings on the pass are not redundantly set or updated. Avoids making the driver do additional checks and makes the frame insights during profiling and instrumentation not complain about the same.

There should be no change to rendering if this caching was absent.

Definition at line 90 of file compute_pass_mtl.mm.

Constructor & Destructor Documentation

◆ ComputePassBindingsCache() [1/3]

impeller::ComputePassBindingsCache::ComputePassBindingsCache ( id< MTLComputeCommandEncoder >  encoder)
inlineexplicit

Definition at line 91 of file compute_pass_mtl.mm.

92  : encoder_(encoder) {}

◆ ComputePassBindingsCache() [2/3]

impeller::ComputePassBindingsCache::ComputePassBindingsCache ( const ComputePassBindingsCache )
delete

◆ ComputePassBindingsCache() [3/3]

impeller::ComputePassBindingsCache::ComputePassBindingsCache ( ComputePassBindingsCache &&  )
delete

Member Function Documentation

◆ GetPipeline()

id<MTLComputePipelineState> impeller::ComputePassBindingsCache::GetPipeline ( ) const
inline

Definition at line 106 of file compute_pass_mtl.mm.

106 { return pipeline_; }

◆ SetBuffer()

void impeller::ComputePassBindingsCache::SetBuffer ( uint64_t  index,
uint64_t  offset,
id< MTLBuffer >  buffer 
)
inline

Definition at line 108 of file compute_pass_mtl.mm.

108  {
109  auto found = buffers_.find(index);
110  if (found != buffers_.end() && found->second.buffer == buffer) {
111  // The right buffer is bound. Check if its offset needs to be updated.
112  if (found->second.offset == offset) {
113  // Buffer and its offset is identical. Nothing to do.
114  return;
115  }
116 
117  // Only the offset needs to be updated.
118  found->second.offset = offset;
119 
120  [encoder_ setBufferOffset:offset atIndex:index];
121  return;
122  }
123 
124  buffers_[index] = {buffer, static_cast<size_t>(offset)};
125  [encoder_ setBuffer:buffer offset:offset atIndex:index];
126  }

Referenced by impeller::Bind().

◆ SetComputePipelineState()

void impeller::ComputePassBindingsCache::SetComputePipelineState ( id< MTLComputePipelineState >  pipeline)
inline

Definition at line 98 of file compute_pass_mtl.mm.

98  {
99  if (pipeline == pipeline_) {
100  return;
101  }
102  pipeline_ = pipeline;
103  [encoder_ setComputePipelineState:pipeline_];
104  }

◆ SetSampler()

void impeller::ComputePassBindingsCache::SetSampler ( uint64_t  index,
id< MTLSamplerState >  sampler 
)
inline

Definition at line 139 of file compute_pass_mtl.mm.

139  {
140  auto found = samplers_.find(index);
141  if (found != samplers_.end() && found->second == sampler) {
142  // Already bound.
143  return;
144  }
145  samplers_[index] = sampler;
146  [encoder_ setSamplerState:sampler atIndex:index];
147  return;
148  }

Referenced by impeller::Bind().

◆ SetTexture()

void impeller::ComputePassBindingsCache::SetTexture ( uint64_t  index,
id< MTLTexture >  texture 
)
inline

Definition at line 128 of file compute_pass_mtl.mm.

128  {
129  auto found = textures_.find(index);
130  if (found != textures_.end() && found->second == texture) {
131  // Already bound.
132  return;
133  }
134  textures_[index] = texture;
135  [encoder_ setTexture:texture atIndex:index];
136  return;
137  }

Referenced by impeller::Bind().


The documentation for this struct was generated from the following file: