i965: Fix typos in license
[mesa.git] / src / mesa / drivers / dri / i965 / brw_draw.c
1 /*
2 * Copyright 2003 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include <sys/errno.h>
27
28 #include "main/glheader.h"
29 #include "main/context.h"
30 #include "main/condrender.h"
31 #include "main/samplerobj.h"
32 #include "main/state.h"
33 #include "main/enums.h"
34 #include "main/macros.h"
35 #include "main/transformfeedback.h"
36 #include "tnl/tnl.h"
37 #include "vbo/vbo_context.h"
38 #include "swrast/swrast.h"
39 #include "swrast_setup/swrast_setup.h"
40 #include "drivers/common/meta.h"
41
42 #include "brw_blorp.h"
43 #include "brw_draw.h"
44 #include "brw_defines.h"
45 #include "brw_context.h"
46 #include "brw_state.h"
47 #include "brw_vs.h"
48
49 #include "intel_batchbuffer.h"
50 #include "intel_buffers.h"
51 #include "intel_fbo.h"
52 #include "intel_mipmap_tree.h"
53 #include "intel_buffer_objects.h"
54
55 #define FILE_DEBUG_FLAG DEBUG_PRIMS
56
57 static const GLuint prim_to_hw_prim[GL_TRIANGLE_STRIP_ADJACENCY+1] = {
58 _3DPRIM_POINTLIST,
59 _3DPRIM_LINELIST,
60 _3DPRIM_LINELOOP,
61 _3DPRIM_LINESTRIP,
62 _3DPRIM_TRILIST,
63 _3DPRIM_TRISTRIP,
64 _3DPRIM_TRIFAN,
65 _3DPRIM_QUADLIST,
66 _3DPRIM_QUADSTRIP,
67 _3DPRIM_POLYGON,
68 _3DPRIM_LINELIST_ADJ,
69 _3DPRIM_LINESTRIP_ADJ,
70 _3DPRIM_TRILIST_ADJ,
71 _3DPRIM_TRISTRIP_ADJ,
72 };
73
74
75 static const GLenum reduced_prim[GL_POLYGON+1] = {
76 GL_POINTS,
77 GL_LINES,
78 GL_LINES,
79 GL_LINES,
80 GL_TRIANGLES,
81 GL_TRIANGLES,
82 GL_TRIANGLES,
83 GL_TRIANGLES,
84 GL_TRIANGLES,
85 GL_TRIANGLES
86 };
87
88 uint32_t
89 get_hw_prim_for_gl_prim(int mode)
90 {
91 if (mode >= BRW_PRIM_OFFSET)
92 return mode - BRW_PRIM_OFFSET;
93 else {
94 assert(mode < ARRAY_SIZE(prim_to_hw_prim));
95 return prim_to_hw_prim[mode];
96 }
97 }
98
99
100 /* When the primitive changes, set a state bit and re-validate. Not
101 * the nicest and would rather deal with this by having all the
102 * programs be immune to the active primitive (ie. cope with all
103 * possibilities). That may not be realistic however.
104 */
105 static void
106 brw_set_prim(struct brw_context *brw, const struct _mesa_prim *prim)
107 {
108 struct gl_context *ctx = &brw->ctx;
109 uint32_t hw_prim = get_hw_prim_for_gl_prim(prim->mode);
110
111 DBG("PRIM: %s\n", _mesa_enum_to_string(prim->mode));
112
113 /* Slight optimization to avoid the GS program when not needed:
114 */
115 if (prim->mode == GL_QUAD_STRIP &&
116 ctx->Light.ShadeModel != GL_FLAT &&
117 ctx->Polygon.FrontMode == GL_FILL &&
118 ctx->Polygon.BackMode == GL_FILL)
119 hw_prim = _3DPRIM_TRISTRIP;
120
121 if (prim->mode == GL_QUADS && prim->count == 4 &&
122 ctx->Light.ShadeModel != GL_FLAT &&
123 ctx->Polygon.FrontMode == GL_FILL &&
124 ctx->Polygon.BackMode == GL_FILL) {
125 hw_prim = _3DPRIM_TRIFAN;
126 }
127
128 if (hw_prim != brw->primitive) {
129 brw->primitive = hw_prim;
130 brw->ctx.NewDriverState |= BRW_NEW_PRIMITIVE;
131
132 if (reduced_prim[prim->mode] != brw->reduced_primitive) {
133 brw->reduced_primitive = reduced_prim[prim->mode];
134 brw->ctx.NewDriverState |= BRW_NEW_REDUCED_PRIMITIVE;
135 }
136 }
137 }
138
139 static void
140 gen6_set_prim(struct brw_context *brw, const struct _mesa_prim *prim)
141 {
142 DBG("PRIM: %s\n", _mesa_enum_to_string(prim->mode));
143
144 const uint32_t hw_prim = get_hw_prim_for_gl_prim(prim->mode);
145 if (hw_prim != brw->primitive) {
146 brw->primitive = hw_prim;
147 brw->ctx.NewDriverState |= BRW_NEW_PRIMITIVE;
148 }
149 }
150
151
152 /**
153 * The hardware is capable of removing dangling vertices on its own; however,
154 * prior to Gen6, we sometimes convert quads into trifans (and quad strips
155 * into tristrips), since pre-Gen6 hardware requires a GS to render quads.
156 * This function manually trims dangling vertices from a draw call involving
157 * quads so that those dangling vertices won't get drawn when we convert to
158 * trifans/tristrips.
159 */
160 static GLuint
161 trim(GLenum prim, GLuint length)
162 {
163 if (prim == GL_QUAD_STRIP)
164 return length > 3 ? (length - length % 2) : 0;
165 else if (prim == GL_QUADS)
166 return length - length % 4;
167 else
168 return length;
169 }
170
171
172 static void
173 brw_emit_prim(struct brw_context *brw,
174 const struct _mesa_prim *prim,
175 uint32_t hw_prim)
176 {
177 int verts_per_instance;
178 int vertex_access_type;
179 int indirect_flag;
180
181 DBG("PRIM: %s %d %d\n", _mesa_enum_to_string(prim->mode),
182 prim->start, prim->count);
183
184 int start_vertex_location = prim->start;
185 int base_vertex_location = prim->basevertex;
186
187 if (prim->indexed) {
188 vertex_access_type = brw->gen >= 7 ?
189 GEN7_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM :
190 GEN4_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM;
191 start_vertex_location += brw->ib.start_vertex_offset;
192 base_vertex_location += brw->vb.start_vertex_bias;
193 } else {
194 vertex_access_type = brw->gen >= 7 ?
195 GEN7_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL :
196 GEN4_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL;
197 start_vertex_location += brw->vb.start_vertex_bias;
198 }
199
200 /* We only need to trim the primitive count on pre-Gen6. */
201 if (brw->gen < 6)
202 verts_per_instance = trim(prim->mode, prim->count);
203 else
204 verts_per_instance = prim->count;
205
206 /* If nothing to emit, just return. */
207 if (verts_per_instance == 0 && !prim->is_indirect)
208 return;
209
210 /* If we're set to always flush, do it before and after the primitive emit.
211 * We want to catch both missed flushes that hurt instruction/state cache
212 * and missed flushes of the render cache as it heads to other parts of
213 * the besides the draw code.
214 */
215 if (brw->always_flush_cache)
216 brw_emit_mi_flush(brw);
217
218 /* If indirect, emit a bunch of loads from the indirect BO. */
219 if (prim->is_indirect) {
220 struct gl_buffer_object *indirect_buffer = brw->ctx.DrawIndirectBuffer;
221 drm_intel_bo *bo = intel_bufferobj_buffer(brw,
222 intel_buffer_object(indirect_buffer),
223 prim->indirect_offset, 5 * sizeof(GLuint));
224
225 indirect_flag = GEN7_3DPRIM_INDIRECT_PARAMETER_ENABLE;
226
227 brw_load_register_mem(brw, GEN7_3DPRIM_VERTEX_COUNT, bo,
228 I915_GEM_DOMAIN_VERTEX, 0,
229 prim->indirect_offset + 0);
230 brw_load_register_mem(brw, GEN7_3DPRIM_INSTANCE_COUNT, bo,
231 I915_GEM_DOMAIN_VERTEX, 0,
232 prim->indirect_offset + 4);
233
234 brw_load_register_mem(brw, GEN7_3DPRIM_START_VERTEX, bo,
235 I915_GEM_DOMAIN_VERTEX, 0,
236 prim->indirect_offset + 8);
237 if (prim->indexed) {
238 brw_load_register_mem(brw, GEN7_3DPRIM_BASE_VERTEX, bo,
239 I915_GEM_DOMAIN_VERTEX, 0,
240 prim->indirect_offset + 12);
241 brw_load_register_mem(brw, GEN7_3DPRIM_START_INSTANCE, bo,
242 I915_GEM_DOMAIN_VERTEX, 0,
243 prim->indirect_offset + 16);
244 } else {
245 brw_load_register_mem(brw, GEN7_3DPRIM_START_INSTANCE, bo,
246 I915_GEM_DOMAIN_VERTEX, 0,
247 prim->indirect_offset + 12);
248 BEGIN_BATCH(3);
249 OUT_BATCH(MI_LOAD_REGISTER_IMM | (3 - 2));
250 OUT_BATCH(GEN7_3DPRIM_BASE_VERTEX);
251 OUT_BATCH(0);
252 ADVANCE_BATCH();
253 }
254 } else {
255 indirect_flag = 0;
256 }
257
258 BEGIN_BATCH(brw->gen >= 7 ? 7 : 6);
259
260 if (brw->gen >= 7) {
261 const int predicate_enable =
262 (brw->predicate.state == BRW_PREDICATE_STATE_USE_BIT)
263 ? GEN7_3DPRIM_PREDICATE_ENABLE : 0;
264
265 OUT_BATCH(CMD_3D_PRIM << 16 | (7 - 2) | indirect_flag | predicate_enable);
266 OUT_BATCH(hw_prim | vertex_access_type);
267 } else {
268 OUT_BATCH(CMD_3D_PRIM << 16 | (6 - 2) |
269 hw_prim << GEN4_3DPRIM_TOPOLOGY_TYPE_SHIFT |
270 vertex_access_type);
271 }
272 OUT_BATCH(verts_per_instance);
273 OUT_BATCH(start_vertex_location);
274 OUT_BATCH(prim->num_instances);
275 OUT_BATCH(prim->base_instance);
276 OUT_BATCH(base_vertex_location);
277 ADVANCE_BATCH();
278
279 if (brw->always_flush_cache)
280 brw_emit_mi_flush(brw);
281 }
282
283
284 static void
285 brw_merge_inputs(struct brw_context *brw,
286 const struct gl_client_array *arrays[])
287 {
288 const struct gl_context *ctx = &brw->ctx;
289 GLuint i;
290
291 for (i = 0; i < brw->vb.nr_buffers; i++) {
292 drm_intel_bo_unreference(brw->vb.buffers[i].bo);
293 brw->vb.buffers[i].bo = NULL;
294 }
295 brw->vb.nr_buffers = 0;
296
297 for (i = 0; i < VERT_ATTRIB_MAX; i++) {
298 brw->vb.inputs[i].buffer = -1;
299 brw->vb.inputs[i].glarray = arrays[i];
300 }
301
302 if (brw->gen < 8 && !brw->is_haswell) {
303 struct gl_program *vp = &ctx->VertexProgram._Current->Base;
304 /* Prior to Haswell, the hardware can't natively support GL_FIXED or
305 * 2_10_10_10_REV vertex formats. Set appropriate workaround flags.
306 */
307 for (i = 0; i < VERT_ATTRIB_MAX; i++) {
308 if (!(vp->InputsRead & BITFIELD64_BIT(i)))
309 continue;
310
311 uint8_t wa_flags = 0;
312
313 switch (brw->vb.inputs[i].glarray->Type) {
314
315 case GL_FIXED:
316 wa_flags = brw->vb.inputs[i].glarray->Size;
317 break;
318
319 case GL_INT_2_10_10_10_REV:
320 wa_flags |= BRW_ATTRIB_WA_SIGN;
321 /* fallthough */
322
323 case GL_UNSIGNED_INT_2_10_10_10_REV:
324 if (brw->vb.inputs[i].glarray->Format == GL_BGRA)
325 wa_flags |= BRW_ATTRIB_WA_BGRA;
326
327 if (brw->vb.inputs[i].glarray->Normalized)
328 wa_flags |= BRW_ATTRIB_WA_NORMALIZE;
329 else if (!brw->vb.inputs[i].glarray->Integer)
330 wa_flags |= BRW_ATTRIB_WA_SCALE;
331
332 break;
333 }
334
335 if (brw->vb.attrib_wa_flags[i] != wa_flags) {
336 brw->vb.attrib_wa_flags[i] = wa_flags;
337 brw->ctx.NewDriverState |= BRW_NEW_VS_ATTRIB_WORKAROUNDS;
338 }
339 }
340 }
341 }
342
343 /**
344 * \brief Call this after drawing to mark which buffers need resolving
345 *
346 * If the depth buffer was written to and if it has an accompanying HiZ
347 * buffer, then mark that it needs a depth resolve.
348 *
349 * If the color buffer is a multisample window system buffer, then
350 * mark that it needs a downsample.
351 *
352 * Also mark any render targets which will be textured as needing a render
353 * cache flush.
354 */
355 static void
356 brw_postdraw_set_buffers_need_resolve(struct brw_context *brw)
357 {
358 struct gl_context *ctx = &brw->ctx;
359 struct gl_framebuffer *fb = ctx->DrawBuffer;
360
361 struct intel_renderbuffer *front_irb = NULL;
362 struct intel_renderbuffer *back_irb = intel_get_renderbuffer(fb, BUFFER_BACK_LEFT);
363 struct intel_renderbuffer *depth_irb = intel_get_renderbuffer(fb, BUFFER_DEPTH);
364 struct intel_renderbuffer *stencil_irb = intel_get_renderbuffer(fb, BUFFER_STENCIL);
365 struct gl_renderbuffer_attachment *depth_att = &fb->Attachment[BUFFER_DEPTH];
366
367 if (brw_is_front_buffer_drawing(fb))
368 front_irb = intel_get_renderbuffer(fb, BUFFER_FRONT_LEFT);
369
370 if (front_irb)
371 front_irb->need_downsample = true;
372 if (back_irb)
373 back_irb->need_downsample = true;
374 if (depth_irb && ctx->Depth.Mask) {
375 intel_renderbuffer_att_set_needs_depth_resolve(depth_att);
376 brw_render_cache_set_add_bo(brw, depth_irb->mt->bo);
377 }
378
379 if (ctx->Extensions.ARB_stencil_texturing &&
380 stencil_irb && ctx->Stencil._WriteEnabled) {
381 brw_render_cache_set_add_bo(brw, stencil_irb->mt->bo);
382 }
383
384 for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) {
385 struct intel_renderbuffer *irb =
386 intel_renderbuffer(fb->_ColorDrawBuffers[i]);
387
388 if (irb)
389 brw_render_cache_set_add_bo(brw, irb->mt->bo);
390 }
391 }
392
393 /* May fail if out of video memory for texture or vbo upload, or on
394 * fallback conditions.
395 */
396 static void
397 brw_try_draw_prims(struct gl_context *ctx,
398 const struct gl_client_array *arrays[],
399 const struct _mesa_prim *prims,
400 GLuint nr_prims,
401 const struct _mesa_index_buffer *ib,
402 GLuint min_index,
403 GLuint max_index,
404 struct gl_buffer_object *indirect)
405 {
406 struct brw_context *brw = brw_context(ctx);
407 GLuint i;
408 bool fail_next = false;
409
410 if (ctx->NewState)
411 _mesa_update_state(ctx);
412
413 /* Find the highest sampler unit used by each shader program. A bit-count
414 * won't work since ARB programs use the texture unit number as the sampler
415 * index.
416 */
417 brw->wm.base.sampler_count =
418 _mesa_fls(ctx->FragmentProgram._Current->Base.SamplersUsed);
419 brw->gs.base.sampler_count = ctx->GeometryProgram._Current ?
420 _mesa_fls(ctx->GeometryProgram._Current->Base.SamplersUsed) : 0;
421 brw->vs.base.sampler_count =
422 _mesa_fls(ctx->VertexProgram._Current->Base.SamplersUsed);
423
424 /* We have to validate the textures *before* checking for fallbacks;
425 * otherwise, the software fallback won't be able to rely on the
426 * texture state, the firstLevel and lastLevel fields won't be
427 * set in the intel texture object (they'll both be 0), and the
428 * software fallback will segfault if it attempts to access any
429 * texture level other than level 0.
430 */
431 brw_validate_textures(brw);
432
433 intel_prepare_render(brw);
434
435 /* This workaround has to happen outside of brw_upload_render_state()
436 * because it may flush the batchbuffer for a blit, affecting the state
437 * flags.
438 */
439 brw_workaround_depthstencil_alignment(brw, 0);
440
441 /* Bind all inputs, derive varying and size information:
442 */
443 brw_merge_inputs(brw, arrays);
444
445 brw->ib.ib = ib;
446 brw->ctx.NewDriverState |= BRW_NEW_INDICES;
447
448 brw->vb.min_index = min_index;
449 brw->vb.max_index = max_index;
450 brw->ctx.NewDriverState |= BRW_NEW_VERTICES;
451
452 for (i = 0; i < nr_prims; i++) {
453 int estimated_max_prim_size;
454 const int sampler_state_size = 16;
455
456 estimated_max_prim_size = 512; /* batchbuffer commands */
457 estimated_max_prim_size += BRW_MAX_TEX_UNIT *
458 (sampler_state_size + sizeof(struct gen5_sampler_default_color));
459 estimated_max_prim_size += 1024; /* gen6 VS push constants */
460 estimated_max_prim_size += 1024; /* gen6 WM push constants */
461 estimated_max_prim_size += 512; /* misc. pad */
462
463 /* Flush the batch if it's approaching full, so that we don't wrap while
464 * we've got validated state that needs to be in the same batch as the
465 * primitives.
466 */
467 intel_batchbuffer_require_space(brw, estimated_max_prim_size, RENDER_RING);
468 intel_batchbuffer_save_state(brw);
469
470 if (brw->num_instances != prims[i].num_instances ||
471 brw->basevertex != prims[i].basevertex) {
472 brw->num_instances = prims[i].num_instances;
473 brw->basevertex = prims[i].basevertex;
474 if (i > 0) { /* For i == 0 we just did this before the loop */
475 brw->ctx.NewDriverState |= BRW_NEW_VERTICES;
476 brw_merge_inputs(brw, arrays);
477 }
478 }
479
480 brw->draw.gl_basevertex =
481 prims[i].indexed ? prims[i].basevertex : prims[i].start;
482
483 drm_intel_bo_unreference(brw->draw.draw_params_bo);
484
485 if (prims[i].is_indirect) {
486 /* Point draw_params_bo at the indirect buffer. */
487 brw->draw.draw_params_bo =
488 intel_buffer_object(ctx->DrawIndirectBuffer)->buffer;
489 drm_intel_bo_reference(brw->draw.draw_params_bo);
490 brw->draw.draw_params_offset =
491 prims[i].indirect_offset + (prims[i].indexed ? 12 : 8);
492 } else {
493 /* Set draw_params_bo to NULL so brw_prepare_vertices knows it
494 * has to upload gl_BaseVertex and such if they're needed.
495 */
496 brw->draw.draw_params_bo = NULL;
497 brw->draw.draw_params_offset = 0;
498 }
499
500 if (brw->gen < 6)
501 brw_set_prim(brw, &prims[i]);
502 else
503 gen6_set_prim(brw, &prims[i]);
504
505 retry:
506
507 /* Note that before the loop, brw->ctx.NewDriverState was set to != 0, and
508 * that the state updated in the loop outside of this block is that in
509 * *_set_prim or intel_batchbuffer_flush(), which only impacts
510 * brw->ctx.NewDriverState.
511 */
512 if (brw->ctx.NewDriverState) {
513 brw->no_batch_wrap = true;
514 brw_upload_render_state(brw);
515 }
516
517 brw_emit_prim(brw, &prims[i], brw->primitive);
518
519 brw->no_batch_wrap = false;
520
521 if (dri_bufmgr_check_aperture_space(&brw->batch.bo, 1)) {
522 if (!fail_next) {
523 intel_batchbuffer_reset_to_saved(brw);
524 intel_batchbuffer_flush(brw);
525 fail_next = true;
526 goto retry;
527 } else {
528 int ret = intel_batchbuffer_flush(brw);
529 WARN_ONCE(ret == -ENOSPC,
530 "i965: Single primitive emit exceeded "
531 "available aperture space\n");
532 }
533 }
534
535 /* Now that we know we haven't run out of aperture space, we can safely
536 * reset the dirty bits.
537 */
538 if (brw->ctx.NewDriverState)
539 brw_render_state_finished(brw);
540 }
541
542 if (brw->always_flush_batch)
543 intel_batchbuffer_flush(brw);
544
545 brw_state_cache_check_size(brw);
546 brw_postdraw_set_buffers_need_resolve(brw);
547
548 return;
549 }
550
551 void
552 brw_draw_prims(struct gl_context *ctx,
553 const struct _mesa_prim *prims,
554 GLuint nr_prims,
555 const struct _mesa_index_buffer *ib,
556 GLboolean index_bounds_valid,
557 GLuint min_index,
558 GLuint max_index,
559 struct gl_transform_feedback_object *unused_tfb_object,
560 unsigned stream,
561 struct gl_buffer_object *indirect)
562 {
563 struct brw_context *brw = brw_context(ctx);
564 const struct gl_client_array **arrays = ctx->Array._DrawArrays;
565
566 assert(unused_tfb_object == NULL);
567
568 if (!brw_check_conditional_render(brw))
569 return;
570
571 /* Handle primitive restart if needed */
572 if (brw_handle_primitive_restart(ctx, prims, nr_prims, ib, indirect)) {
573 /* The draw was handled, so we can exit now */
574 return;
575 }
576
577 /* Do GL_SELECT and GL_FEEDBACK rendering using swrast, even though it
578 * won't support all the extensions we support.
579 */
580 if (ctx->RenderMode != GL_RENDER) {
581 perf_debug("%s render mode not supported in hardware\n",
582 _mesa_enum_to_string(ctx->RenderMode));
583 _swsetup_Wakeup(ctx);
584 _tnl_wakeup(ctx);
585 _tnl_draw_prims(ctx, prims, nr_prims, ib,
586 index_bounds_valid, min_index, max_index, NULL, 0, NULL);
587 return;
588 }
589
590 /* If we're going to have to upload any of the user's vertex arrays, then
591 * get the minimum and maximum of their index buffer so we know what range
592 * to upload.
593 */
594 if (!index_bounds_valid && !vbo_all_varyings_in_vbos(arrays)) {
595 perf_debug("Scanning index buffer to compute index buffer bounds. "
596 "Use glDrawRangeElements() to avoid this.\n");
597 vbo_get_minmax_indices(ctx, prims, ib, &min_index, &max_index, nr_prims);
598 }
599
600 /* Try drawing with the hardware, but don't do anything else if we can't
601 * manage it. swrast doesn't support our featureset, so we can't fall back
602 * to it.
603 */
604 brw_try_draw_prims(ctx, arrays, prims, nr_prims, ib, min_index, max_index,
605 indirect);
606 }
607
608 void
609 brw_draw_init(struct brw_context *brw)
610 {
611 struct gl_context *ctx = &brw->ctx;
612 struct vbo_context *vbo = vbo_context(ctx);
613
614 /* Register our drawing function:
615 */
616 vbo->draw_prims = brw_draw_prims;
617
618 for (int i = 0; i < VERT_ATTRIB_MAX; i++)
619 brw->vb.inputs[i].buffer = -1;
620 brw->vb.nr_buffers = 0;
621 brw->vb.nr_enabled = 0;
622 }
623
624 void
625 brw_draw_destroy(struct brw_context *brw)
626 {
627 unsigned i;
628
629 for (i = 0; i < brw->vb.nr_buffers; i++) {
630 drm_intel_bo_unreference(brw->vb.buffers[i].bo);
631 brw->vb.buffers[i].bo = NULL;
632 }
633 brw->vb.nr_buffers = 0;
634
635 for (i = 0; i < brw->vb.nr_enabled; i++) {
636 brw->vb.enabled[i]->buffer = -1;
637 }
638 brw->vb.nr_enabled = 0;
639
640 drm_intel_bo_unreference(brw->ib.bo);
641 brw->ib.bo = NULL;
642 }