OSDN Git Service

Merge branch 'gallium-docs'
[android-x86/external-mesa.git] / src / mesa / drivers / dri / i915 / i915_vtbl.c
1 /**************************************************************************
2  * 
3  * Copyright 2003 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
29
30 #include "main/glheader.h"
31 #include "main/mtypes.h"
32 #include "main/imports.h"
33 #include "main/macros.h"
34 #include "main/colormac.h"
35
36 #include "tnl/t_context.h"
37 #include "tnl/t_vertex.h"
38
39 #include "intel_batchbuffer.h"
40 #include "intel_tex.h"
41 #include "intel_regions.h"
42 #include "intel_tris.h"
43 #include "intel_fbo.h"
44 #include "intel_chipset.h"
45
46 #include "i915_reg.h"
47 #include "i915_context.h"
48
49 #include "glapi/glapi.h"
50
51 static void
52 i915_render_prevalidate(struct intel_context *intel)
53 {
54    struct i915_context *i915 = i915_context(&intel->ctx);
55
56    i915ValidateFragmentProgram(i915);
57 }
58
59 static void
60 i915_render_start(struct intel_context *intel)
61 {
62 }
63
64
65 static void
66 i915_reduced_primitive_state(struct intel_context *intel, GLenum rprim)
67 {
68    struct i915_context *i915 = i915_context(&intel->ctx);
69    GLuint st1 = i915->state.Stipple[I915_STPREG_ST1];
70
71    st1 &= ~ST1_ENABLE;
72
73    switch (rprim) {
74    case GL_QUADS: /* from RASTERIZE(GL_QUADS) in t_dd_tritemp.h */
75    case GL_TRIANGLES:
76       if (intel->ctx.Polygon.StippleFlag && intel->hw_stipple)
77          st1 |= ST1_ENABLE;
78       break;
79    case GL_LINES:
80    case GL_POINTS:
81    default:
82       break;
83    }
84
85    i915->intel.reduced_primitive = rprim;
86
87    if (st1 != i915->state.Stipple[I915_STPREG_ST1]) {
88       INTEL_FIREVERTICES(intel);
89
90       I915_STATECHANGE(i915, I915_UPLOAD_STIPPLE);
91       i915->state.Stipple[I915_STPREG_ST1] = st1;
92    }
93 }
94
95
96 /* Pull apart the vertex format registers and figure out how large a
97  * vertex is supposed to be. 
98  */
99 static GLboolean
100 i915_check_vertex_size(struct intel_context *intel, GLuint expected)
101 {
102    struct i915_context *i915 = i915_context(&intel->ctx);
103    int lis2 = i915->current->Ctx[I915_CTXREG_LIS2];
104    int lis4 = i915->current->Ctx[I915_CTXREG_LIS4];
105    int i, sz = 0;
106
107    switch (lis4 & S4_VFMT_XYZW_MASK) {
108    case S4_VFMT_XY:
109       sz = 2;
110       break;
111    case S4_VFMT_XYZ:
112       sz = 3;
113       break;
114    case S4_VFMT_XYW:
115       sz = 3;
116       break;
117    case S4_VFMT_XYZW:
118       sz = 4;
119       break;
120    default:
121       fprintf(stderr, "no xyzw specified\n");
122       return 0;
123    }
124
125    if (lis4 & S4_VFMT_SPEC_FOG)
126       sz++;
127    if (lis4 & S4_VFMT_COLOR)
128       sz++;
129    if (lis4 & S4_VFMT_DEPTH_OFFSET)
130       sz++;
131    if (lis4 & S4_VFMT_POINT_WIDTH)
132       sz++;
133    if (lis4 & S4_VFMT_FOG_PARAM)
134       sz++;
135
136    for (i = 0; i < 8; i++) {
137       switch (lis2 & S2_TEXCOORD_FMT0_MASK) {
138       case TEXCOORDFMT_2D:
139          sz += 2;
140          break;
141       case TEXCOORDFMT_3D:
142          sz += 3;
143          break;
144       case TEXCOORDFMT_4D:
145          sz += 4;
146          break;
147       case TEXCOORDFMT_1D:
148          sz += 1;
149          break;
150       case TEXCOORDFMT_2D_16:
151          sz += 1;
152          break;
153       case TEXCOORDFMT_4D_16:
154          sz += 2;
155          break;
156       case TEXCOORDFMT_NOT_PRESENT:
157          break;
158       default:
159          fprintf(stderr, "bad texcoord fmt %d\n", i);
160          return GL_FALSE;
161       }
162       lis2 >>= S2_TEXCOORD_FMT1_SHIFT;
163    }
164
165    if (sz != expected)
166       fprintf(stderr, "vertex size mismatch %d/%d\n", sz, expected);
167
168    return sz == expected;
169 }
170
171
172 static void
173 i915_emit_invarient_state(struct intel_context *intel)
174 {
175    BATCH_LOCALS;
176
177    BEGIN_BATCH(17);
178
179    OUT_BATCH(_3DSTATE_AA_CMD |
180              AA_LINE_ECAAR_WIDTH_ENABLE |
181              AA_LINE_ECAAR_WIDTH_1_0 |
182              AA_LINE_REGION_WIDTH_ENABLE | AA_LINE_REGION_WIDTH_1_0);
183
184    OUT_BATCH(_3DSTATE_DFLT_DIFFUSE_CMD);
185    OUT_BATCH(0);
186
187    OUT_BATCH(_3DSTATE_DFLT_SPEC_CMD);
188    OUT_BATCH(0);
189
190    OUT_BATCH(_3DSTATE_DFLT_Z_CMD);
191    OUT_BATCH(0);
192
193    /* Don't support texture crossbar yet */
194    OUT_BATCH(_3DSTATE_COORD_SET_BINDINGS |
195              CSB_TCB(0, 0) |
196              CSB_TCB(1, 1) |
197              CSB_TCB(2, 2) |
198              CSB_TCB(3, 3) |
199              CSB_TCB(4, 4) | CSB_TCB(5, 5) | CSB_TCB(6, 6) | CSB_TCB(7, 7));
200
201    /* Need to initialize this to zero.
202     */
203    OUT_BATCH(_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(3) | (0));
204    OUT_BATCH(0);
205
206    /* XXX: Use this */
207    OUT_BATCH(_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
208
209    OUT_BATCH(_3DSTATE_SCISSOR_RECT_0_CMD);
210    OUT_BATCH(0);
211    OUT_BATCH(0);
212
213    OUT_BATCH(_3DSTATE_DEPTH_SUBRECT_DISABLE);
214
215    OUT_BATCH(_3DSTATE_LOAD_INDIRECT | 0);       /* disable indirect state */
216    OUT_BATCH(0);
217
218    ADVANCE_BATCH();
219 }
220
221
222 #define emit(intel, state, size )                    \
223    intel_batchbuffer_data(intel->batch, state, size)
224
225 static GLuint
226 get_dirty(struct i915_hw_state *state)
227 {
228    GLuint dirty;
229
230    /* Workaround the multitex hang - if one texture unit state is
231     * modified, emit all texture units.
232     */
233    dirty = state->active & ~state->emitted;
234    if (dirty & I915_UPLOAD_TEX_ALL)
235       state->emitted &= ~I915_UPLOAD_TEX_ALL;
236    dirty = state->active & ~state->emitted;
237    return dirty;
238 }
239
240
241 static GLuint
242 get_state_size(struct i915_hw_state *state)
243 {
244    GLuint dirty = get_dirty(state);
245    GLuint i;
246    GLuint sz = 0;
247
248    if (dirty & I915_UPLOAD_INVARIENT)
249       sz += 30 * 4;
250
251    if (dirty & I915_UPLOAD_RASTER_RULES)
252       sz += sizeof(state->RasterRules);
253
254    if (dirty & I915_UPLOAD_CTX)
255       sz += sizeof(state->Ctx);
256
257    if (dirty & I915_UPLOAD_BUFFERS)
258       sz += sizeof(state->Buffer);
259
260    if (dirty & I915_UPLOAD_STIPPLE)
261       sz += sizeof(state->Stipple);
262
263    if (dirty & I915_UPLOAD_FOG)
264       sz += sizeof(state->Fog);
265
266    if (dirty & I915_UPLOAD_TEX_ALL) {
267       int nr = 0;
268       for (i = 0; i < I915_TEX_UNITS; i++)
269          if (dirty & I915_UPLOAD_TEX(i))
270             nr++;
271
272       sz += (2 + nr * 3) * sizeof(GLuint) * 2;
273    }
274
275    if (dirty & I915_UPLOAD_CONSTANTS)
276       sz += state->ConstantSize * sizeof(GLuint);
277
278    if (dirty & I915_UPLOAD_PROGRAM)
279       sz += state->ProgramSize * sizeof(GLuint);
280
281    return sz;
282 }
283
284 /* Push the state into the sarea and/or texture memory.
285  */
286 static void
287 i915_emit_state(struct intel_context *intel)
288 {
289    struct i915_context *i915 = i915_context(&intel->ctx);
290    struct i915_hw_state *state = i915->current;
291    int i, count, aper_count;
292    GLuint dirty;
293    dri_bo *aper_array[3 + I915_TEX_UNITS];
294    GET_CURRENT_CONTEXT(ctx);
295    BATCH_LOCALS;
296
297    /* We don't hold the lock at this point, so want to make sure that
298     * there won't be a buffer wrap between the state emits and the primitive
299     * emit header.
300     *
301     * It might be better to talk about explicit places where
302     * scheduling is allowed, rather than assume that it is whenever a
303     * batchbuffer fills up.
304     */
305    intel_batchbuffer_require_space(intel->batch,
306                                    get_state_size(state) + INTEL_PRIM_EMIT_SIZE);
307    count = 0;
308  again:
309    aper_count = 0;
310    dirty = get_dirty(state);
311
312    aper_array[aper_count++] = intel->batch->buf;
313    if (dirty & I915_UPLOAD_BUFFERS) {
314       aper_array[aper_count++] = state->draw_region->buffer;
315       if (state->depth_region)
316          aper_array[aper_count++] = state->depth_region->buffer;
317    }
318
319    if (dirty & I915_UPLOAD_TEX_ALL) {
320       for (i = 0; i < I915_TEX_UNITS; i++) {
321          if (dirty & I915_UPLOAD_TEX(i)) {
322             if (state->tex_buffer[i]) {
323                aper_array[aper_count++] = state->tex_buffer[i];
324             }
325          }
326       }
327    }
328
329    if (dri_bufmgr_check_aperture_space(aper_array, aper_count)) {
330        if (count == 0) {
331            count++;
332            intel_batchbuffer_flush(intel->batch);
333            goto again;
334        } else {
335            _mesa_error(ctx, GL_OUT_OF_MEMORY, "i915 emit state");
336            assert(0);
337        }
338    }
339
340    /* work out list of buffers to emit */
341    
342    /* Do this here as we may have flushed the batchbuffer above,
343     * causing more state to be dirty!
344     */
345    dirty = get_dirty(state);
346    state->emitted |= dirty;
347    assert(get_dirty(state) == 0);
348
349    if (INTEL_DEBUG & DEBUG_STATE)
350       fprintf(stderr, "%s dirty: %x\n", __FUNCTION__, dirty);
351
352    if (dirty & I915_UPLOAD_INVARIENT) {
353       if (INTEL_DEBUG & DEBUG_STATE)
354          fprintf(stderr, "I915_UPLOAD_INVARIENT:\n");
355       i915_emit_invarient_state(intel);
356    }
357
358    if (dirty & I915_UPLOAD_RASTER_RULES) {
359       if (INTEL_DEBUG & DEBUG_STATE)
360          fprintf(stderr, "I915_UPLOAD_RASTER_RULES:\n");
361       emit(intel, state->RasterRules, sizeof(state->RasterRules));
362    }
363
364    if (dirty & I915_UPLOAD_CTX) {
365       if (INTEL_DEBUG & DEBUG_STATE)
366          fprintf(stderr, "I915_UPLOAD_CTX:\n");
367
368       emit(intel, state->Ctx, sizeof(state->Ctx));
369    }
370
371    if (dirty & I915_UPLOAD_BUFFERS) {
372       GLuint count = 15;
373
374       if (INTEL_DEBUG & DEBUG_STATE)
375          fprintf(stderr, "I915_UPLOAD_BUFFERS:\n");
376
377       if (state->depth_region)
378           count += 3;
379
380       BEGIN_BATCH(count);
381       OUT_BATCH(state->Buffer[I915_DESTREG_CBUFADDR0]);
382       OUT_BATCH(state->Buffer[I915_DESTREG_CBUFADDR1]);
383       OUT_RELOC(state->draw_region->buffer,
384                 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
385                 state->draw_region->draw_offset);
386
387       if (state->depth_region) {
388          OUT_BATCH(state->Buffer[I915_DESTREG_DBUFADDR0]);
389          OUT_BATCH(state->Buffer[I915_DESTREG_DBUFADDR1]);
390          OUT_RELOC(state->depth_region->buffer,
391                    I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
392                    state->depth_region->draw_offset);
393       }
394
395       OUT_BATCH(state->Buffer[I915_DESTREG_DV0]);
396       OUT_BATCH(state->Buffer[I915_DESTREG_DV1]);
397       OUT_BATCH(state->Buffer[I915_DESTREG_SENABLE]);
398       OUT_BATCH(state->Buffer[I915_DESTREG_SR0]);
399       OUT_BATCH(state->Buffer[I915_DESTREG_SR1]);
400       OUT_BATCH(state->Buffer[I915_DESTREG_SR2]);
401
402       assert(state->Buffer[I915_DESTREG_DRAWRECT0] != MI_NOOP);
403       OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT0]);
404       OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT1]);
405       OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT2]);
406       OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT3]);
407       OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT4]);
408       OUT_BATCH(state->Buffer[I915_DESTREG_DRAWRECT5]);
409
410       ADVANCE_BATCH();
411    }
412
413    if (dirty & I915_UPLOAD_STIPPLE) {
414       if (INTEL_DEBUG & DEBUG_STATE)
415          fprintf(stderr, "I915_UPLOAD_STIPPLE:\n");
416       emit(intel, state->Stipple, sizeof(state->Stipple));
417    }
418
419    if (dirty & I915_UPLOAD_FOG) {
420       if (INTEL_DEBUG & DEBUG_STATE)
421          fprintf(stderr, "I915_UPLOAD_FOG:\n");
422       emit(intel, state->Fog, sizeof(state->Fog));
423    }
424
425    /* Combine all the dirty texture state into a single command to
426     * avoid lockups on I915 hardware. 
427     */
428    if (dirty & I915_UPLOAD_TEX_ALL) {
429       int nr = 0;
430
431       for (i = 0; i < I915_TEX_UNITS; i++)
432          if (dirty & I915_UPLOAD_TEX(i))
433             nr++;
434
435       BEGIN_BATCH(2 + nr * 3);
436       OUT_BATCH(_3DSTATE_MAP_STATE | (3 * nr));
437       OUT_BATCH((dirty & I915_UPLOAD_TEX_ALL) >> I915_UPLOAD_TEX_0_SHIFT);
438       for (i = 0; i < I915_TEX_UNITS; i++)
439          if (dirty & I915_UPLOAD_TEX(i)) {
440
441             if (state->tex_buffer[i]) {
442                OUT_RELOC(state->tex_buffer[i],
443                          I915_GEM_DOMAIN_SAMPLER, 0,
444                          state->tex_offset[i]);
445             }
446             else if (state == &i915->meta) {
447                assert(i == 0);
448                OUT_BATCH(0);
449             }
450             else {
451                OUT_BATCH(state->tex_offset[i]);
452             }
453
454             OUT_BATCH(state->Tex[i][I915_TEXREG_MS3]);
455             OUT_BATCH(state->Tex[i][I915_TEXREG_MS4]);
456          }
457       ADVANCE_BATCH();
458
459       BEGIN_BATCH(2 + nr * 3);
460       OUT_BATCH(_3DSTATE_SAMPLER_STATE | (3 * nr));
461       OUT_BATCH((dirty & I915_UPLOAD_TEX_ALL) >> I915_UPLOAD_TEX_0_SHIFT);
462       for (i = 0; i < I915_TEX_UNITS; i++)
463          if (dirty & I915_UPLOAD_TEX(i)) {
464             OUT_BATCH(state->Tex[i][I915_TEXREG_SS2]);
465             OUT_BATCH(state->Tex[i][I915_TEXREG_SS3]);
466             OUT_BATCH(state->Tex[i][I915_TEXREG_SS4]);
467          }
468       ADVANCE_BATCH();
469    }
470
471    if (dirty & I915_UPLOAD_CONSTANTS) {
472       if (INTEL_DEBUG & DEBUG_STATE)
473          fprintf(stderr, "I915_UPLOAD_CONSTANTS:\n");
474       emit(intel, state->Constant, state->ConstantSize * sizeof(GLuint));
475    }
476
477    if (dirty & I915_UPLOAD_PROGRAM) {
478       if (state->ProgramSize) {
479          if (INTEL_DEBUG & DEBUG_STATE)
480             fprintf(stderr, "I915_UPLOAD_PROGRAM:\n");
481
482          assert((state->Program[0] & 0x1ff) + 2 == state->ProgramSize);
483
484          emit(intel, state->Program, state->ProgramSize * sizeof(GLuint));
485          if (INTEL_DEBUG & DEBUG_STATE)
486             i915_disassemble_program(state->Program, state->ProgramSize);
487       }
488    }
489
490    intel->batch->dirty_state &= ~dirty;
491    assert(get_dirty(state) == 0);
492    assert((intel->batch->dirty_state & (1<<1)) == 0);
493 }
494
495 static void
496 i915_destroy_context(struct intel_context *intel)
497 {
498    GLuint i;
499    struct i915_context *i915 = i915_context(&intel->ctx);
500
501    intel_region_release(&i915->state.draw_region);
502    intel_region_release(&i915->state.depth_region);
503    intel_region_release(&i915->meta.draw_region);
504    intel_region_release(&i915->meta.depth_region);
505    intel_region_release(&i915->initial.draw_region);
506    intel_region_release(&i915->initial.depth_region);
507
508    for (i = 0; i < I915_TEX_UNITS; i++) {
509       if (i915->state.tex_buffer[i] != NULL) {
510          dri_bo_unreference(i915->state.tex_buffer[i]);
511          i915->state.tex_buffer[i] = NULL;
512       }
513    }
514
515    _tnl_free_vertices(&intel->ctx);
516 }
517
518 void
519 i915_set_buf_info_for_region(uint32_t *state, struct intel_region *region,
520                              uint32_t buffer_id)
521 {
522    state[0] = _3DSTATE_BUF_INFO_CMD;
523    state[1] = buffer_id;
524
525    if (region != NULL) {
526       state[1] |= BUF_3D_PITCH(region->pitch * region->cpp);
527
528       if (region->tiling != I915_TILING_NONE) {
529          state[1] |= BUF_3D_TILED_SURFACE;
530          if (region->tiling == I915_TILING_Y)
531             state[1] |= BUF_3D_TILE_WALK_Y;
532       }
533    }
534 }
535
536 /**
537  * Set the drawing regions for the color and depth/stencil buffers.
538  * This involves setting the pitch, cpp and buffer ID/location.
539  * Also set pixel format for color and Z rendering
540  * Used for setting both regular and meta state.
541  */
542 void
543 i915_state_draw_region(struct intel_context *intel,
544                        struct i915_hw_state *state,
545                        struct intel_region *color_region,
546                        struct intel_region *depth_region)
547 {
548    struct i915_context *i915 = i915_context(&intel->ctx);
549    GLcontext *ctx = &intel->ctx;
550    struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
551    struct intel_renderbuffer *irb = intel_renderbuffer(rb);
552    GLuint value;
553
554    ASSERT(state == &i915->state || state == &i915->meta);
555
556    if (state->draw_region != color_region) {
557       intel_region_release(&state->draw_region);
558       intel_region_reference(&state->draw_region, color_region);
559    }
560    if (state->depth_region != depth_region) {
561       intel_region_release(&state->depth_region);
562       intel_region_reference(&state->depth_region, depth_region);
563    }
564
565    /*
566     * Set stride/cpp values
567     */
568    i915_set_buf_info_for_region(&state->Buffer[I915_DESTREG_CBUFADDR0],
569                                 color_region, BUF_3D_ID_COLOR_BACK);
570
571    i915_set_buf_info_for_region(&state->Buffer[I915_DESTREG_DBUFADDR0],
572                                 depth_region, BUF_3D_ID_DEPTH);
573
574    /*
575     * Compute/set I915_DESTREG_DV1 value
576     */
577    value = (DSTORG_HORT_BIAS(0x8) |     /* .5 */
578             DSTORG_VERT_BIAS(0x8) |     /* .5 */
579             LOD_PRECLAMP_OGL | TEX_DEFAULT_COLOR_OGL);
580    if (irb != NULL) {
581       switch (irb->Base.Format) {
582       case MESA_FORMAT_ARGB8888:
583       case MESA_FORMAT_XRGB8888:
584          value |= DV_PF_8888;
585          break;
586       case MESA_FORMAT_RGB565:
587          value |= DV_PF_565 | DITHER_FULL_ALWAYS;
588          break;
589       case MESA_FORMAT_ARGB1555:
590          value |= DV_PF_1555 | DITHER_FULL_ALWAYS;
591          break;
592       case MESA_FORMAT_ARGB4444:
593          value |= DV_PF_4444 | DITHER_FULL_ALWAYS;
594          break;
595       default:
596          _mesa_problem(ctx, "Bad renderbuffer format: %d\n",
597                        irb->Base.Format);
598       }
599    }
600
601    /* This isn't quite safe, thus being hidden behind an option.  When changing
602     * the value of this bit, the pipeline needs to be MI_FLUSHed.  And it
603     * can only be set when a depth buffer is already defined.
604     */
605    if (intel->is_945 && intel->use_early_z &&
606        depth_region->tiling != I915_TILING_NONE)
607       value |= CLASSIC_EARLY_DEPTH;
608
609    if (depth_region && depth_region->cpp == 4) {
610       value |= DEPTH_FRMT_24_FIXED_8_OTHER;
611    }
612    else {
613       value |= DEPTH_FRMT_16_FIXED;
614    }
615    state->Buffer[I915_DESTREG_DV1] = value;
616
617    state->Buffer[I915_DESTREG_DRAWRECT0] = _3DSTATE_DRAWRECT_INFO;
618    state->Buffer[I915_DESTREG_DRAWRECT1] = 0;
619    state->Buffer[I915_DESTREG_DRAWRECT2] = 0; /* xmin, ymin */
620    state->Buffer[I915_DESTREG_DRAWRECT3] =
621       (ctx->DrawBuffer->Width & 0xffff) |
622       (ctx->DrawBuffer->Height << 16);
623    state->Buffer[I915_DESTREG_DRAWRECT4] = 0; /* xoff, yoff */
624    state->Buffer[I915_DESTREG_DRAWRECT5] = 0;
625
626    I915_STATECHANGE(i915, I915_UPLOAD_BUFFERS);
627 }
628
629
630 static void
631 i915_set_draw_region(struct intel_context *intel,
632                      struct intel_region *color_regions[],
633                      struct intel_region *depth_region,
634                      GLuint num_regions)
635 {
636    struct i915_context *i915 = i915_context(&intel->ctx);
637    i915_state_draw_region(intel, &i915->state, color_regions[0], depth_region);
638 }
639
640
641
642 static void
643 i915_new_batch(struct intel_context *intel)
644 {
645    struct i915_context *i915 = i915_context(&intel->ctx);
646
647    /* Mark all state as needing to be emitted when starting a new batchbuffer.
648     * Using hardware contexts would be an alternative, but they have some
649     * difficulties associated with them (physical address requirements).
650     */
651    i915->state.emitted = 0;
652 }
653
654 static void 
655 i915_assert_not_dirty( struct intel_context *intel )
656 {
657    struct i915_context *i915 = i915_context(&intel->ctx);
658    struct i915_hw_state *state = i915->current;
659    GLuint dirty = get_dirty(state);
660    assert(!dirty);
661 }
662
663 void
664 i915InitVtbl(struct i915_context *i915)
665 {
666    i915->intel.vtbl.check_vertex_size = i915_check_vertex_size;
667    i915->intel.vtbl.destroy = i915_destroy_context;
668    i915->intel.vtbl.emit_state = i915_emit_state;
669    i915->intel.vtbl.new_batch = i915_new_batch;
670    i915->intel.vtbl.reduced_primitive_state = i915_reduced_primitive_state;
671    i915->intel.vtbl.render_start = i915_render_start;
672    i915->intel.vtbl.render_prevalidate = i915_render_prevalidate;
673    i915->intel.vtbl.set_draw_region = i915_set_draw_region;
674    i915->intel.vtbl.update_texture_state = i915UpdateTextureState;
675    i915->intel.vtbl.assert_not_dirty = i915_assert_not_dirty;
676    i915->intel.vtbl.finish_batch = intel_finish_vb;
677 }