From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 24047421C2 for ; Thu, 16 Dec 2021 20:29:50 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D554D68AF88; Thu, 16 Dec 2021 22:29:18 +0200 (EET) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6451768AF7B for ; Thu, 16 Dec 2021 22:29:10 +0200 (EET) Received: by mail-pj1-f54.google.com with SMTP id v16so241292pjn.1 for ; Thu, 16 Dec 2021 12:29:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rZWMbgT2GNQAa62hMJIeAGRCGooRp8fEShV/SFqtoxE=; b=lh8AtaCUQAh3iLyjKAKI4Z7rcysLtsJG1afjXmliHRd8hjjh0ByHGZXaXvu7F0eCue 5ek50VD/Xx8/AEJtAdWuvhGd/afKT5ouN8KdNlqedBqqaOllWlmjsGA7POCSoyuHd6gt gMVFRWSUw1D6JGDkOTGyr8tpk0CJM+rfhJB4TBmJ83ufL1uj8h/jQw6RFayO8JgNYziI cgx0BcAPVSaFfpV4foaqMFa5sIafZ38Az0X1/7Pl/dqZIeRrTmpDwICWnWADZ5FMTf1C s9hQxe/0IAQ9VLrWhZ6Bi89KwyLJHwZGuKGO57SGA5QZjs3dfLtJDQqD/MjNYPwJzf/I /+hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=rZWMbgT2GNQAa62hMJIeAGRCGooRp8fEShV/SFqtoxE=; b=z7X0resU6stEkDdzKH57HNGHui9BMn+K1arSYrvx7aXfv93WHF18h5fn3QI+/RMFTP DOzyhs8kwXhwYJ5yqmYPJtKDGDom/XgPV9lsAjUgNfd/wrObBr17ydOWvLPAF3ZZXx3o xeK3+eOR9hULEB15sws0pqFOegWE9xOdZuNcay8xmjfTpXY1XkaKXA6ZP0NDKSwTCdhU AXJrEezG77lGfvlYweic4vYXy/vpzNEVXqgRiQtSxNWGno2GAcSZhvUbqETvq91u0qJO fjowdlQyP/+Ctu3E8u/VWrsOKhsgaq4rsnL1Q5P4/ma4icxJKJOgCSrzfBAbOiPUwTbp lnpQ== X-Gm-Message-State: AOAM531OVlpy/qhJPzwx/nCnEjtzeWP5MNUbri30ASL1jAl4joQEINe9 W5W56XPfCbu4UKxwgrIsiFLgYbhuOpkubg== X-Google-Smtp-Source: ABdhPJyekaoeByplTBy7YQcPAfKeEbwXuURbwUKEUHdcygxINLKyBr6qqkBzE9/6itN84aRQD60YUg== X-Received: by 2002:a17:90b:1d02:: with SMTP id on2mr8041003pjb.226.1639686548374; Thu, 16 Dec 2021 12:29:08 -0800 (PST) Received: from tmm1-imac.lan ([2600:8802:5501:308f:15c6:3324:e59b:bed5]) by smtp.gmail.com with ESMTPSA id k16sm7534732pfu.183.2021.12.16.12.29.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Dec 2021 12:29:07 -0800 (PST) From: Aman Karmani To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Dec 2021 12:28:57 -0800 Message-Id: <20211216202858.77643-4-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211216202858.77643-1-ffmpeg@tmm1.net> References: <20211216202858.77643-1-ffmpeg@tmm1.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 4/5] avfilter: add metal utilities 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: philipl@overt.org, Aman Karmani , kernrj@gmail.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Aman Karmani Signed-off-by: Aman Karmani --- libavfilter/metal/utils.h | 35 +++++++++++++++++++ libavfilter/metal/utils.m | 73 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 libavfilter/metal/utils.h create mode 100644 libavfilter/metal/utils.m diff --git a/libavfilter/metal/utils.h b/libavfilter/metal/utils.h new file mode 100644 index 0000000000..bd0319f63c --- /dev/null +++ b/libavfilter/metal/utils.h @@ -0,0 +1,35 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFILTER_METAL_UTILS_H +#define AVFILTER_METAL_UTILS_H + +#include +#include + +void ff_metal_compute_encoder_dispatch(id device, + id pipeline, + id encoder, + NSUInteger width, NSUInteger height); + +CVMetalTextureRef ff_metal_texture_from_pixbuf(void *avclass, + CVMetalTextureCacheRef textureCache, + CVPixelBufferRef pixbuf, + int plane, + MTLPixelFormat format); +#endif /* AVFILTER_METAL_UTILS_H */ diff --git a/libavfilter/metal/utils.m b/libavfilter/metal/utils.m new file mode 100644 index 0000000000..5df0ed600e --- /dev/null +++ b/libavfilter/metal/utils.m @@ -0,0 +1,73 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/log.h" +#include + +void ff_metal_compute_encoder_dispatch(id device, + id pipeline, + id encoder, + NSUInteger width, NSUInteger height) +{ + [encoder setComputePipelineState:pipeline]; + NSUInteger w = pipeline.threadExecutionWidth; + NSUInteger h = pipeline.maxTotalThreadsPerThreadgroup / w; + MTLSize threadsPerThreadgroup = MTLSizeMake(w, h, 1); + BOOL fallback = YES; + if (@available(macOS 10.15, iOS 11, tvOS 14.5, *)) { + if ([device supportsFamily:MTLGPUFamilyCommon3]) { + MTLSize threadsPerGrid = MTLSizeMake(width, height, 1); + [encoder dispatchThreads:threadsPerGrid threadsPerThreadgroup:threadsPerThreadgroup]; + fallback = NO; + } + } + if (fallback) { + MTLSize threadgroups = MTLSizeMake((width + w - 1) / w, + (height + h - 1) / h, + 1); + [encoder dispatchThreadgroups:threadgroups threadsPerThreadgroup:threadsPerThreadgroup]; + } +} + +CVMetalTextureRef ff_metal_texture_from_pixbuf(void *ctx, + CVMetalTextureCacheRef textureCache, + CVPixelBufferRef pixbuf, + int plane, + MTLPixelFormat format) +{ + CVMetalTextureRef tex = NULL; + CVReturn ret; + + ret = CVMetalTextureCacheCreateTextureFromImage( + NULL, + textureCache, + pixbuf, + NULL, + format, + CVPixelBufferGetWidthOfPlane(pixbuf, plane), + CVPixelBufferGetHeightOfPlane(pixbuf, plane), + plane, + &tex + ); + if (ret != kCVReturnSuccess) { + av_log(ctx, AV_LOG_ERROR, "Failed to create CVMetalTexture from image: %d\n", ret); + return NULL; + } + + return tex; +} \ No newline at end of file -- 2.33.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".