Lines Matching refs:emit

37 static boolean emit_vs_postamble( struct svga_shader_emitter *emit );
38 static boolean emit_ps_postamble( struct svga_shader_emitter *emit );
86 translate_dst_register( struct svga_shader_emitter *emit,
98 dest = emit->output_map[reg->Register.Index];
146 svga_arl_needs_adjustment( const struct svga_shader_emitter *emit )
150 for (i = 0; i < emit->num_arl_consts; ++i) {
151 if (emit->arl_consts[i].arl_num == emit->current_arl)
158 svga_arl_adjustment( const struct svga_shader_emitter *emit )
162 for (i = 0; i < emit->num_arl_consts; ++i) {
163 if (emit->arl_consts[i].arl_num == emit->current_arl)
164 return emit->arl_consts[i].number;
170 translate_src_register( const struct svga_shader_emitter *emit,
180 src = emit->input_map[reg->Register.Index];
188 reg->Register.Index + emit->imm_start );
201 if (emit->unit == PIPE_SHADER_FRAGMENT) {
216 if (svga_arl_needs_adjustment( emit )) {
217 src.base.num -= svga_arl_adjustment( emit );
263 get_temp( struct svga_shader_emitter *emit )
265 int i = emit->nr_hw_temp + emit->internal_temp_count++;
276 release_temp( struct svga_shader_emitter *emit,
279 if (temp.num == emit->internal_temp_count - 1)
280 emit->internal_temp_count--;
283 static void reset_temp_regs( struct svga_shader_emitter *emit )
285 emit->internal_temp_count = 0;
294 static boolean emit_repl( struct svga_shader_emitter *emit,
314 if (!emit_op1( emit, inst_token( SVGA3DOP_MOV ), dst, *src0 ))
324 static boolean submit_op0( struct svga_shader_emitter *emit,
328 return (emit_instruction( emit, inst ) &&
329 emit_dst( emit, dest ));
332 static boolean submit_op1( struct svga_shader_emitter *emit,
337 return emit_op1( emit, inst, dest, src0 );
348 static boolean submit_op2( struct svga_shader_emitter *emit,
373 temp = get_temp( emit );
375 if (!emit_repl( emit, temp, &src0 ))
379 if (!emit_op2( emit, inst, dest, src0, src1 ))
383 release_temp( emit, temp );
393 static boolean submit_op3( struct svga_shader_emitter *emit,
433 temp0 = get_temp( emit );
435 if (!emit_repl( emit, temp0, &src0 ))
440 temp1 = get_temp( emit );
442 if (!emit_repl( emit, temp1, &src1 ))
446 if (!emit_op3( emit, inst, dest, src0, src1, src2 ))
450 release_temp( emit, temp1 );
452 release_temp( emit, temp0 );
463 static boolean submit_op4( struct svga_shader_emitter *emit,
509 temp0 = get_temp( emit );
511 if (!emit_repl( emit, temp0, &src0 ))
516 temp3 = get_temp( emit );
518 if (!emit_repl( emit, temp3, &src3 ))
522 if (!emit_op4( emit, inst, dest, src0, src1, src2, src3 ))
526 release_temp( emit, temp3 );
528 release_temp( emit, temp0 );
547 static boolean submit_lrp(struct svga_shader_emitter *emit,
563 tmp = get_temp( emit );
570 if (!submit_op3(emit, inst_token( SVGA3DOP_LRP ), tmp, src0, src1, src2))
574 if (!submit_op1(emit, inst_token( SVGA3DOP_MOV ), dst, src( tmp )))
582 static boolean emit_def_const( struct svga_shader_emitter *emit,
616 if (!emit_instruction(emit, opcode) ||
617 !svga_shader_emit_dwords( emit, def.values, Elements(def.values)))
624 create_zero_immediate( struct svga_shader_emitter *emit )
626 unsigned idx = emit->nr_hw_float_const++;
631 if (!emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT,
635 emit->zero_immediate_idx = idx;
636 emit->created_zero_immediate = TRUE;
642 create_loop_const( struct svga_shader_emitter *emit )
644 unsigned idx = emit->nr_hw_int_const++;
646 if (!emit_def_const( emit, SVGA3D_CONST_TYPE_INT, idx,
653 emit->loop_const_idx = idx;
654 emit->created_loop_const = TRUE;
660 create_arl_consts( struct svga_shader_emitter *emit )
664 for (i = 0; i < emit->num_arl_consts; i += 4) {
666 unsigned idx = emit->nr_hw_float_const++;
668 for (j = 0; j < 4 && (j + i) < emit->num_arl_consts; ++j) {
669 vals[j] = emit->arl_consts[i + j].number;
670 emit->arl_consts[i + j].idx = idx;
673 emit->arl_consts[i + 0].swizzle = TGSI_SWIZZLE_X;
676 emit->arl_consts[i + 0].swizzle = TGSI_SWIZZLE_Y;
679 emit->arl_consts[i + 0].swizzle = TGSI_SWIZZLE_Z;
682 emit->arl_consts[i + 0].swizzle = TGSI_SWIZZLE_W;
689 if (!emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT, idx,
699 get_vface( struct svga_shader_emitter *emit )
701 assert(emit->emitted_vface);
707 get_zero_immediate( struct svga_shader_emitter *emit )
709 assert(emit->created_zero_immediate);
710 assert(emit->zero_immediate_idx >= 0);
712 emit->zero_immediate_idx),
718 get_pos_neg_one_immediate( struct svga_shader_emitter *emit )
720 assert(emit->created_zero_immediate);
721 assert(emit->zero_immediate_idx >= 0);
723 emit->zero_immediate_idx),
729 get_half_immediate( struct svga_shader_emitter *emit )
731 assert(emit->created_zero_immediate);
732 assert(emit->zero_immediate_idx >= 0);
733 return swizzle(src_register(SVGA3DREG_CONST, emit->zero_immediate_idx),
739 get_loop_const( struct svga_shader_emitter *emit )
741 assert(emit->created_loop_const);
742 assert(emit->loop_const_idx >= 0);
744 emit->loop_const_idx );
748 get_fake_arl_const( struct svga_shader_emitter *emit )
753 for (i = 0; i < emit->num_arl_consts; ++ i) {
754 if (emit->arl_consts[i].arl_num == emit->current_arl) {
755 idx = emit->arl_consts[i].idx;
756 swizzle = emit->arl_consts[i].swizzle;
765 get_tex_dimensions( struct svga_shader_emitter *emit, int sampler_num )
771 idx = emit->key.fkey.tex[sampler_num].width_height_idx +
772 emit->info.file_max[TGSI_FILE_CONSTANT] + 1;
778 static boolean emit_fake_arl(struct svga_shader_emitter *emit,
782 emit, &insn->Src[0] );
783 struct src_register src1 = get_fake_arl_const( emit );
784 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
785 SVGA3dShaderDestToken tmp = get_temp( emit );
787 if (!submit_op1(emit, inst_token( SVGA3DOP_MOV ), tmp, src0))
790 if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), tmp, src( tmp ),
798 return submit_op1( emit, inst_token( SVGA3DOP_MOVA ),
802 static boolean emit_if(struct svga_shader_emitter *emit,
806 emit, &insn->Src[0] );
807 struct src_register zero = get_zero_immediate( emit );
817 SVGA3dShaderDestToken tmp = get_temp( emit );
819 if (!submit_op1(emit, inst_token( SVGA3DOP_MOV ), tmp, src0))
825 emit->dynamic_branching_level++;
827 return (emit_instruction( emit, if_token ) &&
828 emit_src( emit, src0 ) &&
829 emit_src( emit, zero ) );
832 static boolean emit_endif(struct svga_shader_emitter *emit,
835 emit->dynamic_branching_level--;
837 return emit_instruction(emit, inst_token(SVGA3DOP_ENDIF));
840 static boolean emit_else(struct svga_shader_emitter *emit,
843 return emit_instruction(emit, inst_token(SVGA3DOP_ELSE));
852 static boolean emit_floor(struct svga_shader_emitter *emit,
855 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
857 emit, &insn->Src[0] );
858 SVGA3dShaderDestToken temp = get_temp( emit );
861 if (!submit_op1( emit, inst_token( SVGA3DOP_FRC ), temp, src0 ))
865 if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), dst, src0,
879 static boolean emit_ceil(struct svga_shader_emitter *emit,
882 SVGA3dShaderDestToken dst = translate_dst_register(emit, insn, 0);
883 const struct src_register src0 = translate_src_register(emit, &insn->Src[0]);
884 SVGA3dShaderDestToken temp = get_temp(emit);
887 if (!submit_op1(emit, inst_token(SVGA3DOP_FRC), temp, negate(src0)))
891 if (!submit_op2(emit, inst_token(SVGA3DOP_ADD), dst, src0, src(temp)))
905 static boolean emit_div(struct svga_shader_emitter *emit,
908 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
910 emit, &insn->Src[0] );
912 emit, &insn->Src[1] );
913 SVGA3dShaderDestToken temp = get_temp( emit );
923 if (!submit_op1( emit, inst_token( SVGA3DOP_RCP ),
933 if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), dst, src0,
946 static boolean emit_dp2(struct svga_shader_emitter *emit,
949 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
951 emit, &insn->Src[0] );
953 emit, &insn->Src[1] );
954 SVGA3dShaderDestToken temp = get_temp( emit );
958 if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), temp, src0, src1 ))
965 if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), dst,
979 static boolean emit_dph(struct svga_shader_emitter *emit,
982 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
984 emit, &insn->Src[0] );
986 emit, &insn->Src[1] );
987 SVGA3dShaderDestToken temp = get_temp( emit );
990 if (!submit_op2( emit, inst_token( SVGA3DOP_DP3 ), temp, src0, src1 ))
996 if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), dst,
1010 static boolean emit_nrm(struct svga_shader_emitter *emit,
1013 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
1015 emit, &insn->Src[0] );
1016 SVGA3dShaderDestToken temp = get_temp( emit );
1019 if (!submit_op2( emit, inst_token( SVGA3DOP_DP3 ), temp, src0, src0 ))
1023 if (!submit_op1( emit, inst_token( SVGA3DOP_RSQ ), temp, src( temp )))
1027 if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), dst,
1035 static boolean do_emit_sincos(struct svga_shader_emitter *emit,
1040 return submit_op1(emit, inst_token(SVGA3DOP_SINCOS), dst, src0);
1043 static boolean emit_sincos(struct svga_shader_emitter *emit,
1046 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
1048 emit, &insn->Src[0] );
1049 SVGA3dShaderDestToken temp = get_temp( emit );
1052 if (!do_emit_sincos(emit, writemask(temp, TGSI_WRITEMASK_XY), src0 ))
1056 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), dst, src( temp ) ))
1066 static boolean emit_sin(struct svga_shader_emitter *emit,
1069 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
1071 emit, &insn->Src[0] );
1072 SVGA3dShaderDestToken temp = get_temp( emit );
1075 if (!do_emit_sincos(emit, writemask(temp, TGSI_WRITEMASK_Y), src0))
1081 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), dst, src0 ))
1091 static boolean emit_cos(struct svga_shader_emitter *emit,
1094 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
1096 emit, &insn->Src[0] );
1097 SVGA3dShaderDestToken temp = get_temp( emit );
1100 if (!do_emit_sincos( emit, writemask(temp, TGSI_WRITEMASK_X), src0 ))
1106 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), dst, src0 ))
1112 static boolean emit_ssg(struct svga_shader_emitter *emit,
1115 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
1117 emit, &insn->Src[0] );
1118 SVGA3dShaderDestToken temp0 = get_temp( emit );
1119 SVGA3dShaderDestToken temp1 = get_temp( emit );
1122 if (emit->unit == PIPE_SHADER_VERTEX) {
1124 return submit_op3( emit, inst_token( SVGA3DOP_SGN ), dst, src0,
1128 zero = get_zero_immediate( emit );
1133 if (!submit_op3( emit, inst_token( SVGA3DOP_CMP ),
1138 if (!submit_op3( emit, inst_token( SVGA3DOP_CMP ),
1144 return submit_op2( emit, inst_token( SVGA3DOP_ADD ), dst, src( temp0 ),
1151 static boolean emit_sub(struct svga_shader_emitter *emit,
1154 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
1156 emit, &insn->Src[0] );
1158 emit, &insn->Src[1] );
1162 if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), dst,
1170 static boolean emit_kil(struct svga_shader_emitter *emit,
1188 src0 = srcIn = translate_src_register( emit, reg );
1192 temp = get_temp( emit );
1197 submit_op1( emit, inst_token( SVGA3DOP_MOV ),
1205 if (!submit_op0( emit, inst_token( SVGA3DOP_TEXKILL ), dst(src0) ))
1209 /* need to emit a second texkill to test the W component */
1211 if (!submit_op1(emit,
1218 if (!submit_op0( emit, inst_token( SVGA3DOP_TEXKILL ), temp ))
1228 static boolean emit_kilp(struct svga_shader_emitter *emit,
1233 struct src_register one = scalar( get_zero_immediate( emit ),
1240 temp = get_temp( emit );
1241 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), temp,
1245 return submit_op0( emit, inst, temp );
1271 emit_conditional(struct svga_shader_emitter *emit,
1285 return submit_op1( emit, inst_token( SVGA3DOP_MOV ),
1307 return submit_op1( emit, inst_token( SVGA3DOP_MOV ),
1316 SVGA3dShaderDestToken temp = get_temp(emit);
1317 if (!submit_op1(emit, inst_token(SVGA3DOP_MOV), temp, pass))
1323 if (!submit_op2( emit, setp_token, pred_reg,
1330 if (!submit_op1( emit, mov_token, dst,
1340 if (!submit_op2( emit, mov_token, dst,
1349 emit_select(struct svga_shader_emitter *emit,
1358 if (emit->unit == PIPE_SHADER_VERTEX) {
1361 return submit_op2( emit, inst_token( SVGA3DOP_SGE ), dst, src0, src1 );
1363 return submit_op2( emit, inst_token( SVGA3DOP_SGE ), dst, src1, src0 );
1365 return submit_op2( emit, inst_token( SVGA3DOP_SLT ), dst, src1, src0 );
1367 return submit_op2( emit, inst_token( SVGA3DOP_SLT ), dst, src0, src1 );
1379 zero = get_zero_immediate( emit );
1384 emit,
1394 static boolean emit_select_op(struct svga_shader_emitter *emit,
1398 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
1400 emit, &insn->Src[0] );
1402 emit, &insn->Src[1] );
1404 return emit_select( emit, compare, dst, src0, src1 );
1412 emit_cmp(struct svga_shader_emitter *emit,
1415 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
1417 translate_src_register(emit, &insn->Src[0] );
1419 translate_src_register(emit, &insn->Src[1] );
1421 translate_src_register(emit, &insn->Src[2] );
1423 if (emit->unit == PIPE_SHADER_VERTEX) {
1425 scalar(get_zero_immediate(emit), TGSI_SWIZZLE_X);
1431 return emit_conditional(emit, PIPE_FUNC_LESS, dst,
1435 assert(emit->unit == PIPE_SHADER_FRAGMENT);
1438 return submit_op3( emit, inst_token( SVGA3DOP_CMP ), dst,
1446 static boolean emit_tex2(struct svga_shader_emitter *emit,
1477 texcoord = translate_src_register( emit, &insn->Src[0] );
1478 sampler = translate_src_register( emit, &insn->Src[1] );
1480 if (emit->key.fkey.tex[sampler.base.num].unnormalized ||
1481 emit->dynamic_branching_level > 0)
1482 tmp = get_temp( emit );
1487 if (emit->dynamic_branching_level > 0 &&
1490 struct src_register zero = get_zero_immediate( emit );
1493 if (!submit_op1( emit,
1500 if (!submit_op1( emit,
1512 if (emit->key.fkey.tex[sampler.base.num].unnormalized) {
1513 struct src_register wh = get_tex_dimensions( emit, sampler.base.num );
1516 if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ),
1523 return submit_op2( emit, inst, dst, texcoord, sampler );
1531 static boolean emit_tex4(struct svga_shader_emitter *emit,
1541 texcoord = translate_src_register( emit, &insn->Src[0] );
1542 ddx = translate_src_register( emit, &insn->Src[1] );
1543 ddy = translate_src_register( emit, &insn->Src[2] );
1544 sampler = translate_src_register( emit, &insn->Src[3] );
1557 return submit_op4( emit, inst, dst, texcoord, sampler, ddx, ddy );
1564 static boolean emit_tex_swizzle( struct svga_shader_emitter *emit,
1595 if (!submit_op1(emit,
1608 if (!submit_op1(emit,
1611 scalar(get_zero_immediate(emit), TGSI_SWIZZLE_X)))
1617 if (!submit_op1(emit,
1620 scalar(get_zero_immediate(emit), TGSI_SWIZZLE_W)))
1628 static boolean emit_tex(struct svga_shader_emitter *emit,
1632 translate_dst_register( emit, insn, 0 );
1634 translate_src_register( emit, &insn->Src[0] );
1636 translate_src_register( emit, &insn->Src[1] );
1642 boolean compare = (emit->key.fkey.tex[unit].compare_mode ==
1646 boolean swizzle = (emit->key.fkey.tex[unit].swizzle_r != PIPE_SWIZZLE_RED ||
1647 emit->key.fkey.tex[unit].swizzle_g != PIPE_SWIZZLE_GREEN ||
1648 emit->key.fkey.tex[unit].swizzle_b != PIPE_SWIZZLE_BLUE ||
1649 emit->key.fkey.tex[unit].swizzle_a != PIPE_SWIZZLE_ALPHA);
1657 tex_result = get_temp( emit );
1668 if (!emit_tex2( emit, insn, tex_result ))
1672 if (!emit_tex4( emit, insn, tex_result ))
1688 SVGA3dShaderDestToken src0_zdivw = get_temp( emit );
1697 if (!submit_op1( emit, inst_token( SVGA3DOP_RCP ),
1702 if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ),
1715 if (!emit_select(emit,
1716 emit->key.fkey.tex[unit].compare_func,
1725 scalar( get_zero_immediate( emit ), TGSI_SWIZZLE_W );
1727 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
1736 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), dst, src(tex_result) ))
1741 emit_tex_swizzle(emit,
1743 emit->key.fkey.tex[unit].swizzle_r,
1744 emit->key.fkey.tex[unit].swizzle_g,
1745 emit->key.fkey.tex[unit].swizzle_b,
1746 emit->key.fkey.tex[unit].swizzle_a);
1752 static boolean emit_bgnloop2( struct svga_shader_emitter *emit,
1757 struct src_register const_int = get_loop_const( emit );
1759 emit->dynamic_branching_level++;
1761 return (emit_instruction( emit, inst ) &&
1762 emit_src( emit, loop_reg ) &&
1763 emit_src( emit, const_int ) );
1766 static boolean emit_endloop2( struct svga_shader_emitter *emit,
1771 emit->dynamic_branching_level--;
1773 return emit_instruction( emit, inst );
1776 static boolean emit_brk( struct svga_shader_emitter *emit,
1780 return emit_instruction( emit, inst );
1783 static boolean emit_scalar_op1( struct svga_shader_emitter *emit,
1792 dst = translate_dst_register( emit, insn, 0 );
1793 src = translate_src_register( emit, &insn->Src[0] );
1796 return submit_op1( emit, inst, dst, src );
1800 static boolean emit_simple_instruction(struct svga_shader_emitter *emit,
1809 dst = translate_dst_register( emit, insn, 0 );
1813 return submit_op0( emit, inst, dst );
1815 return submit_op1( emit, inst, dst,
1816 translate_src_register( emit, &src[0] ));
1818 return submit_op2( emit, inst, dst,
1819 translate_src_register( emit, &src[0] ),
1820 translate_src_register( emit, &src[1] ) );
1822 return submit_op3( emit, inst, dst,
1823 translate_src_register( emit, &src[0] ),
1824 translate_src_register( emit, &src[1] ),
1825 translate_src_register( emit, &src[2] ) );
1833 static boolean emit_deriv(struct svga_shader_emitter *emit,
1836 if (emit->dynamic_branching_level > 0 &&
1839 struct src_register zero = get_zero_immediate( emit );
1841 translate_dst_register( emit, insn, 0 );
1846 if (!submit_op1(emit,
1873 dst = translate_dst_register( emit, insn, 0 );
1874 src0 = translate_src_register( emit, reg );
1880 SVGA3dShaderDestToken temp = get_temp( emit );
1882 if (!emit_repl( emit, temp, &src0 ))
1886 return submit_op1( emit, inst, dst, src0 );
1890 static boolean emit_arl(struct svga_shader_emitter *emit,
1893 ++emit->current_arl;
1894 if (emit->unit == PIPE_SHADER_FRAGMENT) {
1902 if (svga_arl_needs_adjustment( emit )) {
1903 return emit_fake_arl( emit, insn );
1905 /* no need to adjust, just emit straight arl */
1906 return emit_simple_instruction(emit, SVGA3DOP_MOVA, insn);
1910 static boolean emit_pow(struct svga_shader_emitter *emit,
1913 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
1915 emit, &insn->Src[0] );
1917 emit, &insn->Src[1] );
1933 SVGA3dShaderDestToken tmp = writemask(get_temp( emit ), TGSI_WRITEMASK_X );
1935 if (!submit_op2(emit, inst_token( SVGA3DOP_POW ), tmp, src0, src1))
1938 return submit_op1(emit, inst_token( SVGA3DOP_MOV ), dst, scalar(src(tmp), 0) );
1941 return submit_op2(emit, inst_token( SVGA3DOP_POW ), dst, src0, src1);
1945 static boolean emit_xpd(struct svga_shader_emitter *emit,
1948 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
1950 emit, &insn->Src[0] );
1952 emit, &insn->Src[1] );
1965 SVGA3dShaderDestToken tmp = get_temp( emit );
1971 if (!submit_op2(emit, inst_token( SVGA3DOP_CRS ), tmp, src0, src1))
1974 if (!submit_op1(emit, inst_token( SVGA3DOP_MOV ), dst, src( tmp )))
1978 if (!submit_op2(emit, inst_token( SVGA3DOP_CRS ), dst, src0, src1))
1982 /* Need to emit 1.0 to dst.w?
1985 struct src_register zero = get_zero_immediate( emit );
1987 if (!submit_op1(emit,
1998 static boolean emit_lrp(struct svga_shader_emitter *emit,
2001 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
2003 emit, &insn->Src[0] );
2005 emit, &insn->Src[1] );
2007 emit, &insn->Src[2] );
2009 return submit_lrp(emit, dst, src0, src1, src2);
2013 static boolean emit_dst_insn(struct svga_shader_emitter *emit,
2016 if (emit->unit == PIPE_SHADER_VERTEX) {
2019 return emit_simple_instruction(emit, SVGA3DOP_DST, insn);
2029 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
2032 emit, &insn->Src[0] );
2034 emit, &insn->Src[1] );
2035 struct src_register zero = get_zero_immediate( emit );
2044 tmp = get_temp( emit );
2053 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
2062 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
2071 if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ),
2081 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
2092 static boolean emit_exp(struct svga_shader_emitter *emit,
2095 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
2097 translate_src_register( emit, &insn->Src[0] );
2098 struct src_register zero = get_zero_immediate( emit );
2104 fraction = get_temp( emit );
2111 if (!submit_op1( emit, inst_token( SVGA3DOP_FRC ),
2120 if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ),
2126 if (!submit_op1( emit, inst_token( SVGA3DOP_EXP ),
2132 release_temp( emit, fraction );
2138 if (!submit_op1( emit, inst_token( SVGA3DOP_EXPP ),
2147 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
2156 static boolean emit_lit(struct svga_shader_emitter *emit,
2159 if (emit->unit == PIPE_SHADER_VERTEX) {
2162 return emit_simple_instruction(emit, SVGA3DOP_LIT, insn);
2184 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
2185 SVGA3dShaderDestToken tmp = get_temp( emit );
2187 emit, &insn->Src[0] );
2188 struct src_register zero = get_zero_immediate( emit );
2193 if (!submit_op2(emit, inst_token( SVGA3DOP_POW ),
2203 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
2209 /* Can't quite do this with emit conditional due to the extra
2230 if (!submit_op2( emit, setp_token, pred_reg,
2236 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), dst,
2247 if (!submit_op2( emit, mov_token,
2259 static boolean emit_ex2( struct svga_shader_emitter *emit,
2267 dst = translate_dst_register( emit, insn, 0 );
2268 src0 = translate_src_register( emit, &insn->Src[0] );
2272 SVGA3dShaderDestToken tmp = get_temp( emit );
2274 if (!submit_op1( emit, inst, tmp, src0 ))
2277 return submit_op1( emit, inst_token( SVGA3DOP_MOV ),
2282 return submit_op1( emit, inst, dst, src0 );
2286 static boolean emit_log(struct svga_shader_emitter *emit,
2289 SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 );
2291 translate_src_register( emit, &insn->Src[0] );
2292 struct src_register zero = get_zero_immediate( emit );
2302 log2_abs = get_temp( emit );
2312 abs_tmp = get_temp( emit );
2314 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
2324 if (!submit_op1( emit, inst_token( SVGA3DOP_LOG ),
2336 floor_log2 = get_temp( emit );
2340 if (!submit_op1( emit, inst_token( SVGA3DOP_FRC ),
2345 if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ),
2355 if (!submit_op1( emit, inst_token( SVGA3DOP_EXP ),
2361 if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ),
2369 release_temp( emit, floor_log2 );
2372 release_temp( emit, log2_abs );
2377 release_temp( emit, abs_tmp );
2382 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ),
2398 emit_trunc_round(struct svga_shader_emitter *emit,
2402 SVGA3dShaderDestToken dst = translate_dst_register(emit, insn, 0);
2404 translate_src_register(emit, &insn->Src[0] );
2405 SVGA3dShaderDestToken t1 = get_temp(emit);
2408 SVGA3dShaderDestToken t0 = get_temp(emit);
2409 struct src_register half = get_half_immediate(emit);
2412 if (!submit_op2(emit, inst_token(SVGA3DOP_ADD), t0,
2417 if (!submit_op1(emit, inst_token(SVGA3DOP_FRC), t1, src(t0)))
2421 if (!submit_op2(emit, inst_token(SVGA3DOP_ADD), t1, src(t0),
2429 if (!submit_op1(emit, inst_token(SVGA3DOP_FRC), t1, absolute(src0)))
2433 if (!submit_op2(emit, inst_token(SVGA3DOP_ADD), t1, absolute(src0),
2441 if (emit->unit == PIPE_SHADER_VERTEX) {
2444 SVGA3dShaderDestToken t2 = get_temp(emit), t3 = get_temp(emit),
2445 t4 = get_temp(emit);
2448 if (!submit_op3(emit, inst_token(SVGA3DOP_SGN), t2, src0,
2453 if (!submit_op2(emit, inst_token(SVGA3DOP_MUL), dst, src(t1), src(t2)))
2458 return submit_op3(emit, inst_token( SVGA3DOP_CMP ), dst,
2466 static boolean emit_bgnsub( struct svga_shader_emitter *emit,
2476 emit->in_main_func = FALSE;
2478 for (i = 0; i < emit->nr_labels; i++) {
2479 if (emit->label[i] == position) {
2480 return (emit_instruction( emit, inst_token( SVGA3DOP_RET ) ) &&
2481 emit_instruction( emit, inst_token( SVGA3DOP_LABEL ) ) &&
2482 emit_src( emit, src_register( SVGA3DREG_LABEL, i )));
2490 static boolean emit_call( struct svga_shader_emitter *emit,
2496 for (i = 0; i < emit->nr_labels; i++) {
2497 if (emit->label[i] == position)
2501 if (emit->nr_labels == Elements(emit->label))
2504 if (i == emit->nr_labels) {
2505 emit->label[i] = position;
2506 emit->nr_labels++;
2509 return (emit_instruction( emit, inst_token( SVGA3DOP_CALL ) ) &&
2510 emit_src( emit, src_register( SVGA3DREG_LABEL, i )));
2514 static boolean emit_end( struct svga_shader_emitter *emit )
2516 if (emit->unit == PIPE_SHADER_VERTEX) {
2517 return emit_vs_postamble( emit );
2520 return emit_ps_postamble( emit );
2526 static boolean svga_emit_instruction( struct svga_shader_emitter *emit,
2533 return emit_arl( emit, insn );
2540 return emit_tex( emit, insn );
2544 return emit_deriv( emit, insn );
2547 return emit_bgnsub( emit, position, insn );
2553 return emit_call( emit, insn );
2556 return emit_floor( emit, insn );
2559 return emit_trunc_round( emit, insn, FALSE );
2562 return emit_trunc_round( emit, insn, TRUE );
2565 return emit_ceil( emit, insn );
2568 return emit_cmp( emit, insn );
2571 return emit_div( emit, insn );
2574 return emit_dp2( emit, insn );
2577 return emit_dph( emit, insn );
2580 return emit_nrm( emit, insn );
2583 return emit_cos( emit, insn );
2586 return emit_sin( emit, insn );
2589 return emit_sincos( emit, insn );
2593 return emit_end( emit );
2596 return emit_kil( emit, insn );
2602 return emit_select_op( emit, PIPE_FUNC_EQUAL, insn );
2605 return emit_select_op( emit, PIPE_FUNC_NOTEQUAL, insn );
2608 return emit_select_op( emit, PIPE_FUNC_GREATER, insn );
2611 return emit_select_op( emit, PIPE_FUNC_GEQUAL, insn );
2614 return emit_select_op( emit, PIPE_FUNC_LESS, insn );
2617 return emit_select_op( emit, PIPE_FUNC_LEQUAL, insn );
2620 return emit_sub( emit, insn );
2623 return emit_pow( emit, insn );
2626 return emit_ex2( emit, insn );
2629 return emit_exp( emit, insn );
2632 return emit_log( emit, insn );
2635 return emit_scalar_op1( emit, SVGA3DOP_LOG, insn );
2638 return emit_scalar_op1( emit, SVGA3DOP_RSQ, insn );
2641 return emit_scalar_op1( emit, SVGA3DOP_RCP, insn );
2665 return emit_if( emit, insn );
2667 return emit_else( emit, insn );
2669 return emit_endif( emit, insn );
2672 return emit_bgnloop2( emit, insn );
2674 return emit_endloop2( emit, insn );
2676 return emit_brk( emit, insn );
2679 return emit_xpd( emit, insn );
2682 return emit_kilp( emit, insn );
2685 return emit_dst_insn( emit, insn );
2688 return emit_lit( emit, insn );
2691 return emit_lrp( emit, insn );
2694 return emit_ssg( emit, insn );
2702 if (!emit_simple_instruction( emit, opcode, insn ))
2711 static boolean svga_emit_immediate( struct svga_shader_emitter *emit,
2725 return emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT,
2726 emit->imm_start + emit->internal_imm_count++,
2730 static boolean make_immediate( struct svga_shader_emitter *emit,
2737 unsigned idx = emit->nr_hw_float_const++;
2739 if (!emit_def_const( emit, SVGA3D_CONST_TYPE_FLOAT,
2748 static boolean emit_vs_preamble( struct svga_shader_emitter *emit )
2750 if (!emit->key.vkey.need_prescale) {
2751 if (!make_immediate( emit, 0, 0, .5, .5,
2752 &emit->imm_0055))
2759 static boolean emit_ps_preamble( struct svga_shader_emitter *emit )
2761 if (emit->ps_reads_pos && emit->info.reads_z) {
2771 if (!submit_op1( emit,
2773 writemask( emit->ps_temp_pos, TGSI_WRITEMASK_XY ),
2774 emit->ps_true_pos ))
2777 if (!submit_op1( emit,
2779 writemask( emit->ps_temp_pos, TGSI_WRITEMASK_W ),
2780 scalar( emit->ps_depth_pos, TGSI_SWIZZLE_W ) ))
2783 if (!submit_op2( emit,
2785 writemask( emit->ps_temp_pos, TGSI_WRITEMASK_Z ),
2786 scalar( emit->ps_depth_pos, TGSI_SWIZZLE_Z ),
2787 scalar( src(emit->ps_temp_pos), TGSI_SWIZZLE_W ) ))
2794 static boolean emit_ps_postamble( struct svga_shader_emitter *emit )
2799 * types of usage that break it during shader emit. Easier just to
2803 if (SVGA3dShaderGetRegType(emit->true_pos.value) != 0) {
2805 if (!submit_op1( emit,
2807 emit->true_pos,
2808 scalar(src(emit->temp_pos), TGSI_SWIZZLE_Z) ))
2813 if (SVGA3dShaderGetRegType(emit->true_col[i].value) != 0) {
2818 if (emit->unit == PIPE_SHADER_FRAGMENT &&
2819 emit->key.fkey.white_fragments) {
2821 struct src_register one = scalar( get_zero_immediate( emit ),
2824 if (!submit_op1( emit,
2826 emit->true_col[i],
2831 if (!submit_op1( emit,
2833 emit->true_col[i],
2834 src(emit->temp_col[i]) ))
2843 static boolean emit_vs_postamble( struct svga_shader_emitter *emit )
2846 * the types of usage that break it during shader emit. Easier
2850 if (SVGA3dShaderGetRegType(emit->true_psiz.value) != 0) {
2851 if (!submit_op1( emit,
2853 emit->true_psiz,
2854 scalar(src(emit->temp_psiz), TGSI_SWIZZLE_X) ))
2861 if (emit->key.vkey.need_prescale) {
2862 SVGA3dShaderDestToken temp_pos = emit->temp_pos;
2863 SVGA3dShaderDestToken depth = emit->depth_pos;
2864 SVGA3dShaderDestToken pos = emit->true_pos;
2865 unsigned offset = emit->info.file_max[TGSI_FILE_CONSTANT] + 1;
2871 if (!submit_op1( emit,
2881 if (!submit_op2( emit,
2888 if (!submit_op3( emit,
2897 if (!submit_op3( emit,
2906 SVGA3dShaderDestToken temp_pos = emit->temp_pos;
2907 SVGA3dShaderDestToken depth = emit->depth_pos;
2908 SVGA3dShaderDestToken pos = emit->true_pos;
2909 struct src_register imm_0055 = emit->imm_0055;
2916 if (!submit_op2( emit,
2923 if (!submit_op1( emit,
2930 if (!submit_op1( emit,
2947 static boolean emit_light_twoside( struct svga_shader_emitter *emit )
2953 int count = emit->internal_color_count;
2960 vface = get_vface( emit );
2961 zero = get_zero_immediate( emit );
2968 color[i] = dst_register( SVGA3DREG_TEMP, emit->nr_hw_temp++ );
2969 front[i] = emit->input_map[emit->internal_color_idx[i]];
2978 emit->input_map[emit->internal_color_idx[i]] = src(color[i]);
2983 if (emit->key.fkey.front_ccw)
2990 if (!(emit_instruction( emit, if_token ) &&
2991 emit_src( emit, vface ) &&
2992 emit_src( emit, zero ) ))
2996 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), color[i], front[i] ))
3000 if (!(emit_instruction( emit, inst_token( SVGA3DOP_ELSE))))
3004 if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), color[i], back[i] ))
3008 if (!emit_instruction( emit, inst_token( SVGA3DOP_ENDIF ) ))
3018 static boolean emit_frontface( struct svga_shader_emitter *emit )
3024 vface = get_vface( emit );
3025 zero = get_zero_immediate( emit );
3032 emit->nr_hw_temp++ );
3034 if (emit->key.fkey.front_ccw) {
3042 if (!emit_conditional(emit, PIPE_FUNC_GREATER,
3049 emit->input_map[emit->internal_frontface_idx] = src(temp);
3060 static boolean emit_inverted_texcoords( struct svga_shader_emitter *emit )
3062 struct src_register zero = get_zero_immediate(emit);
3063 struct src_register pos_neg_one = get_pos_neg_one_immediate( emit );
3064 unsigned inverted_texcoords = emit->inverted_texcoords;
3069 assert(emit->inverted_texcoords & (1 << unit));
3071 assert(unit < Elements(emit->ps_true_texcoord));
3073 assert(unit < Elements(emit->ps_inverted_texcoord_input));
3075 assert(emit->ps_inverted_texcoord_input[unit]
3076 < Elements(emit->input_map));
3079 if (!submit_op3(emit,
3081 dst(emit->ps_inverted_texcoord[unit]),
3082 emit->ps_true_texcoord[unit],
3088 emit->input_map[emit->ps_inverted_texcoord_input[unit]] =
3089 emit->ps_inverted_texcoord[unit];
3099 needs_to_create_zero( struct svga_shader_emitter *emit )
3103 if (emit->unit == PIPE_SHADER_FRAGMENT) {
3104 if (emit->key.fkey.light_twoside)
3107 if (emit->key.fkey.white_fragments)
3110 if (emit->emit_frontface)
3113 if (emit->info.opcode_count[TGSI_OPCODE_DST] >= 1 ||
3114 emit->info.opcode_count[TGSI_OPCODE_SSG] >= 1 ||
3115 emit->info.opcode_count[TGSI_OPCODE_LIT] >= 1)
3118 if (emit->inverted_texcoords)
3122 for (i = 0; i < emit->key.fkey.num_textures; i++) {
3123 if (emit->key.fkey.tex[i].swizzle_r > PIPE_SWIZZLE_ALPHA ||
3124 emit->key.fkey.tex[i].swizzle_g > PIPE_SWIZZLE_ALPHA ||
3125 emit->key.fkey.tex[i].swizzle_b > PIPE_SWIZZLE_ALPHA ||
3126 emit->key.fkey.tex[i].swizzle_a > PIPE_SWIZZLE_ALPHA)
3130 for (i = 0; i < emit->key.fkey.num_textures; i++) {
3131 if (emit->key.fkey.tex[i].compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE)
3136 if (emit->unit == PIPE_SHADER_VERTEX) {
3137 if (emit->info.opcode_count[TGSI_OPCODE_CMP] >= 1)
3141 if (emit->info.opcode_count[TGSI_OPCODE_IF] >= 1 ||
3142 emit->info.opcode_count[TGSI_OPCODE_BGNLOOP] >= 1 ||
3143 emit->info.opcode_count[TGSI_OPCODE_DDX] >= 1 ||
3144 emit->info.opcode_count[TGSI_OPCODE_DDY] >= 1 ||
3145 emit->info.opcode_count[TGSI_OPCODE_ROUND] >= 1 ||
3146 emit->info.opcode_count[TGSI_OPCODE_SGE] >= 1 ||
3147 emit->info.opcode_count[TGSI_OPCODE_SGT] >= 1 ||
3148 emit->info.opcode_count[TGSI_OPCODE_SLE] >= 1 ||
3149 emit->info.opcode_count[TGSI_OPCODE_SLT] >= 1 ||
3150 emit->info.opcode_count[TGSI_OPCODE_SNE] >= 1 ||
3151 emit->info.opcode_count[TGSI_OPCODE_SEQ] >= 1 ||
3152 emit->info.opcode_count[TGSI_OPCODE_EXP] >= 1 ||
3153 emit->info.opcode_count[TGSI_OPCODE_LOG] >= 1 ||
3154 emit->info.opcode_count[TGSI_OPCODE_XPD] >= 1 ||
3155 emit->info.opcode_count[TGSI_OPCODE_KILP] >= 1)
3162 needs_to_create_loop_const( struct svga_shader_emitter *emit )
3164 return (emit->info.opcode_count[TGSI_OPCODE_BGNLOOP] >= 1);
3168 needs_to_create_arl_consts( struct svga_shader_emitter *emit )
3170 return (emit->num_arl_consts > 0);
3174 pre_parse_add_indirect( struct svga_shader_emitter *emit,
3180 for (i = 0; i < emit->num_arl_consts; ++i) {
3181 if (emit->arl_consts[i].arl_num == current_arl)
3185 if (emit->num_arl_consts == i) {
3186 ++emit->num_arl_consts;
3188 emit->arl_consts[i].number = (emit->arl_consts[i].number > num) ?
3190 emit->arl_consts[i].number;
3191 emit->arl_consts[i].arl_num = current_arl;
3196 pre_parse_instruction( struct svga_shader_emitter *emit,
3204 pre_parse_add_indirect(emit, reg->Register.Index, current_arl);
3212 pre_parse_add_indirect(emit, reg->Register.Index, current_arl);
3220 pre_parse_add_indirect(emit, reg->Register.Index, current_arl);
3228 pre_parse_tokens( struct svga_shader_emitter *emit,
3247 if (!pre_parse_instruction( emit, &parse.FullToken.FullInstruction,
3259 static boolean svga_shader_emit_helpers( struct svga_shader_emitter *emit )
3262 if (needs_to_create_zero( emit )) {
3263 create_zero_immediate( emit );
3265 if (needs_to_create_loop_const( emit )) {
3266 create_loop_const( emit );
3268 if (needs_to_create_arl_consts( emit )) {
3269 create_arl_consts( emit );
3272 if (emit->unit == PIPE_SHADER_FRAGMENT) {
3273 if (!emit_ps_preamble( emit ))
3276 if (emit->key.fkey.light_twoside) {
3277 if (!emit_light_twoside( emit ))
3280 if (emit->emit_frontface) {
3281 if (!emit_frontface( emit ))
3284 if (emit->inverted_texcoords) {
3285 if (!emit_inverted_texcoords( emit ))
3293 boolean svga_shader_emit_instructions( struct svga_shader_emitter *emit,
3302 emit->internal_imm_count = 0;
3304 if (emit->unit == PIPE_SHADER_VERTEX) {
3305 ret = emit_vs_preamble( emit );
3310 pre_parse_tokens(emit, tokens);
3317 ret = svga_emit_immediate( emit, &parse.FullToken.FullImmediate );
3323 ret = svga_translate_decl_sm30( emit, &parse.FullToken.FullDeclaration );
3330 if (!svga_shader_emit_helpers( emit ))
3334 ret = svga_emit_instruction( emit,
3344 reset_temp_regs( emit );
3351 if (!emit->in_main_func) {
3352 ret = emit_instruction( emit, inst_token( SVGA3DOP_RET ) );
3357 assert(emit->dynamic_branching_level == 0);
3361 ret = emit_instruction( emit, inst_token( SVGA3DOP_END ) );