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"
49 brw_compile_ff_gs_prog(struct brw_context
*brw
,
50 struct brw_ff_gs_prog_key
*key
)
52 struct brw_ff_gs_compile c
;
53 const GLuint
*program
;
57 memset(&c
, 0, sizeof(c
));
60 c
.vue_map
= brw
->vs
.prog_data
->base
.vue_map
;
61 c
.nr_regs
= (c
.vue_map
.num_slots
+ 1)/2;
63 mem_ctx
= ralloc_context(NULL
);
65 /* Begin the compilation:
67 brw_init_compile(brw
, &c
.func
, mem_ctx
);
69 c
.func
.single_program_flow
= 1;
71 /* For some reason the thread is spawned with only 4 channels
74 brw_set_default_mask_control(&c
.func
, BRW_MASK_DISABLE
);
79 /* On Sandybridge, we use the GS for implementing transform feedback
80 * (called "Stream Out" in the PRM).
82 switch (key
->primitive
) {
83 case _3DPRIM_POINTLIST
:
85 check_edge_flag
= false;
87 case _3DPRIM_LINELIST
:
88 case _3DPRIM_LINESTRIP
:
89 case _3DPRIM_LINELOOP
:
91 check_edge_flag
= false;
95 case _3DPRIM_TRISTRIP
:
96 case _3DPRIM_RECTLIST
:
98 check_edge_flag
= false;
100 case _3DPRIM_QUADLIST
:
101 case _3DPRIM_QUADSTRIP
:
102 case _3DPRIM_POLYGON
:
104 check_edge_flag
= true;
107 unreachable("Unexpected primitive type in Gen6 SOL program.");
109 gen6_sol_program(&c
, key
, num_verts
, check_edge_flag
);
111 /* On Gen4-5, we use the GS to decompose certain types of primitives.
112 * Note that primitives which don't require a GS program have already
113 * been weeded out by now.
115 switch (key
->primitive
) {
116 case _3DPRIM_QUADLIST
:
117 brw_ff_gs_quads( &c
, key
);
119 case _3DPRIM_QUADSTRIP
:
120 brw_ff_gs_quad_strip( &c
, key
);
122 case _3DPRIM_LINELOOP
:
123 brw_ff_gs_lines( &c
);
126 ralloc_free(mem_ctx
);
131 brw_compact_instructions(&c
.func
, 0, 0, NULL
);
135 program
= brw_get_program(&c
.func
, &program_size
);
137 if (unlikely(INTEL_DEBUG
& DEBUG_GS
)) {
138 fprintf(stderr
, "gs:\n");
139 brw_disassemble(brw
->intelScreen
->devinfo
, c
.func
.store
,
140 0, program_size
, stderr
);
141 fprintf(stderr
, "\n");
144 brw_upload_cache(&brw
->cache
, BRW_CACHE_FF_GS_PROG
,
145 &c
.key
, sizeof(c
.key
),
146 program
, program_size
,
147 &c
.prog_data
, sizeof(c
.prog_data
),
148 &brw
->ff_gs
.prog_offset
, &brw
->ff_gs
.prog_data
);
149 ralloc_free(mem_ctx
);
153 brw_ff_gs_state_dirty(struct brw_context
*brw
)
155 return brw_state_dirty(brw
,
158 BRW_NEW_TRANSFORM_FEEDBACK
|
159 BRW_NEW_VS_PROG_DATA
);
163 brw_ff_gs_populate_key(struct brw_context
*brw
,
164 struct brw_ff_gs_prog_key
*key
)
166 static const unsigned swizzle_for_offset
[4] = {
167 BRW_SWIZZLE4(0, 1, 2, 3),
168 BRW_SWIZZLE4(1, 2, 3, 3),
169 BRW_SWIZZLE4(2, 3, 3, 3),
170 BRW_SWIZZLE4(3, 3, 3, 3)
173 struct gl_context
*ctx
= &brw
->ctx
;
175 memset(key
, 0, sizeof(*key
));
177 /* BRW_NEW_VS_PROG_DATA (part of VUE map) */
178 key
->attrs
= brw
->vs
.prog_data
->base
.vue_map
.slots_valid
;
180 /* BRW_NEW_PRIMITIVE */
181 key
->primitive
= brw
->primitive
;
184 key
->pv_first
= (ctx
->Light
.ProvokingVertex
== GL_FIRST_VERTEX_CONVENTION
);
185 if (key
->primitive
== _3DPRIM_QUADLIST
&& ctx
->Light
.ShadeModel
!= GL_FLAT
) {
186 /* Provide consistent primitive order with brw_set_prim's
187 * optimization of single quads to trifans.
189 key
->pv_first
= true;
193 /* On Gen7 and later, we don't use GS (yet). */
194 key
->need_gs_prog
= false;
195 } else if (brw
->gen
== 6) {
196 /* On Gen6, GS is used for transform feedback. */
197 /* BRW_NEW_TRANSFORM_FEEDBACK */
198 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
199 const struct gl_shader_program
*shaderprog
=
200 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_VERTEX
];
201 const struct gl_transform_feedback_info
*linked_xfb_info
=
202 &shaderprog
->LinkedTransformFeedback
;
205 /* Make sure that the VUE slots won't overflow the unsigned chars in
206 * key->transform_feedback_bindings[].
208 STATIC_ASSERT(BRW_VARYING_SLOT_COUNT
<= 256);
210 /* Make sure that we don't need more binding table entries than we've
211 * set aside for use in transform feedback. (We shouldn't, since we
212 * set aside enough binding table entries to have one per component).
214 assert(linked_xfb_info
->NumOutputs
<= BRW_MAX_SOL_BINDINGS
);
216 key
->need_gs_prog
= true;
217 key
->num_transform_feedback_bindings
= linked_xfb_info
->NumOutputs
;
218 for (i
= 0; i
< key
->num_transform_feedback_bindings
; ++i
) {
219 key
->transform_feedback_bindings
[i
] =
220 linked_xfb_info
->Outputs
[i
].OutputRegister
;
221 key
->transform_feedback_swizzles
[i
] =
222 swizzle_for_offset
[linked_xfb_info
->Outputs
[i
].ComponentOffset
];
226 /* Pre-gen6, GS is used to transform QUADLIST, QUADSTRIP, and LINELOOP
227 * into simpler primitives.
229 key
->need_gs_prog
= (brw
->primitive
== _3DPRIM_QUADLIST
||
230 brw
->primitive
== _3DPRIM_QUADSTRIP
||
231 brw
->primitive
== _3DPRIM_LINELOOP
);
235 /* Calculate interpolants for triangle and line rasterization.
238 brw_upload_ff_gs_prog(struct brw_context
*brw
)
240 struct brw_ff_gs_prog_key key
;
242 if (!brw_ff_gs_state_dirty(brw
))
247 brw_ff_gs_populate_key(brw
, &key
);
249 if (brw
->ff_gs
.prog_active
!= key
.need_gs_prog
) {
250 brw
->ctx
.NewDriverState
|= BRW_NEW_FF_GS_PROG_DATA
;
251 brw
->ff_gs
.prog_active
= key
.need_gs_prog
;
254 if (brw
->ff_gs
.prog_active
) {
255 if (!brw_search_cache(&brw
->cache
, BRW_CACHE_FF_GS_PROG
,
257 &brw
->ff_gs
.prog_offset
, &brw
->ff_gs
.prog_data
)) {
258 brw_compile_ff_gs_prog(brw
, &key
);
263 void gen6_brw_upload_ff_gs_prog(struct brw_context
*brw
)
265 brw_upload_ff_gs_prog(brw
);