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 F1CF74222B for ; Thu, 16 Dec 2021 23:13:25 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0B25E68AFBA; Fri, 17 Dec 2021 01:13:23 +0200 (EET) Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5F37568A76F for ; Fri, 17 Dec 2021 01:13:16 +0200 (EET) Received: by mail-wr1-f54.google.com with SMTP id j9so845962wrc.0 for ; Thu, 16 Dec 2021 15:13:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version; bh=TJK8+gfVlto0odlJe1liJZg+Eo/BAfK8U/Xw8DABUOs=; b=llQxuSFgkiTE+V4Vzvvai+bts8e4pMgGeUsOibgi0VKQDKoZoNE9XtDOX06vVzB0EU xD4ZxCwXoyuBL2MFYxpfa9xBll/e48AyxpYmrSlSNDY2bmwmV8ZLyoC7p8r0AZOGLwmM Q9dBBAC1tqUD4QoAK4vyuAy56EpohELmG6bmGMwzbpwcq2Ry418Iu7XNB+SbsJcnhKbi 0YE4KSh/cey6gchBh6NZWEZMENaytB6WDQC8N7RpU331nkq21S9s5VQFFvFOjOPQYz5S fwhgS5tPDIia7CT3Ud0uTq/rjrdU1FfGIi+0QZvMCkgu2QLpwLo7cPraWiIRqViDT7eN edkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version; bh=TJK8+gfVlto0odlJe1liJZg+Eo/BAfK8U/Xw8DABUOs=; b=OYEkVngZSR03+uvZ4hQSNfuZelUDfNm0UY1IIq0RPVGNDexEXIN+F8MvCqCxRnDNq6 JC8Cv5vDVkRSmRqAgCFcthNuJLgfctDfvSfUkkj0kaOhw3+vjQnf4t2t0mbL8X/7Jt2p zqrSqjNBj3nelqwCbIgtQQ8g+U7WySAa7gVK9nA0IPEmio7Ss21bpdC3i32Grs/uvC5W JwJTQcUk1tt0d+/43SeQOIi0l3h74dMia7mDb6eLa/puH1QN6F6KHv6flx81lAm2Zib0 FoJAz5IM/XFwBY2tTOObIv74Coz10yQWGTm//4Ne1koCtvn0sEZbNTivUVOANBfYd/oT ptzA== X-Gm-Message-State: AOAM531Q4e9tp9QjpIJX5FBgSMUeOz3G0qUDzGC9ZEatDGWiZHK383bT 8mDVyqCnyJUADco6341OVUw= X-Google-Smtp-Source: ABdhPJx+8tUY4wG0elXDsVkr/bQzoyCqx88Ua/bCy0Gz6vnglTI3TOPrWHMIAOPWyOphX/bgASvaJg== X-Received: by 2002:a5d:6c6b:: with SMTP id r11mr165759wrz.527.1639696395687; Thu, 16 Dec 2021 15:13:15 -0800 (PST) Received: from [10.10.10.172] (84-112-75-55.cable.dynamic.surfer.at. [84.112.75.55]) by smtp.gmail.com with ESMTPSA id h204sm5845218wmh.33.2021.12.16.15.13.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Dec 2021 15:13:15 -0800 (PST) From: "Marvin Scholz" To: "Aman Karmani" Date: Fri, 17 Dec 2021 00:13:14 +0100 X-Mailer: MailMate (1.13.2r5673) Message-ID: <6043C5D9-8BA5-4EFA-BD67-04A64AF348AE@gmail.com> In-Reply-To: References: <20211216202858.77643-1-ffmpeg@tmm1.net> <20211216202858.77643-4-ffmpeg@tmm1.net> <795C47EE-2EB2-4D66-88B3-26D3B55B6D3F@gmail.com> MIME-Version: 1.0 Subject: Re: [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: Richard Kern , FFmpeg development discussions and patches , philipl@overt.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 16 Dec 2021, at 23:53, Aman Karmani wrote: > On Thu, Dec 16, 2021 at 2:45 PM Marvin Scholz > wrote: > >> On 16 Dec 2021, at 21:28, Aman Karmani wrote: >> >>> From: Aman Karmani >>> >> >> Thanks for your work on this! Some comments inline: >> >>> 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; >>> + } >>> + } >> >> Why not just do an else here instead of the fallback variable? >> > > Well there's two if statements, and we need to run the fallback only > when > both fail. So where would the else go? I would need to duplicate it > twice. > Oh, is it not possible to just add the [device supportsFamily:MTLGPUFamilyCommon3] after the @available check? Or does that not work, just like its is not possible to negate a @available for some reason? > >> >>> + 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 >> >> Missing newline at end of file >> > > Fixed locally, thanks. > > >> >>> -- >>> 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". >> _______________________________________________ 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".