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 F156C4221C for ; Thu, 16 Dec 2021 22:45:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B413C68AEFF; Fri, 17 Dec 2021 00:45:23 +0200 (EET) Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 96EEE68819D for ; Fri, 17 Dec 2021 00:45:17 +0200 (EET) Received: by mail-wr1-f52.google.com with SMTP id q16so648902wrg.7 for ; Thu, 16 Dec 2021 14:45:17 -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=06ICLTcKlAiUKySb/49eXgC/7bfZQxVOIwZT6lgNfV0=; b=en17QhJXwPQ+qo7ZAmhIVm7nbBYNP6csgMPkSACpbTGIpTBgxSO2J656rbD0aQsP+t HHnz1D6h4C/IqqLRAZO5TjALwnPivSt+xrKucVjZlJ3vTEnbcjIvgGuOlIzhjErpemwm XiqNcYnRuAoqG2i4J47cYGl7eaqGIw39Y2OnhrdyXz7DiDH49vNFsit0+XWvEJXFK+ah VL5C9AtBqoC1WDMCY4acfoGxiBBUtPUjz65S17fX8s6cgUNebTy+Zj8ku038FkFjmSOU SwV02dkX/YNQl4OlDhKhI/X8AslZ8utEyp3fGZ1FOgOE7AQtYTXK6s+uYCL1FgOuyVDX /10g== 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=06ICLTcKlAiUKySb/49eXgC/7bfZQxVOIwZT6lgNfV0=; b=IwrdZDmBYM+FFjn6dEYmPBGImKwxg537iJtzbinU6uErNhykHEHRJvj7nZRjl3mmNo 4copydEBxS+zYNIAQPI7XSsHvPDiEm57CjLgRyT+34gdATbkgXNfznt8iBYGWQo64Y4M 80j6niZpJOLJ4oHmdyqAhcs019vJkaGe7Ej0YM9Af36yBCkyjqGsiJUUoGnzMKzQTaF9 42G/TgN6e/IVA7mgygYd5arbOUaA1rp7AWAIvkf+lln/xF8bgXb0vigvSuig7Q6G6TCc rBoeA3bHm+e1ODWmXbn2rkDk4FojO0raWbNwo8YOykfNKgvsnQ/PNL4IEbBMc0xufagy CAMg== X-Gm-Message-State: AOAM531gLtyQGid+pTYOi/0ZZCbO+nK5opaq0/0ev44BBawAKOXX909s D8hGIRVUxEhPAFbVVlZpsjFvJ0SNPSZNmA== X-Google-Smtp-Source: ABdhPJypxC2JjUNG9XYLNYaUioQg4rBlbDdbaKbfDP2YAfarrhb1BqONrqXn9Rz+aAKV/oE25OGXJA== X-Received: by 2002:adf:b606:: with SMTP id f6mr123421wre.310.1639694716645; Thu, 16 Dec 2021 14:45:16 -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 k31sm535768wms.21.2021.12.16.14.45.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Dec 2021 14:45:16 -0800 (PST) From: "Marvin Scholz" To: "FFmpeg development discussions and patches" Date: Thu, 16 Dec 2021 23:45:15 +0100 X-Mailer: MailMate (1.13.2r5673) Message-ID: <795C47EE-2EB2-4D66-88B3-26D3B55B6D3F@gmail.com> In-Reply-To: <20211216202858.77643-4-ffmpeg@tmm1.net> References: <20211216202858.77643-1-ffmpeg@tmm1.net> <20211216202858.77643-4-ffmpeg@tmm1.net> 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: kernrj@gmail.com, Aman Karmani , 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 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? > + 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 > -- > 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".