OSDN Git Service

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