History

lavc/texturedsp: require explicitly-set frame dimensions

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`.

Connor Worley committed 2 years ago

Commit 1487f611 parent 0895ef09 files · +25 −11Browse files

Unified · Split

9 files
  1. libavcodec/dds.c +2 −0
  2. libavcodec/dxv.c +10 −9
  3. libavcodec/dxvenc.c +2 −0
  4. libavcodec/hapdec.c +2 −0
  5. libavcodec/hapenc.c +2 −0
  6. libavcodec/texturedsp.h +1 −0
  7. libavcodec/texturedsp_template.c +2 −2
  8. libavcodec/vbndec.c +2 −0
  9. libavcodec/vbnenc.c +2 −0
libavcodec/dds.c+2−0
@@ -636,6 +636,8 @@ static int dds_decode(AVCodecContext *avctx, AVFrame *frame, · 635 unmodified lines
636636 ctx->dec.tex_data.in = gbc->buffer;
637637 ctx->dec.frame_data.out = frame->data[0];
638638 ctx->dec.stride = frame->linesize[0];
639+ ctx->dec.width = avctx->coded_width;
640+ ctx->dec.height = avctx->coded_height;
639641 ff_texturedsp_exec_decompress_threads(avctx, &ctx->dec);
640642 } else if (!ctx->paletted && ctx->bpp == 4 && avctx->pix_fmt == AV_PIX_FMT_PAL8) {
641643 uint8_t *dst = frame->data[0];
libavcodec/dxv.c+10−9
@@ -843,7 +843,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, · 842 unmodified lines
843843 {
844844 DXVContext *ctx = avctx->priv_data;
845845 GetByteContext *gbc = &ctx->gbc;
846− AVCodecContext cavctx = *avctx;
847846 TextureDSPThreadContext texdsp_ctx, ctexdsp_ctx;
848847 int (*decompress_tex)(AVCodecContext *avctx);
849848 const char *msgcomp, *msgtext;
@@ -854,9 +853,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, · 4 unmodified lines
854853
855854 bytestream2_init(gbc, avpkt->data, avpkt->size);
856855
857− cavctx.coded_height = avctx->coded_height / 2;
858− cavctx.coded_width = avctx->coded_width / 2;
859−
860856 avctx->pix_fmt = AV_PIX_FMT_RGBA;
861857 avctx->colorspace = AVCOL_SPC_RGB;
862858
@@ -943,7 +939,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, · 80 unmodified lines
943939 texdsp_ctx.slice_count = av_clip(avctx->thread_count, 1,
944940 avctx->coded_height / TEXTURE_BLOCK_H);
945941 ctexdsp_ctx.slice_count = av_clip(avctx->thread_count, 1,
946− cavctx.coded_height / TEXTURE_BLOCK_H);
942+ avctx->coded_height / 2 / TEXTURE_BLOCK_H);
943+
947944 /* New header is 12 bytes long. */
948945 if (!old_type) {
949946 version_major = bytestream2_get_byte(gbc) - 1;
@@ -979,8 +976,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, · 29 unmodified lines
979976 if (avctx->pix_fmt != AV_PIX_FMT_RGBA) {
980977 int i;
981978
982− ctx->ctex_size = cavctx.coded_width / ctexdsp_ctx.raw_ratio *
983− cavctx.coded_height / TEXTURE_BLOCK_H *
979+ ctx->ctex_size = avctx->coded_width / 2 / ctexdsp_ctx.raw_ratio *
980+ avctx->coded_height / 2 / TEXTURE_BLOCK_H *
984981 ctexdsp_ctx.tex_ratio;
985982
986983 ctx->op_size[0] = avctx->coded_width * avctx->coded_height / 16;
@@ -1007,6 +1004,10 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, · 20 unmodified lines
10071004 if (ret < 0)
10081005 return ret;
10091006
1007+ texdsp_ctx.width = avctx->coded_width;
1008+ texdsp_ctx.height = avctx->coded_height;
1009+ ctexdsp_ctx.width = avctx->coded_width / 2;
1010+ ctexdsp_ctx.height = avctx->coded_height / 2;
10101011 switch (tag) {
10111012 case DXV_FMT_YG10:
10121013 /* BC5 texture with alpha in the second half of each block */
@@ -1022,13 +1023,13 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame, · 9 unmodified lines
10221023 ctexdsp_ctx.tex_data.in = ctx->ctex_data;
10231024 ctexdsp_ctx.frame_data.out = frame->data[2];
10241025 ctexdsp_ctx.stride = frame->linesize[2];
1025− ret = ff_texturedsp_exec_decompress_threads(&cavctx, &ctexdsp_ctx);
1026+ ret = ff_texturedsp_exec_decompress_threads(avctx, &ctexdsp_ctx);
10261027 if (ret < 0)
10271028 return ret;
10281029 ctexdsp_ctx.tex_data.in = ctx->ctex_data + ctexdsp_ctx.tex_ratio / 2;
10291030 ctexdsp_ctx.frame_data.out = frame->data[1];
10301031 ctexdsp_ctx.stride = frame->linesize[1];
1031− ret = ff_texturedsp_exec_decompress_threads(&cavctx, &ctexdsp_ctx);
1032+ ret = ff_texturedsp_exec_decompress_threads(avctx, &ctexdsp_ctx);
10321033 if (ret < 0)
10331034 return ret;
10341035 /* fallthrough */
libavcodec/dxvenc.c+2−0
@@ -233,6 +233,8 @@ static int dxv_encode(AVCodecContext *avctx, AVPacket *pkt, · 232 unmodified lines
233233 ctx->enc.tex_data.out = ctx->tex_data;
234234 ctx->enc.frame_data.in = frame->data[0];
235235 ctx->enc.stride = frame->linesize[0];
236+ ctx->enc.width = avctx->width;
237+ ctx->enc.height = avctx->height;
236238 ff_texturedsp_exec_compress_threads(avctx, &ctx->enc);
237239 } else {
238240 /* unimplemented: YCoCg formats */
libavcodec/hapdec.c+2−0
@@ -323,6 +323,8 @@ static int hap_decode(AVCodecContext *avctx, AVFrame *frame, · 322 unmodified lines
323323
324324 ctx->dec[t].frame_data.out = frame->data[0];
325325 ctx->dec[t].stride = frame->linesize[0];
326+ ctx->dec[t].width = avctx->coded_width;
327+ ctx->dec[t].height = avctx->coded_height;
326328 ff_texturedsp_exec_decompress_threads(avctx, &ctx->dec[t]);
327329 }
328330
libavcodec/hapenc.c+2−0
@@ -63,6 +63,8 @@ static int compress_texture(AVCodecContext *avctx, uint8_t *out, int out_length, · 62 unmodified lines
6363 ctx->enc.tex_data.out = out;
6464 ctx->enc.frame_data.in = f->data[0];
6565 ctx->enc.stride = f->linesize[0];
66+ ctx->enc.width = avctx->width;
67+ ctx->enc.height = avctx->height;
6668 ff_texturedsp_exec_compress_threads(avctx, &ctx->enc);
6769
6870 return 0;
libavcodec/texturedsp.h+1−0
@@ -72,6 +72,7 @@ typedef struct TextureDSPThreadContext { · 71 unmodified lines
7272 uint8_t *out; // Output frame data
7373 } frame_data;
7474 ptrdiff_t stride; // Frame linesize
75+ int width, height; // Frame width / height
7576 union {
7677 const uint8_t *in; // Compressed texture for decompression
7778 uint8_t *out; // Compressed texture of compression
libavcodec/texturedsp_template.c+2−2
@@ -27,8 +27,8 @@ static int exec_func(AVCodecContext *avctx, void *arg, · 26 unmodified lines
2727 {
2828 const TextureDSPThreadContext *ctx = arg;
2929 uint8_t *d = ctx->tex_data.out;
30− int w_block = avctx->coded_width / TEXTURE_BLOCK_W;
31− int h_block = avctx->coded_height / TEXTURE_BLOCK_H;
30+ int w_block = ctx->width / TEXTURE_BLOCK_W;
31+ int h_block = ctx->height / TEXTURE_BLOCK_H;
3232 int x, y;
3333 int start_slice, end_slice;
3434 int base_blocks_per_slice = h_block / ctx->slice_count;
libavcodec/vbndec.c+2−0
@@ -162,6 +162,8 @@ static int vbn_decode_frame(AVCodecContext *avctx, · 161 unmodified lines
162162 ctx->dec.raw_ratio = 16;
163163 ctx->dec.frame_data.out = frame->data[0] + frame->linesize[0] * (frame->height - 1);
164164 ctx->dec.stride = -frame->linesize[0];
165+ ctx->dec.width = avctx->coded_width;
166+ ctx->dec.height = avctx->coded_height;
165167 ff_texturedsp_exec_decompress_threads(avctx, &ctx->dec);
166168 }
167169
libavcodec/vbnenc.c+2−0
@@ -114,6 +114,8 @@ static int vbn_encode(AVCodecContext *avctx, AVPacket *pkt, · 113 unmodified lines
114114 ctx->enc.frame_data.in = (frame->height - 1) * frame->linesize[0] + frame->data[0];
115115 ctx->enc.stride = -frame->linesize[0];
116116 ctx->enc.tex_data.out = pkt->data + VBN_HEADER_SIZE;
117+ ctx->enc.width = avctx->width;
118+ ctx->enc.height = avctx->height;
117119 ff_texturedsp_exec_compress_threads(avctx, &ctx->enc);
118120 } else {
119121 const uint8_t *flipped = frame->data[0] + frame->linesize[0] * (frame->height - 1);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t