Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. typedef unsigned int u32_t;
  3.  
  4.  
  5. typedef enum
  6. {
  7.     VS_OUT_POS   = 0,
  8.     VS_OUT_PSIZE,
  9.     VS_OUT_COL0,
  10.     VS_OUT_COL1,
  11.     VS_OUT_COL2,
  12.     VS_OUT_COL3,
  13.     VS_OUT_TEX0,
  14.     VS_OUT_TEX1,
  15.     VS_OUT_TEX2,
  16.     VS_OUT_TEX3,
  17.     VS_OUT_TEX4,
  18.     VS_OUT_TEX5,
  19.     VS_OUT_TEX6,
  20.     VS_OUT_TEX7,
  21.     VS_OUT_FOG,
  22.     VS_OUT_MAX = 0xFFFFFFFF
  23. }v_out_t;
  24.  
  25.  
  26. #if 0
  27.     vs_1_1
  28.  
  29.     dcl_position   v0
  30.     dcl_color      v1
  31.     dcl_color1     v2
  32.     dcl_fog        v3
  33.     dcl_psize      v4
  34.     dcl_texcoord   v5
  35.     dcl_texcoord1  v6
  36.  
  37.     mov oPos,    v0
  38.  
  39.     mov oD0,     v1
  40.     mov oD1,     v2
  41.  
  42.     mov oFog,    v3.x
  43.     mov oPts,    v4.x
  44.     mov oT0,     v5
  45.     mov oT1,     v6
  46.  
  47. #endif
  48.  
  49. const u32_t vs11[] =
  50. {
  51.     0xfffe0101, 0x0000001f, 0x80000000, 0x900f0000, 0x0000001f, 0x8000000a,
  52.     0x900f0001, 0x0000001f, 0x8001000a, 0x900f0002, 0x0000001f, 0x8000000b,
  53.     0x900f0003, 0x0000001f, 0x80000004, 0x900f0004, 0x0000001f, 0x80000005,
  54.     0x900f0005, 0x0000001f, 0x80010005, 0x900f0006, 0x00000001, 0xc00f0000,
  55.     0x90e40000, 0x00000001, 0xd00f0000, 0x90e40001, 0x00000001, 0xd00f0001,
  56.     0x90e40002, 0x00000001, 0xc00f0001, 0x90000003, 0x00000001, 0xc00f0002,
  57.     0x90000004, 0x00000001, 0xe00f0000, 0x90e40005, 0x00000001, 0xe00f0001,
  58.     0x90e40006, 0x0000ffff
  59. };
  60.  
  61. char *sz_vs_command[] =
  62. {
  63.     "nop",
  64.     "mov",
  65.     "add",
  66.     "sub",
  67.     "mad",
  68.     "mul",
  69.     "rcp",
  70.     "rsq",
  71.     "dp3",
  72.     "dp4",
  73.     "min",
  74.     "max",
  75.     "slt",
  76.     "sge",
  77.     "exp",
  78.     "log",
  79.     "lit",
  80.     "dst",
  81.     "lrp",
  82.     "frc",
  83.     "m4x4",
  84.     "m4x3",
  85.     "m3x4",
  86.     "m3x3",
  87.     "m3x2",
  88. };
  89.  
  90. /*
  91. char *sz_ps_command[] =
  92. {
  93.     texcoord
  94.     texkill
  95.     tex
  96.     texbem
  97.     texbeml
  98.     texreg2ar
  99.     texreg2gb
  100.     texm3x2pad
  101.     texm3x3tex
  102.     texm3x3pad
  103.     texm3x3tex
  104.     texm3x3diff
  105.     texm3x3spec
  106.     texm3x3vspec
  107.     expp
  108.     logp
  109.     cnd
  110.     def
  111.     texreg2rgb
  112.     texdp3tex
  113.     texm3x2depth
  114.     texdp3
  115.     texm3x3
  116.     texdepth
  117.     cmp
  118.     bem
  119. }
  120. */
  121.  
  122. char *szusage[]=
  123. {
  124.    "position",
  125.    "blendweight",
  126.    "blendindices",
  127.    "normal",
  128.    "psize",
  129.    "texcoord",
  130.    "tangent",
  131.    "binormal",
  132.    "tessfactor",
  133.    "positiont",
  134.    "color",
  135.    "fog",
  136.    "depth",
  137.    "sample"
  138. };
  139. char *sztype[]=
  140. {
  141.     "r",
  142.     "v",
  143.     "c"
  144.     "a",
  145.     "t",
  146.     "rasout",
  147.     "attrout",
  148.     "texcrdout",
  149.     "output",
  150.     "constint",
  151.     "colorout",
  152.     "depthout",
  153.     "sampler",
  154.     "const2",
  155.     "const3",
  156.     "const4",
  157.     "constbool",
  158.     "loop",
  159.     "tempfloat16",
  160.     "misctype",
  161.     "label",
  162.     "predicate"
  163. };
  164.  
  165.  
  166. typedef struct
  167. {
  168.   u32_t minor: 8;
  169.   u32_t major: 8;
  170.   u32_t type :16;
  171. }version_t;
  172.  
  173. typedef struct
  174. {
  175.   u32_t type:5;
  176.   u32_t rsv :11;
  177.   u32_t ind :4;
  178.   u32_t rsv2:11;
  179.   u32_t sign:1;
  180. }usage_t;
  181.  
  182. typedef struct
  183. {
  184.   u32_t ind   :11;
  185.   u32_t typeh :2;
  186.   u32_t rsv   :3;
  187.   u32_t wr    :4;
  188.   u32_t mod   :4;
  189.   u32_t scale :4;
  190.   u32_t typel :3;
  191.   u32_t sign  :1;
  192. }dst_t;
  193.  
  194. typedef struct
  195. {
  196.   u32_t ind   :11;
  197.   u32_t rsv   :5;
  198.   u32_t swzl  :8;
  199.   u32_t mod   :4;
  200.   u32_t typel :3;
  201.   u32_t sign  :1;
  202. }src_t;
  203.  
  204.  
  205. int parse_vs(const u32_t *stream);
  206.  
  207. static void assign_outputs();
  208.  
  209. int translate_vs(const u32_t *stream);
  210.  
  211.  
  212. u32_t  vs_out_written;
  213. u32_t  inp_mask;
  214.  
  215. u32_t  vs_outputs[16];
  216.  
  217. int main()
  218. {
  219.     version_t *ver;
  220.  
  221.     ver = (version_t*)vs11;
  222.  
  223.     if(ver->type == 0xFFFE)
  224.     {
  225.         printf("vs_%d_%d\n\n",ver->major,ver->minor);
  226.         if( parse_vs(vs11+1) )
  227.             translate_vs(vs11+1);
  228.     };
  229.  
  230.     return 0;
  231. };
  232.  
  233. static char txt_swzl[4] = {'x','y','z','w'};
  234. static char *txt_mod[2] = { "","_sat"};
  235.  
  236. int parse_vs(const u32_t *stream)
  237. {
  238.   dst_t  *dst;
  239.   src_t  *src;
  240.  
  241.   u32_t  swzl;
  242.   u32_t  wr;
  243.  
  244.   char   szswzl[5];
  245.   char   szwm[5];
  246.  
  247.   int    i,j;
  248.  
  249.   while(1)
  250.   {
  251.     op_type_t instr = *stream++ & 0xFFFF;
  252.  
  253.     switch( instr )
  254.     {
  255.       case D3DSIO_MOV:
  256.         dst = (dst_t*)stream++;
  257.         src = (src_t*)stream++;
  258.  
  259.         swzl = src->swzl;
  260.         wr = dst->wr;
  261.  
  262.         for(i=0,j=0; i < 4; i++)
  263.         {
  264.            szswzl[i] = txt_swzl[swzl&3];
  265.            swzl>>=2;
  266.            if(wr & (1<<i))
  267.            szwm[j++] = txt_swzl[i];
  268.         };
  269.         szswzl[4] = 0;
  270.         szwm[j] = 0;
  271.  
  272.         switch(dst->typel)
  273.         {
  274.            case 4:                   // Rasterizer Register File
  275.               if(dst->ind == 0)
  276.                  vs_out_written |= (1 << VS_OUT_POS);
  277.               else if (dst->ind == 1)
  278.                  vs_out_written |= (1 << VS_OUT_FOG);
  279.               else if (dst->ind == 2)
  280.                  vs_out_written |= (1 << VS_OUT_PSIZE);
  281.               else
  282.                  printf("invalid raster register %d",dst->ind);
  283.               break;
  284.  
  285.            case 5:     // Attribute Output Register File
  286.               if(dst->ind == 0)
  287.                  vs_out_written |= (1 << VS_OUT_COL0);
  288.               else if (dst->ind == 1)
  289.                  vs_out_written |= (1 << VS_OUT_COL1);
  290.               else
  291.                  printf("invalid attribute register %d",dst->ind);
  292.               break;
  293.  
  294.            case 6:          // Texture Coordinate Output Register File
  295.               if(dst->ind < 8)
  296.                  vs_out_written |= (1 << (VS_OUT_TEX0+dst->ind));
  297.               else
  298.                  printf("invalid texture register %d",dst->ind);
  299.         };
  300.         printf("%s%s %s%d.%s,\t %s%d.%s\n",sz_vs_command[instr],txt_mod[dst->mod],
  301.                sztype[dst->typel],dst->ind,szwm,
  302.                sztype[src->typel],src->ind,szswzl);
  303.         break;
  304.  
  305.       case D3DSIO_DCL:
  306.         parse_dcl(stream);
  307.         stream+=2;
  308.         break;
  309.       case 0xFFFF:
  310.         return 1;
  311.  
  312.       default:
  313.         return 0;
  314.     };
  315.   };
  316. };
  317.  
  318.  
  319. int parse_dcl(const u32_t *stream)
  320. {
  321.   usage_t *usage;
  322.   dst_t   *dst;
  323.   int dsttype;
  324.   char szwm[5];
  325.   int i;
  326.   u32_t wr;
  327.  
  328.   usage = (usage_t*)stream++;
  329.   dst = (dst_t*)stream++;
  330.   dsttype = (dst->typeh << 4) | dst->typel;
  331.   wr = dst->wr;
  332.  
  333.   for(i=0; wr; i++, wr>>=1)
  334.   {
  335.     if(wr & 1)
  336.       szwm[i] = txt_swzl[i];
  337.   };
  338.   szwm[i] = 0;
  339.  
  340.   printf("dcl_%s%d \t\t %s%d.%s\n",szusage[usage->type],usage->ind,
  341.          sztype[dsttype],dst->ind, szwm);
  342.  
  343.   return 2;
  344. }
  345.  
  346.  
  347.  
  348. int translate_dcl(const u32_t *stream);
  349. int translate_mov(const u32_t *stream);
  350.  
  351. int translate_vs(const u32_t *stream)
  352. {
  353.   assign_outputs();
  354.  
  355.   while(1)
  356.   {
  357.     op_type_t instr = *stream++ & 0xFFFF;
  358.  
  359.     switch( instr )
  360.     {
  361.       case D3DSIO_MOV:
  362.         translate_mov(stream);
  363.         stream+=2;
  364.         break;
  365.       case D3DSIO_DCL:
  366.         translate_dcl(stream);
  367.         stream+=2;
  368.         break;
  369.       case 0xFFFF:
  370.         return 1;
  371.  
  372.       default:
  373.         return 0;
  374.     };
  375.   };
  376. };
  377.  
  378.  
  379. int translate_dcl(const u32_t *stream)
  380. {
  381.  
  382.  
  383.  
  384.   return 1;
  385. };
  386.  
  387. u32_t inst[4];
  388.  
  389. #include "r300_vertprog.h"
  390.  
  391. /**
  392.  * Swizzle indexes.
  393.  * Do not change!
  394.  */
  395. /*@{*/
  396. #define SWIZZLE_X    0
  397. #define SWIZZLE_Y    1
  398. #define SWIZZLE_Z    2
  399. #define SWIZZLE_W    3
  400. #define SWIZZLE_ZERO 4   /**< For SWZ instruction only */
  401. #define SWIZZLE_ONE  5   /**< For SWZ instruction only */
  402. #define SWIZZLE_NIL  7   /**< used during shader code gen (undefined value) */
  403. /*@}*/
  404.  
  405. #define __CONST(x, y)   \
  406.         (PVS_SRC_OPERAND(t_src_index(vp, &src[x]),      \
  407.                            t_swizzle(y),        \
  408.                            t_swizzle(y),        \
  409.                            t_swizzle(y),        \
  410.                            t_swizzle(y),        \
  411.                            t_src_class(src[x].File), \
  412.                            VSF_FLAG_NONE) | (src[x].RelAddr << 4))
  413.  
  414. static unsigned long t_swizzle(u32_t swizzle)
  415. {
  416. /* this is in fact a NOP as the Mesa SWIZZLE_* are all identical to VSF_IN_COMPONENT_* */
  417.         return swizzle;
  418. }
  419.  
  420. static unsigned long t_dst_mask(u32_t mask)
  421. {
  422.         /* WRITEMASK_* is equivalent to VSF_FLAG_* */
  423.         return mask & VSF_FLAG_ALL;
  424. }
  425.  
  426. static unsigned long t_dst_class(int file)
  427. {
  428.  
  429.         switch (file) {
  430.         case 0:                             //D3DSPR_TEMP
  431.                 return PVS_DST_REG_TEMPORARY;
  432.         case 3:                             //D3DSPR_ADDR
  433.                 return PVS_DST_REG_A0;
  434.         case 4:                             //D3DSPR_RASTOUT
  435.         case 5:
  436.         case 6:                             //D3DSPR_TEXCRDOUT
  437.                 return PVS_DST_REG_OUT;
  438.  
  439.                 /*
  440.                    case PROGRAM_INPUT:
  441.                    case PROGRAM_LOCAL_PARAM:
  442.                    case PROGRAM_ENV_PARAM:
  443.                    case PROGRAM_NAMED_PARAM:
  444.                    case PROGRAM_STATE_VAR:
  445.                    case PROGRAM_WRITE_ONLY:
  446.                    case PROGRAM_ADDRESS:
  447.                  */
  448.         default:
  449.                 printf("problem in %s", __FUNCTION__);
  450.                 return -1;
  451.         }
  452. }
  453.  
  454. static unsigned long t_dst_index(dst_t *dst)
  455. {
  456.   switch(dst->typel)
  457.   {
  458.     case 4:
  459.         if(dst->ind == 0)
  460.            return vs_outputs[VS_OUT_POS];
  461.         else if (dst->ind == 1)
  462.            return vs_outputs[VS_OUT_FOG];
  463.         else if (dst->ind == 2)
  464.            return vs_outputs[VS_OUT_PSIZE];
  465.         break;
  466.     case 5:
  467.         if(dst->ind == 0)
  468.            return vs_outputs[VS_OUT_COL0];
  469.         else if (dst->ind == 1)
  470.            return vs_outputs[VS_OUT_COL1];
  471.  
  472.     case 6:
  473.         return vs_outputs[VS_OUT_TEX0+dst->ind];
  474.  
  475.     default:
  476.       return dst->ind;
  477.   }
  478. }
  479.  
  480.  
  481. static void assign_outputs()
  482. {
  483.         int i;
  484.         int cur_reg = 0;
  485.  
  486.         for (i = 0; i < 16; i++)
  487.                 vs_outputs[i] = -1;
  488.  
  489. //      assert(vs_out_written & (1 << VS_OUT_POS));
  490.  
  491.         if (vs_out_written & (1 << VS_OUT_POS)) {
  492.                  vs_outputs[VS_OUT_POS] = cur_reg++;
  493.         }
  494.  
  495.         if (vs_out_written & (1 << VS_OUT_PSIZE)) {
  496.                  vs_outputs[VS_OUT_PSIZE] = cur_reg++;
  497.         }
  498.  
  499.         if (vs_out_written & (1 << VS_OUT_COL0)) {
  500.                  vs_outputs[VS_OUT_COL0] = cur_reg++;
  501.         }
  502.  
  503.         if (vs_out_written & (1 << VS_OUT_COL1)) {
  504.                  vs_outputs[VS_OUT_COL1] = vs_outputs[VS_OUT_COL0] + 1;           // ???
  505.                  cur_reg = vs_outputs[VS_OUT_COL1] + 1;
  506.         }
  507.  
  508. #if 0
  509.         if (vp->key.OutputsWritten & (1 << VERT_RESULT_FOGC)) {  //fog must be in
  510.                 vp->outputs[VERT_RESULT_FOGC] = cur_reg++;             //one of the color regs
  511.         }
  512. #endif
  513.  
  514.         for (i = VS_OUT_TEX0; i <= VS_OUT_TEX7; i++) {
  515.                 if (vs_out_written & (1 << i)) {
  516.                           vs_outputs[i] = cur_reg++;
  517.                 }
  518.         }
  519. }
  520.  
  521.  
  522. int translate_mov(const u32_t *stream)
  523. {
  524.  
  525.    dst_t *dst = (dst_t*)stream++;
  526.    src_t *src = (src_t*)stream++;
  527.  
  528.    int swzl = src->swzl;
  529.    int wr = dst->wr;
  530.  
  531.  
  532.          inst[0] = PVS_OP_DST_OPERAND(VE_ADD,
  533.                                      0,
  534.                                      0,
  535.                                      t_dst_index(dst),
  536.                                      (dst->wr),
  537.                                      t_dst_class(dst->typel));
  538.  
  539.         //inst[1] = t_src(vp, &src[0]);
  540. //      inst[2] = __CONST(0, SWIZZLE_ZERO);
  541.         //inst[3] = __CONST(0, SWIZZLE_ZERO);
  542.     printf("inst_0  %x\n", inst[0]);
  543.           return 1;
  544. }
  545.  
  546. /*
  547. static GLuint *r300TranslateOpcodeMOV(struct r300_vertex_program *vp,
  548.                                       struct prog_instruction *vpi,
  549.                                       GLuint * inst,
  550.                                       struct prog_src_register src[3])
  551. {
  552.         //ADD RESULT 1.X Y Z W PARAM 0{} {X Y Z W} PARAM 0{} {ZERO ZERO ZERO ZERO}
  553.  
  554.         inst[0] = PVS_OP_DST_OPERAND(VE_ADD,
  555.                                      GL_FALSE,
  556.                                      GL_FALSE,
  557.                                      t_dst_index(vp, &vpi->DstReg),
  558.                                      t_dst_mask(vpi->DstReg.WriteMask),
  559.                                      t_dst_class(vpi->DstReg.File));
  560.         inst[1] = t_src(vp, &src[0]);
  561.         inst[2] = __CONST(0, SWIZZLE_ZERO);
  562.         inst[3] = __CONST(0, SWIZZLE_ZERO);
  563.  
  564.         return inst;
  565. }
  566.  */
  567.