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>
33 #include "main/glheader.h"
34 #include "main/macros.h"
35 #include "main/enums.h"
37 #include "intel_batchbuffer.h"
39 #include "brw_defines.h"
40 #include "brw_context.h"
44 #include "brw_state.h"
46 static void compile_sf_prog( struct brw_context
*brw
,
47 struct brw_sf_prog_key
*key
)
49 GLcontext
*ctx
= &brw
->intel
.ctx
;
50 struct brw_sf_compile c
;
51 const GLuint
*program
;
55 memset(&c
, 0, sizeof(c
));
57 /* Begin the compilation:
59 brw_init_compile(brw
, &c
.func
);
62 c
.nr_attrs
= brw_count_bits(c
.key
.attrs
);
63 c
.nr_attr_regs
= (c
.nr_attrs
+1)/2;
64 c
.nr_setup_attrs
= brw_count_bits(c
.key
.attrs
);
65 c
.nr_setup_regs
= (c
.nr_setup_attrs
+1)/2;
67 c
.prog_data
.urb_read_length
= c
.nr_attr_regs
;
68 c
.prog_data
.urb_entry_size
= c
.nr_setup_regs
* 2;
70 /* Construct map from attribute number to position in the vertex.
72 for (i
= idx
= 0; i
< VERT_RESULT_MAX
; i
++)
73 if (c
.key
.attrs
& BITFIELD64_BIT(i
)) {
74 c
.attr_to_idx
[i
] = idx
;
75 c
.idx_to_attr
[idx
] = i
;
76 if (i
>= VERT_RESULT_TEX0
&& i
<= VERT_RESULT_TEX7
) {
77 c
.point_attrs
[i
].CoordReplace
=
78 ctx
->Point
.CoordReplace
[i
- VERT_RESULT_TEX0
];
81 c
.point_attrs
[i
].CoordReplace
= GL_FALSE
;
86 /* Which primitive? Or all three?
88 switch (key
->primitive
) {
91 brw_emit_tri_setup( &c
, GL_TRUE
);
95 brw_emit_line_setup( &c
, GL_TRUE
);
99 if (key
->do_point_sprite
)
100 brw_emit_point_sprite_setup( &c
, GL_TRUE
);
102 brw_emit_point_setup( &c
, GL_TRUE
);
104 case SF_UNFILLED_TRIS
:
106 brw_emit_anyprim_setup( &c
);
115 program
= brw_get_program(&c
.func
, &program_size
);
119 dri_bo_unreference(brw
->sf
.prog_bo
);
120 brw
->sf
.prog_bo
= brw_upload_cache( &brw
->cache
, BRW_SF_PROG
,
121 &c
.key
, sizeof(c
.key
),
123 program
, program_size
,
125 &brw
->sf
.prog_data
);
128 /* Calculate interpolants for triangle and line rasterization.
130 static void upload_sf_prog(struct brw_context
*brw
)
132 GLcontext
*ctx
= &brw
->intel
.ctx
;
133 struct brw_sf_prog_key key
;
135 memset(&key
, 0, sizeof(key
));
137 /* Populate the key, noting state dependencies:
139 /* CACHE_NEW_VS_PROG */
140 key
.attrs
= brw
->vs
.prog_data
->outputs_written
;
142 /* BRW_NEW_REDUCED_PRIMITIVE */
143 switch (brw
->intel
.reduced_primitive
) {
145 /* NOTE: We just use the edgeflag attribute as an indicator that
146 * unfilled triangles are active. We don't actually do the
147 * edgeflag testing here, it is already done in the clip
150 if (key
.attrs
& BITFIELD64_BIT(VERT_RESULT_EDGE
))
151 key
.primitive
= SF_UNFILLED_TRIS
;
153 key
.primitive
= SF_TRIANGLES
;
156 key
.primitive
= SF_LINES
;
159 key
.primitive
= SF_POINTS
;
163 key
.do_point_sprite
= ctx
->Point
.PointSprite
;
164 key
.sprite_origin_lower_left
= (ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
);
166 key
.do_flat_shading
= (ctx
->Light
.ShadeModel
== GL_FLAT
);
167 key
.do_twoside_color
= (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
);
170 key
.linear_color
= (ctx
->Hint
.PerspectiveCorrection
== GL_FASTEST
);
173 if (key
.do_twoside_color
) {
174 /* If we're rendering to a FBO, we have to invert the polygon
175 * face orientation, just as we invert the viewport in
176 * sf_unit_create_from_key(). ctx->DrawBuffer->Name will be
177 * nonzero if we're rendering to such an FBO.
179 key
.frontface_ccw
= (ctx
->Polygon
.FrontFace
== GL_CCW
) ^ (ctx
->DrawBuffer
->Name
!= 0);
182 dri_bo_unreference(brw
->sf
.prog_bo
);
183 brw
->sf
.prog_bo
= brw_search_cache(&brw
->cache
, BRW_SF_PROG
,
187 if (brw
->sf
.prog_bo
== NULL
)
188 compile_sf_prog( brw
, &key
);
192 const struct brw_tracked_state brw_sf_prog
= {
194 .mesa
= (_NEW_HINT
| _NEW_LIGHT
| _NEW_POLYGON
| _NEW_POINT
),
195 .brw
= (BRW_NEW_REDUCED_PRIMITIVE
),
196 .cache
= CACHE_NEW_VS_PROG
198 .prepare
= upload_sf_prog