Commit 1d33874a82 for ffmpeg
commit 1d33874a8275c11d248b918cfdf1bac0c0c3506a
Author: Niklas Haas <git@haasn.dev>
Date: Sat Nov 7 14:51:48 2026 +0100
swscale/ops: only skip over consumed data in SwsOpImpl
This commit turns on the mechanism built up by the previous commits. This
allows ops to have dynamically sized priv data.
Signed-off-by: Niklas Haas <git@haasn.dev>
diff --git a/libswscale/aarch64/ops.c b/libswscale/aarch64/ops.c
index 46970f7bf5..4d1e8b3345 100644
--- a/libswscale/aarch64/ops.c
+++ b/libswscale/aarch64/ops.c
@@ -193,7 +193,7 @@ static int compile_uops_aarch64(SwsContext *ctx, const SwsUOpList *uops,
if (ret < 0)
goto error;
av_assert1(res.priv_size == aarch64_priv_size(¶ms));
- ret = ff_sws_op_chain_append(chain, func, res.ref, &res.priv, sizeof(res.priv));
+ ret = ff_sws_op_chain_append(chain, func, res.ref, &res.priv, res.priv_size);
av_refstruct_unref(&res.ref);
if (ret < 0)
goto error;
diff --git a/libswscale/aarch64/ops_static.c b/libswscale/aarch64/ops_static.c
index f090e4e099..d3fda52c66 100644
--- a/libswscale/aarch64/ops_static.c
+++ b/libswscale/aarch64/ops_static.c
@@ -635,8 +635,9 @@ static void asmgen_op_cps(SwsAArch64Context *s, const SwsAArch64OpEntry *entry)
i_ret(r);
} else {
/* Load continuation address and increment impl pointer. */
+ const size_t priv_size = FFALIGN(aarch64_priv_size(p), alignof_impl);
RasmNode *node = rasm_set_current_node(r, s->load_cont_node);
- RasmOp impl_pre = a64op_pre(s->impl, sizeof_impl);
+ RasmOp impl_pre = a64op_pre(s->impl, offsetof_impl_priv + priv_size);
i_ldr(r, s->cont, impl_pre); CMT("SwsFuncPtr cont = (++impl)->func;");
rasm_set_current_node(r, node);
/* Common end for remaining CPS functions. */
diff --git a/libswscale/ops_chain.c b/libswscale/ops_chain.c
index 62a487fe54..b977c7e69d 100644
--- a/libswscale/ops_chain.c
+++ b/libswscale/ops_chain.c
@@ -127,7 +127,7 @@ int ff_sws_uop_lookup(SwsContext *ctx, const SwsUOpTable *const tables[],
}
ret = ff_sws_op_chain_append(chain, res.func ? res.func : match->func,
- res.ref, &res.priv, sizeof(res.priv));
+ res.ref, &res.priv, res.priv_size);
av_refstruct_unref(&res.ref);
if (ret < 0)
return ret;
diff --git a/libswscale/uops_tmpl.h b/libswscale/uops_tmpl.h
index 42e0442e15..388ed4c311 100644
--- a/libswscale/uops_tmpl.h
+++ b/libswscale/uops_tmpl.h
@@ -117,13 +117,16 @@ static_assert(alignof(SwsFilterPriv) <= alignof(SwsOpPriv),
#define CALL(NAME, ...) fn(NAME)(iter, impl, x, y, z, w, __VA_ARGS__)
+#define NEXT_IMPL(N) \
+ ((const SwsOpImpl *) &impl->priv.data[FFALIGN(N, alignof(SwsOpImpl))])
+
/* Helper macro to call into the next continuation with a given type; N gives
* the size of private data consumed by this op */
#define CONTINUE(N, ...) \
((void (*)(SwsOpIter *, const SwsOpImpl *, \
void *restrict x, void *restrict y, \
- void *restrict z, void *restrict w)) impl[1].func) \
- (iter, &impl[1], __VA_ARGS__)
+ void *restrict z, void *restrict w)) NEXT_IMPL(N)->func) \
+ (iter, NEXT_IMPL(N), __VA_ARGS__)
/* Helper macros for common op setup code */
#define DECL_SETUP(NAME, PARAMS, OUT) \
diff --git a/libswscale/x86/ops_include.asm b/libswscale/x86/ops_include.asm
index dfe24f85bd..c0655581f1 100644
--- a/libswscale/x86/ops_include.asm
+++ b/libswscale/x86/ops_include.asm
@@ -135,8 +135,7 @@ endstruc
struc SwsOpImpl
.func resq 1
- .priv resb 16
- .next resb 0
+ .priv resb 0
endstruc
%define SWS_COMP_NONE 0
@@ -306,14 +305,16 @@ endstruc
;---------------------------------------------------------
; Common macros for linking together different kernels
+%define sizeof_impl (SwsOpImpl.priv + ((PRIV_SIZE + gprsize - 1) & ~(gprsize - 1)))
+
; Load the next operation kernel's address to a register
%macro LOAD_CONT 1 ; reg
- mov %1, [implq + SwsOpImpl.next + SwsOpImpl.func]
+ mov %1, [implq + sizeof_impl + SwsOpImpl.func]
%endmacro
; Tail call into the next operation kernel, given that kernel's address
%macro CONTINUE 1 ; reg
- add implq, SwsOpImpl.next
+ add implq, sizeof_impl
jmp %1
annotate_function_size
%endmacro