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.
Unified · Split
| @@ -1168,8 +1168,17 @@ static int libplacebo_query_format(const AVFilterContext *ctx, · 1167 unmodified lines | |||
| 1168 | const AVPixFmtDescriptor *desc = NULL; | 1168 | const AVPixFmtDescriptor *desc = NULL; |
| 1169 | AVFilterFormats *infmts = NULL, *outfmts = NULL; | 1169 | AVFilterFormats *infmts = NULL, *outfmts = NULL; |
| 1170 | 1170 | ||
| 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 | |||
| 1171 | while ((desc = av_pix_fmt_desc_next(desc))) { | 1178 | while ((desc = av_pix_fmt_desc_next(desc))) { |
| 1172 | enum AVPixelFormat pixfmt = av_pix_fmt_desc_get_id(desc); | 1179 | enum AVPixelFormat pixfmt = av_pix_fmt_desc_get_id(desc); |
| 1180 | if (pixfmt == AV_PIX_FMT_VULKAN) | ||
| 1181 | continue; /* Handled above */ | ||
| 1173 | 1182 | ||
| 1174 | #if PL_API_VER < 232 | 1183 | #if PL_API_VER < 232 |
| 1175 | // Older libplacebo can't handle >64-bit pixel formats, so safe-guard | 1184 | // 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 | |||
| 1178 | continue; | 1187 | continue; |
| 1179 | #endif | 1188 | #endif |
| 1180 | 1189 | ||
| 1181 | if (pixfmt == AV_PIX_FMT_VULKAN && !s->have_hwdevice) | ||
| 1182 | continue; | ||
| 1183 | |||
| 1184 | if (!pl_test_pixfmt(s->gpu, pixfmt)) | 1190 | if (!pl_test_pixfmt(s->gpu, pixfmt)) |
| 1185 | continue; | 1191 | continue; |
| 1186 | 1192 | ||
| @@ -1191,15 +1197,8 @@ static int libplacebo_query_format(const AVFilterContext *ctx, · 4 unmodified lines | |||
| 1191 | continue; /* BE formats are not supported by pl_download_avframe */ | 1197 | continue; /* BE formats are not supported by pl_download_avframe */ |
| 1192 | 1198 | ||
| 1193 | /* Mask based on user specified format */ | 1199 | /* Mask based on user specified format */ |
| 1194 | if (s->out_format != AV_PIX_FMT_NONE) { | 1200 | if (pixfmt != s->out_format && s->out_format != AV_PIX_FMT_NONE) |
| 1195 | if (pixfmt == AV_PIX_FMT_VULKAN && av_vkfmt_from_pixfmt(s->out_format)) { | 1201 | continue; |
| 1196 | /* OK */ | ||
| 1197 | } else if (pixfmt == s->out_format) { | ||
| 1198 | /* OK */ | ||
| 1199 | } else { | ||
| 1200 | continue; /* Not OK */ | ||
| 1201 | } | ||
| 1202 | } | ||
| 1203 | 1202 | ||
| 1204 | #if PL_API_VER >= 293 | 1203 | #if PL_API_VER >= 293 |
| 1205 | if (!pl_test_pixfmt_caps(s->gpu, pixfmt, PL_FMT_CAP_RENDERABLE)) | 1204 | if (!pl_test_pixfmt_caps(s->gpu, pixfmt, PL_FMT_CAP_RENDERABLE)) |