2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics 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 <keithw@vmware.com>
32 #include "main/macros.h"
33 #include "main/enums.h"
35 #include "intel_batchbuffer.h"
37 #include "brw_defines.h"
38 #include "brw_context.h"
40 #include "brw_state.h"
41 #include "compiler/brw_eu.h"
43 #include "util/ralloc.h"
45 static void compile_clip_prog( struct brw_context
*brw
,
46 struct brw_clip_prog_key
*key
)
48 const unsigned *program
;
50 unsigned program_size
;
52 mem_ctx
= ralloc_context(NULL
);
54 struct brw_clip_prog_data prog_data
;
55 program
= brw_compile_clip(brw
->screen
->compiler
, mem_ctx
, key
, &prog_data
,
56 &brw
->vue_map_geom_out
, &program_size
);
58 brw_upload_cache(&brw
->cache
,
61 program
, program_size
,
62 &prog_data
, sizeof(prog_data
),
63 &brw
->clip
.prog_offset
, &brw
->clip
.prog_data
);
67 /* Calculate interpolants for triangle and line rasterization.
70 brw_upload_clip_prog(struct brw_context
*brw
)
72 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
73 struct gl_context
*ctx
= &brw
->ctx
;
74 struct brw_clip_prog_key key
;
76 if (!brw_state_dirty(brw
,
82 BRW_NEW_FS_PROG_DATA
|
83 BRW_NEW_REDUCED_PRIMITIVE
|
84 BRW_NEW_VUE_MAP_GEOM_OUT
))
87 memset(&key
, 0, sizeof(key
));
92 /* BRW_NEW_FS_PROG_DATA */
93 const struct brw_wm_prog_data
*wm_prog_data
=
94 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
96 key
.contains_flat_varying
= wm_prog_data
->contains_flat_varying
;
97 key
.contains_noperspective_varying
=
98 wm_prog_data
->contains_noperspective_varying
;
100 STATIC_ASSERT(sizeof(key
.interp_mode
) ==
101 sizeof(wm_prog_data
->interp_mode
));
102 memcpy(key
.interp_mode
, wm_prog_data
->interp_mode
,
103 sizeof(key
.interp_mode
));
106 /* BRW_NEW_REDUCED_PRIMITIVE */
107 key
.primitive
= brw
->reduced_primitive
;
108 /* BRW_NEW_VUE_MAP_GEOM_OUT */
109 key
.attrs
= brw
->vue_map_geom_out
.slots_valid
;
112 key
.pv_first
= (ctx
->Light
.ProvokingVertex
== GL_FIRST_VERTEX_CONVENTION
);
113 /* _NEW_TRANSFORM (also part of VUE map)*/
114 if (ctx
->Transform
.ClipPlanesEnabled
)
115 key
.nr_userclip
= util_logbase2(ctx
->Transform
.ClipPlanesEnabled
) + 1;
117 if (devinfo
->gen
== 5)
118 key
.clip_mode
= BRW_CLIP_MODE_KERNEL_CLIP
;
120 key
.clip_mode
= BRW_CLIP_MODE_NORMAL
;
123 if (key
.primitive
== GL_TRIANGLES
) {
124 if (ctx
->Polygon
.CullFlag
&&
125 ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
126 key
.clip_mode
= BRW_CLIP_MODE_REJECT_ALL
;
128 GLuint fill_front
= BRW_CLIP_FILL_MODE_CULL
;
129 GLuint fill_back
= BRW_CLIP_FILL_MODE_CULL
;
130 GLuint offset_front
= 0;
131 GLuint offset_back
= 0;
133 if (!ctx
->Polygon
.CullFlag
||
134 ctx
->Polygon
.CullFaceMode
!= GL_FRONT
) {
135 switch (ctx
->Polygon
.FrontMode
) {
137 fill_front
= BRW_CLIP_FILL_MODE_FILL
;
141 fill_front
= BRW_CLIP_FILL_MODE_LINE
;
142 offset_front
= ctx
->Polygon
.OffsetLine
;
145 fill_front
= BRW_CLIP_FILL_MODE_POINT
;
146 offset_front
= ctx
->Polygon
.OffsetPoint
;
151 if (!ctx
->Polygon
.CullFlag
||
152 ctx
->Polygon
.CullFaceMode
!= GL_BACK
) {
153 switch (ctx
->Polygon
.BackMode
) {
155 fill_back
= BRW_CLIP_FILL_MODE_FILL
;
159 fill_back
= BRW_CLIP_FILL_MODE_LINE
;
160 offset_back
= ctx
->Polygon
.OffsetLine
;
163 fill_back
= BRW_CLIP_FILL_MODE_POINT
;
164 offset_back
= ctx
->Polygon
.OffsetPoint
;
169 if (ctx
->Polygon
.BackMode
!= GL_FILL
||
170 ctx
->Polygon
.FrontMode
!= GL_FILL
) {
173 /* Most cases the fixed function units will handle. Cases where
174 * one or more polygon faces are unfilled will require help:
176 key
.clip_mode
= BRW_CLIP_MODE_CLIP_NON_REJECTED
;
178 if (offset_back
|| offset_front
) {
179 /* _NEW_POLYGON, _NEW_BUFFERS */
180 key
.offset_units
= ctx
->Polygon
.OffsetUnits
* ctx
->DrawBuffer
->_MRD
* 2;
181 key
.offset_factor
= ctx
->Polygon
.OffsetFactor
* ctx
->DrawBuffer
->_MRD
;
182 key
.offset_clamp
= ctx
->Polygon
.OffsetClamp
* ctx
->DrawBuffer
->_MRD
;
185 if (!brw
->polygon_front_bit
) {
186 key
.fill_ccw
= fill_front
;
187 key
.fill_cw
= fill_back
;
188 key
.offset_ccw
= offset_front
;
189 key
.offset_cw
= offset_back
;
190 if (ctx
->Light
.Model
.TwoSide
&&
191 key
.fill_cw
!= BRW_CLIP_FILL_MODE_CULL
)
194 key
.fill_cw
= fill_front
;
195 key
.fill_ccw
= fill_back
;
196 key
.offset_cw
= offset_front
;
197 key
.offset_ccw
= offset_back
;
198 if (ctx
->Light
.Model
.TwoSide
&&
199 key
.fill_ccw
!= BRW_CLIP_FILL_MODE_CULL
)
200 key
.copy_bfc_ccw
= 1;
206 if (!brw_search_cache(&brw
->cache
, BRW_CACHE_CLIP_PROG
, &key
, sizeof(key
),
207 &brw
->clip
.prog_offset
, &brw
->clip
.prog_data
, true)) {
208 compile_clip_prog( brw
, &key
);