draw/sample: add support for indirect images
[mesa.git] / src / gallium / auxiliary / draw / draw_tess.c
1 /**************************************************************************
2 *
3 * Copyright 2020 Red Hat.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **************************************************************************/
25 #include "draw_tess.h"
26 #ifdef LLVM_AVAILABLE
27 #include "draw_llvm.h"
28 #endif
29
30 #include "tessellator/p_tessellator.h"
31 #include "nir/nir_to_tgsi_info.h"
32 #include "util/u_prim.h"
33 #include "util/u_math.h"
34 #include "util/u_memory.h"
35 #include "util/ralloc.h"
36 static inline int
37 draw_tes_get_input_index(int semantic, int index,
38 const struct tgsi_shader_info *input_info)
39 {
40 int i;
41 const ubyte *input_semantic_names = input_info->output_semantic_name;
42 const ubyte *input_semantic_indices = input_info->output_semantic_index;
43 for (i = 0; i < PIPE_MAX_SHADER_OUTPUTS; i++) {
44 if (input_semantic_names[i] == semantic &&
45 input_semantic_indices[i] == index)
46 return i;
47 }
48 return -1;
49 }
50
51 #ifdef LLVM_AVAILABLE
52 #define DEBUG_INPUTS 0
53 static void
54 llvm_fetch_tcs_input(struct draw_tess_ctrl_shader *shader,
55 const struct draw_prim_info *input_prim_info,
56 unsigned prim_id,
57 unsigned num_vertices)
58 {
59 const float (*input_ptr)[4];
60 float (*input_data)[32][NUM_TCS_INPUTS][TGSI_NUM_CHANNELS] = &shader->tcs_input->data;
61 unsigned slot, i;
62 int vs_slot;
63 unsigned input_vertex_stride = shader->input_vertex_stride;
64
65 input_ptr = shader->input;
66 for (i = 0; i < num_vertices; i++) {
67 const float (*input)[4];
68 int vertex_idx = prim_id * num_vertices + i;
69 if (input_prim_info->linear == FALSE)
70 vertex_idx = input_prim_info->elts[vertex_idx];
71 #if DEBUG_INPUTS
72 debug_printf("%d) tcs vertex index = %d (prim idx = %d)\n",
73 i, prim_id, 0);
74 #endif
75 input = (const float (*)[4])((const char *)input_ptr + (vertex_idx * input_vertex_stride));
76 for (slot = 0, vs_slot = 0; slot < shader->info.num_inputs; ++slot) {
77 vs_slot = draw_tes_get_input_index(
78 shader->info.input_semantic_name[slot],
79 shader->info.input_semantic_index[slot],
80 shader->input_info);
81 if (vs_slot < 0) {
82 debug_printf("VS/TCS signature mismatch!\n");
83 (*input_data)[i][slot][0] = 0;
84 (*input_data)[i][slot][1] = 0;
85 (*input_data)[i][slot][2] = 0;
86 (*input_data)[i][slot][3] = 0;
87 } else {
88 (*input_data)[i][slot][0] = input[vs_slot][0];
89 (*input_data)[i][slot][1] = input[vs_slot][1];
90 (*input_data)[i][slot][2] = input[vs_slot][2];
91 (*input_data)[i][slot][3] = input[vs_slot][3];
92 #if DEBUG_INPUTS
93 debug_printf("\t\t%p = %f %f %f %f\n", &(*input_data)[i][slot][0],
94 (*input_data)[i][slot][0],
95 (*input_data)[i][slot][1],
96 (*input_data)[i][slot][2],
97 (*input_data)[i][slot][3]);
98 #endif
99 ++vs_slot;
100 }
101 }
102 }
103 }
104
105 #define DEBUG_OUTPUTS 0
106 static void
107 llvm_store_tcs_output(struct draw_tess_ctrl_shader *shader,
108 unsigned prim_id,
109 struct draw_vertex_info *output_verts,
110 unsigned vert_start)
111 {
112 float (*output_ptr)[4];
113 float (*output_data)[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS] = &shader->tcs_output->data;
114 unsigned slot, i;
115 unsigned num_vertices = shader->vertices_out;
116
117 char *output = (char *)output_verts->verts->data;
118 output += vert_start * output_verts->stride;
119
120 for (i = 0; i < num_vertices; i++) {
121
122 #if DEBUG_OUTPUTS
123 debug_printf("%d) tcs store vertex index = %d (prim idx = %d)\n",
124 i, prim_id, 0);
125 #endif
126 output_ptr = (float(*)[4])(output + (i * output_verts->stride));
127
128 for (slot = 0; slot < shader->info.num_outputs; ++slot) {
129 output_ptr[slot][0] = (*output_data)[i][slot][0];
130 output_ptr[slot][1] = (*output_data)[i][slot][1];
131 output_ptr[slot][2] = (*output_data)[i][slot][2];
132 output_ptr[slot][3] = (*output_data)[i][slot][3];
133 #if DEBUG_OUTPUTS
134 debug_printf("\t\t%p = %f %f %f %f\n",
135 &output_ptr[slot][0],
136 output_ptr[slot][0],
137 output_ptr[slot][1],
138 output_ptr[slot][2],
139 output_ptr[slot][3]);
140 #endif
141 }
142 }
143 }
144
145 static void
146 llvm_tcs_run(struct draw_tess_ctrl_shader *shader, uint32_t prim_id)
147 {
148 shader->current_variant->jit_func(shader->jit_context, shader->tcs_input->data, shader->tcs_output->data, prim_id,
149 shader->draw->pt.vertices_per_patch);
150 }
151 #endif
152
153 /**
154 * Execute tess ctrl shader.
155 */
156 int draw_tess_ctrl_shader_run(struct draw_tess_ctrl_shader *shader,
157 const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
158 const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS],
159 const struct draw_vertex_info *input_verts,
160 const struct draw_prim_info *input_prim,
161 const struct tgsi_shader_info *input_info,
162 struct draw_vertex_info *output_verts,
163 struct draw_prim_info *output_prims )
164 {
165 const float (*input)[4] = (const float (*)[4])input_verts->verts->data;
166 unsigned num_outputs = draw_total_tcs_outputs(shader->draw);
167 unsigned input_stride = input_verts->vertex_size;
168 unsigned vertex_size = sizeof(struct vertex_header) + num_outputs * 4 * sizeof(float);
169 unsigned num_patches = input_prim->count / shader->draw->pt.vertices_per_patch;
170
171 output_verts->vertex_size = vertex_size;
172 output_verts->stride = output_verts->vertex_size;
173 output_verts->verts = NULL;
174 output_verts->count = 0;
175 shader->input = input;
176 shader->input_vertex_stride = input_stride;
177 shader->input_info = input_info;
178
179 output_prims->linear = TRUE;
180 output_prims->start = 0;
181 output_prims->elts = NULL;
182 output_prims->count = 0;
183 output_prims->prim = PIPE_PRIM_PATCHES;
184 output_prims->flags = 0;
185 output_prims->primitive_lengths = NULL;
186 output_prims->primitive_count = 0;
187
188 if (shader->draw->collect_statistics) {
189 shader->draw->statistics.hs_invocations += num_patches;
190 }
191 #ifdef LLVM_AVAILABLE
192 for (unsigned i = 0; i < num_patches; i++) {
193 uint32_t vert_start = output_verts->count;
194
195 output_verts->count += shader->vertices_out;
196
197 llvm_fetch_tcs_input(shader, input_prim, i, shader->draw->pt.vertices_per_patch);
198
199 llvm_tcs_run(shader, i);
200
201 uint32_t old_verts = util_align_npot(vert_start, 16);
202 uint32_t new_verts = util_align_npot(output_verts->count, 16);
203 uint32_t old_size = output_verts->vertex_size * old_verts;
204 uint32_t new_size = output_verts->vertex_size * new_verts;
205 output_verts->verts = REALLOC(output_verts->verts, old_size, new_size);
206
207 llvm_store_tcs_output(shader, i, output_verts, vert_start);
208 }
209 #endif
210
211 output_prims->primitive_count = num_patches;
212 return 0;
213 }
214
215 #ifdef LLVM_AVAILABLE
216 #define DEBUG_INPUTS 0
217 static void
218 llvm_fetch_tes_input(struct draw_tess_eval_shader *shader,
219 const struct draw_prim_info *input_prim_info,
220 unsigned prim_id,
221 unsigned num_vertices)
222 {
223 const float (*input_ptr)[4];
224 float (*input_data)[32][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS] = &shader->tes_input->data;
225 unsigned slot, i;
226 int vs_slot;
227 unsigned input_vertex_stride = shader->input_vertex_stride;
228
229 input_ptr = shader->input;
230 for (i = 0; i < num_vertices; i++) {
231 const float (*input)[4];
232 int vertex_idx = prim_id * num_vertices + i;
233
234 if (input_prim_info->linear == FALSE)
235 vertex_idx = input_prim_info->elts[vertex_idx];
236 #if DEBUG_INPUTS
237 debug_printf("%d) tes vertex index = %d (prim idx = %d)\n",
238 i, prim_id, 0);
239 #endif
240 input = (const float (*)[4])((const char *)input_ptr + (vertex_idx * input_vertex_stride));
241 for (slot = 0, vs_slot = 0; slot < shader->info.num_inputs; ++slot) {
242 vs_slot = draw_tes_get_input_index(
243 shader->info.input_semantic_name[slot],
244 shader->info.input_semantic_index[slot],
245 shader->input_info);
246 if (vs_slot < 0) {
247 debug_printf("TCS/TES signature mismatch!\n");
248 (*input_data)[i][slot][0] = 0;
249 (*input_data)[i][slot][1] = 0;
250 (*input_data)[i][slot][2] = 0;
251 (*input_data)[i][slot][3] = 0;
252 } else {
253 (*input_data)[i][slot][0] = input[vs_slot][0];
254 (*input_data)[i][slot][1] = input[vs_slot][1];
255 (*input_data)[i][slot][2] = input[vs_slot][2];
256 (*input_data)[i][slot][3] = input[vs_slot][3];
257 #if DEBUG_INPUTS
258 debug_printf("\t\t%p = %f %f %f %f\n",
259 &input[vs_slot][0],
260 (*input_data)[i][slot][0],
261 (*input_data)[i][slot][1],
262 (*input_data)[i][slot][2],
263 (*input_data)[i][slot][3]);
264 #endif
265 ++vs_slot;
266 }
267 }
268 }
269 }
270
271 static void
272 llvm_fetch_tess_factors(struct draw_tess_eval_shader *shader,
273 unsigned patch_id,
274 unsigned num_vertices,
275 struct pipe_tessellation_factors *factors)
276 {
277 int outer_slot = draw_tes_get_input_index(
278 TGSI_SEMANTIC_TESSOUTER, 0, shader->input_info);
279 int inner_slot = draw_tes_get_input_index(
280 TGSI_SEMANTIC_TESSINNER, 0, shader->input_info);
281 const float (*input_ptr)[4];
282 const float (*input)[4];
283 input_ptr = shader->input;
284 input = (const float (*)[4])((const char *)input_ptr + ((patch_id * num_vertices) * shader->input_vertex_stride));
285
286 if (outer_slot != -1) {
287 for (unsigned i = 0; i < 4; i++)
288 factors->outer_tf[i] = input[outer_slot][i];
289 } else {
290 for (unsigned i = 0; i < 4; i++)
291 factors->outer_tf[i] = shader->draw->default_outer_tess_level[i];
292 }
293 if (inner_slot != -1) {
294 for (unsigned i = 0; i < 2; i++)
295 factors->inner_tf[i] = input[inner_slot][i];
296 } else {
297 for (unsigned i = 0; i < 2; i++)
298 factors->inner_tf[i] = shader->draw->default_inner_tess_level[i];
299 }
300 }
301
302 static void
303 llvm_tes_run(struct draw_tess_eval_shader *shader,
304 uint32_t prim_id,
305 uint32_t patch_vertices_in,
306 struct pipe_tessellator_data *tess_data,
307 struct pipe_tessellation_factors *tess_factors,
308 struct vertex_header *output)
309 {
310 shader->current_variant->jit_func(shader->jit_context, shader->tes_input->data, output, prim_id,
311 tess_data->num_domain_points, tess_data->domain_points_u, tess_data->domain_points_v,
312 tess_factors->outer_tf, tess_factors->inner_tf, patch_vertices_in);
313 }
314 #endif
315
316 /**
317 * Execute tess eval shader.
318 */
319 int draw_tess_eval_shader_run(struct draw_tess_eval_shader *shader,
320 const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
321 const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS],
322 unsigned num_input_vertices_per_patch,
323 const struct draw_vertex_info *input_verts,
324 const struct draw_prim_info *input_prim,
325 const struct tgsi_shader_info *input_info,
326 struct draw_vertex_info *output_verts,
327 struct draw_prim_info *output_prims,
328 ushort **elts_out)
329 {
330 const float (*input)[4] = (const float (*)[4])input_verts->verts->data;
331 unsigned num_outputs = draw_total_tes_outputs(shader->draw);
332 unsigned input_stride = input_verts->vertex_size;
333 unsigned vertex_size = sizeof(struct vertex_header) + num_outputs * 4 * sizeof(float);
334 ushort *elts = NULL;
335 output_verts->vertex_size = vertex_size;
336 output_verts->stride = output_verts->vertex_size;
337 output_verts->count = 0;
338 output_verts->verts = NULL;
339
340 output_prims->linear = FALSE;
341 output_prims->start = 0;
342 output_prims->elts = NULL;
343 output_prims->count = 0;
344 output_prims->prim = get_tes_output_prim(shader);
345 output_prims->flags = 0;
346 output_prims->primitive_lengths = NULL;
347 output_prims->primitive_count = 0;
348
349 shader->input = input;
350 shader->input_vertex_stride = input_stride;
351 shader->input_info = input_info;
352
353 if (shader->draw->collect_statistics) {
354 shader->draw->statistics.ds_invocations += input_prim->primitive_count;
355 }
356 #ifdef LLVM_AVAILABLE
357 struct pipe_tessellation_factors factors;
358 struct pipe_tessellator_data data = { 0 };
359 struct pipe_tessellator *ptess = p_tess_init(shader->prim_mode,
360 shader->spacing,
361 !shader->vertex_order_cw,
362 shader->point_mode);
363 for (unsigned i = 0; i < input_prim->primitive_count; i++) {
364 uint32_t vert_start = output_verts->count;
365 uint32_t prim_start = output_prims->primitive_count;
366 uint32_t elt_start = output_prims->count;
367
368 llvm_fetch_tess_factors(shader, i, num_input_vertices_per_patch, &factors);
369
370 /* tessellate with the factors for this primitive */
371 p_tessellate(ptess, &factors, &data);
372
373 if (data.num_domain_points == 0)
374 continue;
375
376 uint32_t old_verts = vert_start;
377 uint32_t new_verts = vert_start + util_align_npot(data.num_domain_points, 4);
378 uint32_t old_size = output_verts->vertex_size * old_verts;
379 uint32_t new_size = output_verts->vertex_size * new_verts;
380 output_verts->verts = REALLOC(output_verts->verts, old_size, new_size);
381
382 output_verts->count += data.num_domain_points;
383
384 output_prims->count += data.num_indices;
385 elts = REALLOC(elts, elt_start * sizeof(uint16_t),
386 output_prims->count * sizeof(uint16_t));
387
388 for (unsigned i = 0; i < data.num_indices; i++)
389 elts[elt_start + i] = vert_start + data.indices[i];
390
391 llvm_fetch_tes_input(shader, input_prim, i, num_input_vertices_per_patch);
392 /* run once per primitive? */
393 char *output = (char *)output_verts->verts;
394 output += vert_start * vertex_size;
395 llvm_tes_run(shader, i, num_input_vertices_per_patch, &data, &factors, (struct vertex_header *)output);
396
397 uint32_t prim_len = u_prim_vertex_count(output_prims->prim)->min;
398 output_prims->primitive_count += data.num_indices / prim_len;
399 output_prims->primitive_lengths = REALLOC(output_prims->primitive_lengths, prim_start * sizeof(uint32_t),
400 output_prims->primitive_count * sizeof(uint32_t));
401 for (unsigned i = prim_start; i < output_prims->primitive_count; i++) {
402 output_prims->primitive_lengths[i] = prim_len;
403 }
404 }
405 p_tess_destroy(ptess);
406 #endif
407
408 *elts_out = elts;
409 output_prims->elts = elts;
410 return 0;
411 }
412
413 struct draw_tess_ctrl_shader *
414 draw_create_tess_ctrl_shader(struct draw_context *draw,
415 const struct pipe_shader_state *state)
416 {
417 #ifdef LLVM_AVAILABLE
418 boolean use_llvm = draw->llvm != NULL;
419 struct llvm_tess_ctrl_shader *llvm_tcs = NULL;
420 #endif
421 struct draw_tess_ctrl_shader *tcs;
422
423 #ifdef LLVM_AVAILABLE
424 if (use_llvm) {
425 llvm_tcs = CALLOC_STRUCT(llvm_tess_ctrl_shader);
426
427 if (!llvm_tcs)
428 return NULL;
429
430 tcs = &llvm_tcs->base;
431
432 make_empty_list(&llvm_tcs->variants);
433 } else
434 #endif
435 {
436 tcs = CALLOC_STRUCT(draw_tess_ctrl_shader);
437 }
438
439 if (!tcs)
440 return NULL;
441
442 tcs->draw = draw;
443 tcs->state = *state;
444
445 nir_tgsi_scan_shader(state->ir.nir, &tcs->info, true);
446
447 tcs->vector_length = 4;
448 tcs->vertices_out = tcs->info.properties[TGSI_PROPERTY_TCS_VERTICES_OUT];
449 #ifdef LLVM_AVAILABLE
450 if (use_llvm) {
451
452 tcs->tcs_input = align_malloc(sizeof(struct draw_tcs_inputs), 16);
453 memset(tcs->tcs_input, 0, sizeof(struct draw_tcs_inputs));
454
455 tcs->tcs_output = align_malloc(sizeof(struct draw_tcs_outputs), 16);
456 memset(tcs->tcs_output, 0, sizeof(struct draw_tcs_outputs));
457
458 tcs->jit_context = &draw->llvm->tcs_jit_context;
459 llvm_tcs->variant_key_size =
460 draw_tcs_llvm_variant_key_size(
461 MAX2(tcs->info.file_max[TGSI_FILE_SAMPLER]+1,
462 tcs->info.file_max[TGSI_FILE_SAMPLER_VIEW]+1),
463 tcs->info.file_max[TGSI_FILE_IMAGE]+1);
464 }
465 #endif
466 return tcs;
467 }
468
469 void draw_bind_tess_ctrl_shader(struct draw_context *draw,
470 struct draw_tess_ctrl_shader *dtcs)
471 {
472 draw_do_flush(draw, DRAW_FLUSH_STATE_CHANGE);
473 if (dtcs) {
474 draw->tcs.tess_ctrl_shader = dtcs;
475 } else {
476 draw->tcs.tess_ctrl_shader = NULL;
477 }
478 }
479
480 void draw_delete_tess_ctrl_shader(struct draw_context *draw,
481 struct draw_tess_ctrl_shader *dtcs)
482 {
483 if (!dtcs)
484 return;
485
486 #ifdef LLVM_AVAILABLE
487 if (draw->llvm) {
488 struct llvm_tess_ctrl_shader *shader = llvm_tess_ctrl_shader(dtcs);
489
490 struct draw_tcs_llvm_variant_list_item *li;
491
492 li = first_elem(&shader->variants);
493 while(!at_end(&shader->variants, li)) {
494 struct draw_tcs_llvm_variant_list_item *next = next_elem(li);
495 draw_tcs_llvm_destroy_variant(li->base);
496 li = next;
497 }
498
499 assert(shader->variants_cached == 0);
500 align_free(dtcs->tcs_input);
501 align_free(dtcs->tcs_output);
502 }
503 #endif
504
505 if (dtcs->state.ir.nir)
506 ralloc_free(dtcs->state.ir.nir);
507 FREE(dtcs);
508 }
509
510 #ifdef LLVM_AVAILABLE
511 void draw_tcs_set_current_variant(struct draw_tess_ctrl_shader *shader,
512 struct draw_tcs_llvm_variant *variant)
513 {
514 shader->current_variant = variant;
515 }
516 #endif
517
518 struct draw_tess_eval_shader *
519 draw_create_tess_eval_shader(struct draw_context *draw,
520 const struct pipe_shader_state *state)
521 {
522 #ifdef LLVM_AVAILABLE
523 boolean use_llvm = draw->llvm != NULL;
524 struct llvm_tess_eval_shader *llvm_tes = NULL;
525 #endif
526 struct draw_tess_eval_shader *tes;
527
528 #ifdef LLVM_AVAILABLE
529 if (use_llvm) {
530 llvm_tes = CALLOC_STRUCT(llvm_tess_eval_shader);
531
532 if (!llvm_tes)
533 return NULL;
534
535 tes = &llvm_tes->base;
536 make_empty_list(&llvm_tes->variants);
537 } else
538 #endif
539 {
540 tes = CALLOC_STRUCT(draw_tess_eval_shader);
541 }
542
543 if (!tes)
544 return NULL;
545
546 tes->draw = draw;
547 tes->state = *state;
548
549 nir_tgsi_scan_shader(state->ir.nir, &tes->info, true);
550
551 tes->prim_mode = tes->info.properties[TGSI_PROPERTY_TES_PRIM_MODE];
552 tes->spacing = tes->info.properties[TGSI_PROPERTY_TES_SPACING];
553 tes->vertex_order_cw = tes->info.properties[TGSI_PROPERTY_TES_VERTEX_ORDER_CW];
554 tes->point_mode = tes->info.properties[TGSI_PROPERTY_TES_POINT_MODE];
555
556 tes->vector_length = 4;
557
558 tes->position_output = -1;
559 for (unsigned i = 0; i < tes->info.num_outputs; i++) {
560 if (tes->info.output_semantic_name[i] == TGSI_SEMANTIC_POSITION &&
561 tes->info.output_semantic_index[i] == 0)
562 tes->position_output = i;
563 if (tes->info.output_semantic_name[i] == TGSI_SEMANTIC_VIEWPORT_INDEX)
564 tes->viewport_index_output = i;
565 if (tes->info.output_semantic_name[i] == TGSI_SEMANTIC_CLIPDIST) {
566 debug_assert(tes->info.output_semantic_index[i] <
567 PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT);
568 tes->ccdistance_output[tes->info.output_semantic_index[i]] = i;
569 }
570 }
571
572 #ifdef LLVM_AVAILABLE
573 if (use_llvm) {
574
575 tes->tes_input = align_malloc(sizeof(struct draw_tes_inputs), 16);
576 memset(tes->tes_input, 0, sizeof(struct draw_tes_inputs));
577
578 tes->jit_context = &draw->llvm->tes_jit_context;
579 llvm_tes->variant_key_size =
580 draw_tes_llvm_variant_key_size(
581 MAX2(tes->info.file_max[TGSI_FILE_SAMPLER]+1,
582 tes->info.file_max[TGSI_FILE_SAMPLER_VIEW]+1),
583 tes->info.file_max[TGSI_FILE_IMAGE]+1);
584 }
585 #endif
586 return tes;
587 }
588
589 void draw_bind_tess_eval_shader(struct draw_context *draw,
590 struct draw_tess_eval_shader *dtes)
591 {
592 draw_do_flush(draw, DRAW_FLUSH_STATE_CHANGE);
593 if (dtes) {
594 draw->tes.tess_eval_shader = dtes;
595 draw->tes.position_output = dtes->position_output;
596 } else {
597 draw->tes.tess_eval_shader = NULL;
598 }
599 }
600
601 void draw_delete_tess_eval_shader(struct draw_context *draw,
602 struct draw_tess_eval_shader *dtes)
603 {
604 if (!dtes)
605 return;
606
607 #ifdef LLVM_AVAILABLE
608 if (draw->llvm) {
609 struct llvm_tess_eval_shader *shader = llvm_tess_eval_shader(dtes);
610 struct draw_tes_llvm_variant_list_item *li;
611
612 li = first_elem(&shader->variants);
613 while(!at_end(&shader->variants, li)) {
614 struct draw_tes_llvm_variant_list_item *next = next_elem(li);
615 draw_tes_llvm_destroy_variant(li->base);
616 li = next;
617 }
618
619 assert(shader->variants_cached == 0);
620 align_free(dtes->tes_input);
621 }
622 #endif
623 if (dtes->state.ir.nir)
624 ralloc_free(dtes->state.ir.nir);
625 FREE(dtes);
626 }
627
628 #ifdef LLVM_AVAILABLE
629 void draw_tes_set_current_variant(struct draw_tess_eval_shader *shader,
630 struct draw_tes_llvm_variant *variant)
631 {
632 shader->current_variant = variant;
633 }
634 #endif
635
636 enum pipe_prim_type get_tes_output_prim(struct draw_tess_eval_shader *shader)
637 {
638 if (shader->point_mode)
639 return PIPE_PRIM_POINTS;
640 else if (shader->prim_mode == PIPE_PRIM_LINES)
641 return PIPE_PRIM_LINES;
642 else
643 return PIPE_PRIM_TRIANGLES;
644 }