draw: associate rhw divide with clipping not viewport flag
[mesa.git] / src / gallium / auxiliary / draw / draw_pt.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 */
32
33 #include "pipe/p_util.h"
34 #include "draw/draw_context.h"
35 #include "draw/draw_private.h"
36 #include "draw/draw_pt.h"
37
38
39 /* XXX: Shouldn't those two functions below use the '>' operator???
40 */
41
42 static boolean too_many_verts( struct draw_context *draw,
43 unsigned verts )
44 {
45 return verts < 1024;
46 }
47
48 static boolean too_many_elts( struct draw_context *draw,
49 unsigned elts )
50 {
51 return elts < (16 * 1024);
52 }
53
54
55 boolean
56 draw_pt_arrays(struct draw_context *draw,
57 unsigned prim,
58 unsigned start,
59 unsigned count)
60 {
61 const boolean pipeline = draw_need_pipeline(draw, prim);
62 const boolean cliptest = !draw->rasterizer->bypass_clipping;
63 const boolean shading = !draw->rasterizer->bypass_vs;
64 struct draw_pt_front_end *frontend = NULL;
65 struct draw_pt_middle_end *middle = NULL;
66
67
68 /* Overall we do:
69 * - frontend -- prepare fetch_elts, draw_elts - eg vcache
70 * - middle -- fetch, shade, cliptest, viewport
71 * - pipeline -- the prim pipeline: clipping, wide lines, etc
72 * - backend -- the vbuf_render provided by the driver.
73 */
74
75
76 #if 0
77 if (!cliptest && !pipeline && !shading) {
78 /* This is the 'passthrough' path:
79 */
80 /* Fetch user verts, emit hw verts:
81 */
82 middle = draw->pt.middle.fetch_emit;
83 }
84 else if (!cliptest && !pipeline) {
85 /* Fetch user verts, run vertex shader, emit hw verts:
86 */
87 middle = draw->pt.middle.fetch_shade_emit;
88 }
89 else if (!pipeline) {
90 /* Even though !pipeline, we have to run it to get clipping. We
91 * do know that the pipeline is just the clipping operation, but
92 * that probably doesn't help much.
93 *
94 * This is going to be the most important path for a lot of
95 * swtnl cards.
96 */
97 /* Fetch user verts,
98 * run vertex shader,
99 * cliptest and viewport trasform
100 * if no clipped vertices,
101 * emit hw verts
102 * else
103 * run pipline
104 */
105 middle = draw->pt.middle.fetch_shade_cliptest_pipeline_or_emit;
106 }
107 else if (!cliptest) {
108 /* Fetch user verts, run vertex shader, run pipeline:
109 */
110 middle = draw->pt.middle.fetch_shade_pipeline;
111 }
112 else {
113 /* This is what we're currently always doing:
114 */
115 /* Fetch user verts, run vertex shader, cliptest, run pipeline:
116 */
117 middle = draw->pt.middle.fetch_shade_cliptest_pipeline;
118 }
119 #else
120 if (cliptest || pipeline || shading)
121 return FALSE;
122
123 middle = draw->pt.middle.fetch_emit;
124 #endif
125
126
127 /* If !pipeline, need to make sure we respect the driver's limited
128 * capabilites to receive blocks of vertex data and elements.
129 */
130 #if 0
131 if (!pipeline) {
132 unsigned vertex_mode = passthrough;
133 unsigned nr_verts = count_vertices( draw, start, count );
134 unsigned hw_prim = prim;
135
136 if (is_elts(draw)) {
137 frontend = draw->pt.front.vcache;
138 hw_prim = reduced_prim(prim);
139 }
140
141 if (too_many_verts(nr_verts)) {
142 /* if (is_verts(draw) && can_split(prim)) {
143 draw = draw_arrays_split;
144 }
145 else */ {
146 frontend = draw->pt.front.vcache;
147 hw_prim = reduced_prim(prim);
148 }
149 }
150
151 if (too_many_elts(count)) {
152
153 /* if (is_elts(draw) && can_split(prim)) {
154 draw = draw_elts_split;
155 }
156 else */ {
157 frontend = draw->pt.front.vcache;
158 hw_prim = reduced_prim(prim);
159 }
160 }
161
162 if (!good_prim(hw_prim)) {
163 draw = draw->pt.front.vcache;
164 }
165 }
166 #else
167 frontend = draw->pt.front.vcache;
168 #endif
169
170 /* XXX: need to flush to get prim_vbuf.c to release its allocation??
171 */
172 draw_do_flush( draw, DRAW_FLUSH_BACKEND );
173
174 frontend->prepare( frontend, middle );
175
176 frontend->run( frontend,
177 prim,
178 draw_pt_elt_func( draw ),
179 draw_pt_elt_ptr( draw, start ),
180 count );
181
182 frontend->finish( frontend );
183
184 return TRUE;
185 }
186
187
188 boolean draw_pt_init( struct draw_context *draw )
189 {
190 draw->pt.middle.fetch_emit = draw_pt_fetch_emit( draw );
191 if (!draw->pt.middle.fetch_emit)
192 return FALSE;
193
194 draw->pt.front.vcache = draw_pt_vcache();
195 if (!draw->pt.front.vcache)
196 return FALSE;
197
198 return TRUE;
199 }
200
201
202 void draw_pt_destroy( struct draw_context *draw )
203 {
204 if (draw->pt.middle.fetch_emit) {
205 draw->pt.middle.fetch_emit->destroy( draw->pt.middle.fetch_emit );
206 draw->pt.middle.fetch_emit = NULL;
207 }
208
209 if (draw->pt.front.vcache) {
210 draw->pt.front.vcache->destroy( draw->pt.front.vcache );
211 draw->pt.front.vcache = NULL;
212 }
213 }