Unity-Technologies / com.unity.webrtc

WebRTC package for Unity
Other
739 stars 185 forks source link

performance: Use semaphore to wait command buffer completion on macos/ios #935

Closed karasusan closed 11 months ago

karasusan commented 1 year ago

This is a performance optimization fix for Metal.

Previously, when copying textures for video transmission, MTLCommandBuffer::waitUntilCompleted was used to detect when the texture copy command was finished. Since this method is called on the rendering thread, it could cause subsequent graphics-related operations to block.

This fix uses MTLCommandBuffer::addCompletedHandler and semaphores to implement the wait process. It waits for the semaphore's signal on the worker thread, the load on the rendering thread is reduced.

Refer to this sample provided by Apple.