PR #23811 opened by Timo Rothenpieler (BtbN) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23811 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23811.patch
The CUDA_ARRAY3D_VIDEO_ENCODE_DECODE define was added in the same commit that added the needed Array functions and enums, so it's used as a check. >From e94a006c0bd0744e34da39b9d868badacb768626 Mon Sep 17 00:00:00 2001 From: Timo Rothenpieler <[email protected]> Date: Wed, 15 Jul 2026 00:52:50 +0200 Subject: [PATCH] avutil/hwcontext_cuda: fix build with old cuda headers --- libavutil/hwcontext_cuda.c | 49 +++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c index 61fbf52885..68abcb81ca 100644 --- a/libavutil/hwcontext_cuda.c +++ b/libavutil/hwcontext_cuda.c @@ -30,6 +30,10 @@ #include "pixfmt.h" #include "imgutils.h" +#ifdef CUDA_ARRAY3D_VIDEO_ENCODE_DECODE +#define HAVE_NEW_CUARRAY_FORMATS +#endif + typedef struct CUDAFramesContext { AVCUDAFramesContext p; @@ -79,7 +83,6 @@ static const enum AVPixelFormat supported_formats[] = { #define CHECK_CU(x) FF_CUDA_CHECK_DL(device_ctx, cu, x) static CUarray_format cuda_array_format_for_pix_fmt(enum AVPixelFormat fmt); -static unsigned int cuda_array_numchannels_for_pix_fmt(enum AVPixelFormat fmt); static int cuda_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, @@ -237,6 +240,7 @@ static void cuda_frames_uninit(AVHWFramesContext *ctx) static CUarray_format cuda_array_format_for_pix_fmt(enum AVPixelFormat fmt) { switch (fmt) { +#ifdef HAVE_NEW_CUARRAY_FORMATS case AV_PIX_FMT_NV12: return CU_AD_FORMAT_NV12; case AV_PIX_FMT_P010: case AV_PIX_FMT_P012: @@ -262,10 +266,12 @@ static CUarray_format cuda_array_format_for_pix_fmt(enum AVPixelFormat fmt) case AV_PIX_FMT_0BGR32: case AV_PIX_FMT_RGB32: case AV_PIX_FMT_BGR32: return CU_AD_FORMAT_UNSIGNED_INT8; +#endif default: return 0; } } +#ifdef HAVE_NEW_CUARRAY_FORMATS static unsigned int cuda_array_numchannels_for_pix_fmt(enum AVPixelFormat fmt) { switch (fmt) { @@ -276,6 +282,7 @@ static unsigned int cuda_array_numchannels_for_pix_fmt(enum AVPixelFormat fmt) default: return 3; } } +#endif static int cuda_frames_init(AVHWFramesContext *ctx) { @@ -285,8 +292,6 @@ static int cuda_frames_init(AVHWFramesContext *ctx) CudaFunctions *cu = hwctx->internal->cuda_dl; int err, i; - CUcontext dummy; - for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) { if (ctx->sw_format == supported_formats[i]) break; @@ -297,10 +302,17 @@ static int cuda_frames_init(AVHWFramesContext *ctx) return AVERROR(ENOSYS); } +#ifdef HAVE_NEW_CUARRAY_FORMATS if (ctx->format == AV_PIX_FMT_CUARRAY && !cu->cuArrayGetPlane) { av_log(ctx, AV_LOG_ERROR, "cuArrayGetPlane not available, update your driver\n"); return AVERROR(ENOSYS); } +#else + if (ctx->format == AV_PIX_FMT_CUARRAY) { + av_log(ctx, AV_LOG_ERROR, "Missing support for cuarray frames. Rebuild with newer ffnvcodec headers.\n"); + return AVERROR(ENOSYS); + } +#endif err = CHECK_CU(cu->cuDeviceGetAttribute(&priv->tex_alignment, 14 /* CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT */, @@ -318,6 +330,7 @@ static int cuda_frames_init(AVHWFramesContext *ctx) av_pix_fmt_get_chroma_sub_sample(ctx->sw_format, &priv->shift_width, &priv->shift_height); +#ifdef HAVE_NEW_CUARRAY_FORMATS if (ctx->format == AV_PIX_FMT_CUARRAY) { if (!priv->p.cuarray_desc.Width) priv->p.cuarray_desc.Width = ctx->width; @@ -342,6 +355,8 @@ static int cuda_frames_init(AVHWFramesContext *ctx) } if (ctx->format == AV_PIX_FMT_CUARRAY && priv->p.cuarray_num_surfaces > 0) { + CUcontext dummy; + priv->p.cuarray_surfaces = av_calloc(priv->p.cuarray_num_surfaces, sizeof(*priv->p.cuarray_surfaces)); if (!priv->p.cuarray_surfaces) return AVERROR(ENOMEM); @@ -371,6 +386,7 @@ static int cuda_frames_init(AVHWFramesContext *ctx) av_log(ctx, AV_LOG_DEBUG, "allocated %d CUarray surfaces (%zux%zu)\n", priv->p.cuarray_num_surfaces, priv->p.cuarray_desc.Width, priv->p.cuarray_desc.Height); } +#endif if (!ctx->pool) { int size = av_image_get_buffer_size(ctx->sw_format, ctx->width, ctx->height, priv->tex_alignment); @@ -396,12 +412,7 @@ fail: static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame) { - AVHWDeviceContext *device_ctx = ctx->device_ctx; - AVCUDADeviceContext *hwctx = device_ctx->hwctx; - CUDAFramesContext *priv = ctx->hwctx; - CudaFunctions *cu = hwctx->internal->cuda_dl; - - CUcontext dummy; + CUDAFramesContext *priv = ctx->hwctx; int res; frame->buf[0] = av_buffer_pool_get(ctx->pool); @@ -409,6 +420,11 @@ static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame) return AVERROR(ENOMEM); if (ctx->format == AV_PIX_FMT_CUARRAY) { +#ifdef HAVE_NEW_CUARRAY_FORMATS + AVHWDeviceContext *device_ctx = ctx->device_ctx; + AVCUDADeviceContext *hwctx = device_ctx->hwctx; + CudaFunctions *cu = hwctx->internal->cuda_dl; + CUcontext dummy; AVCUDAArrayFrameDescriptor *desc = (AVCUDAArrayFrameDescriptor*)frame->buf[0]->data; if (!desc) { frame->format = ctx->format; @@ -460,6 +476,9 @@ static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame) res = CHECK_CU(cu->cuCtxPopCurrent(&dummy)); if (res < 0) return res; +#else + return AVERROR(ENOSYS); +#endif } else { res = av_image_fill_arrays(frame->data, frame->linesize, frame->buf[0]->data, ctx->sw_format, ctx->width, ctx->height, priv->tex_alignment); @@ -481,9 +500,11 @@ static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame) return 0; +#ifdef HAVE_NEW_CUARRAY_FORMATS fail: CHECK_CU(cu->cuCtxPopCurrent(&dummy)); return res; +#endif } static enum AVPixelFormat cuda_frame_hw_format(const AVFrame *frame) @@ -569,6 +590,7 @@ static int cuda_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, cpy.srcMemoryType = CU_MEMORYTYPE_DEVICE; cpy.srcDevice = (CUdeviceptr)src->data[i]; } else if (src->format == AV_PIX_FMT_CUARRAY) { +#ifdef HAVE_NEW_CUARRAY_FORMATS CUarray array; CUresult cures = cu->cuArrayGetPlane(&array, (CUarray)src->data[0], i); if (cures == CUDA_ERROR_INVALID_VALUE && i == 0) { @@ -583,6 +605,10 @@ static int cuda_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, cpy.srcMemoryType = CU_MEMORYTYPE_ARRAY; cpy.srcArray = array; +#else + ret = AVERROR(ENOSYS); + goto exit; +#endif } else { cpy.srcMemoryType = CU_MEMORYTYPE_HOST; cpy.srcHost = src->data[i]; @@ -592,6 +618,7 @@ static int cuda_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, cpy.dstMemoryType = CU_MEMORYTYPE_DEVICE; cpy.dstDevice = (CUdeviceptr)dst->data[i]; } else if (dst->format == AV_PIX_FMT_CUARRAY) { +#ifdef HAVE_NEW_CUARRAY_FORMATS CUarray array; CUresult cures = cu->cuArrayGetPlane(&array, (CUarray)dst->data[0], i); if (cures == CUDA_ERROR_INVALID_VALUE && i == 0) { @@ -606,6 +633,10 @@ static int cuda_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, cpy.dstMemoryType = CU_MEMORYTYPE_ARRAY; cpy.dstArray = array; +#else + ret = AVERROR(ENOSYS); + goto exit; +#endif } else { cpy.dstMemoryType = CU_MEMORYTYPE_HOST; cpy.dstHost = dst->data[i]; -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
