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>
34 #include "brw_context.h"
35 #include "brw_state.h"
36 #include "brw_defines.h"
39 static void upload_sf_vp(struct brw_context
*brw
)
41 GLcontext
*ctx
= &brw
->intel
.ctx
;
42 const GLfloat depth_scale
= 1.0F
/ ctx
->DrawBuffer
->_DepthMaxF
;
43 struct brw_sf_viewport sfv
;
45 memset(&sfv
, 0, sizeof(sfv
));
47 if (brw
->intel
.driDrawable
)
49 /* _NEW_VIEWPORT, BRW_NEW_METAOPS */
51 if (!brw
->metaops
.active
) {
52 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
54 sfv
.viewport
.m00
= v
[MAT_SX
];
55 sfv
.viewport
.m11
= - v
[MAT_SY
];
56 sfv
.viewport
.m22
= v
[MAT_SZ
] * depth_scale
;
57 sfv
.viewport
.m30
= v
[MAT_TX
];
58 sfv
.viewport
.m31
= - v
[MAT_TY
] + brw
->intel
.driDrawable
->h
;
59 sfv
.viewport
.m32
= v
[MAT_TZ
] * depth_scale
;
63 sfv
.viewport
.m11
= - 1;
66 sfv
.viewport
.m31
= brw
->intel
.driDrawable
->h
;
71 /* XXX: what state for this? */
72 if (brw
->intel
.driDrawable
)
74 intelScreenPrivate
*screen
= brw
->intel
.intelScreen
;
76 GLint x
= brw
->attribs
.Scissor
->X
;
77 GLint y
= brw
->attribs
.Scissor
->Y
;
78 GLuint w
= brw
->attribs
.Scissor
->Width
;
79 GLuint h
= brw
->attribs
.Scissor
->Height
;
82 GLint y1
= brw
->intel
.driDrawable
->h
- (y
+ h
);
84 GLint y2
= y1
+ h
- 1;
91 if (x2
>= screen
->width
) x2
= screen
->width
-1;
92 if (y2
>= screen
->height
) y2
= screen
->height
-1;
93 if (x1
>= screen
->width
) x1
= screen
->width
-1;
94 if (y1
>= screen
->height
) y1
= screen
->height
-1;
96 sfv
.scissor
.xmin
= x1
;
97 sfv
.scissor
.xmax
= x2
;
98 sfv
.scissor
.ymin
= y1
;
99 sfv
.scissor
.ymax
= y2
;
102 dri_bo_unreference(brw
->sf
.vp_bo
);
103 brw
->sf
.vp_bo
= brw_cache_data( &brw
->cache
, BRW_SF_VP
, &sfv
, NULL
, 0 );
106 const struct brw_tracked_state brw_sf_vp
= {
108 .mesa
= (_NEW_VIEWPORT
|
110 .brw
= BRW_NEW_METAOPS
,
113 .update
= upload_sf_vp
118 static void upload_sf_unit( struct brw_context
*brw
)
120 struct brw_sf_unit_state sf
;
121 memset(&sf
, 0, sizeof(sf
));
122 dri_bo
*reloc_bufs
[2];
124 /* CACHE_NEW_SF_PROG */
125 sf
.thread0
.grf_reg_count
= ALIGN(brw
->sf
.prog_data
->total_grf
, 16) / 16 - 1;
126 sf
.thread0
.kernel_start_pointer
= brw
->sf
.prog_bo
->offset
>> 6; /* reloc */
127 sf
.thread3
.urb_entry_read_length
= brw
->sf
.prog_data
->urb_read_length
;
129 sf
.thread1
.floating_point_mode
= BRW_FLOATING_POINT_NON_IEEE_754
;
130 sf
.thread3
.dispatch_grf_start_reg
= 3;
131 sf
.thread3
.urb_entry_read_offset
= 1;
133 /* BRW_NEW_URB_FENCE */
134 sf
.thread4
.nr_urb_entries
= brw
->urb
.nr_sf_entries
;
135 sf
.thread4
.urb_entry_allocation_size
= brw
->urb
.sfsize
- 1;
136 sf
.thread4
.max_threads
= MIN2(12, brw
->urb
.nr_sf_entries
/ 2) - 1;
138 if (INTEL_DEBUG
& DEBUG_SINGLE_THREAD
)
139 sf
.thread4
.max_threads
= 0;
141 if (INTEL_DEBUG
& DEBUG_STATS
)
142 sf
.thread4
.stats_enable
= 1;
144 /* CACHE_NEW_SF_VP */
145 sf
.sf5
.sf_viewport_state_offset
= brw
->sf
.vp_bo
->offset
>> 5; /* reloc */
147 sf
.sf5
.viewport_transform
= 1;
150 if (brw
->attribs
.Scissor
->Enabled
)
154 if (brw
->attribs
.Polygon
->FrontFace
== GL_CCW
)
155 sf
.sf5
.front_winding
= BRW_FRONTWINDING_CCW
;
157 sf
.sf5
.front_winding
= BRW_FRONTWINDING_CW
;
159 if (brw
->attribs
.Polygon
->CullFlag
) {
160 switch (brw
->attribs
.Polygon
->CullFaceMode
) {
162 sf
.sf6
.cull_mode
= BRW_CULLMODE_FRONT
;
165 sf
.sf6
.cull_mode
= BRW_CULLMODE_BACK
;
167 case GL_FRONT_AND_BACK
:
168 sf
.sf6
.cull_mode
= BRW_CULLMODE_BOTH
;
176 sf
.sf6
.cull_mode
= BRW_CULLMODE_NONE
;
180 /* XXX use ctx->Const.Min/MaxLineWidth here */
181 sf
.sf6
.line_width
= CLAMP(brw
->attribs
.Line
->Width
, 1.0, 5.0) * (1<<1);
183 sf
.sf6
.line_endcap_aa_region_width
= 1;
184 if (brw
->attribs
.Line
->SmoothFlag
)
185 sf
.sf6
.aa_enable
= 1;
186 else if (sf
.sf6
.line_width
<= 0x2)
187 sf
.sf6
.line_width
= 0;
190 sf
.sf6
.point_rast_rule
= 1; /* opengl conventions */
191 /* XXX clamp max depends on AA vs. non-AA */
193 sf
.sf7
.sprite_point
= brw
->attribs
.Point
->PointSprite
;
194 sf
.sf7
.point_size
= CLAMP(brw
->attribs
.Point
->Size
, 1.0, 255.0) * (1<<3);
195 sf
.sf7
.use_point_size_state
= !brw
->attribs
.Point
->_Attenuated
;
197 /* might be BRW_NEW_PRIMITIVE if we have to adjust pv for polygons:
199 sf
.sf7
.trifan_pv
= 2;
200 sf
.sf7
.linestrip_pv
= 1;
201 sf
.sf7
.tristrip_pv
= 2;
202 sf
.sf7
.line_last_pixel_enable
= 0;
204 /* Set bias for OpenGL rasterization rules:
206 sf
.sf6
.dest_org_vbias
= 0x8;
207 sf
.sf6
.dest_org_hbias
= 0x8;
209 reloc_bufs
[0] = brw
->sf
.prog_bo
;
210 reloc_bufs
[1] = brw
->sf
.vp_bo
;
212 brw
->sf
.thread0_delta
= sf
.thread0
.grf_reg_count
<< 1;
213 brw
->sf
.sf5_delta
= sf
.sf5
.front_winding
| (sf
.sf5
.viewport_transform
<< 1);
215 dri_bo_unreference(brw
->sf
.state_bo
);
216 brw
->sf
.state_bo
= brw_cache_data( &brw
->cache
, BRW_SF_UNIT
, &sf
,
220 static void emit_reloc_sf_unit(struct brw_context
*brw
)
222 /* Emit SF program relocation */
223 dri_emit_reloc(brw
->sf
.state_bo
,
224 DRM_BO_FLAG_MEM_TT
| DRM_BO_FLAG_READ
,
225 brw
->sf
.thread0_delta
,
226 offsetof(struct brw_sf_unit_state
, thread0
),
229 /* Emit SF viewport relocation */
230 dri_emit_reloc(brw
->sf
.state_bo
,
231 DRM_BO_FLAG_MEM_TT
| DRM_BO_FLAG_READ
,
233 offsetof(struct brw_sf_unit_state
, sf5
),
237 const struct brw_tracked_state brw_sf_unit
= {
239 .mesa
= (_NEW_POLYGON
|
243 .brw
= (BRW_NEW_URB_FENCE
|
245 .cache
= (CACHE_NEW_SF_VP
|
248 .update
= upload_sf_unit
,
249 .emit_reloc
= emit_reloc_sf_unit
,