00001 /************************************************************************** 00002 * 00003 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 00004 * All Rights Reserved. 00005 * 00006 * Permission is hereby granted, free of charge, to any person obtaining a 00007 * copy of this software and associated documentation files (the 00008 * "Software"), to deal in the Software without restriction, including 00009 * without limitation the rights to use, copy, modify, merge, publish, 00010 * distribute, sub license, and/or sell copies of the Software, and to 00011 * permit persons to whom the Software is furnished to do so, subject to 00012 * the following conditions: 00013 * 00014 * The above copyright notice and this permission notice (including the 00015 * next paragraph) shall be included in all copies or substantial portions 00016 * of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00019 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00020 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 00021 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 00022 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 00023 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 00024 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00025 * 00026 **************************************************************************/ 00027 00028 #ifndef I915_CONTEXT_H 00029 #define I915_CONTEXT_H 00030 00031 00032 #include "pipe/p_context.h" 00033 #include "pipe/p_defines.h" 00034 #include "pipe/p_state.h" 00035 00036 #include "draw/draw_vertex.h" 00037 00038 #include "tgsi/tgsi_scan.h" 00039 00040 00041 #define I915_TEX_UNITS 8 00042 00043 #define I915_DYNAMIC_MODES4 0 00044 #define I915_DYNAMIC_DEPTHSCALE_0 1 /* just the header */ 00045 #define I915_DYNAMIC_DEPTHSCALE_1 2 00046 #define I915_DYNAMIC_IAB 3 00047 #define I915_DYNAMIC_BC_0 4 /* just the header */ 00048 #define I915_DYNAMIC_BC_1 5 00049 #define I915_DYNAMIC_BFO_0 6 00050 #define I915_DYNAMIC_BFO_1 7 00051 #define I915_DYNAMIC_STP_0 8 00052 #define I915_DYNAMIC_STP_1 9 00053 #define I915_DYNAMIC_SC_ENA_0 10 00054 #define I915_DYNAMIC_SC_RECT_0 11 00055 #define I915_DYNAMIC_SC_RECT_1 12 00056 #define I915_DYNAMIC_SC_RECT_2 13 00057 #define I915_MAX_DYNAMIC 14 00058 00059 00060 #define I915_IMMEDIATE_S0 0 00061 #define I915_IMMEDIATE_S1 1 00062 #define I915_IMMEDIATE_S2 2 00063 #define I915_IMMEDIATE_S3 3 00064 #define I915_IMMEDIATE_S4 4 00065 #define I915_IMMEDIATE_S5 5 00066 #define I915_IMMEDIATE_S6 6 00067 #define I915_IMMEDIATE_S7 7 00068 #define I915_MAX_IMMEDIATE 8 00069 00070 /* These must mach the order of LI0_STATE_* bits, as they will be used 00071 * to generate hardware packets: 00072 */ 00073 #define I915_CACHE_STATIC 0 00074 #define I915_CACHE_DYNAMIC 1 /* handled specially */ 00075 #define I915_CACHE_SAMPLER 2 00076 #define I915_CACHE_MAP 3 00077 #define I915_CACHE_PROGRAM 4 00078 #define I915_CACHE_CONSTANTS 5 00079 #define I915_MAX_CACHE 6 00080 00081 #define I915_MAX_CONSTANT 32 00082 00083 00085 #define I915_CONSTFLAG_USER 0x1f 00086 00087 00091 struct i915_fragment_shader 00092 { 00093 struct pipe_shader_state state; 00094 00095 struct tgsi_shader_info info; 00096 00097 uint *program; 00098 uint program_len; 00099 00109 uint num_constants; 00110 float constants[I915_MAX_CONSTANT][4]; 00111 00118 ubyte constant_flags[I915_MAX_CONSTANT]; 00119 }; 00120 00121 00122 struct i915_cache_context; 00123 00124 /* Use to calculate differences between state emitted to hardware and 00125 * current driver-calculated state. 00126 */ 00127 struct i915_state 00128 { 00129 unsigned immediate[I915_MAX_IMMEDIATE]; 00130 unsigned dynamic[I915_MAX_DYNAMIC]; 00131 00132 float constants[PIPE_SHADER_TYPES][I915_MAX_CONSTANT][4]; 00134 uint num_user_constants[PIPE_SHADER_TYPES]; 00135 00136 /* texture sampler state */ 00137 unsigned sampler[I915_TEX_UNITS][3]; 00138 unsigned sampler_enable_flags; 00139 unsigned sampler_enable_nr; 00140 00141 /* texture image buffers */ 00142 unsigned texbuffer[I915_TEX_UNITS][2]; 00143 00145 struct vertex_info vertex_info; 00146 00147 unsigned id; /* track lost context events */ 00148 }; 00149 00150 struct i915_blend_state { 00151 unsigned iab; 00152 unsigned modes4; 00153 unsigned LIS5; 00154 unsigned LIS6; 00155 }; 00156 00157 struct i915_depth_stencil_state { 00158 unsigned stencil_modes4; 00159 unsigned bfo[2]; 00160 unsigned stencil_LIS5; 00161 unsigned depth_LIS6; 00162 }; 00163 00164 struct i915_rasterizer_state { 00165 int light_twoside : 1; 00166 unsigned st; 00167 enum interp_mode color_interp; 00168 00169 unsigned LIS4; 00170 unsigned LIS7; 00171 unsigned sc[1]; 00172 00173 const struct pipe_rasterizer_state *templ; 00174 00175 union { float f; unsigned u; } ds[2]; 00176 }; 00177 00178 struct i915_sampler_state { 00179 unsigned state[3]; 00180 const struct pipe_sampler_state *templ; 00181 unsigned minlod; 00182 unsigned maxlod; 00183 }; 00184 00185 00186 struct i915_texture { 00187 struct pipe_texture base; 00188 00189 /* Derived from the above: 00190 */ 00191 unsigned stride; 00192 unsigned depth_stride; /* per-image on i945? */ 00193 unsigned total_nblocksy; 00194 00195 unsigned tiled; 00196 00197 unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; 00198 00199 /* Explicitly store the offset of each image for each cube face or 00200 * depth value. Pretty much have to accept that hardware formats 00201 * are going to be so diverse that there is no unified way to 00202 * compute the offsets of depth/cube images within a mipmap level, 00203 * so have to store them as a lookup table: 00204 */ 00205 unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; 00207 /* The data is held here: 00208 */ 00209 struct pipe_buffer *buffer; 00210 }; 00211 00212 struct i915_batchbuffer; 00213 00214 struct i915_context 00215 { 00216 struct pipe_context pipe; 00217 struct i915_winsys *winsys; 00218 struct draw_context *draw; 00219 00220 /* The most recent drawing state as set by the driver: 00221 */ 00222 const struct i915_blend_state *blend; 00223 const struct i915_sampler_state *sampler[PIPE_MAX_SAMPLERS]; 00224 const struct i915_depth_stencil_state *depth_stencil; 00225 const struct i915_rasterizer_state *rasterizer; 00226 00227 struct i915_fragment_shader *fs; 00228 00229 struct pipe_blend_color blend_color; 00230 struct pipe_clip_state clip; 00231 struct pipe_constant_buffer constants[PIPE_SHADER_TYPES]; 00232 struct pipe_framebuffer_state framebuffer; 00233 struct pipe_poly_stipple poly_stipple; 00234 struct pipe_scissor_state scissor; 00235 struct i915_texture *texture[PIPE_MAX_SAMPLERS]; 00236 struct pipe_viewport_state viewport; 00237 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; 00238 00239 unsigned dirty; 00240 00241 unsigned num_samplers; 00242 unsigned num_textures; 00243 unsigned num_vertex_elements; 00244 unsigned num_vertex_buffers; 00245 00246 struct i915_batchbuffer *batch; 00247 00249 struct pipe_buffer *vbo; 00250 size_t vbo_offset; 00251 unsigned vbo_flushed; 00252 00253 struct i915_state current; 00254 unsigned hardware_dirty; 00255 00256 unsigned debug; 00257 }; 00258 00259 /* A flag for each state_tracker state object: 00260 */ 00261 #define I915_NEW_VIEWPORT 0x1 00262 #define I915_NEW_RASTERIZER 0x2 00263 #define I915_NEW_FS 0x4 00264 #define I915_NEW_BLEND 0x8 00265 #define I915_NEW_CLIP 0x10 00266 #define I915_NEW_SCISSOR 0x20 00267 #define I915_NEW_STIPPLE 0x40 00268 #define I915_NEW_FRAMEBUFFER 0x80 00269 #define I915_NEW_ALPHA_TEST 0x100 00270 #define I915_NEW_DEPTH_STENCIL 0x200 00271 #define I915_NEW_SAMPLER 0x400 00272 #define I915_NEW_TEXTURE 0x800 00273 #define I915_NEW_CONSTANTS 0x1000 00274 #define I915_NEW_VBO 0x2000 00275 #define I915_NEW_VS 0x4000 00276 00277 00278 /* Driver's internally generated state flags: 00279 */ 00280 #define I915_NEW_VERTEX_FORMAT 0x10000 00281 00282 00283 /* Dirty flags for hardware emit 00284 */ 00285 #define I915_HW_STATIC (1<<I915_CACHE_STATIC) 00286 #define I915_HW_DYNAMIC (1<<I915_CACHE_DYNAMIC) 00287 #define I915_HW_SAMPLER (1<<I915_CACHE_SAMPLER) 00288 #define I915_HW_MAP (1<<I915_CACHE_MAP) 00289 #define I915_HW_PROGRAM (1<<I915_CACHE_PROGRAM) 00290 #define I915_HW_CONSTANTS (1<<I915_CACHE_CONSTANTS) 00291 #define I915_HW_IMMEDIATE (1<<(I915_MAX_CACHE+0)) 00292 #define I915_HW_INVARIENT (1<<(I915_MAX_CACHE+1)) 00293 00294 00295 /*********************************************************************** 00296 * i915_prim_emit.c: 00297 */ 00298 struct draw_stage *i915_draw_render_stage( struct i915_context *i915 ); 00299 00300 00301 /*********************************************************************** 00302 * i915_prim_vbuf.c: 00303 */ 00304 struct draw_stage *i915_draw_vbuf_stage( struct i915_context *i915 ); 00305 00306 00307 /*********************************************************************** 00308 * i915_state_emit.c: 00309 */ 00310 void i915_emit_hardware_state(struct i915_context *i915 ); 00311 00312 00313 00314 /*********************************************************************** 00315 * i915_clear.c: 00316 */ 00317 void i915_clear(struct pipe_context *pipe, struct pipe_surface *ps, 00318 unsigned clearValue); 00319 00320 00321 /*********************************************************************** 00322 * i915_surface.c: 00323 */ 00324 void i915_init_surface_functions( struct i915_context *i915 ); 00325 00326 void i915_init_state_functions( struct i915_context *i915 ); 00327 void i915_init_flush_functions( struct i915_context *i915 ); 00328 void i915_init_string_functions( struct i915_context *i915 ); 00329 00330 00331 00332 00333 /*********************************************************************** 00334 * Inline conversion functions. These are better-typed than the 00335 * macros used previously: 00336 */ 00337 static INLINE struct i915_context * 00338 i915_context( struct pipe_context *pipe ) 00339 { 00340 return (struct i915_context *)pipe; 00341 } 00342 00343 00344 00345 #endif