swscale/ops_chain: add optional check() call to SwsOpEntry

Allows implementations to implement more advanced logic to determine if an
operation is compatible or not.

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Niklas Haas <git@haasn.dev>
This commit is contained in:
Niklas Haas
2026-03-13 14:02:18 +01:00
parent 7b6170a9a5
commit 4ff32b6e86
2 changed files with 16 additions and 11 deletions

View File

@@ -212,34 +212,38 @@ int ff_sws_op_compile_tables(SwsContext *ctx, const SwsOpTable *const tables[],
const SwsOp *op = &ops->ops[0];
int ret, best_score = 0;
SwsImplParams params = {
.ctx = ctx,
.op = op
};
for (int n = 0; n < num_tables; n++) {
const SwsOpTable *table = tables[n];
if (table->block_size && table->block_size != block_size ||
table->cpu_flags & ~cpu_flags)
continue;
params.table = table;
for (int i = 0; table->entries[i]; i++) {
const SwsOpEntry *entry = table->entries[i];
int score = op_match(op, entry, next->comps);
if (score > best_score) {
best_score = score;
best_table = table;
best = entry;
}
if (score <= best_score)
continue;
if (entry->check && !entry->check(&params))
continue;
best_score = score;
best_table = table;
best = entry;
}
}
if (!best)
return AVERROR(ENOTSUP);
params.table = best_table;
SwsImplResult res = {0};
if (best->setup) {
const SwsImplParams params = {
.ctx = ctx,
.op = op,
.table = best_table,
};
ret = best->setup(&params, &res);
if (ret < 0)
return ret;

View File

@@ -137,6 +137,7 @@ typedef struct SwsOpEntry {
/* Kernel implementation */
SwsFuncPtr func;
int (*setup)(const SwsImplParams *params, SwsImplResult *out); /* optional */
bool (*check)(const SwsImplParams *params); /* optional, return true if supported */
} SwsOpEntry;
/* Setup helpers */