OSDN Git Service

i965: new integrated graphics chipset support
[android-x86/external-mesa.git] / src / mesa / drivers / dri / i965 / brw_misc_state.c
1 /*
2  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
3  Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4  develop this 3D driver.
5  
6  Permission is hereby granted, free of charge, to any person obtaining
7  a 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, sublicense, 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
16  portions of the Software.
17  
18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  
26  **********************************************************************/
27  /*
28   * Authors:
29   *   Keith Whitwell <keith@tungstengraphics.com>
30   */
31  
32
33
34 #include "intel_batchbuffer.h"
35 #include "intel_regions.h"
36
37 #include "brw_context.h"
38 #include "brw_state.h"
39 #include "brw_defines.h"
40
41
42
43
44
45 /***********************************************************************
46  * Blend color
47  */
48
49 static void upload_blend_constant_color(struct brw_context *brw)
50 {
51    struct brw_blend_constant_color bcc;
52
53    memset(&bcc, 0, sizeof(bcc));      
54    bcc.header.opcode = CMD_BLEND_CONSTANT_COLOR;
55    bcc.header.length = sizeof(bcc)/4-2;
56    bcc.blend_constant_color[0] = brw->attribs.Color->BlendColor[0];
57    bcc.blend_constant_color[1] = brw->attribs.Color->BlendColor[1];
58    bcc.blend_constant_color[2] = brw->attribs.Color->BlendColor[2];
59    bcc.blend_constant_color[3] = brw->attribs.Color->BlendColor[3];
60
61    BRW_CACHED_BATCH_STRUCT(brw, &bcc);
62 }
63
64
65 const struct brw_tracked_state brw_blend_constant_color = {
66    .dirty = {
67       .mesa = _NEW_COLOR,
68       .brw = 0,
69       .cache = 0
70    },
71    .update = upload_blend_constant_color
72 };
73
74 /**
75  * Upload the binding table pointers, which point each stage's array of surface
76  * state pointers.
77  *
78  * The binding table pointers are relative to the surface state base address,
79  * which is 0.
80  */
81 static void upload_binding_table_pointers(struct brw_context *brw)
82 {
83    struct intel_context *intel = &brw->intel;
84
85    BEGIN_BATCH(6, IGNORE_CLIPRECTS);
86    OUT_BATCH(CMD_BINDING_TABLE_PTRS << 16 | (6 - 2));
87    OUT_BATCH(0); /* vs */
88    OUT_BATCH(0); /* gs */
89    OUT_BATCH(0); /* clip */
90    OUT_BATCH(0); /* sf */
91    OUT_RELOC(brw->wm.bind_bo, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, 0);
92    ADVANCE_BATCH();
93 }
94
95 const struct brw_tracked_state brw_binding_table_pointers = {
96    .dirty = {
97       .mesa = 0,
98       .brw = BRW_NEW_BATCH,
99       .cache = CACHE_NEW_SURF_BIND,
100    },
101    .update = upload_binding_table_pointers,
102 };
103
104
105 /**
106  * Upload pointers to the per-stage state.
107  *
108  * The state pointers in this packet are all relative to the general state
109  * base address set by CMD_STATE_BASE_ADDRESS, which is 0.
110  */
111 static void upload_pipelined_state_pointers(struct brw_context *brw )
112 {
113    struct intel_context *intel = &brw->intel;
114
115    BEGIN_BATCH(7, IGNORE_CLIPRECTS);
116    OUT_BATCH(CMD_PIPELINED_STATE_POINTERS << 16 | (7 - 2));
117    OUT_RELOC(brw->vs.state_bo, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, 0);
118    if (brw->gs.prog_active)
119       OUT_RELOC(brw->gs.state_bo, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, 1);
120    else
121       OUT_BATCH(0);
122    if (!brw->metaops.active)
123       OUT_RELOC(brw->clip.state_bo, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, 1);
124    else
125       OUT_BATCH(0);
126    OUT_RELOC(brw->sf.state_bo, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, 0);
127    OUT_RELOC(brw->wm.state_bo, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, 0);
128    OUT_RELOC(brw->cc.state_bo, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, 0);
129    ADVANCE_BATCH();
130
131    brw->state.dirty.brw |= BRW_NEW_PSP;
132 }
133
134 #if 0
135 /* Combined into brw_psp_urb_cbs */
136 const struct brw_tracked_state brw_pipelined_state_pointers = {
137    .dirty = {
138       .mesa = 0,
139       .brw = BRW_NEW_METAOPS | BRW_NEW_BATCH,
140       .cache = (CACHE_NEW_VS_UNIT | 
141                 CACHE_NEW_GS_UNIT | 
142                 CACHE_NEW_GS_PROG | 
143                 CACHE_NEW_CLIP_UNIT | 
144                 CACHE_NEW_SF_UNIT | 
145                 CACHE_NEW_WM_UNIT | 
146                 CACHE_NEW_CC_UNIT)
147    },
148    .update = upload_pipelined_state_pointers
149 };
150 #endif
151
152 static void upload_psp_urb_cbs(struct brw_context *brw )
153 {
154    upload_pipelined_state_pointers(brw);
155    brw_upload_urb_fence(brw);
156    brw_upload_constant_buffer_state(brw);
157 }
158
159
160 const struct brw_tracked_state brw_psp_urb_cbs = {
161    .dirty = {
162       .mesa = 0,
163       .brw = BRW_NEW_URB_FENCE | BRW_NEW_METAOPS | BRW_NEW_BATCH,
164       .cache = (CACHE_NEW_VS_UNIT | 
165                 CACHE_NEW_GS_UNIT | 
166                 CACHE_NEW_GS_PROG | 
167                 CACHE_NEW_CLIP_UNIT | 
168                 CACHE_NEW_SF_UNIT | 
169                 CACHE_NEW_WM_UNIT | 
170                 CACHE_NEW_CC_UNIT)
171    },
172    .update = upload_psp_urb_cbs,
173 };
174
175 /**
176  * Upload the depthbuffer offset and format.
177  *
178  * We have to do this per state validation as we need to emit the relocation
179  * in the batch buffer.
180  */
181 static void upload_depthbuffer(struct brw_context *brw)
182 {
183    struct intel_context *intel = &brw->intel;
184    struct intel_region *region = brw->state.depth_region;
185    unsigned int len = BRW_IS_IGD(brw) ? sizeof(struct brw_depthbuffer_igd) / 4 : sizeof(struct brw_depthbuffer) / 4;
186
187    if (region == NULL) {
188       BEGIN_BATCH(len, IGNORE_CLIPRECTS);
189       OUT_BATCH(CMD_DEPTH_BUFFER << 16 | (len - 2));
190       OUT_BATCH((BRW_DEPTHFORMAT_D32_FLOAT << 18) |
191                 (BRW_SURFACE_NULL << 29));
192       OUT_BATCH(0);
193       OUT_BATCH(0);
194       OUT_BATCH(0);
195
196       if (BRW_IS_IGD(brw))
197          OUT_BATCH(0);
198
199       ADVANCE_BATCH();
200    } else {
201       unsigned int format;
202
203       switch (region->cpp) {
204       case 2:
205          format = BRW_DEPTHFORMAT_D16_UNORM;
206          break;
207       case 4:
208          if (intel->depth_buffer_is_float)
209             format = BRW_DEPTHFORMAT_D32_FLOAT;
210          else
211             format = BRW_DEPTHFORMAT_D24_UNORM_S8_UINT;
212          break;
213       default:
214          assert(0);
215          return;
216       }
217
218       BEGIN_BATCH(len, IGNORE_CLIPRECTS);
219       OUT_BATCH(CMD_DEPTH_BUFFER << 16 | (len - 2));
220       OUT_BATCH(((region->pitch * region->cpp) - 1) |
221                 (format << 18) |
222                 (BRW_TILEWALK_YMAJOR << 26) |
223                 (region->tiled << 27) |
224                 (BRW_SURFACE_2D << 29));
225       OUT_RELOC(region->buffer,
226                 DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0);
227       OUT_BATCH((BRW_SURFACE_MIPMAPLAYOUT_BELOW << 1) |
228                 ((region->pitch - 1) << 6) |
229                 ((region->height - 1) << 19));
230       OUT_BATCH(0);
231
232       if (BRW_IS_IGD(brw))
233          OUT_BATCH(0);
234
235       ADVANCE_BATCH();
236    }
237 }
238
239 const struct brw_tracked_state brw_depthbuffer = {
240    .dirty = {
241       .mesa = 0,
242       .brw = BRW_NEW_DEPTH_BUFFER | BRW_NEW_BATCH,
243       .cache = 0,
244    },
245    .update = upload_depthbuffer,
246 };
247
248
249
250 /***********************************************************************
251  * Polygon stipple packet
252  */
253
254 static void upload_polygon_stipple(struct brw_context *brw)
255 {
256    struct brw_polygon_stipple bps;
257    GLuint i;
258
259    memset(&bps, 0, sizeof(bps));
260    bps.header.opcode = CMD_POLY_STIPPLE_PATTERN;
261    bps.header.length = sizeof(bps)/4-2;
262
263    for (i = 0; i < 32; i++)
264       bps.stipple[i] = brw->attribs.PolygonStipple[31 - i]; /* invert */
265
266    BRW_CACHED_BATCH_STRUCT(brw, &bps);
267 }
268
269 const struct brw_tracked_state brw_polygon_stipple = {
270    .dirty = {
271       .mesa = _NEW_POLYGONSTIPPLE,
272       .brw = 0,
273       .cache = 0
274    },
275    .update = upload_polygon_stipple
276 };
277
278
279 /***********************************************************************
280  * Polygon stipple offset packet
281  */
282
283 static void upload_polygon_stipple_offset(struct brw_context *brw)
284 {
285    __DRIdrawablePrivate *dPriv = brw->intel.driDrawable;
286    struct brw_polygon_stipple_offset bpso;
287
288    memset(&bpso, 0, sizeof(bpso));
289    bpso.header.opcode = CMD_POLY_STIPPLE_OFFSET;
290    bpso.header.length = sizeof(bpso)/4-2;
291
292    bpso.bits0.x_offset = (32 - (dPriv->x & 31)) & 31;
293    bpso.bits0.y_offset = (32 - ((dPriv->y + dPriv->h) & 31)) & 31;
294
295    BRW_CACHED_BATCH_STRUCT(brw, &bpso);
296 }
297
298 const struct brw_tracked_state brw_polygon_stipple_offset = {
299    .dirty = {
300       .mesa = _NEW_WINDOW_POS,
301       .brw = 0,
302       .cache = 0
303    },
304    .update = upload_polygon_stipple_offset
305 };
306
307 /**********************************************************************
308  * AA Line parameters
309  */
310 static void upload_aa_line_parameters(struct brw_context *brw)
311 {
312    struct brw_aa_line_parameters balp;
313    
314    if (!BRW_IS_IGD(brw))
315       return;
316
317    /* use legacy aa line coverage computation */
318    memset(&balp, 0, sizeof(balp));
319    balp.header.opcode = CMD_AA_LINE_PARAMETERS;
320    balp.header.length = sizeof(balp) / 4 - 2;
321    
322    BRW_CACHED_BATCH_STRUCT(brw, &balp);
323 }
324
325 const struct brw_tracked_state brw_aa_line_parameters = {
326    .dirty = {
327       .mesa = 0,
328       .brw = BRW_NEW_CONTEXT,
329       .cache = 0
330    },
331    .update = upload_aa_line_parameters
332 };
333
334 /***********************************************************************
335  * Line stipple packet
336  */
337
338 static void upload_line_stipple(struct brw_context *brw)
339 {
340    struct brw_line_stipple bls;
341    GLfloat tmp;
342    GLint tmpi;
343
344    memset(&bls, 0, sizeof(bls));
345    bls.header.opcode = CMD_LINE_STIPPLE_PATTERN;
346    bls.header.length = sizeof(bls)/4 - 2;
347
348    bls.bits0.pattern = brw->attribs.Line->StipplePattern;
349    bls.bits1.repeat_count = brw->attribs.Line->StippleFactor;
350
351    tmp = 1.0 / (GLfloat) brw->attribs.Line->StippleFactor;
352    tmpi = tmp * (1<<13);
353
354
355    bls.bits1.inverse_repeat_count = tmpi;
356
357    BRW_CACHED_BATCH_STRUCT(brw, &bls);
358 }
359
360 const struct brw_tracked_state brw_line_stipple = {
361    .dirty = {
362       .mesa = _NEW_LINE,
363       .brw = 0,
364       .cache = 0
365    },
366    .update = upload_line_stipple
367 };
368
369
370
371 /***********************************************************************
372  * Misc constant state packets
373  */
374
375 static void upload_pipe_control(struct brw_context *brw)
376 {
377    struct brw_pipe_control pc;
378
379    return;
380
381    memset(&pc, 0, sizeof(pc));
382
383    pc.header.opcode = CMD_PIPE_CONTROL;
384    pc.header.length = sizeof(pc)/4 - 2;
385    pc.header.post_sync_operation = PIPE_CONTROL_NOWRITE;
386
387    pc.header.instruction_state_cache_flush_enable = 1;
388
389    pc.bits1.dest_addr_type = PIPE_CONTROL_GTTWRITE_GLOBAL;
390
391    BRW_BATCH_STRUCT(brw, &pc);
392 }
393
394 const struct brw_tracked_state brw_pipe_control = {
395    .dirty = {
396       .mesa = 0,
397       .brw = BRW_NEW_CONTEXT,
398       .cache = 0
399    },
400    .update = upload_pipe_control
401 };
402
403
404 /***********************************************************************
405  * Misc invarient state packets
406  */
407
408 static void upload_invarient_state( struct brw_context *brw )
409 {
410    {
411       /* 0x61040000  Pipeline Select */
412       /*     PipelineSelect            : 0 */
413       struct brw_pipeline_select ps;
414
415       memset(&ps, 0, sizeof(ps));
416       ps.header.opcode = CMD_PIPELINE_SELECT(brw);
417       ps.header.pipeline_select = 0;
418       BRW_BATCH_STRUCT(brw, &ps);
419    }
420
421    {
422       struct brw_global_depth_offset_clamp gdo;
423       memset(&gdo, 0, sizeof(gdo));
424
425       /* Disable depth offset clamping. 
426        */
427       gdo.header.opcode = CMD_GLOBAL_DEPTH_OFFSET_CLAMP;
428       gdo.header.length = sizeof(gdo)/4 - 2;
429       gdo.depth_offset_clamp = 0.0;
430
431       BRW_BATCH_STRUCT(brw, &gdo);
432    }
433
434
435    /* 0x61020000  State Instruction Pointer */
436    {
437       struct brw_system_instruction_pointer sip;
438       memset(&sip, 0, sizeof(sip));
439
440       sip.header.opcode = CMD_STATE_INSN_POINTER;
441       sip.header.length = 0;
442       sip.bits0.pad = 0;
443       sip.bits0.system_instruction_pointer = 0;
444       BRW_BATCH_STRUCT(brw, &sip);
445    }
446
447
448    {
449       struct brw_vf_statistics vfs;
450       memset(&vfs, 0, sizeof(vfs));
451
452       vfs.opcode = CMD_VF_STATISTICS(brw);
453       if (INTEL_DEBUG & DEBUG_STATS)
454          vfs.statistics_enable = 1; 
455
456       BRW_BATCH_STRUCT(brw, &vfs);
457    }
458 }
459
460 const struct brw_tracked_state brw_invarient_state = {
461    .dirty = {
462       .mesa = 0,
463       .brw = BRW_NEW_CONTEXT,
464       .cache = 0
465    },
466    .update = upload_invarient_state
467 };
468
469 /**
470  * Define the base addresses which some state is referenced from.
471  *
472  * This allows us to avoid having to emit relocations in many places for
473  * cached state, and instead emit pointers inside of large, mostly-static
474  * state pools.  This comes at the expense of memory, and more expensive cache
475  * misses.
476  */
477 static void upload_state_base_address( struct brw_context *brw )
478 {
479    struct intel_context *intel = &brw->intel;
480
481    /* Output the structure (brw_state_base_address) directly to the
482     * batchbuffer, so we can emit relocations inline.
483     */
484    BEGIN_BATCH(6, IGNORE_CLIPRECTS);
485    OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (6 - 2));
486    OUT_BATCH(1); /* General state base address */
487    OUT_BATCH(1); /* Surface state base address */
488    OUT_BATCH(1); /* Indirect object base address */
489    OUT_BATCH(1); /* General state upper bound */
490    OUT_BATCH(1); /* Indirect object upper bound */
491    ADVANCE_BATCH();
492 }
493
494 const struct brw_tracked_state brw_state_base_address = {
495    .dirty = {
496       .mesa = 0,
497       .brw = BRW_NEW_CONTEXT,
498       .cache = 0,
499    },
500    .update = upload_state_base_address
501 };