b3133359e06a4325a0977679b7fa07f64e12a399
1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "pipe/p_util.h"
34 #include "draw/draw_context.h"
35 #include "draw/draw_private.h"
36 #include "draw/draw_pt.h"
41 #define DRAW_MAX (16*1024)
43 struct vcache_frontend
{
44 struct draw_pt_front_end base
;
45 struct draw_context
*draw
;
47 unsigned in
[CACHE_MAX
];
48 ushort out
[CACHE_MAX
];
50 ushort draw_elts
[DRAW_MAX
];
51 unsigned fetch_elts
[FETCH_MAX
];
56 struct draw_pt_middle_end
*middle
;
62 static void vcache_flush( struct vcache_frontend
*vcache
)
64 if (vcache
->draw_count
) {
65 vcache
->middle
->run( vcache
->middle
,
72 memset(vcache
->in
, ~0, sizeof(vcache
->in
));
73 vcache
->fetch_count
= 0;
74 vcache
->draw_count
= 0;
77 static void vcache_check_flush( struct vcache_frontend
*vcache
)
79 if ( vcache
->draw_count
+ 6 >= DRAW_MAX
||
80 vcache
->fetch_count
+ 4 >= FETCH_MAX
)
82 vcache_flush( vcache
);
87 static INLINE
void vcache_elt( struct vcache_frontend
*vcache
,
91 unsigned idx
= felt
% CACHE_MAX
;
93 if (vcache
->in
[idx
] != felt
) {
94 assert(vcache
->fetch_count
< FETCH_MAX
);
96 vcache
->in
[idx
] = felt
;
97 vcache
->out
[idx
] = (ushort
)vcache
->fetch_count
;
98 vcache
->fetch_elts
[vcache
->fetch_count
++] = felt
;
101 vcache
->draw_elts
[vcache
->draw_count
++] = vcache
->out
[idx
] | flags
;
106 static void vcache_triangle( struct vcache_frontend
*vcache
,
111 vcache_elt(vcache
, i0
, 0);
112 vcache_elt(vcache
, i1
, 0);
113 vcache_elt(vcache
, i2
, 0);
114 vcache_check_flush(vcache
);
118 static void vcache_triangle_flags( struct vcache_frontend
*vcache
,
124 vcache_elt(vcache
, i0
, flags
);
125 vcache_elt(vcache
, i1
, 0);
126 vcache_elt(vcache
, i2
, 0);
127 vcache_check_flush(vcache
);
130 static void vcache_line( struct vcache_frontend
*vcache
,
134 vcache_elt(vcache
, i0
, 0);
135 vcache_elt(vcache
, i1
, 0);
136 vcache_check_flush(vcache
);
140 static void vcache_line_flags( struct vcache_frontend
*vcache
,
145 vcache_elt(vcache
, i0
, flags
);
146 vcache_elt(vcache
, i1
, 0);
147 vcache_check_flush(vcache
);
151 static void vcache_point( struct vcache_frontend
*vcache
,
154 vcache_elt(vcache
, i0
, 0);
155 vcache_check_flush(vcache
);
158 static void vcache_quad( struct vcache_frontend
*vcache
,
164 vcache_triangle( vcache
, i0
, i1
, i3
);
165 vcache_triangle( vcache
, i1
, i2
, i3
);
168 static void vcache_ef_quad( struct vcache_frontend
*vcache
,
174 const unsigned omitEdge1
= DRAW_PIPE_EDGE_FLAG_0
| DRAW_PIPE_EDGE_FLAG_2
;
175 const unsigned omitEdge2
= DRAW_PIPE_EDGE_FLAG_0
| DRAW_PIPE_EDGE_FLAG_1
;
177 vcache_triangle_flags( vcache
,
178 DRAW_PIPE_RESET_STIPPLE
| omitEdge1
,
181 vcache_triangle_flags( vcache
,
186 /* At least for now, we're back to using a template include file for
187 * this. The two paths aren't too different though - it may be
188 * possible to reunify them.
190 #define TRIANGLE(vc,flags,i0,i1,i2) vcache_triangle_flags(vc,flags,i0,i1,i2)
191 #define QUAD(vc,i0,i1,i2,i3) vcache_ef_quad(vc,i0,i1,i2,i3)
192 #define LINE(vc,flags,i0,i1) vcache_line_flags(vc,flags,i0,i1)
193 #define POINT(vc,i0) vcache_point(vc,i0)
194 #define FUNC vcache_run_extras
195 #include "draw_pt_vcache_tmp.h"
197 #define TRIANGLE(vc,flags,i0,i1,i2) vcache_triangle(vc,i0,i1,i2)
198 #define QUAD(vc,i0,i1,i2,i3) vcache_quad(vc,i0,i1,i2,i3)
199 #define LINE(vc,flags,i0,i1) vcache_line(vc,i0,i1)
200 #define POINT(vc,i0) vcache_point(vc,i0)
201 #define FUNC vcache_run
202 #include "draw_pt_vcache_tmp.h"
207 static unsigned reduced_prim
[PIPE_PRIM_POLYGON
+ 1] = {
222 static void vcache_prepare( struct draw_pt_front_end
*frontend
,
224 struct draw_pt_middle_end
*middle
,
227 struct vcache_frontend
*vcache
= (struct vcache_frontend
*)frontend
;
228 const struct pipe_rasterizer_state
*rasterizer
= vcache
->draw
->rasterizer
;
231 if (rasterizer
->fill_cw
!= PIPE_POLYGON_MODE_FILL
||
232 rasterizer
->fill_ccw
!= PIPE_POLYGON_MODE_FILL
||
233 rasterizer
->line_stipple_enable
)
235 assert(opt
& PT_PIPELINE
);
236 vcache
->base
.run
= vcache_run_extras
;
240 vcache
->base
.run
= vcache_run
;
243 vcache
->input_prim
= prim
;
244 vcache
->output_prim
= reduced_prim
[prim
];
246 vcache
->middle
= middle
;
247 middle
->prepare( middle
, vcache
->output_prim
, opt
);
253 static void vcache_finish( struct draw_pt_front_end
*frontend
)
255 struct vcache_frontend
*vcache
= (struct vcache_frontend
*)frontend
;
256 vcache
->middle
->finish( vcache
->middle
);
257 vcache
->middle
= NULL
;
260 static void vcache_destroy( struct draw_pt_front_end
*frontend
)
266 struct draw_pt_front_end
*draw_pt_vcache( struct draw_context
*draw
)
268 struct vcache_frontend
*vcache
= CALLOC_STRUCT( vcache_frontend
);
272 vcache
->base
.prepare
= vcache_prepare
;
273 vcache
->base
.run
= NULL
;
274 vcache
->base
.finish
= vcache_finish
;
275 vcache
->base
.destroy
= vcache_destroy
;
278 memset(vcache
->in
, ~0, sizeof(vcache
->in
));
280 return &vcache
->base
;