PR #23775 opened by KawaiiEngine URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23775 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23775.patch
cuda_device_derive() leaves ret at zero when CUDA initialization and device enumeration succeed but no CUDA UUID matches the source Vulkan device UUID. Its error path then uninitializes the destination and returns success. av_hwdevice_ctx_create_derived() consequently returns a CUDA device reference with no CUDA context. On the reproduced path, frame-context initialization also returned success, and the first frame allocation later failed with ENOMEM after cuCtxPushCurrent(NULL) reported CUDA_ERROR_INVALID_VALUE. Set ret to AVERROR(ENODEV) in the no-match branch. This is consistent with existing Vulkan and OpenCL no-matching-device handling and leaves the existing cleanup and CUDA-call error propagation unchanged. I reproduced the false-success path on Windows with an Intel Arc Vulkan source and one NVIDIA RTX 4060 CUDA device. I also reproduced it deterministically by wrapping the Vulkan vkGetPhysicalDeviceProperties2 lookup and changing one UUID byte, without depending on adapter ordering. A matching NVIDIA Vulkan/CUDA control derived successfully and allocated a CUDA frame. Testing: - CUDA+Vulkan libavutil MSVC build: pass - tools/patcheck: pass (minor-change changelog hint only) - make fate: pass; SAMPLES was not configured, so only the available subset ran - real mismatch: 0/unusable context before; AVERROR(ENODEV)/no ref after - injected mismatch: same - matching-device control: derivation and CUDA frame allocation passed >From b275df403b416aa44e95797869ff91dbc4c75e31 Mon Sep 17 00:00:00 2001 From: "KawaiiEngine (Sashimiso)" <[email protected]> Date: Sat, 11 Jul 2026 22:32:21 +0900 Subject: [PATCH] avutil/hwcontext_cuda: fail derive if no CUDA device matches When CUDA enumeration succeeds but none of the device UUIDs matches the source Vulkan device, ret still holds zero from the last successful CUDA call. The error path therefore uninitializes the destination and returns success. av_hwdevice_ctx_create_derived() then returns a CUDA device context without a CUDA context. Later frame allocation fails with an unrelated error. Set ret to AVERROR(ENODEV) for the no-match case, consistent with equivalent Vulkan and OpenCL device selection failures. Signed-off-by: KawaiiEngine (Sashimiso) <[email protected]> --- libavutil/hwcontext_cuda.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c index f93bdcab9c..a171a9e139 100644 --- a/libavutil/hwcontext_cuda.c +++ b/libavutil/hwcontext_cuda.c @@ -557,6 +557,7 @@ static int cuda_device_derive(AVHWDeviceContext *device_ctx, if (hwctx->internal->cuda_device == -1) { av_log(device_ctx, AV_LOG_ERROR, "Could not derive CUDA device.\n"); + ret = AVERROR(ENODEV); goto error; } -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
