diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2018-10-23 05:47:28 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2018-10-23 05:47:28 +0000 |
commit | f6666e4c3977a5d74f3da7464672ea48e44dff4b (patch) | |
tree | 21df237f03b2aabc094d514d3d8f0d13c4f00f4e /lib/mesa/src/gallium/auxiliary/util | |
parent | 6f93ffbe5713be116f31de00cb562a09606a779c (diff) |
Import Mesa 17.3.9
Diffstat (limited to 'lib/mesa/src/gallium/auxiliary/util')
-rw-r--r-- | lib/mesa/src/gallium/auxiliary/util/u_dump_defines.c | 125 | ||||
-rw-r--r-- | lib/mesa/src/gallium/auxiliary/util/u_format_s3tc.c | 133 | ||||
-rw-r--r-- | lib/mesa/src/gallium/auxiliary/util/u_format_s3tc.h | 6 | ||||
-rw-r--r-- | lib/mesa/src/gallium/auxiliary/util/u_format_tests.c | 19 | ||||
-rw-r--r-- | lib/mesa/src/gallium/auxiliary/util/u_idalloc.c | 96 | ||||
-rw-r--r-- | lib/mesa/src/gallium/auxiliary/util/u_idalloc.h | 62 | ||||
-rw-r--r-- | lib/mesa/src/gallium/auxiliary/util/u_log.c | 235 | ||||
-rw-r--r-- | lib/mesa/src/gallium/auxiliary/util/u_log.h | 100 | ||||
-rw-r--r-- | lib/mesa/src/gallium/auxiliary/util/u_mm.c | 5 |
9 files changed, 603 insertions, 178 deletions
diff --git a/lib/mesa/src/gallium/auxiliary/util/u_dump_defines.c b/lib/mesa/src/gallium/auxiliary/util/u_dump_defines.c index 9d831efcf..e87e53016 100644 --- a/lib/mesa/src/gallium/auxiliary/util/u_dump_defines.c +++ b/lib/mesa/src/gallium/auxiliary/util/u_dump_defines.c @@ -62,36 +62,36 @@ util_dump_enum_continuous(unsigned value, } -#define DEFINE_UTIL_DUMP_CONTINUOUS(_name) \ +#define DEFINE_UTIL_STR_CONTINUOUS(_name) \ const char * \ - util_dump_##_name(unsigned value, boolean shortened) \ + util_str_##_name(unsigned value, boolean shortened) \ { \ if(shortened) \ - return util_dump_enum_continuous(value, ARRAY_SIZE(util_dump_##_name##_short_names), util_dump_##_name##_short_names); \ + return util_dump_enum_continuous(value, ARRAY_SIZE(util_##_name##_short_names), util_##_name##_short_names); \ else \ - return util_dump_enum_continuous(value, ARRAY_SIZE(util_dump_##_name##_names), util_dump_##_name##_names); \ + return util_dump_enum_continuous(value, ARRAY_SIZE(util_##_name##_names), util_##_name##_names); \ } /** - * Same as DEFINE_UTIL_DUMP_CONTINUOUS but with static assertions to detect + * Same as DEFINE_UTIL_STR_CONTINUOUS but with static assertions to detect * failures to update lists. */ -#define DEFINE_UTIL_DUMP_CONTINUOUS_COUNT(_name, _count) \ +#define DEFINE_UTIL_STR_CONTINUOUS_COUNT(_name, _count) \ const char * \ - util_dump_##_name(unsigned value, boolean shortened) \ + util_str_##_name(unsigned value, boolean shortened) \ { \ - STATIC_ASSERT(ARRAY_SIZE(util_dump_##_name##_names) == _count); \ - STATIC_ASSERT(ARRAY_SIZE(util_dump_##_name##_short_names) == _count); \ + STATIC_ASSERT(ARRAY_SIZE(util_##_name##_names) == _count); \ + STATIC_ASSERT(ARRAY_SIZE(util_##_name##_short_names) == _count); \ if(shortened) \ - return util_dump_enum_continuous(value, ARRAY_SIZE(util_dump_##_name##_short_names), util_dump_##_name##_short_names); \ + return util_dump_enum_continuous(value, ARRAY_SIZE(util_##_name##_short_names), util_##_name##_short_names); \ else \ - return util_dump_enum_continuous(value, ARRAY_SIZE(util_dump_##_name##_names), util_dump_##_name##_names); \ + return util_dump_enum_continuous(value, ARRAY_SIZE(util_##_name##_names), util_##_name##_names); \ } static const char * -util_dump_blend_factor_names[] = { +util_blend_factor_names[] = { UTIL_DUMP_INVALID_NAME, /* 0x0 */ "PIPE_BLENDFACTOR_ONE", "PIPE_BLENDFACTOR_SRC_COLOR", @@ -122,7 +122,7 @@ util_dump_blend_factor_names[] = { }; static const char * -util_dump_blend_factor_short_names[] = { +util_blend_factor_short_names[] = { UTIL_DUMP_INVALID_NAME, /* 0x0 */ "one", "src_color", @@ -152,11 +152,11 @@ util_dump_blend_factor_short_names[] = { "inv_src1_alpha" }; -DEFINE_UTIL_DUMP_CONTINUOUS(blend_factor) +DEFINE_UTIL_STR_CONTINUOUS(blend_factor) static const char * -util_dump_blend_func_names[] = { +util_blend_func_names[] = { "PIPE_BLEND_ADD", "PIPE_BLEND_SUBTRACT", "PIPE_BLEND_REVERSE_SUBTRACT", @@ -165,7 +165,7 @@ util_dump_blend_func_names[] = { }; static const char * -util_dump_blend_func_short_names[] = { +util_blend_func_short_names[] = { "add", "sub", "rev_sub", @@ -173,11 +173,11 @@ util_dump_blend_func_short_names[] = { "max" }; -DEFINE_UTIL_DUMP_CONTINUOUS(blend_func) +DEFINE_UTIL_STR_CONTINUOUS(blend_func) static const char * -util_dump_logicop_names[] = { +util_logicop_names[] = { "PIPE_LOGICOP_CLEAR", "PIPE_LOGICOP_NOR", "PIPE_LOGICOP_AND_INVERTED", @@ -197,7 +197,7 @@ util_dump_logicop_names[] = { }; static const char * -util_dump_logicop_short_names[] = { +util_logicop_short_names[] = { "clear", "nor", "and_inverted", @@ -216,11 +216,11 @@ util_dump_logicop_short_names[] = { "set" }; -DEFINE_UTIL_DUMP_CONTINUOUS(logicop) +DEFINE_UTIL_STR_CONTINUOUS(logicop) static const char * -util_dump_func_names[] = { +util_func_names[] = { "PIPE_FUNC_NEVER", "PIPE_FUNC_LESS", "PIPE_FUNC_EQUAL", @@ -232,7 +232,7 @@ util_dump_func_names[] = { }; static const char * -util_dump_func_short_names[] = { +util_func_short_names[] = { "never", "less", "equal", @@ -243,11 +243,11 @@ util_dump_func_short_names[] = { "always" }; -DEFINE_UTIL_DUMP_CONTINUOUS(func) +DEFINE_UTIL_STR_CONTINUOUS(func) static const char * -util_dump_stencil_op_names[] = { +util_stencil_op_names[] = { "PIPE_STENCIL_OP_KEEP", "PIPE_STENCIL_OP_ZERO", "PIPE_STENCIL_OP_REPLACE", @@ -259,7 +259,7 @@ util_dump_stencil_op_names[] = { }; static const char * -util_dump_stencil_op_short_names[] = { +util_stencil_op_short_names[] = { "keep", "zero", "replace", @@ -270,11 +270,11 @@ util_dump_stencil_op_short_names[] = { "invert" }; -DEFINE_UTIL_DUMP_CONTINUOUS(stencil_op) +DEFINE_UTIL_STR_CONTINUOUS(stencil_op) static const char * -util_dump_tex_target_names[] = { +util_tex_target_names[] = { "PIPE_BUFFER", "PIPE_TEXTURE_1D", "PIPE_TEXTURE_2D", @@ -287,7 +287,7 @@ util_dump_tex_target_names[] = { }; static const char * -util_dump_tex_target_short_names[] = { +util_tex_target_short_names[] = { "buffer", "1d", "2d", @@ -299,11 +299,11 @@ util_dump_tex_target_short_names[] = { "cube_array", }; -DEFINE_UTIL_DUMP_CONTINUOUS_COUNT(tex_target, PIPE_MAX_TEXTURE_TYPES) +DEFINE_UTIL_STR_CONTINUOUS_COUNT(tex_target, PIPE_MAX_TEXTURE_TYPES) static const char * -util_dump_tex_wrap_names[] = { +util_tex_wrap_names[] = { "PIPE_TEX_WRAP_REPEAT", "PIPE_TEX_WRAP_CLAMP", "PIPE_TEX_WRAP_CLAMP_TO_EDGE", @@ -315,7 +315,7 @@ util_dump_tex_wrap_names[] = { }; static const char * -util_dump_tex_wrap_short_names[] = { +util_tex_wrap_short_names[] = { "repeat", "clamp", "clamp_to_edge", @@ -326,45 +326,46 @@ util_dump_tex_wrap_short_names[] = { "mirror_clamp_to_border" }; -DEFINE_UTIL_DUMP_CONTINUOUS(tex_wrap) +DEFINE_UTIL_STR_CONTINUOUS(tex_wrap) static const char * -util_dump_tex_mipfilter_names[] = { +util_tex_mipfilter_names[] = { "PIPE_TEX_MIPFILTER_NEAREST", "PIPE_TEX_MIPFILTER_LINEAR", "PIPE_TEX_MIPFILTER_NONE" }; static const char * -util_dump_tex_mipfilter_short_names[] = { +util_tex_mipfilter_short_names[] = { "nearest", "linear", "none" }; -DEFINE_UTIL_DUMP_CONTINUOUS(tex_mipfilter) +DEFINE_UTIL_STR_CONTINUOUS(tex_mipfilter) static const char * -util_dump_tex_filter_names[] = { +util_tex_filter_names[] = { "PIPE_TEX_FILTER_NEAREST", "PIPE_TEX_FILTER_LINEAR" }; static const char * -util_dump_tex_filter_short_names[] = { +util_tex_filter_short_names[] = { "nearest", "linear" }; -DEFINE_UTIL_DUMP_CONTINUOUS(tex_filter) +DEFINE_UTIL_STR_CONTINUOUS(tex_filter) static const char * -util_dump_query_type_names[] = { +util_query_type_names[] = { "PIPE_QUERY_OCCLUSION_COUNTER", "PIPE_QUERY_OCCLUSION_PREDICATE", + "PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE", "PIPE_QUERY_TIMESTAMP", "PIPE_QUERY_TIMESTAMP_DISJOINT", "PIPE_QUERY_TIME_ELAPSED", @@ -372,12 +373,13 @@ util_dump_query_type_names[] = { "PIPE_QUERY_PRIMITIVES_EMITTED", "PIPE_QUERY_SO_STATISTICS", "PIPE_QUERY_SO_OVERFLOW_PREDICATE", + "PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE", "PIPE_QUERY_GPU_FINISHED", "PIPE_QUERY_PIPELINE_STATISTICS", }; static const char * -util_dump_query_type_short_names[] = { +util_query_type_short_names[] = { "occlusion_counter", "occlusion_predicate", "timestamp", @@ -391,11 +393,30 @@ util_dump_query_type_short_names[] = { "pipeline_statistics", }; -DEFINE_UTIL_DUMP_CONTINUOUS(query_type) +DEFINE_UTIL_STR_CONTINUOUS(query_type) static const char * -util_dump_prim_mode_names[] = { +util_query_value_type_names[] = { + "PIPE_QUERY_TYPE_I32", + "PIPE_QUERY_TYPE_U32", + "PIPE_QUERY_TYPE_I64", + "PIPE_QUERY_TYPE_U64", +}; + +static const char * +util_query_value_type_short_names[] = { + "i32", + "u32", + "i64", + "u64", +}; + +DEFINE_UTIL_STR_CONTINUOUS(query_value_type) + + +static const char * +util_prim_mode_names[] = { "PIPE_PRIM_POINTS", "PIPE_PRIM_LINES", "PIPE_PRIM_LINE_LOOP", @@ -414,7 +435,7 @@ util_dump_prim_mode_names[] = { }; static const char * -util_dump_prim_mode_short_names[] = { +util_prim_mode_short_names[] = { "points", "lines", "line_loop", @@ -432,4 +453,20 @@ util_dump_prim_mode_short_names[] = { "patches", }; -DEFINE_UTIL_DUMP_CONTINUOUS(prim_mode) +DEFINE_UTIL_STR_CONTINUOUS(prim_mode) + +void +util_dump_query_type(FILE *stream, unsigned value) +{ + if (value >= PIPE_QUERY_DRIVER_SPECIFIC) + fprintf(stream, "PIPE_QUERY_DRIVER_SPECIFIC + %i", + value - PIPE_QUERY_DRIVER_SPECIFIC); + else + fprintf(stream, "%s", util_str_query_type(value, false)); +} + +void +util_dump_query_value_type(FILE *stream, unsigned value) +{ + fprintf(stream, "%s", util_str_query_value_type(value, false)); +} diff --git a/lib/mesa/src/gallium/auxiliary/util/u_format_s3tc.c b/lib/mesa/src/gallium/auxiliary/util/u_format_s3tc.c index 8c4f2150b..3f755e536 100644 --- a/lib/mesa/src/gallium/auxiliary/util/u_format_s3tc.c +++ b/lib/mesa/src/gallium/auxiliary/util/u_format_s3tc.c @@ -28,136 +28,15 @@ #include "u_format.h" #include "u_format_s3tc.h" #include "util/format_srgb.h" +#include "../../../mesa/main/texcompress_s3tc_tmp.h" -#if defined(_WIN32) || defined(WIN32) -#define DXTN_LIBNAME "dxtn.dll" -#elif defined(__CYGWIN__) -#define DXTN_LIBNAME "cygtxc_dxtn.dll" -#elif defined(__APPLE__) -#define DXTN_LIBNAME "libtxc_dxtn.dylib" -#else -#define DXTN_LIBNAME "libtxc_dxtn.so" -#endif +util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgb_dxt1; +util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt1; +util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt3; +util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt5; - -static void -util_format_dxt1_rgb_fetch_stub(int src_stride, - const uint8_t *src, - int col, int row, - uint8_t *dst) -{ - assert(0); -} - - -static void -util_format_dxt1_rgba_fetch_stub(int src_stride, - const uint8_t *src, - int col, int row, - uint8_t *dst ) -{ - assert(0); -} - - -static void -util_format_dxt3_rgba_fetch_stub(int src_stride, - const uint8_t *src, - int col, int row, - uint8_t *dst ) -{ - assert(0); -} - - -static void -util_format_dxt5_rgba_fetch_stub(int src_stride, - const uint8_t *src, - int col, int row, - uint8_t *dst ) -{ - assert(0); -} - - -static void -util_format_dxtn_pack_stub(int src_comps, - int width, int height, - const uint8_t *src, - enum util_format_dxtn dst_format, - uint8_t *dst, - int dst_stride) -{ - assert(0); -} - - -boolean util_format_s3tc_enabled = FALSE; - -util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = util_format_dxt1_rgb_fetch_stub; -util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = util_format_dxt1_rgba_fetch_stub; -util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = util_format_dxt3_rgba_fetch_stub; -util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = util_format_dxt5_rgba_fetch_stub; - -util_format_dxtn_pack_t util_format_dxtn_pack = util_format_dxtn_pack_stub; - - -void -util_format_s3tc_init(void) -{ - static boolean first_time = TRUE; - struct util_dl_library *library = NULL; - util_dl_proc fetch_2d_texel_rgb_dxt1; - util_dl_proc fetch_2d_texel_rgba_dxt1; - util_dl_proc fetch_2d_texel_rgba_dxt3; - util_dl_proc fetch_2d_texel_rgba_dxt5; - util_dl_proc tx_compress_dxtn; - - if (!first_time) - return; - first_time = FALSE; - - if (util_format_s3tc_enabled) - return; - - library = util_dl_open(DXTN_LIBNAME); - if (!library) { - debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn " - "compression/decompression unavailable\n"); - return; - } - - fetch_2d_texel_rgb_dxt1 = - util_dl_get_proc_address(library, "fetch_2d_texel_rgb_dxt1"); - fetch_2d_texel_rgba_dxt1 = - util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt1"); - fetch_2d_texel_rgba_dxt3 = - util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt3"); - fetch_2d_texel_rgba_dxt5 = - util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt5"); - tx_compress_dxtn = - util_dl_get_proc_address(library, "tx_compress_dxtn"); - - if (!util_format_dxt1_rgb_fetch || - !util_format_dxt1_rgba_fetch || - !util_format_dxt3_rgba_fetch || - !util_format_dxt5_rgba_fetch || - !util_format_dxtn_pack) { - debug_printf("couldn't reference all symbols in " DXTN_LIBNAME - ", software DXTn compression/decompression " - "unavailable\n"); - util_dl_close(library); - return; - } - - util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgb_dxt1; - util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt1; - util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt3; - util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt5; - util_format_dxtn_pack = (util_format_dxtn_pack_t)tx_compress_dxtn; - util_format_s3tc_enabled = TRUE; -} +util_format_dxtn_pack_t util_format_dxtn_pack = (util_format_dxtn_pack_t)tx_compress_dxtn; /* diff --git a/lib/mesa/src/gallium/auxiliary/util/u_format_s3tc.h b/lib/mesa/src/gallium/auxiliary/util/u_format_s3tc.h index ae20010cd..6f188c67f 100644 --- a/lib/mesa/src/gallium/auxiliary/util/u_format_s3tc.h +++ b/lib/mesa/src/gallium/auxiliary/util/u_format_s3tc.h @@ -58,8 +58,6 @@ typedef void uint8_t *dst, int dst_stride); -extern boolean util_format_s3tc_enabled; - extern util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch; extern util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch; extern util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch; @@ -69,10 +67,6 @@ extern util_format_dxtn_pack_t util_format_dxtn_pack; void -util_format_s3tc_init(void); - - -void util_format_dxt1_rgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height); void diff --git a/lib/mesa/src/gallium/auxiliary/util/u_format_tests.c b/lib/mesa/src/gallium/auxiliary/util/u_format_tests.c index 3075ea0ab..9c9a5838d 100644 --- a/lib/mesa/src/gallium/auxiliary/util/u_format_tests.c +++ b/lib/mesa/src/gallium/auxiliary/util/u_format_tests.c @@ -140,6 +140,12 @@ util_format_test_cases[] = {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xc0000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_UNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_UNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x000003ff), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_UNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x000ffc00), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_UNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x3ff00000), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_R10G10B10X2_UNORM, PACKED_1x32(0x3fffffff), PACKED_1x32(0x3fffffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + {PIPE_FORMAT_B10G10R10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, {PIPE_FORMAT_B10G10R10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000003ff), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, {PIPE_FORMAT_B10G10R10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000ffc00), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, @@ -164,6 +170,19 @@ util_format_test_cases[] = {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + {PIPE_FORMAT_X1B5G5R5_UNORM, PACKED_1x16(0xfffe), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X1B5G5R5_UNORM, PACKED_1x16(0xfffe), PACKED_1x16(0x003e), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, + {PIPE_FORMAT_X1B5G5R5_UNORM, PACKED_1x16(0xfffe), PACKED_1x16(0x07c0), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, + {PIPE_FORMAT_X1B5G5R5_UNORM, PACKED_1x16(0xfffe), PACKED_1x16(0xf800), UNPACKED_1x1(1.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_X1B5G5R5_UNORM, PACKED_1x16(0xfffe), PACKED_1x16(0xfffe), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + + {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x003e), UNPACKED_1x1(0.0, 0.0, 1.0, 0.0)}, + {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x07c0), UNPACKED_1x1(0.0, 1.0, 0.0, 0.0)}, + {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf800), UNPACKED_1x1(1.0, 0.0, 0.0, 0.0)}, + {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0001), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, + {PIPE_FORMAT_A1B5G5R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), UNPACKED_1x1(1.0, 1.0, 1.0, 1.0)}, + {PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x0000), UNPACKED_1x1(0.0, 0.0, 0.0, 1.0)}, {PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x000f), UNPACKED_1x1(0.0, 0.0, 1.0, 1.0)}, {PIPE_FORMAT_B4G4R4X4_UNORM, PACKED_1x16(0x0fff), PACKED_1x16(0x00f0), UNPACKED_1x1(0.0, 1.0, 0.0, 1.0)}, diff --git a/lib/mesa/src/gallium/auxiliary/util/u_idalloc.c b/lib/mesa/src/gallium/auxiliary/util/u_idalloc.c new file mode 100644 index 000000000..26104552e --- /dev/null +++ b/lib/mesa/src/gallium/auxiliary/util/u_idalloc.c @@ -0,0 +1,96 @@ +/************************************************************************** + * + * Copyright 2017 Valve Corporation + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * A simple allocator that allocates and release "numbers". + * + * @author Samuel Pitoiset <samuel.pitoiset@gmail.com> + */ + +#include "util/u_idalloc.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +void +util_idalloc_init(struct util_idalloc *buf) +{ + memset(buf, 0, sizeof(*buf)); +} + +void +util_idalloc_fini(struct util_idalloc *buf) +{ + if (buf->data) + free(buf->data); +} + +void +util_idalloc_resize(struct util_idalloc *buf, unsigned new_num_elements) +{ + new_num_elements = align(new_num_elements, 32); + + if (new_num_elements > buf->num_elements) { + unsigned i; + + buf->data = realloc(buf->data, + (new_num_elements / 32) * sizeof(*buf->data)); + + for (i = buf->num_elements / 32; i < new_num_elements / 32; i++) + buf->data[i] = 0; + buf->num_elements = new_num_elements; + } +} + +unsigned +util_idalloc_alloc(struct util_idalloc *buf) +{ + unsigned num_elements = buf->num_elements; + + for (unsigned i = 0; i < num_elements / 32; i++) { + if (buf->data[i] == 0xffffffff) + continue; + + unsigned bit = ffs(~buf->data[i]) - 1; + buf->data[i] |= 1u << bit; + return i * 32 + bit; + } + + /* No slots available, resize and return the first free. */ + util_idalloc_resize(buf, num_elements * 2); + + buf->data[num_elements / 32] |= 1 << (num_elements % 32); + + return num_elements; +} + +void +util_idalloc_free(struct util_idalloc *buf, unsigned id) +{ + assert(id < buf->num_elements); + buf->data[id / 32] &= ~(1 << (id % 32)); +} diff --git a/lib/mesa/src/gallium/auxiliary/util/u_idalloc.h b/lib/mesa/src/gallium/auxiliary/util/u_idalloc.h new file mode 100644 index 000000000..82469e94d --- /dev/null +++ b/lib/mesa/src/gallium/auxiliary/util/u_idalloc.h @@ -0,0 +1,62 @@ +/************************************************************************** + * + * Copyright 2017 Valve Corporation + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef U_IDALLOC_H +#define U_IDALLOC_H + +#include <inttypes.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct util_idalloc +{ + uint32_t *data; + unsigned num_elements; +}; + +void +util_idalloc_init(struct util_idalloc *buf); + +void +util_idalloc_fini(struct util_idalloc *buf); + +void +util_idalloc_resize(struct util_idalloc *buf, unsigned new_num_elements); + +unsigned +util_idalloc_alloc(struct util_idalloc *buf); + +void +util_idalloc_free(struct util_idalloc *buf, unsigned id); + +#ifdef __cplusplus +} +#endif + +#endif /* U_IDALLOC_H */ diff --git a/lib/mesa/src/gallium/auxiliary/util/u_log.c b/lib/mesa/src/gallium/auxiliary/util/u_log.c new file mode 100644 index 000000000..dacbe0505 --- /dev/null +++ b/lib/mesa/src/gallium/auxiliary/util/u_log.c @@ -0,0 +1,235 @@ +/* + * Copyright 2017 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "u_log.h" + +#include "u_memory.h" +#include "util/u_string.h" + +struct page_entry { + const struct u_log_chunk_type *type; + void *data; +}; + +struct u_log_page { + struct page_entry *entries; + unsigned num_entries; + unsigned max_entries; +}; + +struct u_log_auto_logger { + u_auto_log_fn *callback; + void *data; +}; + +/** + * Initialize the given logging context. + */ +void +u_log_context_init(struct u_log_context *ctx) +{ + memset(ctx, 0, sizeof(*ctx)); +} + +/** + * Free all resources associated with the given logging context. + * + * Pages taken from the context via \ref u_log_new_page must be destroyed + * separately. + */ +void +u_log_context_destroy(struct u_log_context *ctx) +{ + u_log_page_destroy(ctx->cur); + FREE(ctx->auto_loggers); + memset(ctx, 0, sizeof(*ctx)); +} + +/** + * Add an auto logger. + * + * Auto loggers are called each time a chunk is added to the log. + */ +void +u_log_add_auto_logger(struct u_log_context *ctx, u_auto_log_fn *callback, + void *data) +{ + struct u_log_auto_logger *new_auto_loggers = + REALLOC(ctx->auto_loggers, + sizeof(*new_auto_loggers) * ctx->num_auto_loggers, + sizeof(*new_auto_loggers) * (ctx->num_auto_loggers + 1)); + if (!new_auto_loggers) { + fprintf(stderr, "Gallium u_log: out of memory\n"); + return; + } + + unsigned idx = ctx->num_auto_loggers++; + ctx->auto_loggers = new_auto_loggers; + ctx->auto_loggers[idx].callback = callback; + ctx->auto_loggers[idx].data = data; +} + +/** + * Make sure that auto loggers have run. + */ +void +u_log_flush(struct u_log_context *ctx) +{ + if (!ctx->num_auto_loggers) + return; + + struct u_log_auto_logger *auto_loggers = ctx->auto_loggers; + unsigned num_auto_loggers = ctx->num_auto_loggers; + + /* Prevent recursion. */ + ctx->num_auto_loggers = 0; + ctx->auto_loggers = NULL; + + for (unsigned i = 0; i < num_auto_loggers; ++i) + auto_loggers[i].callback(auto_loggers[i].data, ctx); + + assert(!ctx->num_auto_loggers); + ctx->num_auto_loggers = num_auto_loggers; + ctx->auto_loggers = auto_loggers; +} + +static void str_print(void *data, FILE *stream) +{ + fputs((char *)data, stream); +} + +static const struct u_log_chunk_type str_chunk_type = { + .destroy = free, + .print = str_print, +}; + +void +u_log_printf(struct u_log_context *ctx, const char *fmt, ...) +{ + va_list va; + char *str = NULL; + + va_start(va, fmt); + int ret = util_vasprintf(&str, fmt, va); + va_end(va); + + if (ret >= 0) { + u_log_chunk(ctx, &str_chunk_type, str); + } else { + fprintf(stderr, "Gallium u_log_printf: out of memory\n"); + } +} + +/** + * Add a custom chunk to the log. + * + * type->destroy will be called as soon as \p data is no longer needed. + */ +void +u_log_chunk(struct u_log_context *ctx, const struct u_log_chunk_type *type, + void *data) +{ + struct u_log_page *page = ctx->cur; + + u_log_flush(ctx); + + if (!page) { + ctx->cur = CALLOC_STRUCT(u_log_page); + page = ctx->cur; + if (!page) + goto out_of_memory; + } + + if (page->num_entries >= page->max_entries) { + unsigned new_max_entries = MAX2(16, page->num_entries * 2); + struct page_entry *new_entries = REALLOC(page->entries, + page->max_entries * sizeof(*page->entries), + new_max_entries * sizeof(*page->entries)); + if (!new_entries) + goto out_of_memory; + + page->entries = new_entries; + page->max_entries = new_max_entries; + } + + page->entries[page->num_entries].type = type; + page->entries[page->num_entries].data = data; + page->num_entries++; + return; + +out_of_memory: + fprintf(stderr, "Gallium: u_log: out of memory\n"); +} + +/** + * Convenience helper that starts a new page and prints the previous one. + */ +void +u_log_new_page_print(struct u_log_context *ctx, FILE *stream) +{ + if (ctx->cur) { + u_log_page_print(ctx->cur, stream); + u_log_page_destroy(ctx->cur); + ctx->cur = NULL; + } +} + +/** + * Return the current page from the logging context and start a new one. + * + * The caller is responsible for destroying the returned page. + */ +struct u_log_page * +u_log_new_page(struct u_log_context *ctx) +{ + struct u_log_page *page = ctx->cur; + ctx->cur = NULL; + return page; +} + +/** + * Free all data associated with \p page. + */ +void +u_log_page_destroy(struct u_log_page *page) +{ + if (!page) + return; + + for (unsigned i = 0; i < page->num_entries; ++i) { + if (page->entries[i].type->destroy) + page->entries[i].type->destroy(page->entries[i].data); + } + FREE(page->entries); + FREE(page); +} + +/** + * Print the given page to \p stream. + */ +void +u_log_page_print(struct u_log_page *page, FILE *stream) +{ + for (unsigned i = 0; i < page->num_entries; ++i) + page->entries[i].type->print(page->entries[i].data, stream); +} diff --git a/lib/mesa/src/gallium/auxiliary/util/u_log.h b/lib/mesa/src/gallium/auxiliary/util/u_log.h new file mode 100644 index 000000000..09c47caee --- /dev/null +++ b/lib/mesa/src/gallium/auxiliary/util/u_log.h @@ -0,0 +1,100 @@ +/* + * Copyright 2017 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * @file u_log.h + * @brief Context logging facilities + * + * Provides a means of logging context events (draw calls, command streams, ...) + * into files. + * + * Log entries start their life cycle as "chunks". Chunks can be plain text + * written by \ref u_log_printf or custom internal representations added by + * \ref u_log_chunk that are only converted to text on-demand (e.g. for higher + * performance pipelined hang-debugging). + * + * Chunks are accumulated into "pages". The manager of the log can periodically + * take out the current page using \ref u_log_new_page and dump it to a file. + * + * Furthermore, "auto loggers" can be added to a context, which are callbacks + * that are given the opportunity to add their own logging each time a chunk is + * added. Drivers can use this to lazily log chunks of their command stream. + * Lazy loggers don't need to be re-entrant. + */ + +#ifndef U_LOG_H +#define U_LOG_H + +#include <stdio.h> + +#include "u_debug.h" + +struct u_log_page; +struct u_log_auto_logger; + +struct u_log_chunk_type { + void (*destroy)(void *data); + void (*print)(void *data, FILE *stream); +}; + +struct u_log_context { + struct u_log_page *cur; + struct u_log_auto_logger *auto_loggers; + unsigned num_auto_loggers; +}; + +typedef void (u_auto_log_fn)(void *data, struct u_log_context *ctx); + +void +u_log_context_init(struct u_log_context *ctx); + +void +u_log_context_destroy(struct u_log_context *ctx); + +void +u_log_add_auto_logger(struct u_log_context *ctx, u_auto_log_fn *callback, + void *data); + +void +u_log_flush(struct u_log_context *ctx); + +void +u_log_printf(struct u_log_context *ctx, const char *fmt, ...) _util_printf_format(2,3); + +void +u_log_chunk(struct u_log_context *ctx, const struct u_log_chunk_type *type, + void *data); + +void +u_log_new_page_print(struct u_log_context *ctx, FILE *stream); + +struct u_log_page * +u_log_new_page(struct u_log_context *ctx); + +void +u_log_page_destroy(struct u_log_page *page); + +void +u_log_page_print(struct u_log_page *page, FILE *stream); + +#endif /* U_LOG_H */ diff --git a/lib/mesa/src/gallium/auxiliary/util/u_mm.c b/lib/mesa/src/gallium/auxiliary/util/u_mm.c index bd4c4e1b1..7a45e2919 100644 --- a/lib/mesa/src/gallium/auxiliary/util/u_mm.c +++ b/lib/mesa/src/gallium/auxiliary/util/u_mm.c @@ -183,7 +183,10 @@ u_mmAllocMem(struct mem_block *heap, int size, int align2, int startSearch) assert(size >= 0); assert(align2 >= 0); - assert(align2 <= 12); /* sanity check, 2^12 (4KB) enough? */ + /* Make sure that a byte alignment isn't getting passed for our + * power-of-two alignment arg. + */ + assert(align2 < 32); if (!heap || align2 < 0 || size <= 0) return NULL; |