Asking it here and not on SO as it seems to be appropriate question for CG. I am learning NVIDIA NVENC API.The SDK supplies a sampled called "NvEncoderCudaInterop" .There is a chunk of code which copies YUV plane arrays from CPU to GPU buffers. This is the code:
// copy luma CUDA_MEMCPY2D copyParam; memset(©Param, 0, sizeof(copyParam)); copyParam.dstMemoryType = CU_MEMORYTYPE_DEVICE; copyParam.dstDevice = pEncodeBuffer->stInputBfr.pNV12devPtr; copyParam.dstPitch = pEncodeBuffer->stInputBfr.uNV12Stride; copyParam.srcMemoryType = CU_MEMORYTYPE_HOST; copyParam.srcHost = yuv; copyParam.srcPitch = width; copyParam.WidthInBytes = width; copyParam.Height = height; __cu(cuMemcpy2D(©Param)); // copy chroma __cu(cuMemcpyHtoD(m_ChromaDevPtr, yuv, width*height / 4)); __cu(cuMemcpyHtoD(m_ChromaDevPtr, yuv, width*height / 4));
I do understand the rationale behind the procedure.The memory is copied to GPU for the kernel to process it.What I don't understand is why,in order to copy Y plane, cuMemcpy2D is used and for UV cuMemcpyHtoD?Why Y can't be copied using cuMemcpyHtoD as well?As far as I understand,YUV planes have the same linear memory layout.The only difference is their size.