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"
34 #include "main/transformfeedback.h"
36 #include "intel_batchbuffer.h"
38 #include "brw_defines.h"
39 #include "brw_context.h"
41 #include "brw_state.h"
42 #include "brw_ff_gs.h"
44 #include "util/ralloc.h"
47 brw_codegen_ff_gs_prog(struct brw_context
*brw
,
48 struct brw_ff_gs_prog_key
*key
)
50 struct brw_ff_gs_compile c
;
51 const GLuint
*program
;
55 memset(&c
, 0, sizeof(c
));
58 c
.vue_map
= brw_vue_prog_data(brw
->vs
.base
.prog_data
)->vue_map
;
59 c
.nr_regs
= (c
.vue_map
.num_slots
+ 1)/2;
61 mem_ctx
= ralloc_context(NULL
);
63 /* Begin the compilation:
65 brw_init_codegen(&brw
->screen
->devinfo
, &c
.func
, mem_ctx
);
67 c
.func
.single_program_flow
= 1;
69 /* For some reason the thread is spawned with only 4 channels
72 brw_set_default_mask_control(&c
.func
, BRW_MASK_DISABLE
);
77 /* On Sandybridge, we use the GS for implementing transform feedback
78 * (called "Stream Out" in the PRM).
80 switch (key
->primitive
) {
81 case _3DPRIM_POINTLIST
:
83 check_edge_flag
= false;
85 case _3DPRIM_LINELIST
:
86 case _3DPRIM_LINESTRIP
:
87 case _3DPRIM_LINELOOP
:
89 check_edge_flag
= false;
93 case _3DPRIM_TRISTRIP
:
94 case _3DPRIM_RECTLIST
:
96 check_edge_flag
= false;
98 case _3DPRIM_QUADLIST
:
99 case _3DPRIM_QUADSTRIP
:
100 case _3DPRIM_POLYGON
:
102 check_edge_flag
= true;
105 unreachable("Unexpected primitive type in Gen6 SOL program.");
107 gen6_sol_program(&c
, key
, num_verts
, check_edge_flag
);
109 /* On Gen4-5, we use the GS to decompose certain types of primitives.
110 * Note that primitives which don't require a GS program have already
111 * been weeded out by now.
113 switch (key
->primitive
) {
114 case _3DPRIM_QUADLIST
:
115 brw_ff_gs_quads( &c
, key
);
117 case _3DPRIM_QUADSTRIP
:
118 brw_ff_gs_quad_strip( &c
, key
);
120 case _3DPRIM_LINELOOP
:
121 brw_ff_gs_lines( &c
);
124 ralloc_free(mem_ctx
);
129 brw_compact_instructions(&c
.func
, 0, 0, NULL
);
133 program
= brw_get_program(&c
.func
, &program_size
);
135 if (unlikely(INTEL_DEBUG
& DEBUG_GS
)) {
136 fprintf(stderr
, "gs:\n");
137 brw_disassemble(&brw
->screen
->devinfo
, c
.func
.store
,
138 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
);
151 brw_ff_gs_state_dirty(const struct brw_context
*brw
)
153 return brw_state_dirty(brw
,
156 BRW_NEW_TRANSFORM_FEEDBACK
|
157 BRW_NEW_VS_PROG_DATA
);
161 brw_ff_gs_populate_key(struct brw_context
*brw
,
162 struct brw_ff_gs_prog_key
*key
)
164 static const unsigned swizzle_for_offset
[4] = {
165 BRW_SWIZZLE4(0, 1, 2, 3),
166 BRW_SWIZZLE4(1, 2, 3, 3),
167 BRW_SWIZZLE4(2, 3, 3, 3),
168 BRW_SWIZZLE4(3, 3, 3, 3)
171 struct gl_context
*ctx
= &brw
->ctx
;
173 memset(key
, 0, sizeof(*key
));
175 /* BRW_NEW_VS_PROG_DATA (part of VUE map) */
176 key
->attrs
= brw_vue_prog_data(brw
->vs
.base
.prog_data
)->vue_map
.slots_valid
;
178 /* BRW_NEW_PRIMITIVE */
179 key
->primitive
= brw
->primitive
;
182 key
->pv_first
= (ctx
->Light
.ProvokingVertex
== GL_FIRST_VERTEX_CONVENTION
);
183 if (key
->primitive
== _3DPRIM_QUADLIST
&& ctx
->Light
.ShadeModel
!= GL_FLAT
) {
184 /* Provide consistent primitive order with brw_set_prim's
185 * optimization of single quads to trifans.
187 key
->pv_first
= true;
191 /* On Gen7 and later, we don't use GS (yet). */
192 key
->need_gs_prog
= false;
193 } else if (brw
->gen
== 6) {
194 /* On Gen6, GS is used for transform feedback. */
195 /* BRW_NEW_TRANSFORM_FEEDBACK */
196 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
197 const struct gl_program
*prog
=
198 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_VERTEX
];
199 const struct gl_transform_feedback_info
*linked_xfb_info
=
200 prog
->sh
.LinkedTransformFeedback
;
203 /* Make sure that the VUE slots won't overflow the unsigned chars in
204 * key->transform_feedback_bindings[].
206 STATIC_ASSERT(BRW_VARYING_SLOT_COUNT
<= 256);
208 /* Make sure that we don't need more binding table entries than we've
209 * set aside for use in transform feedback. (We shouldn't, since we
210 * set aside enough binding table entries to have one per component).
212 assert(linked_xfb_info
->NumOutputs
<= BRW_MAX_SOL_BINDINGS
);
214 key
->need_gs_prog
= true;
215 key
->num_transform_feedback_bindings
= linked_xfb_info
->NumOutputs
;
216 for (i
= 0; i
< key
->num_transform_feedback_bindings
; ++i
) {
217 key
->transform_feedback_bindings
[i
] =
218 linked_xfb_info
->Outputs
[i
].OutputRegister
;
219 key
->transform_feedback_swizzles
[i
] =
220 swizzle_for_offset
[linked_xfb_info
->Outputs
[i
].ComponentOffset
];
224 /* Pre-gen6, GS is used to transform QUADLIST, QUADSTRIP, and LINELOOP
225 * into simpler primitives.
227 key
->need_gs_prog
= (brw
->primitive
== _3DPRIM_QUADLIST
||
228 brw
->primitive
== _3DPRIM_QUADSTRIP
||
229 brw
->primitive
== _3DPRIM_LINELOOP
);
233 /* Calculate interpolants for triangle and line rasterization.
236 brw_upload_ff_gs_prog(struct brw_context
*brw
)
238 struct brw_ff_gs_prog_key key
;
240 if (!brw_ff_gs_state_dirty(brw
))
245 brw_ff_gs_populate_key(brw
, &key
);
247 if (brw
->ff_gs
.prog_active
!= key
.need_gs_prog
) {
248 brw
->ctx
.NewDriverState
|= BRW_NEW_FF_GS_PROG_DATA
;
249 brw
->ff_gs
.prog_active
= key
.need_gs_prog
;
252 if (brw
->ff_gs
.prog_active
) {
253 if (!brw_search_cache(&brw
->cache
, BRW_CACHE_FF_GS_PROG
,
255 &brw
->ff_gs
.prog_offset
, &brw
->ff_gs
.prog_data
)) {
256 brw_codegen_ff_gs_prog(brw
, &key
);
261 void gen6_brw_upload_ff_gs_prog(struct brw_context
*brw
)
263 brw_upload_ff_gs_prog(brw
);