From patchwork Thu Feb 15 05:44:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Connor Worley X-Patchwork-Id: 46294 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:b819:b0:19e:cdac:8cce with SMTP id fi25csp390518pzb; Wed, 14 Feb 2024 21:44:57 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWULcPUZd5EluEama/WX+5CNTVUzH6+vQayCzZF82LmBTYY18qsriIEVb/txT/0oSzS9PMs7B8BFuErxw/6Skl6k7OV8swxbDRfig== X-Google-Smtp-Source: AGHT+IHYDSr9s7GQt5wWNmMRG7zBIJ7bMKBNfUUZA2tUHWXpusT1hupPm58mtWwfuGZ8wRn8Lrtz X-Received: by 2002:a50:cd07:0:b0:561:347f:ef40 with SMTP id z7-20020a50cd07000000b00561347fef40mr611500edi.2.1707975897718; Wed, 14 Feb 2024 21:44:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707975897; cv=none; d=google.com; s=arc-20160816; b=OtmGV8edU/zOQSxWuAd4dZXb7N4qx04JQCbmVwubqrQmuSjWARtyDUPzcB/w0jRkY5 cnm+CLyBsyJPc0+esOOHh4fUR8F/xrBaZgkxPd0FPTJUtAmSDqPYzGQZrARGmS5hluRQ bL/DyBCIVZDi8YjfG9xFafBPatUBzM4izAF+jpKS4+4sE+kZ5a81Eq5w/DZIfO5gTxni jA3+Pao/XVDffRRJ1T8eFO0xiY/iVlH9o/7MdUZ1MUwzFQrZmqoTaT4y9AFIUA1CYZxd T6EJ3dBTEccKvFIjW6GXYJp3mgTzPTNv0S+wdin/xmtmtm9B2H9kDZtWI9PHdF79iHH+ g0qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=Cr5kB/CJrZI49zE/GNYYAaltvuwC3CEUQIlVKCNJeAY=; fh=4o9WedBEbOrq7GvNs0s+TOKeyzmDZRM3O7oe6ZP6vYM=; b=za/Urk8VD5ZH2SFgY8KRU/opykDjEMidYGcY8sgEP0dQ+LFwq5ZoXP7TtsD/tVL4wW O8IP35KUUlR4AGGc9THGTy/k9CMVFnZWxGgksjrwsTuJGZGMvUMLHdUsCRd8f+oPyKAj TAm8VhqvIIx7g29tg4K/unJ6hZhBE7eWtW1VHzLJlH7PiNOdMRH4+icEfvumiV7rAWqi gAowD1GH1jPMz1THSJjR/r+V+2v47+bAyjvD2crSjvMJd26ii2xE07qQGjmarnK71XNl Gti8fNlMj/lAOe9ywIArNuPIMVeDFxy8GzebPja8WsGK1ow/n0FGZpGFvpRYrVWg2/E8 zRLA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=bUQzv5o5; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s17-20020a056402521100b0056389d2d63bsi343177edd.30.2024.02.14.21.44.56; Wed, 14 Feb 2024 21:44:57 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=bUQzv5o5; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C849F68CCA0; Thu, 15 Feb 2024 07:44:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D782868D20C for ; Thu, 15 Feb 2024 07:44:46 +0200 (EET) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e09ea155c5so411740b3a.2 for ; Wed, 14 Feb 2024 21:44:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707975884; x=1708580684; 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=8OGbjRN9eJNcOI05MTA7b2PwZ9p+wLobGhrFx0yNMIs=; b=bUQzv5o5KV9DgmFhFIx+sd+d5yQVz+A8tMJ9FBmQE+YXaDjPJQOGZ2sVUSErukxnb2 xzsOEWP97xwtPoMslSkS46ELDhQpPuN5mwGPqkIJMtQWxhzhGkkww/Gy8UTT/5nr1TB5 glLj5SiCPieu9qihlt4CJinNNxGhNXCBf5t36oASsIJvlpKruXoCGQJoM1kchlXYCMlG nrKeDHTHtXBcHMEarc8Ewi3dRpj7TVu4C1Sqp4GzzO820gXnv+fx1HbMVyneSQRoD/th ukIgSvzTylB7d1i0SZBjxt0a/pz0GPW8VKQkLSvAfuBmLv9jeh95MMjsnzygX4NBZDnW 2mug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707975884; x=1708580684; 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=8OGbjRN9eJNcOI05MTA7b2PwZ9p+wLobGhrFx0yNMIs=; b=vl7VmN1fbhojh7AiZEYN3fdzSzlN+PWyfNHAU6vFS/f+roBW63ZNoc5gYJcuP6KXO0 9+YSAW8GJqG/4p+KFOttAEmnDvSFJLOz44CFN/Ce/cgjm71Kx7inQ8Dd3kPgsyROHMTA g4bj//ofBJX9iL4gz1JqKX2lIrtlJ7krLFJGG0h3htecWKVTmlJBCDc/QbJ3MvRFvXZr Hp6AUgZ+IvtGFak3sK6FQzGLYpbtQlswRcTv+OlekrljV4GNaQatQMZOSx1liZ4dd/er 5t/a81+UylBdCGWnO+GwaPjrB7HYYMPac2cRIVC5d2AgqClFIrHKcyAOiQmgL8KnASCw iAUQ== X-Gm-Message-State: AOJu0YyVsVJsR/EL1BV37L5Ltss7Wl+h+EAsKRzHA+t8B6B9yUqlwwdX JBOj5PQ+PsJMb0Z6MUVtTmxBv2sbdzxotnQeTyZbdP0k6BlcK/JLqT6mEOpjrtU= X-Received: by 2002:a05:6a00:9294:b0:6e0:fe48:7ac0 with SMTP id jw20-20020a056a00929400b006e0fe487ac0mr1034055pfb.23.1707975884161; Wed, 14 Feb 2024 21:44:44 -0800 (PST) Received: from localhost ([2601:647:4600:84e0:8bf:933e:340c:2dec]) by smtp.gmail.com with UTF8SMTPSA id p17-20020a62b811000000b006e10e9b2c4asm432934pfe.7.2024.02.14.21.44.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Feb 2024 21:44:43 -0800 (PST) From: Connor Worley To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Feb 2024 21:44:38 -0800 Message-ID: <20240215054438.32491-1-connorbworley@gmail.com> X-Mailer: git-send-email 2.43.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] lavc/texturedsp: require explicitly-set frame dimensions 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: OkqZx9BWpFeA This change decouples the frame dimensions from avctx, which is useful for DXV decoding, and fixes incorrect behavior in the existing implementation. Tested with `make fate THREADS=7` and `make fate THREADS=7 THREAD_TYPE=slice`. Signed-off-by: Connor Worley --- libavcodec/dds.c | 2 ++ libavcodec/dxv.c | 19 ++++++++++--------- libavcodec/dxvenc.c | 2 ++ libavcodec/hapdec.c | 2 ++ libavcodec/hapenc.c | 2 ++ libavcodec/texturedsp.h | 1 + libavcodec/texturedsp_template.c | 4 ++-- libavcodec/vbndec.c | 2 ++ libavcodec/vbnenc.c | 2 ++ 9 files changed, 25 insertions(+), 11 deletions(-) diff --git a/libavcodec/dds.c b/libavcodec/dds.c index 67e2325a2a..89cf225f25 100644 --- a/libavcodec/dds.c +++ b/libavcodec/dds.c @@ -636,6 +636,8 @@ static int dds_decode(AVCodecContext *avctx, AVFrame *frame, ctx->dec.tex_data.in = gbc->buffer; ctx->dec.frame_data.out = frame->data[0]; ctx->dec.stride = frame->linesize[0]; + ctx->dec.width = avctx->coded_width; + ctx->dec.height = avctx->coded_height; ff_texturedsp_exec_decompress_threads(avctx, &ctx->dec); } else if (!ctx->paletted && ctx->bpp == 4 && avctx->pix_fmt == AV_PIX_FMT_PAL8) { uint8_t *dst = frame->data[0]; diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c index 2eca14c129..b5553a0c86 100644 --- a/libavcodec/dxv.c +++ b/libavcodec/dxv.c @@ -843,7 +843,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, { DXVContext *ctx = avctx->priv_data; GetByteContext *gbc = &ctx->gbc; - AVCodecContext cavctx = *avctx; TextureDSPThreadContext texdsp_ctx, ctexdsp_ctx; int (*decompress_tex)(AVCodecContext *avctx); const char *msgcomp, *msgtext; @@ -854,9 +853,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, bytestream2_init(gbc, avpkt->data, avpkt->size); - cavctx.coded_height = avctx->coded_height / 2; - cavctx.coded_width = avctx->coded_width / 2; - avctx->pix_fmt = AV_PIX_FMT_RGBA; avctx->colorspace = AVCOL_SPC_RGB; @@ -943,7 +939,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, texdsp_ctx.slice_count = av_clip(avctx->thread_count, 1, avctx->coded_height / TEXTURE_BLOCK_H); ctexdsp_ctx.slice_count = av_clip(avctx->thread_count, 1, - cavctx.coded_height / TEXTURE_BLOCK_H); + avctx->coded_height / 2 / TEXTURE_BLOCK_H); + /* New header is 12 bytes long. */ if (!old_type) { version_major = bytestream2_get_byte(gbc) - 1; @@ -979,8 +976,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, if (avctx->pix_fmt != AV_PIX_FMT_RGBA) { int i; - ctx->ctex_size = cavctx.coded_width / ctexdsp_ctx.raw_ratio * - cavctx.coded_height / TEXTURE_BLOCK_H * + ctx->ctex_size = avctx->coded_width / 2 / ctexdsp_ctx.raw_ratio * + avctx->coded_height / 2 / TEXTURE_BLOCK_H * ctexdsp_ctx.tex_ratio; ctx->op_size[0] = avctx->coded_width * avctx->coded_height / 16; @@ -1007,6 +1004,10 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, if (ret < 0) return ret; + texdsp_ctx.width = avctx->coded_width; + texdsp_ctx.height = avctx->coded_height; + ctexdsp_ctx.width = avctx->coded_width / 2; + ctexdsp_ctx.height = avctx->coded_height / 2; switch (tag) { case DXV_FMT_YG10: /* BC5 texture with alpha in the second half of each block */ @@ -1022,13 +1023,13 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, ctexdsp_ctx.tex_data.in = ctx->ctex_data; ctexdsp_ctx.frame_data.out = frame->data[2]; ctexdsp_ctx.stride = frame->linesize[2]; - ret = ff_texturedsp_exec_decompress_threads(&cavctx, &ctexdsp_ctx); + ret = ff_texturedsp_exec_decompress_threads(avctx, &ctexdsp_ctx); if (ret < 0) return ret; ctexdsp_ctx.tex_data.in = ctx->ctex_data + ctexdsp_ctx.tex_ratio / 2; ctexdsp_ctx.frame_data.out = frame->data[1]; ctexdsp_ctx.stride = frame->linesize[1]; - ret = ff_texturedsp_exec_decompress_threads(&cavctx, &ctexdsp_ctx); + ret = ff_texturedsp_exec_decompress_threads(avctx, &ctexdsp_ctx); if (ret < 0) return ret; /* fallthrough */ diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c index bb2c2f8526..85cbca2be8 100644 --- a/libavcodec/dxvenc.c +++ b/libavcodec/dxvenc.c @@ -233,6 +233,8 @@ static int dxv_encode(AVCodecContext *avctx, AVPacket *pkt, ctx->enc.tex_data.out = ctx->tex_data; ctx->enc.frame_data.in = frame->data[0]; ctx->enc.stride = frame->linesize[0]; + ctx->enc.width = avctx->width; + ctx->enc.height = avctx->height; ff_texturedsp_exec_compress_threads(avctx, &ctx->enc); } else { /* unimplemented: YCoCg formats */ diff --git a/libavcodec/hapdec.c b/libavcodec/hapdec.c index 3a848e9f67..6066cb814c 100644 --- a/libavcodec/hapdec.c +++ b/libavcodec/hapdec.c @@ -323,6 +323,8 @@ static int hap_decode(AVCodecContext *avctx, AVFrame *frame, ctx->dec[t].frame_data.out = frame->data[0]; ctx->dec[t].stride = frame->linesize[0]; + ctx->dec[t].width = avctx->coded_width; + ctx->dec[t].height = avctx->coded_height; ff_texturedsp_exec_decompress_threads(avctx, &ctx->dec[t]); } diff --git a/libavcodec/hapenc.c b/libavcodec/hapenc.c index 1464f743d6..e03cf36085 100644 --- a/libavcodec/hapenc.c +++ b/libavcodec/hapenc.c @@ -63,6 +63,8 @@ static int compress_texture(AVCodecContext *avctx, uint8_t *out, int out_length, ctx->enc.tex_data.out = out; ctx->enc.frame_data.in = f->data[0]; ctx->enc.stride = f->linesize[0]; + ctx->enc.width = avctx->width; + ctx->enc.height = avctx->height; ff_texturedsp_exec_compress_threads(avctx, &ctx->enc); return 0; diff --git a/libavcodec/texturedsp.h b/libavcodec/texturedsp.h index 86c8eea02d..0bf49e8729 100644 --- a/libavcodec/texturedsp.h +++ b/libavcodec/texturedsp.h @@ -72,6 +72,7 @@ typedef struct TextureDSPThreadContext { uint8_t *out; // Output frame data } frame_data; ptrdiff_t stride; // Frame linesize + int width, height; // Frame width / height union { const uint8_t *in; // Compressed texture for decompression uint8_t *out; // Compressed texture of compression diff --git a/libavcodec/texturedsp_template.c b/libavcodec/texturedsp_template.c index 9589cc4187..b9caf494cc 100644 --- a/libavcodec/texturedsp_template.c +++ b/libavcodec/texturedsp_template.c @@ -27,8 +27,8 @@ static int exec_func(AVCodecContext *avctx, void *arg, { const TextureDSPThreadContext *ctx = arg; uint8_t *d = ctx->tex_data.out; - int w_block = avctx->coded_width / TEXTURE_BLOCK_W; - int h_block = avctx->coded_height / TEXTURE_BLOCK_H; + int w_block = ctx->width / TEXTURE_BLOCK_W; + int h_block = ctx->height / TEXTURE_BLOCK_H; int x, y; int start_slice, end_slice; int base_blocks_per_slice = h_block / ctx->slice_count; diff --git a/libavcodec/vbndec.c b/libavcodec/vbndec.c index 83ce9e994b..68b2236124 100644 --- a/libavcodec/vbndec.c +++ b/libavcodec/vbndec.c @@ -162,6 +162,8 @@ static int vbn_decode_frame(AVCodecContext *avctx, ctx->dec.raw_ratio = 16; ctx->dec.frame_data.out = frame->data[0] + frame->linesize[0] * (frame->height - 1); ctx->dec.stride = -frame->linesize[0]; + ctx->dec.width = avctx->coded_width; + ctx->dec.height = avctx->coded_height; ff_texturedsp_exec_decompress_threads(avctx, &ctx->dec); } diff --git a/libavcodec/vbnenc.c b/libavcodec/vbnenc.c index abdc33c2c9..12cd3a90ca 100644 --- a/libavcodec/vbnenc.c +++ b/libavcodec/vbnenc.c @@ -114,6 +114,8 @@ static int vbn_encode(AVCodecContext *avctx, AVPacket *pkt, ctx->enc.frame_data.in = (frame->height - 1) * frame->linesize[0] + frame->data[0]; ctx->enc.stride = -frame->linesize[0]; ctx->enc.tex_data.out = pkt->data + VBN_HEADER_SIZE; + ctx->enc.width = avctx->width; + ctx->enc.height = avctx->height; ff_texturedsp_exec_compress_threads(avctx, &ctx->enc); } else { const uint8_t *flipped = frame->data[0] + frame->linesize[0] * (frame->height - 1);