History

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.

Connor Worley committed 2 years ago

Commit d5aaed91 parent c619d203 files · +15 −7Browse files

Showing the changes to libavcodec (2 of 3 files). Show all

Unified · Split

2 files
  1. libavcodec/dxv.c +3 −3
  2. libavcodec/dxvenc.c +11 −3
libavcodec/dxv.c+3−3
@@ -1238,9 +1238,9 @@ static int dxv_init(AVCodecContext *avctx) · 1237 unmodified lines
1238 return ret;1238 return ret;
1239 }1239 }
1240 1240
1241 /* Codec requires 16x16 alignment. */1241 /* Since codec is based on 4x4 blocks, size is aligned to 4 */
1242 avctx->coded_width = FFALIGN(avctx->width, 16);1242 avctx->coded_width = FFALIGN(avctx->width, TEXTURE_BLOCK_W);
1243 avctx->coded_height = FFALIGN(avctx->height, 16);1243 avctx->coded_height = FFALIGN(avctx->height, TEXTURE_BLOCK_H);
1244 1244
1245 ff_texturedsp_init(&ctx->texdsp);1245 ff_texturedsp_init(&ctx->texdsp);
1246 1246
libavcodec/dxvenc.c+11−3
@@ -275,6 +275,14 @@ static av_cold int dxv_init(AVCodecContext *avctx) · 274 unmodified lines
275 return ret;275 return ret;
276 }276 }
277 277
278 if (avctx->width % TEXTURE_BLOCK_W || avctx->height % TEXTURE_BLOCK_H) {
279 av_log(avctx,
280 AV_LOG_ERROR,
281 "Video size %dx%d is not multiple of "AV_STRINGIFY(TEXTURE_BLOCK_W)"x"AV_STRINGIFY(TEXTURE_BLOCK_H)".\n",
282 avctx->width, avctx->height);
283 return AVERROR_INVALIDDATA;
284 }
285
278 ff_texturedspenc_init(&texdsp);286 ff_texturedspenc_init(&texdsp);
279 287
280 switch (ctx->tex_fmt) {288 switch (ctx->tex_fmt) {
@@ -288,10 +296,10 @@ static av_cold int dxv_init(AVCodecContext *avctx) · 7 unmodified lines
288 return AVERROR_INVALIDDATA;296 return AVERROR_INVALIDDATA;
289 }297 }
290 ctx->enc.raw_ratio = 16;298 ctx->enc.raw_ratio = 16;
291 ctx->tex_size = FFALIGN(avctx->width, 16) / TEXTURE_BLOCK_W *299 ctx->tex_size = avctx->width / TEXTURE_BLOCK_W *
292 FFALIGN(avctx->height, 16) / TEXTURE_BLOCK_H *300 avctx->height / TEXTURE_BLOCK_H *
293 ctx->enc.tex_ratio;301 ctx->enc.tex_ratio;
294 ctx->enc.slice_count = av_clip(avctx->thread_count, 1, FFALIGN(avctx->height, 16) / TEXTURE_BLOCK_H);302 ctx->enc.slice_count = av_clip(avctx->thread_count, 1, avctx->height / TEXTURE_BLOCK_H);
295 303
296 ctx->tex_data = av_malloc(ctx->tex_size);304 ctx->tex_data = av_malloc(ctx->tex_size);
297 if (!ctx->tex_data) {305 if (!ctx->tex_data) {

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