Upload of interleaved arrays currently assumes that position is the
[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_attrib.h"
39 #include "brw_context.h"
40 #include "brw_aub.h"
41 #include "brw_state.h"
42 #include "brw_fallback.h"
43
44 #include "intel_ioctl.h"
45 #include "intel_batchbuffer.h"
46 #include "intel_buffer_objects.h"
47
48
49 struct brw_array_state {
50 union header_union header;
51
52 struct {
53 union {
54 struct {
55 GLuint pitch:11;
56 GLuint pad:15;
57 GLuint access_type:1;
58 GLuint vb_index:5;
59 } bits;
60 GLuint dword;
61 } vb0;
62
63 struct buffer *buffer;
64 GLuint offset;
65
66 GLuint max_index;
67 GLuint instance_data_step_rate;
68
69 } vb[BRW_VBP_MAX];
70 };
71
72
73 static struct buffer *array_buffer( const struct gl_client_array *array )
74 {
75 return intel_bufferobj_buffer(intel_buffer_object(array->BufferObj));
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 do_memcpy(dest, src, count * size);
259 else {
260 GLuint i,j;
261
262 for (i = 0; i < count; i++) {
263 for (j = 0; j < size; j++)
264 *dest++ = *src++;
265 src += (stride - 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 = (size + 63) & ~63;
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
307
308 static struct gl_client_array *
309 copy_array_to_vbo_array( struct brw_context *brw,
310 GLuint i,
311 const struct gl_client_array *array,
312 GLuint element_size,
313 GLuint min_index,
314 GLuint count)
315 {
316 GLcontext *ctx = &brw->intel.ctx;
317 struct gl_client_array *vbo_array = &brw->vb.vbo_array[i];
318 GLuint size = count * element_size;
319 struct gl_buffer_object *vbo;
320 GLuint offset;
321 GLuint new_stride;
322
323 get_space(brw, size, &vbo, &offset);
324
325 if (array->StrideB == 0) {
326 assert(count == 1);
327 new_stride = 0;
328 }
329 else
330 new_stride = element_size;
331
332 vbo_array->Size = array->Size;
333 vbo_array->Type = array->Type;
334 vbo_array->Stride = new_stride;
335 vbo_array->StrideB = new_stride;
336 vbo_array->Ptr = (const void *)offset;
337 vbo_array->Enabled = 1;
338 vbo_array->Normalized = array->Normalized;
339 vbo_array->_MaxElement = array->_MaxElement; /* ? */
340 vbo_array->Flags = array->Flags; /* ? */
341 vbo_array->BufferObj = vbo;
342
343 {
344 GLubyte *map = ctx->Driver.MapBuffer(ctx,
345 GL_ARRAY_BUFFER_ARB,
346 GL_DYNAMIC_DRAW_ARB,
347 vbo);
348
349 map += offset;
350
351 copy_strided_array( map,
352 array->Ptr + min_index * array->StrideB,
353 element_size,
354 array->StrideB,
355 count);
356
357 ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB, vbo_array->BufferObj);
358 }
359
360 return vbo_array;
361 }
362
363
364
365 static struct gl_client_array *
366 interleaved_vbo_array( struct brw_context *brw,
367 GLuint i,
368 const struct gl_client_array *uploaded_array,
369 const struct gl_client_array *array,
370 const char *ptr)
371 {
372 struct gl_client_array *vbo_array = &brw->vb.vbo_array[i];
373
374 vbo_array->Size = array->Size;
375 vbo_array->Type = array->Type;
376 vbo_array->Stride = array->Stride;
377 vbo_array->StrideB = array->StrideB;
378 vbo_array->Ptr = (const void *)((const char *)uploaded_array->Ptr +
379 ((const char *)array->Ptr - ptr));
380 vbo_array->Enabled = 1;
381 vbo_array->Normalized = array->Normalized;
382 vbo_array->_MaxElement = array->_MaxElement;
383 vbo_array->Flags = array->Flags; /* ? */
384 vbo_array->BufferObj = uploaded_array->BufferObj;
385
386 return vbo_array;
387 }
388
389
390 GLboolean brw_upload_vertices( struct brw_context *brw,
391 GLuint min_index,
392 GLuint max_index )
393 {
394 GLcontext *ctx = &brw->intel.ctx;
395 struct intel_context *intel = intel_context(ctx);
396 GLuint tmp = brw->vs.prog_data->inputs_read;
397 struct brw_vertex_element_packet vep;
398 struct brw_array_state vbp;
399 GLuint i;
400 const void *ptr = NULL;
401 GLuint interleave = 0;
402
403 struct brw_vertex_element *enabled[BRW_ATTRIB_MAX];
404 GLuint nr_enabled = 0;
405
406 struct brw_vertex_element *upload[BRW_ATTRIB_MAX];
407 GLuint nr_uploads = 0;
408
409
410 memset(&vbp, 0, sizeof(vbp));
411 memset(&vep, 0, sizeof(vep));
412
413 /* First build an array of pointers to ve's in vb.inputs_read
414 */
415
416 while (tmp) {
417 GLuint i = ffs(tmp)-1;
418 struct brw_vertex_element *input = &brw->vb.inputs[i];
419
420 tmp &= ~(1<<i);
421 enabled[nr_enabled++] = input;
422
423 input->index = i;
424 input->element_size = get_size(input->glarray->Type) * input->glarray->Size;
425 input->count = input->glarray->StrideB ? max_index - min_index : 1;
426
427 if (!input->glarray->BufferObj->Name) {
428 if (i == 0) {
429 /* Position array not properly enabled:
430 */
431 if (input->glarray->StrideB == 0)
432 return GL_FALSE;
433
434 interleave = input->glarray->StrideB;
435 ptr = input->glarray->Ptr;
436 }
437 else if (interleave != input->glarray->StrideB ||
438 (const char *)input->glarray->Ptr - (const char *)ptr < 0 ||
439 (const char *)input->glarray->Ptr - (const char *)ptr > interleave) {
440 interleave = 0;
441 }
442
443 upload[nr_uploads++] = input;
444 input->vbo_rebase_offset = 0;
445 }
446 else
447 input->vbo_rebase_offset = min_index * input->glarray->StrideB;
448 }
449
450 /* Upload interleaved arrays if all uploads are interleaved
451 */
452 if (nr_uploads > 1 &&
453 interleave &&
454 interleave <= 256) {
455 struct brw_vertex_element *input0 = upload[0];
456
457 input0->glarray = copy_array_to_vbo_array(brw, 0,
458 input0->glarray,
459 interleave,
460 min_index,
461 input0->count);
462
463 for (i = 1; i < nr_uploads; i++) {
464 upload[i]->glarray = interleaved_vbo_array(brw,
465 i,
466 input0->glarray,
467 upload[i]->glarray,
468 ptr);
469 }
470 }
471 else {
472 for (i = 0; i < nr_uploads; i++) {
473 struct brw_vertex_element *input = upload[i];
474
475 input->glarray = copy_array_to_vbo_array(brw, i,
476 input->glarray,
477 input->element_size,
478 min_index,
479 input->count);
480
481 }
482 }
483
484 /* XXX: In the rare cases where this happens we fallback all
485 * the way to software rasterization, although a tnl fallback
486 * would be sufficient. I don't know of *any* real world
487 * cases with > 17 vertex attributes enabled, so it probably
488 * isn't an issue at this point.
489 */
490 if (nr_enabled >= BRW_VEP_MAX)
491 return GL_FALSE;
492
493 /* This still defines a hardware VB for each input, even if they
494 * are interleaved or from the same VBO. TBD if this makes a
495 * performance difference.
496 */
497 for (i = 0; i < nr_enabled; i++) {
498 struct brw_vertex_element *input = enabled[i];
499
500 input->vep = &vep.ve[i];
501 input->vep->ve0.src_format = get_surface_type(input->glarray->Type,
502 input->glarray->Size,
503 input->glarray->Normalized);
504 input->vep->ve0.valid = 1;
505 input->vep->ve1.dst_offset = (i) * 4;
506 input->vep->ve1.vfcomponent3 = BRW_VFCOMPONENT_STORE_SRC;
507 input->vep->ve1.vfcomponent2 = BRW_VFCOMPONENT_STORE_SRC;
508 input->vep->ve1.vfcomponent1 = BRW_VFCOMPONENT_STORE_SRC;
509 input->vep->ve1.vfcomponent0 = BRW_VFCOMPONENT_STORE_SRC;
510
511 switch (input->glarray->Size) {
512 case 0: input->vep->ve1.vfcomponent0 = BRW_VFCOMPONENT_STORE_0;
513 case 1: input->vep->ve1.vfcomponent1 = BRW_VFCOMPONENT_STORE_0;
514 case 2: input->vep->ve1.vfcomponent2 = BRW_VFCOMPONENT_STORE_0;
515 case 3: input->vep->ve1.vfcomponent3 = BRW_VFCOMPONENT_STORE_1_FLT;
516 break;
517 }
518
519 input->vep->ve0.vertex_buffer_index = i;
520 input->vep->ve0.src_offset = 0;
521
522 vbp.vb[i].vb0.bits.pitch = input->glarray->StrideB;
523 vbp.vb[i].vb0.bits.pad = 0;
524 vbp.vb[i].vb0.bits.access_type = BRW_VERTEXBUFFER_ACCESS_VERTEXDATA;
525 vbp.vb[i].vb0.bits.vb_index = i;
526 vbp.vb[i].offset = (GLuint)input->glarray->Ptr + input->vbo_rebase_offset;
527 vbp.vb[i].buffer = array_buffer(input->glarray);
528 vbp.vb[i].max_index = max_index - min_index;
529 }
530
531
532
533 /* Now emit VB and VEP state packets:
534 */
535 vbp.header.bits.length = (1 + nr_enabled * 4) - 2;
536 vbp.header.bits.opcode = CMD_VERTEX_BUFFER;
537
538 BEGIN_BATCH(vbp.header.bits.length+2, 0);
539 OUT_BATCH( vbp.header.dword );
540
541 for (i = 0; i < nr_enabled; i++) {
542 OUT_BATCH( vbp.vb[i].vb0.dword );
543 OUT_BATCH( bmBufferOffset(&brw->intel, vbp.vb[i].buffer) + vbp.vb[i].offset);
544 OUT_BATCH( vbp.vb[i].max_index );
545 OUT_BATCH( vbp.vb[i].instance_data_step_rate );
546 }
547 ADVANCE_BATCH();
548
549 vep.header.length = (1 + nr_enabled * sizeof(vep.ve[0])/4) - 2;
550 vep.header.opcode = CMD_VERTEX_ELEMENT;
551 brw_cached_batch_struct(brw, &vep, 4 + nr_enabled * sizeof(vep.ve[0]));
552
553 return GL_TRUE;
554 }
555
556
557 static GLuint element_size( GLenum type )
558 {
559 switch(type) {
560 case GL_UNSIGNED_INT: return 4;
561 case GL_UNSIGNED_SHORT: return 2;
562 case GL_UNSIGNED_BYTE: return 1;
563 default: assert(0); return 0;
564 }
565 }
566
567
568
569
570 static void rebase_indices_to_vbo_indices( struct brw_context *brw,
571 const struct brw_draw_index_buffer *index_buffer,
572 struct gl_buffer_object **vbo_return,
573 GLuint *offset_return )
574 {
575 GLcontext *ctx = &brw->intel.ctx;
576 GLuint min_index = index_buffer->rebase;
577 const void *indices = index_buffer->ptr;
578 GLsizei count = index_buffer->count;
579 GLenum type = index_buffer->type;
580 GLuint size = element_size(type) * count;
581 struct gl_buffer_object *bufferobj;
582 GLuint offset;
583 GLuint i;
584
585 get_space(brw, size, &bufferobj, &offset);
586
587 *vbo_return = bufferobj;
588 *offset_return = offset;
589
590 if (min_index == 0) {
591 /* Straight upload
592 */
593 ctx->Driver.BufferSubData( ctx,
594 GL_ELEMENT_ARRAY_BUFFER_ARB,
595 offset,
596 size,
597 indices,
598 bufferobj);
599 }
600 else {
601 void *map = ctx->Driver.MapBuffer(ctx,
602 GL_ELEMENT_ARRAY_BUFFER_ARB,
603 GL_DYNAMIC_DRAW_ARB,
604 bufferobj);
605
606 map += offset;
607
608 switch (type) {
609 case GL_UNSIGNED_INT: {
610 GLuint *ui_map = (GLuint *)map;
611 const GLuint *ui_indices = (const GLuint *)indices;
612
613 for (i = 0; i < count; i++)
614 ui_map[i] = ui_indices[i] - min_index;
615 break;
616 }
617 case GL_UNSIGNED_SHORT: {
618 GLushort *us_map = (GLushort *)map;
619 const GLushort *us_indices = (const GLushort *)indices;
620
621 for (i = 0; i < count; i++)
622 us_map[i] = us_indices[i] - min_index;
623 break;
624 }
625 case GL_UNSIGNED_BYTE: {
626 GLubyte *ub_map = (GLubyte *)map;
627 const GLubyte *ub_indices = (const GLubyte *)indices;
628
629 for (i = 0; i < count; i++)
630 ub_map[i] = ub_indices[i] - min_index;
631 break;
632 }
633 }
634
635 ctx->Driver.UnmapBuffer(ctx,
636 GL_ELEMENT_ARRAY_BUFFER_ARB,
637 bufferobj);
638
639 }
640 }
641
642
643
644 void brw_upload_indices( struct brw_context *brw,
645 const struct brw_draw_index_buffer *index_buffer)
646 {
647 struct intel_context *intel = &brw->intel;
648 GLuint ib_size = get_size(index_buffer->type) * index_buffer->count;
649 struct gl_buffer_object *bufferobj = index_buffer->obj;
650 GLuint offset = (GLuint)index_buffer->ptr;
651
652 /* Already turned into a proper VBO:
653 */
654 if (!index_buffer->obj->Name) {
655 rebase_indices_to_vbo_indices(brw, index_buffer, &bufferobj, &offset );
656 }
657
658 /* Emit the indexbuffer packet:
659 */
660 {
661 struct brw_indexbuffer ib;
662 struct buffer *buffer = intel_bufferobj_buffer(intel_buffer_object(bufferobj));
663
664 memset(&ib, 0, sizeof(ib));
665
666 ib.header.bits.opcode = CMD_INDEX_BUFFER;
667 ib.header.bits.length = sizeof(ib)/4 - 2;
668 ib.header.bits.index_format = get_index_type(index_buffer->type);
669 ib.header.bits.cut_index_enable = 0;
670
671
672 BEGIN_BATCH(4, 0);
673 OUT_BATCH( ib.header.dword );
674 OUT_BATCH( bmBufferOffset(intel, buffer) + offset );
675 OUT_BATCH( bmBufferOffset(intel, buffer) + offset + ib_size );
676 OUT_BATCH( 0 );
677 ADVANCE_BATCH();
678 }
679 }