| 3974 | } |
| 3975 | |
| 3976 | static int vulkan_transfer_data_from_cuda(AVHWFramesContext *hwfc, |
| 3977 | AVFrame *dst, const AVFrame *src) |
| 3978 | { |
| 3979 | int err; |
| 3980 | CUcontext dummy; |
| 3981 | AVVkFrame *dst_f; |
| 3982 | AVVkFrameInternal *dst_int; |
| 3983 | VulkanFramesPriv *fp = hwfc->hwctx; |
| 3984 | const int planes = av_pix_fmt_count_planes(hwfc->sw_format); |
| 3985 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hwfc->sw_format); |
| 3986 | |
| 3987 | AVHWFramesContext *cuda_fc = (AVHWFramesContext*)src->hw_frames_ctx->data; |
| 3988 | AVHWDeviceContext *cuda_cu = cuda_fc->device_ctx; |
| 3989 | AVCUDADeviceContext *cuda_dev = cuda_cu->hwctx; |
| 3990 | AVCUDADeviceContextInternal *cu_internal = cuda_dev->internal; |
| 3991 | CudaFunctions *cu = cu_internal->cuda_dl; |
| 3992 | CUDA_EXTERNAL_SEMAPHORE_WAIT_PARAMS s_w_par[AV_NUM_DATA_POINTERS] = { 0 }; |
| 3993 | CUDA_EXTERNAL_SEMAPHORE_SIGNAL_PARAMS s_s_par[AV_NUM_DATA_POINTERS] = { 0 }; |
| 3994 | |
| 3995 | dst_f = (AVVkFrame *)dst->data[0]; |
| 3996 | |
| 3997 | err = prepare_frame(hwfc, &fp->upload_exec, dst_f, PREP_MODE_EXTERNAL_EXPORT); |
| 3998 | if (err < 0) |
| 3999 | return err; |
| 4000 | |
| 4001 | err = CHECK_CU(cu->cuCtxPushCurrent(cuda_dev->cuda_ctx)); |
| 4002 | if (err < 0) |
| 4003 | return err; |
| 4004 | |
| 4005 | err = vulkan_export_to_cuda(hwfc, src->hw_frames_ctx, dst); |
| 4006 | if (err < 0) { |
| 4007 | CHECK_CU(cu->cuCtxPopCurrent(&dummy)); |
| 4008 | return err; |
| 4009 | } |
| 4010 | |
| 4011 | dst_int = dst_f->internal; |
| 4012 | |
| 4013 | for (int i = 0; i < planes; i++) { |
| 4014 | s_w_par[i].params.fence.value = dst_f->sem_value[i] + 0; |
| 4015 | s_s_par[i].params.fence.value = dst_f->sem_value[i] + 1; |
| 4016 | } |
| 4017 | |
| 4018 | err = CHECK_CU(cu->cuWaitExternalSemaphoresAsync(dst_int->cu_sem, s_w_par, |
| 4019 | planes, cuda_dev->stream)); |
| 4020 | if (err < 0) |
| 4021 | goto fail; |
| 4022 | |
| 4023 | for (int i = 0; i < planes; i++) { |
| 4024 | CUDA_MEMCPY2D cpy = { |
| 4025 | .srcMemoryType = CU_MEMORYTYPE_DEVICE, |
| 4026 | .srcDevice = (CUdeviceptr)src->data[i], |
| 4027 | .srcPitch = src->linesize[i], |
| 4028 | .srcY = 0, |
| 4029 | |
| 4030 | .dstMemoryType = CU_MEMORYTYPE_ARRAY, |
| 4031 | .dstArray = dst_int->cu_array[i], |
| 4032 | }; |
| 4033 |
no test coverage detected