swift - How to use MTLBlitCommandEncoder for copying interlaced video fields into a MTLBuffer -


we working interlaced hd video. metal color attachment use rendering has dimensions of 1 field (1920*540 rgba). when try copy 2 rendered fields same mtlbuffer has size of 1920*1080*4 = 8294400 bytes works if destination offset zero.

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() 

for first field destination offset 0 function works well. destination buffer filled every second row.

but when want write second field same code same mtlbuffer object destinationoffset set 1920*4 see in code above (to start second row in buffer) assertion this:

-[mtldebugblitcommandencoder validatecopyfromtexture:sourceslice:sourcelevel:sourceorigin:sourcesize:tobuffer:destinationoffset:destinationbytesperrow:destinationbytesperimage:options:]:677: failed assertion `totalbytesused(8302080) must <= destinationbuffer length.'

the totalbytesused destination buffer length in bytes plus offset. every offset use in function result in assertion error.

can explain me how use function correctly because other way around creating 2 mtltexture objects (odd , fields) incoming video frame works similar parameters.

i ran recently, too.

you're passing destinationbuffer.length destinationbytesperimage: parameter. you've noticed, metal adding offset , bytes-per-image value , comparing against length of to: destination buffer (destinationbuffer). it's noticing offset plus bytes-per-image won't fit buffer , refusing accept that.

you may able pass 0 destinationbytesperimage:, since you're not working 3d or 2d array texture. if doesn't work, pass destinationbuffer.length - 1920*4.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -