1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * 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, sub license, 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 portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 #include "draw_private.h"
31 #include "draw_context.h"
33 #include "draw_llvm.h"
36 #include "tgsi/tgsi_parse.h"
37 #include "tgsi/tgsi_exec.h"
39 #include "pipe/p_shader_tokens.h"
41 #include "util/u_math.h"
42 #include "util/u_memory.h"
43 #include "util/u_prim.h"
45 /* fixme: move it from here */
46 #define MAX_PRIMITIVES 64
49 draw_gs_get_input_index(int semantic
, int index
,
50 const struct tgsi_shader_info
*input_info
)
53 const ubyte
*input_semantic_names
= input_info
->output_semantic_name
;
54 const ubyte
*input_semantic_indices
= input_info
->output_semantic_index
;
55 for (i
= 0; i
< PIPE_MAX_SHADER_OUTPUTS
; i
++) {
56 if (input_semantic_names
[i
] == semantic
&&
57 input_semantic_indices
[i
] == index
)
65 * We execute geometry shaders in the SOA mode, so ideally we want to
66 * flush when the number of currently fetched primitives is equal to
67 * the number of elements in the SOA vector. This ensures that the
68 * throughput is optimized for the given vector instrunction set.
71 draw_gs_should_flush(struct draw_geometry_shader
*shader
)
73 return (shader
->fetched_prim_count
== shader
->vector_length
);
76 /*#define DEBUG_OUTPUTS 1*/
78 tgsi_fetch_gs_outputs(struct draw_geometry_shader
*shader
,
79 unsigned num_primitives
,
80 float (**p_output
)[4])
82 struct tgsi_exec_machine
*machine
= shader
->machine
;
83 unsigned prim_idx
, j
, slot
;
84 unsigned current_idx
= 0;
89 /* Unswizzle all output results.
92 for (prim_idx
= 0; prim_idx
< num_primitives
; ++prim_idx
) {
93 unsigned num_verts_per_prim
= machine
->Primitives
[prim_idx
];
94 shader
->primitive_lengths
[prim_idx
+ shader
->emitted_primitives
] =
95 machine
->Primitives
[prim_idx
];
96 shader
->emitted_vertices
+= num_verts_per_prim
;
97 for (j
= 0; j
< num_verts_per_prim
; j
++, current_idx
++) {
98 int idx
= current_idx
* shader
->info
.num_outputs
;
100 debug_printf("%d) Output vert:\n", idx
/ shader
->info
.num_outputs
);
102 for (slot
= 0; slot
< shader
->info
.num_outputs
; slot
++) {
103 output
[slot
][0] = machine
->Outputs
[idx
+ slot
].xyzw
[0].f
[0];
104 output
[slot
][1] = machine
->Outputs
[idx
+ slot
].xyzw
[1].f
[0];
105 output
[slot
][2] = machine
->Outputs
[idx
+ slot
].xyzw
[2].f
[0];
106 output
[slot
][3] = machine
->Outputs
[idx
+ slot
].xyzw
[3].f
[0];
108 debug_printf("\t%d: %f %f %f %f\n", slot
,
114 debug_assert(!util_is_inf_or_nan(output
[slot
][0]));
116 output
= (float (*)[4])((char *)output
+ shader
->vertex_size
);
120 shader
->emitted_primitives
+= num_primitives
;
123 /*#define DEBUG_INPUTS 1*/
124 static void tgsi_fetch_gs_input(struct draw_geometry_shader
*shader
,
126 unsigned num_vertices
,
129 struct tgsi_exec_machine
*machine
= shader
->machine
;
130 unsigned slot
, vs_slot
, i
;
131 unsigned input_vertex_stride
= shader
->input_vertex_stride
;
132 const float (*input_ptr
)[4];
134 input_ptr
= shader
->input
;
136 for (i
= 0; i
< num_vertices
; ++i
) {
137 const float (*input
)[4];
139 debug_printf("%d) vertex index = %d (prim idx = %d)\n",
140 i
, indices
[i
], prim_idx
);
142 input
= (const float (*)[4])(
143 (const char *)input_ptr
+ (indices
[i
] * input_vertex_stride
));
144 for (slot
= 0, vs_slot
= 0; slot
< shader
->info
.num_inputs
; ++slot
) {
145 unsigned idx
= i
* TGSI_EXEC_MAX_INPUT_ATTRIBS
+ slot
;
146 if (shader
->info
.input_semantic_name
[slot
] == TGSI_SEMANTIC_PRIMID
) {
147 machine
->Inputs
[idx
].xyzw
[0].f
[prim_idx
] =
148 (float)shader
->in_prim_idx
;
149 machine
->Inputs
[idx
].xyzw
[1].f
[prim_idx
] =
150 (float)shader
->in_prim_idx
;
151 machine
->Inputs
[idx
].xyzw
[2].f
[prim_idx
] =
152 (float)shader
->in_prim_idx
;
153 machine
->Inputs
[idx
].xyzw
[3].f
[prim_idx
] =
154 (float)shader
->in_prim_idx
;
156 vs_slot
= draw_gs_get_input_index(
157 shader
->info
.input_semantic_name
[slot
],
158 shader
->info
.input_semantic_index
[slot
],
161 debug_printf("\tSlot = %d, vs_slot = %d, idx = %d:\n",
165 assert(!util_is_inf_or_nan(input
[vs_slot
][0]));
166 assert(!util_is_inf_or_nan(input
[vs_slot
][1]));
167 assert(!util_is_inf_or_nan(input
[vs_slot
][2]));
168 assert(!util_is_inf_or_nan(input
[vs_slot
][3]));
170 machine
->Inputs
[idx
].xyzw
[0].f
[prim_idx
] = input
[vs_slot
][0];
171 machine
->Inputs
[idx
].xyzw
[1].f
[prim_idx
] = input
[vs_slot
][1];
172 machine
->Inputs
[idx
].xyzw
[2].f
[prim_idx
] = input
[vs_slot
][2];
173 machine
->Inputs
[idx
].xyzw
[3].f
[prim_idx
] = input
[vs_slot
][3];
175 debug_printf("\t\t%f %f %f %f\n",
176 machine
->Inputs
[idx
].xyzw
[0].f
[prim_idx
],
177 machine
->Inputs
[idx
].xyzw
[1].f
[prim_idx
],
178 machine
->Inputs
[idx
].xyzw
[2].f
[prim_idx
],
179 machine
->Inputs
[idx
].xyzw
[3].f
[prim_idx
]);
187 static void tgsi_gs_prepare(struct draw_geometry_shader
*shader
,
188 const void *constants
[PIPE_MAX_CONSTANT_BUFFERS
],
189 const unsigned constants_size
[PIPE_MAX_CONSTANT_BUFFERS
])
191 struct tgsi_exec_machine
*machine
= shader
->machine
;
193 tgsi_exec_set_constant_buffers(machine
, PIPE_MAX_CONSTANT_BUFFERS
,
194 constants
, constants_size
);
197 static unsigned tgsi_gs_run(struct draw_geometry_shader
*shader
,
198 unsigned input_primitives
)
200 struct tgsi_exec_machine
*machine
= shader
->machine
;
202 tgsi_set_exec_mask(machine
,
204 input_primitives
> 1,
205 input_primitives
> 2,
206 input_primitives
> 3);
208 /* run interpreter */
209 tgsi_exec_machine_run(machine
);
212 machine
->Temps
[TGSI_EXEC_TEMP_PRIMITIVE_I
].xyzw
[TGSI_EXEC_TEMP_PRIMITIVE_C
].u
[0];
218 llvm_fetch_gs_input(struct draw_geometry_shader
*shader
,
220 unsigned num_vertices
,
223 unsigned slot
, vs_slot
, i
;
224 unsigned input_vertex_stride
= shader
->input_vertex_stride
;
225 const float (*input_ptr
)[4];
226 float (*input_data
)[6][PIPE_MAX_SHADER_INPUTS
][TGSI_NUM_CHANNELS
][TGSI_NUM_CHANNELS
] = &shader
->gs_input
->data
;
228 input_ptr
= shader
->input
;
230 for (i
= 0; i
< num_vertices
; ++i
) {
231 const float (*input
)[4];
233 debug_printf("%d) vertex index = %d (prim idx = %d)\n",
234 i
, indices
[i
], prim_idx
);
236 input
= (const float (*)[4])(
237 (const char *)input_ptr
+ (indices
[i
] * input_vertex_stride
));
238 for (slot
= 0, vs_slot
= 0; slot
< shader
->info
.num_inputs
; ++slot
) {
239 if (shader
->info
.input_semantic_name
[slot
] == TGSI_SEMANTIC_PRIMID
) {
240 (*input_data
)[i
][slot
][0][prim_idx
] = (float)shader
->in_prim_idx
;
241 (*input_data
)[i
][slot
][1][prim_idx
] = (float)shader
->in_prim_idx
;
242 (*input_data
)[i
][slot
][2][prim_idx
] = (float)shader
->in_prim_idx
;
243 (*input_data
)[i
][slot
][3][prim_idx
] = (float)shader
->in_prim_idx
;
245 vs_slot
= draw_gs_get_input_index(
246 shader
->info
.input_semantic_name
[slot
],
247 shader
->info
.input_semantic_index
[slot
],
250 debug_printf("\tSlot = %d, vs_slot = %d, idx = %d:\n",
254 assert(!util_is_inf_or_nan(input
[vs_slot
][0]));
255 assert(!util_is_inf_or_nan(input
[vs_slot
][1]));
256 assert(!util_is_inf_or_nan(input
[vs_slot
][2]));
257 assert(!util_is_inf_or_nan(input
[vs_slot
][3]));
259 (*input_data
)[i
][slot
][0][prim_idx
] = input
[vs_slot
][0];
260 (*input_data
)[i
][slot
][1][prim_idx
] = input
[vs_slot
][1];
261 (*input_data
)[i
][slot
][2][prim_idx
] = input
[vs_slot
][2];
262 (*input_data
)[i
][slot
][3][prim_idx
] = input
[vs_slot
][3];
264 debug_printf("\t\t%f %f %f %f\n",
265 (*input_data
)[i
][slot
][0][prim_idx
],
266 (*input_data
)[i
][slot
][1][prim_idx
],
267 (*input_data
)[i
][slot
][2][prim_idx
],
268 (*input_data
)[i
][slot
][3][prim_idx
]);
277 llvm_fetch_gs_outputs(struct draw_geometry_shader
*shader
,
278 unsigned num_primitives
,
279 float (**p_output
)[4])
282 int vertex_count
= 0;
284 int max_prims_per_invocation
= 0;
285 char *output_ptr
= (char*)shader
->gs_output
;
288 for (i
= 0; i
< shader
->vector_length
; ++i
) {
289 int prims
= shader
->llvm_emitted_primitives
[i
];
290 total_prims
+= prims
;
291 max_prims_per_invocation
= MAX2(max_prims_per_invocation
, prims
);
293 for (i
= 0; i
< shader
->vector_length
; ++i
) {
294 total_verts
+= shader
->llvm_emitted_vertices
[i
];
298 output_ptr
+= shader
->emitted_vertices
* shader
->vertex_size
;
299 for (i
= 0; i
< shader
->vector_length
- 1; ++i
) {
300 int current_verts
= shader
->llvm_emitted_vertices
[i
];
302 if (current_verts
!= shader
->max_output_vertices
) {
303 memcpy(output_ptr
+ (vertex_count
+ current_verts
) * shader
->vertex_size
,
304 output_ptr
+ (vertex_count
+ shader
->max_output_vertices
) * shader
->vertex_size
,
305 shader
->vertex_size
* (total_verts
- vertex_count
- current_verts
));
307 vertex_count
+= current_verts
;
311 for (i
= 0; i
< shader
->vector_length
; ++i
) {
312 int num_prims
= shader
->llvm_emitted_primitives
[i
];
313 for (j
= 0; j
< num_prims
; ++j
) {
315 shader
->llvm_prim_lengths
[j
][i
];
316 shader
->primitive_lengths
[shader
->emitted_primitives
+ prim_idx
] =
322 shader
->emitted_primitives
+= total_prims
;
323 shader
->emitted_vertices
+= total_verts
;
327 llvm_gs_prepare(struct draw_geometry_shader
*shader
,
328 const void *constants
[PIPE_MAX_CONSTANT_BUFFERS
],
329 const unsigned constants_size
[PIPE_MAX_CONSTANT_BUFFERS
])
334 llvm_gs_run(struct draw_geometry_shader
*shader
,
335 unsigned input_primitives
)
338 char *input
= (char*)shader
->gs_output
;
340 input
+= (shader
->emitted_vertices
* shader
->vertex_size
);
342 ret
= shader
->current_variant
->jit_func(
343 shader
->jit_context
, shader
->gs_input
->data
,
344 (struct vertex_header
*)input
,
346 shader
->draw
->instance_id
);
353 static void gs_flush(struct draw_geometry_shader
*shader
)
355 unsigned out_prim_count
;
357 unsigned input_primitives
= shader
->fetched_prim_count
;
359 debug_assert(input_primitives
> 0 &&
360 input_primitives
<= 4);
362 out_prim_count
= shader
->run(shader
, input_primitives
);
363 shader
->fetch_outputs(shader
, out_prim_count
,
364 &shader
->tmp_output
);
367 debug_printf("PRIM emitted prims = %d (verts=%d), cur prim count = %d\n",
368 shader
->emitted_primitives
, shader
->emitted_vertices
,
372 shader
->fetched_prim_count
= 0;
375 static void gs_point(struct draw_geometry_shader
*shader
,
382 shader
->fetch_inputs(shader
, indices
, 1,
383 shader
->fetched_prim_count
);
384 ++shader
->in_prim_idx
;
385 ++shader
->fetched_prim_count
;
390 static void gs_line(struct draw_geometry_shader
*shader
,
398 shader
->fetch_inputs(shader
, indices
, 2,
399 shader
->fetched_prim_count
);
400 ++shader
->in_prim_idx
;
401 ++shader
->fetched_prim_count
;
406 static void gs_line_adj(struct draw_geometry_shader
*shader
,
407 int i0
, int i1
, int i2
, int i3
)
416 shader
->fetch_inputs(shader
, indices
, 4,
417 shader
->fetched_prim_count
);
418 ++shader
->in_prim_idx
;
419 ++shader
->fetched_prim_count
;
424 static void gs_tri(struct draw_geometry_shader
*shader
,
425 int i0
, int i1
, int i2
)
433 shader
->fetch_inputs(shader
, indices
, 3,
434 shader
->fetched_prim_count
);
435 ++shader
->in_prim_idx
;
436 ++shader
->fetched_prim_count
;
441 static void gs_tri_adj(struct draw_geometry_shader
*shader
,
442 int i0
, int i1
, int i2
,
443 int i3
, int i4
, int i5
)
454 shader
->fetch_inputs(shader
, indices
, 6,
455 shader
->fetched_prim_count
);
456 ++shader
->in_prim_idx
;
457 ++shader
->fetched_prim_count
;
463 #define GET_ELT(idx) (idx)
464 #include "draw_gs_tmp.h"
467 #define FUNC gs_run_elts
468 #define LOCAL_VARS const ushort *elts = input_prims->elts;
469 #define GET_ELT(idx) (elts[idx])
470 #include "draw_gs_tmp.h"
474 * Execute geometry shader.
476 int draw_geometry_shader_run(struct draw_geometry_shader
*shader
,
477 const void *constants
[PIPE_MAX_CONSTANT_BUFFERS
],
478 const unsigned constants_size
[PIPE_MAX_CONSTANT_BUFFERS
],
479 const struct draw_vertex_info
*input_verts
,
480 const struct draw_prim_info
*input_prim
,
481 const struct tgsi_shader_info
*input_info
,
482 struct draw_vertex_info
*output_verts
,
483 struct draw_prim_info
*output_prims
)
485 const float (*input
)[4] = (const float (*)[4])input_verts
->verts
->data
;
486 unsigned input_stride
= input_verts
->vertex_size
;
487 unsigned num_outputs
= shader
->info
.num_outputs
;
488 unsigned vertex_size
= sizeof(struct vertex_header
) + num_outputs
* 4 * sizeof(float);
489 unsigned num_input_verts
= input_prim
->linear
?
492 unsigned num_in_primitives
=
494 MAX2(u_gs_prims_for_vertices(input_prim
->prim
, num_input_verts
),
495 u_gs_prims_for_vertices(shader
->input_primitive
, num_input_verts
)),
496 shader
->vector_length
);
497 unsigned max_out_prims
= u_gs_prims_for_vertices(shader
->output_primitive
,
498 shader
->max_output_vertices
)
501 //Assume at least one primitive
502 max_out_prims
= MAX2(max_out_prims
, 1);
505 output_verts
->vertex_size
= vertex_size
;
506 output_verts
->stride
= output_verts
->vertex_size
;
507 output_verts
->verts
=
508 (struct vertex_header
*)MALLOC(output_verts
->vertex_size
*
510 shader
->max_output_vertices
);
513 debug_printf("%s count = %d (in prims # = %d)\n",
514 __FUNCTION__
, num_input_verts
, num_in_primitives
);
515 debug_printf("\tlinear = %d, prim_info->count = %d\n",
516 input_prim
->linear
, input_prim
->count
);
517 debug_printf("\tprim pipe = %s, shader in = %s, shader out = %s, max out = %d\n",
518 u_prim_name(input_prim
->prim
),
519 u_prim_name(shader
->input_primitive
),
520 u_prim_name(shader
->output_primitive
),
521 shader
->max_output_vertices
);
524 shader
->emitted_vertices
= 0;
525 shader
->emitted_primitives
= 0;
526 shader
->vertex_size
= vertex_size
;
527 shader
->tmp_output
= (float (*)[4])output_verts
->verts
->data
;
528 shader
->in_prim_idx
= 0;
529 shader
->fetched_prim_count
= 0;
530 shader
->input_vertex_stride
= input_stride
;
531 shader
->input
= input
;
532 shader
->input_info
= input_info
;
533 FREE(shader
->primitive_lengths
);
534 shader
->primitive_lengths
= MALLOC(max_out_prims
* sizeof(unsigned));
538 if (draw_get_option_use_llvm()) {
539 shader
->gs_output
= output_verts
->verts
;
540 if (max_out_prims
> shader
->max_out_prims
) {
542 if (shader
->llvm_prim_lengths
) {
543 for (i
= 0; i
< shader
->max_out_prims
; ++i
) {
544 align_free(shader
->llvm_prim_lengths
[i
]);
546 FREE(shader
->llvm_prim_lengths
);
549 shader
->llvm_prim_lengths
= MALLOC(max_out_prims
* sizeof(unsigned*));
550 for (i
= 0; i
< max_out_prims
; ++i
) {
551 int vector_size
= shader
->vector_length
* sizeof(unsigned);
552 shader
->llvm_prim_lengths
[i
] =
553 align_malloc(vector_size
, vector_size
);
556 shader
->max_out_prims
= max_out_prims
;
558 shader
->jit_context
->prim_lengths
= shader
->llvm_prim_lengths
;
559 shader
->jit_context
->emitted_vertices
= shader
->llvm_emitted_vertices
;
560 shader
->jit_context
->emitted_prims
= shader
->llvm_emitted_primitives
;
564 shader
->prepare(shader
, constants
, constants_size
);
566 if (input_prim
->linear
)
567 gs_run(shader
, input_prim
, input_verts
,
568 output_prims
, output_verts
);
570 gs_run_elts(shader
, input_prim
, input_verts
,
571 output_prims
, output_verts
);
573 /* Flush the remaining primitives. Will happen if
574 * num_input_primitives % 4 != 0
576 if (shader
->fetched_prim_count
> 0) {
580 debug_assert(shader
->fetched_prim_count
== 0);
584 output_prims
->linear
= TRUE
;
585 output_prims
->elts
= NULL
;
586 output_prims
->start
= 0;
587 output_prims
->count
= shader
->emitted_vertices
;
588 output_prims
->prim
= shader
->output_primitive
;
589 output_prims
->flags
= 0x0;
590 output_prims
->primitive_lengths
= shader
->primitive_lengths
;
591 output_prims
->primitive_count
= shader
->emitted_primitives
;
592 output_verts
->count
= shader
->emitted_vertices
;
595 debug_printf("GS finished, prims = %d, verts = %d\n",
596 output_prims
->primitive_count
,
597 output_verts
->count
);
600 return shader
->emitted_vertices
;
603 void draw_geometry_shader_prepare(struct draw_geometry_shader
*shader
,
604 struct draw_context
*draw
)
606 if (shader
&& shader
->machine
->Tokens
!= shader
->state
.tokens
) {
607 tgsi_exec_machine_bind_shader(shader
->machine
,
608 shader
->state
.tokens
,
609 draw
->gs
.tgsi
.sampler
);
615 draw_gs_init( struct draw_context
*draw
)
617 draw
->gs
.tgsi
.machine
= tgsi_exec_machine_create();
618 if (!draw
->gs
.tgsi
.machine
)
621 draw
->gs
.tgsi
.machine
->Primitives
= align_malloc(
622 MAX_PRIMITIVES
* sizeof(struct tgsi_exec_vector
), 16);
623 if (!draw
->gs
.tgsi
.machine
->Primitives
)
625 memset(draw
->gs
.tgsi
.machine
->Primitives
, 0,
626 MAX_PRIMITIVES
* sizeof(struct tgsi_exec_vector
));
631 void draw_gs_destroy( struct draw_context
*draw
)
633 if (draw
->gs
.tgsi
.machine
) {
634 align_free(draw
->gs
.tgsi
.machine
->Primitives
);
635 tgsi_exec_machine_destroy(draw
->gs
.tgsi
.machine
);
639 struct draw_geometry_shader
*
640 draw_create_geometry_shader(struct draw_context
*draw
,
641 const struct pipe_shader_state
*state
)
644 struct llvm_geometry_shader
*llvm_gs
;
646 struct draw_geometry_shader
*gs
;
650 if (draw_get_option_use_llvm()) {
651 llvm_gs
= CALLOC_STRUCT(llvm_geometry_shader
);
658 make_empty_list(&llvm_gs
->variants
);
662 gs
= CALLOC_STRUCT(draw_geometry_shader
);
670 gs
->state
.tokens
= tgsi_dup_tokens(state
->tokens
);
671 if (!gs
->state
.tokens
) {
676 tgsi_scan_shader(state
->tokens
, &gs
->info
);
678 /* setup the defaults */
679 gs
->input_primitive
= PIPE_PRIM_TRIANGLES
;
680 gs
->output_primitive
= PIPE_PRIM_TRIANGLE_STRIP
;
681 gs
->max_output_vertices
= 32;
682 gs
->max_out_prims
= 0;
685 if (draw_get_option_use_llvm()) {
686 /* TODO: change the input array to handle the following
687 vector length, instead of the currently hardcoded
689 gs->vector_length = lp_native_vector_width / 32;*/
690 gs
->vector_length
= TGSI_NUM_CHANNELS
;
694 gs
->vector_length
= TGSI_NUM_CHANNELS
;
697 for (i
= 0; i
< gs
->info
.num_properties
; ++i
) {
698 if (gs
->info
.properties
[i
].name
==
699 TGSI_PROPERTY_GS_INPUT_PRIM
)
700 gs
->input_primitive
= gs
->info
.properties
[i
].data
[0];
701 else if (gs
->info
.properties
[i
].name
==
702 TGSI_PROPERTY_GS_OUTPUT_PRIM
)
703 gs
->output_primitive
= gs
->info
.properties
[i
].data
[0];
704 else if (gs
->info
.properties
[i
].name
==
705 TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
)
706 gs
->max_output_vertices
= gs
->info
.properties
[i
].data
[0];
709 for (i
= 0; i
< gs
->info
.num_outputs
; i
++) {
710 if (gs
->info
.output_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
&&
711 gs
->info
.output_semantic_index
[i
] == 0)
712 gs
->position_output
= i
;
715 gs
->machine
= draw
->gs
.tgsi
.machine
;
718 if (draw_get_option_use_llvm()) {
719 int vector_size
= gs
->vector_length
* sizeof(float);
720 gs
->gs_input
= align_malloc(sizeof(struct draw_gs_inputs
), 16);
721 memset(gs
->gs_input
, 0, sizeof(struct draw_gs_inputs
));
722 gs
->llvm_prim_lengths
= 0;
724 gs
->llvm_emitted_primitives
= align_malloc(vector_size
, vector_size
);
725 gs
->llvm_emitted_vertices
= align_malloc(vector_size
, vector_size
);
727 gs
->fetch_outputs
= llvm_fetch_gs_outputs
;
728 gs
->fetch_inputs
= llvm_fetch_gs_input
;
729 gs
->prepare
= llvm_gs_prepare
;
730 gs
->run
= llvm_gs_run
;
732 gs
->jit_context
= &draw
->llvm
->gs_jit_context
;
735 llvm_gs
->variant_key_size
=
736 draw_gs_llvm_variant_key_size(
737 MAX2(gs
->info
.file_max
[TGSI_FILE_SAMPLER
]+1,
738 gs
->info
.file_max
[TGSI_FILE_SAMPLER_VIEW
]+1));
742 gs
->fetch_outputs
= tgsi_fetch_gs_outputs
;
743 gs
->fetch_inputs
= tgsi_fetch_gs_input
;
744 gs
->prepare
= tgsi_gs_prepare
;
745 gs
->run
= tgsi_gs_run
;
751 void draw_bind_geometry_shader(struct draw_context
*draw
,
752 struct draw_geometry_shader
*dgs
)
754 draw_do_flush(draw
, DRAW_FLUSH_STATE_CHANGE
);
757 draw
->gs
.geometry_shader
= dgs
;
758 draw
->gs
.num_gs_outputs
= dgs
->info
.num_outputs
;
759 draw
->gs
.position_output
= dgs
->position_output
;
760 draw_geometry_shader_prepare(dgs
, draw
);
763 draw
->gs
.geometry_shader
= NULL
;
764 draw
->gs
.num_gs_outputs
= 0;
768 void draw_delete_geometry_shader(struct draw_context
*draw
,
769 struct draw_geometry_shader
*dgs
)
772 if (draw_get_option_use_llvm()) {
773 struct llvm_geometry_shader
*shader
= llvm_geometry_shader(dgs
);
774 struct draw_gs_llvm_variant_list_item
*li
;
776 li
= first_elem(&shader
->variants
);
777 while(!at_end(&shader
->variants
, li
)) {
778 struct draw_gs_llvm_variant_list_item
*next
= next_elem(li
);
779 draw_gs_llvm_destroy_variant(li
->base
);
783 assert(shader
->variants_cached
== 0);
785 if (dgs
->llvm_prim_lengths
) {
787 for (i
= 0; i
< dgs
->max_out_prims
; ++i
) {
788 align_free(dgs
->llvm_prim_lengths
[i
]);
790 FREE(dgs
->llvm_prim_lengths
);
792 align_free(dgs
->llvm_emitted_primitives
);
793 align_free(dgs
->llvm_emitted_vertices
);
795 align_free(dgs
->gs_input
);
799 FREE(dgs
->primitive_lengths
);
800 FREE((void*) dgs
->state
.tokens
);
806 void draw_gs_set_current_variant(struct draw_geometry_shader
*shader
,
807 struct draw_gs_llvm_variant
*variant
)
809 shader
->current_variant
= variant
;