[FFmpeg-devel] [PATCH v5 1/2] lavu/hashtable: create generic robin hood hash table

2024-05-23 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavutil/Makefile  |   2 +
 libavutil/hashtable.c   | 192 
 libavutil/hashtable.h   |  91 +
 libavutil/tests/hashtable.c | 108 
 4 files changed, 393 insertions(+)
 create mode 100644 libavutil/hashtable.c
 create mode 100644 libavutil/hashtable.h
 create mode 100644 libavutil/tests/hashtable.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 6e6fa8d800..8c7b4452b4 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -138,6 +138,7 @@ OBJS = adler32.o
\
fixed_dsp.o  \
frame.o  \
hash.o   \
+   hashtable.o  \
hdr_dynamic_metadata.o   \
hdr_dynamic_vivid_metadata.o \
hmac.o   \
@@ -252,6 +253,7 @@ TESTPROGS = adler32 
\
 file\
 fifo\
 hash\
+hashtable   \
 hmac\
 hwdevice\
 integer \
diff --git a/libavutil/hashtable.c b/libavutil/hashtable.c
new file mode 100644
index 00..155a264665
--- /dev/null
+++ b/libavutil/hashtable.c
@@ -0,0 +1,192 @@
+/*
+ * Generic hashtable
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include "crc.h"
+#include "error.h"
+#include "mem.h"
+#include "hashtable.h"
+
+#define ALIGN _Alignof(size_t)
+
+struct AVHashtableContext {
+size_t key_size;
+size_t key_size_aligned;
+size_t val_size;
+size_t val_size_aligned;
+size_t entry_size;
+size_t max_entries;
+size_t utilization;
+const AVCRC *crc;
+uint8_t *table;
+uint8_t *swapbuf;
+};
+
+#define ENTRY_PSL(entry) (entry)
+#define ENTRY_OCC(entry) (ENTRY_PSL(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_KEY(entry) (ENTRY_OCC(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_VAL(entry) (ENTRY_KEY(entry) + ctx->key_size_aligned)
+
+#define KEYS_EQUAL(k1, k2) !memcmp(k1, k2, ctx->key_size)
+
+int av_hashtable_alloc(struct AVHashtableContext **ctx, size_t key_size, 
size_t val_size, size_t max_entries)
+{
+struct AVHashtableContext *res = av_malloc(sizeof(struct 
AVHashtableContext));
+if (!res)
+return AVERROR(ENOMEM);
+res->key_size = key_size;
+res->key_size_aligned = FFALIGN(key_size, ALIGN);
+res->val_size = val_size;
+res->val_size_aligned = FFALIGN(val_size, ALIGN);
+res->entry_size = FFALIGN(sizeof(size_t), ALIGN)
++ FFALIGN(sizeof(size_t), ALIGN)
++ res->key_size_aligned
++ res->val_size_aligned;
+res->max_entries = max_entries;
+res->utilization = 0;
+res->crc = av_crc_get_table(AV_CRC_32_IEEE);
+if (!res->crc) {
+av_hashtable_freep(&res);
+return AVERROR_BUG;
+}
+res->table = av_calloc(res->max_entries, res->entry_size);
+if (!res->table) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+res->swapbuf = av_calloc(2, res->key_size_aligned + res->val_size_aligned);
+if (!res->swapbuf) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+*ctx = res;
+return 0;
+}
+
+static size_t hash_key(const struct AVHashtableContext *ctx, const void *key)
+{
+return av_crc(ctx->crc, 

[FFmpeg-devel] [PATCH v5 2/2] lavc/dxvenc: migrate DXT1 encoder to lavu hashtable

2024-05-23 Thread Connor Worley
Offers a modest performance gain due to the switch from naive linear
probling to robin hood.

Signed-off-by: Connor Worley 
---
 libavcodec/dxvenc.c | 119 
 1 file changed, 32 insertions(+), 87 deletions(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index 8229438373..8962be25a1 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -21,7 +21,7 @@
 
 #include 
 
-#include "libavutil/crc.h"
+#include "libavutil/hashtable.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
@@ -39,72 +39,9 @@
  * appeared in the decompressed stream. Using a simple hash table (HT)
  * significantly speeds up the lookback process while encoding.
  */
-#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_HT_ELEMS 0x20202
 #define LOOKBACK_WORDS0x20202
 
