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>
32 #include "main/glheader.h"
33 #include "main/macros.h"
34 #include "main/enums.h"
36 #include "intel_batchbuffer.h"
38 #include "brw_defines.h"
39 #include "brw_context.h"
42 #include "brw_state.h"
45 #include "glsl/ralloc.h"
47 static void compile_gs_prog( struct brw_context
*brw
,
48 struct brw_gs_prog_key
*key
)
50 struct intel_context
*intel
= &brw
->intel
;
51 struct brw_gs_compile c
;
52 const GLuint
*program
;
56 /* Gen6: VF has already converted into polygon, and LINELOOP is
57 * converted to LINESTRIP at the beginning of the 3D pipeline.
62 memset(&c
, 0, sizeof(c
));
65 /* Need to locate the two positions present in vertex + header.
66 * These are currently hardcoded:
68 c
.nr_attrs
= brw_count_bits(c
.key
.attrs
);
71 c
.nr_regs
= (c
.nr_attrs
+ 1) / 2 + 3; /* are vertices packed, or reg-aligned? */
73 c
.nr_regs
= (c
.nr_attrs
+ 1) / 2 + 1; /* are vertices packed, or reg-aligned? */
75 c
.nr_bytes
= c
.nr_regs
* REG_SIZE
;
79 /* Begin the compilation:
81 brw_init_compile(brw
, &c
.func
, mem_ctx
);
83 c
.func
.single_program_flow
= 1;
85 /* For some reason the thread is spawned with only 4 channels
88 brw_set_mask_control(&c
.func
, BRW_MASK_DISABLE
);
91 /* Note that primitives which don't require a GS program have
92 * already been weeded out by this stage:
95 switch (key
->primitive
) {
97 brw_gs_quads( &c
, key
);
100 brw_gs_quad_strip( &c
, key
);
106 ralloc_free(mem_ctx
);
112 program
= brw_get_program(&c
.func
, &program_size
);
114 if (unlikely(INTEL_DEBUG
& DEBUG_GS
)) {
118 for (i
= 0; i
< program_size
/ sizeof(struct brw_instruction
); i
++)
119 brw_disasm(stdout
, &((struct brw_instruction
*)program
)[i
],
124 brw_upload_cache(&brw
->cache
, BRW_GS_PROG
,
125 &c
.key
, sizeof(c
.key
),
126 program
, program_size
,
127 &c
.prog_data
, sizeof(c
.prog_data
),
128 &brw
->gs
.prog_offset
, &brw
->gs
.prog_data
);
129 ralloc_free(mem_ctx
);
132 static const GLenum gs_prim
[GL_POLYGON
+1] = {
145 static void populate_key( struct brw_context
*brw
,
146 struct brw_gs_prog_key
*key
)
148 struct gl_context
*ctx
= &brw
->intel
.ctx
;
149 struct intel_context
*intel
= &brw
->intel
;
151 memset(key
, 0, sizeof(*key
));
153 /* CACHE_NEW_VS_PROG */
154 key
->attrs
= brw
->vs
.prog_data
->outputs_written
;
156 /* BRW_NEW_PRIMITIVE */
157 key
->primitive
= gs_prim
[brw
->primitive
];
160 key
->pv_first
= (ctx
->Light
.ProvokingVertex
== GL_FIRST_VERTEX_CONVENTION
);
161 if (key
->primitive
== GL_QUADS
&& ctx
->Light
.ShadeModel
!= GL_FLAT
) {
162 /* Provide consistent primitive order with brw_set_prim's
163 * optimization of single quads to trifans.
165 key
->pv_first
= GL_TRUE
;
168 key
->need_gs_prog
= (intel
->gen
>= 6)
170 : (brw
->primitive
== GL_QUADS
||
171 brw
->primitive
== GL_QUAD_STRIP
||
172 brw
->primitive
== GL_LINE_LOOP
);
175 /* Calculate interpolants for triangle and line rasterization.
177 static void prepare_gs_prog(struct brw_context
*brw
)
179 struct brw_gs_prog_key key
;
182 populate_key(brw
, &key
);
184 if (brw
->gs
.prog_active
!= key
.need_gs_prog
) {
185 brw
->state
.dirty
.cache
|= CACHE_NEW_GS_PROG
;
186 brw
->gs
.prog_active
= key
.need_gs_prog
;
189 if (brw
->gs
.prog_active
) {
190 if (!brw_search_cache(&brw
->cache
, BRW_GS_PROG
,
192 &brw
->gs
.prog_offset
, &brw
->gs
.prog_data
)) {
193 compile_gs_prog( brw
, &key
);
199 const struct brw_tracked_state brw_gs_prog
= {
202 .brw
= BRW_NEW_PRIMITIVE
,
203 .cache
= CACHE_NEW_VS_PROG
205 .prepare
= prepare_gs_prog