swscale/ops: simplify SwsOpList.order_src/dst

Just define these directly as integer arrays; there's really no point in
having them re-use SwsSwizzleOp; the only place this was ever even remotely
relevant was in the no-op check, which any decent compiler should already
be capable of optimizing into a single 32-bit comparison.

Signed-off-by: Niklas Haas <git@haasn.dev>
This commit is contained in:
Niklas Haas
2026-03-28 14:57:40 +01:00
committed by Niklas Haas
parent d33403ba50
commit c0cc7f341a
5 changed files with 36 additions and 26 deletions

View File

@@ -323,7 +323,7 @@ void ff_sws_op_list_update_comps(SwsOpList *ops)
/* Active components are taken from the user-provided values,
* other components are explicitly stripped */
for (int i = 0; i < op->rw.elems; i++) {
const int idx = op->rw.packed ? i : ops->order_src.in[i];
const int idx = op->rw.packed ? i : ops->plane_src[i];
op->comps.flags[i] = ops->comps_src.flags[idx];
op->comps.min[i] = ops->comps_src.min[idx];
op->comps.max[i] = ops->comps_src.max[idx];
@@ -566,7 +566,8 @@ SwsOpList *ff_sws_op_list_alloc(void)
if (!ops)
return NULL;
ops->order_src = ops->order_dst = SWS_SWIZZLE(0, 1, 2, 3);
for (int i = 0; i < 4; i++)
ops->plane_src[i] = ops->plane_dst[i] = i;
ff_fmt_clear(&ops->src);
ff_fmt_clear(&ops->dst);
return ops;
@@ -693,7 +694,7 @@ bool ff_sws_op_list_is_noop(const SwsOpList *ops)
*/
const int num_planes = read->rw.packed ? 1 : read->rw.elems;
for (int i = 0; i < num_planes; i++) {
if (ops->order_src.in[i] != ops->order_dst.in[i])
if (ops->plane_src[i] != ops->plane_dst[i])
return false;
}
@@ -899,6 +900,20 @@ void ff_sws_op_desc(AVBPrint *bp, const SwsOp *op, const bool unused[4])
}
}
static void desc_plane_order(AVBPrint *bp, int nb_planes, const uint8_t *order)
{
bool inorder = true;
for (int i = 0; i < nb_planes; i++)
inorder &= order[i] == i;
if (inorder)
return;
av_bprintf(bp, ", via {");
for (int i = 0; i < nb_planes; i++)
av_bprintf(bp, "%s%d", i ? ", " : "", order[i]);
av_bprintf(bp, "}");
}
void ff_sws_op_list_print(void *log, int lev, int lev_extra,
const SwsOpList *ops)
{
@@ -928,14 +943,9 @@ void ff_sws_op_list_print(void *log, int lev, int lev_extra,
ff_sws_op_desc(&bp, op, next->comps.unused);
if (op->op == SWS_OP_READ || op->op == SWS_OP_WRITE) {
SwsSwizzleOp order = op->op == SWS_OP_READ ? ops->order_src : ops->order_dst;
if (order.mask != SWS_SWIZZLE(0, 1, 2, 3).mask) {
const int planes = op->rw.packed ? 1 : op->rw.elems;
av_bprintf(&bp, ", via {");
for (int i = 0; i < planes; i++)
av_bprintf(&bp, "%s%d", i ? ", " : "", order.in[i]);
av_bprintf(&bp, "}");
}
const int planes = op->rw.packed ? 1 : op->rw.elems;
desc_plane_order(&bp, planes,
op->op == SWS_OP_READ ? ops->plane_src : ops->plane_dst);
}
av_assert0(av_bprint_is_complete(&bp));

View File

@@ -255,13 +255,13 @@ typedef struct SwsOpList {
/* Metadata associated with this operation list */
SwsFormat src, dst;
/* Input/output plane pointer swizzle mask */
SwsSwizzleOp order_src, order_dst;
/* Input/output plane indices */
uint8_t plane_src[4], plane_dst[4];
/**
* Source component metadata associated with pixel values from each
* corresponding component (in plane/memory order, i.e. not affected by
* `order_src`). Lets the optimizer know additional information about
* `plane_src`). Lets the optimizer know additional information about
* the value range and/or pixel data to expect.
*
* The default value of {0} is safe to pass in the case that no additional

View File

@@ -418,8 +418,8 @@ static int compile(SwsGraph *graph, const SwsOpList *ops, SwsPass *input,
};
for (int i = 0; i < 4; i++) {
p->idx_in[i] = i < p->planes_in ? ops->order_src.in[i] : -1;
p->idx_out[i] = i < p->planes_out ? ops->order_dst.in[i] : -1;
p->idx_in[i] = i < p->planes_in ? ops->plane_src[i] : -1;
p->idx_out[i] = i < p->planes_out ? ops->plane_dst[i] : -1;
}
const SwsFilterWeights *filter = read->rw.kernel;

View File

@@ -385,7 +385,7 @@ retry:
const int idx = nb_planes++;
av_assert1(idx <= i);
ops->order_src.in[idx] = ops->order_src.in[i];
ops->plane_src[idx] = ops->plane_src[i];
swiz.in[i] = idx;
}
@@ -501,7 +501,7 @@ retry:
for (int dst = 0; dst < prev->rw.elems; dst++) {
const int src = op->swizzle.in[dst];
if (src > dst && src < prev->rw.elems) {
FFSWAP(int, ops->order_src.in[dst], ops->order_src.in[src]);
FFSWAP(int, ops->plane_src[dst], ops->plane_src[src]);
for (int i = dst; i < 4; i++) {
if (op->swizzle.in[i] == dst)
op->swizzle.in[i] = src;
@@ -517,7 +517,7 @@ retry:
for (int dst = 0; dst < next->rw.elems; dst++) {
const int src = op->swizzle.in[dst];
if (src > dst && src < next->rw.elems) {
FFSWAP(int, ops->order_dst.in[dst], ops->order_dst.in[src]);
FFSWAP(int, ops->plane_dst[dst], ops->plane_dst[src]);
FFSWAP(int, op->swizzle.in[dst], op->swizzle.in[src]);
goto retry;
}
@@ -963,15 +963,15 @@ int ff_sws_op_list_subpass(SwsOpList *ops1, SwsOpList **out_rest)
/* Determine metadata for the intermediate format */
const SwsPixelType type = op->type;
ops2->order_src = SWS_SWIZZLE(0, 1, 2, 3);
ops2->comps_src = prev->comps;
ops2->src.format = get_planar_fmt(type, nb_planes);
ops2->src.desc = av_pix_fmt_desc_get(ops2->src.format);
get_input_size(ops1, &ops2->src);
ops1->order_dst = SWS_SWIZZLE(0, 1, 2, 3);
ops1->dst = ops2->src;
for (int i = 0; i < nb_planes; i++)
ops1->plane_dst[i] = ops2->plane_src[i] = i;
ff_sws_op_list_remove_at(ops1, idx, ops1->num_ops - idx);
ff_sws_op_list_remove_at(ops2, 0, idx);
op = NULL; /* the above command may invalidate op */

View File

@@ -245,11 +245,11 @@ static int add_ops_glsl(VulkanPriv *p, FFVulkanOpsCtx *s,
return AVERROR(ENOTSUP);
} else if (op->rw.packed) {
GLSLF(1, %s = %s(imageLoad(src_img[%i], pos)); ,
type_name, type_v, ops->order_src.in[0]);
type_name, type_v, ops->plane_src[0]);
} else {
for (int i = 0; i < op->rw.elems; i++)
GLSLF(1, %s.%c = %s(imageLoad(src_img[%i], pos)[0]); ,
type_name, "xyzw"[i], type_s, ops->order_src.in[i]);
type_name, "xyzw"[i], type_s, ops->plane_src[i]);
}
break;
}
@@ -258,11 +258,11 @@ static int add_ops_glsl(VulkanPriv *p, FFVulkanOpsCtx *s,
return AVERROR(ENOTSUP);
} else if (op->rw.packed) {
GLSLF(1, imageStore(dst_img[%i], pos, %s(%s)); ,
ops->order_dst.in[0], type_v, type_name);
ops->plane_dst[0], type_v, type_name);
} else {
for (int i = 0; i < op->rw.elems; i++)
GLSLF(1, imageStore(dst_img[%i], pos, %s(%s[%i])); ,
ops->order_dst.in[i], type_v, type_name, i);
ops->plane_dst[i], type_v, type_name, i);
}
break;
}