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 #include "glsl/ralloc.h"
48 static void compile_sf_prog( struct brw_context
*brw
,
49 struct brw_sf_prog_key
*key
)
51 struct intel_context
*intel
= &brw
->intel
;
52 struct brw_sf_compile c
;
53 const GLuint
*program
;
58 memset(&c
, 0, sizeof(c
));
60 mem_ctx
= ralloc_context(NULL
);
61 /* Begin the compilation:
63 brw_init_compile(brw
, &c
.func
, mem_ctx
);
66 brw_compute_vue_map(&c
.vue_map
, intel
, c
.key
.userclip_active
, c
.key
.attrs
);
67 c
.urb_entry_read_offset
= brw_sf_compute_urb_entry_read_offset(intel
);
68 c
.nr_attr_regs
= (c
.vue_map
.num_slots
+ 1)/2 - c
.urb_entry_read_offset
;
69 c
.nr_setup_regs
= c
.nr_attr_regs
;
71 c
.prog_data
.urb_read_length
= c
.nr_attr_regs
;
72 c
.prog_data
.urb_entry_size
= c
.nr_setup_regs
* 2;
74 /* Which primitive? Or all three?
76 switch (key
->primitive
) {
79 brw_emit_tri_setup( &c
, true );
83 brw_emit_line_setup( &c
, true );
87 if (key
->do_point_sprite
)
88 brw_emit_point_sprite_setup( &c
, true );
90 brw_emit_point_setup( &c
, true );
92 case SF_UNFILLED_TRIS
:
94 brw_emit_anyprim_setup( &c
);
103 program
= brw_get_program(&c
.func
, &program_size
);
105 if (unlikely(INTEL_DEBUG
& DEBUG_SF
)) {
107 for (i
= 0; i
< program_size
/ sizeof(struct brw_instruction
); i
++)
108 brw_disasm(stdout
, &((struct brw_instruction
*)program
)[i
],
113 brw_upload_cache(&brw
->cache
, BRW_SF_PROG
,
114 &c
.key
, sizeof(c
.key
),
115 program
, program_size
,
116 &c
.prog_data
, sizeof(c
.prog_data
),
117 &brw
->sf
.prog_offset
, &brw
->sf
.prog_data
);
118 ralloc_free(mem_ctx
);
121 /* Calculate interpolants for triangle and line rasterization.
123 static void upload_sf_prog(struct brw_context
*brw
)
125 struct gl_context
*ctx
= &brw
->intel
.ctx
;
126 struct brw_sf_prog_key key
;
128 memset(&key
, 0, sizeof(key
));
130 /* Populate the key, noting state dependencies:
132 /* CACHE_NEW_VS_PROG */
133 key
.attrs
= brw
->vs
.prog_data
->outputs_written
;
135 /* BRW_NEW_REDUCED_PRIMITIVE */
136 switch (brw
->intel
.reduced_primitive
) {
138 /* NOTE: We just use the edgeflag attribute as an indicator that
139 * unfilled triangles are active. We don't actually do the
140 * edgeflag testing here, it is already done in the clip
143 if (key
.attrs
& BITFIELD64_BIT(VERT_RESULT_EDGE
))
144 key
.primitive
= SF_UNFILLED_TRIS
;
146 key
.primitive
= SF_TRIANGLES
;
149 key
.primitive
= SF_LINES
;
152 key
.primitive
= SF_POINTS
;
157 key
.userclip_active
= (ctx
->Transform
.ClipPlanesEnabled
!= 0);
160 key
.do_point_sprite
= ctx
->Point
.PointSprite
;
161 if (key
.do_point_sprite
) {
164 for (i
= 0; i
< 8; i
++) {
165 if (ctx
->Point
.CoordReplace
[i
])
166 key
.point_sprite_coord_replace
|= (1 << i
);
169 key
.sprite_origin_lower_left
= (ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
);
171 key
.do_flat_shading
= (ctx
->Light
.ShadeModel
== GL_FLAT
);
172 key
.do_twoside_color
= (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
);
175 if (key
.do_twoside_color
) {
176 /* If we're rendering to a FBO, we have to invert the polygon
177 * face orientation, just as we invert the viewport in
178 * sf_unit_create_from_key(). ctx->DrawBuffer->Name will be
179 * nonzero if we're rendering to such an FBO.
181 key
.frontface_ccw
= (ctx
->Polygon
.FrontFace
== GL_CCW
) ^ (ctx
->DrawBuffer
->Name
!= 0);
184 if (!brw_search_cache(&brw
->cache
, BRW_SF_PROG
,
186 &brw
->sf
.prog_offset
, &brw
->sf
.prog_data
)) {
187 compile_sf_prog( brw
, &key
);
192 const struct brw_tracked_state brw_sf_prog
= {
194 .mesa
= (_NEW_HINT
| _NEW_LIGHT
| _NEW_POLYGON
| _NEW_POINT
| _NEW_TRANSFORM
),
195 .brw
= (BRW_NEW_REDUCED_PRIMITIVE
),
196 .cache
= CACHE_NEW_VS_PROG
198 .prepare
= upload_sf_prog