2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
32 #include "util/u_math.h"
34 #include "pipe/p_state.h"
36 #include "brw_context.h"
37 #include "brw_state.h"
38 #include "brw_defines.h"
39 #include "brw_debug.h"
40 #include "brw_pipe_rast.h"
42 static enum pipe_error
upload_sf_vp(struct brw_context
*brw
)
44 const struct pipe_viewport_state
*vp
= &brw
->curr
.viewport
;
45 const struct pipe_scissor_state
*scissor
= &brw
->curr
.scissor
;
46 struct brw_sf_viewport sfv
;
49 memset(&sfv
, 0, sizeof(sfv
));
51 /* PIPE_NEW_VIEWPORT, PIPE_NEW_SCISSOR */
53 sfv
.viewport
.m00
= vp
->scale
[0];
54 sfv
.viewport
.m11
= vp
->scale
[1];
55 sfv
.viewport
.m22
= vp
->scale
[2];
56 sfv
.viewport
.m30
= vp
->translate
[0];
57 sfv
.viewport
.m31
= vp
->translate
[1];
58 sfv
.viewport
.m32
= vp
->translate
[2];
60 sfv
.scissor
.xmin
= scissor
->minx
;
61 sfv
.scissor
.xmax
= scissor
->maxx
- 1; /* ? */
62 sfv
.scissor
.ymin
= scissor
->miny
;
63 sfv
.scissor
.ymax
= scissor
->maxy
- 1; /* ? */
65 ret
= brw_cache_data( &brw
->cache
, BRW_SF_VP
, &sfv
, NULL
, 0,
73 const struct brw_tracked_state brw_sf_vp
= {
75 .mesa
= (PIPE_NEW_VIEWPORT
|
80 .prepare
= upload_sf_vp
83 struct brw_sf_unit_key
{
84 unsigned int total_grf
;
85 unsigned int urb_entry_read_length
;
86 unsigned int nr_urb_entries
, urb_size
, sfsize
;
89 unsigned line_smooth
:1;
90 unsigned point_sprite
:1;
91 unsigned point_attenuated
:1;
92 unsigned front_face
:2;
94 unsigned flatshade_first
:1;
95 unsigned gl_rasterization_rules
:1;
96 unsigned line_last_pixel_enable
:1;
102 sf_unit_populate_key(struct brw_context
*brw
, struct brw_sf_unit_key
*key
)
104 const struct pipe_rasterizer_state
*rast
= &brw
->curr
.rast
->templ
;
105 memset(key
, 0, sizeof(*key
));
107 /* CACHE_NEW_SF_PROG */
108 key
->total_grf
= brw
->sf
.prog_data
->total_grf
;
109 key
->urb_entry_read_length
= brw
->sf
.prog_data
->urb_read_length
;
111 /* BRW_NEW_URB_FENCE */
112 key
->nr_urb_entries
= brw
->urb
.nr_sf_entries
;
113 key
->urb_size
= brw
->urb
.vsize
;
114 key
->sfsize
= brw
->urb
.sfsize
;
117 key
->scissor
= rast
->scissor
;
118 key
->front_face
= rast
->front_winding
;
119 key
->cull_mode
= rast
->cull_mode
;
120 key
->line_smooth
= rast
->line_smooth
;
121 key
->line_width
= rast
->line_width
;
122 key
->flatshade_first
= rast
->flatshade_first
;
123 key
->line_last_pixel_enable
= rast
->line_last_pixel
;
124 key
->gl_rasterization_rules
= rast
->gl_rasterization_rules
;
126 key
->point_sprite
= rast
->point_sprite
;
127 key
->point_attenuated
= rast
->point_size_per_vertex
;
129 key
->point_size
= CLAMP(rast
->point_size
,
130 rast
->point_size_min
,
131 rast
->point_size_max
);
134 static enum pipe_error
135 sf_unit_create_from_key(struct brw_context
*brw
,
136 struct brw_sf_unit_key
*key
,
137 struct brw_winsys_reloc
*reloc
,
138 struct brw_winsys_buffer
**bo_out
)
140 struct brw_sf_unit_state sf
;
142 int chipset_max_threads
;
143 memset(&sf
, 0, sizeof(sf
));
145 sf
.thread0
.grf_reg_count
= align(key
->total_grf
, 16) / 16 - 1;
147 sf
.thread0
.kernel_start_pointer
= 0;
149 sf
.thread1
.floating_point_mode
= BRW_FLOATING_POINT_NON_IEEE_754
;
151 sf
.thread3
.dispatch_grf_start_reg
= 3;
153 if (BRW_IS_IGDNG(brw
))
154 sf
.thread3
.urb_entry_read_offset
= 3;
156 sf
.thread3
.urb_entry_read_offset
= 1;
158 sf
.thread3
.urb_entry_read_length
= key
->urb_entry_read_length
;
160 sf
.thread4
.nr_urb_entries
= key
->nr_urb_entries
;
161 sf
.thread4
.urb_entry_allocation_size
= key
->sfsize
- 1;
163 /* Each SF thread produces 1 PUE, and there can be up to 24(Pre-IGDNG) or
166 if (BRW_IS_IGDNG(brw
))
167 chipset_max_threads
= 48;
169 chipset_max_threads
= 24;
171 sf
.thread4
.max_threads
= MIN2(chipset_max_threads
, key
->nr_urb_entries
) - 1;
173 if (BRW_DEBUG
& DEBUG_SINGLE_THREAD
)
174 sf
.thread4
.max_threads
= 0;
176 if (BRW_DEBUG
& DEBUG_STATS
)
177 sf
.thread4
.stats_enable
= 1;
179 /* CACHE_NEW_SF_VP */
181 sf
.sf5
.sf_viewport_state_offset
= 0;
183 sf
.sf5
.viewport_transform
= 1;
188 if (key
->front_face
== PIPE_WINDING_CCW
)
189 sf
.sf5
.front_winding
= BRW_FRONTWINDING_CCW
;
191 sf
.sf5
.front_winding
= BRW_FRONTWINDING_CW
;
193 switch (key
->cull_mode
) {
194 case PIPE_WINDING_CCW
:
195 case PIPE_WINDING_CW
:
196 sf
.sf6
.cull_mode
= (key
->front_face
== key
->cull_mode
?
200 case PIPE_WINDING_BOTH
:
201 sf
.sf6
.cull_mode
= BRW_CULLMODE_BOTH
;
203 case PIPE_WINDING_NONE
:
204 sf
.sf6
.cull_mode
= BRW_CULLMODE_NONE
;
208 sf
.sf6
.cull_mode
= BRW_CULLMODE_NONE
;
213 /* XXX use ctx->Const.Min/MaxLineWidth here */
214 sf
.sf6
.line_width
= CLAMP(key
->line_width
, 1.0, 5.0) * (1<<1);
216 sf
.sf6
.line_endcap_aa_region_width
= 1;
217 if (key
->line_smooth
)
218 sf
.sf6
.aa_enable
= 1;
219 else if (sf
.sf6
.line_width
<= 0x2)
220 sf
.sf6
.line_width
= 0;
222 /* XXX: gl_rasterization_rules? something else?
224 sf
.sf6
.point_rast_rule
= BRW_RASTRULE_UPPER_RIGHT
;
225 sf
.sf6
.point_rast_rule
= BRW_RASTRULE_LOWER_RIGHT
;
226 sf
.sf6
.point_rast_rule
= 1;
228 /* XXX clamp max depends on AA vs. non-AA */
231 sf
.sf7
.sprite_point
= key
->point_sprite
;
232 sf
.sf7
.point_size
= CLAMP(rint(key
->point_size
), 1, 255) * (1<<3);
233 sf
.sf7
.use_point_size_state
= !key
->point_attenuated
;
234 sf
.sf7
.aa_line_distance_mode
= 0;
236 /* might be BRW_NEW_PRIMITIVE if we have to adjust pv for polygons:
238 if (!key
->flatshade_first
) {
239 sf
.sf7
.trifan_pv
= 2;
240 sf
.sf7
.linestrip_pv
= 1;
241 sf
.sf7
.tristrip_pv
= 2;
243 sf
.sf7
.trifan_pv
= 1;
244 sf
.sf7
.linestrip_pv
= 0;
245 sf
.sf7
.tristrip_pv
= 0;
248 sf
.sf7
.line_last_pixel_enable
= key
->line_last_pixel_enable
;
250 /* Set bias for OpenGL rasterization rules:
252 if (key
->gl_rasterization_rules
) {
253 sf
.sf6
.dest_org_vbias
= 0x8;
254 sf
.sf6
.dest_org_hbias
= 0x8;
257 sf
.sf6
.dest_org_vbias
= 0x0;
258 sf
.sf6
.dest_org_hbias
= 0x0;
261 ret
= brw_upload_cache(&brw
->cache
, BRW_SF_UNIT
,
274 static enum pipe_error
upload_sf_unit( struct brw_context
*brw
)
276 struct brw_sf_unit_key key
;
277 struct brw_winsys_reloc reloc
[2];
279 unsigned viewport_transform
;
280 unsigned front_winding
;
283 sf_unit_populate_key(brw
, &key
);
285 /* XXX: cut this crap and pre calculate the key:
287 total_grf
= (align(key
.total_grf
, 16) / 16 - 1);
288 viewport_transform
= 1;
289 front_winding
= (key
.front_face
== PIPE_WINDING_CCW
?
290 BRW_FRONTWINDING_CCW
:
291 BRW_FRONTWINDING_CW
);
293 /* Emit SF program relocation */
294 make_reloc(&reloc
[0],
297 offsetof(struct brw_sf_unit_state
, thread0
),
300 /* Emit SF viewport relocation */
301 make_reloc(&reloc
[1],
303 front_winding
| (viewport_transform
<< 1),
304 offsetof(struct brw_sf_unit_state
, sf5
),
308 if (brw_search_cache(&brw
->cache
, BRW_SF_UNIT
,
316 ret
= sf_unit_create_from_key(brw
, &key
,
325 const struct brw_tracked_state brw_sf_unit
= {
327 .mesa
= (PIPE_NEW_RAST
),
328 .brw
= BRW_NEW_URB_FENCE
,
329 .cache
= (CACHE_NEW_SF_VP
|
332 .prepare
= upload_sf_unit
,