OSDN Git Service

[965] Add a wrapper around interleaved copy_array_to_vbo_array for profiling.
[android-x86/external-mesa.git] / src / mesa / drivers / dri / i965 / brw_draw_upload.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 #include <stdlib.h>
29
30 #include "glheader.h"
31 #include "context.h"
32 #include "state.h"
33 #include "api_validate.h"
34 #include "enums.h"
35
36 #include "brw_draw.h"
37 #include "brw_defines.h"
38 #include "brw_context.h"
39 #include "brw_state.h"
40 #include "brw_fallback.h"
41
42 #include "intel_ioctl.h"
43 #include "intel_batchbuffer.h"
44 #include "intel_buffer_objects.h"
45 #include "intel_tex.h"
46
47 struct brw_array_state {
48    union header_union header;
49
50    struct {
51       union {
52          struct {
53             GLuint pitch:11; 
54             GLuint pad:15;
55             GLuint access_type:1; 
56             GLuint vb_index:5; 
57          } bits;
58          GLuint dword;
59       } vb0;
60    
61       dri_bo *buffer;
62       GLuint offset;
63
64       GLuint max_index;   
65       GLuint instance_data_step_rate;
66
67    } vb[BRW_VBP_MAX];
68 };
69
70
71 static dri_bo *array_buffer( struct intel_context *intel,
72                              const struct gl_client_array *array )
73 {
74    return intel_bufferobj_buffer(intel, intel_buffer_object(array->BufferObj),
75                                  INTEL_WRITE_PART);
76 }
77
78 static GLuint double_types[5] = {
79    0,
80    BRW_SURFACEFORMAT_R64_FLOAT,
81    BRW_SURFACEFORMAT_R64G64_FLOAT,
82    BRW_SURFACEFORMAT_R64G64B64_FLOAT,
83    BRW_SURFACEFORMAT_R64G64B64A64_FLOAT
84 };
85
86 static GLuint float_types[5] = {
87    0,
88    BRW_SURFACEFORMAT_R32_FLOAT,
89    BRW_SURFACEFORMAT_R32G32_FLOAT,
90    BRW_SURFACEFORMAT_R32G32B32_FLOAT,
91    BRW_SURFACEFORMAT_R32G32B32A32_FLOAT
92 };
93
94 static GLuint uint_types_norm[5] = {
95    0,
96    BRW_SURFACEFORMAT_R32_UNORM,
97    BRW_SURFACEFORMAT_R32G32_UNORM,
98    BRW_SURFACEFORMAT_R32G32B32_UNORM,
99    BRW_SURFACEFORMAT_R32G32B32A32_UNORM
100 };
101
102 static GLuint uint_types_scale[5] = {
103    0,
104    BRW_SURFACEFORMAT_R32_USCALED,
105    BRW_SURFACEFORMAT_R32G32_USCALED,
106    BRW_SURFACEFORMAT_R32G32B32_USCALED,
107    BRW_SURFACEFORMAT_R32G32B32A32_USCALED
108 };
109
110 static GLuint int_types_norm[5] = {
111    0,
112    BRW_SURFACEFORMAT_R32_SNORM,
113    BRW_SURFACEFORMAT_R32G32_SNORM,
114    BRW_SURFACEFORMAT_R32G32B32_SNORM,
115    BRW_SURFACEFORMAT_R32G32B32A32_SNORM
116 };
117
118 static GLuint int_types_scale[5] = {
119    0,
120    BRW_SURFACEFORMAT_R32_SSCALED,
121    BRW_SURFACEFORMAT_R32G32_SSCALED,
122    BRW_SURFACEFORMAT_R32G32B32_SSCALED,
123    BRW_SURFACEFORMAT_R32G32B32A32_SSCALED
124 };
125
126 static GLuint ushort_types_norm[5] = {
127    0,
128    BRW_SURFACEFORMAT_R16_UNORM,
129    BRW_SURFACEFORMAT_R16G16_UNORM,
130    BRW_SURFACEFORMAT_R16G16B16_UNORM,
131    BRW_SURFACEFORMAT_R16G16B16A16_UNORM
132 };
133
134 static GLuint ushort_types_scale[5] = {
135    0,
136    BRW_SURFACEFORMAT_R16_USCALED,
137    BRW_SURFACEFORMAT_R16G16_USCALED,
138    BRW_SURFACEFORMAT_R16G16B16_USCALED,
139    BRW_SURFACEFORMAT_R16G16B16A16_USCALED
140 };
141
142 static GLuint short_types_norm[5] = {
143    0,
144    BRW_SURFACEFORMAT_R16_SNORM,
145    BRW_SURFACEFORMAT_R16G16_SNORM,
146    BRW_SURFACEFORMAT_R16G16B16_SNORM,
147    BRW_SURFACEFORMAT_R16G16B16A16_SNORM
148 };
149
150 static GLuint short_types_scale[5] = {
151    0,
152    BRW_SURFACEFORMAT_R16_SSCALED,
153    BRW_SURFACEFORMAT_R16G16_SSCALED,
154    BRW_SURFACEFORMAT_R16G16B16_SSCALED,
155    BRW_SURFACEFORMAT_R16G16B16A16_SSCALED
156 };
157
158 static GLuint ubyte_types_norm[5] = {
159    0,
160    BRW_SURFACEFORMAT_R8_UNORM,
161    BRW_SURFACEFORMAT_R8G8_UNORM,
162    BRW_SURFACEFORMAT_R8G8B8_UNORM,
163    BRW_SURFACEFORMAT_R8G8B8A8_UNORM
164 };
165
166 static GLuint ubyte_types_scale[5] = {
167    0,
168    BRW_SURFACEFORMAT_R8_USCALED,
169    BRW_SURFACEFORMAT_R8G8_USCALED,
170    BRW_SURFACEFORMAT_R8G8B8_USCALED,
171    BRW_SURFACEFORMAT_R8G8B8A8_USCALED
172 };
173
174 static GLuint byte_types_norm[5] = {
175    0,
176    BRW_SURFACEFORMAT_R8_SNORM,
177    BRW_SURFACEFORMAT_R8G8_SNORM,
178    BRW_SURFACEFORMAT_R8G8B8_SNORM,
179    BRW_SURFACEFORMAT_R8G8B8A8_SNORM
180 };
181
182 static GLuint byte_types_scale[5] = {
183    0,
184    BRW_SURFACEFORMAT_R8_SSCALED,
185    BRW_SURFACEFORMAT_R8G8_SSCALED,
186    BRW_SURFACEFORMAT_R8G8B8_SSCALED,
187    BRW_SURFACEFORMAT_R8G8B8A8_SSCALED
188 };
189
190
191 static GLuint get_surface_type( GLenum type, GLuint size, GLboolean normalized )
192 {
193    if (INTEL_DEBUG & DEBUG_VERTS)
194       _mesa_printf("type %s size %d normalized %d\n", 
195                    _mesa_lookup_enum_by_nr(type), size, normalized);
196
197    if (normalized) {
198       switch (type) {
199       case GL_DOUBLE: return double_types[size];
200       case GL_FLOAT: return float_types[size];
201       case GL_INT: return int_types_norm[size];
202       case GL_SHORT: return short_types_norm[size];
203       case GL_BYTE: return byte_types_norm[size];
204       case GL_UNSIGNED_INT: return uint_types_norm[size];
205       case GL_UNSIGNED_SHORT: return ushort_types_norm[size];
206       case GL_UNSIGNED_BYTE: return ubyte_types_norm[size];
207       default: assert(0); return 0;
208       }      
209    }
210    else {
211       switch (type) {
212       case GL_DOUBLE: return double_types[size];
213       case GL_FLOAT: return float_types[size];
214       case GL_INT: return int_types_scale[size];
215       case GL_SHORT: return short_types_scale[size];
216       case GL_BYTE: return byte_types_scale[size];
217       case GL_UNSIGNED_INT: return uint_types_scale[size];
218       case GL_UNSIGNED_SHORT: return ushort_types_scale[size];
219       case GL_UNSIGNED_BYTE: return ubyte_types_scale[size];
220       default: assert(0); return 0;
221       }      
222    }
223 }
224
225
226 static GLuint get_size( GLenum type )
227 {
228    switch (type) {
229    case GL_DOUBLE: return sizeof(GLdouble);
230    case GL_FLOAT: return sizeof(GLfloat);
231    case GL_INT: return sizeof(GLint);
232    case GL_SHORT: return sizeof(GLshort);
233    case GL_BYTE: return sizeof(GLbyte);
234    case GL_UNSIGNED_INT: return sizeof(GLuint);
235    case GL_UNSIGNED_SHORT: return sizeof(GLushort);
236    case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
237    default: return 0;
238    }      
239 }
240
241 static GLuint get_index_type(GLenum type) 
242 {
243    switch (type) {
244    case GL_UNSIGNED_BYTE:  return BRW_INDEX_BYTE;
245    case GL_UNSIGNED_SHORT: return BRW_INDEX_WORD;
246    case GL_UNSIGNED_INT:   return BRW_INDEX_DWORD;
247    default: assert(0); return 0;
248    }
249 }
250
251 static void copy_strided_array( GLubyte *dest, 
252                                 const GLubyte *src, 
253                                 GLuint size, 
254                                 GLuint stride,
255                                 GLuint count )
256 {
257    if (size == stride) 
258       memcpy(dest, src, count * size);
259    else {
260       GLuint i;
261    
262       for (i = 0; i < count; i++) {
263          memcpy(dest, src, size);
264          src += stride;
265          dest += size;
266       }
267    }
268 }
269
270 static void wrap_buffers( struct brw_context *brw,
271                           GLuint size )
272 {
273    GLcontext *ctx = &brw->intel.ctx;
274
275    if (size < BRW_UPLOAD_INIT_SIZE)
276       size = BRW_UPLOAD_INIT_SIZE;
277
278    brw->vb.upload.buf++;
279    brw->vb.upload.buf %= BRW_NR_UPLOAD_BUFS;
280    brw->vb.upload.offset = 0;
281
282    ctx->Driver.BufferData(ctx,
283                           GL_ARRAY_BUFFER_ARB,
284                           size,
285                           NULL,
286                           GL_DYNAMIC_DRAW_ARB,
287                           brw->vb.upload.vbo[brw->vb.upload.buf]);
288 }
289
290 static void get_space( struct brw_context *brw,
291                        GLuint size,
292                        struct gl_buffer_object **vbo_return,
293                        GLuint *offset_return )
294 {
295    size = ALIGN(size, 64);
296    
297    if (brw->vb.upload.offset + size > BRW_UPLOAD_INIT_SIZE)
298       wrap_buffers(brw, size);
299
300    *vbo_return = brw->vb.upload.vbo[brw->vb.upload.buf];
301    *offset_return = brw->vb.upload.offset;
302
303    brw->vb.upload.offset += size;
304 }
305
306 static struct gl_client_array *
307 copy_array_to_vbo_array( struct brw_context *brw,
308                          GLuint i,
309                          const struct gl_client_array *array,
310                          GLuint element_size,
311                          GLuint count)
312 {
313    GLcontext *ctx = &brw->intel.ctx;
314    struct gl_client_array *vbo_array = &brw->vb.vbo_array[i];
315    GLuint size = count * element_size;
316    struct gl_buffer_object *vbo;
317    GLuint offset;
318    GLuint new_stride;
319
320    get_space(brw, size, &vbo, &offset);
321
322    if (array->StrideB == 0) {
323       assert(count == 1);
324       new_stride = 0;
325    }
326    else 
327       new_stride = element_size;
328
329    vbo_array->Size = array->Size;
330    vbo_array->Type = array->Type;
331    vbo_array->Stride = new_stride;
332    vbo_array->StrideB = new_stride;   
333    vbo_array->Ptr = (const void *)offset;
334    vbo_array->Enabled = 1;
335    vbo_array->Normalized = array->Normalized;
336    vbo_array->_MaxElement = array->_MaxElement; /* ? */
337    vbo_array->BufferObj = vbo;
338
339    {
340       GLubyte *map = ctx->Driver.MapBuffer(ctx,
341                                            GL_ARRAY_BUFFER_ARB,
342                                            GL_DYNAMIC_DRAW_ARB,
343                                            vbo);
344    
345       map += offset;
346
347       copy_strided_array( map, 
348                           array->Ptr,
349                           element_size,
350                           array->StrideB,
351                           count);
352
353       ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB, vbo_array->BufferObj);
354    }
355
356    return vbo_array;
357 }
358
359 /**
360  * Just a wrapper to highlight which cause of copy_array_to_vbo_array
361  * is happening in the profile.
362  */
363 static struct gl_client_array *
364 interleaved_copy_array_to_vbo_array(struct brw_context *brw,
365                                     GLuint i,
366                                     const struct gl_client_array *array,
367                                     GLuint element_size,
368                                     GLuint count)
369 {
370    return copy_array_to_vbo_array(brw, i, array, element_size, count);
371 }
372
373 static struct gl_client_array *
374 interleaved_vbo_array( struct brw_context *brw,
375                        GLuint i,
376                        const struct gl_client_array *uploaded_array,
377                        const struct gl_client_array *array,
378                        const char *ptr)
379 {
380    struct gl_client_array *vbo_array = &brw->vb.vbo_array[i];
381
382    vbo_array->Size = array->Size;
383    vbo_array->Type = array->Type;
384    vbo_array->Stride = array->Stride;
385    vbo_array->StrideB = array->StrideB;   
386    vbo_array->Ptr = (const void *)((const char *)uploaded_array->Ptr + 
387                                    ((const char *)array->Ptr - ptr));
388    vbo_array->Enabled = 1;
389    vbo_array->Normalized = array->Normalized;
390    vbo_array->_MaxElement = array->_MaxElement; 
391    vbo_array->BufferObj = uploaded_array->BufferObj;
392
393    return vbo_array;
394 }
395
396
397 GLboolean brw_upload_vertices( struct brw_context *brw,
398                                GLuint min_index,
399                                GLuint max_index )
400 {
401    GLcontext *ctx = &brw->intel.ctx;
402    struct intel_context *intel = intel_context(ctx);
403    GLuint tmp = brw->vs.prog_data->inputs_read; 
404    GLuint i;
405    const void *ptr = NULL;
406    GLuint interleave = 0;
407
408    struct brw_vertex_element *enabled[VERT_ATTRIB_MAX];
409    GLuint nr_enabled = 0;
410
411    struct brw_vertex_element *upload[VERT_ATTRIB_MAX];
412    GLuint nr_uploads = 0;
413
414    /* First build an array of pointers to ve's in vb.inputs_read
415     */
416    if (0)
417       _mesa_printf("%s %d..%d\n", __FUNCTION__, min_index, max_index);
418    
419    while (tmp) {
420       GLuint i = _mesa_ffsll(tmp)-1;
421       struct brw_vertex_element *input = &brw->vb.inputs[i];
422
423       tmp &= ~(1<<i);
424       enabled[nr_enabled++] = input;
425
426       input->index = i;
427       input->element_size = get_size(input->glarray->Type) * input->glarray->Size;
428       input->count = input->glarray->StrideB ? max_index + 1 - min_index : 1;
429
430       if (!input->glarray->BufferObj->Name) {
431          if (i == 0) {
432             /* Position array not properly enabled:
433              */
434             if (input->glarray->StrideB == 0)
435                return GL_FALSE;
436
437             interleave = input->glarray->StrideB;
438             ptr = input->glarray->Ptr;
439          }
440          else if (interleave != input->glarray->StrideB ||
441                   (const char *)input->glarray->Ptr - (const char *)ptr < 0 ||
442                   (const char *)input->glarray->Ptr - (const char *)ptr > interleave) {
443             interleave = 0;
444          }
445
446          upload[nr_uploads++] = input;
447          
448          /* We rebase drawing to start at element zero only when
449           * varyings are not in vbos, which means we can end up
450           * uploading non-varying arrays (stride != 0) when min_index
451           * is zero.  This doesn't matter as the amount to upload is
452           * the same for these arrays whether the draw call is rebased
453           * or not - we just have to upload the one element.
454           */
455          assert(min_index == 0 || input->glarray->StrideB == 0);
456       }
457    }
458
459    /* Upload interleaved arrays if all uploads are interleaved
460     */
461    if (nr_uploads > 1 && 
462        interleave && 
463        interleave <= 256) {
464       upload[0]->glarray =
465          interleaved_copy_array_to_vbo_array(brw, 0,
466                                              upload[0]->glarray,
467                                              interleave,
468                                              upload[0]->count);
469
470       for (i = 1; i < nr_uploads; i++) {
471          upload[i]->glarray = interleaved_vbo_array(brw,
472                                                     i,
473                                                     upload[0]->glarray,
474                                                     upload[i]->glarray,
475                                                     ptr);
476       }
477    }
478    else {
479       for (i = 0; i < nr_uploads; i++) {
480          upload[i]->glarray = copy_array_to_vbo_array(brw, i,
481                                                       upload[i]->glarray,
482                                                       upload[i]->element_size,
483                                                       upload[i]->count);
484
485       }
486    }
487
488    /* XXX: In the rare cases where this happens we fallback all
489     * the way to software rasterization, although a tnl fallback
490     * would be sufficient.  I don't know of *any* real world
491     * cases with > 17 vertex attributes enabled, so it probably
492     * isn't an issue at this point.
493     */
494    if (nr_enabled >= BRW_VEP_MAX)
495          return GL_FALSE;
496
497    /* Now emit VB and VEP state packets.
498     *
499     * This still defines a hardware VB for each input, even if they
500     * are interleaved or from the same VBO.  TBD if this makes a
501     * performance difference.
502     */
503    BEGIN_BATCH(1 + nr_enabled * 4, IGNORE_CLIPRECTS);
504    OUT_BATCH((CMD_VERTEX_BUFFER << 16) |
505              ((1 + nr_enabled * 4) - 2));
506
507    for (i = 0; i < nr_enabled; i++) {
508       struct brw_vertex_element *input = enabled[i];
509
510       OUT_BATCH((i << BRW_VB0_INDEX_SHIFT) |
511                 BRW_VB0_ACCESS_VERTEXDATA |
512                 (input->glarray->StrideB << BRW_VB0_PITCH_SHIFT));
513       OUT_RELOC(array_buffer(intel, input->glarray),
514                 DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ,
515                 (GLuint)input->glarray->Ptr);
516       OUT_BATCH(max_index);
517       OUT_BATCH(0); /* Instance data step rate */
518    }
519    ADVANCE_BATCH();
520
521    BEGIN_BATCH(1 + nr_enabled * 2, IGNORE_CLIPRECTS);
522    OUT_BATCH((CMD_VERTEX_ELEMENT << 16) | ((1 + nr_enabled * 2) - 2));
523    for (i = 0; i < nr_enabled; i++) {
524       struct brw_vertex_element *input = enabled[i];
525       uint32_t format = get_surface_type(input->glarray->Type,
526                                          input->glarray->Size,
527                                          input->glarray->Normalized);
528       uint32_t comp0 = BRW_VE1_COMPONENT_STORE_SRC;
529       uint32_t comp1 = BRW_VE1_COMPONENT_STORE_SRC;
530       uint32_t comp2 = BRW_VE1_COMPONENT_STORE_SRC;
531       uint32_t comp3 = BRW_VE1_COMPONENT_STORE_SRC;
532
533       switch (input->glarray->Size) {
534       case 0: comp0 = BRW_VE1_COMPONENT_STORE_0;
535       case 1: comp1 = BRW_VE1_COMPONENT_STORE_0;
536       case 2: comp2 = BRW_VE1_COMPONENT_STORE_0;
537       case 3: comp3 = BRW_VE1_COMPONENT_STORE_1_FLT;
538          break;
539       }
540
541       OUT_BATCH((i << BRW_VE0_INDEX_SHIFT) |
542                 BRW_VE0_VALID |
543                 (format << BRW_VE0_FORMAT_SHIFT) |
544                 (0 << BRW_VE0_SRC_OFFSET_SHIFT));
545       OUT_BATCH((comp0 << BRW_VE1_COMPONENT_0_SHIFT) |
546                 (comp1 << BRW_VE1_COMPONENT_1_SHIFT) |
547                 (comp2 << BRW_VE1_COMPONENT_2_SHIFT) |
548                 (comp3 << BRW_VE1_COMPONENT_3_SHIFT) |
549                 ((i * 4) << BRW_VE1_DST_OFFSET_SHIFT));
550    }
551    ADVANCE_BATCH();
552
553    return GL_TRUE;
554 }
555
556 void brw_upload_indices( struct brw_context *brw,
557                          const struct _mesa_index_buffer *index_buffer )
558 {
559    GLcontext *ctx = &brw->intel.ctx;
560    struct intel_context *intel = &brw->intel;
561    GLuint ib_size = get_size(index_buffer->type) * index_buffer->count;
562    struct gl_buffer_object *bufferobj = index_buffer->obj;
563    GLuint offset = (GLuint)index_buffer->ptr;
564
565    /* Turn into a proper VBO:
566     */
567    if (!bufferobj->Name) {
568      
569       /* Get new bufferobj, offset:
570        */
571       get_space(brw, ib_size, &bufferobj, &offset);
572
573       /* Straight upload
574        */
575       ctx->Driver.BufferSubData( ctx,
576                                  GL_ELEMENT_ARRAY_BUFFER_ARB,
577                                  offset, 
578                                  ib_size,
579                                  index_buffer->ptr,
580                                  bufferobj);
581    } else {
582       /* If the index buffer isn't aligned to its element size, we have to
583        * rebase it into a temporary.
584        */
585        if ((get_size(index_buffer->type) - 1) & offset) {
586            struct gl_buffer_object *vbo;
587            GLuint voffset;
588            GLubyte *map = ctx->Driver.MapBuffer(ctx,
589                                                 GL_ELEMENT_ARRAY_BUFFER_ARB,
590                                                 GL_DYNAMIC_DRAW_ARB,
591                                                 bufferobj);
592            map += offset;
593            get_space(brw, ib_size, &vbo, &voffset);
594            
595            ctx->Driver.BufferSubData(ctx,
596                                      GL_ELEMENT_ARRAY_BUFFER_ARB,
597                                      voffset,
598                                      ib_size,
599                                      map,
600                                      vbo);
601            ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, bufferobj);
602
603            bufferobj = vbo;
604            offset = voffset;
605        }
606    }
607
608    /* Emit the indexbuffer packet:
609     */
610    {
611       struct brw_indexbuffer ib;
612       dri_bo *buffer = intel_bufferobj_buffer(intel,
613                                               intel_buffer_object(bufferobj),
614                                               INTEL_READ);
615
616       memset(&ib, 0, sizeof(ib));
617    
618       ib.header.bits.opcode = CMD_INDEX_BUFFER;
619       ib.header.bits.length = sizeof(ib)/4 - 2;
620       ib.header.bits.index_format = get_index_type(index_buffer->type);
621       ib.header.bits.cut_index_enable = 0;
622    
623
624       BEGIN_BATCH(4, IGNORE_CLIPRECTS);
625       OUT_BATCH( ib.header.dword );
626       OUT_RELOC( buffer, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ, offset);
627       OUT_RELOC( buffer, DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_READ,
628                  offset + ib_size);
629       OUT_BATCH( 0 );
630       ADVANCE_BATCH();
631    }
632 }