From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id E13D0493CB for ; Fri, 9 Feb 2024 11:35:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D6F7E68D13A; Fri, 9 Feb 2024 13:35:15 +0200 (EET) Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 46AEF68CC0A for ; Fri, 9 Feb 2024 13:35:09 +0200 (EET) Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1d93edfa76dso6816895ad.1 for ; Fri, 09 Feb 2024 03:35:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707478506; x=1708083306; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1hdwlpmK9LupEE5xhVJXz8xlx9pA0QoSr9LkLSB+OQs=; b=fBtyhl6aa+yFHOlY0E5BhGIsdAgctxX4Jgdg7tL1ibnBNZFREwvDKDEz2KTZWTJ1xA ltozMtZ3IIlEZ4sh2eo3DAK5dvip6AcsoxiubJ7YLnDnrih4po7vuKP81nVkI6p1220F 3T9kxYEdlPfzsldwWKtoHxf7Tm0YlVqFCtSVhxbzlpqrPPQvl1XCBmV88uMbPntaK/KR nY5UscDIZ1kuZR1fDg+Yiay4zR0XHvKL4Nk83z4GRd9VuK0mDAoSeGxpELVh4P5J0lk5 Xcx4C7FEzD+/CmGOfm0efEoOM3Ums4Eh+uXLxpzUT/FrjzIUw8kQhUsZwo7XU+p3XP9R vNdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707478506; x=1708083306; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1hdwlpmK9LupEE5xhVJXz8xlx9pA0QoSr9LkLSB+OQs=; b=PcRKDFFhbRQrbWQKWiJ7WsH5cK4UTiT9NQRDo/L0YwtKk3v0tSNWqNwFuBZvYupm3R 7hK4Dpht+ZDk5zeblMzNAe8qmZVlk4zZkjllWRhZPSdWhycCerGn33WRTlWznsaz4SFM +7snkKPjP8cOAve6DS+JeMvrhlMP8kMjHDsZ+Eox2vAb+NPnaJLidBa9VaHz1wd6v7go FcTQAmEbtja8HrFw7PyGiInESiMvgmg6gYZi49ckKBw17NYmqn+nGWq6yK4Q2QVWiRA/ R+kiB+7uJqY7EHEF8k7FhpW5lZweYWlwrhFNn5w8uFfTc8YhH2Fdo5IyXkUlzf423QKM ycAg== X-Gm-Message-State: AOJu0Yy4+Zwx37bv2Dn77MeOX5sSfCBUcgmd62W84wT38z5LrY/fR6hO oAwyxDlO7oH5cAFmidLz7JiJU894a7uyCxNiVSl8gAfrV88BECjSClqsQH68hLI= X-Google-Smtp-Source: AGHT+IE7nzHfFLi18LbE1V6uo0riT6oNjtb+OwtLrMPQNni7bmw8hliqonNN34HBEnwlwQD7fBjoIw== X-Received: by 2002:a17:90a:854c:b0:293:f16d:e53f with SMTP id a12-20020a17090a854c00b00293f16de53fmr1320300pjw.0.1707478506478; Fri, 09 Feb 2024 03:35:06 -0800 (PST) Received: from localhost ([2601:647:4600:84e0:24b5:a909:c5a1:ea01]) by smtp.gmail.com with UTF8SMTPSA id iq6-20020a17090afb4600b0029619c8fa15sm1532756pjb.27.2024.02.09.03.35.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 03:35:05 -0800 (PST) From: Connor Worley To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Feb 2024 03:26:50 -0800 Message-Id: <20240209112649.16556-1-connorbworley@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] lavc/dxv: align to 4x4 blocks instead of 16x16 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Connor Worley Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 --- libavcodec/dxv.c | 6 +++--- libavcodec/dxvenc.c | 14 +++++++++++--- tests/ref/fate/dxv3enc-dxt1 | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index e1c7cee3e8..9261a5cac1 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -1238,9 +1238,9 @@ static int dxv_init(AVCodecContext *avctx) return ret; } - /* Codec requires 16x16 alignment. */ - avctx->coded_width = FFALIGN(avctx->width, 16); - avctx->coded_height = FFALIGN(avctx->height, 16); + /* Since codec is based on 4x4 blocks, size is aligned to 4 */ + avctx->coded_width = FFALIGN(avctx->width, TEXTURE_BLOCK_W); + avctx->coded_height = FFALIGN(avctx->height, TEXTURE_BLOCK_H); ff_texturedsp_init(&ctx->texdsp); 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) { diff --git a/tests/ref/fate/dxv3enc-dxt1 b/tests/ref/fate/dxv3enc-dxt1 index 3cfd73397e..74849a8031 100644 --- a/tests/ref/fate/dxv3enc-dxt1 +++ b/tests/ref/fate/dxv3enc-dxt1 @@ -3,4 +3,4 @@ #codec_id 0: dxv #dimensions 0: 1920x1080 #sar 0: 1/1 -0, 0, 0, 1, 76767, 0x932ecbfa +0, 0, 0, 1, 76521, 0xed387a5e -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".