* [FFmpeg-devel] [PATCH 1/7] configure: fix setting OBJCCFLAGS
@ 2021-12-22 0:07 rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 2/7] configure: fix .d generation for C++ and Obj-C files rcombs
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: rcombs @ 2021-12-22 0:07 UTC (permalink / raw)
To: ffmpeg-devel
We call this OBJCFLAGS in help text, but common.mak looks for OBJCCFLAGS.
---
configure | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure b/configure
index 3abc4428e5..d49457d192 100755
--- a/configure
+++ b/configure
@@ -7643,7 +7643,7 @@ LN_S=$ln_s
CPPFLAGS=$CPPFLAGS
CFLAGS=$CFLAGS
CXXFLAGS=$CXXFLAGS
-OBJCFLAGS=$OBJCFLAGS
+OBJCCFLAGS=$OBJCFLAGS
ASFLAGS=$ASFLAGS
NVCCFLAGS=$nvccflags
AS_C=$AS_C
--
2.33.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 2/7] configure: fix .d generation for C++ and Obj-C files
2021-12-22 0:07 [FFmpeg-devel] [PATCH 1/7] configure: fix setting OBJCCFLAGS rcombs
@ 2021-12-22 0:07 ` rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 3/7] lavfi/metal: don't use braced-include for internal headers rcombs
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: rcombs @ 2021-12-22 0:07 UTC (permalink / raw)
To: ffmpeg-devel
---
configure | 2 ++
1 file changed, 2 insertions(+)
diff --git a/configure b/configure
index d49457d192..3ed7467252 100755
--- a/configure
+++ b/configure
@@ -7693,6 +7693,8 @@ ASDEP_FLAGS=$ASDEP_FLAGS
X86ASMDEP=$X86ASMDEP
X86ASMDEP_FLAGS=$X86ASMDEP_FLAGS
CC_DEPFLAGS=$CC_DEPFLAGS
+CXX_DEPFLAGS=$CXX_DEPFLAGS
+OBJCC_DEPFLAGS=$OBJC_DEPFLAGS
AS_DEPFLAGS=$AS_DEPFLAGS
X86ASM_DEPFLAGS=$X86ASM_DEPFLAGS
HOSTCC=$host_cc
--
2.33.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 3/7] lavfi/metal: don't use braced-include for internal headers
2021-12-22 0:07 [FFmpeg-devel] [PATCH 1/7] configure: fix setting OBJCCFLAGS rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 2/7] configure: fix .d generation for C++ and Obj-C files rcombs
@ 2021-12-22 0:07 ` rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 4/7] configure: ensure we use the macOS SDK's metal compiler by default rcombs
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: rcombs @ 2021-12-22 0:07 UTC (permalink / raw)
To: ffmpeg-devel
---
libavfilter/metal/utils.m | 2 +-
libavfilter/vf_yadif_videotoolbox.m | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavfilter/metal/utils.m b/libavfilter/metal/utils.m
index 759ebedfba..f831502065 100644
--- a/libavfilter/metal/utils.m
+++ b/libavfilter/metal/utils.m
@@ -17,7 +17,7 @@
*/
#include "libavutil/log.h"
-#include <libavfilter/metal/utils.h>
+#include "utils.h"
void ff_metal_compute_encoder_dispatch(id<MTLDevice> device,
id<MTLComputePipelineState> pipeline,
diff --git a/libavfilter/vf_yadif_videotoolbox.m b/libavfilter/vf_yadif_videotoolbox.m
index af83a73e89..65f155982e 100644
--- a/libavfilter/vf_yadif_videotoolbox.m
+++ b/libavfilter/vf_yadif_videotoolbox.m
@@ -20,11 +20,11 @@
*/
#include "internal.h"
+#include "metal/utils.h"
#include "yadif.h"
-#include <libavutil/avassert.h>
-#include <libavutil/hwcontext.h>
-#include <libavutil/objc.h>
-#include <libavfilter/metal/utils.h>
+#include "libavutil/avassert.h"
+#include "libavutil/hwcontext.h"
+#include "libavutil/objc.h"
extern char ff_vf_yadif_videotoolbox_metallib_data[];
extern unsigned int ff_vf_yadif_videotoolbox_metallib_len;
--
2.33.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 4/7] configure: ensure we use the macOS SDK's metal compiler by default
2021-12-22 0:07 [FFmpeg-devel] [PATCH 1/7] configure: fix setting OBJCCFLAGS rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 2/7] configure: fix .d generation for C++ and Obj-C files rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 3/7] lavfi/metal: don't use braced-include for internal headers rcombs
@ 2021-12-22 0:07 ` rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 5/7] configure: test the metal compiler before use rcombs
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: rcombs @ 2021-12-22 0:07 UTC (permalink / raw)
To: ffmpeg-devel
Apparently on some OS and Xcode versions this can select an iOS SDK,
which in turn may fail on the affected versions.
---
configure | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/configure b/configure
index 3ed7467252..06a4d3f485 100755
--- a/configure
+++ b/configure
@@ -3844,8 +3844,8 @@ host_cc_default="gcc"
doxygen_default="doxygen"
install="install"
ln_s_default="ln -s -f"
-metalcc_default="xcrun metal"
-metallib_default="xcrun metallib"
+metalcc_default="xcrun -sdk macosx metal"
+metallib_default="xcrun -sdk macosx metallib"
nm_default="nm -g"
pkg_config_default=pkg-config
ranlib_default="ranlib"
--
2.33.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 5/7] configure: test the metal compiler before use
2021-12-22 0:07 [FFmpeg-devel] [PATCH 1/7] configure: fix setting OBJCCFLAGS rcombs
` (2 preceding siblings ...)
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 4/7] configure: ensure we use the macOS SDK's metal compiler by default rcombs
@ 2021-12-22 0:07 ` rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 6/7] lavfi/metal: fix build on pre-10.15 SDKs rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 7/7] lavfi/metal: fix build with pre-10.11 deployment targets rcombs
5 siblings, 0 replies; 9+ messages in thread
From: rcombs @ 2021-12-22 0:07 UTC (permalink / raw)
To: ffmpeg-devel
Apparently Metal.framework is included with the command line tools
(and thus may be present without Xcode), but the Metal compiler is only
included as part of Xcode.
---
configure | 2 ++
1 file changed, 2 insertions(+)
diff --git a/configure b/configure
index 06a4d3f485..cb02c54bf1 100755
--- a/configure
+++ b/configure
@@ -6365,6 +6365,8 @@ enabled videotoolbox && {
check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferTransferFunction_SMPTE_ST_428_1 "-framework CoreVideo"
}
+enabled metal && test_cmd $metalcc -v || disable metal
+
check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss
check_type "windows.h dxva.h" "DXVA_PicParams_AV1" -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -D_CRT_BUILD_DESKTOP_APP=0
--
2.33.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 6/7] lavfi/metal: fix build on pre-10.15 SDKs
2021-12-22 0:07 [FFmpeg-devel] [PATCH 1/7] configure: fix setting OBJCCFLAGS rcombs
` (3 preceding siblings ...)
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 5/7] configure: test the metal compiler before use rcombs
@ 2021-12-22 0:07 ` rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 7/7] lavfi/metal: fix build with pre-10.11 deployment targets rcombs
5 siblings, 0 replies; 9+ messages in thread
From: rcombs @ 2021-12-22 0:07 UTC (permalink / raw)
To: ffmpeg-devel
---
libavfilter/metal/utils.m | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libavfilter/metal/utils.m b/libavfilter/metal/utils.m
index f831502065..f365d3ceea 100644
--- a/libavfilter/metal/utils.m
+++ b/libavfilter/metal/utils.m
@@ -29,6 +29,8 @@ void ff_metal_compute_encoder_dispatch(id<MTLDevice> device,
NSUInteger h = pipeline.maxTotalThreadsPerThreadgroup / w;
MTLSize threadsPerThreadgroup = MTLSizeMake(w, h, 1);
BOOL fallback = YES;
+ // MAC_OS_X_VERSION_10_15 is only defined on SDKs new enough to include its functionality (including iOS, tvOS, etc)
+#ifdef MAC_OS_X_VERSION_10_15
if (@available(macOS 10.15, iOS 11, tvOS 14.5, *)) {
if ([device supportsFamily:MTLGPUFamilyCommon3]) {
MTLSize threadsPerGrid = MTLSizeMake(width, height, 1);
@@ -36,6 +38,7 @@ void ff_metal_compute_encoder_dispatch(id<MTLDevice> device,
fallback = NO;
}
}
+#endif
if (fallback) {
MTLSize threadgroups = MTLSizeMake((width + w - 1) / w,
(height + h - 1) / h,
--
2.33.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 7/7] lavfi/metal: fix build with pre-10.11 deployment targets
2021-12-22 0:07 [FFmpeg-devel] [PATCH 1/7] configure: fix setting OBJCCFLAGS rcombs
` (4 preceding siblings ...)
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 6/7] lavfi/metal: fix build on pre-10.15 SDKs rcombs
@ 2021-12-22 0:07 ` rcombs
2021-12-22 1:20 ` Aman Karmani
2022-01-27 18:32 ` Alex
5 siblings, 2 replies; 9+ messages in thread
From: rcombs @ 2021-12-22 0:07 UTC (permalink / raw)
To: ffmpeg-devel
- Ensure the yadif .metal compiles when targeting any Metal runtime version
- Use some preprocessor awkwardness to ensure Core Video's Metal-specific
functionality is exposed regardless of our deployment target (this works
around what seems to be an SDK header bug, filed as FB9816002)
- Ensure all direct references to Metal functions and classes are gated
behind runtime version checks (this satisfies clang's deployment-target
violation warnings provided by -Wunguarded-availability).
---
libavfilter/metal/utils.h | 28 +++++++-
libavfilter/metal/vf_yadif_videotoolbox.metal | 11 ++-
libavfilter/vf_yadif_videotoolbox.m | 67 ++++++++++++++++---
3 files changed, 94 insertions(+), 12 deletions(-)
diff --git a/libavfilter/metal/utils.h b/libavfilter/metal/utils.h
index bd0319f63c..7350d42a35 100644
--- a/libavfilter/metal/utils.h
+++ b/libavfilter/metal/utils.h
@@ -20,16 +20,40 @@
#define AVFILTER_METAL_UTILS_H
#include <Metal/Metal.h>
+
+#include <AvailabilityMacros.h>
+
+// CoreVideo accidentally(?) preprocessor-gates Metal functionality
+// on MAC_OS_X_VERSION_MIN_REQUIRED >= 101100 (FB9816002).
+// There doesn't seem to be any particular reason for this,
+// so here we temporarily redefine it to at least that value
+// so CV will give us CVMetalTextureRef and the related functions.
+
+#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && (MAC_OS_X_VERSION_MIN_REQUIRED < 101100)
+#define ORIG_MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_MIN_REQUIRED
+#undef MAC_OS_X_VERSION_MIN_REQUIRED
+#define MAC_OS_X_VERSION_MIN_REQUIRED 101100
+#endif
+
#include <CoreVideo/CoreVideo.h>
+#ifdef ORIG_MAC_OS_X_VERSION_MIN_REQUIRED
+#undef MAC_OS_X_VERSION_MIN_REQUIRED
+#define MAC_OS_X_VERSION_MIN_REQUIRED ORIG_MAC_OS_X_VERSION_MIN_REQUIRED
+#undef ORIG_MAC_OS_X_VERSION_MIN_REQUIRED
+#endif
+
void ff_metal_compute_encoder_dispatch(id<MTLDevice> device,
id<MTLComputePipelineState> pipeline,
id<MTLComputeCommandEncoder> encoder,
- NSUInteger width, NSUInteger height);
+ NSUInteger width, NSUInteger height)
+ API_AVAILABLE(macos(10.11), ios(8.0));
CVMetalTextureRef ff_metal_texture_from_pixbuf(void *avclass,
CVMetalTextureCacheRef textureCache,
CVPixelBufferRef pixbuf,
int plane,
- MTLPixelFormat format);
+ MTLPixelFormat format)
+ API_AVAILABLE(macos(10.11), ios(8.0));
+
#endif /* AVFILTER_METAL_UTILS_H */
diff --git a/libavfilter/metal/vf_yadif_videotoolbox.metal b/libavfilter/metal/vf_yadif_videotoolbox.metal
index 50783f2ffe..8a3d41a30f 100644
--- a/libavfilter/metal/vf_yadif_videotoolbox.metal
+++ b/libavfilter/metal/vf_yadif_videotoolbox.metal
@@ -26,6 +26,15 @@
using namespace metal;
+/*
+ * Version compat shims
+ */
+
+#if __METAL_VERSION__ < 210
+#define max3(x, y, z) max(x, max(y, z))
+#define min3(x, y, z) min(x, min(y, z))
+#endif
+
/*
* Parameters
*/
@@ -44,7 +53,7 @@ struct deintParams {
*/
#define accesstype access::sample
-const sampler s(coord::pixel);
+constexpr sampler s(coord::pixel);
template <typename T>
T tex2D(texture2d<float, access::sample> tex, uint x, uint y)
diff --git a/libavfilter/vf_yadif_videotoolbox.m b/libavfilter/vf_yadif_videotoolbox.m
index 65f155982e..455745817f 100644
--- a/libavfilter/vf_yadif_videotoolbox.m
+++ b/libavfilter/vf_yadif_videotoolbox.m
@@ -26,10 +26,12 @@
#include "libavutil/hwcontext.h"
#include "libavutil/objc.h"
+#include <assert.h>
+
extern char ff_vf_yadif_videotoolbox_metallib_data[];
extern unsigned int ff_vf_yadif_videotoolbox_metallib_len;
-typedef struct YADIFVTContext {
+typedef struct API_AVAILABLE(macos(10.11), ios(8.0)) YADIFVTContext {
YADIFContext yadif;
AVBufferRef *device_ref;
@@ -44,7 +46,12 @@ typedef struct YADIFVTContext {
id<MTLBuffer> mtlParamsBuffer;
CVMetalTextureCacheRef textureCache;
-} YADIFVTContext;
+} YADIFVTContext API_AVAILABLE(macos(10.11), ios(8.0));
+
+// Using sizeof(YADIFVTContext) outside of an availability check will error
+// if we're targeting an older OS version, so we need to calculate the size ourselves
+// (we'll statically verify it's correct in yadif_videotoolbox_init behind a check)
+#define YADIF_VT_CTX_SIZE (sizeof(YADIFContext) + sizeof(void*) * 10)
struct mtlYadifParams {
uint channels;
@@ -62,7 +69,7 @@ static void call_kernel(AVFilterContext *ctx,
id<MTLTexture> next,
int channels,
int parity,
- int tff)
+ int tff) API_AVAILABLE(macos(10.11), ios(8.0))
{
YADIFVTContext *s = ctx->priv;
id<MTLCommandBuffer> buffer = s->mtlQueue.commandBuffer;
@@ -93,7 +100,7 @@ static void call_kernel(AVFilterContext *ctx,
}
static void filter(AVFilterContext *ctx, AVFrame *dst,
- int parity, int tff)
+ int parity, int tff) API_AVAILABLE(macos(10.11), ios(8.0))
{
YADIFVTContext *s = ctx->priv;
YADIFContext *y = &s->yadif;
@@ -162,7 +169,7 @@ exit:
return;
}
-static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx)
+static av_cold void do_uninit(AVFilterContext *ctx) API_AVAILABLE(macos(10.11), ios(8.0))
{
YADIFVTContext *s = ctx->priv;
YADIFContext *y = &s->yadif;
@@ -188,7 +195,15 @@ static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx)
}
}
-static av_cold int yadif_videotoolbox_init(AVFilterContext *ctx)
+
+static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx)
+{
+ if (@available(macOS 10.11, iOS 8.0, *)) {
+ do_uninit(ctx);
+ }
+}
+
+static av_cold int do_init(AVFilterContext *ctx) API_AVAILABLE(macos(10.11), ios(8.0))
{
YADIFVTContext *s = ctx->priv;
NSError *err = nil;
@@ -261,7 +276,19 @@ fail:
return AVERROR_EXTERNAL;
}
-static int config_input(AVFilterLink *inlink)
+static av_cold int yadif_videotoolbox_init(AVFilterContext *ctx)
+{
+ if (@available(macOS 10.11, iOS 8.0, *)) {
+ // Ensure we calculated YADIF_VT_CTX_SIZE correctly
+ static_assert(YADIF_VT_CTX_SIZE == sizeof(YADIFVTContext), "Incorrect YADIF_VT_CTX_SIZE value!");
+ return do_init(ctx);
+ } else {
+ av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n");
+ return AVERROR(ENOSYS);
+ }
+}
+
+static int do_config_input(AVFilterLink *inlink) API_AVAILABLE(macos(10.11), ios(8.0))
{
AVFilterContext *ctx = inlink->dst;
YADIFVTContext *s = ctx->priv;
@@ -283,7 +310,18 @@ static int config_input(AVFilterLink *inlink)
return 0;
}
-static int config_output(AVFilterLink *link)
+static int config_input(AVFilterLink *inlink)
+{
+ AVFilterContext *ctx = inlink->dst;
+ if (@available(macOS 10.11, iOS 8.0, *)) {
+ return do_config_input(inlink);
+ } else {
+ av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n");
+ return AVERROR(ENOSYS);
+ }
+}
+
+static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios(8.0))
{
AVHWFramesContext *output_frames;
AVFilterContext *ctx = link->src;
@@ -347,6 +385,17 @@ exit:
return ret;
}
+static int config_output(AVFilterLink *link)
+{
+ AVFilterContext *ctx = link->src;
+ if (@available(macOS 10.11, iOS 8.0, *)) {
+ return do_config_output(link);
+ } else {
+ av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n");
+ return AVERROR(ENOSYS);
+ }
+}
+
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
#define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, INT_MIN, INT_MAX, FLAGS, unit }
@@ -394,7 +443,7 @@ static const AVFilterPad yadif_videotoolbox_outputs[] = {
AVFilter ff_vf_yadif_videotoolbox = {
.name = "yadif_videotoolbox",
.description = NULL_IF_CONFIG_SMALL("YADIF for VideoToolbox frames using Metal compute"),
- .priv_size = sizeof(YADIFVTContext),
+ .priv_size = YADIF_VT_CTX_SIZE,
.priv_class = &yadif_videotoolbox_class,
.init = yadif_videotoolbox_init,
.uninit = yadif_videotoolbox_uninit,
--
2.33.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH 7/7] lavfi/metal: fix build with pre-10.11 deployment targets
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 7/7] lavfi/metal: fix build with pre-10.11 deployment targets rcombs
@ 2021-12-22 1:20 ` Aman Karmani
2022-01-27 18:32 ` Alex
1 sibling, 0 replies; 9+ messages in thread
From: Aman Karmani @ 2021-12-22 1:20 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Tue, Dec 21, 2021 at 4:15 PM rcombs <rcombs@rcombs.me> wrote:
> - Ensure the yadif .metal compiles when targeting any Metal runtime version
> - Use some preprocessor awkwardness to ensure Core Video's Metal-specific
> functionality is exposed regardless of our deployment target (this works
> around what seems to be an SDK header bug, filed as FB9816002)
> - Ensure all direct references to Metal functions and classes are gated
> behind runtime version checks (this satisfies clang's deployment-target
> violation warnings provided by -Wunguarded-availability).
> ---
> libavfilter/metal/utils.h | 28 +++++++-
> libavfilter/metal/vf_yadif_videotoolbox.metal | 11 ++-
> libavfilter/vf_yadif_videotoolbox.m | 67 ++++++++++++++++---
> 3 files changed, 94 insertions(+), 12 deletions(-)
>
Patchset LGTM. Thanks for your work on this.
>
> diff --git a/libavfilter/metal/utils.h b/libavfilter/metal/utils.h
> index bd0319f63c..7350d42a35 100644
> --- a/libavfilter/metal/utils.h
> +++ b/libavfilter/metal/utils.h
> @@ -20,16 +20,40 @@
> #define AVFILTER_METAL_UTILS_H
>
> #include <Metal/Metal.h>
> +
> +#include <AvailabilityMacros.h>
> +
> +// CoreVideo accidentally(?) preprocessor-gates Metal functionality
> +// on MAC_OS_X_VERSION_MIN_REQUIRED >= 101100 (FB9816002).
> +// There doesn't seem to be any particular reason for this,
> +// so here we temporarily redefine it to at least that value
> +// so CV will give us CVMetalTextureRef and the related functions.
> +
> +#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) &&
> (MAC_OS_X_VERSION_MIN_REQUIRED < 101100)
> +#define ORIG_MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_MIN_REQUIRED
> +#undef MAC_OS_X_VERSION_MIN_REQUIRED
> +#define MAC_OS_X_VERSION_MIN_REQUIRED 101100
> +#endif
> +
> #include <CoreVideo/CoreVideo.h>
>
> +#ifdef ORIG_MAC_OS_X_VERSION_MIN_REQUIRED
> +#undef MAC_OS_X_VERSION_MIN_REQUIRED
> +#define MAC_OS_X_VERSION_MIN_REQUIRED ORIG_MAC_OS_X_VERSION_MIN_REQUIRED
> +#undef ORIG_MAC_OS_X_VERSION_MIN_REQUIRED
> +#endif
> +
> void ff_metal_compute_encoder_dispatch(id<MTLDevice> device,
> id<MTLComputePipelineState>
> pipeline,
> id<MTLComputeCommandEncoder>
> encoder,
> - NSUInteger width, NSUInteger
> height);
> + NSUInteger width, NSUInteger
> height)
> + API_AVAILABLE(macos(10.11),
> ios(8.0));
>
> CVMetalTextureRef ff_metal_texture_from_pixbuf(void *avclass,
> CVMetalTextureCacheRef
> textureCache,
> CVPixelBufferRef pixbuf,
> int plane,
> - MTLPixelFormat format);
> + MTLPixelFormat format)
> +
> API_AVAILABLE(macos(10.11), ios(8.0));
> +
> #endif /* AVFILTER_METAL_UTILS_H */
> diff --git a/libavfilter/metal/vf_yadif_videotoolbox.metal
> b/libavfilter/metal/vf_yadif_videotoolbox.metal
> index 50783f2ffe..8a3d41a30f 100644
> --- a/libavfilter/metal/vf_yadif_videotoolbox.metal
> +++ b/libavfilter/metal/vf_yadif_videotoolbox.metal
> @@ -26,6 +26,15 @@
>
> using namespace metal;
>
> +/*
> + * Version compat shims
> + */
> +
> +#if __METAL_VERSION__ < 210
> +#define max3(x, y, z) max(x, max(y, z))
> +#define min3(x, y, z) min(x, min(y, z))
> +#endif
> +
> /*
> * Parameters
> */
> @@ -44,7 +53,7 @@ struct deintParams {
> */
>
> #define accesstype access::sample
> -const sampler s(coord::pixel);
> +constexpr sampler s(coord::pixel);
>
> template <typename T>
> T tex2D(texture2d<float, access::sample> tex, uint x, uint y)
> diff --git a/libavfilter/vf_yadif_videotoolbox.m
> b/libavfilter/vf_yadif_videotoolbox.m
> index 65f155982e..455745817f 100644
> --- a/libavfilter/vf_yadif_videotoolbox.m
> +++ b/libavfilter/vf_yadif_videotoolbox.m
> @@ -26,10 +26,12 @@
> #include "libavutil/hwcontext.h"
> #include "libavutil/objc.h"
>
> +#include <assert.h>
> +
> extern char ff_vf_yadif_videotoolbox_metallib_data[];
> extern unsigned int ff_vf_yadif_videotoolbox_metallib_len;
>
> -typedef struct YADIFVTContext {
> +typedef struct API_AVAILABLE(macos(10.11), ios(8.0)) YADIFVTContext {
> YADIFContext yadif;
>
> AVBufferRef *device_ref;
> @@ -44,7 +46,12 @@ typedef struct YADIFVTContext {
> id<MTLBuffer> mtlParamsBuffer;
>
> CVMetalTextureCacheRef textureCache;
> -} YADIFVTContext;
> +} YADIFVTContext API_AVAILABLE(macos(10.11), ios(8.0));
> +
> +// Using sizeof(YADIFVTContext) outside of an availability check will
> error
> +// if we're targeting an older OS version, so we need to calculate the
> size ourselves
> +// (we'll statically verify it's correct in yadif_videotoolbox_init
> behind a check)
> +#define YADIF_VT_CTX_SIZE (sizeof(YADIFContext) + sizeof(void*) * 10)
>
> struct mtlYadifParams {
> uint channels;
> @@ -62,7 +69,7 @@ static void call_kernel(AVFilterContext *ctx,
> id<MTLTexture> next,
> int channels,
> int parity,
> - int tff)
> + int tff) API_AVAILABLE(macos(10.11), ios(8.0))
> {
> YADIFVTContext *s = ctx->priv;
> id<MTLCommandBuffer> buffer = s->mtlQueue.commandBuffer;
> @@ -93,7 +100,7 @@ static void call_kernel(AVFilterContext *ctx,
> }
>
> static void filter(AVFilterContext *ctx, AVFrame *dst,
> - int parity, int tff)
> + int parity, int tff) API_AVAILABLE(macos(10.11),
> ios(8.0))
> {
> YADIFVTContext *s = ctx->priv;
> YADIFContext *y = &s->yadif;
> @@ -162,7 +169,7 @@ exit:
> return;
> }
>
> -static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx)
> +static av_cold void do_uninit(AVFilterContext *ctx)
> API_AVAILABLE(macos(10.11), ios(8.0))
> {
> YADIFVTContext *s = ctx->priv;
> YADIFContext *y = &s->yadif;
> @@ -188,7 +195,15 @@ static av_cold void
> yadif_videotoolbox_uninit(AVFilterContext *ctx)
> }
> }
>
> -static av_cold int yadif_videotoolbox_init(AVFilterContext *ctx)
> +
> +static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx)
> +{
> + if (@available(macOS 10.11, iOS 8.0, *)) {
> + do_uninit(ctx);
> + }
> +}
> +
> +static av_cold int do_init(AVFilterContext *ctx)
> API_AVAILABLE(macos(10.11), ios(8.0))
> {
> YADIFVTContext *s = ctx->priv;
> NSError *err = nil;
> @@ -261,7 +276,19 @@ fail:
> return AVERROR_EXTERNAL;
> }
>
> -static int config_input(AVFilterLink *inlink)
> +static av_cold int yadif_videotoolbox_init(AVFilterContext *ctx)
> +{
> + if (@available(macOS 10.11, iOS 8.0, *)) {
> + // Ensure we calculated YADIF_VT_CTX_SIZE correctly
> + static_assert(YADIF_VT_CTX_SIZE == sizeof(YADIFVTContext),
> "Incorrect YADIF_VT_CTX_SIZE value!");
> + return do_init(ctx);
> + } else {
> + av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS
> version\n");
> + return AVERROR(ENOSYS);
> + }
> +}
> +
> +static int do_config_input(AVFilterLink *inlink)
> API_AVAILABLE(macos(10.11), ios(8.0))
> {
> AVFilterContext *ctx = inlink->dst;
> YADIFVTContext *s = ctx->priv;
> @@ -283,7 +310,18 @@ static int config_input(AVFilterLink *inlink)
> return 0;
> }
>
> -static int config_output(AVFilterLink *link)
> +static int config_input(AVFilterLink *inlink)
> +{
> + AVFilterContext *ctx = inlink->dst;
> + if (@available(macOS 10.11, iOS 8.0, *)) {
> + return do_config_input(inlink);
> + } else {
> + av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS
> version\n");
> + return AVERROR(ENOSYS);
> + }
> +}
> +
> +static int do_config_output(AVFilterLink *link)
> API_AVAILABLE(macos(10.11), ios(8.0))
> {
> AVHWFramesContext *output_frames;
> AVFilterContext *ctx = link->src;
> @@ -347,6 +385,17 @@ exit:
> return ret;
> }
>
> +static int config_output(AVFilterLink *link)
> +{
> + AVFilterContext *ctx = link->src;
> + if (@available(macOS 10.11, iOS 8.0, *)) {
> + return do_config_output(link);
> + } else {
> + av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS
> version\n");
> + return AVERROR(ENOSYS);
> + }
> +}
> +
> #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
> #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST,
> {.i64=val}, INT_MIN, INT_MAX, FLAGS, unit }
>
> @@ -394,7 +443,7 @@ static const AVFilterPad yadif_videotoolbox_outputs[]
> = {
> AVFilter ff_vf_yadif_videotoolbox = {
> .name = "yadif_videotoolbox",
> .description = NULL_IF_CONFIG_SMALL("YADIF for VideoToolbox frames
> using Metal compute"),
> - .priv_size = sizeof(YADIFVTContext),
> + .priv_size = YADIF_VT_CTX_SIZE,
> .priv_class = &yadif_videotoolbox_class,
> .init = yadif_videotoolbox_init,
> .uninit = yadif_videotoolbox_uninit,
> --
> 2.33.1
>
> _______________________________________________
> 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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [FFmpeg-devel] [PATCH 7/7] lavfi/metal: fix build with pre-10.11 deployment targets
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 7/7] lavfi/metal: fix build with pre-10.11 deployment targets rcombs
2021-12-22 1:20 ` Aman Karmani
@ 2022-01-27 18:32 ` Alex
1 sibling, 0 replies; 9+ messages in thread
From: Alex @ 2022-01-27 18:32 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Can you tell me more where this come from ?
extern char ff_vf_yadif_videotoolbox_metallib_data[];
extern unsigned int ff_vf_yadif_videotoolbox_metallib_len;
22 December 2021, 02:15:23, by "rcombs" <rcombs@rcombs.me>:
- Ensure the yadif .metal compiles when targeting any Metal runtime version
- Use some preprocessor awkwardness to ensure Core Video's Metal-specific
functionality is exposed regardless of our deployment target (this works
around what seems to be an SDK header bug, filed as FB9816002)
- Ensure all direct references to Metal functions and classes are gated
behind runtime version checks (this satisfies clang's deployment-target
violation warnings provided by -Wunguarded-availability).
---
libavfilter/metal/utils.h | 28 +++++++-
libavfilter/metal/vf_yadif_videotoolbox.metal | 11 ++-
libavfilter/vf_yadif_videotoolbox.m | 67 ++++++++++++++++---
3 files changed, 94 insertions(+), 12 deletions(-)
diff --git a/libavfilter/metal/utils.h b/libavfilter/metal/utils.h
index bd0319f63c..7350d42a35 100644
--- a/libavfilter/metal/utils.h
+++ b/libavfilter/metal/utils.h
@@ -20,16 +20,40 @@
#define AVFILTER_METAL_UTILS_H
#include <Metal/Metal.h>
+
+#include <AvailabilityMacros.h>
+
+// CoreVideo accidentally(?) preprocessor-gates Metal functionality
+// on MAC_OS_X_VERSION_MIN_REQUIRED >= 101100 (FB9816002).
+// There doesn't seem to be any particular reason for this,
+// so here we temporarily redefine it to at least that value
+// so CV will give us CVMetalTextureRef and the related functions.
+
+#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && (MAC_OS_X_VERSION_MIN_REQUIRED < 101100)
+#define ORIG_MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_MIN_REQUIRED
+#undef MAC_OS_X_VERSION_MIN_REQUIRED
+#define MAC_OS_X_VERSION_MIN_REQUIRED 101100
+#endif
+
#include <CoreVideo/CoreVideo.h>
+#ifdef ORIG_MAC_OS_X_VERSION_MIN_REQUIRED
+#undef MAC_OS_X_VERSION_MIN_REQUIRED
+#define MAC_OS_X_VERSION_MIN_REQUIRED ORIG_MAC_OS_X_VERSION_MIN_REQUIRED
+#undef ORIG_MAC_OS_X_VERSION_MIN_REQUIRED
+#endif
+
void ff_metal_compute_encoder_dispatch(id<MTLDevice> device,
id<MTLComputePipelineState> pipeline,
id<MTLComputeCommandEncoder> encoder,
- NSUInteger width, NSUInteger height);
+ NSUInteger width, NSUInteger height)
+ API_AVAILABLE(macos(10.11), ios(8.0));
CVMetalTextureRef ff_metal_texture_from_pixbuf(void *avclass,
CVMetalTextureCacheRef textureCache,
CVPixelBufferRef pixbuf,
int plane,
- MTLPixelFormat format);
+ MTLPixelFormat format)
+ API_AVAILABLE(macos(10.11), ios(8.0));
+
#endif /* AVFILTER_METAL_UTILS_H */
diff --git a/libavfilter/metal/vf_yadif_videotoolbox.metal b/libavfilter/metal/vf_yadif_videotoolbox.metal
index 50783f2ffe..8a3d41a30f 100644
--- a/libavfilter/metal/vf_yadif_videotoolbox.metal
+++ b/libavfilter/metal/vf_yadif_videotoolbox.metal
@@ -26,6 +26,15 @@
using namespace metal;
+/*
+ * Version compat shims
+ */
+
+#if __METAL_VERSION__ < 210
+#define max3(x, y, z) max(x, max(y, z))
+#define min3(x, y, z) min(x, min(y, z))
+#endif
+
/*
* Parameters
*/
@@ -44,7 +53,7 @@ struct deintParams {
*/
#define accesstype access::sample
-const sampler s(coord::pixel);
+constexpr sampler s(coord::pixel);
template <typename T>
T tex2D(texture2d<float, access::sample> tex, uint x, uint y)
diff --git a/libavfilter/vf_yadif_videotoolbox.m b/libavfilter/vf_yadif_videotoolbox.m
index 65f155982e..455745817f 100644
--- a/libavfilter/vf_yadif_videotoolbox.m
+++ b/libavfilter/vf_yadif_videotoolbox.m
@@ -26,10 +26,12 @@
#include "libavutil/hwcontext.h"
#include "libavutil/objc.h"
+#include <assert.h>
+
extern char ff_vf_yadif_videotoolbox_metallib_data[];
extern unsigned int ff_vf_yadif_videotoolbox_metallib_len;
-typedef struct YADIFVTContext {
+typedef struct API_AVAILABLE(macos(10.11), ios(8.0)) YADIFVTContext {
YADIFContext yadif;
AVBufferRef *device_ref;
@@ -44,7 +46,12 @@ typedef struct YADIFVTContext {
id<MTLBuffer> mtlParamsBuffer;
CVMetalTextureCacheRef textureCache;
-} YADIFVTContext;
+} YADIFVTContext API_AVAILABLE(macos(10.11), ios(8.0));
+
+// Using sizeof(YADIFVTContext) outside of an availability check will error
+// if we're targeting an older OS version, so we need to calculate the size ourselves
+// (we'll statically verify it's correct in yadif_videotoolbox_init behind a check)
+#define YADIF_VT_CTX_SIZE (sizeof(YADIFContext) + sizeof(void*) * 10)
struct mtlYadifParams {
uint channels;
@@ -62,7 +69,7 @@ static void call_kernel(AVFilterContext *ctx,
id<MTLTexture> next,
int channels,
int parity,
- int tff)
+ int tff) API_AVAILABLE(macos(10.11), ios(8.0))
{
YADIFVTContext *s = ctx->priv;
id<MTLCommandBuffer> buffer = s->mtlQueue.commandBuffer;
@@ -93,7 +100,7 @@ static void call_kernel(AVFilterContext *ctx,
}
static void filter(AVFilterContext *ctx, AVFrame *dst,
- int parity, int tff)
+ int parity, int tff) API_AVAILABLE(macos(10.11), ios(8.0))
{
YADIFVTContext *s = ctx->priv;
YADIFContext *y = &s->yadif;
@@ -162,7 +169,7 @@ exit:
return;
}
-static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx)
+static av_cold void do_uninit(AVFilterContext *ctx) API_AVAILABLE(macos(10.11), ios(8.0))
{
YADIFVTContext *s = ctx->priv;
YADIFContext *y = &s->yadif;
@@ -188,7 +195,15 @@ static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx)
}
}
-static av_cold int yadif_videotoolbox_init(AVFilterContext *ctx)
+
+static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx)
+{
+ if (@available(macOS 10.11, iOS 8.0, *)) {
+ do_uninit(ctx);
+ }
+}
+
+static av_cold int do_init(AVFilterContext *ctx) API_AVAILABLE(macos(10.11), ios(8.0))
{
YADIFVTContext *s = ctx->priv;
NSError *err = nil;
@@ -261,7 +276,19 @@ fail:
return AVERROR_EXTERNAL;
}
-static int config_input(AVFilterLink *inlink)
+static av_cold int yadif_videotoolbox_init(AVFilterContext *ctx)
+{
+ if (@available(macOS 10.11, iOS 8.0, *)) {
+ // Ensure we calculated YADIF_VT_CTX_SIZE correctly
+ static_assert(YADIF_VT_CTX_SIZE == sizeof(YADIFVTContext), "Incorrect YADIF_VT_CTX_SIZE value!");
+ return do_init(ctx);
+ } else {
+ av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n");
+ return AVERROR(ENOSYS);
+ }
+}
+
+static int do_config_input(AVFilterLink *inlink) API_AVAILABLE(macos(10.11), ios(8.0))
{
AVFilterContext *ctx = inlink->dst;
YADIFVTContext *s = ctx->priv;
@@ -283,7 +310,18 @@ static int config_input(AVFilterLink *inlink)
return 0;
}
-static int config_output(AVFilterLink *link)
+static int config_input(AVFilterLink *inlink)
+{
+ AVFilterContext *ctx = inlink->dst;
+ if (@available(macOS 10.11, iOS 8.0, *)) {
+ return do_config_input(inlink);
+ } else {
+ av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n");
+ return AVERROR(ENOSYS);
+ }
+}
+
+static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios(8.0))
{
AVHWFramesContext *output_frames;
AVFilterContext *ctx = link->src;
@@ -347,6 +385,17 @@ exit:
return ret;
}
+static int config_output(AVFilterLink *link)
+{
+ AVFilterContext *ctx = link->src;
+ if (@available(macOS 10.11, iOS 8.0, *)) {
+ return do_config_output(link);
+ } else {
+ av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n");
+ return AVERROR(ENOSYS);
+ }
+}
+
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
#define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, INT_MIN, INT_MAX, FLAGS, unit }
@@ -394,7 +443,7 @@ static const AVFilterPad yadif_videotoolbox_outputs[] = {
AVFilter ff_vf_yadif_videotoolbox = {
.name = "yadif_videotoolbox",
.description = NULL_IF_CONFIG_SMALL("YADIF for VideoToolbox frames using Metal compute"),
- .priv_size = sizeof(YADIFVTContext),
+ .priv_size = YADIF_VT_CTX_SIZE,
.priv_class = &yadif_videotoolbox_class,
.init = yadif_videotoolbox_init,
.uninit = yadif_videotoolbox_uninit,
--
2.33.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-01-27 18:32 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-22 0:07 [FFmpeg-devel] [PATCH 1/7] configure: fix setting OBJCCFLAGS rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 2/7] configure: fix .d generation for C++ and Obj-C files rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 3/7] lavfi/metal: don't use braced-include for internal headers rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 4/7] configure: ensure we use the macOS SDK's metal compiler by default rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 5/7] configure: test the metal compiler before use rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 6/7] lavfi/metal: fix build on pre-10.15 SDKs rcombs
2021-12-22 0:07 ` [FFmpeg-devel] [PATCH 7/7] lavfi/metal: fix build with pre-10.11 deployment targets rcombs
2021-12-22 1:20 ` Aman Karmani
2022-01-27 18:32 ` Alex
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git