2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Jordan Justen <jordan.l.justen@intel.com>
28 #include "main/bufferobj.h"
29 #include "main/varray.h"
32 #include "brw_context.h"
33 #include "brw_defines.h"
36 #include "intel_batchbuffer.h"
39 * Check if the hardware's cut index support can handle the primitive
40 * restart index value (pre-Haswell only).
43 can_cut_index_handle_restart_index(struct gl_context
*ctx
,
44 const struct _mesa_index_buffer
*ib
)
46 /* The FixedIndex variant means 0xFF, 0xFFFF, or 0xFFFFFFFF based on
47 * the index buffer type, which corresponds exactly to the hardware.
49 if (ctx
->Array
.PrimitiveRestartFixedIndex
)
52 bool cut_index_will_work
;
54 switch (ib
->index_size_shift
) {
56 cut_index_will_work
= ctx
->Array
.RestartIndex
== 0xff;
59 cut_index_will_work
= ctx
->Array
.RestartIndex
== 0xffff;
62 cut_index_will_work
= ctx
->Array
.RestartIndex
== 0xffffffff;
65 unreachable("not reached");
68 return cut_index_will_work
;
72 * Check if the hardware's cut index support can handle the primitive
76 can_cut_index_handle_prims(struct gl_context
*ctx
,
77 const struct _mesa_prim
*prim
,
79 const struct _mesa_index_buffer
*ib
)
81 struct brw_context
*brw
= brw_context(ctx
);
82 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
84 /* Otherwise Haswell can do it all. */
85 if (devinfo
->gen
>= 8 || devinfo
->is_haswell
)
88 if (!can_cut_index_handle_restart_index(ctx
, ib
)) {
89 /* The primitive restart index can't be handled, so take
95 for (unsigned i
= 0; i
< nr_prims
; i
++) {
96 switch (prim
[i
].mode
) {
101 case GL_TRIANGLE_STRIP
:
102 case GL_LINES_ADJACENCY
:
103 case GL_LINE_STRIP_ADJACENCY
:
104 case GL_TRIANGLES_ADJACENCY
:
105 case GL_TRIANGLE_STRIP_ADJACENCY
:
106 /* Cut index supports these primitive types */
109 /* Cut index does not support these primitive types */
111 //case GL_TRIANGLE_FAN:
113 //case GL_QUAD_STRIP:
123 * Check if primitive restart is enabled, and if so, handle it properly.
125 * In some cases the support will be handled in software. When available
126 * hardware will handle primitive restart.
129 brw_handle_primitive_restart(struct gl_context
*ctx
,
130 const struct _mesa_prim
*prims
,
132 const struct _mesa_index_buffer
*ib
,
133 GLuint num_instances
, GLuint base_instance
)
135 struct brw_context
*brw
= brw_context(ctx
);
137 /* We only need to handle cases where there is an index buffer. */
142 /* If we have set the in_progress flag, then we are in the middle
143 * of handling the primitive restart draw.
145 if (brw
->prim_restart
.in_progress
) {
149 /* If PrimitiveRestart is not enabled, then we aren't concerned about
150 * handling this draw.
152 if (!(ctx
->Array
._PrimitiveRestart
)) {
156 /* Signal that we are in the process of handling the
157 * primitive restart draw
159 brw
->prim_restart
.in_progress
= true;
161 if (can_cut_index_handle_prims(ctx
, prims
, nr_prims
, ib
)) {
162 /* Cut index should work for primitive restart, so use it
164 brw
->prim_restart
.enable_cut_index
= true;
165 brw_draw_prims(ctx
, prims
, nr_prims
, ib
, GL_FALSE
, -1, -1,
166 num_instances
, base_instance
, NULL
, 0);
167 brw
->prim_restart
.enable_cut_index
= false;
169 /* Not all the primitive draw modes are supported by the cut index,
170 * so take the software path
172 struct gl_buffer_object
*indirect_data
= brw
->draw
.draw_indirect_data
;
174 /* Clear this to make the draw direct. */
175 brw
->draw
.draw_indirect_data
= NULL
;
177 vbo_sw_primitive_restart(ctx
, prims
, nr_prims
, ib
, num_instances
,
178 base_instance
, indirect_data
,
179 brw
->draw
.draw_indirect_offset
);
182 brw
->prim_restart
.in_progress
= false;
184 /* The primitive restart draw was completed, so return true. */