Path: blob/21.2-virgl/src/gallium/auxiliary/tgsi/tgsi_info.c
4565 views
/**************************************************************************1*2* Copyright 2008 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#include "util/u_debug.h"28#include "util/u_memory.h"29#include "tgsi_info.h"3031#define NONE TGSI_OUTPUT_NONE32#define COMP TGSI_OUTPUT_COMPONENTWISE33#define REPL TGSI_OUTPUT_REPLICATE34#define CHAN TGSI_OUTPUT_CHAN_DEPENDENT35#define OTHR TGSI_OUTPUT_OTHER3637#define OPCODE(_num_dst, _num_src, _output_mode, name, ...) \38{ .opcode = TGSI_OPCODE_ ## name, \39.output_mode = _output_mode, .num_dst = _num_dst, .num_src = _num_src, \40##__VA_ARGS__ },4142#define OPCODE_GAP(opc) { .opcode = opc },4344static const struct tgsi_opcode_info opcode_info[TGSI_OPCODE_LAST] =45{46#include "tgsi_info_opcodes.h"47};4849#undef OPCODE50#undef OPCODE_GAP5152const struct tgsi_opcode_info *53tgsi_get_opcode_info(enum tgsi_opcode opcode)54{55static boolean firsttime = 1;5657ASSERT_BITFIELD_SIZE(struct tgsi_opcode_info, opcode, TGSI_OPCODE_LAST - 1);58ASSERT_BITFIELD_SIZE(struct tgsi_opcode_info, output_mode,59TGSI_OUTPUT_OTHER);6061if (firsttime) {62unsigned i;63firsttime = 0;64for (i = 0; i < ARRAY_SIZE(opcode_info); i++)65assert(opcode_info[i].opcode == i);66}6768if (opcode < TGSI_OPCODE_LAST)69return &opcode_info[opcode];7071assert( 0 );72return NULL;73}7475#define OPCODE(_num_dst, _num_src, _output_mode, name, ...) #name,76#define OPCODE_GAP(opc) "UNK" #opc,7778static const char * const opcode_names[TGSI_OPCODE_LAST] =79{80#include "tgsi_info_opcodes.h"81};8283#undef OPCODE84#undef OPCODE_GAP8586const char *87tgsi_get_opcode_name(enum tgsi_opcode opcode)88{89if (opcode >= ARRAY_SIZE(opcode_names))90return "UNK_OOB";91return opcode_names[opcode];92}939495const char *96tgsi_get_processor_name(enum pipe_shader_type processor)97{98switch (processor) {99case PIPE_SHADER_VERTEX:100return "vertex shader";101case PIPE_SHADER_FRAGMENT:102return "fragment shader";103case PIPE_SHADER_GEOMETRY:104return "geometry shader";105case PIPE_SHADER_TESS_CTRL:106return "tessellation control shader";107case PIPE_SHADER_TESS_EVAL:108return "tessellation evaluation shader";109case PIPE_SHADER_COMPUTE:110return "compute shader";111default:112return "unknown shader type!";113}114}115116/**117* Infer the type (of the dst) of the opcode.118*119* MOV and UCMP is special so return VOID120*/121static inline enum tgsi_opcode_type122tgsi_opcode_infer_type(enum tgsi_opcode opcode)123{124switch (opcode) {125case TGSI_OPCODE_MOV:126case TGSI_OPCODE_UCMP:127return TGSI_TYPE_UNTYPED;128case TGSI_OPCODE_NOT:129case TGSI_OPCODE_SHL:130case TGSI_OPCODE_AND:131case TGSI_OPCODE_OR:132case TGSI_OPCODE_XOR:133case TGSI_OPCODE_TXQ:134case TGSI_OPCODE_TXQS:135case TGSI_OPCODE_F2U:136case TGSI_OPCODE_UDIV:137case TGSI_OPCODE_UMAD:138case TGSI_OPCODE_UMAX:139case TGSI_OPCODE_UMIN:140case TGSI_OPCODE_UMOD:141case TGSI_OPCODE_UMUL:142case TGSI_OPCODE_USEQ:143case TGSI_OPCODE_USGE:144case TGSI_OPCODE_USHR:145case TGSI_OPCODE_USLT:146case TGSI_OPCODE_USNE:147case TGSI_OPCODE_SVIEWINFO:148case TGSI_OPCODE_UMUL_HI:149case TGSI_OPCODE_UBFE:150case TGSI_OPCODE_BFI:151case TGSI_OPCODE_BREV:152case TGSI_OPCODE_IMG2HND:153case TGSI_OPCODE_SAMP2HND:154return TGSI_TYPE_UNSIGNED;155case TGSI_OPCODE_ARL:156case TGSI_OPCODE_ARR:157case TGSI_OPCODE_MOD:158case TGSI_OPCODE_F2I:159case TGSI_OPCODE_FSEQ:160case TGSI_OPCODE_FSGE:161case TGSI_OPCODE_FSLT:162case TGSI_OPCODE_FSNE:163case TGSI_OPCODE_IDIV:164case TGSI_OPCODE_IMAX:165case TGSI_OPCODE_IMIN:166case TGSI_OPCODE_INEG:167case TGSI_OPCODE_ISGE:168case TGSI_OPCODE_ISHR:169case TGSI_OPCODE_ISLT:170case TGSI_OPCODE_UADD:171case TGSI_OPCODE_UARL:172case TGSI_OPCODE_IABS:173case TGSI_OPCODE_ISSG:174case TGSI_OPCODE_IMUL_HI:175case TGSI_OPCODE_IBFE:176case TGSI_OPCODE_IMSB:177case TGSI_OPCODE_DSEQ:178case TGSI_OPCODE_DSGE:179case TGSI_OPCODE_DSLT:180case TGSI_OPCODE_DSNE:181case TGSI_OPCODE_U64SEQ:182case TGSI_OPCODE_U64SNE:183case TGSI_OPCODE_U64SLT:184case TGSI_OPCODE_U64SGE:185case TGSI_OPCODE_I64SLT:186case TGSI_OPCODE_I64SGE:187case TGSI_OPCODE_LSB:188case TGSI_OPCODE_POPC:189case TGSI_OPCODE_UMSB:190return TGSI_TYPE_SIGNED;191case TGSI_OPCODE_DADD:192case TGSI_OPCODE_DABS:193case TGSI_OPCODE_DFMA:194case TGSI_OPCODE_DNEG:195case TGSI_OPCODE_DMUL:196case TGSI_OPCODE_DMAX:197case TGSI_OPCODE_DDIV:198case TGSI_OPCODE_DMIN:199case TGSI_OPCODE_DRCP:200case TGSI_OPCODE_DSQRT:201case TGSI_OPCODE_DMAD:202case TGSI_OPCODE_DLDEXP:203case TGSI_OPCODE_DFRACEXP:204case TGSI_OPCODE_DFRAC:205case TGSI_OPCODE_DRSQ:206case TGSI_OPCODE_DTRUNC:207case TGSI_OPCODE_DCEIL:208case TGSI_OPCODE_DFLR:209case TGSI_OPCODE_DROUND:210case TGSI_OPCODE_DSSG:211case TGSI_OPCODE_F2D:212case TGSI_OPCODE_I2D:213case TGSI_OPCODE_U2D:214case TGSI_OPCODE_U642D:215case TGSI_OPCODE_I642D:216return TGSI_TYPE_DOUBLE;217case TGSI_OPCODE_U64MAX:218case TGSI_OPCODE_U64MIN:219case TGSI_OPCODE_U64ADD:220case TGSI_OPCODE_U64MUL:221case TGSI_OPCODE_U64DIV:222case TGSI_OPCODE_U64MOD:223case TGSI_OPCODE_U64SHL:224case TGSI_OPCODE_U64SHR:225case TGSI_OPCODE_F2U64:226case TGSI_OPCODE_D2U64:227return TGSI_TYPE_UNSIGNED64;228case TGSI_OPCODE_I64MAX:229case TGSI_OPCODE_I64MIN:230case TGSI_OPCODE_I64ABS:231case TGSI_OPCODE_I64SSG:232case TGSI_OPCODE_I64NEG:233case TGSI_OPCODE_I64SHR:234case TGSI_OPCODE_I64DIV:235case TGSI_OPCODE_I64MOD:236case TGSI_OPCODE_F2I64:237case TGSI_OPCODE_U2I64:238case TGSI_OPCODE_I2I64:239case TGSI_OPCODE_D2I64:240return TGSI_TYPE_SIGNED64;241default:242return TGSI_TYPE_FLOAT;243}244}245246/*247* infer the source type of a TGSI opcode.248*/249enum tgsi_opcode_type250tgsi_opcode_infer_src_type(enum tgsi_opcode opcode, uint src_idx)251{252if (src_idx == 1 &&253(opcode == TGSI_OPCODE_DLDEXP || opcode == TGSI_OPCODE_LDEXP))254return TGSI_TYPE_SIGNED;255256if (src_idx == 1 &&257(opcode == TGSI_OPCODE_LOAD))258return TGSI_TYPE_UNSIGNED;259260if (src_idx == 0 &&261(opcode == TGSI_OPCODE_STORE))262return TGSI_TYPE_UNSIGNED;263264if (src_idx == 1 &&265((opcode >= TGSI_OPCODE_ATOMUADD && opcode <= TGSI_OPCODE_ATOMIMAX) ||266opcode == TGSI_OPCODE_ATOMINC_WRAP || opcode == TGSI_OPCODE_ATOMDEC_WRAP))267return TGSI_TYPE_UNSIGNED;268269switch (opcode) {270case TGSI_OPCODE_UIF:271case TGSI_OPCODE_TXF:272case TGSI_OPCODE_TXF_LZ:273case TGSI_OPCODE_U2F:274case TGSI_OPCODE_U2D:275case TGSI_OPCODE_UADD:276case TGSI_OPCODE_SWITCH:277case TGSI_OPCODE_CASE:278case TGSI_OPCODE_SAMPLE_I:279case TGSI_OPCODE_SAMPLE_I_MS:280case TGSI_OPCODE_UMUL_HI:281case TGSI_OPCODE_UP2H:282case TGSI_OPCODE_U2I64:283case TGSI_OPCODE_MEMBAR:284case TGSI_OPCODE_UMSB:285return TGSI_TYPE_UNSIGNED;286case TGSI_OPCODE_IMUL_HI:287case TGSI_OPCODE_I2F:288case TGSI_OPCODE_I2D:289case TGSI_OPCODE_I2I64:290return TGSI_TYPE_SIGNED;291case TGSI_OPCODE_ARL:292case TGSI_OPCODE_ARR:293case TGSI_OPCODE_F2D:294case TGSI_OPCODE_F2I:295case TGSI_OPCODE_F2U:296case TGSI_OPCODE_FSEQ:297case TGSI_OPCODE_FSGE:298case TGSI_OPCODE_FSLT:299case TGSI_OPCODE_FSNE:300case TGSI_OPCODE_UCMP:301case TGSI_OPCODE_F2U64:302case TGSI_OPCODE_F2I64:303return TGSI_TYPE_FLOAT;304case TGSI_OPCODE_D2F:305case TGSI_OPCODE_D2U:306case TGSI_OPCODE_D2I:307case TGSI_OPCODE_DSEQ:308case TGSI_OPCODE_DSGE:309case TGSI_OPCODE_DSLT:310case TGSI_OPCODE_DSNE:311case TGSI_OPCODE_D2U64:312case TGSI_OPCODE_D2I64:313return TGSI_TYPE_DOUBLE;314case TGSI_OPCODE_U64SEQ:315case TGSI_OPCODE_U64SNE:316case TGSI_OPCODE_U64SLT:317case TGSI_OPCODE_U64SGE:318case TGSI_OPCODE_U642F:319case TGSI_OPCODE_U642D:320return TGSI_TYPE_UNSIGNED64;321case TGSI_OPCODE_I64SLT:322case TGSI_OPCODE_I64SGE:323case TGSI_OPCODE_I642F:324case TGSI_OPCODE_I642D:325return TGSI_TYPE_SIGNED64;326default:327return tgsi_opcode_infer_type(opcode);328}329}330331/*332* infer the destination type of a TGSI opcode.333*/334enum tgsi_opcode_type335tgsi_opcode_infer_dst_type(enum tgsi_opcode opcode, uint dst_idx)336{337if (dst_idx == 1 && opcode == TGSI_OPCODE_DFRACEXP)338return TGSI_TYPE_SIGNED;339340return tgsi_opcode_infer_type(opcode);341}342343344