【发布时间】:2017-03-28 12:12:51
【问题描述】:
我们正在处理隔行扫描高清视频。我用于渲染的金属色附件具有一个字段的尺寸(1920*540 RGBA)。 当我尝试将两个渲染字段复制到大小为 1920*1080*4 = 8294400 字节的同一 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()
对于目标偏移量为零的第一个字段,该函数运行良好。每隔一行填充一次目标缓冲区。
但是,当我想将具有相同代码的第二个字段写入相同的 MTLBuffer 对象时,仅将destinationOffset 设置为 1920*4,就像您在上面的代码中看到的那样(从缓冲区中的第二行开始),然后我得到这样的断言:
-[MTLDebugBlitCommandEncoder validateCopyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:options:]:677: 断言失败`totalBytesUsed(8302080) 必须是
totalBytesUsed 正好是目标缓冲区长度(以字节为单位)加上偏移量。所以我在这个函数中使用的每一个偏移量都会导致这个断言错误。
谁能解释我如何正确使用这个函数,因为反过来,比如为传入的视频帧创建两个 MTLTexture 对象(奇数和偶数场)在类似的参数下效果很好。
【问题讨论】: