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/glheader.h"
33 #include "main/macros.h"
34 #include "main/enums.h"
35 #include "main/transformfeedback.h"
37 #include "intel_batchbuffer.h"
39 #include "brw_defines.h"
40 #include "brw_context.h"
43 #include "brw_state.h"
44 #include "brw_ff_gs.h"
46 #include "util/ralloc.h"
48 static void compile_ff_gs_prog(struct brw_context
*brw
,
49 struct brw_ff_gs_prog_key
*key
)
51 struct brw_ff_gs_compile c
;
52 const GLuint
*program
;
56 memset(&c
, 0, sizeof(c
));
59 c
.vue_map
= brw
->vs
.prog_data
->base
.vue_map
;
60 c
.nr_regs
= (c
.vue_map
.num_slots
+ 1)/2;
62 mem_ctx
= ralloc_context(NULL
);
64 /* Begin the compilation:
66 brw_init_compile(brw
, &c
.func
, mem_ctx
);
68 c
.func
.single_program_flow
= 1;
70 /* For some reason the thread is spawned with only 4 channels
73 brw_set_default_mask_control(&c
.func
, BRW_MASK_DISABLE
);
78 /* On Sandybridge, we use the GS for implementing transform feedback
79 * (called "Stream Out" in the PRM).
81 switch (key
->primitive
) {
82 case _3DPRIM_POINTLIST
:
84 check_edge_flag
= false;
86 case _3DPRIM_LINELIST
:
87 case _3DPRIM_LINESTRIP
:
88 case _3DPRIM_LINELOOP
:
90 check_edge_flag
= false;
94 case _3DPRIM_TRISTRIP
:
95 case _3DPRIM_RECTLIST
:
97 check_edge_flag
= false;
99 case _3DPRIM_QUADLIST
:
100 case _3DPRIM_QUADSTRIP
:
101 case _3DPRIM_POLYGON
:
103 check_edge_flag
= true;
106 unreachable("Unexpected primitive type in Gen6 SOL program.");
108 gen6_sol_program(&c
, key
, num_verts
, check_edge_flag
);
110 /* On Gen4-5, we use the GS to decompose certain types of primitives.
111 * Note that primitives which don't require a GS program have already
112 * been weeded out by now.
114 switch (key
->primitive
) {
115 case _3DPRIM_QUADLIST
:
116 brw_ff_gs_quads( &c
, key
);
118 case _3DPRIM_QUADSTRIP
:
119 brw_ff_gs_quad_strip( &c
, key
);
121 case _3DPRIM_LINELOOP
:
122 brw_ff_gs_lines( &c
);
125 ralloc_free(mem_ctx
);
130 brw_compact_instructions(&c
.func
, 0, 0, NULL
);
134 program
= brw_get_program(&c
.func
, &program_size
);
136 if (unlikely(INTEL_DEBUG
& DEBUG_GS
)) {
137 fprintf(stderr
, "gs:\n");
138 brw_disassemble(brw
, c
.func
.store
, 0, program_size
, stderr
);
139 fprintf(stderr
, "\n");
142 brw_upload_cache(&brw
->cache
, BRW_CACHE_FF_GS_PROG
,
143 &c
.key
, sizeof(c
.key
),
144 program
, program_size
,
145 &c
.prog_data
, sizeof(c
.prog_data
),
146 &brw
->ff_gs
.prog_offset
, &brw
->ff_gs
.prog_data
);
147 ralloc_free(mem_ctx
);
150 static void populate_key(struct brw_context
*brw
,
151 struct brw_ff_gs_prog_key
*key
)
153 static const unsigned swizzle_for_offset
[4] = {
154 BRW_SWIZZLE4(0, 1, 2, 3),
155 BRW_SWIZZLE4(1, 2, 3, 3),
156 BRW_SWIZZLE4(2, 3, 3, 3),
157 BRW_SWIZZLE4(3, 3, 3, 3)
160 struct gl_context
*ctx
= &brw
->ctx
;
162 memset(key
, 0, sizeof(*key
));
164 /* CACHE_NEW_VS_PROG (part of VUE map) */
165 key
->attrs
= brw
->vs
.prog_data
->base
.vue_map
.slots_valid
;
167 /* BRW_NEW_PRIMITIVE */
168 key
->primitive
= brw
->primitive
;
171 key
->pv_first
= (ctx
->Light
.ProvokingVertex
== GL_FIRST_VERTEX_CONVENTION
);
172 if (key
->primitive
== _3DPRIM_QUADLIST
&& ctx
->Light
.ShadeModel
!= GL_FLAT
) {
173 /* Provide consistent primitive order with brw_set_prim's
174 * optimization of single quads to trifans.
176 key
->pv_first
= true;
180 /* On Gen7 and later, we don't use GS (yet). */
181 key
->need_gs_prog
= false;
182 } else if (brw
->gen
== 6) {
183 /* On Gen6, GS is used for transform feedback. */
184 /* BRW_NEW_TRANSFORM_FEEDBACK */
185 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
186 const struct gl_shader_program
*shaderprog
=
187 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_VERTEX
];
188 const struct gl_transform_feedback_info
*linked_xfb_info
=
189 &shaderprog
->LinkedTransformFeedback
;
192 /* Make sure that the VUE slots won't overflow the unsigned chars in
193 * key->transform_feedback_bindings[].
195 STATIC_ASSERT(BRW_VARYING_SLOT_COUNT
<= 256);
197 /* Make sure that we don't need more binding table entries than we've
198 * set aside for use in transform feedback. (We shouldn't, since we
199 * set aside enough binding table entries to have one per component).
201 assert(linked_xfb_info
->NumOutputs
<= BRW_MAX_SOL_BINDINGS
);
203 key
->need_gs_prog
= true;
204 key
->num_transform_feedback_bindings
= linked_xfb_info
->NumOutputs
;
205 for (i
= 0; i
< key
->num_transform_feedback_bindings
; ++i
) {
206 key
->transform_feedback_bindings
[i
] =
207 linked_xfb_info
->Outputs
[i
].OutputRegister
;
208 key
->transform_feedback_swizzles
[i
] =
209 swizzle_for_offset
[linked_xfb_info
->Outputs
[i
].ComponentOffset
];
213 /* Pre-gen6, GS is used to transform QUADLIST, QUADSTRIP, and LINELOOP
214 * into simpler primitives.
216 key
->need_gs_prog
= (brw
->primitive
== _3DPRIM_QUADLIST
||
217 brw
->primitive
== _3DPRIM_QUADSTRIP
||
218 brw
->primitive
== _3DPRIM_LINELOOP
);
222 /* Calculate interpolants for triangle and line rasterization.
225 brw_upload_ff_gs_prog(struct brw_context
*brw
)
227 struct brw_ff_gs_prog_key key
;
230 populate_key(brw
, &key
);
232 if (brw
->ff_gs
.prog_active
!= key
.need_gs_prog
) {
233 brw
->state
.dirty
.cache
|= CACHE_NEW_FF_GS_PROG
;
234 brw
->ff_gs
.prog_active
= key
.need_gs_prog
;
237 if (brw
->ff_gs
.prog_active
) {
238 if (!brw_search_cache(&brw
->cache
, BRW_CACHE_FF_GS_PROG
,
240 &brw
->ff_gs
.prog_offset
, &brw
->ff_gs
.prog_data
)) {
241 compile_ff_gs_prog( brw
, &key
);
246 void gen6_brw_upload_ff_gs_prog(struct brw_context
*brw
)
248 brw_upload_ff_gs_prog(brw
);
251 const struct brw_tracked_state brw_ff_gs_prog
= {
254 .brw
= BRW_NEW_PRIMITIVE
|
255 BRW_NEW_TRANSFORM_FEEDBACK
,
256 .cache
= CACHE_NEW_VS_PROG
258 .emit
= brw_upload_ff_gs_prog