I have a decoder which produces NV12 yuv frames. What I would like to do is to copy that frame to ID3D11Texture2D texture with single memcpy. Because D3D11_MAPPED_SUBRESOURCE has a different RowPitch than my NV12 frame has I have to copy whole yuv row by row which is pretty expensive. Is there a better way to do this?
I've tried to find any information on this topic but so far without any luck.
// Copy from CPU access texture to bitmap buffer
D3D11_MAPPED_SUBRESOURCE resource;
UINT subresource = D3D11CalcSubresource(0, 0, 0);
OutMgr.m_DeviceContext->Map(OutMgr.m_texture, subresource, D3D11_MAP_WRITE_DISCARD, 0, &resource);
BYTE* dptr = reinterpret_cast<BYTE*>(resource.pData);
for (int i = 0; i < nv12Frame->height; i++)
{
memcpy(dptr + resource.RowPitch * i, nv12Frame->Y + nv12Frame->pitch * i, nv12Frame->pitch);
}
for (int i = 0; i < nv12Frame->height / 2; i++)
{
memcpy(dptr + resource.RowPitch *(nv12Frame->height + i), nv12Frame->UV + nv12Frame->pitch * i, nv12Frame->pitch);
}
OutMgr.m_DeviceContext->Unmap(OutMgr.m_texture, subresource);