-typedef struct HTEntry {
-uint32_t key;
-uint32_t pos;
-} HTEntry;
-
-static void ht_init(HTEntry *ht)
-{
-for (size_t i = 0; i < LOOKBACK_HT_ELEMS; i++) {
-ht[i].pos = -1;
-}
-}
-
-static uint32_t ht_lookup_and_upsert(HTEntry *ht, const AVCRC *hash_ctx,
-uint32_t key, uint32_t pos)
-{
-uint32_t ret = -1;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->key == key || entry->pos == -1) {
-ret = entry->pos;
-entry->key = key;
-entry->pos = pos;
-break;
-}
-}
-return ret;
-}
-
-static void ht_delete(HTEntry *ht, const AVCRC *hash_ctx,
-  uint32_t key, uint32_t pos)
-{
-HTEntry *removed_entry = NULL;
-size_t removed_hash;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->pos == -1)
-return;
-if (removed_entry) {
-size_t candidate_hash = av_crc(hash_ctx, 0, (uint8_t*)&entry->key, 
4) % LOOKBACK_HT_ELEMS;
-if ((wrapped_index > removed_hash && (candidate_hash <= 
removed_hash || candidate_hash > wrapped_index)) ||
-(wrapped_index < removed_hash && (candidate_hash <= 
removed_hash && candidate_hash > wrapped_index))) {
-*removed_entry = *entry;
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-}
-} else if (entry->key == key) {
-if (entry->pos <= pos) {
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-} else {
-return;
-}
-}
-}
-}
-
 typedef struct DXVEncContext {
 AVClass *class;
 
@@ -121,10 +58,8 @@ typedef struct DXVEncContext {
 DXVTextureFormat tex_fmt;
 int (*compress_tex)(AVCodecContext *avctx);
 
-const AVCRC *crc_ctx;
-
-HTEntry color_lookback_ht[LOOKBACK_HT_ELEMS];
-HTEntry lut_lookback_ht[LOOKBACK_HT_ELEMS];
+struct AVHashtableContext *color_ht;
+struct AVHashtableContext *lut_ht;
 } DXVEncContext;
 
 /* Converts an index offset value to a 2-bit opcode and pushes it to a stream.
@@ -161,25 +96,30 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
 void *value;
 uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
2, op = 0;
 
-ht_init(ctx->color_lookback_ht);
-ht_init(ctx->lut_lookback_ht);
+av_hashtable_clear(ctx->color_ht);
+av_hashtable_clear(ctx->lut_ht);
 
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data));
+av_hashtable_set(ctx->color_ht, ctx->tex_data, &pos);
+pos++;
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + 4));
-
-ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data), 0);
-ht_lookup_and_upsert(ctx->lut_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data + 4), 1);
+av_hashtable_set(ctx->lut_ht, ctx->tex_data + 4, &pos);
+pos++;
 
 while (pos + 2 <= ctx->tex_size / 4) {
 idx = 0;
+color_idx = 0;
+lut_idx = 0;
 
 color = AV_RL32(ctx->tex_data + pos * 4);
-prev_pos = ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
color, pos);
-color_idx = prev_pos != -1 ? pos - prev_pos : 0;
+if (av_hashtable_get(ctx->color_ht, &color, &prev_pos))
+color_idx = pos - prev_pos;
+av_hashtable_set(ctx->color_ht, &color, &po

[FFmpeg-devel] [PATCH v6 1/2] lavu/hashtable: create generic robin hood hash table

2024-06-03 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavutil/Makefile  |   2 +
 libavutil/hashtable.c   | 192 
 libavutil/hashtable.h   |  91 +
 libavutil/tests/hashtable.c | 110 +
 4 files changed, 395 insertions(+)
 create mode 100644 libavutil/hashtable.c
 create mode 100644 libavutil/hashtable.h
 create mode 100644 libavutil/tests/hashtable.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 6e6fa8d800..8c7b4452b4 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -138,6 +138,7 @@ OBJS = adler32.o
\
fixed_dsp.o  \
frame.o  \
hash.o   \
+   hashtable.o  \
hdr_dynamic_metadata.o   \
hdr_dynamic_vivid_metadata.o \
hmac.o   \
@@ -252,6 +253,7 @@ TESTPROGS = adler32 
\
 file\
 fifo\
 hash\
+hashtable   \
 hmac\
 hwdevice\
 integer \
diff --git a/libavutil/hashtable.c b/libavutil/hashtable.c
new file mode 100644
index 00..155a264665
--- /dev/null
+++ b/libavutil/hashtable.c
@@ -0,0 +1,192 @@
+/*
+ * Generic hashtable
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include "crc.h"
+#include "error.h"
+#include "mem.h"
+#include "hashtable.h"
+
+#define ALIGN _Alignof(size_t)
+
+struct AVHashtableContext {
+size_t key_size;
+size_t key_size_aligned;
+size_t val_size;
+size_t val_size_aligned;
+size_t entry_size;
+size_t max_entries;
+size_t utilization;
+const AVCRC *crc;
+uint8_t *table;
+uint8_t *swapbuf;
+};
+
+#define ENTRY_PSL(entry) (entry)
+#define ENTRY_OCC(entry) (ENTRY_PSL(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_KEY(entry) (ENTRY_OCC(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_VAL(entry) (ENTRY_KEY(entry) + ctx->key_size_aligned)
+
+#define KEYS_EQUAL(k1, k2) !memcmp(k1, k2, ctx->key_size)
+
+int av_hashtable_alloc(struct AVHashtableContext **ctx, size_t key_size, 
size_t val_size, size_t max_entries)
+{
+struct AVHashtableContext *res = av_malloc(sizeof(struct 
AVHashtableContext));
+if (!res)
+return AVERROR(ENOMEM);
+res->key_size = key_size;
+res->key_size_aligned = FFALIGN(key_size, ALIGN);
+res->val_size = val_size;
+res->val_size_aligned = FFALIGN(val_size, ALIGN);
+res->entry_size = FFALIGN(sizeof(size_t), ALIGN)
++ FFALIGN(sizeof(size_t), ALIGN)
++ res->key_size_aligned
++ res->val_size_aligned;
+res->max_entries = max_entries;
+res->utilization = 0;
+res->crc = av_crc_get_table(AV_CRC_32_IEEE);
+if (!res->crc) {
+av_hashtable_freep(&res);
+return AVERROR_BUG;
+}
+res->table = av_calloc(res->max_entries, res->entry_size);
+if (!res->table) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+res->swapbuf = av_calloc(2, res->key_size_aligned + res->val_size_aligned);
+if (!res->swapbuf) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+*ctx = res;
+return 0;
+}
+
+static size_t hash_key(const struct AVHashtableContext *ctx, const void *key)
+{
+return av_crc(ctx->crc, 

[FFmpeg-devel] [PATCH v6 2/2] lavc/dxvenc: migrate DXT1 encoder to lavu hashtable

2024-06-03 Thread Connor Worley
Offers a modest performance gain due to the switch from naive linear
probling to robin hood.

Signed-off-by: Connor Worley 
---
 libavcodec/dxvenc.c | 119 
 1 file changed, 32 insertions(+), 87 deletions(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index 8229438373..8962be25a1 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -21,7 +21,7 @@
 
 #include 
 
-#include "libavutil/crc.h"
+#include "libavutil/hashtable.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
@@ -39,72 +39,9 @@
  * appeared in the decompressed stream. Using a simple hash table (HT)
  * significantly speeds up the lookback process while encoding.
  */
-#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_HT_ELEMS 0x20202
 #define LOOKBACK_WORDS0x20202
 
-typedef struct HTEntry {
-uint32_t key;
-uint32_t pos;
-} HTEntry;
-
-static void ht_init(HTEntry *ht)
-{
-for (size_t i = 0; i < LOOKBACK_HT_ELEMS; i++) {
-ht[i].pos = -1;
-}
-}
-
-static uint32_t ht_lookup_and_upsert(HTEntry *ht, const AVCRC *hash_ctx,
-uint32_t key, uint32_t pos)
-{
-uint32_t ret = -1;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->key == key || entry->pos == -1) {
-ret = entry->pos;
-entry->key = key;
-entry->pos = pos;
-break;
-}
-}
-return ret;
-}
-
-static void ht_delete(HTEntry *ht, const AVCRC *hash_ctx,
-  uint32_t key, uint32_t pos)
-{
-HTEntry *removed_entry = NULL;
-size_t removed_hash;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->pos == -1)
-return;
-if (removed_entry) {
-size_t candidate_hash = av_crc(hash_ctx, 0, (uint8_t*)&entry->key, 
4) % LOOKBACK_HT_ELEMS;
-if ((wrapped_index > removed_hash && (candidate_hash <= 
removed_hash || candidate_hash > wrapped_index)) ||
-(wrapped_index < removed_hash && (candidate_hash <= 
removed_hash && candidate_hash > wrapped_index))) {
-*removed_entry = *entry;
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-}
-} else if (entry->key == key) {
-if (entry->pos <= pos) {
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-} else {
-return;
-}
-}
-}
-}
-
 typedef struct DXVEncContext {
 AVClass *class;
 
@@ -121,10 +58,8 @@ typedef struct DXVEncContext {
 DXVTextureFormat tex_fmt;
 int (*compress_tex)(AVCodecContext *avctx);
 
-const AVCRC *crc_ctx;
-
-HTEntry color_lookback_ht[LOOKBACK_HT_ELEMS];
-HTEntry lut_lookback_ht[LOOKBACK_HT_ELEMS];
+struct AVHashtableContext *color_ht;
+struct AVHashtableContext *lut_ht;
 } DXVEncContext;
 
 /* Converts an index offset value to a 2-bit opcode and pushes it to a stream.
@@ -161,25 +96,30 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
 void *value;
 uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
2, op = 0;
 
-ht_init(ctx->color_lookback_ht);
-ht_init(ctx->lut_lookback_ht);
+av_hashtable_clear(ctx->color_ht);
+av_hashtable_clear(ctx->lut_ht);
 
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data));
+av_hashtable_set(ctx->color_ht, ctx->tex_data, &pos);
+pos++;
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + 4));
-
-ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data), 0);
-ht_lookup_and_upsert(ctx->lut_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data + 4), 1);
+av_hashtable_set(ctx->lut_ht, ctx->tex_data + 4, &pos);
+pos++;
 
 while (pos + 2 <= ctx->tex_size / 4) {
 idx = 0;
+color_idx = 0;
+lut_idx = 0;
 
 color = AV_RL32(ctx->tex_data + pos * 4);
-prev_pos = ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
color, pos);
-color_idx = prev_pos != -1 ? pos - prev_pos : 0;
+if (av_hashtable_get(ctx->color_ht, &color, &prev_pos))
+color_idx = pos - prev_pos;
+av_hashtable_set(ctx->color_ht, &color, &po

[FFmpeg-devel] [PATCH v7 1/2] lavu/hashtable: create generic robin hood hash table

2024-06-05 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavutil/Makefile  |   2 +
 libavutil/hashtable.c   | 192 
 libavutil/hashtable.h   |  91 +
 libavutil/tests/hashtable.c | 110 +
 4 files changed, 395 insertions(+)
 create mode 100644 libavutil/hashtable.c
 create mode 100644 libavutil/hashtable.h
 create mode 100644 libavutil/tests/hashtable.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index 6e6fa8d800..8c7b4452b4 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -138,6 +138,7 @@ OBJS = adler32.o
\
fixed_dsp.o  \
frame.o  \
hash.o   \
+   hashtable.o  \
hdr_dynamic_metadata.o   \
hdr_dynamic_vivid_metadata.o \
hmac.o   \
@@ -252,6 +253,7 @@ TESTPROGS = adler32 
\
 file\
 fifo\
 hash\
+hashtable   \
 hmac\
 hwdevice\
 integer \
diff --git a/libavutil/hashtable.c b/libavutil/hashtable.c
new file mode 100644
index 00..155a264665
--- /dev/null
+++ b/libavutil/hashtable.c
@@ -0,0 +1,192 @@
+/*
+ * Generic hashtable
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include "crc.h"
+#include "error.h"
+#include "mem.h"
+#include "hashtable.h"
+
+#define ALIGN _Alignof(size_t)
+
+struct AVHashtableContext {
+size_t key_size;
+size_t key_size_aligned;
+size_t val_size;
+size_t val_size_aligned;
+size_t entry_size;
+size_t max_entries;
+size_t utilization;
+const AVCRC *crc;
+uint8_t *table;
+uint8_t *swapbuf;
+};
+
+#define ENTRY_PSL(entry) (entry)
+#define ENTRY_OCC(entry) (ENTRY_PSL(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_KEY(entry) (ENTRY_OCC(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_VAL(entry) (ENTRY_KEY(entry) + ctx->key_size_aligned)
+
+#define KEYS_EQUAL(k1, k2) !memcmp(k1, k2, ctx->key_size)
+
+int av_hashtable_alloc(struct AVHashtableContext **ctx, size_t key_size, 
size_t val_size, size_t max_entries)
+{
+struct AVHashtableContext *res = av_malloc(sizeof(struct 
AVHashtableContext));
+if (!res)
+return AVERROR(ENOMEM);
+res->key_size = key_size;
+res->key_size_aligned = FFALIGN(key_size, ALIGN);
+res->val_size = val_size;
+res->val_size_aligned = FFALIGN(val_size, ALIGN);
+res->entry_size = FFALIGN(sizeof(size_t), ALIGN)
++ FFALIGN(sizeof(size_t), ALIGN)
++ res->key_size_aligned
++ res->val_size_aligned;
+res->max_entries = max_entries;
+res->utilization = 0;
+res->crc = av_crc_get_table(AV_CRC_32_IEEE);
+if (!res->crc) {
+av_hashtable_freep(&res);
+return AVERROR_BUG;
+}
+res->table = av_calloc(res->max_entries, res->entry_size);
+if (!res->table) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+res->swapbuf = av_calloc(2, res->key_size_aligned + res->val_size_aligned);
+if (!res->swapbuf) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+*ctx = res;
+return 0;
+}
+
+static size_t hash_key(const struct AVHashtableContext *ctx, const void *key)
+{
+return av_crc(ctx->crc, 

[FFmpeg-devel] [PATCH v7 2/2] lavc/dxvenc: migrate DXT1 encoder to lavu hashtable

2024-06-05 Thread Connor Worley
Offers a modest performance gain due to the switch from naive linear
probling to robin hood.

Signed-off-by: Connor Worley 
---
 libavcodec/dxvenc.c | 121 
 1 file changed, 33 insertions(+), 88 deletions(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index 8229438373..38c7d7a0ab 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -21,7 +21,7 @@
 
 #include 
 
-#include "libavutil/crc.h"
+#include "libavutil/hashtable.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/mem.h"
 #include "libavutil/opt.h"
@@ -39,72 +39,9 @@
  * appeared in the decompressed stream. Using a simple hash table (HT)
  * significantly speeds up the lookback process while encoding.
  */
-#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_HT_ELEMS 0x20202
 #define LOOKBACK_WORDS0x20202
 
-typedef struct HTEntry {
-uint32_t key;
-uint32_t pos;
-} HTEntry;
-
-static void ht_init(HTEntry *ht)
-{
-for (size_t i = 0; i < LOOKBACK_HT_ELEMS; i++) {
-ht[i].pos = -1;
-}
-}
-
-static uint32_t ht_lookup_and_upsert(HTEntry *ht, const AVCRC *hash_ctx,
-uint32_t key, uint32_t pos)
-{
-uint32_t ret = -1;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->key == key || entry->pos == -1) {
-ret = entry->pos;
-entry->key = key;
-entry->pos = pos;
-break;
-}
-}
-return ret;
-}
-
-static void ht_delete(HTEntry *ht, const AVCRC *hash_ctx,
-  uint32_t key, uint32_t pos)
-{
-HTEntry *removed_entry = NULL;
-size_t removed_hash;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->pos == -1)
-return;
-if (removed_entry) {
-size_t candidate_hash = av_crc(hash_ctx, 0, (uint8_t*)&entry->key, 
4) % LOOKBACK_HT_ELEMS;
-if ((wrapped_index > removed_hash && (candidate_hash <= 
removed_hash || candidate_hash > wrapped_index)) ||
-(wrapped_index < removed_hash && (candidate_hash <= 
removed_hash && candidate_hash > wrapped_index))) {
-*removed_entry = *entry;
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-}
-} else if (entry->key == key) {
-if (entry->pos <= pos) {
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-} else {
-return;
-}
-}
-}
-}
-
 typedef struct DXVEncContext {
 AVClass *class;
 
@@ -121,10 +58,8 @@ typedef struct DXVEncContext {
 DXVTextureFormat tex_fmt;
 int (*compress_tex)(AVCodecContext *avctx);
 
-const AVCRC *crc_ctx;
-
-HTEntry color_lookback_ht[LOOKBACK_HT_ELEMS];
-HTEntry lut_lookback_ht[LOOKBACK_HT_ELEMS];
+struct AVHashtableContext *color_ht;
+struct AVHashtableContext *lut_ht;
 } DXVEncContext;
 
 /* Converts an index offset value to a 2-bit opcode and pushes it to a stream.
@@ -159,27 +94,32 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
 DXVEncContext *ctx = avctx->priv_data;
 PutByteContext *pbc = &ctx->pbc;
 void *value;
-uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
2, op = 0;
+uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
0, op = 0;
 
-ht_init(ctx->color_lookback_ht);
-ht_init(ctx->lut_lookback_ht);
+av_hashtable_clear(ctx->color_ht);
+av_hashtable_clear(ctx->lut_ht);
 
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data));
+av_hashtable_set(ctx->color_ht, ctx->tex_data, &pos);
+pos++;
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + 4));
-
-ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data), 0);
-ht_lookup_and_upsert(ctx->lut_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data + 4), 1);
+av_hashtable_set(ctx->lut_ht, ctx->tex_data + 4, &pos);
+pos++;
 
 while (pos + 2 <= ctx->tex_size / 4) {
 idx = 0;
+color_idx = 0;
+lut_idx = 0;
 
 color = AV_RL32(ctx->tex_data + pos * 4);
-prev_pos = ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
color, pos);
-color_idx = prev_pos != -1 ? pos - prev_pos : 0;

[FFmpeg-devel] [PATCH] lavc/texturedsp: require explicitly-set frame dimensions

2024-02-11 Thread Connor Worley
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 |  3 +++
 libavcodec/dxv.c | 19 ++-
 libavcodec/dxvenc.c  |  3 +++
 libavcodec/hapdec.c  |  5 +
 libavcodec/hapenc.c  |  3 +++
 libavcodec/texturedsp.h  |  1 +
 libavcodec/texturedsp_template.c |  4 ++--
 libavcodec/vbndec.c  |  3 +++
 libavcodec/vbnenc.c  |  3 +++
 9 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/libavcodec/dds.c b/libavcodec/dds.c
index 67e2325a2a..83f51be802 100644
--- a/libavcodec/dds.c
+++ b/libavcodec/dds.c
@@ -339,6 +339,9 @@ static int parse_pixel_format(AVCodecContext *avctx)
 av_log(avctx, AV_LOG_ERROR, "Unsupported %s fourcc.\n", 
av_fourcc2str(fourcc));
 return AVERROR_INVALIDDATA;
 }
+
+ctx->dec.width  = avctx->coded_width;
+ctx->dec.height = avctx->coded_height;
 } else if (ctx->paletted) {
 if (bpp == 8) {
 avctx->pix_fmt = AV_PIX_FMT_PAL8;
diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 2eca14c129..4eaa6dc224 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,12 @@ 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);
+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;
+
 /* New header is 12 bytes long. */
 if (!old_type) {
 version_major = bytestream2_get_byte(gbc) - 1;
@@ -979,8 +980,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;
@@ -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..62ac812226 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -298,6 +298,9 @@ static av_cold int dxv_init(AVCodecContext *avctx)
 ctx->enc.tex_ratio;
 ctx->enc.slice_count = av_clip(avctx->thread_count, 1, avctx->height / 
TEXTURE_BLOCK_H);
 
+ctx->enc.width  = avctx->width;
+ctx->enc.height = avctx->height;
+
 ctx->tex_data = av_malloc(ctx->tex_size);
 if (!ctx->tex_data) {
 return AVERROR(ENOMEM);
diff -

Re: [FFmpeg-devel] [PATCH v2 3/3] lavc/dxv: remove ctx fields that can be derived from texdsp ctxs

2024-02-11 Thread Connor Worley
On Sun, Feb 11, 2024 at 9:41 AM James Almer  wrote:

> This set broke fate when using slice threading:
>
> https://fate.ffmpeg.org/report.cgi?slot=x86_64-archlinux-gcc-threads-misc&time=20240211015448
>

https://ffmpeg.org//pipermail/ffmpeg-devel/2024-February/321317.html
contains a fix.

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] lavc/texturedsp: require explicitly-set frame dimensions

2024-02-14 Thread Connor Worley
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, AVPacke

[FFmpeg-devel] [PATCH v3 1/2] lavu/hashtable: create generic robin hood hash table

2024-02-21 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavutil/Makefile  |   2 +
 libavutil/hashtable.c   | 192 
 libavutil/hashtable.h   |  40 
 libavutil/tests/hashtable.c | 108 
 4 files changed, 342 insertions(+)
 create mode 100644 libavutil/hashtable.c
 create mode 100644 libavutil/hashtable.h
 create mode 100644 libavutil/tests/hashtable.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index e7709b97d0..be75d464fc 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -138,6 +138,7 @@ OBJS = adler32.o
\
fixed_dsp.o  \
frame.o  \
hash.o   \
+   hashtable.o  \
hdr_dynamic_metadata.o   \
hdr_dynamic_vivid_metadata.o \
hmac.o   \
@@ -251,6 +252,7 @@ TESTPROGS = adler32 
\
 file\
 fifo\
 hash\
+hashtable   \
 hmac\
 hwdevice\
 integer \
diff --git a/libavutil/hashtable.c b/libavutil/hashtable.c
new file mode 100644
index 00..155a264665
--- /dev/null
+++ b/libavutil/hashtable.c
@@ -0,0 +1,192 @@
+/*
+ * Generic hashtable
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include "crc.h"
+#include "error.h"
+#include "mem.h"
+#include "hashtable.h"
+
+#define ALIGN _Alignof(size_t)
+
+struct AVHashtableContext {
+size_t key_size;
+size_t key_size_aligned;
+size_t val_size;
+size_t val_size_aligned;
+size_t entry_size;
+size_t max_entries;
+size_t utilization;
+const AVCRC *crc;
+uint8_t *table;
+uint8_t *swapbuf;
+};
+
+#define ENTRY_PSL(entry) (entry)
+#define ENTRY_OCC(entry) (ENTRY_PSL(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_KEY(entry) (ENTRY_OCC(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_VAL(entry) (ENTRY_KEY(entry) + ctx->key_size_aligned)
+
+#define KEYS_EQUAL(k1, k2) !memcmp(k1, k2, ctx->key_size)
+
+int av_hashtable_alloc(struct AVHashtableContext **ctx, size_t key_size, 
size_t val_size, size_t max_entries)
+{
+struct AVHashtableContext *res = av_malloc(sizeof(struct 
AVHashtableContext));
+if (!res)
+return AVERROR(ENOMEM);
+res->key_size = key_size;
+res->key_size_aligned = FFALIGN(key_size, ALIGN);
+res->val_size = val_size;
+res->val_size_aligned = FFALIGN(val_size, ALIGN);
+res->entry_size = FFALIGN(sizeof(size_t), ALIGN)
++ FFALIGN(sizeof(size_t), ALIGN)
++ res->key_size_aligned
++ res->val_size_aligned;
+res->max_entries = max_entries;
+res->utilization = 0;
+res->crc = av_crc_get_table(AV_CRC_32_IEEE);
+if (!res->crc) {
+av_hashtable_freep(&res);
+return AVERROR_BUG;
+}
+res->table = av_calloc(res->max_entries, res->entry_size);
+if (!res->table) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+res->swapbuf = av_calloc(2, res->key_size_aligned + res->val_size_aligned);
+if (!res->swapbuf) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+*ctx = res;
+return 0;
+}
+
+static size_t hash_key(const struct AVHashtableContext *ctx, const void *key)
+{
+return av_crc(ctx->crc, 0, key, ctx-

[FFmpeg-devel] [PATCH v3 2/2] lavc/dxvenc: migrate DXT1 encoder to lavu hashtable

2024-02-21 Thread Connor Worley
Offers a modest performance gain due to the switch from naive linear
probling to robin hood.

Signed-off-by: Connor Worley 
---
 libavcodec/dxvenc.c | 121 
 1 file changed, 33 insertions(+), 88 deletions(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index 1ce2b1d014..980269657d 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -21,7 +21,7 @@
 
 #include 
 
-#include "libavutil/crc.h"
+#include "libavutil/hashtable.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 
@@ -38,72 +38,9 @@
  * appeared in the decompressed stream. Using a simple hash table (HT)
  * significantly speeds up the lookback process while encoding.
  */
-#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_HT_ELEMS 0x20202
 #define LOOKBACK_WORDS0x20202
 
-typedef struct HTEntry {
-uint32_t key;
-uint32_t pos;
-} HTEntry;
-
-static void ht_init(HTEntry *ht)
-{
-for (size_t i = 0; i < LOOKBACK_HT_ELEMS; i++) {
-ht[i].pos = -1;
-}
-}
-
-static uint32_t ht_lookup_and_upsert(HTEntry *ht, const AVCRC *hash_ctx,
-uint32_t key, uint32_t pos)
-{
-uint32_t ret = -1;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->key == key || entry->pos == -1) {
-ret = entry->pos;
-entry->key = key;
-entry->pos = pos;
-break;
-}
-}
-return ret;
-}
-
-static void ht_delete(HTEntry *ht, const AVCRC *hash_ctx,
-  uint32_t key, uint32_t pos)
-{
-HTEntry *removed_entry = NULL;
-size_t removed_hash;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->pos == -1)
-return;
-if (removed_entry) {
-size_t candidate_hash = av_crc(hash_ctx, 0, (uint8_t*)&entry->key, 
4) % LOOKBACK_HT_ELEMS;
-if ((wrapped_index > removed_hash && (candidate_hash <= 
removed_hash || candidate_hash > wrapped_index)) ||
-(wrapped_index < removed_hash && (candidate_hash <= 
removed_hash && candidate_hash > wrapped_index))) {
-*removed_entry = *entry;
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-}
-} else if (entry->key == key) {
-if (entry->pos <= pos) {
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-} else {
-return;
-}
-}
-}
-}
-
 typedef struct DXVEncContext {
 AVClass *class;
 
@@ -120,10 +57,8 @@ typedef struct DXVEncContext {
 DXVTextureFormat tex_fmt;
 int (*compress_tex)(AVCodecContext *avctx);
 
-const AVCRC *crc_ctx;
-
-HTEntry color_lookback_ht[LOOKBACK_HT_ELEMS];
-HTEntry lut_lookback_ht[LOOKBACK_HT_ELEMS];
+struct AVHashtableContext *color_ht;
+struct AVHashtableContext *lut_ht;
 } DXVEncContext;
 
 /* Converts an index offset value to a 2-bit opcode and pushes it to a stream.
@@ -158,27 +93,32 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
 DXVEncContext *ctx = avctx->priv_data;
 PutByteContext *pbc = &ctx->pbc;
 uint32_t *value;
-uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
2, op = 0;
+uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
0, op = 0;
 
-ht_init(ctx->color_lookback_ht);
-ht_init(ctx->lut_lookback_ht);
+av_hashtable_clear(ctx->color_ht);
+av_hashtable_clear(ctx->lut_ht);
 
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data));
+av_hashtable_set(ctx->color_ht, ctx->tex_data, &pos);
+pos++;
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + 4));
-
-ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data), 0);
-ht_lookup_and_upsert(ctx->lut_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data + 4), 1);
+av_hashtable_set(ctx->lut_ht, ctx->tex_data + 4, &pos);
+pos++;
 
 while (pos + 2 <= ctx->tex_size / 4) {
 idx = 0;
+color_idx = 0;
+lut_idx = 0;
 
 color = AV_RL32(ctx->tex_data + pos * 4);
-prev_pos = ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
color, pos);
-color_idx = prev_pos != -1 ? pos - prev_pos : 0;
+if (av_hashtable_

[FFmpeg-devel] [PATCH v4 1/2] lavu/hashtable: create generic robin hood hash table

2024-02-24 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavutil/Makefile  |   2 +
 libavutil/hashtable.c   | 192 
 libavutil/hashtable.h   |  40 
 libavutil/tests/hashtable.c | 110 +
 4 files changed, 344 insertions(+)
 create mode 100644 libavutil/hashtable.c
 create mode 100644 libavutil/hashtable.h
 create mode 100644 libavutil/tests/hashtable.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index e7709b97d0..be75d464fc 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -138,6 +138,7 @@ OBJS = adler32.o
\
fixed_dsp.o  \
frame.o  \
hash.o   \
+   hashtable.o  \
hdr_dynamic_metadata.o   \
hdr_dynamic_vivid_metadata.o \
hmac.o   \
@@ -251,6 +252,7 @@ TESTPROGS = adler32 
\
 file\
 fifo\
 hash\
+hashtable   \
 hmac\
 hwdevice\
 integer \
diff --git a/libavutil/hashtable.c b/libavutil/hashtable.c
new file mode 100644
index 00..155a264665
--- /dev/null
+++ b/libavutil/hashtable.c
@@ -0,0 +1,192 @@
+/*
+ * Generic hashtable
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include "crc.h"
+#include "error.h"
+#include "mem.h"
+#include "hashtable.h"
+
+#define ALIGN _Alignof(size_t)
+
+struct AVHashtableContext {
+size_t key_size;
+size_t key_size_aligned;
+size_t val_size;
+size_t val_size_aligned;
+size_t entry_size;
+size_t max_entries;
+size_t utilization;
+const AVCRC *crc;
+uint8_t *table;
+uint8_t *swapbuf;
+};
+
+#define ENTRY_PSL(entry) (entry)
+#define ENTRY_OCC(entry) (ENTRY_PSL(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_KEY(entry) (ENTRY_OCC(entry) + FFALIGN(sizeof(size_t), ALIGN))
+#define ENTRY_VAL(entry) (ENTRY_KEY(entry) + ctx->key_size_aligned)
+
+#define KEYS_EQUAL(k1, k2) !memcmp(k1, k2, ctx->key_size)
+
+int av_hashtable_alloc(struct AVHashtableContext **ctx, size_t key_size, 
size_t val_size, size_t max_entries)
+{
+struct AVHashtableContext *res = av_malloc(sizeof(struct 
AVHashtableContext));
+if (!res)
+return AVERROR(ENOMEM);
+res->key_size = key_size;
+res->key_size_aligned = FFALIGN(key_size, ALIGN);
+res->val_size = val_size;
+res->val_size_aligned = FFALIGN(val_size, ALIGN);
+res->entry_size = FFALIGN(sizeof(size_t), ALIGN)
++ FFALIGN(sizeof(size_t), ALIGN)
++ res->key_size_aligned
++ res->val_size_aligned;
+res->max_entries = max_entries;
+res->utilization = 0;
+res->crc = av_crc_get_table(AV_CRC_32_IEEE);
+if (!res->crc) {
+av_hashtable_freep(&res);
+return AVERROR_BUG;
+}
+res->table = av_calloc(res->max_entries, res->entry_size);
+if (!res->table) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+res->swapbuf = av_calloc(2, res->key_size_aligned + res->val_size_aligned);
+if (!res->swapbuf) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+*ctx = res;
+return 0;
+}
+
+static size_t hash_key(const struct AVHashtableContext *ctx, const void *key)
+{
+return av_crc(ctx->crc, 0, key, ctx-

[FFmpeg-devel] [PATCH v4 2/2] lavc/dxvenc: migrate DXT1 encoder to lavu hashtable

2024-02-24 Thread Connor Worley
Offers a modest performance gain due to the switch from naive linear
probling to robin hood.

Signed-off-by: Connor Worley 
---
 libavcodec/dxvenc.c | 121 
 1 file changed, 33 insertions(+), 88 deletions(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index 1ce2b1d014..980269657d 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -21,7 +21,7 @@
 
 #include 
 
-#include "libavutil/crc.h"
+#include "libavutil/hashtable.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 
@@ -38,72 +38,9 @@
  * appeared in the decompressed stream. Using a simple hash table (HT)
  * significantly speeds up the lookback process while encoding.
  */
-#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_HT_ELEMS 0x20202
 #define LOOKBACK_WORDS0x20202
 
-typedef struct HTEntry {
-uint32_t key;
-uint32_t pos;
-} HTEntry;
-
-static void ht_init(HTEntry *ht)
-{
-for (size_t i = 0; i < LOOKBACK_HT_ELEMS; i++) {
-ht[i].pos = -1;
-}
-}
-
-static uint32_t ht_lookup_and_upsert(HTEntry *ht, const AVCRC *hash_ctx,
-uint32_t key, uint32_t pos)
-{
-uint32_t ret = -1;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->key == key || entry->pos == -1) {
-ret = entry->pos;
-entry->key = key;
-entry->pos = pos;
-break;
-}
-}
-return ret;
-}
-
-static void ht_delete(HTEntry *ht, const AVCRC *hash_ctx,
-  uint32_t key, uint32_t pos)
-{
-HTEntry *removed_entry = NULL;
-size_t removed_hash;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->pos == -1)
-return;
-if (removed_entry) {
-size_t candidate_hash = av_crc(hash_ctx, 0, (uint8_t*)&entry->key, 
4) % LOOKBACK_HT_ELEMS;
-if ((wrapped_index > removed_hash && (candidate_hash <= 
removed_hash || candidate_hash > wrapped_index)) ||
-(wrapped_index < removed_hash && (candidate_hash <= 
removed_hash && candidate_hash > wrapped_index))) {
-*removed_entry = *entry;
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-}
-} else if (entry->key == key) {
-if (entry->pos <= pos) {
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-} else {
-return;
-}
-}
-}
-}
-
 typedef struct DXVEncContext {
 AVClass *class;
 
@@ -120,10 +57,8 @@ typedef struct DXVEncContext {
 DXVTextureFormat tex_fmt;
 int (*compress_tex)(AVCodecContext *avctx);
 
-const AVCRC *crc_ctx;
-
-HTEntry color_lookback_ht[LOOKBACK_HT_ELEMS];
-HTEntry lut_lookback_ht[LOOKBACK_HT_ELEMS];
+struct AVHashtableContext *color_ht;
+struct AVHashtableContext *lut_ht;
 } DXVEncContext;
 
 /* Converts an index offset value to a 2-bit opcode and pushes it to a stream.
@@ -158,27 +93,32 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
 DXVEncContext *ctx = avctx->priv_data;
 PutByteContext *pbc = &ctx->pbc;
 uint32_t *value;
-uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
2, op = 0;
+uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
0, op = 0;
 
-ht_init(ctx->color_lookback_ht);
-ht_init(ctx->lut_lookback_ht);
+av_hashtable_clear(ctx->color_ht);
+av_hashtable_clear(ctx->lut_ht);
 
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data));
+av_hashtable_set(ctx->color_ht, ctx->tex_data, &pos);
+pos++;
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + 4));
-
-ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data), 0);
-ht_lookup_and_upsert(ctx->lut_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data + 4), 1);
+av_hashtable_set(ctx->lut_ht, ctx->tex_data + 4, &pos);
+pos++;
 
 while (pos + 2 <= ctx->tex_size / 4) {
 idx = 0;
+color_idx = 0;
+lut_idx = 0;
 
 color = AV_RL32(ctx->tex_data + pos * 4);
-prev_pos = ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
color, pos);
-color_idx = prev_pos != -1 ? pos - prev_pos : 0;
+if (av_hashtable_

Re: [FFmpeg-devel] [PATCH v4 1/2] lavu/hashtable: create generic robin hood hash table

2024-03-03 Thread Connor Worley
Any objections to this patchset?

On Sat, Feb 24, 2024 at 12:06 PM Connor Worley 
wrote:

> Signed-off-by: Connor Worley 
> ---
>  libavutil/Makefile  |   2 +
>  libavutil/hashtable.c   | 192 
>  libavutil/hashtable.h   |  40 
>  libavutil/tests/hashtable.c | 110 +
>  4 files changed, 344 insertions(+)
>  create mode 100644 libavutil/hashtable.c
>  create mode 100644 libavutil/hashtable.h
>  create mode 100644 libavutil/tests/hashtable.c
>
> diff --git a/libavutil/Makefile b/libavutil/Makefile
> index e7709b97d0..be75d464fc 100644
> --- a/libavutil/Makefile
> +++ b/libavutil/Makefile
> @@ -138,6 +138,7 @@ OBJS = adler32.o
>   \
> fixed_dsp.o  \
> frame.o  \
> hash.o   \
> +   hashtable.o  \
> hdr_dynamic_metadata.o   \
> hdr_dynamic_vivid_metadata.o \
> hmac.o   \
> @@ -251,6 +252,7 @@ TESTPROGS = adler32
>  \
>  file\
>  fifo\
>  hash\
> +hashtable   \
>  hmac\
>  hwdevice\
>  integer \
> diff --git a/libavutil/hashtable.c b/libavutil/hashtable.c
> new file mode 100644
> index 00..155a264665
> --- /dev/null
> +++ b/libavutil/hashtable.c
> @@ -0,0 +1,192 @@
> +/*
> + * Generic hashtable
> + * Copyright (C) 2024 Connor Worley 
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> 02110-1301 USA
> + */
> +
> +#include 
> +#include 
> +
> +#include "crc.h"
> +#include "error.h"
> +#include "mem.h"
> +#include "hashtable.h"
> +
> +#define ALIGN _Alignof(size_t)
> +
> +struct AVHashtableContext {
> +size_t key_size;
> +size_t key_size_aligned;
> +size_t val_size;
> +size_t val_size_aligned;
> +size_t entry_size;
> +size_t max_entries;
> +size_t utilization;
> +const AVCRC *crc;
> +uint8_t *table;
> +uint8_t *swapbuf;
> +};
> +
> +#define ENTRY_PSL(entry) (entry)
> +#define ENTRY_OCC(entry) (ENTRY_PSL(entry) + FFALIGN(sizeof(size_t),
> ALIGN))
> +#define ENTRY_KEY(entry) (ENTRY_OCC(entry) + FFALIGN(sizeof(size_t),
> ALIGN))
> +#define ENTRY_VAL(entry) (ENTRY_KEY(entry) + ctx->key_size_aligned)
> +
> +#define KEYS_EQUAL(k1, k2) !memcmp(k1, k2, ctx->key_size)
> +
> +int av_hashtable_alloc(struct AVHashtableContext **ctx, size_t key_size,
> size_t val_size, size_t max_entries)
> +{
> +struct AVHashtableContext *res = av_malloc(sizeof(struct
> AVHashtableContext));
> +if (!res)
> +return AVERROR(ENOMEM);
> +res->key_size = key_size;
> +res->key_size_aligned = FFALIGN(key_size, ALIGN);
> +res->val_size = val_size;
> +res->val_size_aligned = FFALIGN(val_size, ALIGN);
> +res->entry_size = FFALIGN(sizeof(size_t), ALIGN)
> ++ FFALIGN(sizeof(size_t), ALIGN)
> ++ res->key_size_aligned
> ++ res->val_size_aligned;
> +res->max_entries = max_entries;
> +res->utilization = 0;
> +res->crc = av_crc_get_table(AV_CRC_32_IEEE);
> +if (!res->crc) {
> +av_hashtable_freep(&re

[FFmpeg-devel] [PATCH] Add DXV encoder with support for DXT1 texture format

2024-01-17 Thread Connor Worley

Signed-off-by: Connor Worley 
---
 Changelog |   1 +
 configure |   1 +
 doc/general_contents.texi |   3 +-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/dxvenc.c   | 362 ++
 libavcodec/version.h  |   2 +-
 7 files changed, 369 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/dxvenc.c

diff --git a/Changelog b/Changelog
index 5b2899d05b..224d84664a 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to 
youngest within each release,

 releases are sorted from youngest to oldest.
  version :
+- DXV DXT1 encoder
 - LEAD MCMP decoder
 - EVC decoding using external library libxevd
 - EVC encoding using external library libxeve
diff --git a/configure b/configure
index c8ae0a061d..21663000f8 100755
--- a/configure
+++ b/configure
@@ -2851,6 +2851,7 @@ dvvideo_decoder_select="dvprofile idctdsp"
 dvvideo_encoder_select="dvprofile fdctdsp me_cmp pixblockdsp"
 dxa_decoder_deps="zlib"
 dxv_decoder_select="lzf texturedsp"
+dxv_encoder_select="texturedspenc"
 eac3_decoder_select="ac3_decoder"
 eac3_encoder_select="ac3_encoder"
 eamad_decoder_select="aandcttables blockdsp bswapdsp"
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 8b48fed060..f269cbd1a9 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -670,7 +670,8 @@ library:
 @item Redirector@tab   @tab X
 @item RedSpark  @tab   @tab X
 @item Renderware TeXture Dictionary @tab   @tab X
-@item Resolume DXV  @tab   @tab X
+@item Resolume DXV  @tab X @tab X
+@tab Encoding is only supported for the DXT1 (Normal Quality, No 
Alpha) texture format.

 @item RF64  @tab   @tab X
 @item RL2   @tab   @tab X
 @tab Audio and video format used in some games by Entertainment 
Software Partners.

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index bb42095165..96361ac794 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -341,6 +341,7 @@ OBJS-$(CONFIG_DVVIDEO_ENCODER) += dvenc.o 
dv.o dvdata.o

 OBJS-$(CONFIG_DXA_DECODER) += dxa.o
 OBJS-$(CONFIG_DXTORY_DECODER)  += dxtory.o
 OBJS-$(CONFIG_DXV_DECODER) += dxv.o
+OBJS-$(CONFIG_DXV_ENCODER) += dxvenc.o
 OBJS-$(CONFIG_EAC3_DECODER)+= eac3_data.o
 OBJS-$(CONFIG_EAC3_ENCODER)+= eac3enc.o eac3_data.o
 OBJS-$(CONFIG_EACMV_DECODER)   += eacmv.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 93ce8e3224..ef8c3a6d7d 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -106,6 +106,7 @@ extern const FFCodec ff_dvvideo_encoder;
 extern const FFCodec ff_dvvideo_decoder;
 extern const FFCodec ff_dxa_decoder;
 extern const FFCodec ff_dxtory_decoder;
+extern const FFCodec ff_dxv_encoder;
 extern const FFCodec ff_dxv_decoder;
 extern const FFCodec ff_eacmv_decoder;
 extern const FFCodec ff_eamad_decoder;
diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
new file mode 100644
index 00..36ee06699d
--- /dev/null
+++ b/libavcodec/dxvenc.c
@@ -0,0 +1,362 @@
+/*
+ * Resolume DXV encoder
+ * Copyright (C) 2015 Vittorio Giovara 
+ * Copyright (C) 2015 Tom Butterworth 
+ * Copyright (C) 2018 Paul B Mahol
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
02110-1301 USA

+ */
+
+#include 
+
+#include "libavutil/crc.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+
+#include "mathops.h"
+#include "avcodec.h"
+#include "bytestream.h"
+#include "codec_internal.h"
+#include "encode.h"
+#include "lzf.h"
+#include "texturedsp.h"
+#include "thread.h"
+
+#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_WORDS0x20202
+
+enum DXVTextureFormat {
+DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
+};
+
+typedef struct HTEntry {
+uint32_t key;
+uint32_t pos;
+} HTEntry;
+
+static void ht_init(HTEntry *ht)
+{
+for (

[FFmpeg-devel] [PATCH] Add DXV encoder with support for DXT1 texture format

2024-01-17 Thread Connor Worley

Signed-off-by: Connor Worley 
---
 Changelog |   1 +
 configure |   1 +
 doc/general_contents.texi |   3 +-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/dxvenc.c   | 362 ++
 libavcodec/version.h  |   2 +-
 7 files changed, 369 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/dxvenc.c

diff --git a/Changelog b/Changelog
index 5b2899d05b..224d84664a 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest 
within each release,
 releases are sorted from youngest to oldest.
 
 version :

+- DXV DXT1 encoder
 - LEAD MCMP decoder
 - EVC decoding using external library libxevd
 - EVC encoding using external library libxeve
diff --git a/configure b/configure
index c8ae0a061d..21663000f8 100755
--- a/configure
+++ b/configure
@@ -2851,6 +2851,7 @@ dvvideo_decoder_select="dvprofile idctdsp"
 dvvideo_encoder_select="dvprofile fdctdsp me_cmp pixblockdsp"
 dxa_decoder_deps="zlib"
 dxv_decoder_select="lzf texturedsp"
+dxv_encoder_select="texturedspenc"
 eac3_decoder_select="ac3_decoder"
 eac3_encoder_select="ac3_encoder"
 eamad_decoder_select="aandcttables blockdsp bswapdsp"
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 8b48fed060..f269cbd1a9 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -670,7 +670,8 @@ library:
 @item Redirector@tab   @tab X
 @item RedSpark  @tab   @tab X
 @item Renderware TeXture Dictionary @tab   @tab X
-@item Resolume DXV  @tab   @tab X
+@item Resolume DXV  @tab X @tab X
+@tab Encoding is only supported for the DXT1 (Normal Quality, No Alpha) 
texture format.
 @item RF64  @tab   @tab X
 @item RL2   @tab   @tab X
 @tab Audio and video format used in some games by Entertainment Software 
Partners.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index bb42095165..96361ac794 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -341,6 +341,7 @@ OBJS-$(CONFIG_DVVIDEO_ENCODER) += dvenc.o dv.o 
dvdata.o
 OBJS-$(CONFIG_DXA_DECODER) += dxa.o
 OBJS-$(CONFIG_DXTORY_DECODER)  += dxtory.o
 OBJS-$(CONFIG_DXV_DECODER) += dxv.o
+OBJS-$(CONFIG_DXV_ENCODER) += dxvenc.o
 OBJS-$(CONFIG_EAC3_DECODER)+= eac3_data.o
 OBJS-$(CONFIG_EAC3_ENCODER)+= eac3enc.o eac3_data.o
 OBJS-$(CONFIG_EACMV_DECODER)   += eacmv.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 93ce8e3224..ef8c3a6d7d 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -106,6 +106,7 @@ extern const FFCodec ff_dvvideo_encoder;
 extern const FFCodec ff_dvvideo_decoder;
 extern const FFCodec ff_dxa_decoder;
 extern const FFCodec ff_dxtory_decoder;
+extern const FFCodec ff_dxv_encoder;
 extern const FFCodec ff_dxv_decoder;
 extern const FFCodec ff_eacmv_decoder;
 extern const FFCodec ff_eamad_decoder;
diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
new file mode 100644
index 00..36ee06699d
--- /dev/null
+++ b/libavcodec/dxvenc.c
@@ -0,0 +1,362 @@
+/*
+ * Resolume DXV encoder
+ * Copyright (C) 2015 Vittorio Giovara 
+ * Copyright (C) 2015 Tom Butterworth 
+ * Copyright (C) 2018 Paul B Mahol
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/crc.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+
+#include "mathops.h"
+#include "avcodec.h"
+#include "bytestream.h"
+#include "codec_internal.h"
+#include "encode.h"
+#include "lzf.h"
+#include "texturedsp.h"
+#include "thread.h"
+
+#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_WORDS0x20202
+
+enum DXVTextureFormat {
+DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
+};
+
+typedef struct HTEntry {
+uint32_t key;
+uint32_t pos;
+} HTEntry;
+
+static void ht_init(HTEntry *ht)
+{
+for (size

Re: [FFmpeg-devel] [PATCH] Add DXV encoder with support for DXT1 texture format

2024-01-17 Thread Connor Worley

On 1/17/24 08:55, Connor Worley wrote:


Signed-off-by: Connor Worley 
---
 Changelog |   1 +
 configure |   1 +
 doc/general_contents.texi |   3 +-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c    |   1 +
 libavcodec/dxvenc.c   | 362 ++
 libavcodec/version.h  |   2 +-
 7 files changed, 369 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/dxvenc.c

diff --git a/Changelog b/Changelog
index 5b2899d05b..224d84664a 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest 
within each release,
 releases are sorted from youngest to oldest.

 version :
+- DXV DXT1 encoder
 - LEAD MCMP decoder
 - EVC decoding using external library libxevd
 - EVC encoding using external library libxeve
diff --git a/configure b/configure
index c8ae0a061d..21663000f8 100755
--- a/configure
+++ b/configure
@@ -2851,6 +2851,7 @@ dvvideo_decoder_select="dvprofile idctdsp"
 dvvideo_encoder_select="dvprofile fdctdsp me_cmp pixblockdsp"
 dxa_decoder_deps="zlib"
 dxv_decoder_select="lzf texturedsp"
+dxv_encoder_select="texturedspenc"
 eac3_decoder_select="ac3_decoder"
 eac3_encoder_select="ac3_encoder"
 eamad_decoder_select="aandcttables blockdsp bswapdsp"
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 8b48fed060..f269cbd1a9 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -670,7 +670,8 @@ library:
 @item Redirector    @tab   @tab X
 @item RedSpark  @tab   @tab X
 @item Renderware TeXture Dictionary @tab   @tab X
-@item Resolume DXV  @tab   @tab X
+@item Resolume DXV  @tab X @tab X
+    @tab Encoding is only supported for the DXT1 (Normal Quality, No Alpha) 
texture format.
 @item RF64  @tab   @tab X
 @item RL2   @tab   @tab X
 @tab Audio and video format used in some games by Entertainment Software 
Partners.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index bb42095165..96361ac794 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -341,6 +341,7 @@ OBJS-$(CONFIG_DVVIDEO_ENCODER) += dvenc.o dv.o 
dvdata.o
 OBJS-$(CONFIG_DXA_DECODER) += dxa.o
 OBJS-$(CONFIG_DXTORY_DECODER)  += dxtory.o
 OBJS-$(CONFIG_DXV_DECODER) += dxv.o
+OBJS-$(CONFIG_DXV_ENCODER) += dxvenc.o
 OBJS-$(CONFIG_EAC3_DECODER)    += eac3_data.o
 OBJS-$(CONFIG_EAC3_ENCODER)    += eac3enc.o eac3_data.o
 OBJS-$(CONFIG_EACMV_DECODER)   += eacmv.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 93ce8e3224..ef8c3a6d7d 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -106,6 +106,7 @@ extern const FFCodec ff_dvvideo_encoder;
 extern const FFCodec ff_dvvideo_decoder;
 extern const FFCodec ff_dxa_decoder;
 extern const FFCodec ff_dxtory_decoder;
+extern const FFCodec ff_dxv_encoder;
 extern const FFCodec ff_dxv_decoder;
 extern const FFCodec ff_eacmv_decoder;
 extern const FFCodec ff_eamad_decoder;
diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
new file mode 100644
index 00..36ee06699d
--- /dev/null
+++ b/libavcodec/dxvenc.c
@@ -0,0 +1,362 @@
+/*
+ * Resolume DXV encoder
+ * Copyright (C) 2015 Vittorio Giovara 
+ * Copyright (C) 2015 Tom Butterworth 
+ * Copyright (C) 2018 Paul B Mahol
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/crc.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+
+#include "mathops.h"
+#include "avcodec.h"
+#include "bytestream.h"
+#include "codec_internal.h"
+#include "encode.h"
+#include "lzf.h"
+#include "texturedsp.h"
+#include "thread.h"
+
+#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_WORDS    0x20202
+
+enum DXVTextureFormat {
+    DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
+};
+
+typedef struct HTEntry {
+    uint32_t key;
+    uint32_t pos;
+} HTEntry;
+
+static voi

[FFmpeg-devel] [PATCH] Add DXV encoder with support for DXT1 texture format

2024-01-17 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 Changelog |   1 +
 configure |   1 +
 doc/general_contents.texi |   3 +-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/dxvenc.c   | 358 ++
 libavcodec/version.h  |   2 +-
 7 files changed, 365 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/dxvenc.c

diff --git a/Changelog b/Changelog
index 5b2899d05b..224d84664a 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest 
within each release,
 releases are sorted from youngest to oldest.
 
 version :
+- DXV DXT1 encoder
 - LEAD MCMP decoder
 - EVC decoding using external library libxevd
 - EVC encoding using external library libxeve
diff --git a/configure b/configure
index c8ae0a061d..21663000f8 100755
--- a/configure
+++ b/configure
@@ -2851,6 +2851,7 @@ dvvideo_decoder_select="dvprofile idctdsp"
 dvvideo_encoder_select="dvprofile fdctdsp me_cmp pixblockdsp"
 dxa_decoder_deps="zlib"
 dxv_decoder_select="lzf texturedsp"
+dxv_encoder_select="texturedspenc"
 eac3_decoder_select="ac3_decoder"
 eac3_encoder_select="ac3_encoder"
 eamad_decoder_select="aandcttables blockdsp bswapdsp"
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 8b48fed060..f269cbd1a9 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -670,7 +670,8 @@ library:
 @item Redirector@tab   @tab X
 @item RedSpark  @tab   @tab X
 @item Renderware TeXture Dictionary @tab   @tab X
-@item Resolume DXV  @tab   @tab X
+@item Resolume DXV  @tab X @tab X
+@tab Encoding is only supported for the DXT1 (Normal Quality, No Alpha) 
texture format.
 @item RF64  @tab   @tab X
 @item RL2   @tab   @tab X
 @tab Audio and video format used in some games by Entertainment Software 
Partners.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index bb42095165..96361ac794 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -341,6 +341,7 @@ OBJS-$(CONFIG_DVVIDEO_ENCODER) += dvenc.o dv.o 
dvdata.o
 OBJS-$(CONFIG_DXA_DECODER) += dxa.o
 OBJS-$(CONFIG_DXTORY_DECODER)  += dxtory.o
 OBJS-$(CONFIG_DXV_DECODER) += dxv.o
+OBJS-$(CONFIG_DXV_ENCODER) += dxvenc.o
 OBJS-$(CONFIG_EAC3_DECODER)+= eac3_data.o
 OBJS-$(CONFIG_EAC3_ENCODER)+= eac3enc.o eac3_data.o
 OBJS-$(CONFIG_EACMV_DECODER)   += eacmv.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 93ce8e3224..ef8c3a6d7d 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -106,6 +106,7 @@ extern const FFCodec ff_dvvideo_encoder;
 extern const FFCodec ff_dvvideo_decoder;
 extern const FFCodec ff_dxa_decoder;
 extern const FFCodec ff_dxtory_decoder;
+extern const FFCodec ff_dxv_encoder;
 extern const FFCodec ff_dxv_decoder;
 extern const FFCodec ff_eacmv_decoder;
 extern const FFCodec ff_eamad_decoder;
diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
new file mode 100644
index 00..33080fa1c9
--- /dev/null
+++ b/libavcodec/dxvenc.c
@@ -0,0 +1,358 @@
+/*
+ * Resolume DXV encoder
+ * Copyright (C) 2015 Vittorio Giovara 
+ * Copyright (C) 2015 Tom Butterworth 
+ * Copyright (C) 2018 Paul B Mahol
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/crc.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+
+#include "bytestream.h"
+#include "codec_internal.h"
+#include "encode.h"
+#include "texturedsp.h"
+
+#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_WORDS0x20202
+
+enum DXVTextureFormat {
+DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
+};
+
+typedef struct HTEntry {
+uint32_t key;
+uint32_t pos;
+} HTEntry;
+
+static void ht_init(HTEntry *ht)
+{
+for (size_t i = 0; i < LOOKBACK_HT_ELEMS; i++) {
+ht[i].pos = -1;
+}
+}
+
+static uint32_t ht_lookup_and_upsert(HTEntr

[FFmpeg-devel] [PATCH] lavc/dxvenc: add DXV encoder with support for DXT1 texture format

2024-01-18 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 Changelog |   1 +
 configure |   1 +
 doc/general_contents.texi |   3 +-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/dxvenc.c   | 358 ++
 libavcodec/version.h  |   2 +-
 7 files changed, 365 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/dxvenc.c

diff --git a/Changelog b/Changelog
index 5b2899d05b..224d84664a 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest 
within each release,
 releases are sorted from youngest to oldest.
 
 version :
+- DXV DXT1 encoder
 - LEAD MCMP decoder
 - EVC decoding using external library libxevd
 - EVC encoding using external library libxeve
diff --git a/configure b/configure
index c8ae0a061d..21663000f8 100755
--- a/configure
+++ b/configure
@@ -2851,6 +2851,7 @@ dvvideo_decoder_select="dvprofile idctdsp"
 dvvideo_encoder_select="dvprofile fdctdsp me_cmp pixblockdsp"
 dxa_decoder_deps="zlib"
 dxv_decoder_select="lzf texturedsp"
+dxv_encoder_select="texturedspenc"
 eac3_decoder_select="ac3_decoder"
 eac3_encoder_select="ac3_encoder"
 eamad_decoder_select="aandcttables blockdsp bswapdsp"
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 8b48fed060..f269cbd1a9 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -670,7 +670,8 @@ library:
 @item Redirector@tab   @tab X
 @item RedSpark  @tab   @tab X
 @item Renderware TeXture Dictionary @tab   @tab X
-@item Resolume DXV  @tab   @tab X
+@item Resolume DXV  @tab X @tab X
+@tab Encoding is only supported for the DXT1 (Normal Quality, No Alpha) 
texture format.
 @item RF64  @tab   @tab X
 @item RL2   @tab   @tab X
 @tab Audio and video format used in some games by Entertainment Software 
Partners.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index bb42095165..96361ac794 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -341,6 +341,7 @@ OBJS-$(CONFIG_DVVIDEO_ENCODER) += dvenc.o dv.o 
dvdata.o
 OBJS-$(CONFIG_DXA_DECODER) += dxa.o
 OBJS-$(CONFIG_DXTORY_DECODER)  += dxtory.o
 OBJS-$(CONFIG_DXV_DECODER) += dxv.o
+OBJS-$(CONFIG_DXV_ENCODER) += dxvenc.o
 OBJS-$(CONFIG_EAC3_DECODER)+= eac3_data.o
 OBJS-$(CONFIG_EAC3_ENCODER)+= eac3enc.o eac3_data.o
 OBJS-$(CONFIG_EACMV_DECODER)   += eacmv.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 93ce8e3224..ef8c3a6d7d 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -106,6 +106,7 @@ extern const FFCodec ff_dvvideo_encoder;
 extern const FFCodec ff_dvvideo_decoder;
 extern const FFCodec ff_dxa_decoder;
 extern const FFCodec ff_dxtory_decoder;
+extern const FFCodec ff_dxv_encoder;
 extern const FFCodec ff_dxv_decoder;
 extern const FFCodec ff_eacmv_decoder;
 extern const FFCodec ff_eamad_decoder;
diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
new file mode 100644
index 00..33080fa1c9
--- /dev/null
+++ b/libavcodec/dxvenc.c
@@ -0,0 +1,358 @@
+/*
+ * Resolume DXV encoder
+ * Copyright (C) 2015 Vittorio Giovara 
+ * Copyright (C) 2015 Tom Butterworth 
+ * Copyright (C) 2018 Paul B Mahol
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/crc.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+
+#include "bytestream.h"
+#include "codec_internal.h"
+#include "encode.h"
+#include "texturedsp.h"
+
+#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_WORDS0x20202
+
+enum DXVTextureFormat {
+DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
+};
+
+typedef struct HTEntry {
+uint32_t key;
+uint32_t pos;
+} HTEntry;
+
+static void ht_init(HTEntry *ht)
+{
+for (size_t i = 0; i < LOOKBACK_HT_ELEMS; i++) {
+ht[i].pos = -1;
+}
+}
+
+static uint32_t ht_lookup_and_upsert(HTEntr

Re: [FFmpeg-devel] [PATCH] Add DXV encoder with support for DXT1 texture format

2024-01-19 Thread Connor Worley
Thanks for the feedback! For the next revision, is it preferred to reply to 
this thread or create a new one?

On 1/19/24 08:23, Vittorio Giovara wrote:
>> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
>> index 93ce8e3224..ef8c3a6d7d 100644
>> --- a/libavcodec/allcodecs.c
>> +++ b/libavcodec/allcodecs.c
>> @@ -106,6 +106,7 @@ extern const FFCodec ff_dvvideo_encoder;
>>  extern const FFCodec ff_dvvideo_decoder;
>>  extern const FFCodec ff_dxa_decoder;
>>  extern const FFCodec ff_dxtory_decoder;
>> +extern const FFCodec ff_dxv_encoder;
>>  extern const FFCodec ff_dxv_decoder;
>>
> nit: keep list in order


Not sure what you mean, the present order seems to be encoder followed by 
decoder for codecs that have both.

>>  extern const FFCodec ff_eacmv_decoder;
>>  extern const FFCodec ff_eamad_decoder;
>> diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
>> new file mode 100644
>> index 00..33080fa1c9
>> --- /dev/null
>> +++ b/libavcodec/dxvenc.c
>> @@ -0,0 +1,358 @@
>> +/*
>> + * Resolume DXV encoder
>> + * Copyright (C) 2015 Vittorio Giovara 
>> + * Copyright (C) 2015 Tom Butterworth 
>> + * Copyright (C) 2018 Paul B Mahol
>> + * Copyright (C) 2024 Connor Worley 
>>
> Idk about tom or paul, but I haven't done anything for this encoder :)
> I think you can prune the list of copyright quite a bit here


Got it. I copied some code verbatim from dxv.c and hapenc.c and erred on the 
side of overcrediting.


>> +#define LOOKBACK_HT_ELEMS 0x4
>>
> What does the HT stand for?


Hash table --  this change implements a simple linear probing approach.

>> +#define LOOKBACK_WORDS0x20202
>> +
>> +enum DXVTextureFormat {
>> +DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
>> +};
>>
> Why would you go for an enum here? Just for future expansion and the switch
> case below?


Exactly, that's the plan.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] lavc/dxvenc: add DXV encoder with support for DXT1 texture format

2024-01-19 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 Changelog |   1 +
 configure |   1 +
 doc/general_contents.texi |   3 +-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/dxvenc.c   | 361 ++
 libavcodec/version.h  |   2 +-
 7 files changed, 368 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/dxvenc.c

diff --git a/Changelog b/Changelog
index 5b2899d05b..224d84664a 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest 
within each release,
 releases are sorted from youngest to oldest.
 
 version :
+- DXV DXT1 encoder
 - LEAD MCMP decoder
 - EVC decoding using external library libxevd
 - EVC encoding using external library libxeve
diff --git a/configure b/configure
index c8ae0a061d..21663000f8 100755
--- a/configure
+++ b/configure
@@ -2851,6 +2851,7 @@ dvvideo_decoder_select="dvprofile idctdsp"
 dvvideo_encoder_select="dvprofile fdctdsp me_cmp pixblockdsp"
 dxa_decoder_deps="zlib"
 dxv_decoder_select="lzf texturedsp"
+dxv_encoder_select="texturedspenc"
 eac3_decoder_select="ac3_decoder"
 eac3_encoder_select="ac3_encoder"
 eamad_decoder_select="aandcttables blockdsp bswapdsp"
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 8b48fed060..f269cbd1a9 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -670,7 +670,8 @@ library:
 @item Redirector@tab   @tab X
 @item RedSpark  @tab   @tab X
 @item Renderware TeXture Dictionary @tab   @tab X
-@item Resolume DXV  @tab   @tab X
+@item Resolume DXV  @tab X @tab X
+@tab Encoding is only supported for the DXT1 (Normal Quality, No Alpha) 
texture format.
 @item RF64  @tab   @tab X
 @item RL2   @tab   @tab X
 @tab Audio and video format used in some games by Entertainment Software 
Partners.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index bb42095165..96361ac794 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -341,6 +341,7 @@ OBJS-$(CONFIG_DVVIDEO_ENCODER) += dvenc.o dv.o 
dvdata.o
 OBJS-$(CONFIG_DXA_DECODER) += dxa.o
 OBJS-$(CONFIG_DXTORY_DECODER)  += dxtory.o
 OBJS-$(CONFIG_DXV_DECODER) += dxv.o
+OBJS-$(CONFIG_DXV_ENCODER) += dxvenc.o
 OBJS-$(CONFIG_EAC3_DECODER)+= eac3_data.o
 OBJS-$(CONFIG_EAC3_ENCODER)+= eac3enc.o eac3_data.o
 OBJS-$(CONFIG_EACMV_DECODER)   += eacmv.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 93ce8e3224..ef8c3a6d7d 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -106,6 +106,7 @@ extern const FFCodec ff_dvvideo_encoder;
 extern const FFCodec ff_dvvideo_decoder;
 extern const FFCodec ff_dxa_decoder;
 extern const FFCodec ff_dxtory_decoder;
+extern const FFCodec ff_dxv_encoder;
 extern const FFCodec ff_dxv_decoder;
 extern const FFCodec ff_eacmv_decoder;
 extern const FFCodec ff_eamad_decoder;
diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
new file mode 100644
index 00..3a5b310c9b
--- /dev/null
+++ b/libavcodec/dxvenc.c
@@ -0,0 +1,361 @@
+/*
+ * Resolume DXV encoder
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/crc.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+
+#include "bytestream.h"
+#include "codec_internal.h"
+#include "encode.h"
+#include "texturedsp.h"
+
+#define DXV_HEADER_LENGTH 12
+
+/*
+ * DXV uses LZ-like back-references to avoid copying words that have already
+ * appeared in the decompressed stream. Using a simple hash table (HT)
+ * significantly speeds up the lookback process while encoding.
+ */
+#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_WORDS0x20202
+
+enum DXVTextureFormat {
+DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
+};
+
+typedef struct HTEntry {
+uint32_t key;
+uint32_t pos;
+} HTEntry;
+
+sta

Re: [FFmpeg-devel] [PATCH v2] lavc/dxvenc: add DXV encoder with support for DXT1 texture format

2024-01-19 Thread Connor Worley
I've tested the latest patch with both the lavc decoder and Resolume's 
proprietary software, and the encoded outputs are working for me.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] fate/video: add DXV3 HQ tests

2024-01-23 Thread Connor Worley
Adds tests to cover decoding YCoCg DXV3 formats with and without alpha

Samples:
https://connorworley.com/fate-suite/dxv/dxv3-hqna.mov
https://connorworley.com/fate-suite/dxv/dxv3-hqwa.mov
Signed-off-by: Connor Worley 
---
 tests/fate/video.mak | 6 ++
 tests/ref/fate/dxv3-ycg6 | 6 ++
 tests/ref/fate/dxv3-yg10 | 6 ++
 3 files changed, 18 insertions(+)
 create mode 100644 tests/ref/fate/dxv3-ycg6
 create mode 100644 tests/ref/fate/dxv3-yg10

diff --git a/tests/fate/video.mak b/tests/fate/video.mak
index 4e7a77537f..85a166ebdd 100644
--- a/tests/fate/video.mak
+++ b/tests/fate/video.mak
@@ -152,6 +152,12 @@ fate-dxv3-dxt1: CMD = framecrc -i 
$(TARGET_SAMPLES)/dxv/dxv3-nqna.mov
 FATE_DXV += fate-dxv3-dxt5
 fate-dxv3-dxt5: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-nqwa.mov
 
+FATE_DXV += fate-dxv3-ycg6
+fate-dxv3-ycg6: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-hqna.mov
+
+FATE_DXV += fate-dxv3-yg10
+fate-dxv3-yg10: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-hqwa.mov
+
 FATE_VIDEO-$(call FRAMECRC, MOV, DXV) += $(FATE_DXV)
 fate-dxv: $(FATE_DXV)
 
diff --git a/tests/ref/fate/dxv3-ycg6 b/tests/ref/fate/dxv3-ycg6
new file mode 100644
index 00..63c614fbaf
--- /dev/null
+++ b/tests/ref/fate/dxv3-ycg6
@@ -0,0 +1,6 @@
+#tb 0: 1/30
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 1920x1080
+#sar 0: 0/1
+0,  0,  0,1,  3110400, 0x1e979f00
diff --git a/tests/ref/fate/dxv3-yg10 b/tests/ref/fate/dxv3-yg10
new file mode 100644
index 00..30e122e4d5
--- /dev/null
+++ b/tests/ref/fate/dxv3-yg10
@@ -0,0 +1,6 @@
+#tb 0: 1/30
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 1920x1080
+#sar 0: 0/1
+0,  0,  0,1,  5184000, 0xe5f0d3da
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] fate/video: add DXV3 DXT1 encoding test

2024-01-24 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 tests/fate/video.mak| 7 +++
 tests/ref/fate/dxv3enc-dxt1 | 6 ++
 2 files changed, 13 insertions(+)
 create mode 100644 tests/ref/fate/dxv3enc-dxt1

diff --git a/tests/fate/video.mak b/tests/fate/video.mak
index 4e7a77537f..fbc8a1a682 100644
--- a/tests/fate/video.mak
+++ b/tests/fate/video.mak
@@ -155,6 +155,13 @@ fate-dxv3-dxt5: CMD = framecrc -i 
$(TARGET_SAMPLES)/dxv/dxv3-nqwa.mov
 FATE_VIDEO-$(call FRAMECRC, MOV, DXV) += $(FATE_DXV)
 fate-dxv: $(FATE_DXV)
 
+fate-dxv3enc%: FMT = $(word 3, $(subst -, ,$(@)))
+fate-dxv3enc%: CMD = framecrc -lavfi testsrc2=duration=1:rate=1:size=1920x1080 
-c:v dxv -format $(FMT)
+
+FATE_DXVENC_FMT = dxt1
+FATE_VIDEO-$(call FILTERFRAMECRC, TESTSRC2, DXV_ENCODER) += 
$(FATE_DXVENC_FMT:%=fate-dxv3enc-%)
+fate-dxvenc: $(FATE_DXVENC_FMT:%=fate-dxv3enc-%)
+
 FATE_VIDEO-$(call FRAMECRC, SEGAFILM, CINEPAK) += fate-film-cvid
 fate-film-cvid: CMD = framecrc -i $(TARGET_SAMPLES)/film/logo-capcom.cpk -an
 
diff --git a/tests/ref/fate/dxv3enc-dxt1 b/tests/ref/fate/dxv3enc-dxt1
new file mode 100644
index 00..3cfd73397e
--- /dev/null
+++ b/tests/ref/fate/dxv3enc-dxt1
@@ -0,0 +1,6 @@
+#tb 0: 1/1
+#media_type 0: video
+#codec_id 0: dxv
+#dimensions 0: 1920x1080
+#sar 0: 1/1
+0,  0,  0,1,76767, 0x932ecbfa
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] fate/video: add DXV3 HQ tests

2024-01-24 Thread Connor Worley
Adds tests to cover decoding YCoCg DXV3 formats with and without alpha

Samples:
https://connorworley.com/fate-suite/dxv/dxv3-hqna.mov
https://connorworley.com/fate-suite/dxv/dxv3-hqwa.mov
Signed-off-by: Connor Worley 
---
 tests/fate/video.mak | 6 ++
 tests/ref/fate/dxv3-ycg6 | 6 ++
 tests/ref/fate/dxv3-yg10 | 6 ++
 3 files changed, 18 insertions(+)
 create mode 100644 tests/ref/fate/dxv3-ycg6
 create mode 100644 tests/ref/fate/dxv3-yg10

diff --git a/tests/fate/video.mak b/tests/fate/video.mak
index fbc8a1a682..8f51a42077 100644
--- a/tests/fate/video.mak
+++ b/tests/fate/video.mak
@@ -152,6 +152,12 @@ fate-dxv3-dxt1: CMD = framecrc -i 
$(TARGET_SAMPLES)/dxv/dxv3-nqna.mov
 FATE_DXV += fate-dxv3-dxt5
 fate-dxv3-dxt5: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-nqwa.mov
 
+FATE_DXV += fate-dxv3-ycg6
+fate-dxv3-ycg6: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-hqna.mov
+
+FATE_DXV += fate-dxv3-yg10
+fate-dxv3-yg10: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-hqwa.mov
+
 FATE_VIDEO-$(call FRAMECRC, MOV, DXV) += $(FATE_DXV)
 fate-dxv: $(FATE_DXV)
 
diff --git a/tests/ref/fate/dxv3-ycg6 b/tests/ref/fate/dxv3-ycg6
new file mode 100644
index 00..63c614fbaf
--- /dev/null
+++ b/tests/ref/fate/dxv3-ycg6
@@ -0,0 +1,6 @@
+#tb 0: 1/30
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 1920x1080
+#sar 0: 0/1
+0,  0,  0,1,  3110400, 0x1e979f00
diff --git a/tests/ref/fate/dxv3-yg10 b/tests/ref/fate/dxv3-yg10
new file mode 100644
index 00..30e122e4d5
--- /dev/null
+++ b/tests/ref/fate/dxv3-yg10
@@ -0,0 +1,6 @@
+#tb 0: 1/30
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 1920x1080
+#sar 0: 0/1
+0,  0,  0,1,  5184000, 0xe5f0d3da
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/7] avcodec/dxvenc: Don't cast const away

2024-01-24 Thread Connor Worley
Thanks for fixing this :)
Are you planning more work on the DXV side following this? I have a patch
to follow that replaces `decompress_texture_thread` with purely
texdsp calls (HQ BC4/BC5 textures can be decompressed with
`rgtc1u_gray_block`).

