From: Brian Paul Date: Wed, 19 Jun 2013 16:39:43 +0000 (-0600) Subject: svga: formatting fixes in svga_tgsi_insn.c X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3abd9285be7b2b71dab0b8ed20ebbceea9e9d2dd;p=mesa.git svga: formatting fixes in svga_tgsi_insn.c Reviewed-by: Jose Fonseca --- diff --git a/src/gallium/drivers/svga/svga_tgsi_insn.c b/src/gallium/drivers/svga/svga_tgsi_insn.c index f94f3b2fc80..1e0579d95e6 100644 --- a/src/gallium/drivers/svga/svga_tgsi_insn.c +++ b/src/gallium/drivers/svga/svga_tgsi_insn.c @@ -39,8 +39,7 @@ static boolean emit_ps_postamble( struct svga_shader_emitter *emit ); static unsigned -translate_opcode( - uint opcode ) +translate_opcode(uint opcode) { switch (opcode) { case TGSI_OPCODE_ABS: return SVGA3DOP_ABS; @@ -64,7 +63,8 @@ translate_opcode( } -static unsigned translate_file( unsigned file ) +static unsigned +translate_file(unsigned file) { switch (file) { case TGSI_FILE_TEMPORARY: return SVGA3DREG_TEMP; @@ -134,6 +134,7 @@ swizzle( struct src_register src, return src; } + static struct src_register scalar( struct src_register src, int comp ) @@ -141,7 +142,8 @@ scalar( struct src_register src, return swizzle( src, comp, comp, comp, comp ); } -static INLINE boolean + +static boolean svga_arl_needs_adjustment( const struct svga_shader_emitter *emit ) { int i; @@ -153,7 +155,8 @@ svga_arl_needs_adjustment( const struct svga_shader_emitter *emit ) return FALSE; } -static INLINE int + +static int svga_arl_adjustment( const struct svga_shader_emitter *emit ) { int i; @@ -165,6 +168,7 @@ svga_arl_adjustment( const struct svga_shader_emitter *emit ) return 0; } + static struct src_register translate_src_register( const struct svga_shader_emitter *emit, const struct tgsi_full_src_register *reg ) @@ -190,7 +194,6 @@ translate_src_register( const struct svga_shader_emitter *emit, default: src = src_register( translate_file( reg->Register.File ), reg->Register.Index ); - break; } @@ -258,7 +261,7 @@ translate_src_register( const struct svga_shader_emitter *emit, * Note: if we exceed the temporary register limit we just use * register SVGA3D_TEMPREG_MAX - 1. */ -static INLINE SVGA3dShaderDestToken +static SVGA3dShaderDestToken get_temp( struct svga_shader_emitter *emit ) { int i = emit->nr_hw_temp + emit->internal_temp_count++; @@ -267,11 +270,13 @@ get_temp( struct svga_shader_emitter *emit ) return dst_register( SVGA3DREG_TEMP, i ); } -/* Release a single temp. Currently only effective if it was the last + +/** + * Release a single temp. Currently only effective if it was the last * allocated temp, otherwise release will be delayed until the next * call to reset_temp_regs(). */ -static INLINE void +static void release_temp( struct svga_shader_emitter *emit, SVGA3dShaderDestToken temp ) { @@ -279,7 +284,9 @@ release_temp( struct svga_shader_emitter *emit, emit->internal_temp_count--; } -static void reset_temp_regs( struct svga_shader_emitter *emit ) + +static void +reset_temp_regs(struct svga_shader_emitter *emit) { emit->internal_temp_count = 0; } @@ -290,9 +297,10 @@ static void reset_temp_regs( struct svga_shader_emitter *emit ) * important given that several opcodes have constraints in the allowed * swizzles). */ -static boolean emit_repl( struct svga_shader_emitter *emit, - SVGA3dShaderDestToken dst, - struct src_register *src0) +static boolean +emit_repl(struct svga_shader_emitter *emit, + SVGA3dShaderDestToken dst, + struct src_register *src0) { unsigned src0_swizzle; unsigned chan; @@ -320,35 +328,40 @@ static boolean emit_repl( struct svga_shader_emitter *emit, } -static boolean submit_op0( struct svga_shader_emitter *emit, - SVGA3dShaderInstToken inst, - SVGA3dShaderDestToken dest ) +static boolean +submit_op0(struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest) { return (emit_instruction( emit, inst ) && emit_dst( emit, dest )); } -static boolean submit_op1( struct svga_shader_emitter *emit, - SVGA3dShaderInstToken inst, - SVGA3dShaderDestToken dest, - struct src_register src0 ) + +static boolean +submit_op1(struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0) { return emit_op1( emit, inst, dest, src0 ); } -/* SVGA shaders may not refer to >1 constant register in a single +/** + * SVGA shaders may not refer to >1 constant register in a single * instruction. This function checks for that usage and inserts a * move to temporary if detected. * * The same applies to input registers -- at most a single input * register may be read by any instruction. */ -static boolean submit_op2( struct svga_shader_emitter *emit, - SVGA3dShaderInstToken inst, - SVGA3dShaderDestToken dest, - struct src_register src0, - struct src_register src1 ) +static boolean +submit_op2(struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0, + struct src_register src1) { SVGA3dShaderDestToken temp; SVGA3dShaderRegType type0, type1; @@ -385,16 +398,18 @@ static boolean submit_op2( struct svga_shader_emitter *emit, } -/* SVGA shaders may not refer to >1 constant register in a single +/** + * SVGA shaders may not refer to >1 constant register in a single * instruction. This function checks for that usage and inserts a * move to temporary if detected. */ -static boolean submit_op3( struct svga_shader_emitter *emit, - SVGA3dShaderInstToken inst, - SVGA3dShaderDestToken dest, - struct src_register src0, - struct src_register src1, - struct src_register src2 ) +static boolean +submit_op3(struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0, + struct src_register src1, + struct src_register src2) { SVGA3dShaderDestToken temp0; SVGA3dShaderDestToken temp1; @@ -453,19 +468,19 @@ static boolean submit_op3( struct svga_shader_emitter *emit, } - - -/* SVGA shaders may not refer to >1 constant register in a single +/** + * SVGA shaders may not refer to >1 constant register in a single * instruction. This function checks for that usage and inserts a * move to temporary if detected. */ -static boolean submit_op4( struct svga_shader_emitter *emit, - SVGA3dShaderInstToken inst, - SVGA3dShaderDestToken dest, - struct src_register src0, - struct src_register src1, - struct src_register src2, - struct src_register src3) +static boolean +submit_op4(struct svga_shader_emitter *emit, + SVGA3dShaderInstToken inst, + SVGA3dShaderDestToken dest, + struct src_register src0, + struct src_register src1, + struct src_register src2, + struct src_register src3) { SVGA3dShaderDestToken temp0; SVGA3dShaderDestToken temp3; @@ -529,8 +544,12 @@ static boolean submit_op4( struct svga_shader_emitter *emit, } -static boolean alias_src_dst( struct src_register src, - SVGA3dShaderDestToken dst ) +/** + * Do the src and dest registers refer to the same register? + */ +static boolean +alias_src_dst(struct src_register src, + SVGA3dShaderDestToken dst) { if (src.base.num != dst.num) return FALSE; @@ -543,11 +562,12 @@ static boolean alias_src_dst( struct src_register src, } -static boolean submit_lrp(struct svga_shader_emitter *emit, - SVGA3dShaderDestToken dst, - struct src_register src0, - struct src_register src1, - struct src_register src2) +static boolean +submit_lrp(struct svga_shader_emitter *emit, + SVGA3dShaderDestToken dst, + struct src_register src0, + struct src_register src1, + struct src_register src2) { SVGA3dShaderDestToken tmp; boolean need_dst_tmp = FALSE; @@ -578,13 +598,10 @@ static boolean submit_lrp(struct svga_shader_emitter *emit, } -static boolean emit_def_const( struct svga_shader_emitter *emit, - SVGA3dShaderConstType type, - unsigned idx, - float a, - float b, - float c, - float d ) +static boolean +emit_def_const(struct svga_shader_emitter *emit, + SVGA3dShaderConstType type, + unsigned idx, float a, float b, float c, float d) { SVGA3DOpDefArgs def; SVGA3dShaderInstToken opcode; @@ -619,7 +636,8 @@ static boolean emit_def_const( struct svga_shader_emitter *emit, return TRUE; } -static INLINE boolean + +static boolean create_zero_immediate( struct svga_shader_emitter *emit ) { unsigned idx = emit->nr_hw_float_const++; @@ -637,7 +655,8 @@ create_zero_immediate( struct svga_shader_emitter *emit ) return TRUE; } -static INLINE boolean + +static boolean create_loop_const( struct svga_shader_emitter *emit ) { unsigned idx = emit->nr_hw_int_const++; @@ -655,7 +674,7 @@ create_loop_const( struct svga_shader_emitter *emit ) return TRUE; } -static INLINE boolean +static boolean create_arl_consts( struct svga_shader_emitter *emit ) { int i; @@ -694,15 +713,23 @@ create_arl_consts( struct svga_shader_emitter *emit ) return TRUE; } -static INLINE struct src_register + +/** + * Return the register which holds the pixel shaders front/back- + * facing value. + */ +static struct src_register get_vface( struct svga_shader_emitter *emit ) { assert(emit->emitted_vface); return src_register(SVGA3DREG_MISCTYPE, SVGA3DMISCREG_FACE); } -/* returns {0, 0, 0, 1} immediate */ -static INLINE struct src_register + +/** + * returns {0, 0, 0, 1} immediate + */ +static struct src_register get_zero_immediate( struct svga_shader_emitter *emit ) { assert(emit->created_zero_immediate); @@ -712,8 +739,11 @@ get_zero_immediate( struct svga_shader_emitter *emit ) 0, 0, 0, 3); } -/* returns {1, 1, 1, -1} immediate */ -static INLINE struct src_register + +/** + * returns {1, 1, 1, -1} immediate + */ +static struct src_register get_pos_neg_one_immediate( struct svga_shader_emitter *emit ) { assert(emit->created_zero_immediate); @@ -723,8 +753,11 @@ get_pos_neg_one_immediate( struct svga_shader_emitter *emit ) 3, 3, 3, 2); } -/* returns {0.5, 0.5, 0.5, 0.5} immediate */ -static INLINE struct src_register + +/** + * returns {0.5, 0.5, 0.5, 0.5} immediate + */ +static struct src_register get_half_immediate( struct svga_shader_emitter *emit ) { assert(emit->created_zero_immediate); @@ -733,8 +766,11 @@ get_half_immediate( struct svga_shader_emitter *emit ) 1, 1, 1, 1); } -/* returns the loop const */ -static INLINE struct src_register + +/** + * returns the loop const + */ +static struct src_register get_loop_const( struct svga_shader_emitter *emit ) { assert(emit->created_loop_const); @@ -743,7 +779,8 @@ get_loop_const( struct svga_shader_emitter *emit ) emit->loop_const_idx ); } -static INLINE struct src_register + +static struct src_register get_fake_arl_const( struct svga_shader_emitter *emit ) { struct src_register reg; @@ -760,7 +797,12 @@ get_fake_arl_const( struct svga_shader_emitter *emit ) return scalar(reg, swizzle); } -static INLINE struct src_register + +/** + * Return the register which holds the current dimenions of the + * texture bound to the given sampler + */ +static struct src_register get_tex_dimensions( struct svga_shader_emitter *emit, int sampler_num ) { int idx; @@ -774,11 +816,13 @@ get_tex_dimensions( struct svga_shader_emitter *emit, int sampler_num ) return reg; } -static boolean emit_fake_arl(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) + +static boolean +emit_fake_arl(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { - const struct src_register src0 = translate_src_register( - emit, &insn->Src[0] ); + const struct src_register src0 = + translate_src_register(emit, &insn->Src[0] ); struct src_register src1 = get_fake_arl_const( emit ); SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); SVGA3dShaderDestToken tmp = get_temp( emit ); @@ -798,11 +842,13 @@ static boolean emit_fake_arl(struct svga_shader_emitter *emit, dst, src1 ); } -static boolean emit_if(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) + +static boolean +emit_if(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { - struct src_register src0 = translate_src_register( - emit, &insn->Src[0] ); + struct src_register src0 = + translate_src_register(emit, &insn->Src[0]); struct src_register zero = get_zero_immediate( emit ); SVGA3dShaderInstToken if_token = inst_token( SVGA3DOP_IFC ); @@ -828,32 +874,39 @@ static boolean emit_if(struct svga_shader_emitter *emit, emit_src( emit, zero ) ); } -static boolean emit_endif(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) + +static boolean +emit_endif(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { emit->dynamic_branching_level--; return emit_instruction(emit, inst_token(SVGA3DOP_ENDIF)); } -static boolean emit_else(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) + +static boolean +emit_else(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { return emit_instruction(emit, inst_token(SVGA3DOP_ELSE)); } -/* Translate the following TGSI FLR instruction. + +/** + * Translate the following TGSI FLR instruction. * FLR DST, SRC * To the following SVGA3D instruction sequence. * FRC TMP, SRC * SUB DST, SRC, TMP */ -static boolean emit_floor(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_floor(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); - const struct src_register src0 = translate_src_register( - emit, &insn->Src[0] ); + const struct src_register src0 = + translate_src_register(emit, &insn->Src[0] ); SVGA3dShaderDestToken temp = get_temp( emit ); /* FRC TMP, SRC */ @@ -869,17 +922,20 @@ static boolean emit_floor(struct svga_shader_emitter *emit, } -/* Translate the following TGSI CEIL instruction. +/** + * Translate the following TGSI CEIL instruction. * CEIL DST, SRC * To the following SVGA3D instruction sequence. * FRC TMP, -SRC * ADD DST, SRC, TMP */ -static boolean emit_ceil(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) +static boolean +emit_ceil(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register(emit, insn, 0); - const struct src_register src0 = translate_src_register(emit, &insn->Src[0]); + const struct src_register src0 = + translate_src_register(emit, &insn->Src[0]); SVGA3dShaderDestToken temp = get_temp(emit); /* FRC TMP, -SRC */ @@ -894,21 +950,23 @@ static boolean emit_ceil(struct svga_shader_emitter *emit, } -/* Translate the following TGSI DIV instruction. +/** + * Translate the following TGSI DIV instruction. * DIV DST.xy, SRC0, SRC1 * To the following SVGA3D instruction sequence. * RCP TMP.x, SRC1.xxxx * RCP TMP.y, SRC1.yyyy * MUL DST.xy, SRC0, TMP */ -static boolean emit_div(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_div(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); - const struct src_register src0 = translate_src_register( - emit, &insn->Src[0] ); - const struct src_register src1 = translate_src_register( - emit, &insn->Src[1] ); + const struct src_register src0 = + translate_src_register(emit, &insn->Src[0] ); + const struct src_register src1 = + translate_src_register(emit, &insn->Src[1] ); SVGA3dShaderDestToken temp = get_temp( emit ); int i; @@ -936,20 +994,23 @@ static boolean emit_div(struct svga_shader_emitter *emit, return TRUE; } -/* Translate the following TGSI DP2 instruction. + +/** + * Translate the following TGSI DP2 instruction. * DP2 DST, SRC1, SRC2 * To the following SVGA3D instruction sequence. * MUL TMP, SRC1, SRC2 * ADD DST, TMP.xxxx, TMP.yyyy */ -static boolean emit_dp2(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_dp2(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); - const struct src_register src0 = translate_src_register( - emit, &insn->Src[0] ); - const struct src_register src1 = translate_src_register( - emit, &insn->Src[1] ); + const struct src_register src0 = + translate_src_register(emit, &insn->Src[0]); + const struct src_register src1 = + translate_src_register(emit, &insn->Src[1]); SVGA3dShaderDestToken temp = get_temp( emit ); struct src_register temp_src0, temp_src1; @@ -969,20 +1030,22 @@ static boolean emit_dp2(struct svga_shader_emitter *emit, } -/* Translate the following TGSI DPH instruction. +/** + * Translate the following TGSI DPH instruction. * DPH DST, SRC1, SRC2 * To the following SVGA3D instruction sequence. * DP3 TMP, SRC1, SRC2 * ADD DST, TMP, SRC2.wwww */ -static boolean emit_dph(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_dph(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); const struct src_register src0 = translate_src_register( emit, &insn->Src[0] ); - struct src_register src1 = translate_src_register( - emit, &insn->Src[1] ); + struct src_register src1 = + translate_src_register(emit, &insn->Src[1]); SVGA3dShaderDestToken temp = get_temp( emit ); /* DP3 TMP, SRC1, SRC2 */ @@ -999,19 +1062,22 @@ static boolean emit_dph(struct svga_shader_emitter *emit, return TRUE; } -/* Translate the following TGSI DST instruction. + +/** + * Translate the following TGSI DST instruction. * NRM DST, SRC * To the following SVGA3D instruction sequence. * DP3 TMP, SRC, SRC * RSQ TMP, TMP * MUL DST, SRC, TMP */ -static boolean emit_nrm(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_nrm(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); - const struct src_register src0 = translate_src_register( - emit, &insn->Src[0] ); + const struct src_register src0 = + translate_src_register(emit, &insn->Src[0]); SVGA3dShaderDestToken temp = get_temp( emit ); /* DP3 TMP, SRC, SRC */ @@ -1028,23 +1094,25 @@ static boolean emit_nrm(struct svga_shader_emitter *emit, return FALSE; return TRUE; - } -static boolean do_emit_sincos(struct svga_shader_emitter *emit, - SVGA3dShaderDestToken dst, - struct src_register src0) + +static boolean +do_emit_sincos(struct svga_shader_emitter *emit, + SVGA3dShaderDestToken dst, + struct src_register src0) { src0 = scalar(src0, TGSI_SWIZZLE_X); return submit_op1(emit, inst_token(SVGA3DOP_SINCOS), dst, src0); } -static boolean emit_sincos(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) + +static boolean +emit_sincos(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); - struct src_register src0 = translate_src_register( - emit, &insn->Src[0] ); + struct src_register src0 = translate_src_register(emit, &insn->Src[0]); SVGA3dShaderDestToken temp = get_temp( emit ); /* SCS TMP SRC */ @@ -1058,16 +1126,18 @@ static boolean emit_sincos(struct svga_shader_emitter *emit, return TRUE; } -/* + +/** * SCS TMP SRC * MOV DST TMP.yyyy */ -static boolean emit_sin(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_sin(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); - struct src_register src0 = translate_src_register( - emit, &insn->Src[0] ); + struct src_register src0 = + translate_src_register(emit, &insn->Src[0] ); SVGA3dShaderDestToken temp = get_temp( emit ); /* SCS TMP SRC */ @@ -1087,12 +1157,13 @@ static boolean emit_sin(struct svga_shader_emitter *emit, * SCS TMP SRC * MOV DST TMP.xxxx */ -static boolean emit_cos(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_cos(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); - struct src_register src0 = translate_src_register( - emit, &insn->Src[0] ); + struct src_register src0 = + translate_src_register(emit, &insn->Src[0] ); SVGA3dShaderDestToken temp = get_temp( emit ); /* SCS TMP SRC */ @@ -1108,12 +1179,14 @@ static boolean emit_cos(struct svga_shader_emitter *emit, return TRUE; } -static boolean emit_ssg(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) + +static boolean +emit_ssg(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); - struct src_register src0 = translate_src_register( - emit, &insn->Src[0] ); + struct src_register src0 = + translate_src_register(emit, &insn->Src[0] ); SVGA3dShaderDestToken temp0 = get_temp( emit ); SVGA3dShaderDestToken temp1 = get_temp( emit ); struct src_register zero, one; @@ -1144,11 +1217,13 @@ static boolean emit_ssg(struct svga_shader_emitter *emit, src( temp1 ) ); } -/* + +/** * ADD DST SRC0, negate(SRC0) */ -static boolean emit_sub(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) +static boolean +emit_sub(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); struct src_register src0 = translate_src_register( @@ -1166,8 +1241,9 @@ static boolean emit_sub(struct svga_shader_emitter *emit, } -static boolean emit_kil(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_kil(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { const struct tgsi_full_src_register *reg = &insn->Src[0]; struct src_register src0, srcIn; @@ -1222,17 +1298,17 @@ static boolean emit_kil(struct svga_shader_emitter *emit, } -/* mesa state tracker always emits kilp as an unconditional - * kil */ -static boolean emit_kilp(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +/** + * mesa state tracker always emits kilp as an unconditional kil + */ +static boolean +emit_kilp(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { - SVGA3dShaderInstToken inst; SVGA3dShaderDestToken temp; struct src_register one = scalar( get_zero_immediate( emit ), TGSI_SWIZZLE_W ); - - inst = inst_token( SVGA3DOP_TEXKILL ); + SVGA3dShaderInstToken inst = inst_token( SVGA3DOP_TEXKILL ); /* texkill doesn't allow negation on the operand so lets move * negation of {1} to a temp register */ @@ -1369,7 +1445,6 @@ emit_select(struct svga_shader_emitter *emit, } } - /* Otherwise, need to use the setp approach: */ { @@ -1390,9 +1465,10 @@ emit_select(struct svga_shader_emitter *emit, } -static boolean emit_select_op(struct svga_shader_emitter *emit, - unsigned compare, - const struct tgsi_full_instruction *insn) +static boolean +emit_select_op(struct svga_shader_emitter *emit, + unsigned compare, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); struct src_register src0 = translate_src_register( @@ -1440,11 +1516,13 @@ emit_cmp(struct svga_shader_emitter *emit, } -/* Translate texture instructions to SVGA3D representation. +/** + * Translate texture instructions to SVGA3D representation. */ -static boolean emit_tex2(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn, - SVGA3dShaderDestToken dst ) +static boolean +emit_tex2(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn, + SVGA3dShaderDestToken dst) { SVGA3dShaderInstToken inst; struct src_register texcoord; @@ -1523,13 +1601,13 @@ static boolean emit_tex2(struct svga_shader_emitter *emit, } - - -/* Translate texture instructions to SVGA3D representation. +/** + * Translate texture instructions to SVGA3D representation. */ -static boolean emit_tex4(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn, - SVGA3dShaderDestToken dst ) +static boolean +emit_tex4(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn, + SVGA3dShaderDestToken dst ) { SVGA3dShaderInstToken inst; struct src_register texcoord; @@ -1560,13 +1638,14 @@ static boolean emit_tex4(struct svga_shader_emitter *emit, /** * Emit texture swizzle code. */ -static boolean emit_tex_swizzle( struct svga_shader_emitter *emit, - SVGA3dShaderDestToken dst, - struct src_register src, - unsigned swizzle_x, - unsigned swizzle_y, - unsigned swizzle_z, - unsigned swizzle_w) +static boolean +emit_tex_swizzle(struct svga_shader_emitter *emit, + SVGA3dShaderDestToken dst, + struct src_register src, + unsigned swizzle_x, + unsigned swizzle_y, + unsigned swizzle_z, + unsigned swizzle_w) { const unsigned swizzleIn[4] = {swizzle_x, swizzle_y, swizzle_z, swizzle_w}; unsigned srcSwizzle[4]; @@ -1624,8 +1703,9 @@ static boolean emit_tex_swizzle( struct svga_shader_emitter *emit, } -static boolean emit_tex(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_tex(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); @@ -1748,8 +1828,10 @@ static boolean emit_tex(struct svga_shader_emitter *emit, return TRUE; } -static boolean emit_bgnloop2( struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) + +static boolean +emit_bgnloop2(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderInstToken inst = inst_token( SVGA3DOP_LOOP ); struct src_register loop_reg = src_register( SVGA3DREG_LOOP, 0 ); @@ -1762,8 +1844,10 @@ static boolean emit_bgnloop2( struct svga_shader_emitter *emit, emit_src( emit, const_int ) ); } -static boolean emit_endloop2( struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) + +static boolean +emit_endloop2(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderInstToken inst = inst_token( SVGA3DOP_ENDLOOP ); @@ -1772,16 +1856,20 @@ static boolean emit_endloop2( struct svga_shader_emitter *emit, return emit_instruction( emit, inst ); } -static boolean emit_brk( struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) + +static boolean +emit_brk(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderInstToken inst = inst_token( SVGA3DOP_BREAK ); return emit_instruction( emit, inst ); } -static boolean emit_scalar_op1( struct svga_shader_emitter *emit, - unsigned opcode, - const struct tgsi_full_instruction *insn ) + +static boolean +emit_scalar_op1(struct svga_shader_emitter *emit, + unsigned opcode, + const struct tgsi_full_instruction *insn) { SVGA3dShaderInstToken inst; SVGA3dShaderDestToken dst; @@ -1796,9 +1884,10 @@ static boolean emit_scalar_op1( struct svga_shader_emitter *emit, } -static boolean emit_simple_instruction(struct svga_shader_emitter *emit, - unsigned opcode, - const struct tgsi_full_instruction *insn ) +static boolean +emit_simple_instruction(struct svga_shader_emitter *emit, + unsigned opcode, + const struct tgsi_full_instruction *insn) { const struct tgsi_full_src_register *src = insn->Src; SVGA3dShaderInstToken inst; @@ -1829,8 +1918,9 @@ static boolean emit_simple_instruction(struct svga_shader_emitter *emit, } -static boolean emit_deriv(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_deriv(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn ) { if (emit->dynamic_branching_level > 0 && insn->Src[0].Register.File == TGSI_FILE_TEMPORARY) @@ -1886,8 +1976,10 @@ static boolean emit_deriv(struct svga_shader_emitter *emit, } } -static boolean emit_arl(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) + +static boolean +emit_arl(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { ++emit->current_arl; if (emit->unit == PIPE_SHADER_FRAGMENT) { @@ -1906,8 +1998,10 @@ static boolean emit_arl(struct svga_shader_emitter *emit, } } -static boolean emit_pow(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) + +static boolean +emit_pow(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); struct src_register src0 = translate_src_register( @@ -1929,20 +2023,24 @@ static boolean emit_pow(struct svga_shader_emitter *emit, src1 = scalar( src1, TGSI_SWIZZLE_X ); if (need_tmp) { - SVGA3dShaderDestToken tmp = writemask(get_temp( emit ), TGSI_WRITEMASK_X ); + SVGA3dShaderDestToken tmp = + writemask(get_temp( emit ), TGSI_WRITEMASK_X ); if (!submit_op2(emit, inst_token( SVGA3DOP_POW ), tmp, src0, src1)) return FALSE; - return submit_op1(emit, inst_token( SVGA3DOP_MOV ), dst, scalar(src(tmp), 0) ); + return submit_op1(emit, inst_token( SVGA3DOP_MOV ), + dst, scalar(src(tmp), 0) ); } else { return submit_op2(emit, inst_token( SVGA3DOP_POW ), dst, src0, src1); } } -static boolean emit_xpd(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) + +static boolean +emit_xpd(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); const struct src_register src0 = translate_src_register( @@ -1994,8 +2092,9 @@ static boolean emit_xpd(struct svga_shader_emitter *emit, } -static boolean emit_lrp(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) +static boolean +emit_lrp(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); const struct src_register src0 = translate_src_register( @@ -2009,8 +2108,9 @@ static boolean emit_lrp(struct svga_shader_emitter *emit, } -static boolean emit_dst_insn(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_dst_insn(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { if (emit->unit == PIPE_SHADER_VERTEX) { /* SVGA/DX9 has a DST instruction, but only for vertex shaders: @@ -2018,13 +2118,11 @@ static boolean emit_dst_insn(struct svga_shader_emitter *emit, return emit_simple_instruction(emit, SVGA3DOP_DST, insn); } else { - /* result[0] = 1 * 1; * result[1] = a[1] * b[1]; * result[2] = a[2] * 1; * result[3] = 1 * b[3]; */ - SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); SVGA3dShaderDestToken tmp; const struct src_register src0 = translate_src_register( @@ -2088,8 +2186,9 @@ static boolean emit_dst_insn(struct svga_shader_emitter *emit, } -static boolean emit_exp(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) +static boolean +emit_exp(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); struct src_register src0 = @@ -2152,8 +2251,10 @@ static boolean emit_exp(struct svga_shader_emitter *emit, return TRUE; } -static boolean emit_lit(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) + +static boolean +emit_lit(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { if (emit->unit == PIPE_SHADER_VERTEX) { /* SVGA/DX9 has a LIT instruction, but only for vertex shaders: @@ -2255,8 +2356,9 @@ static boolean emit_lit(struct svga_shader_emitter *emit, } -static boolean emit_ex2( struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) +static boolean +emit_ex2(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderInstToken inst; SVGA3dShaderDestToken dst; @@ -2282,8 +2384,9 @@ static boolean emit_ex2( struct svga_shader_emitter *emit, } -static boolean emit_log(struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn) +static boolean +emit_log(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { SVGA3dShaderDestToken dst = translate_dst_register( emit, insn, 0 ); struct src_register src0 = @@ -2462,9 +2565,10 @@ emit_trunc_round(struct svga_shader_emitter *emit, } -static boolean emit_bgnsub( struct svga_shader_emitter *emit, - unsigned position, - const struct tgsi_full_instruction *insn ) +static boolean +emit_bgnsub(struct svga_shader_emitter *emit, + unsigned position, + const struct tgsi_full_instruction *insn) { unsigned i; @@ -2486,8 +2590,10 @@ static boolean emit_bgnsub( struct svga_shader_emitter *emit, return TRUE; } -static boolean emit_call( struct svga_shader_emitter *emit, - const struct tgsi_full_instruction *insn ) + +static boolean +emit_call(struct svga_shader_emitter *emit, + const struct tgsi_full_instruction *insn) { unsigned position = insn->Label.Label; unsigned i; @@ -2510,7 +2616,12 @@ static boolean emit_call( struct svga_shader_emitter *emit, } -static boolean emit_end( struct svga_shader_emitter *emit ) +/** + * Called at the end of the shader. Actually, emit special "fix-up" + * code for the vertex/fragment shader. + */ +static boolean +emit_end(struct svga_shader_emitter *emit) { if (emit->unit == PIPE_SHADER_VERTEX) { return emit_vs_postamble( emit ); @@ -2522,9 +2633,10 @@ static boolean emit_end( struct svga_shader_emitter *emit ) -static boolean svga_emit_instruction( struct svga_shader_emitter *emit, - unsigned position, - const struct tgsi_full_instruction *insn ) +static boolean +svga_emit_instruction(struct svga_shader_emitter *emit, + unsigned position, + const struct tgsi_full_instruction *insn) { switch (insn->Instruction.Opcode) { @@ -2692,23 +2804,25 @@ static boolean svga_emit_instruction( struct svga_shader_emitter *emit, case TGSI_OPCODE_SSG: return emit_ssg( emit, insn ); - default: { - unsigned opcode = translate_opcode(insn->Instruction.Opcode); + default: + { + unsigned opcode = translate_opcode(insn->Instruction.Opcode); - if (opcode == SVGA3DOP_LAST_INST) - return FALSE; + if (opcode == SVGA3DOP_LAST_INST) + return FALSE; - if (!emit_simple_instruction( emit, opcode, insn )) - return FALSE; - } + if (!emit_simple_instruction( emit, opcode, insn )) + return FALSE; + } } return TRUE; } -static boolean svga_emit_immediate( struct svga_shader_emitter *emit, - struct tgsi_full_immediate *imm) +static boolean +svga_emit_immediate(struct svga_shader_emitter *emit, + struct tgsi_full_immediate *imm) { static const float id[4] = {0,0,0,1}; float value[4]; @@ -2728,12 +2842,11 @@ static boolean svga_emit_immediate( struct svga_shader_emitter *emit, value[0], value[1], value[2], value[3]); } -static boolean make_immediate( struct svga_shader_emitter *emit, - float a, - float b, - float c, - float d, - struct src_register *out ) + +static boolean +make_immediate(struct svga_shader_emitter *emit, + float a, float b, float c, float d, + struct src_register *out ) { unsigned idx = emit->nr_hw_float_const++; @@ -2746,7 +2859,9 @@ static boolean make_immediate( struct svga_shader_emitter *emit, return TRUE; } -static boolean emit_vs_preamble( struct svga_shader_emitter *emit ) + +static boolean +emit_vs_preamble(struct svga_shader_emitter *emit) { if (!emit->key.vkey.need_prescale) { if (!make_immediate( emit, 0, 0, .5, .5, @@ -2757,7 +2872,9 @@ static boolean emit_vs_preamble( struct svga_shader_emitter *emit ) return TRUE; } -static boolean emit_ps_preamble( struct svga_shader_emitter *emit ) + +static boolean +emit_ps_preamble(struct svga_shader_emitter *emit) { if (emit->ps_reads_pos && emit->info.reads_z) { /* @@ -2792,7 +2909,9 @@ static boolean emit_ps_preamble( struct svga_shader_emitter *emit ) return TRUE; } -static boolean emit_ps_postamble( struct svga_shader_emitter *emit ) + +static boolean +emit_ps_postamble(struct svga_shader_emitter *emit) { unsigned i; @@ -2802,7 +2921,6 @@ static boolean emit_ps_postamble( struct svga_shader_emitter *emit ) * oDepth with a hand-crafted MOV below. */ if (SVGA3dShaderGetRegType(emit->true_pos.value) != 0) { - if (!submit_op1( emit, inst_token(SVGA3DOP_MOV), emit->true_pos, @@ -2812,13 +2930,11 @@ static boolean emit_ps_postamble( struct svga_shader_emitter *emit ) for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { if (SVGA3dShaderGetRegType(emit->true_col[i].value) != 0) { - /* Potentially override output colors with white for XOR * logicop workaround. */ if (emit->unit == PIPE_SHADER_FRAGMENT && emit->key.fkey.white_fragments) { - struct src_register one = scalar( get_zero_immediate( emit ), TGSI_SWIZZLE_W ); @@ -2841,7 +2957,9 @@ static boolean emit_ps_postamble( struct svga_shader_emitter *emit ) return TRUE; } -static boolean emit_vs_postamble( struct svga_shader_emitter *emit ) + +static boolean +emit_vs_postamble(struct svga_shader_emitter *emit) { /* PSIZ output is incredibly fragile and it's very hard to catch * the types of usage that break it during shader emit. Easier @@ -2938,20 +3056,25 @@ static boolean emit_vs_postamble( struct svga_shader_emitter *emit ) return TRUE; } -/* - 0: IF VFACE :4 - 1: COLOR = FrontColor; - 2: ELSE - 3: COLOR = BackColor; - 4: ENDIF + +/** + * For the pixel shader: emit the code which chooses the front + * or back face color depending on triangle orientation. + * + * 0: IF VFACE :4 + * 1: COLOR = FrontColor; + * 2: ELSE + * 3: COLOR = BackColor; + * 4: ENDIF */ -static boolean emit_light_twoside( struct svga_shader_emitter *emit ) +static boolean +emit_light_twoside(struct svga_shader_emitter *emit) { struct src_register vface, zero; struct src_register front[2]; struct src_register back[2]; SVGA3dShaderDestToken color[2]; - int count = emit->internal_color_count; + int count = emit->internal_color_count; int i; SVGA3dShaderInstToken if_token; @@ -3012,11 +3135,13 @@ static boolean emit_light_twoside( struct svga_shader_emitter *emit ) return TRUE; } -/* - 0: SETP_GT TEMP, VFACE, 0 - where TEMP is a fake frontface register + +/** + * 0: SETP_GT TEMP, VFACE, 0 + * where TEMP is a fake frontface register */ -static boolean emit_frontface( struct svga_shader_emitter *emit ) +static boolean +emit_frontface(struct svga_shader_emitter *emit) { struct src_register vface, zero; SVGA3dShaderDestToken temp; @@ -3058,7 +3183,8 @@ static boolean emit_frontface( struct svga_shader_emitter *emit ) * This is used for drawing point sprites when * pipe_rasterizer_state::sprite_coord_mode == PIPE_SPRITE_COORD_LOWER_LEFT. */ -static boolean emit_inverted_texcoords( struct svga_shader_emitter *emit ) +static boolean +emit_inverted_texcoords(struct svga_shader_emitter *emit) { struct src_register zero = get_zero_immediate(emit); struct src_register pos_neg_one = get_pos_neg_one_immediate( emit ); @@ -3096,7 +3222,7 @@ static boolean emit_inverted_texcoords( struct svga_shader_emitter *emit ) } -static INLINE boolean +static boolean needs_to_create_zero( struct svga_shader_emitter *emit ) { unsigned i; @@ -3129,7 +3255,8 @@ needs_to_create_zero( struct svga_shader_emitter *emit ) } for (i = 0; i < emit->key.fkey.num_textures; i++) { - if (emit->key.fkey.tex[i].compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) + if (emit->key.fkey.tex[i].compare_mode + == PIPE_TEX_COMPARE_R_TO_TEXTURE) return TRUE; } } @@ -3159,19 +3286,22 @@ needs_to_create_zero( struct svga_shader_emitter *emit ) return FALSE; } -static INLINE boolean + +static boolean needs_to_create_loop_const( struct svga_shader_emitter *emit ) { return (emit->info.opcode_count[TGSI_OPCODE_BGNLOOP] >= 1); } -static INLINE boolean + +static boolean needs_to_create_arl_consts( struct svga_shader_emitter *emit ) { return (emit->num_arl_consts > 0); } -static INLINE boolean + +static boolean pre_parse_add_indirect( struct svga_shader_emitter *emit, int num, int current_arl) { @@ -3193,6 +3323,7 @@ pre_parse_add_indirect( struct svga_shader_emitter *emit, return TRUE; } + static boolean pre_parse_instruction( struct svga_shader_emitter *emit, const struct tgsi_full_instruction *insn, @@ -3225,6 +3356,7 @@ pre_parse_instruction( struct svga_shader_emitter *emit, return TRUE; } + static boolean pre_parse_tokens( struct svga_shader_emitter *emit, const struct tgsi_token *tokens ) @@ -3257,8 +3389,9 @@ pre_parse_tokens( struct svga_shader_emitter *emit, return TRUE; } -static boolean svga_shader_emit_helpers( struct svga_shader_emitter *emit ) +static boolean +svga_shader_emit_helpers(struct svga_shader_emitter *emit) { if (needs_to_create_zero( emit )) { create_zero_immediate( emit ); @@ -3291,8 +3424,10 @@ static boolean svga_shader_emit_helpers( struct svga_shader_emitter *emit ) return TRUE; } -boolean svga_shader_emit_instructions( struct svga_shader_emitter *emit, - const struct tgsi_token *tokens ) + +boolean +svga_shader_emit_instructions(struct svga_shader_emitter *emit, + const struct tgsi_token *tokens) { struct tgsi_parse_context parse; boolean ret = TRUE;