Skip to content

Commit

Permalink
metalvc don’t lock semaphores on missing texture
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Mattiello <[email protected]>
  • Loading branch information
JoeMatt committed Dec 31, 2024
1 parent 86aab29 commit 5d0aabe
Showing 1 changed file with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1566,15 +1566,20 @@ class PVMetalViewController : PVGPUViewController, PVRenderDelegate, MTKViewDele
}

func didRenderFrameOnAlternateThread() {
guard backingMTLTexture != nil else {
ELOG("backingMTLTexture was nil")
return
}
glFlush()

emulatorCore?.frontBufferLock.lock()

previousCommandBuffer?.waitUntilScheduled()

defer {
emulatorCore?.frontBufferLock.unlock()

emulatorCore?.frontBufferCondition.lock()
emulatorCore?.isFrontBufferReady = true
emulatorCore?.frontBufferCondition.signal()
emulatorCore?.frontBufferCondition.unlock()
}

guard let commandBuffer = commandQueue?.makeCommandBuffer() else {
ELOG("commandBuffer was nil")
Expand All @@ -1586,27 +1591,26 @@ class PVMetalViewController : PVGPUViewController, PVRenderDelegate, MTKViewDele
return
}

let screenRect = emulatorCore?.screenRect ?? .zero

encoder.copy(from: backingMTLTexture!,
sourceSlice: 0, sourceLevel: 0,
sourceOrigin: MTLOrigin(x: Int(screenRect.origin.x),
y: Int(screenRect.origin.y), z: 0),
sourceSize: MTLSize(width: Int(screenRect.width),
height: Int(screenRect.height), depth: 1),
to: inputTexture!,
destinationSlice: 0, destinationLevel: 0,
destinationOrigin: MTLOrigin(x: 0, y: 0, z: 0))
if let backingMTLTexture = backingMTLTexture {
let screenRect = emulatorCore?.screenRect ?? .zero

encoder.endEncoding()
commandBuffer.commit()
encoder.copy(from: backingMTLTexture,
sourceSlice: 0, sourceLevel: 0,
sourceOrigin: MTLOrigin(x: Int(screenRect.origin.x),
y: Int(screenRect.origin.y), z: 0),
sourceSize: MTLSize(width: Int(screenRect.width),
height: Int(screenRect.height), depth: 1),
to: inputTexture!,
destinationSlice: 0, destinationLevel: 0,
destinationOrigin: MTLOrigin(x: 0, y: 0, z: 0))

emulatorCore?.frontBufferLock.unlock()
encoder.endEncoding()
commandBuffer.commit()

emulatorCore?.frontBufferCondition.lock()
emulatorCore?.isFrontBufferReady = true
emulatorCore?.frontBufferCondition.signal()
emulatorCore?.frontBufferCondition.unlock()
} else {
ELOG("backingMTLTexture was nil")
return
}
}

/// Cached viewport values
Expand Down

0 comments on commit 5d0aabe

Please sign in to comment.