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 struct gl_context
*ctx
= &brw
->ctx
;
73 struct brw_clip_prog_key key
;
75 if (!brw_state_dirty(brw
,
81 BRW_NEW_FS_PROG_DATA
|
82 BRW_NEW_REDUCED_PRIMITIVE
|
83 BRW_NEW_VUE_MAP_GEOM_OUT
))
86 memset(&key
, 0, sizeof(key
));
91 /* BRW_NEW_FS_PROG_DATA */
92 const struct brw_wm_prog_data
*wm_prog_data
=
93 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
95 key
.contains_flat_varying
= wm_prog_data
->contains_flat_varying
;
96 key
.contains_noperspective_varying
=
97 wm_prog_data
->contains_noperspective_varying
;
99 STATIC_ASSERT(sizeof(key
.interp_mode
) ==
100 sizeof(wm_prog_data
->interp_mode
));
101 memcpy(key
.interp_mode
, wm_prog_data
->interp_mode
,
102 sizeof(key
.interp_mode
));
105 /* BRW_NEW_REDUCED_PRIMITIVE */
106 key
.primitive
= brw
->reduced_primitive
;
107 /* BRW_NEW_VUE_MAP_GEOM_OUT */
108 key
.attrs
= brw
->vue_map_geom_out
.slots_valid
;
111 key
.pv_first
= (ctx
->Light
.ProvokingVertex
== GL_FIRST_VERTEX_CONVENTION
);
112 /* _NEW_TRANSFORM (also part of VUE map)*/
113 if (ctx
->Transform
.ClipPlanesEnabled
)
114 key
.nr_userclip
= _mesa_logbase2(ctx
->Transform
.ClipPlanesEnabled
) + 1;
117 key
.clip_mode
= BRW_CLIP_MODE_KERNEL_CLIP
;
119 key
.clip_mode
= BRW_CLIP_MODE_NORMAL
;
122 if (key
.primitive
== GL_TRIANGLES
) {
123 if (ctx
->Polygon
.CullFlag
&&
124 ctx
->Polygon
.CullFaceMode
== GL_FRONT_AND_BACK
)
125 key
.clip_mode
= BRW_CLIP_MODE_REJECT_ALL
;
127 GLuint fill_front
= BRW_CLIP_FILL_MODE_CULL
;
128 GLuint fill_back
= BRW_CLIP_FILL_MODE_CULL
;
129 GLuint offset_front
= 0;
130 GLuint offset_back
= 0;
132 if (!ctx
->Polygon
.CullFlag
||
133 ctx
->Polygon
.CullFaceMode
!= GL_FRONT
) {
134 switch (ctx
->Polygon
.FrontMode
) {
136 fill_front
= BRW_CLIP_FILL_MODE_FILL
;
140 fill_front
= BRW_CLIP_FILL_MODE_LINE
;
141 offset_front
= ctx
->Polygon
.OffsetLine
;
144 fill_front
= BRW_CLIP_FILL_MODE_POINT
;
145 offset_front
= ctx
->Polygon
.OffsetPoint
;
150 if (!ctx
->Polygon
.CullFlag
||
151 ctx
->Polygon
.CullFaceMode
!= GL_BACK
) {
152 switch (ctx
->Polygon
.BackMode
) {
154 fill_back
= BRW_CLIP_FILL_MODE_FILL
;
158 fill_back
= BRW_CLIP_FILL_MODE_LINE
;
159 offset_back
= ctx
->Polygon
.OffsetLine
;
162 fill_back
= BRW_CLIP_FILL_MODE_POINT
;
163 offset_back
= ctx
->Polygon
.OffsetPoint
;
168 if (ctx
->Polygon
.BackMode
!= GL_FILL
||
169 ctx
->Polygon
.FrontMode
!= GL_FILL
) {
172 /* Most cases the fixed function units will handle. Cases where
173 * one or more polygon faces are unfilled will require help:
175 key
.clip_mode
= BRW_CLIP_MODE_CLIP_NON_REJECTED
;
177 if (offset_back
|| offset_front
) {
178 /* _NEW_POLYGON, _NEW_BUFFERS */
179 key
.offset_units
= ctx
->Polygon
.OffsetUnits
* ctx
->DrawBuffer
->_MRD
* 2;
180 key
.offset_factor
= ctx
->Polygon
.OffsetFactor
* ctx
->DrawBuffer
->_MRD
;
181 key
.offset_clamp
= ctx
->Polygon
.OffsetClamp
* ctx
->DrawBuffer
->_MRD
;
184 if (!brw
->polygon_front_bit
) {
185 key
.fill_ccw
= fill_front
;
186 key
.fill_cw
= fill_back
;
187 key
.offset_ccw
= offset_front
;
188 key
.offset_cw
= offset_back
;
189 if (ctx
->Light
.Model
.TwoSide
&&
190 key
.fill_cw
!= BRW_CLIP_FILL_MODE_CULL
)
193 key
.fill_cw
= fill_front
;
194 key
.fill_ccw
= fill_back
;
195 key
.offset_cw
= offset_front
;
196 key
.offset_ccw
= offset_back
;
197 if (ctx
->Light
.Model
.TwoSide
&&
198 key
.fill_ccw
!= BRW_CLIP_FILL_MODE_CULL
)
199 key
.copy_bfc_ccw
= 1;
205 if (!brw_search_cache(&brw
->cache
, BRW_CACHE_CLIP_PROG
,
207 &brw
->clip
.prog_offset
, &brw
->clip
.prog_data
)) {
208 compile_clip_prog( brw
, &key
);