On Wed, Jan 24, 2024 at 11:49 AM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/dxvenc.c | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
> index 3a5b310c9b..10473038cc 100644
> --- a/libavcodec/dxvenc.c
> +++ b/libavcodec/dxvenc.c
> @@ -56,7 +56,7 @@ static void ht_init(HTEntry *ht)
>  }
>  }
>
> -static uint32_t ht_lookup_and_upsert(HTEntry *ht, AVCRC *hash_ctx,
> +static uint32_t ht_lookup_and_upsert(HTEntry *ht, const AVCRC *hash_ctx,
>  uint32_t key, uint32_t pos)
>  {
>  uint32_t ret = -1;
> @@ -74,7 +74,7 @@ static uint32_t ht_lookup_and_upsert(HTEntry *ht, AVCRC
> *hash_ctx,
>  return ret;
>  }
>
> -static void ht_delete(HTEntry *ht, AVCRC *hash_ctx,
> +static void ht_delete(HTEntry *ht, const AVCRC *hash_ctx,
>uint32_t key, uint32_t pos)
>  {
>  HTEntry *removed_entry = NULL;
> @@ -124,7 +124,7 @@ typedef struct DXVEncContext {
>  enum DXVTextureFormat tex_fmt;
>  int (*compress_tex)(AVCodecContext *avctx);
>
> -AVCRC *crc_ctx;
> +const AVCRC *crc_ctx;
>
>  HTEntry color_lookback_ht[LOOKBACK_HT_ELEMS];
>  HTEntry lut_lookback_ht[LOOKBACK_HT_ELEMS];
> @@ -309,7 +309,7 @@ static av_cold int dxv_init(AVCodecContext *avctx)
>  return AVERROR(ENOMEM);
>  }
>
> -ctx->crc_ctx = (AVCRC*)av_crc_get_table(AV_CRC_32_IEEE);
> +ctx->crc_ctx = av_crc_get_table(AV_CRC_32_IEEE);
>  if (!ctx->crc_ctx) {
>  av_log(avctx, AV_LOG_ERROR, "Could not initialize CRC table.\n");
>  return AVERROR_BUG;
> --
> 2.34.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-requ...@ffmpeg.org with subject "unsubscribe".
>


-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/7] avcodec/dxvenc: Don't cast const away

2024-01-26 Thread Connor Worley
I tested against
https://patchwork.ffmpeg.org/project/ffmpeg/list/?series=10566, seems happy.

On Fri, Jan 26, 2024 at 10:58 AM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Andreas Rheinhardt:
> > Signed-off-by: Andreas Rheinhardt 
> > ---
> >  libavcodec/dxvenc.c | 8 
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
> > index 3a5b310c9b..10473038cc 100644
> > --- a/libavcodec/dxvenc.c
> > +++ b/libavcodec/dxvenc.c
> > @@ -56,7 +56,7 @@ static void ht_init(HTEntry *ht)
> >  }
> >  }
> >
> > -static uint32_t ht_lookup_and_upsert(HTEntry *ht, AVCRC *hash_ctx,
> > +static uint32_t ht_lookup_and_upsert(HTEntry *ht, const AVCRC *hash_ctx,
> >  uint32_t key, uint32_t pos)
> >  {
> >  uint32_t ret = -1;
> > @@ -74,7 +74,7 @@ static uint32_t ht_lookup_and_upsert(HTEntry *ht,
> AVCRC *hash_ctx,
> >  return ret;
> >  }
> >
> > -static void ht_delete(HTEntry *ht, AVCRC *hash_ctx,
> > +static void ht_delete(HTEntry *ht, const AVCRC *hash_ctx,
> >uint32_t key, uint32_t pos)
> >  {
> >  HTEntry *removed_entry = NULL;
> > @@ -124,7 +124,7 @@ typedef struct DXVEncContext {
> >  enum DXVTextureFormat tex_fmt;
> >  int (*compress_tex)(AVCodecContext *avctx);
> >
> > -AVCRC *crc_ctx;
> > +const AVCRC *crc_ctx;
> >
> >  HTEntry color_lookback_ht[LOOKBACK_HT_ELEMS];
> >  HTEntry lut_lookback_ht[LOOKBACK_HT_ELEMS];
> > @@ -309,7 +309,7 @@ static av_cold int dxv_init(AVCodecContext *avctx)
> >  return AVERROR(ENOMEM);
> >  }
> >
> > -ctx->crc_ctx = (AVCRC*)av_crc_get_table(AV_CRC_32_IEEE);
> > +ctx->crc_ctx = av_crc_get_table(AV_CRC_32_IEEE);
> >  if (!ctx->crc_ctx) {
> >  av_log(avctx, AV_LOG_ERROR, "Could not initialize CRC
> table.\n");
> >  return AVERROR_BUG;
>
> Will apply this patchset tomorrow unless there are objections.
>
> - Andreas
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>


-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/3] lavc/dxv: move tag definitions to common header

2024-01-28 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c|  9 +
 libavcodec/dxv.h| 34 ++
 libavcodec/dxvenc.c |  7 ++-
 3 files changed, 41 insertions(+), 9 deletions(-)
 create mode 100644 libavcodec/dxv.h

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 5923811b29..a2ae070984 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -28,6 +28,7 @@
 #include "avcodec.h"
 #include "bytestream.h"
 #include "codec_internal.h"
+#include "dxv.h"
 #include "lzf.h"
 #include "texturedsp.h"
 #include "thread.h"
@@ -1064,7 +1065,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 
 tag = bytestream2_get_le32(gbc);
 switch (tag) {
-case MKBETAG('D', 'X', 'T', '1'):
+case DXV_FMT_DXT1:
 decompress_tex = dxv_decompress_dxt1;
 ctx->tex_funct = ctx->texdsp.dxt1_block;
 ctx->tex_rat   = 8;
@@ -1072,7 +1073,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 msgcomp = "DXTR1";
 msgtext = "DXT1";
 break;
-case MKBETAG('D', 'X', 'T', '5'):
+case DXV_FMT_DXT5:
 decompress_tex = dxv_decompress_dxt5;
 ctx->tex_funct = ctx->texdsp.dxt5_block;
 ctx->tex_rat   = 4;
@@ -1080,7 +1081,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 msgcomp = "DXTR5";
 msgtext = "DXT5";
 break;
-case MKBETAG('Y', 'C', 'G', '6'):
+case DXV_FMT_YCG6:
 decompress_tex = dxv_decompress_ycg6;
 ctx->tex_funct_planar[0] = yo_block;
 ctx->tex_funct_planar[1] = cocg_block;
@@ -1097,7 +1098,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 avctx->colorspace = AVCOL_SPC_YCOCG;
 break;
-case MKBETAG('Y', 'G', '1', '0'):
+case DXV_FMT_YG10:
 decompress_tex = dxv_decompress_yg10;
     ctx->tex_funct_planar[0] = yao_block;
 ctx->tex_funct_planar[1] = cocg_block;
diff --git a/libavcodec/dxv.h b/libavcodec/dxv.h
new file mode 100644
index 00..71cfddec85
--- /dev/null
+++ b/libavcodec/dxv.h
@@ -0,0 +1,34 @@
+/*
+ * Resolume DXV common
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_DXV_H
+#define AVCODEC_DXV_H
+
+#include "libavutil/macros.h"
+
+typedef enum DXVTextureFormat {
+DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
+DXV_FMT_DXT5 = MKBETAG('D', 'X', 'T', '5'),
+DXV_FMT_YCG6 = MKBETAG('Y', 'C', 'G', '6'),
+DXV_FMT_YG10 = MKBETAG('Y', 'G', '1', '0'),
+} DXVTextureFormat;
+
+#endif /* AVCODEC_DXV_H */
diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index b274175689..6a67dd75d4 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -27,6 +27,7 @@
 
 #include "bytestream.h"
 #include "codec_internal.h"
+#include "dxv.h"
 #include "encode.h"
 #include "texturedsp.h"
 
@@ -40,10 +41,6 @@
 #define LOOKBACK_HT_ELEMS 0x4
 #define LOOKBACK_WORDS0x20202
 
-enum DXVTextureFormat {
-DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
-};
-
 typedef struct HTEntry {
 uint32_t key;
 uint32_t pos;
@@ -120,7 +117,7 @@ typedef struct DXVEncContext {
 
 TextureDSPThreadContext enc;
 
-enum DXVTextureFormat tex_fmt;
+DXVTextureFormat tex_fmt;
 int (*compress_tex)(AVCodecContext *avctx);
 
 const AVCRC *crc_ctx;
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/3] lavc/dvx: use texdsp funcs for texture block decompression

2024-01-28 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c | 289 ---
 1 file changed, 75 insertions(+), 214 deletions(-)

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index a2ae070984..cae5d8a92f 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -38,15 +38,12 @@ typedef struct DXVContext {
 GetByteContext gbc;
 
 uint8_t *tex_data;   // Compressed texture
-uint8_t *ctex_data;  // Compressed texture
+uint8_t *ctex_data;  // Compressed chroma texture
 int tex_rat; // Compression ratio
 int tex_step;// Distance between blocks
 int ctex_step;   // Distance between blocks
 int64_t tex_size;// Texture size
-int64_t ctex_size;   // Texture size
-
-/* Optimal number of slices for parallel decoding */
-int slice_count;
+int64_t ctex_size;   // Chroma texture size
 
 uint8_t *op_data[4]; // Opcodes
 int64_t op_size[4];  // Opcodes size
@@ -56,198 +53,8 @@ typedef struct DXVContext {
 
 int ctexture_block_w;
 int ctexture_block_h;
-
-/* Pointer to the selected decompression function */
-int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
-int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0,
-   uint8_t *plane1, ptrdiff_t stride1,
-   const uint8_t *block);
 } DXVContext;
 
-static void decompress_indices(uint8_t *dst, const uint8_t *src)
-{
-int block, i;
-
-for (block = 0; block < 2; block++) {
-int tmp = AV_RL24(src);
-
-/* Unpack 8x3 bit from last 3 byte block */
-for (i = 0; i < 8; i++)
-dst[i] = (tmp >> (i * 3)) & 0x7;
-
-src += 3;
-dst += 8;
-}
-}
-
-static int extract_component(int yo0, int yo1, int code)
-{
-int yo;
-
-if (yo0 == yo1) {
-yo = yo0;
-} else if (code == 0) {
-yo = yo0;
-} else if (code == 1) {
-yo = yo1;
-} else {
-if (yo0 > yo1) {
-yo = (uint8_t) (((8 - code) * yo0 +
- (code - 1) * yo1) / 7);
-} else {
-if (code == 6) {
-yo = 0;
-} else if (code == 7) {
-yo = 255;
-} else {
-yo = (uint8_t) (((6 - code) * yo0 +
- (code - 1) * yo1) / 5);
-}
-}
-}
-
-return yo;
-}
-
-static int cocg_block(uint8_t *plane0, ptrdiff_t stride0,
-  uint8_t *plane1, ptrdiff_t stride1,
-  const uint8_t *block)
-{
-uint8_t co_indices[16];
-uint8_t cg_indices[16];
-uint8_t co0 = *(block);
-uint8_t co1 = *(block + 1);
-uint8_t cg0 = *(block + 8);
-uint8_t cg1 = *(block + 9);
-int x, y;
-
-decompress_indices(co_indices, block + 2);
-decompress_indices(cg_indices, block + 10);
-
-for (y = 0; y < 4; y++) {
-for (x = 0; x < 4; x++) {
-int co_code = co_indices[x + y * 4];
-int cg_code = cg_indices[x + y * 4];
-
-plane0[x] = extract_component(cg0, cg1, cg_code);
-plane1[x] = extract_component(co0, co1, co_code);
-}
-plane0 += stride0;
-plane1 += stride1;
-}
-
-return 16;
-}
-
-static void yao_subblock(uint8_t *dst, uint8_t *yo_indices,
-ptrdiff_t stride, const uint8_t *block)
-{
-uint8_t yo0 = *(block);
-uint8_t yo1 = *(block + 1);
-int x, y;
-
-decompress_indices(yo_indices, block + 2);
-
-for (y = 0; y < 4; y++) {
-for (x = 0; x < 4; x++) {
-int yo_code = yo_indices[x + y * 4];
-
-dst[x] = extract_component(yo0, yo1, yo_code);
-}
-dst += stride;
-}
-}
-
-static int yo_block(uint8_t *dst, ptrdiff_t stride,
-uint8_t *unused0, ptrdiff_t unused1,
-const uint8_t *block)
-{
-uint8_t yo_indices[16];
-
-yao_subblock(dst,  yo_indices, stride, block);
-yao_subblock(dst + 4,  yo_indices, stride, block + 8);
-yao_subblock(dst + 8,  yo_indices, stride, block + 16);
-yao_subblock(dst + 12, yo_indices, stride, block + 24);
-
-return 32;
-}
-
-static int yao_block(uint8_t *plane0, ptrdiff_t stride0,
- uint8_t *plane3, ptrdiff_t stride1,
- const uint8_t *block)
-{
-uint8_t yo_indices[16];
-uint8_t a_indices[16];
-
-yao_subblock(plane0,  yo_indices, stride0, block);
-yao_subblock(plane3,  a_indices,  stride1, block + 8);
-yao_subblock(plane0 + 4,  yo_indices, stride0, block + 16);
-yao_subblock(plane3 + 4,  a_indices,  stride1, block + 24);
-yao_subblock(plane0 + 8,  yo_indices, stride0, block + 32);
-yao_subblock(plane3 + 8,  a_indices,  stride1, block + 40);
-yao_subblock(plane0 + 12, yo_indices, stride0, block + 48);
-yao_subblock(plane3 + 12, a_indices,  stride1

[FFmpeg-devel] [PATCH 3/3] lavc/dxv: remove ctx fields that can be derived from texdsp ctxs

2024-01-28 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c | 53 
 1 file changed, 9 insertions(+), 44 deletions(-)

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index cae5d8a92f..b29adf8ad9 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -39,20 +39,12 @@ typedef struct DXVContext {
 
 uint8_t *tex_data;   // Compressed texture
 uint8_t *ctex_data;  // Compressed chroma texture
-int tex_rat; // Compression ratio
-int tex_step;// Distance between blocks
-int ctex_step;   // Distance between blocks
+
 int64_t tex_size;// Texture size
 int64_t ctex_size;   // Chroma texture size
 
 uint8_t *op_data[4]; // Opcodes
 int64_t op_size[4];  // Opcodes size
-
-int texture_block_w;
-int texture_block_h;
-
-int ctexture_block_w;
-int ctexture_block_h;
 } DXVContext;
 
 /* This scheme addresses already decoded elements depending on 2-bit status:
@@ -865,9 +857,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 cavctx.coded_height = avctx->coded_height / 2;
 cavctx.coded_width  = avctx->coded_width  / 2;
 
-ctx->texture_block_h = 4;
-ctx->texture_block_w = 4;
-
 avctx->pix_fmt = AV_PIX_FMT_RGBA;
 avctx->colorspace = AVCOL_SPC_RGB;
 
@@ -878,8 +867,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 texdsp_ctx.tex_funct = ctx->texdsp.dxt1_block;
 texdsp_ctx.tex_ratio = 8;
 texdsp_ctx.raw_ratio = 16;
-ctx->tex_rat   = 8;
-ctx->tex_step  = 8;
 msgcomp = "DXTR1";
 msgtext = "DXT1";
 break;
@@ -888,8 +875,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 texdsp_ctx.tex_funct = ctx->texdsp.dxt5_block;
 texdsp_ctx.tex_ratio = 16;
 texdsp_ctx.raw_ratio = 16;
-ctx->tex_rat   = 4;
-ctx->tex_step  = 16;
 msgcomp = "DXTR5";
 msgtext = "DXT5";
 break;
@@ -901,16 +886,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 ctexdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block;
 ctexdsp_ctx.tex_ratio = 16;
 ctexdsp_ctx.raw_ratio = 4;
-ctx->tex_rat   = 8;
-ctx->tex_step  = 32;
-ctx->ctex_step = 16;
 msgcomp = "YOCOCG6";
 msgtext = "YCG6";
-ctx->ctex_size = avctx->coded_width * avctx->coded_height / 4;
-ctx->texture_block_h = 4;
-ctx->texture_block_w = 16;
-ctx->ctexture_block_h = 4;
-ctx->ctexture_block_w = 4;
 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 avctx->colorspace = AVCOL_SPC_YCOCG;
 break;
@@ -922,16 +899,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 ctexdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block;
 ctexdsp_ctx.tex_ratio = 16;
 ctexdsp_ctx.raw_ratio = 4;
-ctx->tex_rat   = 4;
-ctx->tex_step  = 64;
-ctx->ctex_step = 16;
 msgcomp = "YAOCOCG10";
 msgtext = "YG10";
-ctx->ctex_size = avctx->coded_width * avctx->coded_height / 4;
-ctx->texture_block_h = 4;
-ctx->texture_block_w = 16;
-ctx->ctexture_block_h = 4;
-ctx->ctexture_block_w = 4;
 avctx->pix_fmt = AV_PIX_FMT_YUVA420P;
 avctx->colorspace = AVCOL_SPC_YCOCG;
 break;
@@ -956,7 +925,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 texdsp_ctx.tex_funct = ctx->texdsp.dxt5_block;
 texdsp_ctx.tex_ratio = 16;
 texdsp_ctx.raw_ratio = 16;
-ctx->tex_step  = 16;
 } else if (old_type & 0x20 || version_major == 1) {
 tag = DXV_FMT_DXT1;
 msgtext = "DXT1";
@@ -964,12 +932,10 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 texdsp_ctx.tex_funct = ctx->texdsp.dxt1_block;
 texdsp_ctx.tex_ratio = 8;
 texdsp_ctx.raw_ratio = 16;
-ctx->tex_step  = 8;
 } else {
 av_log(avctx, AV_LOG_ERROR, "Unsupported header 
(0x%08"PRIX32")\n.", tag);
 return AVERROR_INVALIDDATA;
 }
-ctx->tex_rat = 1;
 break;
 }
 
@@ -985,7 +951,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 /* Encoder copies texture data when compression is not advantageous. */
 if (bytestream2_get_byte(gbc)) {
 msgcomp = "RAW";
-ctx->tex_rat = 1;
 decompress_tex = dxv_decompress_raw;
 }
 
@@ -1003,14 +968,20 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 return AVERROR_INVALIDDATA;
 }
 
-ctx->tex_size = avctx->coded_width * avctx->coded_height * 

Re: [FFmpeg-devel] [PATCH 2/2] fate/video: add DXV3 HQ tests

2024-01-28 Thread Connor Worley
I'd like to get this series merged before doing any further DXV work. Is
anyone able to help with uploading the linked samples?

On Wed, Jan 24, 2024 at 11:45 AM Connor Worley 
wrote:

> Adds tests to cover decoding YCoCg DXV3 formats with and without alpha
>
> Samples:
> https://connorworley.com/fate-suite/dxv/dxv3-hqna.mov
> https://connorworley.com/fate-suite/dxv/dxv3-hqwa.mov
> Signed-off-by: Connor Worley 
> ---
>  tests/fate/video.mak | 6 ++
>  tests/ref/fate/dxv3-ycg6 | 6 ++
>  tests/ref/fate/dxv3-yg10 | 6 ++
>  3 files changed, 18 insertions(+)
>  create mode 100644 tests/ref/fate/dxv3-ycg6
>  create mode 100644 tests/ref/fate/dxv3-yg10
>
> diff --git a/tests/fate/video.mak b/tests/fate/video.mak
> index fbc8a1a682..8f51a42077 100644
> --- a/tests/fate/video.mak
> +++ b/tests/fate/video.mak
> @@ -152,6 +152,12 @@ fate-dxv3-dxt1: CMD = framecrc -i
> $(TARGET_SAMPLES)/dxv/dxv3-nqna.mov
>  FATE_DXV += fate-dxv3-dxt5
>  fate-dxv3-dxt5: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-nqwa.mov
>
> +FATE_DXV += fate-dxv3-ycg6
> +fate-dxv3-ycg6: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-hqna.mov
> +
> +FATE_DXV += fate-dxv3-yg10
> +fate-dxv3-yg10: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-hqwa.mov
> +
>  FATE_VIDEO-$(call FRAMECRC, MOV, DXV) += $(FATE_DXV)
>  fate-dxv: $(FATE_DXV)
>
> diff --git a/tests/ref/fate/dxv3-ycg6 b/tests/ref/fate/dxv3-ycg6
> new file mode 100644
> index 00..63c614fbaf
> --- /dev/null
> +++ b/tests/ref/fate/dxv3-ycg6
> @@ -0,0 +1,6 @@
> +#tb 0: 1/30
> +#media_type 0: video
> +#codec_id 0: rawvideo
> +#dimensions 0: 1920x1080
> +#sar 0: 0/1
> +0,  0,  0,1,  3110400, 0x1e979f00
> diff --git a/tests/ref/fate/dxv3-yg10 b/tests/ref/fate/dxv3-yg10
> new file mode 100644
> index 00..30e122e4d5
> --- /dev/null
> +++ b/tests/ref/fate/dxv3-yg10
> @@ -0,0 +1,6 @@
> +#tb 0: 1/30
> +#media_type 0: video
> +#codec_id 0: rawvideo
> +#dimensions 0: 1920x1080
> +#sar 0: 0/1
> +0,  0,  0,1,  5184000, 0xe5f0d3da
> --
> 2.40.1
>
>

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] fate/video: add DXV3 HQ tests

2024-01-29 Thread Connor Worley
I could generate smaller samples if preferred. I opted to match the
existing NQ ones.

On Mon, Jan 29, 2024 at 1:56 AM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Connor Worley:
> > Adds tests to cover decoding YCoCg DXV3 formats with and without alpha
> >
> > Samples:
> > https://connorworley.com/fate-suite/dxv/dxv3-hqna.mov
> > https://connorworley.com/fate-suite/dxv/dxv3-hqwa.mov
> > Signed-off-by: Connor Worley 
> > ---
> >  tests/fate/video.mak | 6 ++
> >  tests/ref/fate/dxv3-ycg6 | 6 ++
> >  tests/ref/fate/dxv3-yg10 | 6 ++
> >  3 files changed, 18 insertions(+)
> >  create mode 100644 tests/ref/fate/dxv3-ycg6
> >  create mode 100644 tests/ref/fate/dxv3-yg10
> >
> > diff --git a/tests/fate/video.mak b/tests/fate/video.mak
> > index fbc8a1a682..8f51a42077 100644
> > --- a/tests/fate/video.mak
> > +++ b/tests/fate/video.mak
> > @@ -152,6 +152,12 @@ fate-dxv3-dxt1: CMD = framecrc -i
> $(TARGET_SAMPLES)/dxv/dxv3-nqna.mov
> >  FATE_DXV += fate-dxv3-dxt5
> >  fate-dxv3-dxt5: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-nqwa.mov
> >
> > +FATE_DXV += fate-dxv3-ycg6
> > +fate-dxv3-ycg6: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-hqna.mov
> > +
> > +FATE_DXV += fate-dxv3-yg10
> > +fate-dxv3-yg10: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-hqwa.mov
> > +
> >  FATE_VIDEO-$(call FRAMECRC, MOV, DXV) += $(FATE_DXV)
> >  fate-dxv: $(FATE_DXV)
> >
> > diff --git a/tests/ref/fate/dxv3-ycg6 b/tests/ref/fate/dxv3-ycg6
> > new file mode 100644
> > index 00..63c614fbaf
> > --- /dev/null
> > +++ b/tests/ref/fate/dxv3-ycg6
> > @@ -0,0 +1,6 @@
> > +#tb 0: 1/30
> > +#media_type 0: video
> > +#codec_id 0: rawvideo
> > +#dimensions 0: 1920x1080
> > +#sar 0: 0/1
> > +0,  0,  0,1,  3110400, 0x1e979f00
> > diff --git a/tests/ref/fate/dxv3-yg10 b/tests/ref/fate/dxv3-yg10
> > new file mode 100644
> > index 00..30e122e4d5
> > --- /dev/null
> > +++ b/tests/ref/fate/dxv3-yg10
> > @@ -0,0 +1,6 @@
> > +#tb 0: 1/30
> > +#media_type 0: video
> > +#codec_id 0: rawvideo
> > +#dimensions 0: 1920x1080
>
> Why not use a smaller resolution?
>
> > +#sar 0: 0/1
> > +0,  0,  0,1,  5184000, 0xe5f0d3da
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>


-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 3/3] lavc/dxv: remove ctx fields that can be derived from texdsp ctxs

2024-01-29 Thread Connor Worley
I'm not sure how I would write it in a way that isn't a repetition of the
new definition of ctx->tex_size

On Sun, Jan 28, 2024 at 11:52 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Connor Worley:
> > Signed-off-by: Connor Worley 
> > ---
> >  libavcodec/dxv.c | 53 
> >  1 file changed, 9 insertions(+), 44 deletions(-)
> >
> > diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
> > index cae5d8a92f..b29adf8ad9 100644
> > --- a/libavcodec/dxv.c
> > +++ b/libavcodec/dxv.c
> > @@ -39,20 +39,12 @@ typedef struct DXVContext {
> >
> >  uint8_t *tex_data;   // Compressed texture
> >  uint8_t *ctex_data;  // Compressed chroma texture
> > -int tex_rat; // Compression ratio
> > -int tex_step;// Distance between blocks
> > -int ctex_step;   // Distance between blocks
> > +
> >  int64_t tex_size;// Texture size
> >  int64_t ctex_size;   // Chroma texture size
> >
> >  uint8_t *op_data[4]; // Opcodes
> >  int64_t op_size[4];  // Opcodes size
> > -
> > -int texture_block_w;
> > -int texture_block_h;
> > -
> > -int ctexture_block_w;
> > -int ctexture_block_h;
> >  } DXVContext;
> >
> >  /* This scheme addresses already decoded elements depending on 2-bit
> status:
> > @@ -865,9 +857,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame
> *frame,
> >  cavctx.coded_height = avctx->coded_height / 2;
> >  cavctx.coded_width  = avctx->coded_width  / 2;
> >
> > -ctx->texture_block_h = 4;
> > -ctx->texture_block_w = 4;
> > -
> >  avctx->pix_fmt = AV_PIX_FMT_RGBA;
> >  avctx->colorspace = AVCOL_SPC_RGB;
> >
> > @@ -878,8 +867,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame
> *frame,
> >  texdsp_ctx.tex_funct = ctx->texdsp.dxt1_block;
> >  texdsp_ctx.tex_ratio = 8;
> >  texdsp_ctx.raw_ratio = 16;
> > -ctx->tex_rat   = 8;
> > -ctx->tex_step  = 8;
> >  msgcomp = "DXTR1";
> >  msgtext = "DXT1";
> >  break;
> > @@ -888,8 +875,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame
> *frame,
> >  texdsp_ctx.tex_funct = ctx->texdsp.dxt5_block;
> >  texdsp_ctx.tex_ratio = 16;
> >  texdsp_ctx.raw_ratio = 16;
> > -ctx->tex_rat   = 4;
> > -ctx->tex_step  = 16;
> >  msgcomp = "DXTR5";
> >  msgtext = "DXT5";
> >  break;
> > @@ -901,16 +886,8 @@ static int dxv_decode(AVCodecContext *avctx,
> AVFrame *frame,
> >  ctexdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block;
> >  ctexdsp_ctx.tex_ratio = 16;
> >  ctexdsp_ctx.raw_ratio = 4;
> > -ctx->tex_rat   = 8;
> > -ctx->tex_step  = 32;
> > -ctx->ctex_step = 16;
> >  msgcomp = "YOCOCG6";
> >  msgtext = "YCG6";
> > -ctx->ctex_size = avctx->coded_width * avctx->coded_height / 4;
> > -ctx->texture_block_h = 4;
> > -ctx->texture_block_w = 16;
> > -ctx->ctexture_block_h = 4;
> > -ctx->ctexture_block_w = 4;
> >  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
> >  avctx->colorspace = AVCOL_SPC_YCOCG;
> >  break;
> > @@ -922,16 +899,8 @@ static int dxv_decode(AVCodecContext *avctx,
> AVFrame *frame,
> >  ctexdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block;
> >  ctexdsp_ctx.tex_ratio = 16;
> >  ctexdsp_ctx.raw_ratio = 4;
> > -ctx->tex_rat   = 4;
> > -ctx->tex_step  = 64;
> > -ctx->ctex_step = 16;
> >  msgcomp = "YAOCOCG10";
> >  msgtext = "YG10";
> > -ctx->ctex_size = avctx->coded_width * avctx->coded_height / 4;
> > -ctx->texture_block_h = 4;
> > -ctx->texture_block_w = 16;
> > -ctx->ctexture_block_h = 4;
> > -ctx->ctexture_block_w = 4;
> >  avctx->pix_fmt = AV_PIX_FMT_YUVA420P;
> >  avctx->colorspace = AVCOL_SPC_YCOCG;
> >  break;
> > @@ -956,7 +925,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame
> *frame,
> >  texdsp_ctx.tex_funct = ctx->texdsp.dxt5_block;
> >  texdsp_ctx.tex_ratio = 16;
> >  texdsp_ct

[FFmpeg-devel] [PATCH] lavc/dxv: fix incorrect back-reference index calculation in DXT5 decoding

2024-01-29 Thread Connor Worley
This bug causes the DXT5 decoder to produce incorrect block texture data.
After the fix, textures are visually correct and match data decoded by
Resolume Alley (extracted with Nvida Nsight for comparison). Current FATE DXT5
samples did not cover this case.

Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index b29adf8ad9..be1216da86 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -755,7 +755,7 @@ static int dxv_decompress_dxt5(AVCodecContext *avctx)
 break;
 case 2:
 /* Copy two dwords from a previous index */
-idx = 8 + bytestream2_get_le16(gbc);
+idx = 8 + 4 * bytestream2_get_le16(gbc);
 if (idx > pos || (unsigned int)(pos - idx) + 2 > ctx->tex_size 
/ 4)
 return AVERROR_INVALIDDATA;
 prev = AV_RL32(ctx->tex_data + 4 * (pos - idx));
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] fate/video: add DXV3 HQ tests

2024-01-30 Thread Connor Worley
Samples have been added, and this series now passes FATE
-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] fate/video: add DXV3 HQ tests

2024-01-30 Thread Connor Worley
In that case, it is probably worth replacing the existing "normal quality"
samples as they're even larger.
dxv3-nqwa.mov does not adequately exercise the code fixed in
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240130062626.98273-1-connorbwor...@gmail.com/
I'm not sure what the process for removing samples from fate-suite is.

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] fate/video: add DXV3 HQ tests

2024-01-30 Thread Connor Worley
Each sample covers a different texture format, but it may be possible to
generate smaller versions for each case with the same or better coverage.

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] fate/video: add DXV3 HQ tests

2024-01-30 Thread Connor Worley
OK, attached are some significantly smaller HQ samples that produce the
same coverage.

5b11c393dda223b5dd198ad2f2576fe2  fate-suite/dxv/dxv3-hqna.mov
3af30eaba2b6ec68a0f5b2c136f4dab6  fate-suite/dxv/dxv3-hqwa.mov

-- 
Connor Worley


dxv3-hqwa.mov
Description: QuickTime movie


dxv3-hqna.mov
Description: QuickTime movie
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/2] fate/video: add DXV3 DXT1 encoding test

2024-02-01 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 tests/fate/video.mak| 7 +++
 tests/ref/fate/dxv3enc-dxt1 | 6 ++
 2 files changed, 13 insertions(+)
 create mode 100644 tests/ref/fate/dxv3enc-dxt1

diff --git a/tests/fate/video.mak b/tests/fate/video.mak
index 4e7a77537f..fbc8a1a682 100644
--- a/tests/fate/video.mak
+++ b/tests/fate/video.mak
@@ -155,6 +155,13 @@ fate-dxv3-dxt5: CMD = framecrc -i 
$(TARGET_SAMPLES)/dxv/dxv3-nqwa.mov
 FATE_VIDEO-$(call FRAMECRC, MOV, DXV) += $(FATE_DXV)
 fate-dxv: $(FATE_DXV)
 
+fate-dxv3enc%: FMT = $(word 3, $(subst -, ,$(@)))
+fate-dxv3enc%: CMD = framecrc -lavfi testsrc2=duration=1:rate=1:size=1920x1080 
-c:v dxv -format $(FMT)
+
+FATE_DXVENC_FMT = dxt1
+FATE_VIDEO-$(call FILTERFRAMECRC, TESTSRC2, DXV_ENCODER) += 
$(FATE_DXVENC_FMT:%=fate-dxv3enc-%)
+fate-dxvenc: $(FATE_DXVENC_FMT:%=fate-dxv3enc-%)
+
 FATE_VIDEO-$(call FRAMECRC, SEGAFILM, CINEPAK) += fate-film-cvid
 fate-film-cvid: CMD = framecrc -i $(TARGET_SAMPLES)/film/logo-capcom.cpk -an
 
diff --git a/tests/ref/fate/dxv3enc-dxt1 b/tests/ref/fate/dxv3enc-dxt1
new file mode 100644
index 00..3cfd73397e
--- /dev/null
+++ b/tests/ref/fate/dxv3enc-dxt1
@@ -0,0 +1,6 @@
+#tb 0: 1/1
+#media_type 0: video
+#codec_id 0: dxv
+#dimensions 0: 1920x1080
+#sar 0: 1/1
+0,  0,  0,1,76767, 0x932ecbfa
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 2/2] fate/video: add DXV3 HQ tests

2024-02-01 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 tests/fate/video.mak | 6 ++
 tests/ref/fate/dxv3-ycg6 | 6 ++
 tests/ref/fate/dxv3-yg10 | 6 ++
 3 files changed, 18 insertions(+)
 create mode 100644 tests/ref/fate/dxv3-ycg6
 create mode 100644 tests/ref/fate/dxv3-yg10

diff --git a/tests/fate/video.mak b/tests/fate/video.mak
index fbc8a1a682..8f51a42077 100644
--- a/tests/fate/video.mak
+++ b/tests/fate/video.mak
@@ -152,6 +152,12 @@ fate-dxv3-dxt1: CMD = framecrc -i 
$(TARGET_SAMPLES)/dxv/dxv3-nqna.mov
 FATE_DXV += fate-dxv3-dxt5
 fate-dxv3-dxt5: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-nqwa.mov
 
+FATE_DXV += fate-dxv3-ycg6
+fate-dxv3-ycg6: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-hqna.mov
+
+FATE_DXV += fate-dxv3-yg10
+fate-dxv3-yg10: CMD = framecrc -i $(TARGET_SAMPLES)/dxv/dxv3-hqwa.mov
+
 FATE_VIDEO-$(call FRAMECRC, MOV, DXV) += $(FATE_DXV)
 fate-dxv: $(FATE_DXV)
 
diff --git a/tests/ref/fate/dxv3-ycg6 b/tests/ref/fate/dxv3-ycg6
new file mode 100644
index 00..9650f7ce5e
--- /dev/null
+++ b/tests/ref/fate/dxv3-ycg6
@@ -0,0 +1,6 @@
+#tb 0: 1/30
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 256x256
+#sar 0: 0/1
+0,  0,  0,1,98304, 0x22992f41
diff --git a/tests/ref/fate/dxv3-yg10 b/tests/ref/fate/dxv3-yg10
new file mode 100644
index 00..541107bb9a
--- /dev/null
+++ b/tests/ref/fate/dxv3-yg10
@@ -0,0 +1,6 @@
+#tb 0: 1/30
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 256x256
+#sar 0: 0/1
+0,  0,  0,1,   163840, 0x5f1d3e32
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/dxv: fix incorrect back-reference index calculation in DXT5 decoding

2024-02-01 Thread Connor Worley
Got some confirmation that this patch fixes
https://trac.ffmpeg.org/ticket/10264

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] lavc/texturedsp: fix premult2straight inversion

2024-02-01 Thread Connor Worley
This function should convert premultiplied alpha to straight, but does the 
opposite.

Signed-off-by: Connor Worley 
---
 libavcodec/texturedsp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/texturedsp.c b/libavcodec/texturedsp.c
index 5fb79937da..1b8237e9f7 100644
--- a/libavcodec/texturedsp.c
+++ b/libavcodec/texturedsp.c
@@ -175,9 +175,9 @@ static av_always_inline void premult2straight(uint8_t *src)
 int b = src[2];
 int a = src[3]; /* unchanged */
 
-src[0] = (uint8_t) r * a / 255;
-src[1] = (uint8_t) g * a / 255;
-src[2] = (uint8_t) b * a / 255;
+src[0] = (uint8_t) FFMIN(r * 255 / a, 255);
+src[1] = (uint8_t) FFMIN(g * 255 / a, 255);
+src[2] = (uint8_t) FFMIN(b * 255 / a, 255);
 }
 
 /**
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] lavc/dxv: treat DXT5-tagged files as DXT4

2024-02-01 Thread Connor Worley
DXV files seem to misnomer DXT5 and really encode DXT4 with premultiplied alpha.
At least, this is what Resolume alley does. To check, encode some input with 
alpha
as "Normal Quality, With Alpha" in Alley, then decode the output with this 
change
-- results are true to the original input compared to git-master.

Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 5923811b29..1e6791e63f 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -1074,7 +1074,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 break;
 case MKBETAG('D', 'X', 'T', '5'):
 decompress_tex = dxv_decompress_dxt5;
-ctx->tex_funct = ctx->texdsp.dxt5_block;
+/* DXV misnomers DXT5, alpha is premultiplied so use DXT4 instead */
+ctx->tex_funct = ctx->texdsp.dxt4_block;
 ctx->tex_rat   = 4;
 ctx->tex_step  = 16;
 msgcomp = "DXTR5";
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] lavc/texturedsp: add DXT4 texturedspenc function

