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/imports.h"
29 #include "main/bufferobj.h"
31 #include "brw_context.h"
32 #include "brw_defines.h"
35 #include "intel_batchbuffer.h"
38 * Check if the hardware's cut index support can handle the primitive
39 * restart index value.
42 can_cut_index_handle_restart_index(struct gl_context
*ctx
,
43 const struct _mesa_index_buffer
*ib
)
45 struct intel_context
*intel
= intel_context(ctx
);
47 /* Haswell supports an arbitrary cut index. */
48 if (intel
->is_haswell
)
51 bool cut_index_will_work
;
54 case GL_UNSIGNED_BYTE
:
55 cut_index_will_work
= (ctx
->Array
._RestartIndex
& 0xff) == 0xff;
57 case GL_UNSIGNED_SHORT
:
58 cut_index_will_work
= (ctx
->Array
._RestartIndex
& 0xffff) == 0xffff;
61 cut_index_will_work
= ctx
->Array
._RestartIndex
== 0xffffffff;
64 cut_index_will_work
= false;
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
);
83 if (brw
->sol
.counting_primitives_generated
||
84 brw
->sol
.counting_primitives_written
) {
85 /* Counting primitives generated in hardware is not currently
86 * supported, so take the software path. We need to investigate
87 * the *_PRIMITIVES_COUNT registers to allow this to be handled
88 * entirely in hardware.
93 if (!can_cut_index_handle_restart_index(ctx
, ib
)) {
94 /* The primitive restart index can't be handled, so take
100 for ( ; nr_prims
> 0; nr_prims
--) {
106 case GL_TRIANGLE_STRIP
:
107 /* Cut index supports these primitive types */
110 /* Cut index does not support these primitive types */
112 //case GL_TRIANGLE_FAN:
114 //case GL_QUAD_STRIP:
124 * Check if primitive restart is enabled, and if so, handle it properly.
126 * In some cases the support will be handled in software. When available
127 * hardware will handle primitive restart.
130 brw_handle_primitive_restart(struct gl_context
*ctx
,
131 const struct _mesa_prim
*prim
,
133 const struct _mesa_index_buffer
*ib
)
135 struct brw_context
*brw
= brw_context(ctx
);
137 /* We only need to handle cases where there is an index buffer. */
142 /* If the driver has requested software handling of primitive restarts,
143 * then the VBO module has already taken care of things, and we can
144 * just draw as normal.
146 if (ctx
->Const
.PrimitiveRestartInSoftware
) {
150 /* If we have set the in_progress flag, then we are in the middle
151 * of handling the primitive restart draw.
153 if (brw
->prim_restart
.in_progress
) {
157 /* If PrimitiveRestart is not enabled, then we aren't concerned about
158 * handling this draw.
160 if (!(ctx
->Array
._PrimitiveRestart
)) {
164 /* Signal that we are in the process of handling the
165 * primitive restart draw
167 brw
->prim_restart
.in_progress
= true;
169 if (can_cut_index_handle_prims(ctx
, prim
, nr_prims
, ib
)) {
170 /* Cut index should work for primitive restart, so use it
172 brw
->prim_restart
.enable_cut_index
= true;
173 brw_draw_prims(ctx
, prim
, nr_prims
, ib
, GL_FALSE
, -1, -1, NULL
);
174 brw
->prim_restart
.enable_cut_index
= false;
176 /* Not all the primitive draw modes are supported by the cut index,
177 * so take the software path
179 vbo_sw_primitive_restart(ctx
, prim
, nr_prims
, ib
);
182 brw
->prim_restart
.in_progress
= false;
184 /* The primitive restart draw was completed, so return true. */
189 haswell_upload_cut_index(struct brw_context
*brw
)
191 struct intel_context
*intel
= &brw
->intel
;
192 struct gl_context
*ctx
= &intel
->ctx
;
194 /* Don't trigger on Ivybridge */
195 if (!intel
->is_haswell
)
198 const unsigned cut_index_setting
=
199 ctx
->Array
.PrimitiveRestart
? HSW_CUT_INDEX_ENABLE
: 0;
202 OUT_BATCH(_3DSTATE_VF
<< 16 | cut_index_setting
| (2 - 2));
203 OUT_BATCH(ctx
->Array
.RestartIndex
);
207 const struct brw_tracked_state haswell_cut_index
= {
209 .mesa
= _NEW_TRANSFORM
,
213 .emit
= haswell_upload_cut_index
,