From patchwork Tue Feb 13 12:23:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 46235 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9002:b0:19e:cdac:8cce with SMTP id d2csp1256124pzc; Tue, 13 Feb 2024 04:21:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjZHsDj01tS7fqj5uzEy6VWPNQRZLwoq2KYdAWboF7oGVZjLLNRT1/4ukPcKi16ERvfUzk X-Received: by 2002:aa7:d8ce:0:b0:560:e6b1:f73 with SMTP id k14-20020aa7d8ce000000b00560e6b10f73mr7503878eds.16.1707826884105; Tue, 13 Feb 2024 04:21:24 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXb/e+JlcprwmlY40t6GpDmIpt233T5tBRRfaC7qWESNCt796Ez1pUUpSp1lMbkuaR760RVE6ToRfL413FAv5ojjRvLSVIlbigLdk3ppfMcOcV2PTmWxXQMAeE91A7ooRe6993B1E055niVyWSAMfB3CJKYgAWnwoZhsSRMR1oK0TMhZyyMDyoA4hXE8Fz+FytVEH0JHMDMmJ0UhVa1rZr+LCR0t9doJCjF2qY3WU54eYa/1b3fvfHqL5adr173KvuoHtV+hudc/VrAWlmDWfpNNKN69USvHz1X2pYTpOiFChHewC2gM0CGaFuk4bvbxYXEfBuQHfjMNz67qU44wEkIZeGdbrZUfpVzrLuVcjhE1/BpBo5bqOs+NjyjkLEujxl3AopsPprJMSt0B7pesRkDmspZYPnoMsvnI5Io99XJ/u0zagdgaceT+PTQLYbaUQMrwZx+OzeC9zZIL5HXsBzq9rv4ZI8wWhve92vR9EVcRJgytWq+2W7UgGuk28YEsDPmbCngcS6Mylw76m6z9ytyqp8/zo9YtNF0jt2hq9caZaior0D4Dkr9is55QxL5/yL9WD4JFx8NVs+Yz9HOelA1VvizOOQldD6a+/aRA+HE3X5jQfRTsoh9uxoe86keX8r5KjcjSwrDxrZPKtzjgRmDqZKD7Dh1roRvSs6Jft2zVViu2+MkSpqgvdLLT4wfKhlnZ5ofFt1UftvrELt8nD20rd6Bp4Yr7HGUPW0y88betIST40tGuu4N+WYA6INnrxZv5rL/UhaNWTxWT1yLZz9dcKvqWcc/dkQDGHXv6/0a0xBsFLQt0IjoJnYWsyK1Ga6H3kZ0c3xPnJBEqZDRCb1ca3T7BtJcSxZkgogl6odpmP4Rq41eJHTTWXew4jALTRQY11MVCUvhA7gjYmo2tu0AD63z9wUA5quDe/5pLM250EOCpQsr2Jp336QMRHO7fAk1u2 nsXidRXbVNBL8kydPT1J4srAr8vU3Sr/d7endOmEm2y9gjlOs2O785p2VIpNfbU1Az5DNejTO8OgiClPQ803IGQw+M8IJA+2sxU8Rng7heLcYDjLFGLUy+3haGSYVCeLRfaT6uYLEtnl11V9SmK/QcSljPcpgUgjkviYU2uR/09kUAnZejeZk2H27a5YaMswpUETrD1sMPl3uyOHR9YmAmTnn3JKfXu/RgnIH1K//iqKLSy8LnZIiP0Q+byjedJiPefHYuBelY65ZrOTnOg1VCqeSgWsAu/W22NANFmM9dhTsN1o5IWsRFwxzr3Um3xnJiMDBNC8pf8haloa+yhumTIHbRxXW/ZQdx/sd/VvyoXeKCw8zL8JuGpjLNDZAdBQrtolIPQnHNE7H6QeKkLYaQYkVHhkFTeGqyHA7AZOyd62U0YhlcyKxZ/CoV+Y66pgpPtdPCMxUAUxfkGLiVw/+f0gmIPuWvIx9c7SaqAMFe2wzqCsdo5OZjLEd2pebaYp9bjDlTwUYcnnAnetejjcusFt5WdL3W4LMJ7AmIDDnKreYkljtvI9m1OC8NpNzkaDi5YurWWwLYCxU4xNEv0pz5vmWPuqi9fWVcRdVGAaPF0oJ0oC1hOl6qQ9iOrNg= Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id en20-20020a056402529400b0055cf49783e6si3783938edb.520.2024.02.13.04.21.23; Tue, 13 Feb 2024 04:21:24 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=E2JRwnYz; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DC4F668CA86; Tue, 13 Feb 2024 14:21:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01olkn2049.outbound.protection.outlook.com [40.92.66.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 12FCD68CA86 for ; Tue, 13 Feb 2024 14:21:14 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ivPXFCt+oTIz8KMEm+Zw3V4PNn5CGpXIVKU7PiL3fpxVjs/es17U4ZMgmK6lZt5fM3G0hYg5OUNxvhj/Vh8CsdgCCKQGT1NoMKyqyY/enwyn+6kFnzOX/r+FFexozC+Pqo+LRN37td5274sQachFqky6XblQyL5hACrYR4fbAYUOYA+fOZqZLhiwweSOILWsgG6mZGgIkSn4+ADFy0ONNpdDzEdI+rpS+eT8mX9pc7msG0ZWGAiXPgobokkba5RD5AhaN5cWX6WFpPIJ5F3ddgYrnlMIvruWDe86Rz2KaAFgezNlfj/0UcVhan7A2UzRh+dpTKs5cy+g/5G35fSUug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xtLPXL/FNCeAOfxZoNtm8WhBB5ODFbDUowA01GeAmeU=; b=YMzUkm7RyxljYTLu+O3Ssuwb7vQ6VjFdI9ri2BdJecjWmsIQYoak3QkrOvk6kaw5V1mshD1we2GNP4pfuRmsTdotDzRBnhXMjMratMm302H3DkLXf3C+dinauXLkM/G/Ccj57JMXQjV8/huJm82+pFNct+AhIKOhECk5R0DgwZnjIqJModbqq282KbsXBycA44y2lfHXix0UEY/dL7y0D3M5/Lj+iJuPQ98XDB8LEjVOIUBNTZGBYcHhW0qAg0aVm8msmc7xxTjKm9udRkgvt/5zF/l6z3Vn80DvEuVxXIvVdV+FuFrDez4+mlCJjmb6S9ecN/HidgYx45T7cFPGvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xtLPXL/FNCeAOfxZoNtm8WhBB5ODFbDUowA01GeAmeU=; b=E2JRwnYz8XPQsoCG/+xbzE/5yi2CpaA8qbQA5NuyjsI1fKPhS6iLyKaRcyYAMU27k+DpSv7mFEq18zQkAZcmUQ+dq+f2uLL3ocCRDOjHRuHQDoRupoOY+kIDSyvlqsuGxO/YktdxgyB/URTDWo4XI5t4PebNr2GVQnASrJpXcBUmkZIXnl+p8xyjshYBRbDVMMo6zwP5hF6FfuDDtZMEeLis05DBM4hXyKpgBJ1L/ia4uILU/ZXWcb0tB8NEBBcXvEpPMmRYm6GiyRIfGMYD+uIlG1OB8sKgbACgB22rsGClOlIbQxSuI60jV18M5nyzbLO6Nu6kA4SvaJLDCgeVog== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0266.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:37d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.35; Tue, 13 Feb 2024 12:21:11 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d%5]) with mapi id 15.20.7270.036; Tue, 13 Feb 2024 12:21:11 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 13 Feb 2024 13:23:01 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [7V2bgBZjn47gVwNoGkbl3fE7K7WyfePSxXfVS2uFjWo=] X-ClientProxiedBy: FR0P281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:15::15) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240213122301.247941-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0266:EE_ X-MS-Office365-Filtering-Correlation-Id: 69612481-94cb-4887-d3b3-08dc2c8e4388 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ltbqGwoL+8Khluzak0VM+fAZ3hMBJNMO+3nBhSgKtGSwLC0m8pVaQm/89CQnAuXG9n6MDUnW/VI+lbmVgcXai+s4SaUd4fpCVofOeNHSlCOawytX9NtfO4cYWIWEhZISyJEKAvxE/qi4S5Ihq5M9ikNiW2cDsTAEpb6RiLGqmC6KOjTCBXAQ+dPg6hL5DQcINZAn/lmG74cw89Jmkv82yofHEDnOprXFPGXktBxqWXVGHA2MMh7wo3f7CQmIUa5df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2p1x0llkIuwRyXgoD9z4isT1y+JwNXWZdjQMjUj1c6N1NZyU98D1YxI0YzknlXMpsqUXVB8gFd/eSLtJiQmDkijAPSCAzDAxLOMrc3YzJ070nE7LrzF0F7bpOSrRrOYL/C2qEOj8dI2tW1hKVTJ7zByulhkaO+LV8dBzfvByZvKAWyoCmEUoUOd70iEGluWbV8U3B7D+RMsel8BFttmoTOTn4Czny7rrWs1GQUfUnpdztoUzY3mDsCm53XGXyvBSoYzrUPs+vnVjZV3eCVDhzETjhXnGiqGb1s9uT4XiUHh9P9S++XGxpxD/6PXU2GJyd5DKJXFSKtkTWlBeY5i2myAykt7HNiviMiB1naiSdCJXq2d4MtFIPqIFlez04eucoKkEkNCAcLZ6IKBkZgqu+pirF9aniA6Lf9+Myf8axp+qqa77k4u4StCWyvib/fCcChvoDVmTc9wpn1URCPECMg/xlEYRZxQFcSlGS8J6OQq5hsQPWE38DuAQ2WsOEiDMzyoLygMupaqUK5Hrh/jxNf4OZ81CWcFac+WJ32kTO2fIxxmm2t4ME5K68rrv6byAnR6s55WHfNdQXE5BbzVjmONElpRUei3AwrBTWkCrz4CQYSd8kBbzsguKnbyUETw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69612481-94cb-4887-d3b3-08dc2c8e4388 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2024 12:21:11.1573 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8P250MB0266 Subject: [FFmpeg-devel] [PATCH 24/24] avutil/hwcontext_cuda: Allocate public and internal device ctx jointly X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AEHPbhd/O8f8 Signed-off-by: Andreas Rheinhardt --- libavutil/hwcontext_cuda.c | 43 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c index b430b42f62..3de3847399 100644 --- a/libavutil/hwcontext_cuda.c +++ b/libavutil/hwcontext_cuda.c @@ -35,6 +35,11 @@ typedef struct CUDAFramesContext { int tex_alignment; } CUDAFramesContext; +typedef struct CUDADeviceContext { + AVCUDADeviceContext p; + AVCUDADeviceContextInternal internal; +} CUDADeviceContext; + static const enum AVPixelFormat supported_formats[] = { AV_PIX_FMT_NV12, AV_PIX_FMT_YUV420P, @@ -283,39 +288,35 @@ exit: static void cuda_device_uninit(AVHWDeviceContext *device_ctx) { - AVCUDADeviceContext *hwctx = device_ctx->hwctx; + CUDADeviceContext *hwctx = device_ctx->hwctx; - if (hwctx->internal) { - CudaFunctions *cu = hwctx->internal->cuda_dl; + if (hwctx->p.internal) { + CudaFunctions *cu = hwctx->internal.cuda_dl; - if (hwctx->internal->is_allocated && hwctx->cuda_ctx) { - if (hwctx->internal->flags & AV_CUDA_USE_PRIMARY_CONTEXT) - CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal->cuda_device)); - else if (!(hwctx->internal->flags & AV_CUDA_USE_CURRENT_CONTEXT)) - CHECK_CU(cu->cuCtxDestroy(hwctx->cuda_ctx)); + if (hwctx->internal.is_allocated && hwctx->p.cuda_ctx) { + if (hwctx->internal.flags & AV_CUDA_USE_PRIMARY_CONTEXT) + CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal.cuda_device)); + else if (!(hwctx->internal.flags & AV_CUDA_USE_CURRENT_CONTEXT)) + CHECK_CU(cu->cuCtxDestroy(hwctx->p.cuda_ctx)); - hwctx->cuda_ctx = NULL; + hwctx->p.cuda_ctx = NULL; } - cuda_free_functions(&hwctx->internal->cuda_dl); + cuda_free_functions(&hwctx->internal.cuda_dl); + memset(&hwctx->internal, 0, sizeof(hwctx->internal)); + hwctx->p.internal = NULL; } - - av_freep(&hwctx->internal); } static int cuda_device_init(AVHWDeviceContext *ctx) { - AVCUDADeviceContext *hwctx = ctx->hwctx; + CUDADeviceContext *hwctx = ctx->hwctx; int ret; - if (!hwctx->internal) { - hwctx->internal = av_mallocz(sizeof(*hwctx->internal)); - if (!hwctx->internal) - return AVERROR(ENOMEM); - } + hwctx->p.internal = &hwctx->internal; - if (!hwctx->internal->cuda_dl) { - ret = cuda_load_functions(&hwctx->internal->cuda_dl, ctx); + if (!hwctx->internal.cuda_dl) { + ret = cuda_load_functions(&hwctx->internal.cuda_dl, ctx); if (ret < 0) { av_log(ctx, AV_LOG_ERROR, "Could not dynamically load CUDA\n"); goto error; @@ -563,7 +564,7 @@ const HWContextType ff_hwcontext_type_cuda = { .type = AV_HWDEVICE_TYPE_CUDA, .name = "CUDA", - .device_hwctx_size = sizeof(AVCUDADeviceContext), + .device_hwctx_size = sizeof(CUDADeviceContext), .frames_hwctx_size = sizeof(CUDAFramesContext), .device_create = cuda_device_create,