📄 brw_wm_emit.c
字号:
/* 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 "macros.h"#include "brw_context.h"#include "brw_wm.h"#define SATURATE (1<<5)/* Not quite sure how correct this is - need to understand horiz * vs. vertical strides a little better. */static INLINE struct brw_reg sechalf( struct brw_reg reg ){ if (reg.vstride) reg.nr++; return reg;}/* Payload R0: * * R0.0 -- pixel mask, one bit for each of 4 pixels in 4 tiles, * corresponding to each of the 16 execution channels. * R0.1..8 -- ? * R1.0 -- triangle vertex 0.X * R1.1 -- triangle vertex 0.Y * R1.2 -- tile 0 x,y coords (2 packed uwords) * R1.3 -- tile 1 x,y coords (2 packed uwords) * R1.4 -- tile 2 x,y coords (2 packed uwords) * R1.5 -- tile 3 x,y coords (2 packed uwords) * R1.6 -- ? * R1.7 -- ? * R1.8 -- ? */static void emit_pixel_xy(struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0){ struct brw_reg r1 = brw_vec1_grf(1, 0); struct brw_reg r1_uw = retype(r1, BRW_REGISTER_TYPE_UW); brw_set_compression_control(p, BRW_COMPRESSION_NONE); /* Calculate pixel centers by adding 1 or 0 to each of the * micro-tile coordinates passed in r1. */ if (mask & WRITEMASK_X) { brw_ADD(p, vec16(retype(dst[0], BRW_REGISTER_TYPE_UW)), stride(suboffset(r1_uw, 4), 2, 4, 0), brw_imm_v(0x10101010)); } if (mask & WRITEMASK_Y) { brw_ADD(p, vec16(retype(dst[1], BRW_REGISTER_TYPE_UW)), stride(suboffset(r1_uw,5), 2, 4, 0), brw_imm_v(0x11001100)); } brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);}static void emit_delta_xy(struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *arg1){ struct brw_reg r1 = brw_vec1_grf(1, 0); /* Calc delta X,Y by subtracting origin in r1 from the pixel * centers. */ if (mask & WRITEMASK_X) { brw_ADD(p, dst[0], retype(arg0[0], BRW_REGISTER_TYPE_UW), negate(r1)); } if (mask & WRITEMASK_Y) { brw_ADD(p, dst[1], retype(arg0[1], BRW_REGISTER_TYPE_UW), negate(suboffset(r1,1))); }}static void emit_wpos_xy(struct brw_wm_compile *c, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0){ struct brw_compile *p = &c->func; /* Calculate the pixel offset from window bottom left into destination * X and Y channels. */ if (mask & WRITEMASK_X) { /* X' = X - origin */ brw_ADD(p, dst[0], retype(arg0[0], BRW_REGISTER_TYPE_W), brw_imm_d(0 - c->key.origin_x)); } if (mask & WRITEMASK_Y) { /* Y' = height - (Y - origin_y) = height + origin_y - Y */ brw_ADD(p, dst[1], negate(retype(arg0[1], BRW_REGISTER_TYPE_W)), brw_imm_d(c->key.origin_y + c->key.drawable_height - 1)); }}static void emit_pixel_w( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *deltas){ /* Don't need this if all you are doing is interpolating color, for * instance. */ if (mask & WRITEMASK_W) { struct brw_reg interp3 = brw_vec1_grf(arg0[0].nr+1, 4); /* Calc 1/w - just linterp wpos[3] optimized by putting the * result straight into a message reg. */ brw_LINE(p, brw_null_reg(), interp3, deltas[0]); brw_MAC(p, brw_message_reg(2), suboffset(interp3, 1), deltas[1]); /* Calc w */ brw_math_16( p, dst[3], BRW_MATH_FUNCTION_INV, BRW_MATH_SATURATE_NONE, 2, brw_null_reg(), BRW_MATH_PRECISION_FULL); }}static void emit_linterp( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *deltas ){ struct brw_reg interp[4]; GLuint nr = arg0[0].nr; GLuint i; interp[0] = brw_vec1_grf(nr, 0); interp[1] = brw_vec1_grf(nr, 4); interp[2] = brw_vec1_grf(nr+1, 0); interp[3] = brw_vec1_grf(nr+1, 4); for(i = 0; i < 4; i++ ) { if (mask & (1<<i)) { brw_LINE(p, brw_null_reg(), interp[i], deltas[0]); brw_MAC(p, dst[i], suboffset(interp[i],1), deltas[1]); } }}static void emit_pinterp( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *deltas, const struct brw_reg *w){ struct brw_reg interp[4]; GLuint nr = arg0[0].nr; GLuint i; interp[0] = brw_vec1_grf(nr, 0); interp[1] = brw_vec1_grf(nr, 4); interp[2] = brw_vec1_grf(nr+1, 0); interp[3] = brw_vec1_grf(nr+1, 4); for(i = 0; i < 4; i++ ) { if (mask & (1<<i)) { brw_LINE(p, brw_null_reg(), interp[i], deltas[0]); brw_MAC(p, dst[i], suboffset(interp[i],1), deltas[1]); } } for(i = 0; i < 4; i++ ) { if (mask & (1<<i)) { brw_MUL(p, dst[i], dst[i], w[3]); } }}static void emit_cinterp( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0 ){ struct brw_reg interp[4]; GLuint nr = arg0[0].nr; GLuint i; interp[0] = brw_vec1_grf(nr, 0); interp[1] = brw_vec1_grf(nr, 4); interp[2] = brw_vec1_grf(nr+1, 0); interp[3] = brw_vec1_grf(nr+1, 4); for(i = 0; i < 4; i++ ) { if (mask & (1<<i)) { brw_MOV(p, dst[i], suboffset(interp[i],3)); /* TODO: optimize away like other moves */ } }}static void emit_alu1( struct brw_compile *p, struct brw_instruction *(*func)(struct brw_compile *, struct brw_reg, struct brw_reg), const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0 ){ GLuint i; if (mask & SATURATE) brw_set_saturate(p, 1); for (i = 0; i < 4; i++) { if (mask & (1<<i)) { func(p, dst[i], arg0[i]); } } if (mask & SATURATE) brw_set_saturate(p, 0);}static void emit_alu2( struct brw_compile *p, struct brw_instruction *(*func)(struct brw_compile *, struct brw_reg, struct brw_reg, struct brw_reg), const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *arg1 ){ GLuint i; if (mask & SATURATE) brw_set_saturate(p, 1); for (i = 0; i < 4; i++) { if (mask & (1<<i)) { func(p, dst[i], arg0[i], arg1[i]); } } if (mask & SATURATE) brw_set_saturate(p, 0);}static void emit_mad( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *arg1, const struct brw_reg *arg2 ){ GLuint i; for (i = 0; i < 4; i++) { if (mask & (1<<i)) { brw_MUL(p, dst[i], arg0[i], arg1[i]); brw_set_saturate(p, (mask & SATURATE) ? 1 : 0); brw_ADD(p, dst[i], dst[i], arg2[i]); brw_set_saturate(p, 0); } }}static void emit_lrp( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *arg1, const struct brw_reg *arg2 ){ GLuint i; /* Uses dst as a temporary: */ for (i = 0; i < 4; i++) { if (mask & (1<<i)) { /* Can I use the LINE instruction for this? */ brw_ADD(p, dst[i], negate(arg0[i]), brw_imm_f(1.0)); brw_MUL(p, brw_null_reg(), dst[i], arg2[i]); brw_set_saturate(p, (mask & SATURATE) ? 1 : 0); brw_MAC(p, dst[i], arg0[i], arg1[i]); brw_set_saturate(p, 0); } }}static void emit_sop( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, GLuint cond, const struct brw_reg *arg0, const struct brw_reg *arg1 ){ GLuint i; for (i = 0; i < 4; i++) { if (mask & (1<<i)) { brw_MOV(p, dst[i], brw_imm_f(0)); brw_CMP(p, brw_null_reg(), cond, arg0[i], arg1[i]); brw_MOV(p, dst[i], brw_imm_f(1.0)); brw_set_predicate_control_flag_value(p, 0xff); } }}static void emit_slt( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *arg1 ){ emit_sop(p, dst, mask, BRW_CONDITIONAL_L, arg0, arg1);}static void emit_sle( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *arg1 ){ emit_sop(p, dst, mask, BRW_CONDITIONAL_LE, arg0, arg1);}static void emit_sgt( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *arg1 ){ emit_sop(p, dst, mask, BRW_CONDITIONAL_G, arg0, arg1);}static void emit_sge( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *arg1 ){ emit_sop(p, dst, mask, BRW_CONDITIONAL_GE, arg0, arg1);}static void emit_seq( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *arg1 ){ emit_sop(p, dst, mask, BRW_CONDITIONAL_EQ, arg0, arg1);}static void emit_sne( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *arg1 ){ emit_sop(p, dst, mask, BRW_CONDITIONAL_NEQ, arg0, arg1);}static void emit_cmp( struct brw_compile *p, const struct brw_reg *dst, GLuint mask, const struct brw_reg *arg0, const struct brw_reg *arg1, const struct brw_reg *arg2 ){ GLuint i; for (i = 0; i < 4; i++) { if (mask & (1<<i)) { brw_set_saturate(p, (mask & SATURATE) ? 1 : 0); brw_MOV(p, dst[i], arg2[i]); brw_set_saturate(p, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -