i915_state_derived.c revision 4901410293b35ac6bb4759142b50fcc0be8a1b25
101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell/************************************************************************** 201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * 301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * All Rights Reserved. 501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * 601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * copy of this software and associated documentation files (the 801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * "Software"), to deal in the Software without restriction, including 901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * without limitation the rights to use, copy, modify, merge, publish, 1001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * distribute, sub license, and/or sell copies of the Software, and to 1101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * permit persons to whom the Software is furnished to do so, subject to 1201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * the following conditions: 1301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * 1401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * The above copyright notice and this permission notice (including the 1501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * next paragraph) shall be included in all copies or substantial portions 1601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * of the Software. 1701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * 1801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 2101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 2201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 2301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 2401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * 2601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell **************************************************************************/ 2701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell 28d3eb25c575464bed7dbfc8be4717d85cb2928ec1Brian 29d3eb25c575464bed7dbfc8be4717d85cb2928ec1Brian#include "pipe/p_util.h" 30846b7fbc6c9cbd57eed01bd04b1da73109935091Brian#include "pipe/p_shader_tokens.h" 316acd63a4980951727939c0dd545a0324965b3834José Fonseca#include "draw/draw_context.h" 326acd63a4980951727939c0dd545a0324965b3834José Fonseca#include "draw/draw_vertex.h" 3301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell#include "i915_context.h" 3401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell#include "i915_state.h" 35c990d0fd57a05301429b3af75b7fed0337621941Brian#include "i915_reg.h" 366d88515190ed7500e201706cc14d30072ba42d6fBrian#include "i915_fpc.h" 37846b7fbc6c9cbd57eed01bd04b1da73109935091Brian 384ed87bf2291e4873e94cefe44ddf2b590b09cc42Brian 394ed87bf2291e4873e94cefe44ddf2b590b09cc42Brian 4001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell/** 41846b7fbc6c9cbd57eed01bd04b1da73109935091Brian * Determine the hardware vertex layout. 42846b7fbc6c9cbd57eed01bd04b1da73109935091Brian * Depends on vertex/fragment shader state. 4301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell */ 4401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellstatic void calculate_vertex_layout( struct i915_context *i915 ) 4501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{ 464901410293b35ac6bb4759142b50fcc0be8a1b25Brian const struct i915_fragment_shader *fs = i915->fs; 47a70c5e37f1c2e43738469e4799ad2b9e7c604782Zack Rusin const enum interp_mode colorInterp = i915->rasterizer->color_interp; 48f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian struct vertex_info vinfo; 49846b7fbc6c9cbd57eed01bd04b1da73109935091Brian boolean texCoords[8], colors[2], fog, needW; 5037cf13ed9a429c755f121daa1776b1b30a985ab3Brian uint i; 51846b7fbc6c9cbd57eed01bd04b1da73109935091Brian int src; 5201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell 5337cf13ed9a429c755f121daa1776b1b30a985ab3Brian memset(texCoords, 0, sizeof(texCoords)); 54846b7fbc6c9cbd57eed01bd04b1da73109935091Brian colors[0] = colors[1] = fog = needW = FALSE; 55f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian memset(&vinfo, 0, sizeof(vinfo)); 5601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell 57846b7fbc6c9cbd57eed01bd04b1da73109935091Brian /* Determine which fragment program inputs are needed. Setup HW vertex 58846b7fbc6c9cbd57eed01bd04b1da73109935091Brian * layout below, in the HW-specific attribute order. 59846b7fbc6c9cbd57eed01bd04b1da73109935091Brian */ 604901410293b35ac6bb4759142b50fcc0be8a1b25Brian for (i = 0; i < fs->info.num_inputs; i++) { 614901410293b35ac6bb4759142b50fcc0be8a1b25Brian switch (fs->info.input_semantic_name[i]) { 6237cf13ed9a429c755f121daa1776b1b30a985ab3Brian case TGSI_SEMANTIC_POSITION: 6337cf13ed9a429c755f121daa1776b1b30a985ab3Brian break; 64f69b5c56feb60791bad27d491ee9592238d4efb0Brian case TGSI_SEMANTIC_COLOR: 654901410293b35ac6bb4759142b50fcc0be8a1b25Brian assert(fs->info.input_semantic_index[i] < 2); 664901410293b35ac6bb4759142b50fcc0be8a1b25Brian colors[fs->info.input_semantic_index[i]] = TRUE; 6737cf13ed9a429c755f121daa1776b1b30a985ab3Brian break; 68e9259ad0d7f674a1f2f9156ba0baeedc0e7d0d54Brian case TGSI_SEMANTIC_GENERIC: 69e9259ad0d7f674a1f2f9156ba0baeedc0e7d0d54Brian /* usually a texcoord */ 7037cf13ed9a429c755f121daa1776b1b30a985ab3Brian { 714901410293b35ac6bb4759142b50fcc0be8a1b25Brian const uint unit = fs->info.input_semantic_index[i]; 72846b7fbc6c9cbd57eed01bd04b1da73109935091Brian assert(unit < 8); 7337cf13ed9a429c755f121daa1776b1b30a985ab3Brian texCoords[unit] = TRUE; 7437cf13ed9a429c755f121daa1776b1b30a985ab3Brian needW = TRUE; 7537cf13ed9a429c755f121daa1776b1b30a985ab3Brian } 7637cf13ed9a429c755f121daa1776b1b30a985ab3Brian break; 77726060680ba69aaec659f78e24f2db58acd780cbBrian case TGSI_SEMANTIC_FOG: 78846b7fbc6c9cbd57eed01bd04b1da73109935091Brian fog = TRUE; 79726060680ba69aaec659f78e24f2db58acd780cbBrian break; 8037cf13ed9a429c755f121daa1776b1b30a985ab3Brian default: 8137cf13ed9a429c755f121daa1776b1b30a985ab3Brian assert(0); 8237cf13ed9a429c755f121daa1776b1b30a985ab3Brian } 8337cf13ed9a429c755f121daa1776b1b30a985ab3Brian } 8437cf13ed9a429c755f121daa1776b1b30a985ab3Brian 85846b7fbc6c9cbd57eed01bd04b1da73109935091Brian 86846b7fbc6c9cbd57eed01bd04b1da73109935091Brian /* pos */ 87846b7fbc6c9cbd57eed01bd04b1da73109935091Brian src = draw_find_vs_output(i915->draw, TGSI_SEMANTIC_POSITION, 0); 886998402016e146d6afe06549ce2fb5941d6b03c7Brian if (needW) { 89846b7fbc6c9cbd57eed01bd04b1da73109935091Brian draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, src); 90f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian vinfo.hwfmt[0] |= S4_VFMT_XYZW; 912549d79ae5342a2b97c06e3b0db9da6eb7821d2eBrian vinfo.emit[0] = EMIT_4F; 926998402016e146d6afe06549ce2fb5941d6b03c7Brian } 936998402016e146d6afe06549ce2fb5941d6b03c7Brian else { 94846b7fbc6c9cbd57eed01bd04b1da73109935091Brian draw_emit_vertex_attr(&vinfo, EMIT_3F, INTERP_LINEAR, src); 95f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian vinfo.hwfmt[0] |= S4_VFMT_XYZ; 962549d79ae5342a2b97c06e3b0db9da6eb7821d2eBrian vinfo.emit[0] = EMIT_3F; 976998402016e146d6afe06549ce2fb5941d6b03c7Brian } 986998402016e146d6afe06549ce2fb5941d6b03c7Brian 99846b7fbc6c9cbd57eed01bd04b1da73109935091Brian /* hardware point size */ 100846b7fbc6c9cbd57eed01bd04b1da73109935091Brian /* XXX todo */ 101846b7fbc6c9cbd57eed01bd04b1da73109935091Brian 102846b7fbc6c9cbd57eed01bd04b1da73109935091Brian /* primary color */ 103846b7fbc6c9cbd57eed01bd04b1da73109935091Brian if (colors[0]) { 104846b7fbc6c9cbd57eed01bd04b1da73109935091Brian src = draw_find_vs_output(i915->draw, TGSI_SEMANTIC_COLOR, 0); 105846b7fbc6c9cbd57eed01bd04b1da73109935091Brian draw_emit_vertex_attr(&vinfo, EMIT_4UB, colorInterp, src); 106846b7fbc6c9cbd57eed01bd04b1da73109935091Brian vinfo.hwfmt[0] |= S4_VFMT_COLOR; 107846b7fbc6c9cbd57eed01bd04b1da73109935091Brian } 108846b7fbc6c9cbd57eed01bd04b1da73109935091Brian 109846b7fbc6c9cbd57eed01bd04b1da73109935091Brian /* secondary color */ 110846b7fbc6c9cbd57eed01bd04b1da73109935091Brian if (colors[1]) { 111846b7fbc6c9cbd57eed01bd04b1da73109935091Brian src = draw_find_vs_output(i915->draw, TGSI_SEMANTIC_COLOR, 1); 112846b7fbc6c9cbd57eed01bd04b1da73109935091Brian draw_emit_vertex_attr(&vinfo, EMIT_4UB, colorInterp, src); 113846b7fbc6c9cbd57eed01bd04b1da73109935091Brian vinfo.hwfmt[0] |= S4_VFMT_SPEC_FOG; 114846b7fbc6c9cbd57eed01bd04b1da73109935091Brian } 115846b7fbc6c9cbd57eed01bd04b1da73109935091Brian 116846b7fbc6c9cbd57eed01bd04b1da73109935091Brian /* fog coord, not fog blend factor */ 117846b7fbc6c9cbd57eed01bd04b1da73109935091Brian if (fog) { 118846b7fbc6c9cbd57eed01bd04b1da73109935091Brian src = draw_find_vs_output(i915->draw, TGSI_SEMANTIC_FOG, 0); 119846b7fbc6c9cbd57eed01bd04b1da73109935091Brian draw_emit_vertex_attr(&vinfo, EMIT_1F, INTERP_PERSPECTIVE, src); 120846b7fbc6c9cbd57eed01bd04b1da73109935091Brian vinfo.hwfmt[0] |= S4_VFMT_FOG_PARAM; 121846b7fbc6c9cbd57eed01bd04b1da73109935091Brian } 122846b7fbc6c9cbd57eed01bd04b1da73109935091Brian 123846b7fbc6c9cbd57eed01bd04b1da73109935091Brian /* texcoords */ 124846b7fbc6c9cbd57eed01bd04b1da73109935091Brian for (i = 0; i < 8; i++) { 125846b7fbc6c9cbd57eed01bd04b1da73109935091Brian uint hwtc; 126846b7fbc6c9cbd57eed01bd04b1da73109935091Brian if (texCoords[i]) { 127846b7fbc6c9cbd57eed01bd04b1da73109935091Brian hwtc = TEXCOORDFMT_4D; 128846b7fbc6c9cbd57eed01bd04b1da73109935091Brian src = draw_find_vs_output(i915->draw, TGSI_SEMANTIC_GENERIC, i); 129846b7fbc6c9cbd57eed01bd04b1da73109935091Brian draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, src); 130cc2629f5912d1c608f830ab63f6c4e0875d2fcefZack Rusin } 131846b7fbc6c9cbd57eed01bd04b1da73109935091Brian else { 132846b7fbc6c9cbd57eed01bd04b1da73109935091Brian hwtc = TEXCOORDFMT_NOT_PRESENT; 13301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell } 134846b7fbc6c9cbd57eed01bd04b1da73109935091Brian vinfo.hwfmt[1] |= hwtc << (i * 4); 13501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell } 13601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell 137f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian draw_compute_vertex_size(&vinfo); 138f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian 139f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian if (memcmp(&i915->current.vertex_info, &vinfo, sizeof(vinfo))) { 140f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian /* Need to set this flag so that the LIS2/4 registers get set. 141f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian * It also means the i915_update_immediate() function must be called 142f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian * after this one, in i915_update_derived(). 143f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian */ 144f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian i915->dirty |= I915_NEW_VERTEX_FORMAT; 145f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian 146f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian memcpy(&i915->current.vertex_info, &vinfo, sizeof(vinfo)); 147f8b2148a2b0c28ea5970be275f1bd678aa32094dBrian } 14801c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell} 14901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell 15001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell 15101c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell 152c990d0fd57a05301429b3af75b7fed0337621941Brian 15301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell/* Hopefully this will remain quite simple, otherwise need to pull in 15401c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell * something like the state tracker mechanism. 15501c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell */ 15601c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwellvoid i915_update_derived( struct i915_context *i915 ) 15701c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell{ 158f41e95755757cb1452697fafa1dd5288390ed57eBrian if (i915->dirty & (I915_NEW_RASTERIZER | I915_NEW_FS | I915_NEW_VS)) 15901c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell calculate_vertex_layout( i915 ); 16001c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell 161b4d8be235b018594a79258d36e70880ab9019b72keithw if (i915->dirty & (I915_NEW_SAMPLER | I915_NEW_TEXTURE)) 162c990d0fd57a05301429b3af75b7fed0337621941Brian i915_update_samplers(i915); 163c990d0fd57a05301429b3af75b7fed0337621941Brian 164c990d0fd57a05301429b3af75b7fed0337621941Brian if (i915->dirty & I915_NEW_TEXTURE) 165c990d0fd57a05301429b3af75b7fed0337621941Brian i915_update_textures(i915); 166c990d0fd57a05301429b3af75b7fed0337621941Brian 167277e4989f348913e3852f3d8c4efb82ba1380fcbKeith Whitwell if (i915->dirty) 168e23966f3de81342f7bd11f1e79c04022b5f0193fKeith Whitwell i915_update_immediate( i915 ); 169e23966f3de81342f7bd11f1e79c04022b5f0193fKeith Whitwell 1707c9a1357beabd6d0df88142d31cd5d77a012e85aKeith Whitwell if (i915->dirty) 1717c9a1357beabd6d0df88142d31cd5d77a012e85aKeith Whitwell i915_update_dynamic( i915 ); 1727c9a1357beabd6d0df88142d31cd5d77a012e85aKeith Whitwell 1730d9bcdbeb11ad1ce7e5257f652ccf9ebf1aa59a7Brian if (i915->dirty & I915_NEW_FS) { 1740d9bcdbeb11ad1ce7e5257f652ccf9ebf1aa59a7Brian i915->hardware_dirty |= I915_HW_PROGRAM; /* XXX right? */ 1750d9bcdbeb11ad1ce7e5257f652ccf9ebf1aa59a7Brian } 1760d9bcdbeb11ad1ce7e5257f652ccf9ebf1aa59a7Brian 177e23966f3de81342f7bd11f1e79c04022b5f0193fKeith Whitwell /* HW emit currently references framebuffer state directly: 178e23966f3de81342f7bd11f1e79c04022b5f0193fKeith Whitwell */ 179e23966f3de81342f7bd11f1e79c04022b5f0193fKeith Whitwell if (i915->dirty & I915_NEW_FRAMEBUFFER) 1807c9a1357beabd6d0df88142d31cd5d77a012e85aKeith Whitwell i915->hardware_dirty |= I915_HW_STATIC; 181277e4989f348913e3852f3d8c4efb82ba1380fcbKeith Whitwell 18201c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell i915->dirty = 0; 18301c35b52a1fccbe4253a96b9c0506ef6c991e44fKeith Whitwell} 184