History

avfilter/vf_libplacebo: list AV_PIX_FMT_VULKAN first

Under normal circumstances, this change does not affect anything, as the vast majority of filters either support only vulkan or only software formats. However, when a filter supports both (such as vf_libplacebo itself, and possibly vf_scale in the future), linking together two such filter instances without an explicit format will default matching the input format, resulting in a redundant round trip through host RAM. This change bumps up AV_PIX_FMT_VULKAN to the first entry in the format list, ensuring that it gets preferred whenever possible.

Niklas Haas committed 1 year ago

Commit f883b7c1 parent 88ac6961 file · +11 −12Browse files

Unified · Split

libavfilter/vf_libplacebo.c+11−12
@@ -1168,8 +1168,17 @@ static int libplacebo_query_format(const AVFilterContext *ctx, · 1167 unmodified lines
11681168 const AVPixFmtDescriptor *desc = NULL;
11691169 AVFilterFormats *infmts = NULL, *outfmts = NULL;
11701170
1171+ /* List AV_PIX_FMT_VULKAN first to prefer it when possible */
1172+ if (s->have_hwdevice) {
1173+ RET(ff_add_format(&infmts, AV_PIX_FMT_VULKAN));
1174+ if (s->out_format == AV_PIX_FMT_NONE || av_vkfmt_from_pixfmt(s->out_format))
1175+ RET(ff_add_format(&outfmts, AV_PIX_FMT_VULKAN));
1176+ }
1177+
11711178 while ((desc = av_pix_fmt_desc_next(desc))) {
11721179 enum AVPixelFormat pixfmt = av_pix_fmt_desc_get_id(desc);
1180+ if (pixfmt == AV_PIX_FMT_VULKAN)
1181+ continue; /* Handled above */
11731182
11741183 #if PL_API_VER < 232
11751184 // Older libplacebo can't handle >64-bit pixel formats, so safe-guard
@@ -1178,9 +1187,6 @@ static int libplacebo_query_format(const AVFilterContext *ctx, · 2 unmodified lines
11781187 continue;
11791188 #endif
11801189
1181− if (pixfmt == AV_PIX_FMT_VULKAN && !s->have_hwdevice)
1182− continue;
1183−
11841190 if (!pl_test_pixfmt(s->gpu, pixfmt))
11851191 continue;
11861192
@@ -1191,15 +1197,8 @@ static int libplacebo_query_format(const AVFilterContext *ctx, · 4 unmodified lines
11911197 continue; /* BE formats are not supported by pl_download_avframe */
11921198
11931199 /* Mask based on user specified format */
1194− if (s->out_format != AV_PIX_FMT_NONE) {
1195− if (pixfmt == AV_PIX_FMT_VULKAN && av_vkfmt_from_pixfmt(s->out_format)) {
1196− /* OK */
1197− } else if (pixfmt == s->out_format) {
1198− /* OK */
1199− } else {
1200− continue; /* Not OK */
1201− }
1202− }
1200+ if (pixfmt != s->out_format && s->out_format != AV_PIX_FMT_NONE)
1201+ continue;
12031202
12041203 #if PL_API_VER >= 293
12051204 if (!pl_test_pixfmt_caps(s->gpu, pixfmt, PL_FMT_CAP_RENDERABLE))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t