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>
This commit is contained in:
Eric Anholt 2020-08-13 09:37:32 -07:00 committed by Marge Bot
parent 9cc84369b7
commit 5b8d67cb64
7 changed files with 61 additions and 34 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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 */

View file

@ -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)
{

View file

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

View file

@ -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 = []

View file

@ -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);