Home | History | Annotate | Download | only in util
      1 /**************************************************************************
      2  *
      3  * Copyright 2009 VMware, Inc.
      4  * All Rights Reserved.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the
      8  * "Software"), to deal in the Software without restriction, including
      9  * without limitation the rights to use, copy, modify, merge, publish,
     10  * distribute, sub license, and/or sell copies of the Software, and to
     11  * permit persons to whom the Software is furnished to do so, subject to
     12  * the following conditions:
     13  *
     14  * The above copyright notice and this permission notice (including the
     15  * next paragraph) shall be included in all copies or substantial portions
     16  * of the Software.
     17  *
     18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
     21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
     22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     25  *
     26  **************************************************************************/
     27 
     28 
     29 #include "util/u_memory.h"
     30 #include "util/u_debug.h"
     31 #include "util/u_dump.h"
     32 
     33 
     34 #if 0
     35 static const char *
     36 util_dump_strip_prefix(const char *name,
     37                         const char *prefix)
     38 {
     39    const char *stripped;
     40    assert(name);
     41    assert(prefix);
     42    stripped = name;
     43    while(*prefix) {
     44       if(*stripped != *prefix)
     45 	 return name;
     46 
     47       ++stripped;
     48       ++prefix;
     49    }
     50    return stripped;
     51 }
     52 #endif
     53 
     54 static const char *
     55 util_dump_enum_continuous(unsigned value,
     56                            unsigned num_names,
     57                            const char **names)
     58 {
     59    if (value >= num_names)
     60       return UTIL_DUMP_INVALID_NAME;
     61    return names[value];
     62 }
     63 
     64 
     65 #define DEFINE_UTIL_DUMP_CONTINUOUS(_name) \
     66    const char * \
     67    util_dump_##_name(unsigned value, boolean shortened) \
     68    { \
     69       if(shortened) \
     70          return util_dump_enum_continuous(value, ARRAY_SIZE(util_dump_##_name##_short_names), util_dump_##_name##_short_names); \
     71       else \
     72          return util_dump_enum_continuous(value, ARRAY_SIZE(util_dump_##_name##_names), util_dump_##_name##_names); \
     73    }
     74 
     75 
     76 /**
     77  * Same as DEFINE_UTIL_DUMP_CONTINUOUS but with static assertions to detect
     78  * failures to update lists.
     79  */
     80 #define DEFINE_UTIL_DUMP_CONTINUOUS_COUNT(_name, _count) \
     81    const char * \
     82    util_dump_##_name(unsigned value, boolean shortened) \
     83    { \
     84       STATIC_ASSERT(ARRAY_SIZE(util_dump_##_name##_names) == _count); \
     85       STATIC_ASSERT(ARRAY_SIZE(util_dump_##_name##_short_names) == _count); \
     86       if(shortened) \
     87          return util_dump_enum_continuous(value, ARRAY_SIZE(util_dump_##_name##_short_names), util_dump_##_name##_short_names); \
     88       else \
     89          return util_dump_enum_continuous(value, ARRAY_SIZE(util_dump_##_name##_names), util_dump_##_name##_names); \
     90    }
     91 
     92 
     93 static const char *
     94 util_dump_blend_factor_names[] = {
     95    UTIL_DUMP_INVALID_NAME, /* 0x0 */
     96    "PIPE_BLENDFACTOR_ONE",
     97    "PIPE_BLENDFACTOR_SRC_COLOR",
     98    "PIPE_BLENDFACTOR_SRC_ALPHA",
     99    "PIPE_BLENDFACTOR_DST_ALPHA",
    100    "PIPE_BLENDFACTOR_DST_COLOR",
    101    "PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE",
    102    "PIPE_BLENDFACTOR_CONST_COLOR",
    103    "PIPE_BLENDFACTOR_CONST_ALPHA",
    104    "PIPE_BLENDFACTOR_SRC1_COLOR",
    105    "PIPE_BLENDFACTOR_SRC1_ALPHA",
    106    UTIL_DUMP_INVALID_NAME, /* 0x0b */
    107    UTIL_DUMP_INVALID_NAME, /* 0x0c */
    108    UTIL_DUMP_INVALID_NAME, /* 0x0d */
    109    UTIL_DUMP_INVALID_NAME, /* 0x0e */
    110    UTIL_DUMP_INVALID_NAME, /* 0x0f */
    111    UTIL_DUMP_INVALID_NAME, /* 0x10 */
    112    "PIPE_BLENDFACTOR_ZERO",
    113    "PIPE_BLENDFACTOR_INV_SRC_COLOR",
    114    "PIPE_BLENDFACTOR_INV_SRC_ALPHA",
    115    "PIPE_BLENDFACTOR_INV_DST_ALPHA",
    116    "PIPE_BLENDFACTOR_INV_DST_COLOR",
    117    UTIL_DUMP_INVALID_NAME, /* 0x16 */
    118    "PIPE_BLENDFACTOR_INV_CONST_COLOR",
    119    "PIPE_BLENDFACTOR_INV_CONST_ALPHA",
    120    "PIPE_BLENDFACTOR_INV_SRC1_COLOR",
    121    "PIPE_BLENDFACTOR_INV_SRC1_ALPHA"
    122 };
    123 
    124 static const char *
    125 util_dump_blend_factor_short_names[] = {
    126    UTIL_DUMP_INVALID_NAME, /* 0x0 */
    127    "one",
    128    "src_color",
    129    "src_alpha",
    130    "dst_alpha",
    131    "dst_color",
    132    "src_alpha_saturate",
    133    "const_color",
    134    "const_alpha",
    135    "src1_color",
    136    "src1_alpha",
    137    UTIL_DUMP_INVALID_NAME, /* 0x0b */
    138    UTIL_DUMP_INVALID_NAME, /* 0x0c */
    139    UTIL_DUMP_INVALID_NAME, /* 0x0d */
    140    UTIL_DUMP_INVALID_NAME, /* 0x0e */
    141    UTIL_DUMP_INVALID_NAME, /* 0x0f */
    142    UTIL_DUMP_INVALID_NAME, /* 0x10 */
    143    "zero",
    144    "inv_src_color",
    145    "inv_src_alpha",
    146    "inv_dst_alpha",
    147    "inv_dst_color",
    148    UTIL_DUMP_INVALID_NAME, /* 0x16 */
    149    "inv_const_color",
    150    "inv_const_alpha",
    151    "inv_src1_color",
    152    "inv_src1_alpha"
    153 };
    154 
    155 DEFINE_UTIL_DUMP_CONTINUOUS(blend_factor)
    156 
    157 
    158 static const char *
    159 util_dump_blend_func_names[] = {
    160    "PIPE_BLEND_ADD",
    161    "PIPE_BLEND_SUBTRACT",
    162    "PIPE_BLEND_REVERSE_SUBTRACT",
    163    "PIPE_BLEND_MIN",
    164    "PIPE_BLEND_MAX"
    165 };
    166 
    167 static const char *
    168 util_dump_blend_func_short_names[] = {
    169    "add",
    170    "sub",
    171    "rev_sub",
    172    "min",
    173    "max"
    174 };
    175 
    176 DEFINE_UTIL_DUMP_CONTINUOUS(blend_func)
    177 
    178 
    179 static const char *
    180 util_dump_logicop_names[] = {
    181    "PIPE_LOGICOP_CLEAR",
    182    "PIPE_LOGICOP_NOR",
    183    "PIPE_LOGICOP_AND_INVERTED",
    184    "PIPE_LOGICOP_COPY_INVERTED",
    185    "PIPE_LOGICOP_AND_REVERSE",
    186    "PIPE_LOGICOP_INVERT",
    187    "PIPE_LOGICOP_XOR",
    188    "PIPE_LOGICOP_NAND",
    189    "PIPE_LOGICOP_AND",
    190    "PIPE_LOGICOP_EQUIV",
    191    "PIPE_LOGICOP_NOOP",
    192    "PIPE_LOGICOP_OR_INVERTED",
    193    "PIPE_LOGICOP_COPY",
    194    "PIPE_LOGICOP_OR_REVERSE",
    195    "PIPE_LOGICOP_OR",
    196    "PIPE_LOGICOP_SET"
    197 };
    198 
    199 static const char *
    200 util_dump_logicop_short_names[] = {
    201    "clear",
    202    "nor",
    203    "and_inverted",
    204    "copy_inverted",
    205    "and_reverse",
    206    "invert",
    207    "xor",
    208    "nand",
    209    "and",
    210    "equiv",
    211    "noop",
    212    "or_inverted",
    213    "copy",
    214    "or_reverse",
    215    "or",
    216    "set"
    217 };
    218 
    219 DEFINE_UTIL_DUMP_CONTINUOUS(logicop)
    220 
    221 
    222 static const char *
    223 util_dump_func_names[] = {
    224    "PIPE_FUNC_NEVER",
    225    "PIPE_FUNC_LESS",
    226    "PIPE_FUNC_EQUAL",
    227    "PIPE_FUNC_LEQUAL",
    228    "PIPE_FUNC_GREATER",
    229    "PIPE_FUNC_NOTEQUAL",
    230    "PIPE_FUNC_GEQUAL",
    231    "PIPE_FUNC_ALWAYS"
    232 };
    233 
    234 static const char *
    235 util_dump_func_short_names[] = {
    236    "never",
    237    "less",
    238    "equal",
    239    "less_equal",
    240    "greater",
    241    "not_equal",
    242    "greater_equal",
    243    "always"
    244 };
    245 
    246 DEFINE_UTIL_DUMP_CONTINUOUS(func)
    247 
    248 
    249 static const char *
    250 util_dump_stencil_op_names[] = {
    251    "PIPE_STENCIL_OP_KEEP",
    252    "PIPE_STENCIL_OP_ZERO",
    253    "PIPE_STENCIL_OP_REPLACE",
    254    "PIPE_STENCIL_OP_INCR",
    255    "PIPE_STENCIL_OP_DECR",
    256    "PIPE_STENCIL_OP_INCR_WRAP",
    257    "PIPE_STENCIL_OP_DECR_WRAP",
    258    "PIPE_STENCIL_OP_INVERT"
    259 };
    260 
    261 static const char *
    262 util_dump_stencil_op_short_names[] = {
    263    "keep",
    264    "zero",
    265    "replace",
    266    "incr",
    267    "decr",
    268    "incr_wrap",
    269    "decr_wrap",
    270    "invert"
    271 };
    272 
    273 DEFINE_UTIL_DUMP_CONTINUOUS(stencil_op)
    274 
    275 
    276 static const char *
    277 util_dump_tex_target_names[] = {
    278    "PIPE_BUFFER",
    279    "PIPE_TEXTURE_1D",
    280    "PIPE_TEXTURE_2D",
    281    "PIPE_TEXTURE_3D",
    282    "PIPE_TEXTURE_CUBE",
    283    "PIPE_TEXTURE_RECT",
    284    "PIPE_TEXTURE_1D_ARRAY",
    285    "PIPE_TEXTURE_2D_ARRAY",
    286    "PIPE_TEXTURE_CUBE_ARRAY",
    287 };
    288 
    289 static const char *
    290 util_dump_tex_target_short_names[] = {
    291    "buffer",
    292    "1d",
    293    "2d",
    294    "3d",
    295    "cube",
    296    "rect",
    297    "1d_array",
    298    "2d_array",
    299    "cube_array",
    300 };
    301 
    302 DEFINE_UTIL_DUMP_CONTINUOUS_COUNT(tex_target, PIPE_MAX_TEXTURE_TYPES)
    303 
    304 
    305 static const char *
    306 util_dump_tex_wrap_names[] = {
    307    "PIPE_TEX_WRAP_REPEAT",
    308    "PIPE_TEX_WRAP_CLAMP",
    309    "PIPE_TEX_WRAP_CLAMP_TO_EDGE",
    310    "PIPE_TEX_WRAP_CLAMP_TO_BORDER",
    311    "PIPE_TEX_WRAP_MIRROR_REPEAT",
    312    "PIPE_TEX_WRAP_MIRROR_CLAMP",
    313    "PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE",
    314    "PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER"
    315 };
    316 
    317 static const char *
    318 util_dump_tex_wrap_short_names[] = {
    319    "repeat",
    320    "clamp",
    321    "clamp_to_edge",
    322    "clamp_to_border",
    323    "mirror_repeat",
    324    "mirror_clamp",
    325    "mirror_clamp_to_edge",
    326    "mirror_clamp_to_border"
    327 };
    328 
    329 DEFINE_UTIL_DUMP_CONTINUOUS(tex_wrap)
    330 
    331 
    332 static const char *
    333 util_dump_tex_mipfilter_names[] = {
    334    "PIPE_TEX_MIPFILTER_NEAREST",
    335    "PIPE_TEX_MIPFILTER_LINEAR",
    336    "PIPE_TEX_MIPFILTER_NONE"
    337 };
    338 
    339 static const char *
    340 util_dump_tex_mipfilter_short_names[] = {
    341    "nearest",
    342    "linear",
    343    "none"
    344 };
    345 
    346 DEFINE_UTIL_DUMP_CONTINUOUS(tex_mipfilter)
    347 
    348 
    349 static const char *
    350 util_dump_tex_filter_names[] = {
    351    "PIPE_TEX_FILTER_NEAREST",
    352    "PIPE_TEX_FILTER_LINEAR"
    353 };
    354 
    355 static const char *
    356 util_dump_tex_filter_short_names[] = {
    357    "nearest",
    358    "linear"
    359 };
    360 
    361 DEFINE_UTIL_DUMP_CONTINUOUS(tex_filter)
    362 
    363 
    364 static const char *
    365 util_dump_query_type_names[] = {
    366    "PIPE_QUERY_OCCLUSION_COUNTER",
    367    "PIPE_QUERY_OCCLUSION_PREDICATE",
    368    "PIPE_QUERY_TIMESTAMP",
    369    "PIPE_QUERY_TIMESTAMP_DISJOINT",
    370    "PIPE_QUERY_TIME_ELAPSED",
    371    "PIPE_QUERY_PRIMITIVES_GENERATED",
    372    "PIPE_QUERY_PRIMITIVES_EMITTED",
    373    "PIPE_QUERY_SO_STATISTICS",
    374    "PIPE_QUERY_SO_OVERFLOW_PREDICATE",
    375    "PIPE_QUERY_GPU_FINISHED",
    376    "PIPE_QUERY_PIPELINE_STATISTICS",
    377 };
    378 
    379 static const char *
    380 util_dump_query_type_short_names[] = {
    381    "occlusion_counter",
    382    "occlusion_predicate",
    383    "timestamp",
    384    "timestamp_disjoint",
    385    "time_elapsed",
    386    "primitives_generated",
    387    "primitives_emitted",
    388    "so_statistics",
    389    "so_overflow_predicate",
    390    "gpu_finished",
    391    "pipeline_statistics",
    392 };
    393 
    394 DEFINE_UTIL_DUMP_CONTINUOUS(query_type)
    395 
    396 
    397 static const char *
    398 util_dump_prim_mode_names[] = {
    399    "PIPE_PRIM_POINTS",
    400    "PIPE_PRIM_LINES",
    401    "PIPE_PRIM_LINE_LOOP",
    402    "PIPE_PRIM_LINE_STRIP",
    403    "PIPE_PRIM_TRIANGLES",
    404    "PIPE_PRIM_TRIANGLE_STRIP",
    405    "PIPE_PRIM_TRIANGLE_FAN",
    406    "PIPE_PRIM_QUADS",
    407    "PIPE_PRIM_QUAD_STRIP",
    408    "PIPE_PRIM_POLYGON",
    409    "PIPE_PRIM_LINES_ADJACENCY",
    410    "PIPE_PRIM_LINE_STRIP_ADJACENCY",
    411    "PIPE_PRIM_TRIANGLES_ADJACENCY",
    412    "PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY",
    413    "PIPE_PRIM_PATCHES",
    414 };
    415 
    416 static const char *
    417 util_dump_prim_mode_short_names[] = {
    418    "points",
    419    "lines",
    420    "line_loop",
    421    "line_strip",
    422    "triangles",
    423    "triangle_strip",
    424    "triangle_fan",
    425    "quads",
    426    "quad_strip",
    427    "polygon",
    428    "lines_adjacency",
    429    "line_strip_adjacency",
    430    "triangles_adjacency",
    431    "triangle_strip_adjacency",
    432    "patches",
    433 };
    434 
    435 DEFINE_UTIL_DUMP_CONTINUOUS(prim_mode)
    436