2024-02-01 Thread Connor Worley
For future use in lavc/dxvenc.

Signed-off-by: Connor Worley 
---
 libavcodec/texturedsp.h|  1 +
 libavcodec/texturedspenc.c | 41 ++
 2 files changed, 42 insertions(+)

diff --git a/libavcodec/texturedsp.h b/libavcodec/texturedsp.h
index 86c8eea02d..8881436187 100644
--- a/libavcodec/texturedsp.h
+++ b/libavcodec/texturedsp.h
@@ -62,6 +62,7 @@ typedef struct TextureDSPContext {
 
 typedef struct TextureDSPEncContext {
 int (*dxt1_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t 
*block);
+int (*dxt4_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t 
*block);
 int (*dxt5_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t 
*block);
 int (*dxt5ys_block)  (uint8_t *dst, ptrdiff_t stride, const uint8_t 
*block);
 } TextureDSPEncContext;
diff --git a/libavcodec/texturedspenc.c b/libavcodec/texturedspenc.c
index 5657a6ef61..c98a277f56 100644
--- a/libavcodec/texturedspenc.c
+++ b/libavcodec/texturedspenc.c
@@ -589,6 +589,20 @@ static void rgba2ycocg(uint8_t *dst, const uint8_t *pixel)
 dst[3] = av_clip_uint8(g + t);  /* Y */
 }
 
