2 * Copyright 2003 VMware, Inc.
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
26 #include <sys/errno.h>
28 #include "main/context.h"
29 #include "main/condrender.h"
30 #include "main/samplerobj.h"
31 #include "main/state.h"
32 #include "main/enums.h"
33 #include "main/macros.h"
34 #include "main/transformfeedback.h"
35 #include "main/framebuffer.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 #include "util/bitscan.h"
43 #include "brw_blorp.h"
45 #include "brw_defines.h"
46 #include "brw_context.h"
47 #include "brw_state.h"
50 #include "intel_batchbuffer.h"
51 #include "intel_buffers.h"
52 #include "intel_fbo.h"
53 #include "intel_mipmap_tree.h"
54 #include "intel_buffer_objects.h"
56 #define FILE_DEBUG_FLAG DEBUG_PRIMS
59 static const GLenum reduced_prim
[GL_POLYGON
+1] = {
60 [GL_POINTS
] = GL_POINTS
,
61 [GL_LINES
] = GL_LINES
,
62 [GL_LINE_LOOP
] = GL_LINES
,
63 [GL_LINE_STRIP
] = GL_LINES
,
64 [GL_TRIANGLES
] = GL_TRIANGLES
,
65 [GL_TRIANGLE_STRIP
] = GL_TRIANGLES
,
66 [GL_TRIANGLE_FAN
] = GL_TRIANGLES
,
67 [GL_QUADS
] = GL_TRIANGLES
,
68 [GL_QUAD_STRIP
] = GL_TRIANGLES
,
69 [GL_POLYGON
] = GL_TRIANGLES
72 /* When the primitive changes, set a state bit and re-validate. Not
73 * the nicest and would rather deal with this by having all the
74 * programs be immune to the active primitive (ie. cope with all
75 * possibilities). That may not be realistic however.
78 brw_set_prim(struct brw_context
*brw
, const struct _mesa_prim
*prim
)
80 struct gl_context
*ctx
= &brw
->ctx
;
81 uint32_t hw_prim
= get_hw_prim_for_gl_prim(prim
->mode
);
83 DBG("PRIM: %s\n", _mesa_enum_to_string(prim
->mode
));
85 /* Slight optimization to avoid the GS program when not needed:
87 if (prim
->mode
== GL_QUAD_STRIP
&&
88 ctx
->Light
.ShadeModel
!= GL_FLAT
&&
89 ctx
->Polygon
.FrontMode
== GL_FILL
&&
90 ctx
->Polygon
.BackMode
== GL_FILL
)
91 hw_prim
= _3DPRIM_TRISTRIP
;
93 if (prim
->mode
== GL_QUADS
&& prim
->count
== 4 &&
94 ctx
->Light
.ShadeModel
!= GL_FLAT
&&
95 ctx
->Polygon
.FrontMode
== GL_FILL
&&
96 ctx
->Polygon
.BackMode
== GL_FILL
) {
97 hw_prim
= _3DPRIM_TRIFAN
;
100 if (hw_prim
!= brw
->primitive
) {
101 brw
->primitive
= hw_prim
;
102 brw
->ctx
.NewDriverState
|= BRW_NEW_PRIMITIVE
;
104 if (reduced_prim
[prim
->mode
] != brw
->reduced_primitive
) {
105 brw
->reduced_primitive
= reduced_prim
[prim
->mode
];
106 brw
->ctx
.NewDriverState
|= BRW_NEW_REDUCED_PRIMITIVE
;
112 gen6_set_prim(struct brw_context
*brw
, const struct _mesa_prim
*prim
)
114 const struct gl_context
*ctx
= &brw
->ctx
;
117 DBG("PRIM: %s\n", _mesa_enum_to_string(prim
->mode
));
119 if (prim
->mode
== GL_PATCHES
) {
120 hw_prim
= _3DPRIM_PATCHLIST(ctx
->TessCtrlProgram
.patch_vertices
);
122 hw_prim
= get_hw_prim_for_gl_prim(prim
->mode
);
125 if (hw_prim
!= brw
->primitive
) {
126 brw
->primitive
= hw_prim
;
127 brw
->ctx
.NewDriverState
|= BRW_NEW_PRIMITIVE
;
128 if (prim
->mode
== GL_PATCHES
)
129 brw
->ctx
.NewDriverState
|= BRW_NEW_PATCH_PRIMITIVE
;
135 * The hardware is capable of removing dangling vertices on its own; however,
136 * prior to Gen6, we sometimes convert quads into trifans (and quad strips
137 * into tristrips), since pre-Gen6 hardware requires a GS to render quads.
138 * This function manually trims dangling vertices from a draw call involving
139 * quads so that those dangling vertices won't get drawn when we convert to
143 trim(GLenum prim
, GLuint length
)
145 if (prim
== GL_QUAD_STRIP
)
146 return length
> 3 ? (length
- length
% 2) : 0;
147 else if (prim
== GL_QUADS
)
148 return length
- length
% 4;
155 brw_emit_prim(struct brw_context
*brw
,
156 const struct _mesa_prim
*prim
,
158 struct brw_transform_feedback_object
*xfb_obj
,
161 int verts_per_instance
;
162 int vertex_access_type
;
165 DBG("PRIM: %s %d %d\n", _mesa_enum_to_string(prim
->mode
),
166 prim
->start
, prim
->count
);
168 int start_vertex_location
= prim
->start
;
169 int base_vertex_location
= prim
->basevertex
;
172 vertex_access_type
= brw
->gen
>= 7 ?
173 GEN7_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM
:
174 GEN4_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM
;
175 start_vertex_location
+= brw
->ib
.start_vertex_offset
;
176 base_vertex_location
+= brw
->vb
.start_vertex_bias
;
178 vertex_access_type
= brw
->gen
>= 7 ?
179 GEN7_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL
:
180 GEN4_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL
;
181 start_vertex_location
+= brw
->vb
.start_vertex_bias
;
184 /* We only need to trim the primitive count on pre-Gen6. */
186 verts_per_instance
= trim(prim
->mode
, prim
->count
);
188 verts_per_instance
= prim
->count
;
190 /* If nothing to emit, just return. */
191 if (verts_per_instance
== 0 && !prim
->is_indirect
&& !xfb_obj
)
194 /* If we're set to always flush, do it before and after the primitive emit.
195 * We want to catch both missed flushes that hurt instruction/state cache
196 * and missed flushes of the render cache as it heads to other parts of
197 * the besides the draw code.
199 if (brw
->always_flush_cache
)
200 brw_emit_mi_flush(brw
);
202 /* If indirect, emit a bunch of loads from the indirect BO. */
204 indirect_flag
= GEN7_3DPRIM_INDIRECT_PARAMETER_ENABLE
;
206 brw_load_register_mem(brw
, GEN7_3DPRIM_VERTEX_COUNT
,
207 xfb_obj
->prim_count_bo
,
208 I915_GEM_DOMAIN_VERTEX
, 0,
209 stream
* sizeof(uint32_t));
211 OUT_BATCH(MI_LOAD_REGISTER_IMM
| (9 - 2));
212 OUT_BATCH(GEN7_3DPRIM_INSTANCE_COUNT
);
213 OUT_BATCH(prim
->num_instances
);
214 OUT_BATCH(GEN7_3DPRIM_START_VERTEX
);
216 OUT_BATCH(GEN7_3DPRIM_BASE_VERTEX
);
218 OUT_BATCH(GEN7_3DPRIM_START_INSTANCE
);
221 } else if (prim
->is_indirect
) {
222 struct gl_buffer_object
*indirect_buffer
= brw
->ctx
.DrawIndirectBuffer
;
223 drm_intel_bo
*bo
= intel_bufferobj_buffer(brw
,
224 intel_buffer_object(indirect_buffer
),
225 prim
->indirect_offset
, 5 * sizeof(GLuint
));
227 indirect_flag
= GEN7_3DPRIM_INDIRECT_PARAMETER_ENABLE
;
229 brw_load_register_mem(brw
, GEN7_3DPRIM_VERTEX_COUNT
, bo
,
230 I915_GEM_DOMAIN_VERTEX
, 0,
231 prim
->indirect_offset
+ 0);
232 brw_load_register_mem(brw
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
,
233 I915_GEM_DOMAIN_VERTEX
, 0,
234 prim
->indirect_offset
+ 4);
236 brw_load_register_mem(brw
, GEN7_3DPRIM_START_VERTEX
, bo
,
237 I915_GEM_DOMAIN_VERTEX
, 0,
238 prim
->indirect_offset
+ 8);
240 brw_load_register_mem(brw
, GEN7_3DPRIM_BASE_VERTEX
, bo
,
241 I915_GEM_DOMAIN_VERTEX
, 0,
242 prim
->indirect_offset
+ 12);
243 brw_load_register_mem(brw
, GEN7_3DPRIM_START_INSTANCE
, bo
,
244 I915_GEM_DOMAIN_VERTEX
, 0,
245 prim
->indirect_offset
+ 16);
247 brw_load_register_mem(brw
, GEN7_3DPRIM_START_INSTANCE
, bo
,
248 I915_GEM_DOMAIN_VERTEX
, 0,
249 prim
->indirect_offset
+ 12);
251 OUT_BATCH(MI_LOAD_REGISTER_IMM
| (3 - 2));
252 OUT_BATCH(GEN7_3DPRIM_BASE_VERTEX
);
260 BEGIN_BATCH(brw
->gen
>= 7 ? 7 : 6);
263 const int predicate_enable
=
264 (brw
->predicate
.state
== BRW_PREDICATE_STATE_USE_BIT
)
265 ? GEN7_3DPRIM_PREDICATE_ENABLE
: 0;
267 OUT_BATCH(CMD_3D_PRIM
<< 16 | (7 - 2) | indirect_flag
| predicate_enable
);
268 OUT_BATCH(hw_prim
| vertex_access_type
);
270 OUT_BATCH(CMD_3D_PRIM
<< 16 | (6 - 2) |
271 hw_prim
<< GEN4_3DPRIM_TOPOLOGY_TYPE_SHIFT
|
274 OUT_BATCH(verts_per_instance
);
275 OUT_BATCH(start_vertex_location
);
276 OUT_BATCH(prim
->num_instances
);
277 OUT_BATCH(prim
->base_instance
);
278 OUT_BATCH(base_vertex_location
);
281 if (brw
->always_flush_cache
)
282 brw_emit_mi_flush(brw
);
287 brw_merge_inputs(struct brw_context
*brw
,
288 const struct gl_vertex_array
*arrays
[])
290 const struct gl_context
*ctx
= &brw
->ctx
;
293 for (i
= 0; i
< brw
->vb
.nr_buffers
; i
++) {
294 drm_intel_bo_unreference(brw
->vb
.buffers
[i
].bo
);
295 brw
->vb
.buffers
[i
].bo
= NULL
;
297 brw
->vb
.nr_buffers
= 0;
299 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
300 brw
->vb
.inputs
[i
].buffer
= -1;
301 brw
->vb
.inputs
[i
].glarray
= arrays
[i
];
304 if (brw
->gen
< 8 && !brw
->is_haswell
) {
305 uint64_t mask
= ctx
->VertexProgram
._Current
->info
.inputs_read
;
306 /* Prior to Haswell, the hardware can't natively support GL_FIXED or
307 * 2_10_10_10_REV vertex formats. Set appropriate workaround flags.
310 uint8_t wa_flags
= 0;
312 i
= u_bit_scan64(&mask
);
314 switch (brw
->vb
.inputs
[i
].glarray
->Type
) {
317 wa_flags
= brw
->vb
.inputs
[i
].glarray
->Size
;
320 case GL_INT_2_10_10_10_REV
:
321 wa_flags
|= BRW_ATTRIB_WA_SIGN
;
324 case GL_UNSIGNED_INT_2_10_10_10_REV
:
325 if (brw
->vb
.inputs
[i
].glarray
->Format
== GL_BGRA
)
326 wa_flags
|= BRW_ATTRIB_WA_BGRA
;
328 if (brw
->vb
.inputs
[i
].glarray
->Normalized
)
329 wa_flags
|= BRW_ATTRIB_WA_NORMALIZE
;
330 else if (!brw
->vb
.inputs
[i
].glarray
->Integer
)
331 wa_flags
|= BRW_ATTRIB_WA_SCALE
;
336 if (brw
->vb
.attrib_wa_flags
[i
] != wa_flags
) {
337 brw
->vb
.attrib_wa_flags
[i
] = wa_flags
;
338 brw
->ctx
.NewDriverState
|= BRW_NEW_VS_ATTRIB_WORKAROUNDS
;
345 * \brief Call this after drawing to mark which buffers need resolving
347 * If the depth buffer was written to and if it has an accompanying HiZ
348 * buffer, then mark that it needs a depth resolve.
350 * If the color buffer is a multisample window system buffer, then
351 * mark that it needs a downsample.
353 * Also mark any render targets which will be textured as needing a render
357 brw_postdraw_set_buffers_need_resolve(struct brw_context
*brw
)
359 struct gl_context
*ctx
= &brw
->ctx
;
360 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
362 struct intel_renderbuffer
*front_irb
= NULL
;
363 struct intel_renderbuffer
*back_irb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
364 struct intel_renderbuffer
*depth_irb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
365 struct intel_renderbuffer
*stencil_irb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
366 struct gl_renderbuffer_attachment
*depth_att
= &fb
->Attachment
[BUFFER_DEPTH
];
368 if (_mesa_is_front_buffer_drawing(fb
))
369 front_irb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
372 front_irb
->need_downsample
= true;
374 back_irb
->need_downsample
= true;
375 if (depth_irb
&& brw_depth_writes_enabled(brw
)) {
376 intel_renderbuffer_att_set_needs_depth_resolve(depth_att
);
377 brw_render_cache_set_add_bo(brw
, depth_irb
->mt
->bo
);
380 if (ctx
->Extensions
.ARB_stencil_texturing
&&
381 stencil_irb
&& ctx
->Stencil
._WriteEnabled
) {
382 brw_render_cache_set_add_bo(brw
, stencil_irb
->mt
->bo
);
385 for (unsigned i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
386 struct intel_renderbuffer
*irb
=
387 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
390 brw_render_cache_set_add_bo(brw
, irb
->mt
->bo
);
391 intel_miptree_used_for_rendering(brw
, irb
->mt
);
397 brw_predraw_set_aux_buffers(struct brw_context
*brw
)
402 struct gl_context
*ctx
= &brw
->ctx
;
403 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
405 for (unsigned i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
406 struct intel_renderbuffer
*irb
=
407 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
415 /* May fail if out of video memory for texture or vbo upload, or on
416 * fallback conditions.
419 brw_try_draw_prims(struct gl_context
*ctx
,
420 const struct gl_vertex_array
*arrays
[],
421 const struct _mesa_prim
*prims
,
423 const struct _mesa_index_buffer
*ib
,
424 bool index_bounds_valid
,
427 struct brw_transform_feedback_object
*xfb_obj
,
429 struct gl_buffer_object
*indirect
)
431 struct brw_context
*brw
= brw_context(ctx
);
433 bool fail_next
= false;
436 _mesa_update_state(ctx
);
438 /* We have to validate the textures *before* checking for fallbacks;
439 * otherwise, the software fallback won't be able to rely on the
440 * texture state, the firstLevel and lastLevel fields won't be
441 * set in the intel texture object (they'll both be 0), and the
442 * software fallback will segfault if it attempts to access any
443 * texture level other than level 0.
445 brw_validate_textures(brw
);
447 /* Find the highest sampler unit used by each shader program. A bit-count
448 * won't work since ARB programs use the texture unit number as the sampler
451 brw
->wm
.base
.sampler_count
=
452 util_last_bit(ctx
->FragmentProgram
._Current
->SamplersUsed
);
453 brw
->gs
.base
.sampler_count
= ctx
->GeometryProgram
._Current
?
454 util_last_bit(ctx
->GeometryProgram
._Current
->SamplersUsed
) : 0;
455 brw
->tes
.base
.sampler_count
= ctx
->TessEvalProgram
._Current
?
456 util_last_bit(ctx
->TessEvalProgram
._Current
->SamplersUsed
) : 0;
457 brw
->tcs
.base
.sampler_count
= ctx
->TessCtrlProgram
._Current
?
458 util_last_bit(ctx
->TessCtrlProgram
._Current
->SamplersUsed
) : 0;
459 brw
->vs
.base
.sampler_count
=
460 util_last_bit(ctx
->VertexProgram
._Current
->SamplersUsed
);
462 intel_prepare_render(brw
);
463 brw_predraw_set_aux_buffers(brw
);
465 /* This workaround has to happen outside of brw_upload_render_state()
466 * because it may flush the batchbuffer for a blit, affecting the state
469 brw_workaround_depthstencil_alignment(brw
, 0);
471 /* Bind all inputs, derive varying and size information:
473 brw_merge_inputs(brw
, arrays
);
476 brw
->ctx
.NewDriverState
|= BRW_NEW_INDICES
;
478 brw
->vb
.index_bounds_valid
= index_bounds_valid
;
479 brw
->vb
.min_index
= min_index
;
480 brw
->vb
.max_index
= max_index
;
481 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTICES
;
483 for (i
= 0; i
< nr_prims
; i
++) {
484 int estimated_max_prim_size
;
485 const int sampler_state_size
= 16;
487 estimated_max_prim_size
= 512; /* batchbuffer commands */
488 estimated_max_prim_size
+= BRW_MAX_TEX_UNIT
*
489 (sampler_state_size
+ sizeof(struct gen5_sampler_default_color
));
490 estimated_max_prim_size
+= 1024; /* gen6 VS push constants */
491 estimated_max_prim_size
+= 1024; /* gen6 WM push constants */
492 estimated_max_prim_size
+= 512; /* misc. pad */
494 /* Flush the batch if it's approaching full, so that we don't wrap while
495 * we've got validated state that needs to be in the same batch as the
498 intel_batchbuffer_require_space(brw
, estimated_max_prim_size
, RENDER_RING
);
499 intel_batchbuffer_save_state(brw
);
501 if (brw
->num_instances
!= prims
[i
].num_instances
||
502 brw
->basevertex
!= prims
[i
].basevertex
||
503 brw
->baseinstance
!= prims
[i
].base_instance
) {
504 brw
->num_instances
= prims
[i
].num_instances
;
505 brw
->basevertex
= prims
[i
].basevertex
;
506 brw
->baseinstance
= prims
[i
].base_instance
;
507 if (i
> 0) { /* For i == 0 we just did this before the loop */
508 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTICES
;
509 brw_merge_inputs(brw
, arrays
);
513 /* Determine if we need to flag BRW_NEW_VERTICES for updating the
514 * gl_BaseVertexARB or gl_BaseInstanceARB values. For indirect draw, we
515 * always flag if the shader uses one of the values. For direct draws,
516 * we only flag if the values change.
518 const int new_basevertex
=
519 prims
[i
].indexed
? prims
[i
].basevertex
: prims
[i
].start
;
520 const int new_baseinstance
= prims
[i
].base_instance
;
521 const struct brw_vs_prog_data
*vs_prog_data
=
522 brw_vs_prog_data(brw
->vs
.base
.prog_data
);
524 const bool uses_draw_parameters
=
525 vs_prog_data
->uses_basevertex
||
526 vs_prog_data
->uses_baseinstance
;
528 if ((uses_draw_parameters
&& prims
[i
].is_indirect
) ||
529 (vs_prog_data
->uses_basevertex
&&
530 brw
->draw
.params
.gl_basevertex
!= new_basevertex
) ||
531 (vs_prog_data
->uses_baseinstance
&&
532 brw
->draw
.params
.gl_baseinstance
!= new_baseinstance
))
533 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTICES
;
536 brw
->draw
.params
.gl_basevertex
= new_basevertex
;
537 brw
->draw
.params
.gl_baseinstance
= new_baseinstance
;
538 drm_intel_bo_unreference(brw
->draw
.draw_params_bo
);
540 if (prims
[i
].is_indirect
) {
541 /* Point draw_params_bo at the indirect buffer. */
542 brw
->draw
.draw_params_bo
=
543 intel_buffer_object(ctx
->DrawIndirectBuffer
)->buffer
;
544 drm_intel_bo_reference(brw
->draw
.draw_params_bo
);
545 brw
->draw
.draw_params_offset
=
546 prims
[i
].indirect_offset
+ (prims
[i
].indexed
? 12 : 8);
548 /* Set draw_params_bo to NULL so brw_prepare_vertices knows it
549 * has to upload gl_BaseVertex and such if they're needed.
551 brw
->draw
.draw_params_bo
= NULL
;
552 brw
->draw
.draw_params_offset
= 0;
555 /* gl_DrawID always needs its own vertex buffer since it's not part of
556 * the indirect parameter buffer. If the program uses gl_DrawID we need
557 * to flag BRW_NEW_VERTICES. For the first iteration, we don't have
558 * valid vs_prog_data, but we always flag BRW_NEW_VERTICES before
561 brw
->draw
.gl_drawid
= prims
[i
].draw_id
;
562 drm_intel_bo_unreference(brw
->draw
.draw_id_bo
);
563 brw
->draw
.draw_id_bo
= NULL
;
564 if (i
> 0 && vs_prog_data
->uses_drawid
)
565 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTICES
;
568 brw_set_prim(brw
, &prims
[i
]);
570 gen6_set_prim(brw
, &prims
[i
]);
574 /* Note that before the loop, brw->ctx.NewDriverState was set to != 0, and
575 * that the state updated in the loop outside of this block is that in
576 * *_set_prim or intel_batchbuffer_flush(), which only impacts
577 * brw->ctx.NewDriverState.
579 if (brw
->ctx
.NewDriverState
) {
580 brw
->no_batch_wrap
= true;
581 brw_upload_render_state(brw
);
584 brw_emit_prim(brw
, &prims
[i
], brw
->primitive
, xfb_obj
, stream
);
586 brw
->no_batch_wrap
= false;
588 if (dri_bufmgr_check_aperture_space(&brw
->batch
.bo
, 1)) {
590 intel_batchbuffer_reset_to_saved(brw
);
591 intel_batchbuffer_flush(brw
);
595 int ret
= intel_batchbuffer_flush(brw
);
596 WARN_ONCE(ret
== -ENOSPC
,
597 "i965: Single primitive emit exceeded "
598 "available aperture space\n");
602 /* Now that we know we haven't run out of aperture space, we can safely
603 * reset the dirty bits.
605 if (brw
->ctx
.NewDriverState
)
606 brw_render_state_finished(brw
);
609 if (brw
->always_flush_batch
)
610 intel_batchbuffer_flush(brw
);
612 brw_program_cache_check_size(brw
);
613 brw_postdraw_set_buffers_need_resolve(brw
);
619 brw_draw_prims(struct gl_context
*ctx
,
620 const struct _mesa_prim
*prims
,
622 const struct _mesa_index_buffer
*ib
,
623 GLboolean index_bounds_valid
,
626 struct gl_transform_feedback_object
*gl_xfb_obj
,
628 struct gl_buffer_object
*indirect
)
630 struct brw_context
*brw
= brw_context(ctx
);
631 const struct gl_vertex_array
**arrays
= ctx
->Array
._DrawArrays
;
632 struct brw_transform_feedback_object
*xfb_obj
=
633 (struct brw_transform_feedback_object
*) gl_xfb_obj
;
635 if (!brw_check_conditional_render(brw
))
638 /* Handle primitive restart if needed */
639 if (brw_handle_primitive_restart(ctx
, prims
, nr_prims
, ib
, indirect
)) {
640 /* The draw was handled, so we can exit now */
644 /* Do GL_SELECT and GL_FEEDBACK rendering using swrast, even though it
645 * won't support all the extensions we support.
647 if (ctx
->RenderMode
!= GL_RENDER
) {
648 perf_debug("%s render mode not supported in hardware\n",
649 _mesa_enum_to_string(ctx
->RenderMode
));
650 _swsetup_Wakeup(ctx
);
652 _tnl_draw_prims(ctx
, prims
, nr_prims
, ib
,
653 index_bounds_valid
, min_index
, max_index
, NULL
, 0, NULL
);
657 /* If we're going to have to upload any of the user's vertex arrays, then
658 * get the minimum and maximum of their index buffer so we know what range
661 if (!index_bounds_valid
&& !vbo_all_varyings_in_vbos(arrays
)) {
662 perf_debug("Scanning index buffer to compute index buffer bounds. "
663 "Use glDrawRangeElements() to avoid this.\n");
664 vbo_get_minmax_indices(ctx
, prims
, ib
, &min_index
, &max_index
, nr_prims
);
665 index_bounds_valid
= true;
668 /* Try drawing with the hardware, but don't do anything else if we can't
669 * manage it. swrast doesn't support our featureset, so we can't fall back
672 brw_try_draw_prims(ctx
, arrays
, prims
, nr_prims
, ib
, index_bounds_valid
,
673 min_index
, max_index
, xfb_obj
, stream
, indirect
);
677 brw_draw_init(struct brw_context
*brw
)
679 struct gl_context
*ctx
= &brw
->ctx
;
680 struct vbo_context
*vbo
= vbo_context(ctx
);
682 /* Register our drawing function:
684 vbo
->draw_prims
= brw_draw_prims
;
686 for (int i
= 0; i
< VERT_ATTRIB_MAX
; i
++)
687 brw
->vb
.inputs
[i
].buffer
= -1;
688 brw
->vb
.nr_buffers
= 0;
689 brw
->vb
.nr_enabled
= 0;
693 brw_draw_destroy(struct brw_context
*brw
)
697 for (i
= 0; i
< brw
->vb
.nr_buffers
; i
++) {
698 drm_intel_bo_unreference(brw
->vb
.buffers
[i
].bo
);
699 brw
->vb
.buffers
[i
].bo
= NULL
;
701 brw
->vb
.nr_buffers
= 0;
703 for (i
= 0; i
< brw
->vb
.nr_enabled
; i
++) {
704 brw
->vb
.enabled
[i
]->buffer
= -1;
706 brw
->vb
.nr_enabled
= 0;
708 drm_intel_bo_unreference(brw
->ib
.bo
);