我们正在使用交错的高清视频。我用于渲染的金属颜色附件具有一个字段的尺寸(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,就像您在上面的代码中看到的那样(从缓冲区中的第二行开始),则得到如下断言:
validateCopyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:options::677:失败断言“-MTLDebugBlitCommandEncoder be (8302080)必须是<= destinationBuffer must”。
totalBytesUsed正好是目标缓冲区长度(以字节为单位)加上偏移量。因此,我在这个函数中使用的每一个偏移量都会导致断言错误。
有人能解释一下如何正确地使用这个函数吗?因为相反的方式,比如为传入的视频帧创建两个MTLTexture对象(奇数和偶数字段),可以很好地处理类似的参数。
发布于 2017-03-28 13:08:15
我最近也碰到了这样的事。
将destinationBuffer.length
传递给destinationBytesPerImage:
参数。正如您注意到的,Metal正在将偏移量和每个图像的字节值相加,并将其与to:
目标缓冲区(destinationBuffer
)的长度进行比较。它注意到偏移加上每个图像的字节不适合缓冲区,并拒绝接受这一点。
您可以简单地为destinationBytesPerImage:
传递0,因为您没有使用3D或2D数组纹理。如果这不起作用,请通过destinationBuffer.length - 1920*4
。
https://stackoverflow.com/questions/43069257
复制相似问题