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 89 of file compute_pass_mtl.mm.

Constructor & Destructor Documentation

◆ ComputePassBindingsCache() [1/3]

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

Definition at line 90 of file compute_pass_mtl.mm.

91  : 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 105 of file compute_pass_mtl.mm.

105 { return pipeline_; }

◆ SetBuffer()

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

Definition at line 107 of file compute_pass_mtl.mm.

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

Referenced by impeller::Bind().

◆ SetComputePipelineState()

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

Definition at line 97 of file compute_pass_mtl.mm.

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

◆ SetSampler()

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

Definition at line 138 of file compute_pass_mtl.mm.

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

Referenced by impeller::Bind().

◆ SetTexture()

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

Definition at line 127 of file compute_pass_mtl.mm.

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

Referenced by impeller::Bind().


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