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/arrayobj.h"
29 #include "main/blend.h"
30 #include "main/context.h"
31 #include "main/condrender.h"
32 #include "main/samplerobj.h"
33 #include "main/state.h"
34 #include "main/enums.h"
35 #include "main/macros.h"
36 #include "main/transformfeedback.h"
37 #include "main/framebuffer.h"
38 #include "main/varray.h"
41 #include "swrast/swrast.h"
42 #include "swrast_setup/swrast_setup.h"
43 #include "drivers/common/meta.h"
44 #include "util/bitscan.h"
45 #include "util/bitset.h"
47 #include "brw_blorp.h"
49 #include "brw_defines.h"
50 #include "compiler/brw_eu_defines.h"
51 #include "brw_context.h"
52 #include "brw_state.h"
54 #include "intel_batchbuffer.h"
55 #include "intel_buffers.h"
56 #include "intel_fbo.h"
57 #include "intel_mipmap_tree.h"
58 #include "intel_buffer_objects.h"
60 #define FILE_DEBUG_FLAG DEBUG_PRIMS
63 static const GLenum reduced_prim
[GL_POLYGON
+1] = {
64 [GL_POINTS
] = GL_POINTS
,
65 [GL_LINES
] = GL_LINES
,
66 [GL_LINE_LOOP
] = GL_LINES
,
67 [GL_LINE_STRIP
] = GL_LINES
,
68 [GL_TRIANGLES
] = GL_TRIANGLES
,
69 [GL_TRIANGLE_STRIP
] = GL_TRIANGLES
,
70 [GL_TRIANGLE_FAN
] = GL_TRIANGLES
,
71 [GL_QUADS
] = GL_TRIANGLES
,
72 [GL_QUAD_STRIP
] = GL_TRIANGLES
,
73 [GL_POLYGON
] = GL_TRIANGLES
76 /* When the primitive changes, set a state bit and re-validate. Not
77 * the nicest and would rather deal with this by having all the
78 * programs be immune to the active primitive (ie. cope with all
79 * possibilities). That may not be realistic however.
82 brw_set_prim(struct brw_context
*brw
, const struct _mesa_prim
*prim
)
84 struct gl_context
*ctx
= &brw
->ctx
;
85 uint32_t hw_prim
= get_hw_prim_for_gl_prim(prim
->mode
);
87 DBG("PRIM: %s\n", _mesa_enum_to_string(prim
->mode
));
89 /* Slight optimization to avoid the GS program when not needed:
91 if (prim
->mode
== GL_QUAD_STRIP
&&
92 ctx
->Light
.ShadeModel
!= GL_FLAT
&&
93 ctx
->Polygon
.FrontMode
== GL_FILL
&&
94 ctx
->Polygon
.BackMode
== GL_FILL
)
95 hw_prim
= _3DPRIM_TRISTRIP
;
97 if (prim
->mode
== GL_QUADS
&& prim
->count
== 4 &&
98 ctx
->Light
.ShadeModel
!= GL_FLAT
&&
99 ctx
->Polygon
.FrontMode
== GL_FILL
&&
100 ctx
->Polygon
.BackMode
== GL_FILL
) {
101 hw_prim
= _3DPRIM_TRIFAN
;
104 if (hw_prim
!= brw
->primitive
) {
105 brw
->primitive
= hw_prim
;
106 brw
->ctx
.NewDriverState
|= BRW_NEW_PRIMITIVE
;
108 if (reduced_prim
[prim
->mode
] != brw
->reduced_primitive
) {
109 brw
->reduced_primitive
= reduced_prim
[prim
->mode
];
110 brw
->ctx
.NewDriverState
|= BRW_NEW_REDUCED_PRIMITIVE
;
116 gen6_set_prim(struct brw_context
*brw
, const struct _mesa_prim
*prim
)
118 const struct gl_context
*ctx
= &brw
->ctx
;
121 DBG("PRIM: %s\n", _mesa_enum_to_string(prim
->mode
));
123 if (prim
->mode
== GL_PATCHES
) {
124 hw_prim
= _3DPRIM_PATCHLIST(ctx
->TessCtrlProgram
.patch_vertices
);
126 hw_prim
= get_hw_prim_for_gl_prim(prim
->mode
);
129 if (hw_prim
!= brw
->primitive
) {
130 brw
->primitive
= hw_prim
;
131 brw
->ctx
.NewDriverState
|= BRW_NEW_PRIMITIVE
;
132 if (prim
->mode
== GL_PATCHES
)
133 brw
->ctx
.NewDriverState
|= BRW_NEW_PATCH_PRIMITIVE
;
139 * The hardware is capable of removing dangling vertices on its own; however,
140 * prior to Gen6, we sometimes convert quads into trifans (and quad strips
141 * into tristrips), since pre-Gen6 hardware requires a GS to render quads.
142 * This function manually trims dangling vertices from a draw call involving
143 * quads so that those dangling vertices won't get drawn when we convert to
147 trim(GLenum prim
, GLuint length
)
149 if (prim
== GL_QUAD_STRIP
)
150 return length
> 3 ? (length
- length
% 2) : 0;
151 else if (prim
== GL_QUADS
)
152 return length
- length
% 4;
159 brw_emit_prim(struct brw_context
*brw
,
160 const struct _mesa_prim
*prim
,
162 struct brw_transform_feedback_object
*xfb_obj
,
165 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
166 int verts_per_instance
;
167 int vertex_access_type
;
170 DBG("PRIM: %s %d %d\n", _mesa_enum_to_string(prim
->mode
),
171 prim
->start
, prim
->count
);
173 int start_vertex_location
= prim
->start
;
174 int base_vertex_location
= prim
->basevertex
;
177 vertex_access_type
= devinfo
->gen
>= 7 ?
178 GEN7_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM
:
179 GEN4_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM
;
180 start_vertex_location
+= brw
->ib
.start_vertex_offset
;
181 base_vertex_location
+= brw
->vb
.start_vertex_bias
;
183 vertex_access_type
= devinfo
->gen
>= 7 ?
184 GEN7_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL
:
185 GEN4_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL
;
186 start_vertex_location
+= brw
->vb
.start_vertex_bias
;
189 /* We only need to trim the primitive count on pre-Gen6. */
190 if (devinfo
->gen
< 6)
191 verts_per_instance
= trim(prim
->mode
, prim
->count
);
193 verts_per_instance
= prim
->count
;
195 /* If nothing to emit, just return. */
196 if (verts_per_instance
== 0 && !prim
->is_indirect
&& !xfb_obj
)
199 /* If we're set to always flush, do it before and after the primitive emit.
200 * We want to catch both missed flushes that hurt instruction/state cache
201 * and missed flushes of the render cache as it heads to other parts of
202 * the besides the draw code.
204 if (brw
->always_flush_cache
)
205 brw_emit_mi_flush(brw
);
207 /* If indirect, emit a bunch of loads from the indirect BO. */
209 indirect_flag
= GEN7_3DPRIM_INDIRECT_PARAMETER_ENABLE
;
211 brw_load_register_mem(brw
, GEN7_3DPRIM_VERTEX_COUNT
,
212 xfb_obj
->prim_count_bo
,
213 stream
* sizeof(uint32_t));
215 OUT_BATCH(MI_LOAD_REGISTER_IMM
| (9 - 2));
216 OUT_BATCH(GEN7_3DPRIM_INSTANCE_COUNT
);
217 OUT_BATCH(prim
->num_instances
);
218 OUT_BATCH(GEN7_3DPRIM_START_VERTEX
);
220 OUT_BATCH(GEN7_3DPRIM_BASE_VERTEX
);
222 OUT_BATCH(GEN7_3DPRIM_START_INSTANCE
);
225 } else if (prim
->is_indirect
) {
226 struct gl_buffer_object
*indirect_buffer
= brw
->ctx
.DrawIndirectBuffer
;
227 struct brw_bo
*bo
= intel_bufferobj_buffer(brw
,
228 intel_buffer_object(indirect_buffer
),
229 prim
->indirect_offset
, 5 * sizeof(GLuint
), false);
231 indirect_flag
= GEN7_3DPRIM_INDIRECT_PARAMETER_ENABLE
;
233 brw_load_register_mem(brw
, GEN7_3DPRIM_VERTEX_COUNT
, bo
,
234 prim
->indirect_offset
+ 0);
235 brw_load_register_mem(brw
, GEN7_3DPRIM_INSTANCE_COUNT
, bo
,
236 prim
->indirect_offset
+ 4);
238 brw_load_register_mem(brw
, GEN7_3DPRIM_START_VERTEX
, bo
,
239 prim
->indirect_offset
+ 8);
241 brw_load_register_mem(brw
, GEN7_3DPRIM_BASE_VERTEX
, bo
,
242 prim
->indirect_offset
+ 12);
243 brw_load_register_mem(brw
, GEN7_3DPRIM_START_INSTANCE
, bo
,
244 prim
->indirect_offset
+ 16);
246 brw_load_register_mem(brw
, GEN7_3DPRIM_START_INSTANCE
, bo
,
247 prim
->indirect_offset
+ 12);
248 brw_load_register_imm32(brw
, GEN7_3DPRIM_BASE_VERTEX
, 0);
254 BEGIN_BATCH(devinfo
->gen
>= 7 ? 7 : 6);
256 if (devinfo
->gen
>= 7) {
257 const int predicate_enable
=
258 (brw
->predicate
.state
== BRW_PREDICATE_STATE_USE_BIT
)
259 ? GEN7_3DPRIM_PREDICATE_ENABLE
: 0;
261 OUT_BATCH(CMD_3D_PRIM
<< 16 | (7 - 2) | indirect_flag
| predicate_enable
);
262 OUT_BATCH(hw_prim
| vertex_access_type
);
264 OUT_BATCH(CMD_3D_PRIM
<< 16 | (6 - 2) |
265 hw_prim
<< GEN4_3DPRIM_TOPOLOGY_TYPE_SHIFT
|
268 OUT_BATCH(verts_per_instance
);
269 OUT_BATCH(start_vertex_location
);
270 OUT_BATCH(prim
->num_instances
);
271 OUT_BATCH(prim
->base_instance
);
272 OUT_BATCH(base_vertex_location
);
275 if (brw
->always_flush_cache
)
276 brw_emit_mi_flush(brw
);
281 brw_merge_inputs(struct brw_context
*brw
)
283 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
284 const struct gl_context
*ctx
= &brw
->ctx
;
287 for (i
= 0; i
< brw
->vb
.nr_buffers
; i
++) {
288 brw_bo_unreference(brw
->vb
.buffers
[i
].bo
);
289 brw
->vb
.buffers
[i
].bo
= NULL
;
291 brw
->vb
.nr_buffers
= 0;
293 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
294 struct brw_vertex_element
*input
= &brw
->vb
.inputs
[i
];
296 _mesa_draw_attrib_and_binding(ctx
, i
,
297 &input
->glattrib
, &input
->glbinding
);
300 if (devinfo
->gen
< 8 && !devinfo
->is_haswell
) {
301 uint64_t mask
= ctx
->VertexProgram
._Current
->info
.inputs_read
;
302 /* Prior to Haswell, the hardware can't natively support GL_FIXED or
303 * 2_10_10_10_REV vertex formats. Set appropriate workaround flags.
306 const struct gl_vertex_format
*glformat
;
307 uint8_t wa_flags
= 0;
309 i
= u_bit_scan64(&mask
);
310 glformat
= &brw
->vb
.inputs
[i
].glattrib
->Format
;
312 switch (glformat
->Type
) {
315 wa_flags
= glformat
->Size
;
318 case GL_INT_2_10_10_10_REV
:
319 wa_flags
|= BRW_ATTRIB_WA_SIGN
;
322 case GL_UNSIGNED_INT_2_10_10_10_REV
:
323 if (glformat
->Format
== GL_BGRA
)
324 wa_flags
|= BRW_ATTRIB_WA_BGRA
;
326 if (glformat
->Normalized
)
327 wa_flags
|= BRW_ATTRIB_WA_NORMALIZE
;
328 else if (!glformat
->Integer
)
329 wa_flags
|= BRW_ATTRIB_WA_SCALE
;
334 if (brw
->vb
.attrib_wa_flags
[i
] != wa_flags
) {
335 brw
->vb
.attrib_wa_flags
[i
] = wa_flags
;
336 brw
->ctx
.NewDriverState
|= BRW_NEW_VS_ATTRIB_WORKAROUNDS
;
342 /* Disable auxiliary buffers if a renderbuffer is also bound as a texture
343 * or shader image. This causes a self-dependency, where both rendering
344 * and sampling may concurrently read or write the CCS buffer, causing
348 intel_disable_rb_aux_buffer(struct brw_context
*brw
,
349 bool *draw_aux_buffer_disabled
,
350 struct intel_mipmap_tree
*tex_mt
,
351 unsigned min_level
, unsigned num_levels
,
354 const struct gl_framebuffer
*fb
= brw
->ctx
.DrawBuffer
;
357 /* We only need to worry about color compression and fast clears. */
358 if (tex_mt
->aux_usage
!= ISL_AUX_USAGE_CCS_D
&&
359 tex_mt
->aux_usage
!= ISL_AUX_USAGE_CCS_E
)
362 for (unsigned i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
363 const struct intel_renderbuffer
*irb
=
364 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
366 if (irb
&& irb
->mt
->bo
== tex_mt
->bo
&&
367 irb
->mt_level
>= min_level
&&
368 irb
->mt_level
< min_level
+ num_levels
) {
369 found
= draw_aux_buffer_disabled
[i
] = true;
374 perf_debug("Disabling CCS because a renderbuffer is also bound %s.\n",
381 /** Implement the ASTC 5x5 sampler workaround
383 * Gen9 sampling hardware has a bug where an ASTC 5x5 compressed surface
384 * cannot live in the sampler cache at the same time as an aux compressed
385 * surface. In order to work around the bug we have to stall rendering with a
386 * CS and pixel scoreboard stall (implicit in the CS stall) and invalidate the
387 * texture cache whenever one of ASTC 5x5 or aux compressed may be in the
388 * sampler cache and we're about to render with something which samples from
391 * In the case of a single shader which textures from both ASTC 5x5 and
392 * a texture which is CCS or HiZ compressed, we have to resolve the aux
393 * compressed texture prior to rendering. This second part is handled in
394 * brw_predraw_resolve_inputs() below.
396 * We have observed this issue to affect CCS and HiZ sampling but whether or
397 * not it also affects MCS is unknown. Because MCS has no concept of a
398 * resolve (and doing one would be stupid expensive), we choose to simply
399 * ignore the possibility and hope for the best.
402 gen9_apply_astc5x5_wa_flush(struct brw_context
*brw
,
403 enum gen9_astc5x5_wa_tex_type curr_mask
)
405 assert(brw
->screen
->devinfo
.gen
== 9);
407 if (((brw
->gen9_astc5x5_wa_tex_mask
& GEN9_ASTC5X5_WA_TEX_TYPE_ASTC5x5
) &&
408 (curr_mask
& GEN9_ASTC5X5_WA_TEX_TYPE_AUX
)) ||
409 ((brw
->gen9_astc5x5_wa_tex_mask
& GEN9_ASTC5X5_WA_TEX_TYPE_AUX
) &&
410 (curr_mask
& GEN9_ASTC5X5_WA_TEX_TYPE_ASTC5x5
))) {
411 brw_emit_pipe_control_flush(brw
, PIPE_CONTROL_CS_STALL
);
412 brw_emit_pipe_control_flush(brw
, PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE
);
415 brw
->gen9_astc5x5_wa_tex_mask
= curr_mask
;
418 static enum gen9_astc5x5_wa_tex_type
419 gen9_astc5x5_wa_bits(mesa_format format
, enum isl_aux_usage aux_usage
)
421 if (aux_usage
!= ISL_AUX_USAGE_NONE
&&
422 aux_usage
!= ISL_AUX_USAGE_MCS
)
423 return GEN9_ASTC5X5_WA_TEX_TYPE_AUX
;
425 if (format
== MESA_FORMAT_RGBA_ASTC_5x5
||
426 format
== MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5
)
427 return GEN9_ASTC5X5_WA_TEX_TYPE_ASTC5x5
;
432 /* Helper for the gen9 ASTC 5x5 workaround. This version exists for BLORP's
433 * use-cases where only a single texture is bound.
436 gen9_apply_single_tex_astc5x5_wa(struct brw_context
*brw
,
438 enum isl_aux_usage aux_usage
)
440 gen9_apply_astc5x5_wa_flush(brw
, gen9_astc5x5_wa_bits(format
, aux_usage
));
444 mark_textures_used_for_txf(BITSET_WORD
*used_for_txf
,
445 const struct gl_program
*prog
)
450 uint32_t mask
= prog
->info
.textures_used_by_txf
;
452 int s
= u_bit_scan(&mask
);
453 BITSET_SET(used_for_txf
, prog
->SamplerUnits
[s
]);
458 * \brief Resolve buffers before drawing.
460 * Resolve the depth buffer's HiZ buffer, resolve the depth buffer of each
461 * enabled depth texture, and flush the render cache for any dirty textures.
464 brw_predraw_resolve_inputs(struct brw_context
*brw
, bool rendering
,
465 bool *draw_aux_buffer_disabled
)
467 struct gl_context
*ctx
= &brw
->ctx
;
468 struct intel_texture_object
*tex_obj
;
470 BITSET_DECLARE(used_for_txf
, MAX_COMBINED_TEXTURE_IMAGE_UNITS
);
471 memset(used_for_txf
, 0, sizeof(used_for_txf
));
473 mark_textures_used_for_txf(used_for_txf
, ctx
->VertexProgram
._Current
);
474 mark_textures_used_for_txf(used_for_txf
, ctx
->TessCtrlProgram
._Current
);
475 mark_textures_used_for_txf(used_for_txf
, ctx
->TessEvalProgram
._Current
);
476 mark_textures_used_for_txf(used_for_txf
, ctx
->GeometryProgram
._Current
);
477 mark_textures_used_for_txf(used_for_txf
, ctx
->FragmentProgram
._Current
);
479 mark_textures_used_for_txf(used_for_txf
, ctx
->ComputeProgram
._Current
);
482 int maxEnabledUnit
= ctx
->Texture
._MaxEnabledTexImageUnit
;
484 enum gen9_astc5x5_wa_tex_type astc5x5_wa_bits
= 0;
485 if (brw
->screen
->devinfo
.gen
== 9) {
486 /* In order to properly implement the ASTC 5x5 workaround for an
487 * arbitrary draw or dispatch call, we have to walk the entire list of
488 * textures looking for ASTC 5x5. If there is any ASTC 5x5 in this draw
489 * call, all aux compressed textures must be resolved and have aux
490 * compression disabled while sampling.
492 for (int i
= 0; i
<= maxEnabledUnit
; i
++) {
493 if (!ctx
->Texture
.Unit
[i
]._Current
)
495 tex_obj
= intel_texture_object(ctx
->Texture
.Unit
[i
]._Current
);
496 if (!tex_obj
|| !tex_obj
->mt
)
499 astc5x5_wa_bits
|= gen9_astc5x5_wa_bits(tex_obj
->_Format
,
500 tex_obj
->mt
->aux_usage
);
502 gen9_apply_astc5x5_wa_flush(brw
, astc5x5_wa_bits
);
505 /* Resolve depth buffer and render cache of each enabled texture. */
506 for (int i
= 0; i
<= maxEnabledUnit
; i
++) {
507 if (!ctx
->Texture
.Unit
[i
]._Current
)
509 tex_obj
= intel_texture_object(ctx
->Texture
.Unit
[i
]._Current
);
510 if (!tex_obj
|| !tex_obj
->mt
)
513 struct gl_sampler_object
*sampler
= _mesa_get_samplerobj(ctx
, i
);
514 enum isl_format view_format
=
515 translate_tex_format(brw
, tex_obj
->_Format
, sampler
->sRGBDecode
);
517 unsigned min_level
, min_layer
, num_levels
, num_layers
;
518 if (tex_obj
->base
.Immutable
) {
519 min_level
= tex_obj
->base
.MinLevel
;
520 num_levels
= MIN2(tex_obj
->base
.NumLevels
, tex_obj
->_MaxLevel
+ 1);
521 min_layer
= tex_obj
->base
.MinLayer
;
522 num_layers
= tex_obj
->base
.Target
!= GL_TEXTURE_3D
?
523 tex_obj
->base
.NumLayers
: INTEL_REMAINING_LAYERS
;
525 min_level
= tex_obj
->base
.BaseLevel
;
526 num_levels
= tex_obj
->_MaxLevel
- tex_obj
->base
.BaseLevel
+ 1;
528 num_layers
= INTEL_REMAINING_LAYERS
;
532 intel_disable_rb_aux_buffer(brw
, draw_aux_buffer_disabled
,
533 tex_obj
->mt
, min_level
, num_levels
,
537 intel_miptree_prepare_texture(brw
, tex_obj
->mt
, view_format
,
538 min_level
, num_levels
,
539 min_layer
, num_layers
,
542 /* If any programs are using it with texelFetch, we may need to also do
543 * a prepare with an sRGB format to ensure texelFetch works "properly".
545 if (BITSET_TEST(used_for_txf
, i
)) {
546 enum isl_format txf_format
=
547 translate_tex_format(brw
, tex_obj
->_Format
, GL_DECODE_EXT
);
548 if (txf_format
!= view_format
) {
549 intel_miptree_prepare_texture(brw
, tex_obj
->mt
, txf_format
,
550 min_level
, num_levels
,
551 min_layer
, num_layers
,
556 brw_cache_flush_for_read(brw
, tex_obj
->mt
->bo
);
558 if (tex_obj
->base
.StencilSampling
||
559 tex_obj
->mt
->format
== MESA_FORMAT_S_UINT8
) {
560 intel_update_r8stencil(brw
, tex_obj
->mt
);
563 if (intel_miptree_has_etc_shadow(brw
, tex_obj
->mt
) &&
564 tex_obj
->mt
->shadow_needs_update
) {
565 intel_miptree_update_etc_shadow_levels(brw
, tex_obj
->mt
);
569 /* Resolve color for each active shader image. */
570 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
571 const struct gl_program
*prog
= ctx
->_Shader
->CurrentProgram
[i
];
573 if (unlikely(prog
&& prog
->info
.num_images
)) {
574 for (unsigned j
= 0; j
< prog
->info
.num_images
; j
++) {
575 struct gl_image_unit
*u
=
576 &ctx
->ImageUnits
[prog
->sh
.ImageUnits
[j
]];
577 tex_obj
= intel_texture_object(u
->TexObj
);
579 if (tex_obj
&& tex_obj
->mt
) {
581 intel_disable_rb_aux_buffer(brw
, draw_aux_buffer_disabled
,
583 "as a shader image");
586 intel_miptree_prepare_image(brw
, tex_obj
->mt
);
588 brw_cache_flush_for_read(brw
, tex_obj
->mt
->bo
);
596 brw_predraw_resolve_framebuffer(struct brw_context
*brw
,
597 bool *draw_aux_buffer_disabled
)
599 struct gl_context
*ctx
= &brw
->ctx
;
600 struct intel_renderbuffer
*depth_irb
;
602 /* Resolve the depth buffer's HiZ buffer. */
603 depth_irb
= intel_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_DEPTH
);
604 if (depth_irb
&& depth_irb
->mt
) {
605 intel_miptree_prepare_depth(brw
, depth_irb
->mt
,
608 depth_irb
->layer_count
);
611 /* Resolve color buffers for non-coherent framebuffer fetch. */
612 if (!ctx
->Extensions
.EXT_shader_framebuffer_fetch
&&
613 ctx
->FragmentProgram
._Current
&&
614 ctx
->FragmentProgram
._Current
->info
.outputs_read
) {
615 const struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
617 /* This is only used for non-coherent framebuffer fetch, so we don't
618 * need to worry about CCS_E and can simply pass 'false' below.
620 assert(brw
->screen
->devinfo
.gen
< 9);
622 for (unsigned i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
623 const struct intel_renderbuffer
*irb
=
624 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
627 intel_miptree_prepare_texture(brw
, irb
->mt
, irb
->mt
->surf
.format
,
629 irb
->mt_layer
, irb
->layer_count
,
630 brw
->gen9_astc5x5_wa_tex_mask
);
635 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
636 for (int i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
637 struct intel_renderbuffer
*irb
=
638 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
640 if (irb
== NULL
|| irb
->mt
== NULL
)
643 mesa_format mesa_format
=
644 _mesa_get_render_format(ctx
, intel_rb_format(irb
));
645 enum isl_format isl_format
= brw_isl_format_for_mesa_format(mesa_format
);
646 bool blend_enabled
= ctx
->Color
.BlendEnabled
& (1 << i
);
647 enum isl_aux_usage aux_usage
=
648 intel_miptree_render_aux_usage(brw
, irb
->mt
, isl_format
,
650 draw_aux_buffer_disabled
[i
]);
651 if (brw
->draw_aux_usage
[i
] != aux_usage
) {
652 brw
->ctx
.NewDriverState
|= BRW_NEW_AUX_STATE
;
653 brw
->draw_aux_usage
[i
] = aux_usage
;
656 intel_miptree_prepare_render(brw
, irb
->mt
, irb
->mt_level
,
657 irb
->mt_layer
, irb
->layer_count
,
660 brw_cache_flush_for_render(brw
, irb
->mt
->bo
,
661 isl_format
, aux_usage
);
666 * \brief Call this after drawing to mark which buffers need resolving
668 * If the depth buffer was written to and if it has an accompanying HiZ
669 * buffer, then mark that it needs a depth resolve.
671 * If the stencil buffer was written to then mark that it may need to be
672 * copied to an R8 texture.
674 * If the color buffer is a multisample window system buffer, then
675 * mark that it needs a downsample.
677 * Also mark any render targets which will be textured as needing a render
681 brw_postdraw_set_buffers_need_resolve(struct brw_context
*brw
)
683 struct gl_context
*ctx
= &brw
->ctx
;
684 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
686 struct intel_renderbuffer
*front_irb
= NULL
;
687 struct intel_renderbuffer
*back_irb
= intel_get_renderbuffer(fb
, BUFFER_BACK_LEFT
);
688 struct intel_renderbuffer
*depth_irb
= intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
689 struct intel_renderbuffer
*stencil_irb
= intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
690 struct gl_renderbuffer_attachment
*depth_att
= &fb
->Attachment
[BUFFER_DEPTH
];
692 if (_mesa_is_front_buffer_drawing(fb
))
693 front_irb
= intel_get_renderbuffer(fb
, BUFFER_FRONT_LEFT
);
696 front_irb
->need_downsample
= true;
698 back_irb
->need_downsample
= true;
700 bool depth_written
= brw_depth_writes_enabled(brw
);
701 if (depth_att
->Layered
) {
702 intel_miptree_finish_depth(brw
, depth_irb
->mt
,
705 depth_irb
->layer_count
,
708 intel_miptree_finish_depth(brw
, depth_irb
->mt
,
710 depth_irb
->mt_layer
, 1,
714 brw_depth_cache_add_bo(brw
, depth_irb
->mt
->bo
);
717 if (stencil_irb
&& brw
->stencil_write_enabled
) {
718 struct intel_mipmap_tree
*stencil_mt
=
719 stencil_irb
->mt
->stencil_mt
!= NULL
?
720 stencil_irb
->mt
->stencil_mt
: stencil_irb
->mt
;
721 brw_depth_cache_add_bo(brw
, stencil_mt
->bo
);
722 intel_miptree_finish_write(brw
, stencil_mt
, stencil_irb
->mt_level
,
723 stencil_irb
->mt_layer
,
724 stencil_irb
->layer_count
, ISL_AUX_USAGE_NONE
);
727 for (unsigned i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
728 struct intel_renderbuffer
*irb
=
729 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
734 mesa_format mesa_format
=
735 _mesa_get_render_format(ctx
, intel_rb_format(irb
));
736 enum isl_format isl_format
= brw_isl_format_for_mesa_format(mesa_format
);
737 enum isl_aux_usage aux_usage
= brw
->draw_aux_usage
[i
];
739 brw_render_cache_add_bo(brw
, irb
->mt
->bo
, isl_format
, aux_usage
);
741 intel_miptree_finish_render(brw
, irb
->mt
, irb
->mt_level
,
742 irb
->mt_layer
, irb
->layer_count
,
748 intel_renderbuffer_move_temp_back(struct brw_context
*brw
,
749 struct intel_renderbuffer
*irb
)
751 if (irb
->align_wa_mt
== NULL
)
754 brw_cache_flush_for_read(brw
, irb
->align_wa_mt
->bo
);
756 intel_miptree_copy_slice(brw
, irb
->align_wa_mt
, 0, 0,
758 irb
->Base
.Base
.TexImage
->Level
, irb
->mt_layer
);
760 intel_miptree_reference(&irb
->align_wa_mt
, NULL
);
762 /* Finally restore the x,y to correspond to full miptree. */
763 intel_renderbuffer_set_draw_offset(irb
);
765 /* Make sure render surface state gets re-emitted with updated miptree. */
766 brw
->NewGLState
|= _NEW_BUFFERS
;
770 brw_postdraw_reconcile_align_wa_slices(struct brw_context
*brw
)
772 struct gl_context
*ctx
= &brw
->ctx
;
773 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
775 struct intel_renderbuffer
*depth_irb
=
776 intel_get_renderbuffer(fb
, BUFFER_DEPTH
);
777 struct intel_renderbuffer
*stencil_irb
=
778 intel_get_renderbuffer(fb
, BUFFER_STENCIL
);
780 if (depth_irb
&& depth_irb
->align_wa_mt
)
781 intel_renderbuffer_move_temp_back(brw
, depth_irb
);
783 if (stencil_irb
&& stencil_irb
->align_wa_mt
)
784 intel_renderbuffer_move_temp_back(brw
, stencil_irb
);
786 for (unsigned i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++) {
787 struct intel_renderbuffer
*irb
=
788 intel_renderbuffer(fb
->_ColorDrawBuffers
[i
]);
790 if (!irb
|| irb
->align_wa_mt
== NULL
)
793 intel_renderbuffer_move_temp_back(brw
, irb
);
798 brw_prepare_drawing(struct gl_context
*ctx
,
799 const struct _mesa_index_buffer
*ib
,
800 bool index_bounds_valid
,
804 struct brw_context
*brw
= brw_context(ctx
);
807 _mesa_update_state(ctx
);
809 /* We have to validate the textures *before* checking for fallbacks;
810 * otherwise, the software fallback won't be able to rely on the
811 * texture state, the firstLevel and lastLevel fields won't be
812 * set in the intel texture object (they'll both be 0), and the
813 * software fallback will segfault if it attempts to access any
814 * texture level other than level 0.
816 brw_validate_textures(brw
);
818 /* Find the highest sampler unit used by each shader program. A bit-count
819 * won't work since ARB programs use the texture unit number as the sampler
822 brw
->wm
.base
.sampler_count
=
823 util_last_bit(ctx
->FragmentProgram
._Current
->info
.textures_used
);
824 brw
->gs
.base
.sampler_count
= ctx
->GeometryProgram
._Current
?
825 util_last_bit(ctx
->GeometryProgram
._Current
->info
.textures_used
) : 0;
826 brw
->tes
.base
.sampler_count
= ctx
->TessEvalProgram
._Current
?
827 util_last_bit(ctx
->TessEvalProgram
._Current
->info
.textures_used
) : 0;
828 brw
->tcs
.base
.sampler_count
= ctx
->TessCtrlProgram
._Current
?
829 util_last_bit(ctx
->TessCtrlProgram
._Current
->info
.textures_used
) : 0;
830 brw
->vs
.base
.sampler_count
=
831 util_last_bit(ctx
->VertexProgram
._Current
->info
.textures_used
);
833 intel_prepare_render(brw
);
835 /* This workaround has to happen outside of brw_upload_render_state()
836 * because it may flush the batchbuffer for a blit, affecting the state
839 brw_workaround_depthstencil_alignment(brw
, 0);
841 /* Resolves must occur after updating renderbuffers, updating context state,
842 * and finalizing textures but before setting up any hardware state for
845 bool draw_aux_buffer_disabled
[MAX_DRAW_BUFFERS
] = { };
846 brw_predraw_resolve_inputs(brw
, true, draw_aux_buffer_disabled
);
847 brw_predraw_resolve_framebuffer(brw
, draw_aux_buffer_disabled
);
849 /* Bind all inputs, derive varying and size information:
851 brw_merge_inputs(brw
);
854 brw
->ctx
.NewDriverState
|= BRW_NEW_INDICES
;
856 brw
->vb
.index_bounds_valid
= index_bounds_valid
;
857 brw
->vb
.min_index
= min_index
;
858 brw
->vb
.max_index
= max_index
;
859 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTICES
;
863 brw_finish_drawing(struct gl_context
*ctx
)
865 struct brw_context
*brw
= brw_context(ctx
);
867 if (brw
->always_flush_batch
)
868 intel_batchbuffer_flush(brw
);
870 brw_program_cache_check_size(brw
);
871 brw_postdraw_reconcile_align_wa_slices(brw
);
872 brw_postdraw_set_buffers_need_resolve(brw
);
874 if (brw
->draw
.draw_params_count_bo
) {
875 brw_bo_unreference(brw
->draw
.draw_params_count_bo
);
876 brw
->draw
.draw_params_count_bo
= NULL
;
879 if (brw
->draw
.draw_params_bo
) {
880 brw_bo_unreference(brw
->draw
.draw_params_bo
);
881 brw
->draw
.draw_params_bo
= NULL
;
884 if (brw
->draw
.derived_draw_params_bo
) {
885 brw_bo_unreference(brw
->draw
.derived_draw_params_bo
);
886 brw
->draw
.derived_draw_params_bo
= NULL
;
891 * Implement workarounds for preemption:
892 * - WaDisableMidObjectPreemptionForGSLineStripAdj
893 * - WaDisableMidObjectPreemptionForTrifanOrPolygon
894 * - WaDisableMidObjectPreemptionForLineLoop
898 gen9_emit_preempt_wa(struct brw_context
*brw
,
899 const struct _mesa_prim
*prim
)
901 bool object_preemption
= true;
902 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
904 /* Only apply these workarounds for gen9 */
905 assert(devinfo
->gen
== 9);
907 /* WaDisableMidObjectPreemptionForGSLineStripAdj
909 * WA: Disable mid-draw preemption when draw-call is a linestrip_adj and
912 if (brw
->primitive
== _3DPRIM_LINESTRIP_ADJ
&& brw
->gs
.enabled
)
913 object_preemption
= false;
915 /* WaDisableMidObjectPreemptionForTrifanOrPolygon
917 * TriFan miscompare in Execlist Preemption test. Cut index that is on a
918 * previous context. End the previous, the resume another context with a
919 * tri-fan or polygon, and the vertex count is corrupted. If we prempt
920 * again we will cause corruption.
922 * WA: Disable mid-draw preemption when draw-call has a tri-fan.
924 if (brw
->primitive
== _3DPRIM_TRIFAN
)
925 object_preemption
= false;
927 /* WaDisableMidObjectPreemptionForLineLoop
929 * VF Stats Counters Missing a vertex when preemption enabled.
931 * WA: Disable mid-draw preemption when the draw uses a lineloop
934 if (brw
->primitive
== _3DPRIM_LINELOOP
)
935 object_preemption
= false;
939 * VF is corrupting GAFS data when preempted on an instance boundary and
940 * replayed with instancing enabled.
942 * WA: Disable preemption when using instanceing.
944 if (prim
->num_instances
> 1)
945 object_preemption
= false;
947 brw_enable_obj_preemption(brw
, object_preemption
);
950 /* May fail if out of video memory for texture or vbo upload, or on
951 * fallback conditions.
954 brw_draw_single_prim(struct gl_context
*ctx
,
955 const struct _mesa_prim
*prim
,
957 struct brw_transform_feedback_object
*xfb_obj
,
959 struct gl_buffer_object
*indirect
)
961 struct brw_context
*brw
= brw_context(ctx
);
962 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
965 /* Flag BRW_NEW_DRAW_CALL on every draw. This allows us to have
966 * atoms that happen on every draw call.
968 brw
->ctx
.NewDriverState
|= BRW_NEW_DRAW_CALL
;
970 /* Flush the batch if the batch/state buffers are nearly full. We can
971 * grow them if needed, but this is not free, so we'd like to avoid it.
973 intel_batchbuffer_require_space(brw
, 1500);
974 brw_require_statebuffer_space(brw
, 2400);
975 intel_batchbuffer_save_state(brw
);
976 fail_next
= intel_batchbuffer_saved_state_is_empty(brw
);
978 if (brw
->num_instances
!= prim
->num_instances
||
979 brw
->basevertex
!= prim
->basevertex
||
980 brw
->baseinstance
!= prim
->base_instance
) {
981 brw
->num_instances
= prim
->num_instances
;
982 brw
->basevertex
= prim
->basevertex
;
983 brw
->baseinstance
= prim
->base_instance
;
984 if (prim_id
> 0) { /* For i == 0 we just did this before the loop */
985 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTICES
;
986 brw_merge_inputs(brw
);
990 /* Determine if we need to flag BRW_NEW_VERTICES for updating the
991 * gl_BaseVertexARB or gl_BaseInstanceARB values. For indirect draw, we
992 * always flag if the shader uses one of the values. For direct draws,
993 * we only flag if the values change.
995 const int new_firstvertex
=
996 prim
->indexed
? prim
->basevertex
: prim
->start
;
997 const int new_baseinstance
= prim
->base_instance
;
998 const struct brw_vs_prog_data
*vs_prog_data
=
999 brw_vs_prog_data(brw
->vs
.base
.prog_data
);
1001 const bool uses_draw_parameters
=
1002 vs_prog_data
->uses_firstvertex
||
1003 vs_prog_data
->uses_baseinstance
;
1005 if ((uses_draw_parameters
&& prim
->is_indirect
) ||
1006 (vs_prog_data
->uses_firstvertex
&&
1007 brw
->draw
.params
.firstvertex
!= new_firstvertex
) ||
1008 (vs_prog_data
->uses_baseinstance
&&
1009 brw
->draw
.params
.gl_baseinstance
!= new_baseinstance
))
1010 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTICES
;
1013 brw
->draw
.params
.firstvertex
= new_firstvertex
;
1014 brw
->draw
.params
.gl_baseinstance
= new_baseinstance
;
1015 brw_bo_unreference(brw
->draw
.draw_params_bo
);
1017 if (prim
->is_indirect
) {
1018 /* Point draw_params_bo at the indirect buffer. */
1019 brw
->draw
.draw_params_bo
=
1020 intel_buffer_object(ctx
->DrawIndirectBuffer
)->buffer
;
1021 brw_bo_reference(brw
->draw
.draw_params_bo
);
1022 brw
->draw
.draw_params_offset
=
1023 prim
->indirect_offset
+ (prim
->indexed
? 12 : 8);
1025 /* Set draw_params_bo to NULL so brw_prepare_vertices knows it
1026 * has to upload gl_BaseVertex and such if they're needed.
1028 brw
->draw
.draw_params_bo
= NULL
;
1029 brw
->draw
.draw_params_offset
= 0;
1032 /* gl_DrawID always needs its own vertex buffer since it's not part of
1033 * the indirect parameter buffer. Same for is_indexed_draw, which shares
1034 * the buffer with gl_DrawID. If the program uses gl_DrawID, we need to
1035 * flag BRW_NEW_VERTICES. For the first iteration, we don't have valid
1036 * vs_prog_data, but we always flag BRW_NEW_VERTICES before the loop.
1038 if (prim_id
> 0 && vs_prog_data
->uses_drawid
)
1039 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTICES
;
1041 brw
->draw
.derived_params
.gl_drawid
= prim
->draw_id
;
1042 brw
->draw
.derived_params
.is_indexed_draw
= prim
->indexed
? ~0 : 0;
1044 brw_bo_unreference(brw
->draw
.derived_draw_params_bo
);
1045 brw
->draw
.derived_draw_params_bo
= NULL
;
1046 brw
->draw
.derived_draw_params_offset
= 0;
1048 if (devinfo
->gen
< 6)
1049 brw_set_prim(brw
, prim
);
1051 gen6_set_prim(brw
, prim
);
1055 /* Note that before the loop, brw->ctx.NewDriverState was set to != 0, and
1056 * that the state updated in the loop outside of this block is that in
1057 * *_set_prim or intel_batchbuffer_flush(), which only impacts
1058 * brw->ctx.NewDriverState.
1060 if (brw
->ctx
.NewDriverState
) {
1061 brw
->batch
.no_wrap
= true;
1062 brw_upload_render_state(brw
);
1065 if (devinfo
->gen
== 9)
1066 gen9_emit_preempt_wa(brw
, prim
);
1068 brw_emit_prim(brw
, prim
, brw
->primitive
, xfb_obj
, stream
);
1070 brw
->batch
.no_wrap
= false;
1072 if (!brw_batch_has_aperture_space(brw
, 0)) {
1074 intel_batchbuffer_reset_to_saved(brw
);
1075 intel_batchbuffer_flush(brw
);
1079 int ret
= intel_batchbuffer_flush(brw
);
1080 WARN_ONCE(ret
== -ENOSPC
,
1081 "i965: Single primitive emit exceeded "
1082 "available aperture space\n");
1086 /* Now that we know we haven't run out of aperture space, we can safely
1087 * reset the dirty bits.
1089 if (brw
->ctx
.NewDriverState
)
1090 brw_render_state_finished(brw
);
1098 brw_draw_prims(struct gl_context
*ctx
,
1099 const struct _mesa_prim
*prims
,
1101 const struct _mesa_index_buffer
*ib
,
1102 GLboolean index_bounds_valid
,
1105 struct gl_transform_feedback_object
*gl_xfb_obj
,
1107 struct gl_buffer_object
*indirect
)
1110 struct brw_context
*brw
= brw_context(ctx
);
1111 int predicate_state
= brw
->predicate
.state
;
1112 struct brw_transform_feedback_object
*xfb_obj
=
1113 (struct brw_transform_feedback_object
*) gl_xfb_obj
;
1115 if (!brw_check_conditional_render(brw
))
1118 /* Handle primitive restart if needed */
1119 if (brw_handle_primitive_restart(ctx
, prims
, nr_prims
, ib
, indirect
)) {
1120 /* The draw was handled, so we can exit now */
1124 /* Do GL_SELECT and GL_FEEDBACK rendering using swrast, even though it
1125 * won't support all the extensions we support.
1127 if (ctx
->RenderMode
!= GL_RENDER
) {
1128 perf_debug("%s render mode not supported in hardware\n",
1129 _mesa_enum_to_string(ctx
->RenderMode
));
1130 _swsetup_Wakeup(ctx
);
1132 _tnl_draw(ctx
, prims
, nr_prims
, ib
,
1133 index_bounds_valid
, min_index
, max_index
, NULL
, 0, NULL
);
1137 /* If we're going to have to upload any of the user's vertex arrays, then
1138 * get the minimum and maximum of their index buffer so we know what range
1141 if (!index_bounds_valid
&& _mesa_draw_user_array_bits(ctx
) != 0) {
1142 perf_debug("Scanning index buffer to compute index buffer bounds. "
1143 "Use glDrawRangeElements() to avoid this.\n");
1144 vbo_get_minmax_indices(ctx
, prims
, ib
, &min_index
, &max_index
, nr_prims
);
1145 index_bounds_valid
= true;
1148 brw_prepare_drawing(ctx
, ib
, index_bounds_valid
, min_index
, max_index
);
1149 /* Try drawing with the hardware, but don't do anything else if we can't
1150 * manage it. swrast doesn't support our featureset, so we can't fall back
1154 for (i
= 0; i
< nr_prims
; i
++) {
1155 /* Implementation of ARB_indirect_parameters via predicates */
1156 if (brw
->draw
.draw_params_count_bo
) {
1157 brw_emit_pipe_control_flush(brw
, PIPE_CONTROL_FLUSH_ENABLE
);
1159 /* Upload the current draw count from the draw parameters buffer to
1160 * MI_PREDICATE_SRC0.
1162 brw_load_register_mem(brw
, MI_PREDICATE_SRC0
,
1163 brw
->draw
.draw_params_count_bo
,
1164 brw
->draw
.draw_params_count_offset
);
1165 /* Zero the top 32-bits of MI_PREDICATE_SRC0 */
1166 brw_load_register_imm32(brw
, MI_PREDICATE_SRC0
+ 4, 0);
1167 /* Upload the id of the current primitive to MI_PREDICATE_SRC1. */
1168 brw_load_register_imm64(brw
, MI_PREDICATE_SRC1
, prims
[i
].draw_id
);
1171 if (i
== 0 && brw
->predicate
.state
!= BRW_PREDICATE_STATE_USE_BIT
) {
1172 OUT_BATCH(GEN7_MI_PREDICATE
| MI_PREDICATE_LOADOP_LOADINV
|
1173 MI_PREDICATE_COMBINEOP_SET
|
1174 MI_PREDICATE_COMPAREOP_SRCS_EQUAL
);
1176 OUT_BATCH(GEN7_MI_PREDICATE
|
1177 MI_PREDICATE_LOADOP_LOAD
| MI_PREDICATE_COMBINEOP_XOR
|
1178 MI_PREDICATE_COMPAREOP_SRCS_EQUAL
);
1182 brw
->predicate
.state
= BRW_PREDICATE_STATE_USE_BIT
;
1185 brw_draw_single_prim(ctx
, &prims
[i
], i
, xfb_obj
, stream
, indirect
);
1188 brw_finish_drawing(ctx
);
1189 brw
->predicate
.state
= predicate_state
;
1193 brw_draw_indirect_prims(struct gl_context
*ctx
,
1195 struct gl_buffer_object
*indirect_data
,
1196 GLsizeiptr indirect_offset
,
1197 unsigned draw_count
,
1199 struct gl_buffer_object
*indirect_params
,
1200 GLsizeiptr indirect_params_offset
,
1201 const struct _mesa_index_buffer
*ib
)
1203 struct brw_context
*brw
= brw_context(ctx
);
1204 struct _mesa_prim
*prim
;
1207 prim
= calloc(draw_count
, sizeof(*prim
));
1209 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "gl%sDraw%sIndirect%s",
1210 (draw_count
> 1) ? "Multi" : "",
1211 ib
? "Elements" : "Arrays",
1212 indirect_params
? "CountARB" : "");
1217 prim
[draw_count
- 1].end
= 1;
1218 for (i
= 0; i
< draw_count
; ++i
, indirect_offset
+= stride
) {
1219 prim
[i
].mode
= mode
;
1220 prim
[i
].indexed
= ib
!= NULL
;
1221 prim
[i
].indirect_offset
= indirect_offset
;
1222 prim
[i
].is_indirect
= 1;
1223 prim
[i
].draw_id
= i
;
1226 if (indirect_params
) {
1227 brw
->draw
.draw_params_count_bo
=
1228 intel_buffer_object(indirect_params
)->buffer
;
1229 brw_bo_reference(brw
->draw
.draw_params_count_bo
);
1230 brw
->draw
.draw_params_count_offset
= indirect_params_offset
;
1233 brw_draw_prims(ctx
, prim
, draw_count
,
1242 brw_init_draw_functions(struct dd_function_table
*functions
)
1244 /* Register our drawing function:
1246 functions
->Draw
= brw_draw_prims
;
1247 functions
->DrawIndirect
= brw_draw_indirect_prims
;
1251 brw_draw_init(struct brw_context
*brw
)
1253 for (int i
= 0; i
< VERT_ATTRIB_MAX
; i
++)
1254 brw
->vb
.inputs
[i
].buffer
= -1;
1255 brw
->vb
.nr_buffers
= 0;
1256 brw
->vb
.nr_enabled
= 0;
1260 brw_draw_destroy(struct brw_context
*brw
)
1264 for (i
= 0; i
< brw
->vb
.nr_buffers
; i
++) {
1265 brw_bo_unreference(brw
->vb
.buffers
[i
].bo
);
1266 brw
->vb
.buffers
[i
].bo
= NULL
;
1268 brw
->vb
.nr_buffers
= 0;
1270 for (i
= 0; i
< brw
->vb
.nr_enabled
; i
++) {
1271 brw
->vb
.enabled
[i
]->buffer
= -1;
1273 brw
->vb
.nr_enabled
= 0;
1275 brw_bo_unreference(brw
->ib
.bo
);