Hi all,
We want to use OpenVX API functions, namely vxCreateImageFromHandle() and vxSwapImageHandle(), to exploit zero-copy mechanism when it comes to updating image buffer in vx_image container. Basically, instead of using vxCopyImagePatch() to copy some input image buffer, we wish just to swap pointers in an existing vx_image. As a proof of concept, I used the simple application running on A72 under Linux.
int main(int argc, char *argv[]) { int status = 0; if (0 == status) { status = appInit(); } if(0 == status) { input_img1 = (uint8_t*)malloc(MAX_WIDTH*MAX_HEIGHT); input_img2 = (uint8_t*)malloc(MAX_WIDTH*MAX_HEIGHT); printf("input_img1=%p\n", input_img1); printf("input_img2=%p\n", input_img2); context = vxCreateContext(); vx_imagepatch_addressing_t image_addr; image_addr.dim_x = MAX_WIDTH; image_addr.dim_y = MAX_HEIGHT; image_addr.stride_x = 1U; image_addr.stride_y = MAX_WIDTH; out_img = vxCreateImageFromHandle(context, VX_DF_IMAGE_U8, &image_addr, (void**)&input_img1, VX_MEMORY_TYPE_HOST); void *old_ptr; printf("old_ptr=%p\n", old_ptr); status = vxSwapImageHandle(out_img, (void**)&input_img2, &old_ptr, 1U); free(input_img1); free(input_img2); vxReleaseImage(&out_img); vxReleaseContext(&context); appDeInit(); } return status; }
In addition, I enabled printing of the host_ptr and shared_ptr in vxCreateImageFromHandle() and vxSwapImageHandle() functions.
The execution log is provided below.
APP: Init ... !!! MEM: Init ... !!! MEM: Initialized DMA HEAP (fd=4) !!! MEM: Init ... Done !!! IPC: Init ... !!! IPC: Init ... Done !!! REMOTE_SERVICE: Init ... !!! REMOTE_SERVICE: Init ... Done !!! 3504.498443 s: GTC Frequency = 200 MHz APP: Init ... Done !!! 3504.504597 s: VX_ZONE_INIT:Enabled 3504.504620 s: VX_ZONE_ERROR:Enabled 3504.504750 s: VX_ZONE_WARNING:Enabled 3504.505294 s: VX_ZONE_INIT:[tivxInit:71] Initialization Done !!! 3504.505509 s: VX_ZONE_INIT:[tivxHostInit:48] Initialization Done for HOST !!! input_img1=0xffffb2d90010 input_img2=0xffffb2b90010 [vxCreateImageFromHandle]host_ptr[0] = 0xffffb2d90010 [vxCreateImageFromHandle]shared_ptr[0] = 0x0, mem_region=0 [vxSwapImageHandle]new_ptrs[0]=0xffffb2b90010 [vxSwapImageHandle]host_ptr[0] = 0xffffb2b90010 [vxSwapImageHandle]shared_ptr[0] = 0x0, mem_region=0 old_ptr=0xffffb2d90010 3504.506443 s: VX_ZONE_INIT:[tivxHostDeInit:56] De-Initialization Done for HOST !!! 3504.510779 s: VX_ZONE_INIT:[tivxDeInit:111] De-Initialization Done !!! APP: Deinit ... !!! REMOTE_SERVICE: Deinit ... !!! REMOTE_SERVICE: Deinit ... Done !!! IPC: Deinit ... !!! IPC: DeInit ... Done !!! MEM: Deinit ... !!! MEM: Alloc's: 0 alloc's of 0 bytes MEM: Free's : 0 free's of 0 bytes MEM: Open's : 0 allocs of 0 bytes MEM: Deinit ... Done !!! APP: Deinit ... Done !!!
As you can see from the log, the host_ptr is updated as expected. However, shared_ptr is always NULL, which makes trouble if the buffer is going to be consumed outside the host. I suspect tivxMemHost2SharedPtr() function does not return correct result, but I am not sure why this is the case. Could someone, please, help me out finding the cause of this issue and provide some pointers to what I am doing wrong?
Used PSDK version: 08.00.00.12
Best regards,
Mladen