+/** Convert a straight alpha pixel to a premultiplied alpha pixel. */
+static av_always_inline void straight2premult(uint8_t *dst, const uint8_t *src)
+{
+const int r = src[0];
+const int g = src[1];
+const int b = src[2];
+const int a = src[3]; /* unchanged */
+
+dst[0] = (uint8_t) r * a / 255;
+dst[1] = (uint8_t) g * a / 255;
+dst[2] = (uint8_t) b * a / 255;
+dst[3] = a;
+}
+
 /**
  * Compress one block of RGBA pixels in a DXT1 texture and store the
  * resulting bytes in 'dst'. Alpha is not preserved.
@@ -605,6 +619,32 @@ static int dxt1_block(uint8_t *dst, ptrdiff_t stride, 
const uint8_t *block)
 return 8;
 }
 
+/**
+ * Compress one block of RGBA pixels in a DXT4 texture and store the
+ * resulting bytes in 'dst'. Alpha is preserved.
+ *
+ * @param dstoutput buffer.
+ * @param stride scanline in bytes.
+ * @param block  block to compress.
+ * @return how much texture data has been written.
+ */
+static int dxt4_block(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
+{
+int x, y;
+uint8_t premult[64];
+
+for (y = 0; y < 4; y++) {
+for (x = 0; x < 4; x++) {
+straight2premult(premult + x * 4 + y * 16, block + x * 4 + y * 
stride);
+}
+}
+
+compress_alpha(dst, 16, premult);
+compress_color(dst + 8, 16, premult);
+
+return 16;
+}
+
 /**
  * Compress one block of RGBA pixels in a DXT5 texture and store the
  * resulting bytes in 'dst'. Alpha is preserved.
@@ -650,6 +690,7 @@ static int dxt5ys_block(uint8_t *dst, ptrdiff_t stride, 
const uint8_t *block)
 av_cold void ff_texturedspenc_init(TextureDSPEncContext *c)
 {
 c->dxt1_block = dxt1_block;
+c->dxt4_block = dxt4_block;
 c->dxt5_block = dxt5_block;
 c->dxt5ys_block   = dxt5ys_block;
 }
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/2] lavc/texturedsp: fix premult2straight inversion

2024-02-01 Thread Connor Worley
This function should convert premultiplied alpha to straight, but does the 
opposite.

Signed-off-by: Connor Worley 
---
 libavcodec/texturedsp.c | 9 ++---
 tests/ref/fate/dds-dxt2 | 2 +-
 tests/ref/fate/dds-dxt4 | 2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/libavcodec/texturedsp.c b/libavcodec/texturedsp.c
index 5fb79937da..721bfc17f5 100644
--- a/libavcodec/texturedsp.c
+++ b/libavcodec/texturedsp.c
@@ -175,9 +175,12 @@ static av_always_inline void premult2straight(uint8_t *src)
 int b = src[2];
 int a = src[3]; /* unchanged */
 
-src[0] = (uint8_t) r * a / 255;
-src[1] = (uint8_t) g * a / 255;
-src[2] = (uint8_t) b * a / 255;
+if (a == 0)
+return;
+
+src[0] = (uint8_t) FFMIN(r * 255 / a, 255);
+src[1] = (uint8_t) FFMIN(g * 255 / a, 255);
+src[2] = (uint8_t) FFMIN(b * 255 / a, 255);
 }
 
 /**
diff --git a/tests/ref/fate/dds-dxt2 b/tests/ref/fate/dds-dxt2
index b5bdfbadc3..1744ef41f6 100644
--- a/tests/ref/fate/dds-dxt2
+++ b/tests/ref/fate/dds-dxt2
@@ -3,4 +3,4 @@
 #codec_id 0: rawvideo
 #dimensions 0: 64x64
 #sar 0: 0/1
-0,  0,  0,1,16384, 0x11cebeb0
+0,  0,  0,1,16384, 0xd7f7241b
diff --git a/tests/ref/fate/dds-dxt4 b/tests/ref/fate/dds-dxt4
index 136dfd8006..f22878da56 100644
--- a/tests/ref/fate/dds-dxt4
+++ b/tests/ref/fate/dds-dxt4
@@ -3,4 +3,4 @@
 #codec_id 0: rawvideo
 #dimensions 0: 64x64
 #sar 0: 0/1
-0,  0,  0,1,16384, 0x31aaacd6
+0,  0,  0,1,16384, 0xf18d4216
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 2/2] lavc/dxv: treat DXT5-tagged files as DXT4

2024-02-01 Thread Connor Worley
DXV files seem to misnomer DXT5 and really encode DXT4 with premultiplied alpha.
At least, this is what Resolume alley does. To check, encode some input with 
alpha
as "Normal Quality, With Alpha" in Alley, then decode the output with this 
change
-- results are true to the original input compared to git-master.

Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 5923811b29..1e6791e63f 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -1074,7 +1074,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 break;
 case MKBETAG('D', 'X', 'T', '5'):
 decompress_tex = dxv_decompress_dxt5;
-ctx->tex_funct = ctx->texdsp.dxt5_block;
+/* DXV misnomers DXT5, alpha is premultiplied so use DXT4 instead */
+ctx->tex_funct = ctx->texdsp.dxt4_block;
 ctx->tex_rat   = 4;
 ctx->tex_step  = 16;
 msgcomp = "DXTR5";
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 1/2] lavc/texturedsp: fix premult2straight inversion

