@@ -127,21 +127,23 @@ static bool ConfigureStencilAttachment(
127127 if (!IsValid ()) {
128128 return false ;
129129 }
130- auto pass = [buffer_ renderCommandEncoderWithDescriptor: desc_];
130+ auto render_command_encoder =
131+ [buffer_ renderCommandEncoderWithDescriptor: desc_];
131132
132- if (!pass ) {
133+ if (!render_command_encoder ) {
133134 return false ;
134135 }
135136
136137 if (!label_.empty ()) {
137- [pass setLabel: @(label_.c_str ())];
138+ [render_command_encoder setLabel: @(label_.c_str ())];
138139 }
139140
140141 // Success or failure, the pass must end. The buffer can only process one pass
141142 // at a time.
142- fml::ScopedCleanupClosure auto_end ([pass]() { [pass endEncoding ]; });
143+ fml::ScopedCleanupClosure auto_end (
144+ [render_command_encoder]() { [render_command_encoder endEncoding ]; });
143145
144- return EncodeCommands (transients_allocator, pass );
146+ return EncodeCommands (transients_allocator, render_command_encoder );
145147}
146148
147149// -----------------------------------------------------------------------------
@@ -154,7 +156,7 @@ static bool ConfigureStencilAttachment(
154156// / absent.
155157// /
156158struct PassBindingsCache {
157- PassBindingsCache (id <MTLRenderCommandEncoder > pass ) : pass_(pass ) {}
159+ PassBindingsCache (id <MTLRenderCommandEncoder > encoder ) : encoder_(encoder ) {}
158160
159161 PassBindingsCache (const PassBindingsCache&) = delete ;
160162
@@ -165,15 +167,15 @@ void SetRenderPipelineState(id<MTLRenderPipelineState> pipeline) {
165167 return ;
166168 }
167169 pipeline_ = pipeline;
168- [pass_ setRenderPipelineState: pipeline_];
170+ [encoder_ setRenderPipelineState: pipeline_];
169171 }
170172
171173 void SetDepthStencilState (id <MTLDepthStencilState > depth_stencil) {
172174 if (depth_stencil_ == depth_stencil) {
173175 return ;
174176 }
175177 depth_stencil_ = depth_stencil;
176- [pass_ setDepthStencilState: depth_stencil_];
178+ [encoder_ setDepthStencilState: depth_stencil_];
177179 }
178180
179181 bool SetBuffer (ShaderStage stage,
@@ -194,10 +196,10 @@ bool SetBuffer(ShaderStage stage,
194196
195197 switch (stage) {
196198 case ShaderStage::kVertex :
197- [pass_ setVertexBufferOffset: offset atIndex: index];
199+ [encoder_ setVertexBufferOffset: offset atIndex: index];
198200 return true ;
199201 case ShaderStage::kFragment :
200- [pass_ setFragmentBufferOffset: offset atIndex: index];
202+ [encoder_ setFragmentBufferOffset: offset atIndex: index];
201203 return true ;
202204 default :
203205 FML_DCHECK (false )
@@ -209,10 +211,10 @@ bool SetBuffer(ShaderStage stage,
209211 buffers_map[index] = {buffer, offset};
210212 switch (stage) {
211213 case ShaderStage::kVertex :
212- [pass_ setVertexBuffer: buffer offset: offset atIndex: index];
214+ [encoder_ setVertexBuffer: buffer offset: offset atIndex: index];
213215 return true ;
214216 case ShaderStage::kFragment :
215- [pass_ setFragmentBuffer: buffer offset: offset atIndex: index];
217+ [encoder_ setFragmentBuffer: buffer offset: offset atIndex: index];
216218 return true ;
217219 default :
218220 FML_DCHECK (false ) << " Cannot bind buffer to unknown shader stage." ;
@@ -231,10 +233,10 @@ bool SetTexture(ShaderStage stage, uint64_t index, id<MTLTexture> texture) {
231233 texture_map[index] = texture;
232234 switch (stage) {
233235 case ShaderStage::kVertex :
234- [pass_ setVertexTexture: texture atIndex: index];
236+ [encoder_ setVertexTexture: texture atIndex: index];
235237 return true ;
236238 case ShaderStage::kFragment :
237- [pass_ setFragmentTexture: texture atIndex: index];
239+ [encoder_ setFragmentTexture: texture atIndex: index];
238240 return true ;
239241 default :
240242 FML_DCHECK (false ) << " Cannot bind buffer to unknown shader stage." ;
@@ -255,10 +257,10 @@ bool SetSampler(ShaderStage stage,
255257 sampler_map[index] = sampler;
256258 switch (stage) {
257259 case ShaderStage::kVertex :
258- [pass_ setVertexSamplerState: sampler atIndex: index];
260+ [encoder_ setVertexSamplerState: sampler atIndex: index];
259261 return true ;
260262 case ShaderStage::kFragment :
261- [pass_ setFragmentSamplerState: sampler atIndex: index];
263+ [encoder_ setFragmentSamplerState: sampler atIndex: index];
262264 return true ;
263265 default :
264266 FML_DCHECK (false ) << " Cannot bind buffer to unknown shader stage." ;
@@ -276,7 +278,7 @@ bool SetSampler(ShaderStage stage,
276278 using TextureMap = std::map<uint64_t , id <MTLTexture >>;
277279 using SamplerMap = std::map<uint64_t , id <MTLSamplerState >>;
278280
279- const id <MTLRenderCommandEncoder > pass_ ;
281+ const id <MTLRenderCommandEncoder > encoder_ ;
280282 id <MTLRenderPipelineState > pipeline_ = nullptr ;
281283 id <MTLDepthStencilState > depth_stencil_ = nullptr ;
282284 std::map<ShaderStage, BufferMap> buffers_;
@@ -332,8 +334,8 @@ static bool Bind(PassBindingsCache& pass,
332334}
333335
334336bool RenderPassMTL::EncodeCommands (Allocator& allocator,
335- id <MTLRenderCommandEncoder > pass ) const {
336- PassBindingsCache pass_bindings (pass );
337+ id <MTLRenderCommandEncoder > encoder ) const {
338+ PassBindingsCache pass_bindings (encoder );
337339 auto bind_stage_resources = [&allocator, &pass_bindings](
338340 const Bindings& bindings,
339341 ShaderStage stage) -> bool {
@@ -355,7 +357,7 @@ static bool Bind(PassBindingsCache& pass,
355357 return true ;
356358 };
357359
358- fml::closure pop_debug_marker = [pass ]() { [pass popDebugGroup ]; };
360+ fml::closure pop_debug_marker = [encoder ]() { [encoder popDebugGroup ]; };
359361 for (const auto & command : commands_) {
360362 if (command.index_count == 0u ) {
361363 FML_DLOG (ERROR) << " Zero index count in render pass command." ;
@@ -364,19 +366,19 @@ static bool Bind(PassBindingsCache& pass,
364366
365367 fml::ScopedCleanupClosure auto_pop_debug_marker (pop_debug_marker);
366368 if (!command.label .empty ()) {
367- [pass pushDebugGroup: @(command.label.c_str ())];
369+ [encoder pushDebugGroup: @(command.label.c_str ())];
368370 } else {
369371 auto_pop_debug_marker.Release ();
370372 }
371373 pass_bindings.SetRenderPipelineState (
372374 PipelineMTL::Cast (*command.pipeline ).GetMTLRenderPipelineState ());
373375 pass_bindings.SetDepthStencilState (
374376 PipelineMTL::Cast (*command.pipeline ).GetMTLDepthStencilState ());
375- [pass setFrontFacingWinding: command.winding == WindingOrder: :kClockwise
376- ? MTLWindingClockwise
377- : MTLWindingCounterClockwise ];
378- [pass setCullMode: MTLCullModeNone ];
379- [pass setStencilReferenceValue: command.stencil_reference];
377+ [encoder setFrontFacingWinding: command.winding == WindingOrder: :kClockwise
378+ ? MTLWindingClockwise
379+ : MTLWindingCounterClockwise ];
380+ [encoder setCullMode: MTLCullModeNone ];
381+ [encoder setStencilReferenceValue: command.stencil_reference];
380382 if (!bind_stage_resources (command.vertex_bindings , ShaderStage::kVertex )) {
381383 return false ;
382384 }
@@ -400,14 +402,14 @@ static bool Bind(PassBindingsCache& pass,
400402 FML_DCHECK (command.index_count * sizeof (uint32_t ) ==
401403 command.index_buffer .range .length );
402404 // Returns void. All error checking must be done by this point.
403- [pass drawIndexedPrimitives: ToMTLPrimitiveType (command.primitive_type)
404- indexCount: command.index_count
405- indexType: MTLIndexTypeUInt32
406- indexBuffer: mtl_index_buffer
407- indexBufferOffset: command.index_buffer.range.offset
408- instanceCount: 1u
409- baseVertex: 0u
410- baseInstance: 0u ];
405+ [encoder drawIndexedPrimitives: ToMTLPrimitiveType (command.primitive_type)
406+ indexCount: command.index_count
407+ indexType: MTLIndexTypeUInt32
408+ indexBuffer: mtl_index_buffer
409+ indexBufferOffset: command.index_buffer.range.offset
410+ instanceCount: 1u
411+ baseVertex: 0u
412+ baseInstance: 0u ];
411413 }
412414 return true ;
413415}
0 commit comments