diff options
author | Connor Worley <connorbworley@gmail.com> | 2024-02-09 03:26:50 -0800 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2024-02-09 23:47:14 +0200 |
commit | d5aaed9d4c60a1c3508317bf0cbc469eab339932 (patch) | |
tree | 959bac52137b5798199ec00fc8d4c4a2f8c1a478 /libavcodec/dxvenc.c | |
parent | c619d20906d039060efbeaa822daf8e949f3ef24 (diff) | |
download | ffmpeg-d5aaed9d4c60a1c3508317bf0cbc469eab339932.tar.gz |
lavc/dxv: align to 4x4 blocks instead of 16x16
The previous assumption that DXV needs to be aligned to 16x16 was
erroneous. 4x4 works just as well, and FATE decoder tests pass for all
texture formats.
On the encoder side, we should reject input that isn't 4x4 aligned,
like the HAP encoder does, and stop aligning to 16x16. This both solves
the uninitialized reads causing current FATE tests to fail and produces
smaller encoded outputs.
With regard to correctness, I've checked the decoding path by encoding a
real-world sample with git master, and decoding it with
ffmpeg -i dxt1-master.mov -c:v rawvideo -f framecrc -
The results are exactly the same between master and this patch.
On the encoding side, I've encoded a real-world sample with both master
and this patch, and decoded both versions with
ffmpeg -i dxt1-{master,patch}.mov -c:v rawvideo -f framecrc -
Under this patch, results for both inputs are exactly the same.
In other words, the extra padding gained by 16x16 alignment over 4x4
alignment has no impact on decoded video.
Signed-off-by: Connor Worley <connorbworley@gmail.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavcodec/dxvenc.c')
-rw-r--r-- | libavcodec/dxvenc.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c index b274175689..33a18d53d8 100644 --- a/libavcodec/dxvenc.c +++ b/libavcodec/dxvenc.c @@ -275,6 +275,14 @@ static av_cold int dxv_init(AVCodecContext *avctx) return ret; } + if (avctx->width % TEXTURE_BLOCK_W || avctx->height % TEXTURE_BLOCK_H) { + av_log(avctx, + AV_LOG_ERROR, + "Video size %dx%d is not multiple of "AV_STRINGIFY(TEXTURE_BLOCK_W)"x"AV_STRINGIFY(TEXTURE_BLOCK_H)".\n", + avctx->width, avctx->height); + return AVERROR_INVALIDDATA; + } + ff_texturedspenc_init(&texdsp); switch (ctx->tex_fmt) { @@ -288,10 +296,10 @@ static av_cold int dxv_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } ctx->enc.raw_ratio = 16; - ctx->tex_size = FFALIGN(avctx->width, 16) / TEXTURE_BLOCK_W * - FFALIGN(avctx->height, 16) / TEXTURE_BLOCK_H * + ctx->tex_size = avctx->width / TEXTURE_BLOCK_W * + avctx->height / TEXTURE_BLOCK_H * ctx->enc.tex_ratio; - ctx->enc.slice_count = av_clip(avctx->thread_count, 1, FFALIGN(avctx->height, 16) / TEXTURE_BLOCK_H); + ctx->enc.slice_count = av_clip(avctx->thread_count, 1, avctx->height / TEXTURE_BLOCK_H); ctx->tex_data = av_malloc(ctx->tex_size); if (!ctx->tex_data) { |