2024-02-02 Thread Connor Worley
Linked are some demo files.

I converted a sample to DDS with texconv.exe -f DXT4 -pmalpha sample.png
I converted it back to PNG against master with ffmpeg -i sample.dds
master.png
I converted it back to PNG against this patch with ffmpeg -i sample.dds
patch.png

The color in master.png is dark due to being premultiplied twice.
The color in patch.png is true to sample.png.

https://connorworley.com/sample.png
https://connorworley.com/sample.dds
https://connorworley.com/master.png
https://connorworley.com/patch.png

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/3] lavc/dxv: move tag definitions to common header

2024-02-03 Thread Connor Worley
Any objections to merging this series?

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 2/2] fate/video: add DXV3 HQ tests

2024-02-04 Thread Connor Worley
Samples have been added to fate-suite and this series is ready to be merged.

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] lavu/hashtable: create generic robin hood hash table

2024-02-04 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavutil/Makefile  |   2 +
 libavutil/hashtable.c   | 172 
 libavutil/hashtable.h   |  62 +
 libavutil/tests/hashtable.c | 104 ++
 4 files changed, 340 insertions(+)
 create mode 100644 libavutil/hashtable.c
 create mode 100644 libavutil/hashtable.h
 create mode 100644 libavutil/tests/hashtable.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index e7709b97d0..be75d464fc 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -138,6 +138,7 @@ OBJS = adler32.o
\
fixed_dsp.o  \
frame.o  \
hash.o   \
+   hashtable.o  \
hdr_dynamic_metadata.o   \
hdr_dynamic_vivid_metadata.o \
hmac.o   \
@@ -251,6 +252,7 @@ TESTPROGS = adler32 
\
 file\
 fifo\
 hash\
+hashtable   \
 hmac\
 hwdevice\
 integer \
diff --git a/libavutil/hashtable.c b/libavutil/hashtable.c
new file mode 100644
index 00..fb0f0aae99
--- /dev/null
+++ b/libavutil/hashtable.c
@@ -0,0 +1,172 @@
+/*
+ * Generic hashtable
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "error.h"
+#include "mem.h"
+#include "hashtable.h"
+#include "string.h"
+
+#define ENTRY_OCC(entry)   (entry)
+#define ENTRY_KEY(entry)   (ENTRY_OCC(entry) + 1)
+#define ENTRY_VAL(entry)   (ENTRY_KEY(entry) + ctx->key_size)
+#define ENTRY_PSL(entry) (size_t*) (ENTRY_VAL(entry) + ctx->val_size)
+
+#define KEYS_EQUAL(k1, k2) !memcmp(k1, k2, ctx->key_size)
+
+int av_hashtable_init(AVHashtableContext* ctx, size_t key_size, size_t 
val_size, size_t max_entries)
+{
+ctx->key_size = key_size;
+ctx->val_size = val_size;
+ctx->entry_size = 1 + key_size + val_size + sizeof(size_t);
+ctx->max_entries = max_entries;
+ctx->utilization = 0;
+ctx->crc = av_crc_get_table(AV_CRC_32_IEEE);
+if (!ctx->crc)
+return AVERROR_BUG;
+ctx->table = av_mallocz(ctx->entry_size * max_entries);
+if (!ctx->table)
+return AVERROR(ENOMEM);
+ctx->set_key = av_malloc(key_size);
+if (!ctx->set_key)
+return AVERROR(ENOMEM);
+ctx->set_val = av_malloc(key_size);
+if (!ctx->set_val)
+return AVERROR(ENOMEM);
+ctx->tmp_key = av_malloc(key_size);
+if (!ctx->tmp_key)
+return AVERROR(ENOMEM);
+ctx->tmp_val = av_malloc(val_size);
+if (!ctx->tmp_val)
+return AVERROR(ENOMEM);
+return 0;
+}
+
+static size_t hash_key(const AVHashtableContext* ctx, const void* key)
+{
+return av_crc(ctx->crc, 0, key, ctx->key_size) % ctx->max_entries;
+}
+
+int av_hashtable_get(const AVHashtableContext* ctx, const void* key, void* val)
+{
+size_t hash = hash_key(ctx, key);
+
+if (!ctx->utilization)
+return 0;
+
+for (size_t psl = 0; psl < ctx->max_entries; psl++) {
+size_t wrapped_index = (hash + psl) % ctx->max_entries;
+uint8_t *entry = ctx->table + wrapped_index * ctx->entry_size;
+if (!*ENTRY_OCC(entry) || *ENTRY_PSL(entry) < psl)
+return 0;
+if (KEYS_EQUAL(ENTRY_KEY(entry), key)) {
+memcpy(val, ENTRY_VAL(entry), ctx->val_size);
+   

[FFmpeg-devel] [PATCH 2/2] lavc/dxvenc: migrate DXT1 encoder to lavu hashtable

2024-02-04 Thread Connor Worley
Offers a modest performance gain due to the switch from naive linear
probling to robin hood.

Signed-off-by: Connor Worley 
---
 libavcodec/dxvenc.c | 121 +---
 1 file changed, 35 insertions(+), 86 deletions(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index b274175689..e17b3b2c36 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -21,7 +21,7 @@
 
 #include 
 
-#include "libavutil/crc.h"
+#include "libavutil/hashtable.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 
@@ -44,69 +44,6 @@ enum DXVTextureFormat {
 DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
 };
 
-typedef struct HTEntry {
-uint32_t key;
-uint32_t pos;
-} HTEntry;
-
-static void ht_init(HTEntry *ht)
-{
-for (size_t i = 0; i < LOOKBACK_HT_ELEMS; i++) {
-ht[i].pos = -1;
-}
-}
-
-static uint32_t ht_lookup_and_upsert(HTEntry *ht, const AVCRC *hash_ctx,
-uint32_t key, uint32_t pos)
-{
-uint32_t ret = -1;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->key == key || entry->pos == -1) {
-ret = entry->pos;
-entry->key = key;
-entry->pos = pos;
-break;
-}
-}
-return ret;
-}
-
-static void ht_delete(HTEntry *ht, const AVCRC *hash_ctx,
-  uint32_t key, uint32_t pos)
-{
-HTEntry *removed_entry = NULL;
-size_t removed_hash;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->pos == -1)
-return;
-if (removed_entry) {
-size_t candidate_hash = av_crc(hash_ctx, 0, (uint8_t*)&entry->key, 
4) % LOOKBACK_HT_ELEMS;
-if ((wrapped_index > removed_hash && (candidate_hash <= 
removed_hash || candidate_hash > wrapped_index)) ||
-(wrapped_index < removed_hash && (candidate_hash <= 
removed_hash && candidate_hash > wrapped_index))) {
-*removed_entry = *entry;
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-}
-} else if (entry->key == key) {
-if (entry->pos <= pos) {
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-} else {
-return;
-}
-}
-}
-}
-
 typedef struct DXVEncContext {
 AVClass *class;
 
@@ -123,10 +60,8 @@ typedef struct DXVEncContext {
 enum DXVTextureFormat tex_fmt;
 int (*compress_tex)(AVCodecContext *avctx);
 
-const AVCRC *crc_ctx;
-
-HTEntry color_lookback_ht[LOOKBACK_HT_ELEMS];
-HTEntry lut_lookback_ht[LOOKBACK_HT_ELEMS];
+AVHashtableContext color_ht;
+AVHashtableContext lut_ht;
 } DXVEncContext;
 
 /* Converts an index offset value to a 2-bit opcode and pushes it to a stream.
@@ -161,27 +96,32 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
 DXVEncContext *ctx = avctx->priv_data;
 PutByteContext *pbc = &ctx->pbc;
 uint32_t *value;
-uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
2, op = 0;
+uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
0, op = 0;
 
-ht_init(ctx->color_lookback_ht);
-ht_init(ctx->lut_lookback_ht);
+av_hashtable_clear(&ctx->color_ht);
+av_hashtable_clear(&ctx->lut_ht);
 
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data));
+av_hashtable_set(&ctx->color_ht, ctx->tex_data, &pos);
+pos++;
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + 4));
-
-ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data), 0);
-ht_lookup_and_upsert(ctx->lut_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data + 4), 1);
+av_hashtable_set(&ctx->lut_ht, ctx->tex_data + 4, &pos);
+pos++;
 
 while (pos + 2 <= ctx->tex_size / 4) {
 idx = 0;
+color_idx = 0;
+lut_idx = 0;
 
 color = AV_RL32(ctx->tex_data + pos * 4);
-prev_pos = ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
color, pos);
-color_idx = prev_pos != -1 ? pos - prev_pos : 0;
+if (av_hashtable_get(&ctx->color_ht, &color, &prev_pos))
+color_idx = pos - prev_pos;
+av_hashtable_

Re: [FFmpeg-devel] [PATCH] lavc/dxv: fix incorrect back-reference index calculation in DXT5 decoding

2024-02-04 Thread Connor Worley
Given that Paul is no longer a maintainer, can someone else please take a
look?

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] avutil/thread: fix pthread_setname_np parameters for NetBSD and Apple

2024-02-05 Thread Connor Worley
Can confirm this fixes the build on my Mac.

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] lavc/dxvenc: migrate DXT1 encoder to lavu hashtable

2024-02-05 Thread Connor Worley
>
> How much would one gain if the hash function knew that key_size and
> val_size are four?
>

That yields a nice 10-20% speedup on my machine. Are you thinking of macros
to parametrize key/val size, or possibly optimized versions for common
sizes?
-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 2/2] lavc/dxvenc: migrate DXT1 encoder to lavu hashtable

2024-02-05 Thread Connor Worley
On Mon, Feb 5, 2024 at 12:06 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Connor Worley:
> >>
> >> How much would one gain if the hash function knew that key_size and
> >> val_size are four?
> >>
> >
> > That yields a nice 10-20% speedup on my machine. Are you thinking of
> macros
> > to parametrize key/val size, or possibly optimized versions for common
> > sizes?
>
> I am thinking about it not being public at all; as long as we have only
> one user...
>

 That's fair. I will need some variants for future DXV work, but they can
also be private if this doesn't seem generally useful.

PS: Is the speedup only for the hashing part or for overall decoding? Is
> the comparison the current version of your patch or something that
> already has my comments incorporated?
>

Overall encoding -- current version of my patch with ctx->key/val_size vs
hardcoded sizes.

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/2] lavu/hashtable: create generic robin hood hash table

2024-02-05 Thread Connor Worley
On Mon, Feb 5, 2024 at 3:58 AM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Connor Worley:
> > +memcpy(ctx->tmp_key, ctx->set_key, ctx->key_size);
> > +memcpy(ctx->tmp_val, ctx->set_val, ctx->val_size);
>
> Given that set_key/val are overwritten below, these two can be done via
> pointerswaps.


I don't quite follow, can you elaborate on this part?
-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH 1/2] lavu/hashtable: create generic robin hood hash table

2024-02-06 Thread Connor Worley
NVM, I see what you mean by pointerswaps.

On Mon, Feb 5, 2024 at 9:00 PM Connor Worley 
wrote:

> On Mon, Feb 5, 2024 at 3:58 AM Andreas Rheinhardt <
> andreas.rheinha...@outlook.com> wrote:
>
>> Connor Worley:
>> > +memcpy(ctx->tmp_key, ctx->set_key, ctx->key_size);
>> > +memcpy(ctx->tmp_val, ctx->set_val, ctx->val_size);
>>
>> Given that set_key/val are overwritten below, these two can be done via
>> pointerswaps.
>
>
> I don't quite follow, can you elaborate on this part?
> --
> Connor Worley
>


-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/2] lavu/hashtable: create generic robin hood hash table

2024-02-06 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavutil/Makefile  |   2 +
 libavutil/hashtable.c   | 183 
 libavutil/hashtable.h   |  47 +
 libavutil/tests/hashtable.c | 108 +
 4 files changed, 340 insertions(+)
 create mode 100644 libavutil/hashtable.c
 create mode 100644 libavutil/hashtable.h
 create mode 100644 libavutil/tests/hashtable.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index e7709b97d0..be75d464fc 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -138,6 +138,7 @@ OBJS = adler32.o
\
fixed_dsp.o  \
frame.o  \
hash.o   \
+   hashtable.o  \
hdr_dynamic_metadata.o   \
hdr_dynamic_vivid_metadata.o \
hmac.o   \
@@ -251,6 +252,7 @@ TESTPROGS = adler32 
\
 file\
 fifo\
 hash\
+hashtable   \
 hmac\
 hwdevice\
 integer \
diff --git a/libavutil/hashtable.c b/libavutil/hashtable.c
new file mode 100644
index 00..6fa2af8af3
--- /dev/null
+++ b/libavutil/hashtable.c
@@ -0,0 +1,183 @@
+/*
+ * Generic hashtable
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+#include 
+
+#include "crc.h"
+#include "error.h"
+#include "mem.h"
+#include "hashtable.h"
+
+struct AVHashtableContext {
+size_t key_size;
+size_t val_size;
+size_t entry_size;
+size_t max_entries;
+size_t utilization;
+const AVCRC *crc;
+uint8_t *table;
+uint8_t *swapbuf;
+};
+
+#define ENTRY_PSL(entry) (entry)
+#define ENTRY_OCC(entry) (ENTRY_PSL(entry) + sizeof(size_t))
+#define ENTRY_KEY(entry) (ENTRY_OCC(entry) + 4)
+#define ENTRY_VAL(entry) (ENTRY_KEY(entry) + FFALIGN(ctx->key_size, 4))
+
+#define KEYS_EQUAL(k1, k2) !memcmp(k1, k2, ctx->key_size)
+
+int av_hashtable_alloc(struct AVHashtableContext** ctx, size_t key_size, 
size_t val_size, size_t max_entries)
+{
+struct AVHashtableContext *res = av_malloc(sizeof(struct 
AVHashtableContext));
+if (!res)
+return AVERROR(ENOMEM);
+res->key_size = key_size;
+res->val_size = val_size;
+res->entry_size = sizeof(size_t) + 4 + FFALIGN(key_size, 4) + 
FFALIGN(val_size, 4);
+res->max_entries = max_entries;
+res->utilization = 0;
+res->crc = av_crc_get_table(AV_CRC_32_IEEE);
+if (!res->crc) {
+av_hashtable_freep(&res);
+return AVERROR_BUG;
+}
+res->table = av_calloc(res->max_entries, res->entry_size);
+if (!res->table) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+res->swapbuf = av_calloc(2, FFALIGN(key_size, 4) + FFALIGN(val_size, 4));
+if (!res->swapbuf) {
+av_hashtable_freep(&res);
+return AVERROR(ENOMEM);
+}
+*ctx = res;
+return 0;
+}
+
+static size_t hash_key(const struct AVHashtableContext* ctx, const void* key)
+{
+return av_crc(ctx->crc, 0, key, ctx->key_size) % ctx->max_entries;
+}
+
+int av_hashtable_get(const struct AVHashtableContext* ctx, const void* key, 
void* val)
+{
+size_t hash = hash_key(ctx, key);
+
+if (!ctx->utilization)
+return 0;
+
+for (size_t psl = 0; psl < ctx->max_entries; psl++) {
+size_t wrapped_index = (hash + psl) % ctx->max_entries;
+   

[FFmpeg-devel] [PATCH v2 2/2] lavc/dxvenc: migrate DXT1 encoder to lavu hashtable

2024-02-06 Thread Connor Worley
Offers a modest performance gain due to the switch from naive linear
probling to robin hood.

Signed-off-by: Connor Worley 
---
 libavcodec/dxvenc.c | 121 
 1 file changed, 33 insertions(+), 88 deletions(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index b274175689..ebc48aace3 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -21,7 +21,7 @@
 
 #include 
 
-#include "libavutil/crc.h"
+#include "libavutil/hashtable.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 
@@ -37,76 +37,13 @@
  * appeared in the decompressed stream. Using a simple hash table (HT)
  * significantly speeds up the lookback process while encoding.
  */
-#define LOOKBACK_HT_ELEMS 0x4
+#define LOOKBACK_HT_ELEMS 0x20202
 #define LOOKBACK_WORDS0x20202
 
 enum DXVTextureFormat {
 DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
 };
 
-typedef struct HTEntry {
-uint32_t key;
-uint32_t pos;
-} HTEntry;
-
-static void ht_init(HTEntry *ht)
-{
-for (size_t i = 0; i < LOOKBACK_HT_ELEMS; i++) {
-ht[i].pos = -1;
-}
-}
-
-static uint32_t ht_lookup_and_upsert(HTEntry *ht, const AVCRC *hash_ctx,
-uint32_t key, uint32_t pos)
-{
-uint32_t ret = -1;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->key == key || entry->pos == -1) {
-ret = entry->pos;
-entry->key = key;
-entry->pos = pos;
-break;
-}
-}
-return ret;
-}
-
-static void ht_delete(HTEntry *ht, const AVCRC *hash_ctx,
-  uint32_t key, uint32_t pos)
-{
-HTEntry *removed_entry = NULL;
-size_t removed_hash;
-size_t hash = av_crc(hash_ctx, 0, (uint8_t*)&key, 4) % LOOKBACK_HT_ELEMS;
-
-for (size_t i = hash; i < hash + LOOKBACK_HT_ELEMS; i++) {
-size_t wrapped_index = i % LOOKBACK_HT_ELEMS;
-HTEntry *entry = &ht[wrapped_index];
-if (entry->pos == -1)
-return;
-if (removed_entry) {
-size_t candidate_hash = av_crc(hash_ctx, 0, (uint8_t*)&entry->key, 
4) % LOOKBACK_HT_ELEMS;
-if ((wrapped_index > removed_hash && (candidate_hash <= 
removed_hash || candidate_hash > wrapped_index)) ||
-(wrapped_index < removed_hash && (candidate_hash <= 
removed_hash && candidate_hash > wrapped_index))) {
-*removed_entry = *entry;
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-}
-} else if (entry->key == key) {
-if (entry->pos <= pos) {
-entry->pos = -1;
-removed_entry = entry;
-removed_hash = wrapped_index;
-} else {
-return;
-}
-}
-}
-}
-
 typedef struct DXVEncContext {
 AVClass *class;
 
@@ -123,10 +60,8 @@ typedef struct DXVEncContext {
 enum DXVTextureFormat tex_fmt;
 int (*compress_tex)(AVCodecContext *avctx);
 
-const AVCRC *crc_ctx;
-
-HTEntry color_lookback_ht[LOOKBACK_HT_ELEMS];
-HTEntry lut_lookback_ht[LOOKBACK_HT_ELEMS];
+struct AVHashtableContext *color_ht;
+struct AVHashtableContext *lut_ht;
 } DXVEncContext;
 
 /* Converts an index offset value to a 2-bit opcode and pushes it to a stream.
@@ -161,27 +96,32 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
 DXVEncContext *ctx = avctx->priv_data;
 PutByteContext *pbc = &ctx->pbc;
 uint32_t *value;
-uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
2, op = 0;
+uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 
0, op = 0;
 
-ht_init(ctx->color_lookback_ht);
-ht_init(ctx->lut_lookback_ht);
+av_hashtable_clear(ctx->color_ht);
+av_hashtable_clear(ctx->lut_ht);
 
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data));
+av_hashtable_set(ctx->color_ht, ctx->tex_data, &pos);
+pos++;
 bytestream2_put_le32(pbc, AV_RL32(ctx->tex_data + 4));
-
-ht_lookup_and_upsert(ctx->color_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data), 0);
-ht_lookup_and_upsert(ctx->lut_lookback_ht, ctx->crc_ctx, 
AV_RL32(ctx->tex_data + 4), 1);
+av_hashtable_set(ctx->lut_ht, ctx->tex_data + 4, &pos);
+pos++;
 
 while (pos + 2 <= ctx->tex_size / 4) {
 idx = 0;
+color_idx = 0;
+lut_idx = 0;
 
 color = AV_RL32(ctx->tex_data + pos * 4);
-prev_pos = ht_lookup_and_upsert(ctx->color_lookback_

[FFmpeg-devel] [PATCH v3 1/2] lavc/texturedsp: fix premult2straight inversion

2024-02-08 Thread Connor Worley
This function should convert premultiplied alpha to straight, but does the 
opposite.

Signed-off-by: Connor Worley 
---
 libavcodec/texturedsp.c | 9 ++---
 tests/ref/fate/dds-dxt2 | 2 +-
 tests/ref/fate/dds-dxt4 | 2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/libavcodec/texturedsp.c b/libavcodec/texturedsp.c
index 5fb79937da..721bfc17f5 100644
--- a/libavcodec/texturedsp.c
+++ b/libavcodec/texturedsp.c
@@ -175,9 +175,12 @@ static av_always_inline void premult2straight(uint8_t *src)
 int b = src[2];
 int a = src[3]; /* unchanged */
 
-src[0] = (uint8_t) r * a / 255;
-src[1] = (uint8_t) g * a / 255;
-src[2] = (uint8_t) b * a / 255;
+if (a == 0)
+return;
+
+src[0] = (uint8_t) FFMIN(r * 255 / a, 255);
+src[1] = (uint8_t) FFMIN(g * 255 / a, 255);
+src[2] = (uint8_t) FFMIN(b * 255 / a, 255);
 }
 
 /**
diff --git a/tests/ref/fate/dds-dxt2 b/tests/ref/fate/dds-dxt2
index b5bdfbadc3..1744ef41f6 100644
--- a/tests/ref/fate/dds-dxt2
+++ b/tests/ref/fate/dds-dxt2
@@ -3,4 +3,4 @@
 #codec_id 0: rawvideo
 #dimensions 0: 64x64
 #sar 0: 0/1
-0,  0,  0,1,16384, 0x11cebeb0
+0,  0,  0,1,16384, 0xd7f7241b
diff --git a/tests/ref/fate/dds-dxt4 b/tests/ref/fate/dds-dxt4
index 136dfd8006..f22878da56 100644
--- a/tests/ref/fate/dds-dxt4
+++ b/tests/ref/fate/dds-dxt4
@@ -3,4 +3,4 @@
 #codec_id 0: rawvideo
 #dimensions 0: 64x64
 #sar 0: 0/1
-0,  0,  0,1,16384, 0x31aaacd6
+0,  0,  0,1,16384, 0xf18d4216
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 2/2] lavc/dxv: treat DXT5-tagged files as DXT4

2024-02-08 Thread Connor Worley
DXV files seem to misnomer DXT5 and really encode DXT4 with
premultiplied alpha. At least, this is what Resolume alley does.

To check, encode some input with alpha as "Normal Quality, With Alpha"
in Alley, then decode the output with this change -- results are true
to the original input compared to git-master.

Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 5923811b29..1e6791e63f 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -1074,7 +1074,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 break;
 case MKBETAG('D', 'X', 'T', '5'):
 decompress_tex = dxv_decompress_dxt5;
-ctx->tex_funct = ctx->texdsp.dxt5_block;
+/* DXV misnomers DXT5, alpha is premultiplied so use DXT4 instead */
+ctx->tex_funct = ctx->texdsp.dxt4_block;
 ctx->tex_rat   = 4;
 ctx->tex_step  = 16;
 msgcomp = "DXTR5";
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] lavc/dxvenc: fix failing FATE tests

2024-02-09 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavcodec/dxvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index ebc48aace3..b92d99981c 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -234,7 +234,7 @@ static av_cold int dxv_init(AVCodecContext *avctx)
 ctx->enc.tex_ratio;
 ctx->enc.slice_count = av_clip(avctx->thread_count, 1, 
FFALIGN(avctx->height, 16) / TEXTURE_BLOCK_H);
 
-ctx->tex_data = av_malloc(ctx->tex_size);
+ctx->tex_data = av_mallocz(ctx->tex_size);
 if (!ctx->tex_data) {
 return AVERROR(ENOMEM);
 }
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] lavc/dxvenc: fix failing FATE tests

2024-02-09 Thread Connor Worley
Prevents access to uninitialized parts of ctx->tex_data, which were
causing FATE tets to fail under valgrind with --malloc-fill set.

