}
/*
- * 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.
*
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);
#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);
struct {
enum translate_element_type type;
- fetch_func fetch;
+ util_format_fetch_rgba_func_ptr fetch;
unsigned buffer;
unsigned input_offset;
unsigned instance_divisor;
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);
}
}
- 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;
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) {
* 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 */
{
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
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;
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
{
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)
{
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.
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;
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.
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:
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)
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 = []
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;
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;
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);