brw_vs_constval.c revision 064ae479a770bf434958d673baf6f7530f642697
19f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* 29f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Copyright (C) Intel Corp. 2006. All Rights Reserved. 39f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to 49f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt develop this 3D driver. 59f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 69f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Permission is hereby granted, free of charge, to any person obtaining 79f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt a copy of this software and associated documentation files (the 89f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt "Software"), to deal in the Software without restriction, including 99f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt without limitation the rights to use, copy, modify, merge, publish, 109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt distribute, sublicense, and/or sell copies of the Software, and to 119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt permit persons to whom the Software is furnished to do so, subject to 129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt the following conditions: 139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt The above copyright notice and this permission notice (including the 159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt next paragraph) shall be included in all copies or substantial 169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt portions of the Software. 179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt **********************************************************************/ 279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* 289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * Authors: 299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * Keith Whitwell <keith@tungstengraphics.com> 309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "macros.h" 34064ae479a770bf434958d673baf6f7530f642697Brian#include "brw_context.h" 359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_vs.h" 369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* Component is active if it may diverge from [0,0,0,1]. Undef values 389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * are promoted to [0,0,0,1] for the purposes of this analysis. 399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstruct tracker { 419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLboolean twoside; 429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLubyte active[PROGRAM_OUTPUT+1][128]; 439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint size_masks[4]; 449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}; 459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void set_active_component( struct tracker *t, 489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint file, 499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint index, 509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLubyte active ) 519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt switch (file) { 539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case PROGRAM_TEMPORARY: 549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case PROGRAM_INPUT: 559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case PROGRAM_OUTPUT: 569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt t->active[file][index] |= active; 579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void set_active( struct tracker *t, 649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct prog_dst_register dst, 659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint active ) 669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt set_active_component( t, dst.File, dst.Index, active & dst.WriteMask ); 689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic GLubyte get_active_component( struct tracker *t, 729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint file, 739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint index, 749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint component, 759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLubyte swz ) 769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt switch (swz) { 789f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case SWIZZLE_ZERO: 799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return component < 3 ? 0 : (1<<component); 809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case SWIZZLE_ONE: 819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return component == 3 ? 0 : (1<<component); 829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt switch (file) { 849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case PROGRAM_TEMPORARY: 859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case PROGRAM_INPUT: 869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case PROGRAM_OUTPUT: 879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return t->active[file][index] & (1<<component); 889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return 1 << component; 909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 929f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic GLubyte get_active( struct tracker *t, 969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct prog_src_register src ) 979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint i; 999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLubyte active = src.NegateBase; /* NOTE! */ 1009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (src.RelAddr) 1029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return 0xf; 1039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt for (i = 0; i < 4; i++) 1059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt active |= get_active_component(t, src.File, src.Index, i, 1069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GET_SWZ(src.Swizzle, i)); 1079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return active; 1099f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 1109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic GLubyte get_output_size( struct tracker *t, 1129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint idx ) 1139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 1149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLubyte active = t->active[PROGRAM_OUTPUT][idx]; 1159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (active & (1<<3)) return 4; 1169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (active & (1<<2)) return 3; 1179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (active & (1<<1)) return 2; 1189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (active & (1<<0)) return 1; 1199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return 0; 1209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 1219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* Note the potential copying that occurs in the setup program: 1239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 1249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void calc_sizes( struct tracker *t ) 1259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 1269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint i; 1279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (t->twoside) { 1299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt t->active[PROGRAM_OUTPUT][VERT_RESULT_COL0] |= 1309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt t->active[PROGRAM_OUTPUT][VERT_RESULT_BFC0]; 1319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt t->active[PROGRAM_OUTPUT][VERT_RESULT_COL1] |= 1339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt t->active[PROGRAM_OUTPUT][VERT_RESULT_BFC1]; 1349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt for (i = 0; i < FRAG_ATTRIB_MAX; i++) { 1379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt switch (get_output_size(t, i)) { 1389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case 4: t->size_masks[4-1] |= 1<<i; 1399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case 3: t->size_masks[3-1] |= 1<<i; 1409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case 2: t->size_masks[2-1] |= 1<<i; 1419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case 1: t->size_masks[1-1] |= 1<<i; 1429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 1459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 1469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic GLubyte szflag[4+1] = { 1489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 0, 1499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 0x1, 1509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 0x3, 1519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 0x7, 1529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 0xf 1539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}; 1549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* Pull a size out of the packed array: 1569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 1579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic GLuint get_input_size(struct brw_context *brw, 1589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint attr) 1599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 1609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint sizes_dword = brw->vb.info.sizes[attr/16]; 1619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint sizes_bits = (sizes_dword>>((attr%16)*2)) & 0x3; 1629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return sizes_bits + 1; 163f2eb6434ab1cf72e938956c82d2f530368a6be4aKeith Whitwell/* return brw->vb.inputs[attr].glarray->Size; */ 1649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 1659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/* Calculate sizes of vertex program outputs. Size is the largest 1679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt * component index which might vary from [0,0,0,1] 1689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 1699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void calc_wm_input_sizes( struct brw_context *brw ) 1709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 1719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* BRW_NEW_VERTEX_PROGRAM */ 1729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct brw_vertex_program *vp = 1739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt (struct brw_vertex_program *)brw->vertex_program; 1749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* BRW_NEW_INPUT_DIMENSIONS */ 1759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct tracker t; 1769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint insn; 1779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint i; 1789f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt memset(&t, 0, sizeof(t)); 1809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_LIGHT */ 1829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (brw->attribs.Light->Model.TwoSide) 1839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt t.twoside = 1; 1849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 185f2eb6434ab1cf72e938956c82d2f530368a6be4aKeith Whitwell for (i = 0; i < VERT_ATTRIB_MAX; i++) 186f2eb6434ab1cf72e938956c82d2f530368a6be4aKeith Whitwell if (vp->program.Base.InputsRead & (1<<i)) 1879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt set_active_component(&t, PROGRAM_INPUT, i, 1889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt szflag[get_input_size(brw, i)]); 1899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt for (insn = 0; insn < vp->program.Base.NumInstructions; insn++) { 1919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct prog_instruction *inst = &vp->program.Base.Instructions[insn]; 1929f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt switch (inst->Opcode) { 1949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_ARL: 1959f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 1969f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 1979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_MOV: 1989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt set_active(&t, inst->DstReg, get_active(&t, inst->SrcReg[0])); 1999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2019f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 2029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt set_active(&t, inst->DstReg, 0xf); 2039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt break; 2049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt calc_sizes(&t); 2089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2099f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (memcmp(brw->wm.input_size_masks, t.size_masks, sizeof(t.size_masks)) != 0) { 2109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt memcpy(brw->wm.input_size_masks, t.size_masks, sizeof(t.size_masks)); 2119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt brw->state.dirty.brw |= BRW_NEW_WM_INPUT_DIMENSIONS; 2129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 2149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_wm_input_sizes = { 2169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .dirty = { 2179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .mesa = _NEW_LIGHT, 2189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .brw = BRW_NEW_VERTEX_PROGRAM | BRW_NEW_INPUT_DIMENSIONS, 2199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .cache = 0 2209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt }, 2219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .update = calc_wm_input_sizes 2229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}; 2239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 224