Mesa (master): util: Move fetch_rgba to a separate function table.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Aug 16 21:42:25 UTC 2020
Module: Mesa
Branch: master
Commit: 5b8d67cb64ca38c93089da2f0b414c5897a19e27
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=5b8d67cb64ca38c93089da2f0b414c5897a19e27
Author: Eric Anholt <eric at anholt.net>
Date: Thu Aug 13 09:37:32 2020 -0700
util: Move fetch_rgba to a separate function table.
Only llvmpipe and translate_generic use it, and only in fallbacks, so if
you're not building that then let's not bloat our binaries with it.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6305>
---
src/gallium/auxiliary/gallivm/lp_bld_format_aos.c | 8 ++++---
.../auxiliary/translate/translate_generic.c | 10 +++-----
src/gallium/drivers/llvmpipe/lp_test_format.c | 4 +---
src/gallium/tests/unit/translate_test.c | 16 +++++++------
src/util/format/u_format.h | 18 ++++++++-------
src/util/format/u_format_table.py | 27 ++++++++++++++++++++--
src/util/tests/format/u_format_test.c | 12 ++++++----
7 files changed, 61 insertions(+), 34 deletions(-)
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
index aa99c2a7e2e..74fe1672b27 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
@@ -894,10 +894,12 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm,
}
/*
- * Fallback to util_format_description::fetch_rgba_float().
+ * Fallback to fetch_rgba().
*/
- if (unpack->fetch_rgba) {
+ util_format_fetch_rgba_func_ptr fetch_rgba =
+ util_format_fetch_rgba_func(format_desc->format);
+ if (fetch_rgba) {
/*
* Fallback to calling util_format_description::fetch_rgba_float.
*
@@ -944,7 +946,7 @@ lp_build_fetch_rgba_aos(struct gallivm_state *gallivm,
if (gallivm->cache)
gallivm->cache->dont_cache = true;
function = lp_build_const_func_pointer(gallivm,
- func_to_pointer((func_pointer) unpack->fetch_rgba),
+ func_to_pointer((func_pointer) fetch_rgba),
ret_type,
arg_types, ARRAY_SIZE(arg_types),
format_desc->short_name);
diff --git a/src/gallium/auxiliary/translate/translate_generic.c b/src/gallium/auxiliary/translate/translate_generic.c
index 311fc384ffe..14631da33cd 100644
--- a/src/gallium/auxiliary/translate/translate_generic.c
+++ b/src/gallium/auxiliary/translate/translate_generic.c
@@ -40,9 +40,6 @@
#define DRAW_DBG 0
-typedef void (*fetch_func)(void *dst,
- const uint8_t *src,
- unsigned i, unsigned j);
typedef void (*emit_func)(const void *attrib, void *ptr);
@@ -53,7 +50,7 @@ struct translate_generic {
struct {
enum translate_element_type type;
- fetch_func fetch;
+ util_format_fetch_rgba_func_ptr fetch;
unsigned buffer;
unsigned input_offset;
unsigned instance_divisor;
@@ -799,8 +796,6 @@ translate_generic_create(const struct translate_key *key)
for (i = 0; i < key->nr_elements; i++) {
const struct util_format_description *format_desc =
util_format_description(key->element[i].input_format);
- const struct util_format_unpack_description *unpack =
- util_format_unpack_description(key->element[i].input_format);
assert(format_desc);
@@ -816,7 +811,8 @@ translate_generic_create(const struct translate_key *key)
}
}
- tg->attrib[i].fetch = (fetch_func)unpack->fetch_rgba;
+ tg->attrib[i].fetch =
+ util_format_fetch_rgba_func(key->element[i].input_format);
tg->attrib[i].buffer = key->element[i].input_buffer;
tg->attrib[i].input_offset = key->element[i].input_offset;
tg->attrib[i].instance_divisor = key->element[i].instance_divisor;
diff --git a/src/gallium/drivers/llvmpipe/lp_test_format.c b/src/gallium/drivers/llvmpipe/lp_test_format.c
index 5facd85e309..38b3c48b294 100644
--- a/src/gallium/drivers/llvmpipe/lp_test_format.c
+++ b/src/gallium/drivers/llvmpipe/lp_test_format.c
@@ -367,8 +367,6 @@ test_all(unsigned verbose, FILE *fp)
for (use_cache = 0; use_cache < 2; use_cache++) {
for (format = 1; format < PIPE_FORMAT_COUNT; ++format) {
const struct util_format_description *format_desc;
- const struct util_format_unpack_description *unpack =
- util_format_unpack_description(format);
format_desc = util_format_description(format);
if (!format_desc) {
@@ -392,7 +390,7 @@ test_all(unsigned verbose, FILE *fp)
* precompiled fetch func for any format before we write LLVM code to
* fetch from it.
*/
- if (!unpack->fetch_rgba)
+ if (!util_format_fetch_rgba_func(format))
continue;
/* only test twice with formats which can use cache */
diff --git a/src/gallium/tests/unit/translate_test.c b/src/gallium/tests/unit/translate_test.c
index 807995cd256..b07db7f4eb8 100644
--- a/src/gallium/tests/unit/translate_test.c
+++ b/src/gallium/tests/unit/translate_test.c
@@ -173,12 +173,13 @@ int main(int argc, char** argv)
{
const struct util_format_description* output_format_desc = util_format_description(output_format);
const struct util_format_pack_description* output_format_pack = util_format_pack_description(output_format);
- const struct util_format_unpack_description* output_format_unpack = util_format_unpack_description(output_format);
+ util_format_fetch_rgba_func_ptr fetch_rgba =
+ util_format_fetch_rgba_func(output_format);
unsigned output_format_size;
unsigned output_normalized = 0;
if (!output_format_desc
- || !output_format_unpack->fetch_rgba
+ || !fetch_rgba
|| !output_format_pack->pack_rgba_float
|| output_format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB
|| output_format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN
@@ -196,8 +197,9 @@ int main(int argc, char** argv)
for (input_format = 1; input_format < PIPE_FORMAT_COUNT; ++input_format)
{
const struct util_format_description* input_format_desc = util_format_description(input_format);
- const struct util_format_pack_description* input_format_pack = util_format_pack_description(input_format);
- const struct util_format_unpack_description* input_format_unpack = util_format_unpack_description(input_format);
+ const struct util_format_pack_description* input_format_pack = util_format_pack_description(input_format);
+ util_format_fetch_rgba_func_ptr fetch_rgba =
+ util_format_fetch_rgba_func(input_format);
unsigned input_format_size;
struct translate* translate[2];
unsigned fail = 0;
@@ -206,7 +208,7 @@ int main(int argc, char** argv)
boolean input_is_float = FALSE;
if (!input_format_desc
- || !input_format_unpack->fetch_rgba
+ || !fetch_rgba
|| !input_format_pack->pack_rgba_float
|| input_format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB
|| input_format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN
@@ -277,8 +279,8 @@ int main(int argc, char** argv)
{
float a[4];
float b[4];
- input_format_unpack->fetch_rgba(a, buffer[2] + i * input_format_size, 0, 0);
- input_format_unpack->fetch_rgba(b, buffer[4] + i * input_format_size, 0, 0);
+ fetch_rgba(a, buffer[2] + i * input_format_size, 0, 0);
+ fetch_rgba(b, buffer[4] + i * input_format_size, 0, 0);
for (j = 0; j < count; ++j)
{
diff --git a/src/util/format/u_format.h b/src/util/format/u_format.h
index bfbf74d1fb8..034d43a2897 100644
--- a/src/util/format/u_format.h
+++ b/src/util/format/u_format.h
@@ -345,14 +345,6 @@ struct util_format_unpack_description {
const uint8_t *src, unsigned src_stride,
unsigned width, unsigned height);
- /**
- * Fetch a single pixel (i, j) from a block.
- *
- * Only defined for non-depth-stencil and non-integer formats.
- */
- void
- (*fetch_rgba)(void *dst, const uint8_t *src, unsigned i, unsigned j);
-
/**
* Unpack pixels to Z32_UNORM.
* Note: strides are in bytes.
@@ -387,6 +379,9 @@ struct util_format_unpack_description {
unsigned width, unsigned height);
};
+typedef void (*util_format_fetch_rgba_func_ptr)(void *dst, const uint8_t *src,
+ unsigned i, unsigned j);
+
const struct util_format_description *
util_format_description(enum pipe_format format) ATTRIBUTE_CONST;
@@ -396,6 +391,13 @@ util_format_pack_description(enum pipe_format format) ATTRIBUTE_CONST;
const struct util_format_unpack_description *
util_format_unpack_description(enum pipe_format format) ATTRIBUTE_CONST;
+/**
+ * Returns a function to fetch a single pixel (i, j) from a block.
+ *
+ * Only defined for non-depth-stencil and non-integer formats.
+ */
+util_format_fetch_rgba_func_ptr
+util_format_fetch_rgba_func(enum pipe_format format) ATTRIBUTE_CONST;
/*
* Format query functions.
diff --git a/src/util/format/u_format_table.py b/src/util/format/u_format_table.py
index 7be1d4fdb5b..e3bbe1d27e6 100644
--- a/src/util/format/u_format_table.py
+++ b/src/util/format/u_format_table.py
@@ -174,6 +174,17 @@ def write_format_table(formats):
print("}")
print()
+ def generate_function_getter(func):
+ print("util_format_%s_func_ptr" % func)
+ print("util_format_%s_func(enum pipe_format format)" % (func))
+ print("{")
+ print(" if (format >= ARRAY_SIZE(util_format_%s_table))" % (func))
+ print(" return NULL;")
+ print()
+ print(" return util_format_%s_table[format];" % (func))
+ print("}")
+ print()
+
print('static const struct util_format_description')
print('util_format_descriptions[] = {')
for format in formats:
@@ -240,8 +251,6 @@ def write_format_table(formats):
continue
print(" [%s] = {" % (format.name,))
- if format.colorspace != ZS:
- print(" .fetch_rgba = &util_format_%s_fetch_rgba," % sn)
if format.colorspace != ZS and not format.is_pure_color():
print(" .unpack_rgba_8unorm = &util_format_%s_unpack_rgba_8unorm," % sn)
@@ -266,6 +275,20 @@ def write_format_table(formats):
generate_table_getter("unpack_")
+ print('static const util_format_fetch_rgba_func_ptr util_format_fetch_rgba_table[] = {')
+ for format in formats:
+ sn = format.short_name()
+
+ if format.colorspace != ZS and has_access(format):
+ print(" [%s] = &util_format_%s_fetch_rgba," % (format.name, sn))
+ else:
+ print(" [%s] = NULL," % format.name)
+
+ print("};")
+ print()
+
+ generate_function_getter("fetch_rgba")
+
def main():
formats = []
diff --git a/src/util/tests/format/u_format_test.c b/src/util/tests/format/u_format_test.c
index 992bf5f3a95..d33b41af8c2 100644
--- a/src/util/tests/format/u_format_test.c
+++ b/src/util/tests/format/u_format_test.c
@@ -204,8 +204,8 @@ static boolean
test_format_fetch_rgba(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
- const struct util_format_unpack_description *unpack =
- util_format_unpack_description(format_desc->format);
+ util_format_fetch_rgba_func_ptr fetch_rgba =
+ util_format_fetch_rgba_func(format_desc->format);
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
unsigned i, j, k;
boolean success;
@@ -213,7 +213,7 @@ test_format_fetch_rgba(const struct util_format_description *format_desc,
success = TRUE;
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
- unpack->fetch_rgba(unpacked[i][j], test->packed, j, i);
+ fetch_rgba(unpacked[i][j], test->packed, j, i);
for (k = 0; k < 4; ++k) {
if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) {
success = FALSE;
@@ -818,7 +818,11 @@ test_all(void)
success = FALSE; \
} \
- TEST_ONE_UNPACK_FUNC(fetch_rgba);
+ if (util_format_fetch_rgba_func(format)) {
+ if (!test_one_func(format_desc, test_format_fetch_rgba, "fetch_rgba"))
+ success = FALSE;
+ }
+
TEST_ONE_PACK_FUNC(pack_rgba_float);
TEST_ONE_UNPACK_FUNC(unpack_rgba);
TEST_ONE_PACK_FUNC(pack_rgba_8unorm);
More information about the mesa-commit
mailing list