fix: attempt to fix occasional video freeze with metal renderer
This commit is contained in:
1 parent
225b66cb06
commit
bcb4d0a905
1 file changed
+17
-4
@@ -650,9 +650,14 @@ CFStringRef __currentColorSpace;
|
|||||||
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> cb) {
|
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> cb) {
|
||||||
dispatch_semaphore_signal(block_semaphore);
|
dispatch_semaphore_signal(block_semaphore);
|
||||||
|
|
||||||
const CFTimeInterval GPUTime = cb.GPUEndTime - cb.GPUStartTime;
|
if (cb.error) {
|
||||||
const double alpha = 0.25f;
|
// Request IDR frame to recover from rendering error
|
||||||
self->_averageGPUTime = (GPUTime * alpha) + (self->_averageGPUTime * (1.0 - alpha));
|
LiRequestIdrFrame();
|
||||||
|
} else {
|
||||||
|
const CFTimeInterval GPUTime = cb.GPUEndTime - cb.GPUStartTime;
|
||||||
|
const double alpha = 0.25f;
|
||||||
|
self->_averageGPUTime = (GPUTime * alpha) + (self->_averageGPUTime * (1.0 - alpha));
|
||||||
|
}
|
||||||
|
|
||||||
// Free textures after completion of rendering
|
// Free textures after completion of rendering
|
||||||
for (size_t i = 0; i < planes; i++) {
|
for (size_t i = 0; i < planes; i++) {
|
||||||
@@ -677,7 +682,15 @@ CFStringRef __currentColorSpace;
|
|||||||
// by any stage in the Metal pipeline (CPU, GPU, Metal, Drivers, etc.).
|
// by any stage in the Metal pipeline (CPU, GPU, Metal, Drivers, etc.).
|
||||||
if (!self.isStopping) {
|
if (!self.isStopping) {
|
||||||
dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)); // 100ms
|
dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1f * NSEC_PER_SEC)); // 100ms
|
||||||
dispatch_semaphore_wait(_inFlightSemaphore, timeout);
|
long result = dispatch_semaphore_wait(_inFlightSemaphore, timeout);
|
||||||
|
if (result != 0) {
|
||||||
|
// Timeout occurred - this is the main cause of video freezes
|
||||||
|
// Signal the semaphore to unblock potentially stuck frames
|
||||||
|
for (NSUInteger i = 0; i < MaxFramesInFlight; i++) {
|
||||||
|
dispatch_semaphore_signal(_inFlightSemaphore);
|
||||||
|
}
|
||||||
|
LiRequestIdrFrame(); // Request recovery
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user