⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 brw_vs_emit.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 3 页
字号:
/* Copyright (C) Intel Corp.  2006.  All Rights Reserved. Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to develop this 3D driver.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  **********************************************************************/ /*  * Authors:  *   Keith Whitwell <keith@tungstengraphics.com>  */            #include "main/macros.h"#include "shader/program.h"#include "shader/prog_parameter.h"#include "shader/prog_print.h"#include "brw_context.h"#include "brw_vs.h"/* Do things as simply as possible.  Allocate and populate all regs * ahead of time. */static void brw_vs_alloc_regs( struct brw_vs_compile *c ){   GLuint i, reg = 0, mrf;   GLuint nr_params;   /* r0 -- reserved as usual    */   c->r0 = brw_vec8_grf(reg, 0); reg++;   /* User clip planes from curbe:     */   if (c->key.nr_userclip) {      for (i = 0; i < c->key.nr_userclip; i++) {	 c->userplane[i] = stride( brw_vec4_grf(reg+3+i/2, (i%2) * 4), 0, 4, 1);      }           /* Deal with curbe alignment:       */      reg += ((6+c->key.nr_userclip+3)/4)*2;   }   /* Vertex program parameters from curbe:    */   nr_params = c->vp->program.Base.Parameters->NumParameters;   for (i = 0; i < nr_params; i++) {      c->regs[PROGRAM_STATE_VAR][i] = stride( brw_vec4_grf(reg+i/2, (i%2) * 4), 0, 4, 1);   }        reg += (nr_params+1)/2;   c->prog_data.curb_read_length = reg - 1;   /* Allocate input regs:      */   c->nr_inputs = 0;   for (i = 0; i < VERT_ATTRIB_MAX; i++) {      if (c->prog_data.inputs_read & (1<<i)) {	 c->nr_inputs++;	 c->regs[PROGRAM_INPUT][i] = brw_vec8_grf(reg, 0);	 reg++;      }   }        /* Allocate outputs: TODO: could organize the non-position outputs    * to go straight into message regs.    */   c->nr_outputs = 0;   c->first_output = reg;   mrf = 4;   for (i = 0; i < VERT_RESULT_MAX; i++) {      if (c->prog_data.outputs_written & (1<<i)) {	 c->nr_outputs++;	 if (i == VERT_RESULT_HPOS) {	    c->regs[PROGRAM_OUTPUT][i] = brw_vec8_grf(reg, 0);	    reg++;	 }	 else if (i == VERT_RESULT_PSIZ) {	    c->regs[PROGRAM_OUTPUT][i] = brw_vec8_grf(reg, 0);	    reg++;	    mrf++;		/* just a placeholder?  XXX fix later stages & remove this */	 }	 else {	    c->regs[PROGRAM_OUTPUT][i] = brw_message_reg(mrf);	    mrf++;	 }      }   }        /* Allocate program temporaries:    */   for (i = 0; i < c->vp->program.Base.NumTemporaries; i++) {      c->regs[PROGRAM_TEMPORARY][i] = brw_vec8_grf(reg, 0);      reg++;   }   /* Address reg(s).  Don't try to use the internal address reg until    * deref time.    */   for (i = 0; i < c->vp->program.Base.NumAddressRegs; i++) {      c->regs[PROGRAM_ADDRESS][i] =  brw_reg(BRW_GENERAL_REGISTER_FILE,					     reg,					     0,					     BRW_REGISTER_TYPE_D,					     BRW_VERTICAL_STRIDE_8,					     BRW_WIDTH_8,					     BRW_HORIZONTAL_STRIDE_1,					     BRW_SWIZZLE_XXXX,					     WRITEMASK_X);      reg++;   }   for (i = 0; i < 128; i++) {       if (c->output_regs[i].used_in_src) {            c->output_regs[i].reg = brw_vec8_grf(reg, 0);            reg++;        }   }   c->stack =  brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, reg, 0);   reg += 2;       /* Some opcodes need an internal temporary:    */   c->first_tmp = reg;   c->last_tmp = reg;		/* for allocation purposes */   /* Each input reg holds data from two vertices.  The    * urb_read_length is the number of registers read from *each*    * vertex urb, so is half the amount:    */   c->prog_data.urb_read_length = (c->nr_inputs+1)/2;   c->prog_data.urb_entry_size = (c->nr_outputs+2+3)/4;   c->prog_data.total_grf = reg;}static struct brw_reg get_tmp( struct brw_vs_compile *c ){   struct brw_reg tmp = brw_vec8_grf(c->last_tmp, 0);   if (++c->last_tmp > c->prog_data.total_grf)      c->prog_data.total_grf = c->last_tmp;   return tmp;}static void release_tmp( struct brw_vs_compile *c, struct brw_reg tmp ){   if (tmp.nr == c->last_tmp-1)      c->last_tmp--;}			       static void release_tmps( struct brw_vs_compile *c ){   c->last_tmp = c->first_tmp;}static void unalias1( struct brw_vs_compile *c,		      struct brw_reg dst,		      struct brw_reg arg0,		      void (*func)( struct brw_vs_compile *,				    struct brw_reg,				    struct brw_reg )){   if (dst.file == arg0.file && dst.nr == arg0.nr) {      struct brw_compile *p = &c->func;      struct brw_reg tmp = brw_writemask(get_tmp(c), dst.dw1.bits.writemask);      func(c, tmp, arg0);      brw_MOV(p, dst, tmp);   }   else {      func(c, dst, arg0);   }}static void unalias2( struct brw_vs_compile *c,		      struct brw_reg dst,		      struct brw_reg arg0,		      struct brw_reg arg1,		      void (*func)( struct brw_vs_compile *,				    struct brw_reg,				    struct brw_reg,				    struct brw_reg )){   if ((dst.file == arg0.file && dst.nr == arg0.nr) ||       (dst.file == arg1.file && dst.nr == arg1.nr)) {      struct brw_compile *p = &c->func;      struct brw_reg tmp = brw_writemask(get_tmp(c), dst.dw1.bits.writemask);      func(c, tmp, arg0, arg1);      brw_MOV(p, dst, tmp);   }   else {      func(c, dst, arg0, arg1);   }}static void emit_sop( struct brw_compile *p,                      struct brw_reg dst,                      struct brw_reg arg0,                      struct brw_reg arg1, 		      GLuint cond){   brw_MOV(p, dst, brw_imm_f(0.0f));   brw_CMP(p, brw_null_reg(), cond, arg0, arg1);   brw_MOV(p, dst, brw_imm_f(1.0f));   brw_set_predicate_control_flag_value(p, 0xff);}static void emit_seq( struct brw_compile *p,                      struct brw_reg dst,                      struct brw_reg arg0,                      struct brw_reg arg1 ){   emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_EQ);}static void emit_sne( struct brw_compile *p,                      struct brw_reg dst,                      struct brw_reg arg0,                      struct brw_reg arg1 ){   emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_NEQ);}static void emit_slt( struct brw_compile *p, 		      struct brw_reg dst,		      struct brw_reg arg0,		      struct brw_reg arg1 ){   emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_L);}static void emit_sle( struct brw_compile *p, 		      struct brw_reg dst,		      struct brw_reg arg0,		      struct brw_reg arg1 ){   emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_LE);}static void emit_sgt( struct brw_compile *p, 		      struct brw_reg dst,		      struct brw_reg arg0,		      struct brw_reg arg1 ){   emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_G);}static void emit_sge( struct brw_compile *p, 		      struct brw_reg dst,		      struct brw_reg arg0,		      struct brw_reg arg1 ){  emit_sop(p, dst, arg0, arg1, BRW_CONDITIONAL_GE);}static void emit_max( struct brw_compile *p, 		      struct brw_reg dst,		      struct brw_reg arg0,		      struct brw_reg arg1 ){   brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_L, arg0, arg1);   brw_SEL(p, dst, arg1, arg0);   brw_set_predicate_control(p, BRW_PREDICATE_NONE);}static void emit_min( struct brw_compile *p, 		      struct brw_reg dst,		      struct brw_reg arg0,		      struct brw_reg arg1 ){   brw_CMP(p, brw_null_reg(), BRW_CONDITIONAL_L, arg0, arg1);   brw_SEL(p, dst, arg0, arg1);   brw_set_predicate_control(p, BRW_PREDICATE_NONE);}static void emit_math1( struct brw_vs_compile *c,			GLuint function,			struct brw_reg dst,			struct brw_reg arg0,			GLuint precision){   /* There are various odd behaviours with SEND on the simulator.  In    * addition there are documented issues with the fact that the GEN4    * processor doesn't do dependency control properly on SEND    * results.  So, on balance, this kludge to get around failures    * with writemasked math results looks like it might be necessary    * whether that turns out to be a simulator bug or not:    */   struct brw_compile *p = &c->func;   struct brw_reg tmp = dst;   GLboolean need_tmp = (dst.dw1.bits.writemask != 0xf ||			 dst.file != BRW_GENERAL_REGISTER_FILE);   if (need_tmp)       tmp = get_tmp(c);   brw_math(p, 	    tmp,	    function,	    BRW_MATH_SATURATE_NONE,	    2,	    arg0,	    BRW_MATH_DATA_SCALAR,	    precision);   if (need_tmp) {      brw_MOV(p, dst, tmp);      release_tmp(c, tmp);   }}static void emit_math2( struct brw_vs_compile *c, 			GLuint function,			struct brw_reg dst,			struct brw_reg arg0,			struct brw_reg arg1,			GLuint precision){   struct brw_compile *p = &c->func;   struct brw_reg tmp = dst;   GLboolean need_tmp = (dst.dw1.bits.writemask != 0xf ||			 dst.file != BRW_GENERAL_REGISTER_FILE);   if (need_tmp)       tmp = get_tmp(c);   brw_MOV(p, brw_message_reg(3), arg1);      brw_math(p, 	    tmp,	    function,	    BRW_MATH_SATURATE_NONE,	    2, 	    arg0,	    BRW_MATH_DATA_SCALAR,	    precision);   if (need_tmp) {      brw_MOV(p, dst, tmp);      release_tmp(c, tmp);   }}		     static void emit_exp_noalias( struct brw_vs_compile *c,			      struct brw_reg dst,			      struct brw_reg arg0 ){   struct brw_compile *p = &c->func;      if (dst.dw1.bits.writemask & WRITEMASK_X) {      struct brw_reg tmp = get_tmp(c);      struct brw_reg tmp_d = retype(tmp, BRW_REGISTER_TYPE_D);      /* tmp_d = floor(arg0.x) */      brw_RNDD(p, tmp_d, brw_swizzle1(arg0, 0));      /* result[0] = 2.0 ^ tmp */      /* Adjust exponent for floating point:        * exp += 127        */      brw_ADD(p, brw_writemask(tmp_d, WRITEMASK_X), tmp_d, brw_imm_d(127));      /* Install exponent and sign.         * Excess drops off the edge:        */      brw_SHL(p, brw_writemask(retype(dst, BRW_REGISTER_TYPE_D), WRITEMASK_X), 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -