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"
35 * Check if the hardware's cut index support can handle the primitive
36 * restart index value.
39 can_cut_index_handle_restart_index(struct gl_context *ctx,
40 const struct _mesa_index_buffer *ib)
42 bool cut_index_will_work;
45 case GL_UNSIGNED_BYTE:
46 cut_index_will_work = (ctx->Array.RestartIndex & 0xff) == 0xff;
48 case GL_UNSIGNED_SHORT:
49 cut_index_will_work = (ctx->Array.RestartIndex & 0xffff) == 0xffff;
52 cut_index_will_work = ctx->Array.RestartIndex == 0xffffffff;
55 cut_index_will_work = false;
59 return cut_index_will_work;
63 * Check if the hardware's cut index support can handle the primitive
67 can_cut_index_handle_prims(struct gl_context *ctx,
68 const struct _mesa_prim *prim,
70 const struct _mesa_index_buffer *ib)
72 if (!can_cut_index_handle_restart_index(ctx, ib)) {
73 /* The primitive restart index can't be handled, so take
79 for ( ; nr_prims > 0; nr_prims--) {
85 case GL_TRIANGLE_STRIP:
86 /* Cut index supports these primitive types */
89 /* Cut index does not support these primitive types */
91 //case GL_TRIANGLE_FAN:
103 * Check if primitive restart is enabled, and if so, handle it properly.
105 * In some cases the support will be handled in software. When available
106 * hardware will handle primitive restart.
109 brw_handle_primitive_restart(struct gl_context *ctx,
110 const struct _mesa_prim *prim,
112 const struct _mesa_index_buffer *ib)
114 struct brw_context *brw = brw_context(ctx);
116 /* We only need to handle cases where there is an index buffer. */
121 /* If the driver has requested software handling of primitive restarts,
122 * then the VBO module has already taken care of things, and we can
123 * just draw as normal.
125 if (ctx->Const.PrimitiveRestartInSoftware) {
129 /* If we have set the in_progress flag, then we are in the middle
130 * of handling the primitive restart draw.
132 if (brw->prim_restart.in_progress) {
136 /* If PrimitiveRestart is not enabled, then we aren't concerned about
137 * handling this draw.
139 if (!(ctx->Array.PrimitiveRestart)) {
143 /* Signal that we are in the process of handling the
144 * primitive restart draw
146 brw->prim_restart.in_progress = true;
148 if (can_cut_index_handle_prims(ctx, prim, nr_prims, ib)) {
149 /* Cut index should work for primitive restart, so use it
151 brw->prim_restart.enable_cut_index = true;
152 brw_draw_prims(ctx, prim, nr_prims, ib, GL_FALSE, -1, -1, NULL);
153 brw->prim_restart.enable_cut_index = false;
155 /* Not all the primitive draw modes are supported by the cut index,
156 * so take the software path
158 vbo_sw_primitive_restart(ctx, prim, nr_prims, ib);
161 brw->prim_restart.in_progress = false;
163 /* The primitive restart draw was completed, so return true. */