i915_state_immediate.c revision 481fad15526d30e121d031bfcb765ed7847f50a7
1/************************************************************************** 2 * 3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 /* 28 * Authors: 29 * Keith Whitwell <keith@tungstengraphics.com> 30 */ 31 32#include "i915_state_inlines.h" 33#include "i915_context.h" 34#include "i915_state.h" 35#include "i915_reg.h" 36#include "util/u_memory.h" 37 38 39 40/*********************************************************************** 41 * S0,S1: Vertex buffer state. 42 */ 43static void upload_S0S1(struct i915_context *i915) 44{ 45 unsigned LIS0, LIS1; 46 47 /* I915_NEW_VBO 48 */ 49 LIS0 = i915->vbo_offset; 50 51 /* I915_NEW_VERTEX_SIZE 52 */ 53 /* XXX do this where the vertex size is calculated! */ 54 { 55 unsigned vertex_size = i915->current.vertex_info.size; 56 57 LIS1 = ((vertex_size << 24) | 58 (vertex_size << 16)); 59 } 60 61 /* I915_NEW_VBO 62 */ 63 if (1 || 64 i915->current.immediate[I915_IMMEDIATE_S0] != LIS0 || 65 i915->current.immediate[I915_IMMEDIATE_S1] != LIS1) 66 { 67 i915->current.immediate[I915_IMMEDIATE_S0] = LIS0; 68 i915->current.immediate[I915_IMMEDIATE_S1] = LIS1; 69 i915->hardware_dirty |= I915_HW_IMMEDIATE; 70 } 71} 72 73const struct i915_tracked_state i915_upload_S0S1 = { 74 "imm S0 S1", 75 upload_S0S1, 76 I915_NEW_VBO | I915_NEW_VERTEX_FORMAT 77}; 78 79 80 81/*********************************************************************** 82 * S4: Vertex format, rasterization state 83 */ 84static void upload_S2S4(struct i915_context *i915) 85{ 86 unsigned LIS2, LIS4; 87 88 /* I915_NEW_VERTEX_FORMAT 89 */ 90 { 91 LIS2 = i915->current.vertex_info.hwfmt[1]; 92 LIS4 = i915->current.vertex_info.hwfmt[0]; 93 /* 94 debug_printf("LIS2: 0x%x LIS4: 0x%x\n", LIS2, LIS4); 95 */ 96 assert(LIS4); /* should never be zero? */ 97 } 98 99 LIS4 |= i915->rasterizer->LIS4; 100 101 if (LIS2 != i915->current.immediate[I915_IMMEDIATE_S2] || 102 LIS4 != i915->current.immediate[I915_IMMEDIATE_S4]) { 103 104 i915->current.immediate[I915_IMMEDIATE_S2] = LIS2; 105 i915->current.immediate[I915_IMMEDIATE_S4] = LIS4; 106 i915->hardware_dirty |= I915_HW_IMMEDIATE; 107 } 108} 109 110const struct i915_tracked_state i915_upload_S2S4 = { 111 "imm S2 S4", 112 upload_S2S4, 113 I915_NEW_RASTERIZER | I915_NEW_VERTEX_FORMAT 114}; 115 116 117 118/*********************************************************************** 119 */ 120static void upload_S5(struct i915_context *i915) 121{ 122 unsigned LIS5 = 0; 123 124 /* I915_NEW_DEPTH_STENCIL 125 */ 126 LIS5 |= i915->depth_stencil->stencil_LIS5; 127 /* hope it's safe to set stencil ref value even if stencil test is disabled? */ 128 LIS5 |= i915->stencil_ref.ref_value[0] << S5_STENCIL_REF_SHIFT; 129 130 /* I915_NEW_BLEND 131 */ 132 LIS5 |= i915->blend->LIS5; 133 134#if 0 135 /* I915_NEW_RASTERIZER 136 */ 137 if (i915->state.Polygon->OffsetFill) { 138 LIS5 |= S5_GLOBAL_DEPTH_OFFSET_ENABLE; 139 } 140#endif 141 142 if (LIS5 != i915->current.immediate[I915_IMMEDIATE_S5]) { 143 i915->current.immediate[I915_IMMEDIATE_S5] = LIS5; 144 i915->hardware_dirty |= I915_HW_IMMEDIATE; 145 } 146} 147 148const struct i915_tracked_state i915_upload_S5 = { 149 "imm S5", 150 upload_S5, 151 I915_NEW_DEPTH_STENCIL | I915_NEW_BLEND | I915_NEW_RASTERIZER 152}; 153 154 155 156/*********************************************************************** 157 */ 158static void upload_S6(struct i915_context *i915) 159{ 160 unsigned LIS6 = (2 << S6_TRISTRIP_PV_SHIFT); 161 162 /* I915_NEW_FRAMEBUFFER 163 */ 164 if (i915->framebuffer.cbufs[0]) 165 LIS6 |= S6_COLOR_WRITE_ENABLE; 166 167 /* I915_NEW_BLEND 168 */ 169 LIS6 |= i915->blend->LIS6; 170 171 /* I915_NEW_DEPTH 172 */ 173 LIS6 |= i915->depth_stencil->depth_LIS6; 174 175 if (LIS6 != i915->current.immediate[I915_IMMEDIATE_S6]) { 176 i915->current.immediate[I915_IMMEDIATE_S6] = LIS6; 177 i915->hardware_dirty |= I915_HW_IMMEDIATE; 178 } 179} 180 181const struct i915_tracked_state i915_upload_S6 = { 182 "imm s6", 183 upload_S6, 184 I915_NEW_BLEND | I915_NEW_DEPTH_STENCIL | I915_NEW_FRAMEBUFFER 185}; 186 187 188 189/*********************************************************************** 190 */ 191static void upload_S7(struct i915_context *i915) 192{ 193 unsigned LIS7; 194 195 /* I915_NEW_RASTERIZER 196 */ 197 LIS7 = i915->rasterizer->LIS7; 198 199 if (LIS7 != i915->current.immediate[I915_IMMEDIATE_S7]) { 200 i915->current.immediate[I915_IMMEDIATE_S7] = LIS7; 201 i915->hardware_dirty |= I915_HW_IMMEDIATE; 202 } 203} 204 205const struct i915_tracked_state i915_upload_S7 = { 206 "imm S7", 207 upload_S7, 208 I915_NEW_RASTERIZER 209}; 210 211 212 213/*********************************************************************** 214 */ 215static const struct i915_tracked_state *atoms[] = { 216 &i915_upload_S0S1, 217 &i915_upload_S2S4, 218 &i915_upload_S5, 219 &i915_upload_S6, 220 &i915_upload_S7 221}; 222 223static void update_immediate(struct i915_context *i915) 224{ 225 int i; 226 227 for (i = 0; i < Elements(atoms); i++) 228 if (i915->dirty & atoms[i]->dirty) 229 atoms[i]->update(i915); 230} 231 232struct i915_tracked_state i915_hw_immediate = { 233 "immediate", 234 update_immediate, 235 ~0 /* all state atoms, becuase we do internal checking */ 236}; 237