2017-03-28 1 views
1

우리는 인터레이스 된 HD 비디오로 작업하고 있습니다. 렌더링에 사용하는 금속 색상 첨부 파일은 한 필드 (1920 * 540 RGBA) 크기입니다. 두 개의 렌더링 된 필드를 1920 * 1080 * 4 = 8294400 바이트 크기의 동일한 MTLBuffer로 복사하려고하면 대상 오프셋이 0 인 경우에만 작동합니다.MTLBlitCommandEncoder를 사용하여 인터레이스 된 비디오 필드를 MTLBuffer로 복사하는 방법

let commandBuffer = commandQueue.makeCommandBuffer() 
let blitEncoder = commandBuffer.makeBlitCommandEncoder() 
blitEncoder.copy(from: attachmentTexture, 
       sourceSlice: 0, 
       sourceLevel: 0, 
       sourceOrigin: MTLOriginMake(0, 0, 0), 
       sourceSize: MTLSizeMake(attachmentTexture.width, attachmentTexture.height, 1), 
       to: destinationBuffer, 
       destinationOffset: 1920*4, 
       destinationBytesPerRow: 1920*4*2, 
       destinationBytesPerImage: destinationBuffer.length) 
blitEncoder.endEncoding() 
commandBuffer.commit() 

대상 오프셋이 0 인 첫 번째 필드의 경우 기능이 잘 작동합니다. 대상 버퍼는 두 번째 행마다 채워집니다.

그러나 동일한 코드가있는 두 번째 필드를 동일한 MTLBuffer 객체에 쓰고 싶을 때 (위의 코드에서 보듯이 (버퍼의 두 번째 행으로 시작) destinationOffset을 1920 * 4로 설정 한 경우) 내가 주장과 같이 얻을 :

가 - [MTLDebugBlitCommandEncoder validateCopyFromTexture : sourceSlice : sourceLevel : sourceOrigin : sourceSize : toBuffer : destinationOffset : destinationBytesPerRow : destinationBytesPerImage : 옵션 :] : 677 : 이 주장`totalBytesUsed (8302080)를 실패해야합니다 < = destinationBuffer 길이 '

totalBytesUsed는 정확하게 대상 버퍼 길이에 바이트와 오프셋을 더한 것입니다. 따라서이 함수에서 사용하는 모든 오프셋은이 어설 션 오류를 발생시킵니다.

들어오는 비디오 프레임에 대해 두 개의 MTLTexture 개체 (홀수 및 짝수 필드)를 만드는 것과 같은 다른 방법으로 비슷한 매개 변수에서 잘 작동하므로이 함수를 올바르게 사용하는 방법을 설명 할 수 있습니까?

답변

1

최근에 이와 비슷한 문제가 발생했습니다.

destinationBytesPerImage: 매개 변수로 전달 중입니다. 메탈은 오프셋과 바이트 당 이미지 값을 더하고이를 to: 대상 버퍼 (destinationBuffer)의 길이와 비교합니다. 오프셋과 이미지 당 바이트가 버퍼에 맞지 않으며 받아들이기를 거부하는 것을 알 수 있습니다.

3D 또는 2D 배열 텍스처로 작업하지 않으므로 destinationBytesPerImage:에 0을 단순히 전달할 수 있습니다. 그래도 문제가 해결되지 않으면 destinationBuffer.length - 1920*4을 전달하세요.

관련 문제