Signed-off-by: Connor Worley 
---
 libavcodec/dxvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index ebc48aace3..b92d99981c 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -234,7 +234,7 @@ static av_cold int dxv_init(AVCodecContext *avctx)
 ctx->enc.tex_ratio;
 ctx->enc.slice_count = av_clip(avctx->thread_count, 1, 
FFALIGN(avctx->height, 16) / TEXTURE_BLOCK_H);

-ctx->tex_data = av_malloc(ctx->tex_size);
+ctx->tex_data = av_mallocz(ctx->tex_size);
 if (!ctx->tex_data) {
 return AVERROR(ENOMEM);
 }
--
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] lavc/dxvenc: fix uninitialized texture data access

2024-02-09 Thread Connor Worley
Prevents access to uninitialized parts of ctx->tex_data, which were
causing FATE tets to fail under valgrind with --malloc-fill set.

Signed-off-by: Connor Worley 
---
 libavcodec/dxvenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index ebc48aace3..b92d99981c 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -234,7 +234,7 @@ static av_cold int dxv_init(AVCodecContext *avctx)
 ctx->enc.tex_ratio;
 ctx->enc.slice_count = av_clip(avctx->thread_count, 1, 
FFALIGN(avctx->height, 16) / TEXTURE_BLOCK_H);
 
-ctx->tex_data = av_malloc(ctx->tex_size);
+ctx->tex_data = av_mallocz(ctx->tex_size);
 if (!ctx->tex_data) {
 return AVERROR(ENOMEM);
 }
-- 
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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] lavc/dxv: align to 4x4 blocks instead of 16x16

2024-02-09 Thread Connor Worley
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.

Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c|  6 +++---
 libavcodec/dxvenc.c | 13 ++---
 tests/ref/fate/dxv3enc-dxt1 |  2 +-
 3 files changed, 14 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 ebc48aace3..3023a6da6c 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -216,6 +216,13 @@ 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 
%dx%d.\n",
+   avctx->width, avctx->height,
+   TEXTURE_BLOCK_W, TEXTURE_BLOCK_H);
+return AVERROR_INVALIDDATA;
+}
+
 ff_texturedspenc_init(&texdsp);
 
 switch (ctx->tex_fmt) {
@@ -229,10 +236,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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] lavc/dxv: align to 4x4 blocks instead of 16x16

2024-02-09 Thread Connor Worley
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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 1/2] lavu/hashtable: create generic robin hood hash table

2024-02-10 Thread Connor Worley
On Wed, Feb 7, 2024 at 2:16 AM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Connor Worley:
> > +#define ENTRY_PSL(entry) (entry)
> > +#define ENTRY_OCC(entry) (ENTRY_PSL(entry) + sizeof(size_t))
> > +#define ENTRY_KEY(entry) (ENTRY_OCC(entry) + 4)
> > +#define ENTRY_VAL(entry) (ENTRY_KEY(entry) + FFALIGN(ctx->key_size, 4))
> > +
>
> It seems you misunderstood what I said about alignment in my last
> review. You should align entry_size and not align the size of key and
> val fields. The way you are doing it now does not prevent unaligned
> accesses: Imagine the common case of size_t having an alignment
> requirement of 8 and key_size and val_size being four. Then entry_size
> is not a multiple of 8 and therefore of two consecutive entries, only
> one can be properly aligned (e.g. the second entry
> ctx->table+ctx->entry_size is misaligned).
> (For the same reason, the alignment of a struct is a multiple of the
> alignment of every member of said struct.)
> The way you are doing it also adds FFALIGN to every access to val.
>

Apologies as I don't usually write C. Is it not necessary to ensure val is
aligned?
Would aligning every field to sizeof(size_t) be sufficient for ensuring
consecutive entries are aligned?

I believe I would need to store a possibly rounded-up key_size to avoid the
FFALIGN in val access.

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 1/3] lavc/dxv: move tag definitions to common header

2024-02-10 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c|  9 +
 libavcodec/dxv.h| 34 ++
 libavcodec/dxvenc.c |  7 ++-
 3 files changed, 41 insertions(+), 9 deletions(-)
 create mode 100644 libavcodec/dxv.h

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 9261a5cac1..16c34fff3b 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -28,6 +28,7 @@
 #include "avcodec.h"
 #include "bytestream.h"
 #include "codec_internal.h"
+#include "dxv.h"
 #include "lzf.h"
 #include "texturedsp.h"
 #include "thread.h"
@@ -1064,7 +1065,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 
 tag = bytestream2_get_le32(gbc);
 switch (tag) {
-case MKBETAG('D', 'X', 'T', '1'):
+case DXV_FMT_DXT1:
 decompress_tex = dxv_decompress_dxt1;
 ctx->tex_funct = ctx->texdsp.dxt1_block;
 ctx->tex_rat   = 8;
@@ -1072,7 +1073,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 msgcomp = "DXTR1";
 msgtext = "DXT1";
 break;
-case MKBETAG('D', 'X', 'T', '5'):
+case DXV_FMT_DXT5:
 decompress_tex = dxv_decompress_dxt5;
 /* DXV misnomers DXT5, alpha is premultiplied so use DXT4 instead */
 ctx->tex_funct = ctx->texdsp.dxt4_block;
@@ -1081,7 +1082,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 msgcomp = "DXTR5";
 msgtext = "DXT5";
 break;
-case MKBETAG('Y', 'C', 'G', '6'):
+case DXV_FMT_YCG6:
 decompress_tex = dxv_decompress_ycg6;
 ctx->tex_funct_planar[0] = yo_block;
 ctx->tex_funct_planar[1] = cocg_block;
@@ -1098,7 +1099,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 avctx->colorspace = AVCOL_SPC_YCOCG;
 break;
-case MKBETAG('Y', 'G', '1', '0'):
+case DXV_FMT_YG10:
 decompress_tex = dxv_decompress_yg10;
     ctx->tex_funct_planar[0] = yao_block;
 ctx->tex_funct_planar[1] = cocg_block;
diff --git a/libavcodec/dxv.h b/libavcodec/dxv.h
new file mode 100644
index 00..71cfddec85
--- /dev/null
+++ b/libavcodec/dxv.h
@@ -0,0 +1,34 @@
+/*
+ * Resolume DXV common
+ * Copyright (C) 2024 Connor Worley 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_DXV_H
+#define AVCODEC_DXV_H
+
+#include "libavutil/macros.h"
+
+typedef enum DXVTextureFormat {
+DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
+DXV_FMT_DXT5 = MKBETAG('D', 'X', 'T', '5'),
+DXV_FMT_YCG6 = MKBETAG('Y', 'C', 'G', '6'),
+DXV_FMT_YG10 = MKBETAG('Y', 'G', '1', '0'),
+} DXVTextureFormat;
+
+#endif /* AVCODEC_DXV_H */
diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index 33a18d53d8..bb2c2f8526 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -27,6 +27,7 @@
 
 #include "bytestream.h"
 #include "codec_internal.h"
+#include "dxv.h"
 #include "encode.h"
 #include "texturedsp.h"
 
@@ -40,10 +41,6 @@
 #define LOOKBACK_HT_ELEMS 0x4
 #define LOOKBACK_WORDS0x20202
 
-enum DXVTextureFormat {
-DXV_FMT_DXT1 = MKBETAG('D', 'X', 'T', '1'),
-};
-
 typedef struct HTEntry {
 uint32_t key;
 uint32_t pos;
@@ -120,7 +117,7 @@ typedef struct DXVEncContext {
 
 TextureDSPThreadContext enc;
 
-enum DXVTextureFormat tex_fmt;
+DXVTextureFormat tex_fmt;
 int (*compress_tex)(AVCodecContext *avctx);
 
 const AVCRC *crc_ctx;
-- 
2.43.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 2/3] lavc/dvx: use texdsp funcs for texture block decompression

2024-02-10 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c | 289 ---
 1 file changed, 75 insertions(+), 214 deletions(-)

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 16c34fff3b..cd78de3e0d 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -38,15 +38,12 @@ typedef struct DXVContext {
 GetByteContext gbc;
 
 uint8_t *tex_data;   // Compressed texture
-uint8_t *ctex_data;  // Compressed texture
+uint8_t *ctex_data;  // Compressed chroma texture
 int tex_rat; // Compression ratio
 int tex_step;// Distance between blocks
 int ctex_step;   // Distance between blocks
 int64_t tex_size;// Texture size
-int64_t ctex_size;   // Texture size
-
-/* Optimal number of slices for parallel decoding */
-int slice_count;
+int64_t ctex_size;   // Chroma texture size
 
 uint8_t *op_data[4]; // Opcodes
 int64_t op_size[4];  // Opcodes size
@@ -56,198 +53,8 @@ typedef struct DXVContext {
 
 int ctexture_block_w;
 int ctexture_block_h;
-
-/* Pointer to the selected decompression function */
-int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
-int (*tex_funct_planar[2])(uint8_t *plane0, ptrdiff_t stride0,
-   uint8_t *plane1, ptrdiff_t stride1,
-   const uint8_t *block);
 } DXVContext;
 
-static void decompress_indices(uint8_t *dst, const uint8_t *src)
-{
-int block, i;
-
-for (block = 0; block < 2; block++) {
-int tmp = AV_RL24(src);
-
-/* Unpack 8x3 bit from last 3 byte block */
-for (i = 0; i < 8; i++)
-dst[i] = (tmp >> (i * 3)) & 0x7;
-
-src += 3;
-dst += 8;
-}
-}
-
-static int extract_component(int yo0, int yo1, int code)
-{
-int yo;
-
-if (yo0 == yo1) {
-yo = yo0;
-} else if (code == 0) {
-yo = yo0;
-} else if (code == 1) {
-yo = yo1;
-} else {
-if (yo0 > yo1) {
-yo = (uint8_t) (((8 - code) * yo0 +
- (code - 1) * yo1) / 7);
-} else {
-if (code == 6) {
-yo = 0;
-} else if (code == 7) {
-yo = 255;
-} else {
-yo = (uint8_t) (((6 - code) * yo0 +
- (code - 1) * yo1) / 5);
-}
-}
-}
-
-return yo;
-}
-
-static int cocg_block(uint8_t *plane0, ptrdiff_t stride0,
-  uint8_t *plane1, ptrdiff_t stride1,
-  const uint8_t *block)
-{
-uint8_t co_indices[16];
-uint8_t cg_indices[16];
-uint8_t co0 = *(block);
-uint8_t co1 = *(block + 1);
-uint8_t cg0 = *(block + 8);
-uint8_t cg1 = *(block + 9);
-int x, y;
-
-decompress_indices(co_indices, block + 2);
-decompress_indices(cg_indices, block + 10);
-
-for (y = 0; y < 4; y++) {
-for (x = 0; x < 4; x++) {
-int co_code = co_indices[x + y * 4];
-int cg_code = cg_indices[x + y * 4];
-
-plane0[x] = extract_component(cg0, cg1, cg_code);
-plane1[x] = extract_component(co0, co1, co_code);
-}
-plane0 += stride0;
-plane1 += stride1;
-}
-
-return 16;
-}
-
-static void yao_subblock(uint8_t *dst, uint8_t *yo_indices,
-ptrdiff_t stride, const uint8_t *block)
-{
-uint8_t yo0 = *(block);
-uint8_t yo1 = *(block + 1);
-int x, y;
-
-decompress_indices(yo_indices, block + 2);
-
-for (y = 0; y < 4; y++) {
-for (x = 0; x < 4; x++) {
-int yo_code = yo_indices[x + y * 4];
-
-dst[x] = extract_component(yo0, yo1, yo_code);
-}
-dst += stride;
-}
-}
-
-static int yo_block(uint8_t *dst, ptrdiff_t stride,
-uint8_t *unused0, ptrdiff_t unused1,
-const uint8_t *block)
-{
-uint8_t yo_indices[16];
-
-yao_subblock(dst,  yo_indices, stride, block);
-yao_subblock(dst + 4,  yo_indices, stride, block + 8);
-yao_subblock(dst + 8,  yo_indices, stride, block + 16);
-yao_subblock(dst + 12, yo_indices, stride, block + 24);
-
-return 32;
-}
-
-static int yao_block(uint8_t *plane0, ptrdiff_t stride0,
- uint8_t *plane3, ptrdiff_t stride1,
- const uint8_t *block)
-{
-uint8_t yo_indices[16];
-uint8_t a_indices[16];
-
-yao_subblock(plane0,  yo_indices, stride0, block);
-yao_subblock(plane3,  a_indices,  stride1, block + 8);
-yao_subblock(plane0 + 4,  yo_indices, stride0, block + 16);
-yao_subblock(plane3 + 4,  a_indices,  stride1, block + 24);
-yao_subblock(plane0 + 8,  yo_indices, stride0, block + 32);
-yao_subblock(plane3 + 8,  a_indices,  stride1, block + 40);
-yao_subblock(plane0 + 12, yo_indices, stride0, block + 48);
-yao_subblock(plane3 + 12, a_indices,  stride1

[FFmpeg-devel] [PATCH v2 3/3] lavc/dxv: remove ctx fields that can be derived from texdsp ctxs

2024-02-10 Thread Connor Worley
Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c | 53 
 1 file changed, 9 insertions(+), 44 deletions(-)

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index cd78de3e0d..82c493f1de 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -39,20 +39,12 @@ typedef struct DXVContext {
 
 uint8_t *tex_data;   // Compressed texture
 uint8_t *ctex_data;  // Compressed chroma texture
-int tex_rat; // Compression ratio
-int tex_step;// Distance between blocks
-int ctex_step;   // Distance between blocks
+
 int64_t tex_size;// Texture size
 int64_t ctex_size;   // Chroma texture size
 
 uint8_t *op_data[4]; // Opcodes
 int64_t op_size[4];  // Opcodes size
-
-int texture_block_w;
-int texture_block_h;
-
-int ctexture_block_w;
-int ctexture_block_h;
 } DXVContext;
 
 /* This scheme addresses already decoded elements depending on 2-bit status:
@@ -865,9 +857,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 cavctx.coded_height = avctx->coded_height / 2;
 cavctx.coded_width  = avctx->coded_width  / 2;
 
-ctx->texture_block_h = 4;
-ctx->texture_block_w = 4;
-
 avctx->pix_fmt = AV_PIX_FMT_RGBA;
 avctx->colorspace = AVCOL_SPC_RGB;
 
@@ -878,8 +867,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 texdsp_ctx.tex_funct = ctx->texdsp.dxt1_block;
 texdsp_ctx.tex_ratio = 8;
 texdsp_ctx.raw_ratio = 16;
-ctx->tex_rat   = 8;
-ctx->tex_step  = 8;
 msgcomp = "DXTR1";
 msgtext = "DXT1";
 break;
@@ -889,8 +876,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 texdsp_ctx.tex_funct = ctx->texdsp.dxt4_block;
 texdsp_ctx.tex_ratio = 16;
 texdsp_ctx.raw_ratio = 16;
-ctx->tex_rat   = 4;
-ctx->tex_step  = 16;
 msgcomp = "DXTR5";
 msgtext = "DXT5";
 break;
@@ -902,16 +887,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 ctexdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block;
 ctexdsp_ctx.tex_ratio = 16;
 ctexdsp_ctx.raw_ratio = 4;
-ctx->tex_rat   = 8;
-ctx->tex_step  = 32;
-ctx->ctex_step = 16;
 msgcomp = "YOCOCG6";
 msgtext = "YCG6";
-ctx->ctex_size = avctx->coded_width * avctx->coded_height / 4;
-ctx->texture_block_h = 4;
-ctx->texture_block_w = 16;
-ctx->ctexture_block_h = 4;
-ctx->ctexture_block_w = 4;
 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 avctx->colorspace = AVCOL_SPC_YCOCG;
 break;
@@ -923,16 +900,8 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 ctexdsp_ctx.tex_funct = ctx->texdsp.rgtc1u_gray_block;
 ctexdsp_ctx.tex_ratio = 16;
 ctexdsp_ctx.raw_ratio = 4;
-ctx->tex_rat   = 4;
-ctx->tex_step  = 64;
-ctx->ctex_step = 16;
 msgcomp = "YAOCOCG10";
 msgtext = "YG10";
-ctx->ctex_size = avctx->coded_width * avctx->coded_height / 4;
-ctx->texture_block_h = 4;
-ctx->texture_block_w = 16;
-ctx->ctexture_block_h = 4;
-ctx->ctexture_block_w = 4;
 avctx->pix_fmt = AV_PIX_FMT_YUVA420P;
 avctx->colorspace = AVCOL_SPC_YCOCG;
 break;
@@ -957,7 +926,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 texdsp_ctx.tex_funct = ctx->texdsp.dxt5_block;
 texdsp_ctx.tex_ratio = 16;
 texdsp_ctx.raw_ratio = 16;
-ctx->tex_step  = 16;
 } else if (old_type & 0x20 || version_major == 1) {
 tag = DXV_FMT_DXT1;
 msgtext = "DXT1";
@@ -965,12 +933,10 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 texdsp_ctx.tex_funct = ctx->texdsp.dxt1_block;
 texdsp_ctx.tex_ratio = 8;
 texdsp_ctx.raw_ratio = 16;
-ctx->tex_step  = 8;
 } else {
 av_log(avctx, AV_LOG_ERROR, "Unsupported header 
(0x%08"PRIX32")\n.", tag);
 return AVERROR_INVALIDDATA;
 }
-ctx->tex_rat = 1;
 break;
 }
 
@@ -986,7 +952,6 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 /* Encoder copies texture data when compression is not advantageous. */
 if (bytestream2_get_byte(gbc)) {
 msgcomp = "RAW";
-ctx->tex_rat = 1;
 decompress_tex = dxv_decompress_raw;
 }
 
@@ -1004,14 +969,20 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame 
*frame,
 return AVERROR_INVALIDDATA;
 }
 
-ctx->tex_size = avctx->coded_width * avctx->coded_height * 

[FFmpeg-devel] [PATCH] lavc/dxv: assume DXV2 files use premultiplied alpha

2024-02-11 Thread Connor Worley
I generated a DXV2 file with an interesting alpha channel using
Adobe Media Encoder 2015 and compared decoding it using Resolume Alley
and ffmpeg. Similarly to DXV3 files, Alley expects premultiplied alpha
and ffmpeg matches its decoding more closely when it does the same.

Reference file: https://connorworley.com/dxv2-dxt5.mov

Existing FATE tests for DXV2 files do not cover this change.

Signed-off-by: Connor Worley 
---
 libavcodec/dxv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dxv.c b/libavcodec/dxv.c
index 82c493f1de..2eca14c129 100644
--- a/libavcodec/dxv.c
+++ b/libavcodec/dxv.c
@@ -923,7 +923,7 @@ static int dxv_decode(AVCodecContext *avctx, AVFrame *frame,
 tag = DXV_FMT_DXT5;
 msgtext = "DXT5";
 
-texdsp_ctx.tex_funct = ctx->texdsp.dxt5_block;
+texdsp_ctx.tex_funct = ctx->texdsp.dxt4_block;
 texdsp_ctx.tex_ratio = 16;
 texdsp_ctx.raw_ratio = 16;
 } else if (old_type & 0x20 || version_major == 1) {
-- 
2.43.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-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 3/3] lavc/dxv: remove ctx fields that can be derived from texdsp ctxs

2024-02-11 Thread Connor Worley
On Sun, Feb 11, 2024 at 1:03 AM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Connor Worley:
> > -{
> > -int w_block = avctx->coded_width / ctx->texture_block_w;
> > -int h_block = avctx->coded_height / ctx->texture_block_h;
> > -if (w_block * h_block * ctx->tex_step > ctx->tex_size * 8LL)
> > -return AVERROR_INVALIDDATA;
> > -}
>
> You removed this check without replacement. It presumably fixed a bug.
> Did you test whether you reopened said bug?
> (I think I already asked this in an earlier iteration of this patchset.)
>
> - Andreas
>

My change redefines tex_size to be equal to or less than the left-hand-side
of that if statement, making it redundant AFAICT.
I do see the check was added to fix
10979/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_DXV_fuzzer-6178582203203584,
but I'm not familiar with the fuzzing system. If there's a way to replay
the bad input, I'd be curious to try.

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 3/3] lavc/dxv: remove ctx fields that can be derived from texdsp ctxs

2024-02-11 Thread Connor Worley
"or less than" is wrong -- rather tex_step seems to have been larger than
necessary in some cases. With the minimal tex_step in those cases, the new
tex_size should be equal to the LHS.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH v2 3/3] lavc/dxv: remove ctx fields that can be derived from texdsp ctxs

2024-02-11 Thread Connor Worley
On Sun, Feb 11, 2024 at 9:41 AM James Almer  wrote:

> On 2/11/2024 9:41 AM, Connor Worley wrote:
> > "or less than" is wrong -- rather tex_step seems to have been larger than
> > necessary in some cases. With the minimal tex_step in those cases, the
> new
> > tex_size should be equal to the LHS.
>
> This set broke fate when using slice threading:
>
> https://fate.ffmpeg.org/report.cgi?slot=x86_64-archlinux-gcc-threads-misc&time=20240211015448


Thanks, I will investigate.

-- 
Connor Worley
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".