st/glsl: set req_local_mem earlier for compute shaders
[mesa.git] / src / mesa / state_tracker / st_program.c
1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
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
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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 VMWARE 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.
25 *
26 **************************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keithw@vmware.com>
30 * Brian Paul
31 */
32
33
34 #include "main/imports.h"
35 #include "main/hash.h"
36 #include "main/mtypes.h"
37 #include "program/prog_parameter.h"
38 #include "program/prog_print.h"
39 #include "program/programopt.h"
40
41 #include "compiler/nir/nir.h"
42
43 #include "pipe/p_context.h"
44 #include "pipe/p_defines.h"
45 #include "pipe/p_shader_tokens.h"
46 #include "draw/draw_context.h"
47 #include "tgsi/tgsi_dump.h"
48 #include "tgsi/tgsi_emulate.h"
49 #include "tgsi/tgsi_parse.h"
50 #include "tgsi/tgsi_ureg.h"
51
52 #include "st_debug.h"
53 #include "st_cb_bitmap.h"
54 #include "st_cb_drawpixels.h"
55 #include "st_context.h"
56 #include "st_tgsi_lower_yuv.h"
57 #include "st_program.h"
58 #include "st_mesa_to_tgsi.h"
59 #include "st_atifs_to_tgsi.h"
60 #include "st_nir.h"
61 #include "st_shader_cache.h"
62 #include "cso_cache/cso_context.h"
63
64
65
66 static void
67 set_affected_state_flags(uint64_t *states,
68 struct gl_program *prog,
69 uint64_t new_constants,
70 uint64_t new_sampler_views,
71 uint64_t new_samplers,
72 uint64_t new_images,
73 uint64_t new_ubos,
74 uint64_t new_ssbos,
75 uint64_t new_atomics)
76 {
77 if (prog->Parameters->NumParameters)
78 *states |= new_constants;
79
80 if (prog->info.num_textures)
81 *states |= new_sampler_views | new_samplers;
82
83 if (prog->info.num_images)
84 *states |= new_images;
85
86 if (prog->info.num_ubos)
87 *states |= new_ubos;
88
89 if (prog->info.num_ssbos)
90 *states |= new_ssbos;
91
92 if (prog->info.num_abos)
93 *states |= new_atomics;
94 }
95
96 /**
97 * This determines which states will be updated when the shader is bound.
98 */
99 void
100 st_set_prog_affected_state_flags(struct gl_program *prog)
101 {
102 uint64_t *states;
103
104 switch (prog->info.stage) {
105 case MESA_SHADER_VERTEX:
106 states = &((struct st_vertex_program*)prog)->affected_states;
107
108 *states = ST_NEW_VS_STATE |
109 ST_NEW_RASTERIZER |
110 ST_NEW_VERTEX_ARRAYS;
111
112 set_affected_state_flags(states, prog,
113 ST_NEW_VS_CONSTANTS,
114 ST_NEW_VS_SAMPLER_VIEWS,
115 ST_NEW_VS_SAMPLERS,
116 ST_NEW_VS_IMAGES,
117 ST_NEW_VS_UBOS,
118 ST_NEW_VS_SSBOS,
119 ST_NEW_VS_ATOMICS);
120 break;
121
122 case MESA_SHADER_TESS_CTRL:
123 states = &(st_common_program(prog))->affected_states;
124
125 *states = ST_NEW_TCS_STATE;
126
127 set_affected_state_flags(states, prog,
128 ST_NEW_TCS_CONSTANTS,
129 ST_NEW_TCS_SAMPLER_VIEWS,
130 ST_NEW_TCS_SAMPLERS,
131 ST_NEW_TCS_IMAGES,
132 ST_NEW_TCS_UBOS,
133 ST_NEW_TCS_SSBOS,
134 ST_NEW_TCS_ATOMICS);
135 break;
136
137 case MESA_SHADER_TESS_EVAL:
138 states = &(st_common_program(prog))->affected_states;
139
140 *states = ST_NEW_TES_STATE |
141 ST_NEW_RASTERIZER;
142
143 set_affected_state_flags(states, prog,
144 ST_NEW_TES_CONSTANTS,
145 ST_NEW_TES_SAMPLER_VIEWS,
146 ST_NEW_TES_SAMPLERS,
147 ST_NEW_TES_IMAGES,
148 ST_NEW_TES_UBOS,
149 ST_NEW_TES_SSBOS,
150 ST_NEW_TES_ATOMICS);
151 break;
152
153 case MESA_SHADER_GEOMETRY:
154 states = &(st_common_program(prog))->affected_states;
155
156 *states = ST_NEW_GS_STATE |
157 ST_NEW_RASTERIZER;
158
159 set_affected_state_flags(states, prog,
160 ST_NEW_GS_CONSTANTS,
161 ST_NEW_GS_SAMPLER_VIEWS,
162 ST_NEW_GS_SAMPLERS,
163 ST_NEW_GS_IMAGES,
164 ST_NEW_GS_UBOS,
165 ST_NEW_GS_SSBOS,
166 ST_NEW_GS_ATOMICS);
167 break;
168
169 case MESA_SHADER_FRAGMENT:
170 states = &((struct st_fragment_program*)prog)->affected_states;
171
172 /* gl_FragCoord and glDrawPixels always use constants. */
173 *states = ST_NEW_FS_STATE |
174 ST_NEW_SAMPLE_SHADING |
175 ST_NEW_FS_CONSTANTS;
176
177 set_affected_state_flags(states, prog,
178 ST_NEW_FS_CONSTANTS,
179 ST_NEW_FS_SAMPLER_VIEWS,
180 ST_NEW_FS_SAMPLERS,
181 ST_NEW_FS_IMAGES,
182 ST_NEW_FS_UBOS,
183 ST_NEW_FS_SSBOS,
184 ST_NEW_FS_ATOMICS);
185 break;
186
187 case MESA_SHADER_COMPUTE:
188 states = &((struct st_compute_program*)prog)->affected_states;
189
190 *states = ST_NEW_CS_STATE;
191
192 set_affected_state_flags(states, prog,
193 ST_NEW_CS_CONSTANTS,
194 ST_NEW_CS_SAMPLER_VIEWS,
195 ST_NEW_CS_SAMPLERS,
196 ST_NEW_CS_IMAGES,
197 ST_NEW_CS_UBOS,
198 ST_NEW_CS_SSBOS,
199 ST_NEW_CS_ATOMICS);
200 break;
201
202 default:
203 unreachable("unhandled shader stage");
204 }
205 }
206
207 /**
208 * Delete a vertex program variant. Note the caller must unlink
209 * the variant from the linked list.
210 */
211 static void
212 delete_vp_variant(struct st_context *st, struct st_vp_variant *vpv)
213 {
214 if (vpv->driver_shader)
215 cso_delete_vertex_shader(st->cso_context, vpv->driver_shader);
216
217 if (vpv->draw_shader)
218 draw_delete_vertex_shader( st->draw, vpv->draw_shader );
219
220 if (((vpv->tgsi.type == PIPE_SHADER_IR_TGSI)) && vpv->tgsi.tokens)
221 ureg_free_tokens(vpv->tgsi.tokens);
222
223 free( vpv );
224 }
225
226
227
228 /**
229 * Clean out any old compilations:
230 */
231 void
232 st_release_vp_variants( struct st_context *st,
233 struct st_vertex_program *stvp )
234 {
235 struct st_vp_variant *vpv;
236
237 for (vpv = stvp->variants; vpv; ) {
238 struct st_vp_variant *next = vpv->next;
239 delete_vp_variant(st, vpv);
240 vpv = next;
241 }
242
243 stvp->variants = NULL;
244
245 if ((stvp->tgsi.type == PIPE_SHADER_IR_TGSI) && stvp->tgsi.tokens) {
246 tgsi_free_tokens(stvp->tgsi.tokens);
247 stvp->tgsi.tokens = NULL;
248 }
249 }
250
251
252
253 /**
254 * Delete a fragment program variant. Note the caller must unlink
255 * the variant from the linked list.
256 */
257 static void
258 delete_fp_variant(struct st_context *st, struct st_fp_variant *fpv)
259 {
260 if (fpv->driver_shader)
261 cso_delete_fragment_shader(st->cso_context, fpv->driver_shader);
262 free(fpv);
263 }
264
265
266 /**
267 * Free all variants of a fragment program.
268 */
269 void
270 st_release_fp_variants(struct st_context *st, struct st_fragment_program *stfp)
271 {
272 struct st_fp_variant *fpv;
273
274 for (fpv = stfp->variants; fpv; ) {
275 struct st_fp_variant *next = fpv->next;
276 delete_fp_variant(st, fpv);
277 fpv = next;
278 }
279
280 stfp->variants = NULL;
281
282 if ((stfp->tgsi.type == PIPE_SHADER_IR_TGSI) && stfp->tgsi.tokens) {
283 ureg_free_tokens(stfp->tgsi.tokens);
284 stfp->tgsi.tokens = NULL;
285 }
286 }
287
288
289 /**
290 * Delete a basic program variant. Note the caller must unlink
291 * the variant from the linked list.
292 */
293 static void
294 delete_basic_variant(struct st_context *st, struct st_basic_variant *v,
295 GLenum target)
296 {
297 if (v->driver_shader) {
298 switch (target) {
299 case GL_TESS_CONTROL_PROGRAM_NV:
300 cso_delete_tessctrl_shader(st->cso_context, v->driver_shader);
301 break;
302 case GL_TESS_EVALUATION_PROGRAM_NV:
303 cso_delete_tesseval_shader(st->cso_context, v->driver_shader);
304 break;
305 case GL_GEOMETRY_PROGRAM_NV:
306 cso_delete_geometry_shader(st->cso_context, v->driver_shader);
307 break;
308 case GL_COMPUTE_PROGRAM_NV:
309 cso_delete_compute_shader(st->cso_context, v->driver_shader);
310 break;
311 default:
312 assert(!"this shouldn't occur");
313 }
314 }
315
316 free(v);
317 }
318
319
320 /**
321 * Free all basic program variants.
322 */
323 void
324 st_release_basic_variants(struct st_context *st, GLenum target,
325 struct st_basic_variant **variants,
326 struct pipe_shader_state *tgsi)
327 {
328 struct st_basic_variant *v;
329
330 for (v = *variants; v; ) {
331 struct st_basic_variant *next = v->next;
332 delete_basic_variant(st, v, target);
333 v = next;
334 }
335
336 *variants = NULL;
337
338 if (tgsi->tokens) {
339 ureg_free_tokens(tgsi->tokens);
340 tgsi->tokens = NULL;
341 }
342 }
343
344
345 /**
346 * Free all variants of a compute program.
347 */
348 void
349 st_release_cp_variants(struct st_context *st, struct st_compute_program *stcp)
350 {
351 struct st_basic_variant **variants = &stcp->variants;
352 struct st_basic_variant *v;
353
354 for (v = *variants; v; ) {
355 struct st_basic_variant *next = v->next;
356 delete_basic_variant(st, v, stcp->Base.Target);
357 v = next;
358 }
359
360 *variants = NULL;
361
362 if (stcp->tgsi.prog) {
363 switch (stcp->tgsi.ir_type) {
364 case PIPE_SHADER_IR_TGSI:
365 ureg_free_tokens(stcp->tgsi.prog);
366 stcp->tgsi.prog = NULL;
367 break;
368 case PIPE_SHADER_IR_NIR:
369 /* pipe driver took ownership of prog */
370 break;
371 case PIPE_SHADER_IR_NATIVE:
372 /* ??? */
373 stcp->tgsi.prog = NULL;
374 break;
375 }
376 }
377 }
378
379 /**
380 * Translate a vertex program.
381 */
382 bool
383 st_translate_vertex_program(struct st_context *st,
384 struct st_vertex_program *stvp)
385 {
386 struct ureg_program *ureg;
387 enum pipe_error error;
388 unsigned num_outputs = 0;
389 unsigned attr;
390 ubyte input_to_index[VERT_ATTRIB_MAX] = {0};
391 ubyte output_semantic_name[VARYING_SLOT_MAX] = {0};
392 ubyte output_semantic_index[VARYING_SLOT_MAX] = {0};
393
394 stvp->num_inputs = 0;
395
396 if (stvp->Base.arb.IsPositionInvariant)
397 _mesa_insert_mvp_code(st->ctx, &stvp->Base);
398
399 /*
400 * Determine number of inputs, the mappings between VERT_ATTRIB_x
401 * and TGSI generic input indexes, plus input attrib semantic info.
402 */
403 for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) {
404 if ((stvp->Base.info.inputs_read & BITFIELD64_BIT(attr)) != 0) {
405 input_to_index[attr] = stvp->num_inputs;
406 stvp->index_to_input[stvp->num_inputs] = attr;
407 stvp->num_inputs++;
408 if ((stvp->Base.info.vs.double_inputs_read &
409 BITFIELD64_BIT(attr)) != 0) {
410 /* add placeholder for second part of a double attribute */
411 stvp->index_to_input[stvp->num_inputs] = ST_DOUBLE_ATTRIB_PLACEHOLDER;
412 stvp->num_inputs++;
413 }
414 }
415 }
416 /* bit of a hack, presetup potentially unused edgeflag input */
417 input_to_index[VERT_ATTRIB_EDGEFLAG] = stvp->num_inputs;
418 stvp->index_to_input[stvp->num_inputs] = VERT_ATTRIB_EDGEFLAG;
419
420 /* Compute mapping of vertex program outputs to slots.
421 */
422 for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
423 if ((stvp->Base.info.outputs_written & BITFIELD64_BIT(attr)) == 0) {
424 stvp->result_to_output[attr] = ~0;
425 }
426 else {
427 unsigned slot = num_outputs++;
428
429 stvp->result_to_output[attr] = slot;
430
431 unsigned semantic_name, semantic_index;
432 tgsi_get_gl_varying_semantic(attr, st->needs_texcoord_semantic,
433 &semantic_name, &semantic_index);
434 output_semantic_name[slot] = semantic_name;
435 output_semantic_index[slot] = semantic_index;
436 }
437 }
438 /* similar hack to above, presetup potentially unused edgeflag output */
439 stvp->result_to_output[VARYING_SLOT_EDGE] = num_outputs;
440 output_semantic_name[num_outputs] = TGSI_SEMANTIC_EDGEFLAG;
441 output_semantic_index[num_outputs] = 0;
442
443 /* ARB_vp: */
444 if (!stvp->glsl_to_tgsi && !stvp->shader_program) {
445 _mesa_remove_output_reads(&stvp->Base, PROGRAM_OUTPUT);
446
447 /* This determines which states will be updated when the assembly
448 * shader is bound.
449 */
450 stvp->affected_states = ST_NEW_VS_STATE |
451 ST_NEW_RASTERIZER |
452 ST_NEW_VERTEX_ARRAYS;
453
454 if (stvp->Base.Parameters->NumParameters)
455 stvp->affected_states |= ST_NEW_VS_CONSTANTS;
456
457 /* No samplers are allowed in ARB_vp. */
458 }
459
460 if (stvp->shader_program) {
461 struct gl_program *prog = stvp->shader_program->last_vert_prog;
462 if (prog) {
463 st_translate_stream_output_info2(prog->sh.LinkedTransformFeedback,
464 stvp->result_to_output,
465 &stvp->tgsi.stream_output);
466 }
467
468 st_store_ir_in_disk_cache(st, &stvp->Base, true);
469 return true;
470 }
471
472 ureg = ureg_create_with_screen(PIPE_SHADER_VERTEX, st->pipe->screen);
473 if (ureg == NULL)
474 return false;
475
476 if (stvp->Base.info.clip_distance_array_size)
477 ureg_property(ureg, TGSI_PROPERTY_NUM_CLIPDIST_ENABLED,
478 stvp->Base.info.clip_distance_array_size);
479 if (stvp->Base.info.cull_distance_array_size)
480 ureg_property(ureg, TGSI_PROPERTY_NUM_CULLDIST_ENABLED,
481 stvp->Base.info.cull_distance_array_size);
482
483 if (ST_DEBUG & DEBUG_MESA) {
484 _mesa_print_program(&stvp->Base);
485 _mesa_print_program_parameters(st->ctx, &stvp->Base);
486 debug_printf("\n");
487 }
488
489 if (stvp->glsl_to_tgsi) {
490 error = st_translate_program(st->ctx,
491 PIPE_SHADER_VERTEX,
492 ureg,
493 stvp->glsl_to_tgsi,
494 &stvp->Base,
495 /* inputs */
496 stvp->num_inputs,
497 input_to_index,
498 NULL, /* inputSlotToAttr */
499 NULL, /* input semantic name */
500 NULL, /* input semantic index */
501 NULL, /* interp mode */
502 /* outputs */
503 num_outputs,
504 stvp->result_to_output,
505 output_semantic_name,
506 output_semantic_index);
507
508 st_translate_stream_output_info(stvp->glsl_to_tgsi,
509 stvp->result_to_output,
510 &stvp->tgsi.stream_output);
511
512 free_glsl_to_tgsi_visitor(stvp->glsl_to_tgsi);
513 } else
514 error = st_translate_mesa_program(st->ctx,
515 PIPE_SHADER_VERTEX,
516 ureg,
517 &stvp->Base,
518 /* inputs */
519 stvp->num_inputs,
520 input_to_index,
521 NULL, /* input semantic name */
522 NULL, /* input semantic index */
523 NULL,
524 /* outputs */
525 num_outputs,
526 stvp->result_to_output,
527 output_semantic_name,
528 output_semantic_index);
529
530 if (error) {
531 debug_printf("%s: failed to translate Mesa program:\n", __func__);
532 _mesa_print_program(&stvp->Base);
533 debug_assert(0);
534 return false;
535 }
536
537 stvp->tgsi.tokens = ureg_get_tokens(ureg, &stvp->num_tgsi_tokens);
538 ureg_destroy(ureg);
539
540 if (stvp->glsl_to_tgsi) {
541 stvp->glsl_to_tgsi = NULL;
542 st_store_ir_in_disk_cache(st, &stvp->Base, false);
543 }
544
545 return stvp->tgsi.tokens != NULL;
546 }
547
548 static struct st_vp_variant *
549 st_create_vp_variant(struct st_context *st,
550 struct st_vertex_program *stvp,
551 const struct st_vp_variant_key *key)
552 {
553 struct st_vp_variant *vpv = CALLOC_STRUCT(st_vp_variant);
554 struct pipe_context *pipe = st->pipe;
555
556 vpv->key = *key;
557 vpv->tgsi.stream_output = stvp->tgsi.stream_output;
558 vpv->num_inputs = stvp->num_inputs;
559
560 if (stvp->tgsi.type == PIPE_SHADER_IR_NIR) {
561 vpv->tgsi.type = PIPE_SHADER_IR_NIR;
562 vpv->tgsi.ir.nir = nir_shader_clone(NULL, stvp->tgsi.ir.nir);
563 if (key->clamp_color)
564 NIR_PASS_V(vpv->tgsi.ir.nir, nir_lower_clamp_color_outputs);
565 if (key->passthrough_edgeflags) {
566 NIR_PASS_V(vpv->tgsi.ir.nir, nir_lower_passthrough_edgeflags);
567 vpv->num_inputs++;
568 }
569
570 st_finalize_nir(st, &stvp->Base, stvp->shader_program,
571 vpv->tgsi.ir.nir);
572
573 vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->tgsi);
574 /* driver takes ownership of IR: */
575 vpv->tgsi.ir.nir = NULL;
576 return vpv;
577 }
578
579 vpv->tgsi.tokens = tgsi_dup_tokens(stvp->tgsi.tokens);
580
581 /* Emulate features. */
582 if (key->clamp_color || key->passthrough_edgeflags) {
583 const struct tgsi_token *tokens;
584 unsigned flags =
585 (key->clamp_color ? TGSI_EMU_CLAMP_COLOR_OUTPUTS : 0) |
586 (key->passthrough_edgeflags ? TGSI_EMU_PASSTHROUGH_EDGEFLAG : 0);
587
588 tokens = tgsi_emulate(vpv->tgsi.tokens, flags);
589
590 if (tokens) {
591 tgsi_free_tokens(vpv->tgsi.tokens);
592 vpv->tgsi.tokens = tokens;
593
594 if (key->passthrough_edgeflags)
595 vpv->num_inputs++;
596 } else
597 fprintf(stderr, "mesa: cannot emulate deprecated features\n");
598 }
599
600 if (ST_DEBUG & DEBUG_TGSI) {
601 tgsi_dump(vpv->tgsi.tokens, 0);
602 debug_printf("\n");
603 }
604
605 vpv->driver_shader = pipe->create_vs_state(pipe, &vpv->tgsi);
606 return vpv;
607 }
608
609
610 /**
611 * Find/create a vertex program variant.
612 */
613 struct st_vp_variant *
614 st_get_vp_variant(struct st_context *st,
615 struct st_vertex_program *stvp,
616 const struct st_vp_variant_key *key)
617 {
618 struct st_vp_variant *vpv;
619
620 /* Search for existing variant */
621 for (vpv = stvp->variants; vpv; vpv = vpv->next) {
622 if (memcmp(&vpv->key, key, sizeof(*key)) == 0) {
623 break;
624 }
625 }
626
627 if (!vpv) {
628 /* create now */
629 vpv = st_create_vp_variant(st, stvp, key);
630 if (vpv) {
631 /* insert into list */
632 vpv->next = stvp->variants;
633 stvp->variants = vpv;
634 }
635 }
636
637 return vpv;
638 }
639
640
641 /**
642 * Translate a Mesa fragment shader into a TGSI shader.
643 */
644 bool
645 st_translate_fragment_program(struct st_context *st,
646 struct st_fragment_program *stfp)
647 {
648 ubyte outputMapping[2 * FRAG_RESULT_MAX];
649 ubyte inputMapping[VARYING_SLOT_MAX];
650 ubyte inputSlotToAttr[VARYING_SLOT_MAX];
651 ubyte interpMode[PIPE_MAX_SHADER_INPUTS]; /* XXX size? */
652 GLuint attr;
653 GLbitfield64 inputsRead;
654 struct ureg_program *ureg;
655
656 GLboolean write_all = GL_FALSE;
657
658 ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
659 ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
660 uint fs_num_inputs = 0;
661
662 ubyte fs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS];
663 ubyte fs_output_semantic_index[PIPE_MAX_SHADER_OUTPUTS];
664 uint fs_num_outputs = 0;
665
666 memset(inputSlotToAttr, ~0, sizeof(inputSlotToAttr));
667
668 /* Non-GLSL programs: */
669 if (!stfp->glsl_to_tgsi && !stfp->shader_program) {
670 _mesa_remove_output_reads(&stfp->Base, PROGRAM_OUTPUT);
671 if (st->ctx->Const.GLSLFragCoordIsSysVal)
672 _mesa_program_fragment_position_to_sysval(&stfp->Base);
673
674 /* This determines which states will be updated when the assembly
675 * shader is bound.
676 *
677 * fragment.position and glDrawPixels always use constants.
678 */
679 stfp->affected_states = ST_NEW_FS_STATE |
680 ST_NEW_SAMPLE_SHADING |
681 ST_NEW_FS_CONSTANTS;
682
683 if (stfp->ati_fs) {
684 /* Just set them for ATI_fs unconditionally. */
685 stfp->affected_states |= ST_NEW_FS_SAMPLER_VIEWS |
686 ST_NEW_FS_SAMPLERS;
687 } else {
688 /* ARB_fp */
689 if (stfp->Base.SamplersUsed)
690 stfp->affected_states |= ST_NEW_FS_SAMPLER_VIEWS |
691 ST_NEW_FS_SAMPLERS;
692 }
693 }
694
695 /*
696 * Convert Mesa program inputs to TGSI input register semantics.
697 */
698 inputsRead = stfp->Base.info.inputs_read;
699 for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
700 if ((inputsRead & BITFIELD64_BIT(attr)) != 0) {
701 const GLuint slot = fs_num_inputs++;
702
703 inputMapping[attr] = slot;
704 inputSlotToAttr[slot] = attr;
705
706 switch (attr) {
707 case VARYING_SLOT_POS:
708 input_semantic_name[slot] = TGSI_SEMANTIC_POSITION;
709 input_semantic_index[slot] = 0;
710 interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
711 break;
712 case VARYING_SLOT_COL0:
713 input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
714 input_semantic_index[slot] = 0;
715 interpMode[slot] = stfp->glsl_to_tgsi ?
716 TGSI_INTERPOLATE_COUNT : TGSI_INTERPOLATE_COLOR;
717 break;
718 case VARYING_SLOT_COL1:
719 input_semantic_name[slot] = TGSI_SEMANTIC_COLOR;
720 input_semantic_index[slot] = 1;
721 interpMode[slot] = stfp->glsl_to_tgsi ?
722 TGSI_INTERPOLATE_COUNT : TGSI_INTERPOLATE_COLOR;
723 break;
724 case VARYING_SLOT_FOGC:
725 input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
726 input_semantic_index[slot] = 0;
727 interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
728 break;
729 case VARYING_SLOT_FACE:
730 input_semantic_name[slot] = TGSI_SEMANTIC_FACE;
731 input_semantic_index[slot] = 0;
732 interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
733 break;
734 case VARYING_SLOT_PRIMITIVE_ID:
735 input_semantic_name[slot] = TGSI_SEMANTIC_PRIMID;
736 input_semantic_index[slot] = 0;
737 interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
738 break;
739 case VARYING_SLOT_LAYER:
740 input_semantic_name[slot] = TGSI_SEMANTIC_LAYER;
741 input_semantic_index[slot] = 0;
742 interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
743 break;
744 case VARYING_SLOT_VIEWPORT:
745 input_semantic_name[slot] = TGSI_SEMANTIC_VIEWPORT_INDEX;
746 input_semantic_index[slot] = 0;
747 interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
748 break;
749 case VARYING_SLOT_CLIP_DIST0:
750 input_semantic_name[slot] = TGSI_SEMANTIC_CLIPDIST;
751 input_semantic_index[slot] = 0;
752 interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
753 break;
754 case VARYING_SLOT_CLIP_DIST1:
755 input_semantic_name[slot] = TGSI_SEMANTIC_CLIPDIST;
756 input_semantic_index[slot] = 1;
757 interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
758 break;
759 case VARYING_SLOT_CULL_DIST0:
760 case VARYING_SLOT_CULL_DIST1:
761 /* these should have been lowered by GLSL */
762 assert(0);
763 break;
764 /* In most cases, there is nothing special about these
765 * inputs, so adopt a convention to use the generic
766 * semantic name and the mesa VARYING_SLOT_ number as the
767 * index.
768 *
769 * All that is required is that the vertex shader labels
770 * its own outputs similarly, and that the vertex shader
771 * generates at least every output required by the
772 * fragment shader plus fixed-function hardware (such as
773 * BFC).
774 *
775 * However, some drivers may need us to identify the PNTC and TEXi
776 * varyings if, for example, their capability to replace them with
777 * sprite coordinates is limited.
778 */
779 case VARYING_SLOT_PNTC:
780 if (st->needs_texcoord_semantic) {
781 input_semantic_name[slot] = TGSI_SEMANTIC_PCOORD;
782 input_semantic_index[slot] = 0;
783 interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
784 break;
785 }
786 /* fall through */
787 case VARYING_SLOT_TEX0:
788 case VARYING_SLOT_TEX1:
789 case VARYING_SLOT_TEX2:
790 case VARYING_SLOT_TEX3:
791 case VARYING_SLOT_TEX4:
792 case VARYING_SLOT_TEX5:
793 case VARYING_SLOT_TEX6:
794 case VARYING_SLOT_TEX7:
795 if (st->needs_texcoord_semantic) {
796 input_semantic_name[slot] = TGSI_SEMANTIC_TEXCOORD;
797 input_semantic_index[slot] = attr - VARYING_SLOT_TEX0;
798 interpMode[slot] = stfp->glsl_to_tgsi ?
799 TGSI_INTERPOLATE_COUNT : TGSI_INTERPOLATE_PERSPECTIVE;
800 break;
801 }
802 /* fall through */
803 case VARYING_SLOT_VAR0:
804 default:
805 /* Semantic indices should be zero-based because drivers may choose
806 * to assign a fixed slot determined by that index.
807 * This is useful because ARB_separate_shader_objects uses location
808 * qualifiers for linkage, and if the semantic index corresponds to
809 * these locations, linkage passes in the driver become unecessary.
810 *
811 * If needs_texcoord_semantic is true, no semantic indices will be
812 * consumed for the TEXi varyings, and we can base the locations of
813 * the user varyings on VAR0. Otherwise, we use TEX0 as base index.
814 */
815 assert(attr >= VARYING_SLOT_VAR0 || attr == VARYING_SLOT_PNTC ||
816 (attr >= VARYING_SLOT_TEX0 && attr <= VARYING_SLOT_TEX7));
817 input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
818 input_semantic_index[slot] = st_get_generic_varying_index(st, attr);
819 if (attr == VARYING_SLOT_PNTC)
820 interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
821 else {
822 interpMode[slot] = stfp->glsl_to_tgsi ?
823 TGSI_INTERPOLATE_COUNT : TGSI_INTERPOLATE_PERSPECTIVE;
824 }
825 break;
826 }
827 }
828 else {
829 inputMapping[attr] = -1;
830 }
831 }
832
833 /*
834 * Semantics and mapping for outputs
835 */
836 GLbitfield64 outputsWritten = stfp->Base.info.outputs_written;
837
838 /* if z is written, emit that first */
839 if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
840 fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_POSITION;
841 fs_output_semantic_index[fs_num_outputs] = 0;
842 outputMapping[FRAG_RESULT_DEPTH] = fs_num_outputs;
843 fs_num_outputs++;
844 outputsWritten &= ~(1 << FRAG_RESULT_DEPTH);
845 }
846
847 if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_STENCIL)) {
848 fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_STENCIL;
849 fs_output_semantic_index[fs_num_outputs] = 0;
850 outputMapping[FRAG_RESULT_STENCIL] = fs_num_outputs;
851 fs_num_outputs++;
852 outputsWritten &= ~(1 << FRAG_RESULT_STENCIL);
853 }
854
855 if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)) {
856 fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_SAMPLEMASK;
857 fs_output_semantic_index[fs_num_outputs] = 0;
858 outputMapping[FRAG_RESULT_SAMPLE_MASK] = fs_num_outputs;
859 fs_num_outputs++;
860 outputsWritten &= ~(1 << FRAG_RESULT_SAMPLE_MASK);
861 }
862
863 /* handle remaining outputs (color) */
864 for (attr = 0; attr < ARRAY_SIZE(outputMapping); attr++) {
865 const GLbitfield64 written = attr < FRAG_RESULT_MAX ? outputsWritten :
866 stfp->Base.SecondaryOutputsWritten;
867 const unsigned loc = attr % FRAG_RESULT_MAX;
868
869 if (written & BITFIELD64_BIT(loc)) {
870 switch (loc) {
871 case FRAG_RESULT_DEPTH:
872 case FRAG_RESULT_STENCIL:
873 case FRAG_RESULT_SAMPLE_MASK:
874 /* handled above */
875 assert(0);
876 break;
877 case FRAG_RESULT_COLOR:
878 write_all = GL_TRUE; /* fallthrough */
879 default: {
880 int index;
881 assert(loc == FRAG_RESULT_COLOR ||
882 (FRAG_RESULT_DATA0 <= loc && loc < FRAG_RESULT_MAX));
883
884 index = (loc == FRAG_RESULT_COLOR) ? 0 : (loc - FRAG_RESULT_DATA0);
885
886 if (attr >= FRAG_RESULT_MAX) {
887 /* Secondary color for dual source blending. */
888 assert(index == 0);
889 index++;
890 }
891
892 fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_COLOR;
893 fs_output_semantic_index[fs_num_outputs] = index;
894 outputMapping[attr] = fs_num_outputs;
895 break;
896 }
897 }
898
899 fs_num_outputs++;
900 }
901 }
902
903 /* We have already compiled to NIR so just return */
904 if (stfp->shader_program) {
905 st_store_ir_in_disk_cache(st, &stfp->Base, true);
906 return true;
907 }
908
909 ureg = ureg_create_with_screen(PIPE_SHADER_FRAGMENT, st->pipe->screen);
910 if (ureg == NULL)
911 return false;
912
913 if (ST_DEBUG & DEBUG_MESA) {
914 _mesa_print_program(&stfp->Base);
915 _mesa_print_program_parameters(st->ctx, &stfp->Base);
916 debug_printf("\n");
917 }
918 if (write_all == GL_TRUE)
919 ureg_property(ureg, TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS, 1);
920
921 if (stfp->Base.info.fs.depth_layout != FRAG_DEPTH_LAYOUT_NONE) {
922 switch (stfp->Base.info.fs.depth_layout) {
923 case FRAG_DEPTH_LAYOUT_ANY:
924 ureg_property(ureg, TGSI_PROPERTY_FS_DEPTH_LAYOUT,
925 TGSI_FS_DEPTH_LAYOUT_ANY);
926 break;
927 case FRAG_DEPTH_LAYOUT_GREATER:
928 ureg_property(ureg, TGSI_PROPERTY_FS_DEPTH_LAYOUT,
929 TGSI_FS_DEPTH_LAYOUT_GREATER);
930 break;
931 case FRAG_DEPTH_LAYOUT_LESS:
932 ureg_property(ureg, TGSI_PROPERTY_FS_DEPTH_LAYOUT,
933 TGSI_FS_DEPTH_LAYOUT_LESS);
934 break;
935 case FRAG_DEPTH_LAYOUT_UNCHANGED:
936 ureg_property(ureg, TGSI_PROPERTY_FS_DEPTH_LAYOUT,
937 TGSI_FS_DEPTH_LAYOUT_UNCHANGED);
938 break;
939 default:
940 assert(0);
941 }
942 }
943
944 if (stfp->glsl_to_tgsi) {
945 st_translate_program(st->ctx,
946 PIPE_SHADER_FRAGMENT,
947 ureg,
948 stfp->glsl_to_tgsi,
949 &stfp->Base,
950 /* inputs */
951 fs_num_inputs,
952 inputMapping,
953 inputSlotToAttr,
954 input_semantic_name,
955 input_semantic_index,
956 interpMode,
957 /* outputs */
958 fs_num_outputs,
959 outputMapping,
960 fs_output_semantic_name,
961 fs_output_semantic_index);
962
963 free_glsl_to_tgsi_visitor(stfp->glsl_to_tgsi);
964 } else if (stfp->ati_fs)
965 st_translate_atifs_program(ureg,
966 stfp->ati_fs,
967 &stfp->Base,
968 /* inputs */
969 fs_num_inputs,
970 inputMapping,
971 input_semantic_name,
972 input_semantic_index,
973 interpMode,
974 /* outputs */
975 fs_num_outputs,
976 outputMapping,
977 fs_output_semantic_name,
978 fs_output_semantic_index);
979 else
980 st_translate_mesa_program(st->ctx,
981 PIPE_SHADER_FRAGMENT,
982 ureg,
983 &stfp->Base,
984 /* inputs */
985 fs_num_inputs,
986 inputMapping,
987 input_semantic_name,
988 input_semantic_index,
989 interpMode,
990 /* outputs */
991 fs_num_outputs,
992 outputMapping,
993 fs_output_semantic_name,
994 fs_output_semantic_index);
995
996 stfp->tgsi.tokens = ureg_get_tokens(ureg, &stfp->num_tgsi_tokens);
997 ureg_destroy(ureg);
998
999 if (stfp->glsl_to_tgsi) {
1000 stfp->glsl_to_tgsi = NULL;
1001 st_store_ir_in_disk_cache(st, &stfp->Base, false);
1002 }
1003
1004 return stfp->tgsi.tokens != NULL;
1005 }
1006
1007 static struct st_fp_variant *
1008 st_create_fp_variant(struct st_context *st,
1009 struct st_fragment_program *stfp,
1010 const struct st_fp_variant_key *key)
1011 {
1012 struct pipe_context *pipe = st->pipe;
1013 struct st_fp_variant *variant = CALLOC_STRUCT(st_fp_variant);
1014 struct pipe_shader_state tgsi = {0};
1015 struct gl_program_parameter_list *params = stfp->Base.Parameters;
1016 static const gl_state_index16 texcoord_state[STATE_LENGTH] =
1017 { STATE_INTERNAL, STATE_CURRENT_ATTRIB, VERT_ATTRIB_TEX0 };
1018 static const gl_state_index16 scale_state[STATE_LENGTH] =
1019 { STATE_INTERNAL, STATE_PT_SCALE };
1020 static const gl_state_index16 bias_state[STATE_LENGTH] =
1021 { STATE_INTERNAL, STATE_PT_BIAS };
1022
1023 if (!variant)
1024 return NULL;
1025
1026 if (stfp->tgsi.type == PIPE_SHADER_IR_NIR) {
1027 tgsi.type = PIPE_SHADER_IR_NIR;
1028 tgsi.ir.nir = nir_shader_clone(NULL, stfp->tgsi.ir.nir);
1029
1030 if (key->clamp_color)
1031 NIR_PASS_V(tgsi.ir.nir, nir_lower_clamp_color_outputs);
1032
1033 if (key->persample_shading) {
1034 nir_shader *shader = tgsi.ir.nir;
1035 nir_foreach_variable(var, &shader->inputs)
1036 var->data.sample = true;
1037 }
1038
1039 assert(!(key->bitmap && key->drawpixels));
1040
1041 /* glBitmap */
1042 if (key->bitmap) {
1043 nir_lower_bitmap_options options = {0};
1044
1045 variant->bitmap_sampler = ffs(~stfp->Base.SamplersUsed) - 1;
1046 options.sampler = variant->bitmap_sampler;
1047 options.swizzle_xxxx = (st->bitmap.tex_format == PIPE_FORMAT_L8_UNORM);
1048
1049 NIR_PASS_V(tgsi.ir.nir, nir_lower_bitmap, &options);
1050 }
1051
1052 /* glDrawPixels (color only) */
1053 if (key->drawpixels) {
1054 nir_lower_drawpixels_options options = {{0}};
1055 unsigned samplers_used = stfp->Base.SamplersUsed;
1056
1057 /* Find the first unused slot. */
1058 variant->drawpix_sampler = ffs(~samplers_used) - 1;
1059 options.drawpix_sampler = variant->drawpix_sampler;
1060 samplers_used |= (1 << variant->drawpix_sampler);
1061
1062 options.pixel_maps = key->pixelMaps;
1063 if (key->pixelMaps) {
1064 variant->pixelmap_sampler = ffs(~samplers_used) - 1;
1065 options.pixelmap_sampler = variant->pixelmap_sampler;
1066 }
1067
1068 options.scale_and_bias = key->scaleAndBias;
1069 if (key->scaleAndBias) {
1070 _mesa_add_state_reference(params, scale_state);
1071 memcpy(options.scale_state_tokens, scale_state,
1072 sizeof(options.scale_state_tokens));
1073 _mesa_add_state_reference(params, bias_state);
1074 memcpy(options.bias_state_tokens, bias_state,
1075 sizeof(options.bias_state_tokens));
1076 }
1077
1078 _mesa_add_state_reference(params, texcoord_state);
1079 memcpy(options.texcoord_state_tokens, texcoord_state,
1080 sizeof(options.texcoord_state_tokens));
1081
1082 NIR_PASS_V(tgsi.ir.nir, nir_lower_drawpixels, &options);
1083 }
1084
1085 if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv)) {
1086 nir_lower_tex_options options = {0};
1087 options.lower_y_uv_external = key->external.lower_nv12;
1088 options.lower_y_u_v_external = key->external.lower_iyuv;
1089 NIR_PASS_V(tgsi.ir.nir, nir_lower_tex, &options);
1090 }
1091
1092 st_finalize_nir(st, &stfp->Base, stfp->shader_program, tgsi.ir.nir);
1093
1094 if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv)) {
1095 /* This pass needs to happen *after* nir_lower_sampler */
1096 NIR_PASS_V(tgsi.ir.nir, st_nir_lower_tex_src_plane,
1097 ~stfp->Base.SamplersUsed,
1098 key->external.lower_nv12,
1099 key->external.lower_iyuv);
1100 }
1101
1102 variant->driver_shader = pipe->create_fs_state(pipe, &tgsi);
1103 variant->key = *key;
1104
1105 return variant;
1106 }
1107
1108 tgsi.tokens = stfp->tgsi.tokens;
1109
1110 assert(!(key->bitmap && key->drawpixels));
1111
1112 /* Fix texture targets and add fog for ATI_fs */
1113 if (stfp->ati_fs) {
1114 const struct tgsi_token *tokens = st_fixup_atifs(tgsi.tokens, key);
1115
1116 if (tokens)
1117 tgsi.tokens = tokens;
1118 else
1119 fprintf(stderr, "mesa: cannot post-process ATI_fs\n");
1120 }
1121
1122 /* Emulate features. */
1123 if (key->clamp_color || key->persample_shading) {
1124 const struct tgsi_token *tokens;
1125 unsigned flags =
1126 (key->clamp_color ? TGSI_EMU_CLAMP_COLOR_OUTPUTS : 0) |
1127 (key->persample_shading ? TGSI_EMU_FORCE_PERSAMPLE_INTERP : 0);
1128
1129 tokens = tgsi_emulate(tgsi.tokens, flags);
1130
1131 if (tokens) {
1132 if (tgsi.tokens != stfp->tgsi.tokens)
1133 tgsi_free_tokens(tgsi.tokens);
1134 tgsi.tokens = tokens;
1135 } else
1136 fprintf(stderr, "mesa: cannot emulate deprecated features\n");
1137 }
1138
1139 /* glBitmap */
1140 if (key->bitmap) {
1141 const struct tgsi_token *tokens;
1142
1143 variant->bitmap_sampler = ffs(~stfp->Base.SamplersUsed) - 1;
1144
1145 tokens = st_get_bitmap_shader(tgsi.tokens,
1146 st->internal_target,
1147 variant->bitmap_sampler,
1148 st->needs_texcoord_semantic,
1149 st->bitmap.tex_format ==
1150 PIPE_FORMAT_L8_UNORM);
1151
1152 if (tokens) {
1153 if (tgsi.tokens != stfp->tgsi.tokens)
1154 tgsi_free_tokens(tgsi.tokens);
1155 tgsi.tokens = tokens;
1156 } else
1157 fprintf(stderr, "mesa: cannot create a shader for glBitmap\n");
1158 }
1159
1160 /* glDrawPixels (color only) */
1161 if (key->drawpixels) {
1162 const struct tgsi_token *tokens;
1163 unsigned scale_const = 0, bias_const = 0, texcoord_const = 0;
1164
1165 /* Find the first unused slot. */
1166 variant->drawpix_sampler = ffs(~stfp->Base.SamplersUsed) - 1;
1167
1168 if (key->pixelMaps) {
1169 unsigned samplers_used = stfp->Base.SamplersUsed |
1170 (1 << variant->drawpix_sampler);
1171
1172 variant->pixelmap_sampler = ffs(~samplers_used) - 1;
1173 }
1174
1175 if (key->scaleAndBias) {
1176 scale_const = _mesa_add_state_reference(params, scale_state);
1177 bias_const = _mesa_add_state_reference(params, bias_state);
1178 }
1179
1180 texcoord_const = _mesa_add_state_reference(params, texcoord_state);
1181
1182 tokens = st_get_drawpix_shader(tgsi.tokens,
1183 st->needs_texcoord_semantic,
1184 key->scaleAndBias, scale_const,
1185 bias_const, key->pixelMaps,
1186 variant->drawpix_sampler,
1187 variant->pixelmap_sampler,
1188 texcoord_const, st->internal_target);
1189
1190 if (tokens) {
1191 if (tgsi.tokens != stfp->tgsi.tokens)
1192 tgsi_free_tokens(tgsi.tokens);
1193 tgsi.tokens = tokens;
1194 } else
1195 fprintf(stderr, "mesa: cannot create a shader for glDrawPixels\n");
1196 }
1197
1198 if (unlikely(key->external.lower_nv12 || key->external.lower_iyuv)) {
1199 const struct tgsi_token *tokens;
1200
1201 /* samplers inserted would conflict, but this should be unpossible: */
1202 assert(!(key->bitmap || key->drawpixels));
1203
1204 tokens = st_tgsi_lower_yuv(tgsi.tokens,
1205 ~stfp->Base.SamplersUsed,
1206 key->external.lower_nv12,
1207 key->external.lower_iyuv);
1208 if (tokens) {
1209 if (tgsi.tokens != stfp->tgsi.tokens)
1210 tgsi_free_tokens(tgsi.tokens);
1211 tgsi.tokens = tokens;
1212 } else {
1213 fprintf(stderr, "mesa: cannot create a shader for samplerExternalOES\n");
1214 }
1215 }
1216
1217 if (ST_DEBUG & DEBUG_TGSI) {
1218 tgsi_dump(tgsi.tokens, 0);
1219 debug_printf("\n");
1220 }
1221
1222 /* fill in variant */
1223 variant->driver_shader = pipe->create_fs_state(pipe, &tgsi);
1224 variant->key = *key;
1225
1226 if (tgsi.tokens != stfp->tgsi.tokens)
1227 tgsi_free_tokens(tgsi.tokens);
1228 return variant;
1229 }
1230
1231 /**
1232 * Translate fragment program if needed.
1233 */
1234 struct st_fp_variant *
1235 st_get_fp_variant(struct st_context *st,
1236 struct st_fragment_program *stfp,
1237 const struct st_fp_variant_key *key)
1238 {
1239 struct st_fp_variant *fpv;
1240
1241 /* Search for existing variant */
1242 for (fpv = stfp->variants; fpv; fpv = fpv->next) {
1243 if (memcmp(&fpv->key, key, sizeof(*key)) == 0) {
1244 break;
1245 }
1246 }
1247
1248 if (!fpv) {
1249 /* create new */
1250 fpv = st_create_fp_variant(st, stfp, key);
1251 if (fpv) {
1252 if (key->bitmap || key->drawpixels) {
1253 /* Regular variants should always come before the
1254 * bitmap & drawpixels variants, (unless there
1255 * are no regular variants) so that
1256 * st_update_fp can take a fast path when
1257 * shader_has_one_variant is set.
1258 */
1259 if (!stfp->variants) {
1260 stfp->variants = fpv;
1261 } else {
1262 /* insert into list after the first one */
1263 fpv->next = stfp->variants->next;
1264 stfp->variants->next = fpv;
1265 }
1266 } else {
1267 /* insert into list */
1268 fpv->next = stfp->variants;
1269 stfp->variants = fpv;
1270 }
1271 }
1272 }
1273
1274 return fpv;
1275 }
1276
1277
1278 /**
1279 * Translate a program. This is common code for geometry and tessellation
1280 * shaders.
1281 */
1282 static void
1283 st_translate_program_common(struct st_context *st,
1284 struct gl_program *prog,
1285 struct glsl_to_tgsi_visitor *glsl_to_tgsi,
1286 struct ureg_program *ureg,
1287 unsigned tgsi_processor,
1288 struct pipe_shader_state *out_state)
1289 {
1290 ubyte inputSlotToAttr[VARYING_SLOT_TESS_MAX];
1291 ubyte inputMapping[VARYING_SLOT_TESS_MAX];
1292 ubyte outputMapping[VARYING_SLOT_TESS_MAX];
1293 GLuint attr;
1294
1295 ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS];
1296 ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
1297 uint num_inputs = 0;
1298
1299 ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS];
1300 ubyte output_semantic_index[PIPE_MAX_SHADER_OUTPUTS];
1301 uint num_outputs = 0;
1302
1303 GLint i;
1304
1305 memset(inputSlotToAttr, 0, sizeof(inputSlotToAttr));
1306 memset(inputMapping, 0, sizeof(inputMapping));
1307 memset(outputMapping, 0, sizeof(outputMapping));
1308 memset(out_state, 0, sizeof(*out_state));
1309
1310 if (prog->info.clip_distance_array_size)
1311 ureg_property(ureg, TGSI_PROPERTY_NUM_CLIPDIST_ENABLED,
1312 prog->info.clip_distance_array_size);
1313 if (prog->info.cull_distance_array_size)
1314 ureg_property(ureg, TGSI_PROPERTY_NUM_CULLDIST_ENABLED,
1315 prog->info.cull_distance_array_size);
1316
1317 /*
1318 * Convert Mesa program inputs to TGSI input register semantics.
1319 */
1320 for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
1321 if ((prog->info.inputs_read & BITFIELD64_BIT(attr)) == 0)
1322 continue;
1323
1324 unsigned slot = num_inputs++;
1325
1326 inputMapping[attr] = slot;
1327 inputSlotToAttr[slot] = attr;
1328
1329 unsigned semantic_name, semantic_index;
1330 tgsi_get_gl_varying_semantic(attr, st->needs_texcoord_semantic,
1331 &semantic_name, &semantic_index);
1332 input_semantic_name[slot] = semantic_name;
1333 input_semantic_index[slot] = semantic_index;
1334 }
1335
1336 /* Also add patch inputs. */
1337 for (attr = 0; attr < 32; attr++) {
1338 if (prog->info.patch_inputs_read & (1u << attr)) {
1339 GLuint slot = num_inputs++;
1340 GLuint patch_attr = VARYING_SLOT_PATCH0 + attr;
1341
1342 inputMapping[patch_attr] = slot;
1343 inputSlotToAttr[slot] = patch_attr;
1344 input_semantic_name[slot] = TGSI_SEMANTIC_PATCH;
1345 input_semantic_index[slot] = attr;
1346 }
1347 }
1348
1349 /* initialize output semantics to defaults */
1350 for (i = 0; i < PIPE_MAX_SHADER_OUTPUTS; i++) {
1351 output_semantic_name[i] = TGSI_SEMANTIC_GENERIC;
1352 output_semantic_index[i] = 0;
1353 }
1354
1355 /*
1356 * Determine number of outputs, the (default) output register
1357 * mapping and the semantic information for each output.
1358 */
1359 for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
1360 if (prog->info.outputs_written & BITFIELD64_BIT(attr)) {
1361 GLuint slot = num_outputs++;
1362
1363 outputMapping[attr] = slot;
1364
1365 unsigned semantic_name, semantic_index;
1366 tgsi_get_gl_varying_semantic(attr, st->needs_texcoord_semantic,
1367 &semantic_name, &semantic_index);
1368 output_semantic_name[slot] = semantic_name;
1369 output_semantic_index[slot] = semantic_index;
1370 }
1371 }
1372
1373 /* Also add patch outputs. */
1374 for (attr = 0; attr < 32; attr++) {
1375 if (prog->info.patch_outputs_written & (1u << attr)) {
1376 GLuint slot = num_outputs++;
1377 GLuint patch_attr = VARYING_SLOT_PATCH0 + attr;
1378
1379 outputMapping[patch_attr] = slot;
1380 output_semantic_name[slot] = TGSI_SEMANTIC_PATCH;
1381 output_semantic_index[slot] = attr;
1382 }
1383 }
1384
1385 st_translate_program(st->ctx,
1386 tgsi_processor,
1387 ureg,
1388 glsl_to_tgsi,
1389 prog,
1390 /* inputs */
1391 num_inputs,
1392 inputMapping,
1393 inputSlotToAttr,
1394 input_semantic_name,
1395 input_semantic_index,
1396 NULL,
1397 /* outputs */
1398 num_outputs,
1399 outputMapping,
1400 output_semantic_name,
1401 output_semantic_index);
1402
1403 if (tgsi_processor == PIPE_SHADER_COMPUTE) {
1404 struct st_compute_program *stcp = (struct st_compute_program *) prog;
1405 out_state->tokens = ureg_get_tokens(ureg, &stcp->num_tgsi_tokens);
1406 stcp->tgsi.prog = out_state->tokens;
1407 } else {
1408 struct st_common_program *stcp = (struct st_common_program *) prog;
1409 out_state->tokens = ureg_get_tokens(ureg, &stcp->num_tgsi_tokens);
1410 }
1411 ureg_destroy(ureg);
1412
1413 st_translate_stream_output_info(glsl_to_tgsi,
1414 outputMapping,
1415 &out_state->stream_output);
1416
1417 st_store_ir_in_disk_cache(st, prog, false);
1418
1419 if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) {
1420 _mesa_print_program(prog);
1421 debug_printf("\n");
1422 }
1423
1424 if (ST_DEBUG & DEBUG_TGSI) {
1425 tgsi_dump(out_state->tokens, 0);
1426 debug_printf("\n");
1427 }
1428 }
1429
1430 /**
1431 * Update stream-output info for GS/TCS/TES. Normally this is done in
1432 * st_translate_program_common() but that is not called for glsl_to_nir
1433 * case.
1434 */
1435 static void
1436 st_translate_program_stream_output(struct gl_program *prog,
1437 struct pipe_stream_output_info *stream_output)
1438 {
1439 if (!prog->sh.LinkedTransformFeedback)
1440 return;
1441
1442 ubyte outputMapping[VARYING_SLOT_TESS_MAX];
1443 GLuint attr;
1444 uint num_outputs = 0;
1445
1446 memset(outputMapping, 0, sizeof(outputMapping));
1447
1448 /*
1449 * Determine number of outputs, the (default) output register
1450 * mapping and the semantic information for each output.
1451 */
1452 for (attr = 0; attr < VARYING_SLOT_MAX; attr++) {
1453 if (prog->info.outputs_written & BITFIELD64_BIT(attr)) {
1454 GLuint slot = num_outputs++;
1455
1456 outputMapping[attr] = slot;
1457 }
1458 }
1459
1460 st_translate_stream_output_info2(prog->sh.LinkedTransformFeedback,
1461 outputMapping,
1462 stream_output);
1463 }
1464
1465 /**
1466 * Translate a geometry program to create a new variant.
1467 */
1468 bool
1469 st_translate_geometry_program(struct st_context *st,
1470 struct st_common_program *stgp)
1471 {
1472 struct ureg_program *ureg;
1473
1474 /* We have already compiled to NIR so just return */
1475 if (stgp->shader_program) {
1476 st_translate_program_stream_output(&stgp->Base, &stgp->tgsi.stream_output);
1477 st_store_ir_in_disk_cache(st, &stgp->Base, true);
1478 return true;
1479 }
1480
1481 ureg = ureg_create_with_screen(PIPE_SHADER_GEOMETRY, st->pipe->screen);
1482 if (ureg == NULL)
1483 return false;
1484
1485 ureg_property(ureg, TGSI_PROPERTY_GS_INPUT_PRIM,
1486 stgp->Base.info.gs.input_primitive);
1487 ureg_property(ureg, TGSI_PROPERTY_GS_OUTPUT_PRIM,
1488 stgp->Base.info.gs.output_primitive);
1489 ureg_property(ureg, TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES,
1490 stgp->Base.info.gs.vertices_out);
1491 ureg_property(ureg, TGSI_PROPERTY_GS_INVOCATIONS,
1492 stgp->Base.info.gs.invocations);
1493
1494 st_translate_program_common(st, &stgp->Base, stgp->glsl_to_tgsi, ureg,
1495 PIPE_SHADER_GEOMETRY, &stgp->tgsi);
1496
1497 free_glsl_to_tgsi_visitor(stgp->glsl_to_tgsi);
1498 stgp->glsl_to_tgsi = NULL;
1499 return true;
1500 }
1501
1502
1503 /**
1504 * Get/create a basic program variant.
1505 */
1506 struct st_basic_variant *
1507 st_get_basic_variant(struct st_context *st,
1508 unsigned pipe_shader,
1509 struct st_common_program *prog)
1510 {
1511 struct pipe_context *pipe = st->pipe;
1512 struct st_basic_variant *v;
1513 struct st_basic_variant_key key;
1514 struct pipe_shader_state tgsi = {0};
1515 memset(&key, 0, sizeof(key));
1516 key.st = st->has_shareable_shaders ? NULL : st;
1517
1518 /* Search for existing variant */
1519 for (v = prog->variants; v; v = v->next) {
1520 if (memcmp(&v->key, &key, sizeof(key)) == 0) {
1521 break;
1522 }
1523 }
1524
1525 if (!v) {
1526 /* create new */
1527 v = CALLOC_STRUCT(st_basic_variant);
1528 if (v) {
1529
1530 if (prog->tgsi.type == PIPE_SHADER_IR_NIR) {
1531 tgsi.type = PIPE_SHADER_IR_NIR;
1532 tgsi.ir.nir = nir_shader_clone(NULL, prog->tgsi.ir.nir);
1533 st_finalize_nir(st, &prog->Base, prog->shader_program,
1534 tgsi.ir.nir);
1535 tgsi.stream_output = prog->tgsi.stream_output;
1536 } else
1537 tgsi = prog->tgsi;
1538 /* fill in new variant */
1539 switch (pipe_shader) {
1540 case PIPE_SHADER_TESS_CTRL:
1541 v->driver_shader = pipe->create_tcs_state(pipe, &tgsi);
1542 break;
1543 case PIPE_SHADER_TESS_EVAL:
1544 v->driver_shader = pipe->create_tes_state(pipe, &tgsi);
1545 break;
1546 case PIPE_SHADER_GEOMETRY:
1547 v->driver_shader = pipe->create_gs_state(pipe, &tgsi);
1548 break;
1549 default:
1550 assert(!"unhandled shader type");
1551 free(v);
1552 return NULL;
1553 }
1554
1555 v->key = key;
1556
1557 /* insert into list */
1558 v->next = prog->variants;
1559 prog->variants = v;
1560 }
1561 }
1562
1563 return v;
1564 }
1565
1566
1567 /**
1568 * Translate a tessellation control program to create a new variant.
1569 */
1570 bool
1571 st_translate_tessctrl_program(struct st_context *st,
1572 struct st_common_program *sttcp)
1573 {
1574 struct ureg_program *ureg;
1575
1576 /* We have already compiled to NIR so just return */
1577 if (sttcp->shader_program) {
1578 st_store_ir_in_disk_cache(st, &sttcp->Base, true);
1579 return true;
1580 }
1581
1582 ureg = ureg_create_with_screen(PIPE_SHADER_TESS_CTRL, st->pipe->screen);
1583 if (ureg == NULL)
1584 return false;
1585
1586 ureg_property(ureg, TGSI_PROPERTY_TCS_VERTICES_OUT,
1587 sttcp->Base.info.tess.tcs_vertices_out);
1588
1589 st_translate_program_common(st, &sttcp->Base, sttcp->glsl_to_tgsi, ureg,
1590 PIPE_SHADER_TESS_CTRL, &sttcp->tgsi);
1591
1592 free_glsl_to_tgsi_visitor(sttcp->glsl_to_tgsi);
1593 sttcp->glsl_to_tgsi = NULL;
1594 return true;
1595 }
1596
1597
1598 /**
1599 * Translate a tessellation evaluation program to create a new variant.
1600 */
1601 bool
1602 st_translate_tesseval_program(struct st_context *st,
1603 struct st_common_program *sttep)
1604 {
1605 struct ureg_program *ureg;
1606
1607 /* We have already compiled to NIR so just return */
1608 if (sttep->shader_program) {
1609 st_translate_program_stream_output(&sttep->Base, &sttep->tgsi.stream_output);
1610 st_store_ir_in_disk_cache(st, &sttep->Base, true);
1611 return true;
1612 }
1613
1614 ureg = ureg_create_with_screen(PIPE_SHADER_TESS_EVAL, st->pipe->screen);
1615 if (ureg == NULL)
1616 return false;
1617
1618 if (sttep->Base.info.tess.primitive_mode == GL_ISOLINES)
1619 ureg_property(ureg, TGSI_PROPERTY_TES_PRIM_MODE, GL_LINES);
1620 else
1621 ureg_property(ureg, TGSI_PROPERTY_TES_PRIM_MODE,
1622 sttep->Base.info.tess.primitive_mode);
1623
1624 STATIC_ASSERT((TESS_SPACING_EQUAL + 1) % 3 == PIPE_TESS_SPACING_EQUAL);
1625 STATIC_ASSERT((TESS_SPACING_FRACTIONAL_ODD + 1) % 3 ==
1626 PIPE_TESS_SPACING_FRACTIONAL_ODD);
1627 STATIC_ASSERT((TESS_SPACING_FRACTIONAL_EVEN + 1) % 3 ==
1628 PIPE_TESS_SPACING_FRACTIONAL_EVEN);
1629
1630 ureg_property(ureg, TGSI_PROPERTY_TES_SPACING,
1631 (sttep->Base.info.tess.spacing + 1) % 3);
1632
1633 ureg_property(ureg, TGSI_PROPERTY_TES_VERTEX_ORDER_CW,
1634 !sttep->Base.info.tess.ccw);
1635 ureg_property(ureg, TGSI_PROPERTY_TES_POINT_MODE,
1636 sttep->Base.info.tess.point_mode);
1637
1638 st_translate_program_common(st, &sttep->Base, sttep->glsl_to_tgsi,
1639 ureg, PIPE_SHADER_TESS_EVAL, &sttep->tgsi);
1640
1641 free_glsl_to_tgsi_visitor(sttep->glsl_to_tgsi);
1642 sttep->glsl_to_tgsi = NULL;
1643 return true;
1644 }
1645
1646
1647 /**
1648 * Translate a compute program to create a new variant.
1649 */
1650 bool
1651 st_translate_compute_program(struct st_context *st,
1652 struct st_compute_program *stcp)
1653 {
1654 struct ureg_program *ureg;
1655 struct pipe_shader_state prog;
1656
1657 stcp->tgsi.req_local_mem = stcp->Base.info.cs.shared_size;
1658
1659 if (stcp->shader_program) {
1660 /* no compute variants: */
1661 st_finalize_nir(st, &stcp->Base, stcp->shader_program,
1662 (struct nir_shader *) stcp->tgsi.prog);
1663 st_store_ir_in_disk_cache(st, &stcp->Base, true);
1664 return true;
1665 }
1666
1667 ureg = ureg_create_with_screen(PIPE_SHADER_COMPUTE, st->pipe->screen);
1668 if (ureg == NULL)
1669 return false;
1670
1671 st_translate_program_common(st, &stcp->Base, stcp->glsl_to_tgsi, ureg,
1672 PIPE_SHADER_COMPUTE, &prog);
1673
1674 stcp->tgsi.ir_type = PIPE_SHADER_IR_TGSI;
1675 stcp->tgsi.req_private_mem = 0;
1676 stcp->tgsi.req_input_mem = 0;
1677
1678 free_glsl_to_tgsi_visitor(stcp->glsl_to_tgsi);
1679 stcp->glsl_to_tgsi = NULL;
1680 return true;
1681 }
1682
1683
1684 /**
1685 * Get/create compute program variant.
1686 */
1687 struct st_basic_variant *
1688 st_get_cp_variant(struct st_context *st,
1689 struct pipe_compute_state *tgsi,
1690 struct st_basic_variant **variants)
1691 {
1692 struct pipe_context *pipe = st->pipe;
1693 struct st_basic_variant *v;
1694 struct st_basic_variant_key key;
1695
1696 memset(&key, 0, sizeof(key));
1697 key.st = st->has_shareable_shaders ? NULL : st;
1698
1699 /* Search for existing variant */
1700 for (v = *variants; v; v = v->next) {
1701 if (memcmp(&v->key, &key, sizeof(key)) == 0) {
1702 break;
1703 }
1704 }
1705
1706 if (!v) {
1707 /* create new */
1708 v = CALLOC_STRUCT(st_basic_variant);
1709 if (v) {
1710 /* fill in new variant */
1711 struct pipe_compute_state cs = *tgsi;
1712 if (tgsi->ir_type == PIPE_SHADER_IR_NIR)
1713 cs.prog = nir_shader_clone(NULL, tgsi->prog);
1714 v->driver_shader = pipe->create_compute_state(pipe, &cs);
1715 v->key = key;
1716
1717 /* insert into list */
1718 v->next = *variants;
1719 *variants = v;
1720 }
1721 }
1722
1723 return v;
1724 }
1725
1726
1727 /**
1728 * Vert/Geom/Frag programs have per-context variants. Free all the
1729 * variants attached to the given program which match the given context.
1730 */
1731 static void
1732 destroy_program_variants(struct st_context *st, struct gl_program *target)
1733 {
1734 if (!target || target == &_mesa_DummyProgram)
1735 return;
1736
1737 switch (target->Target) {
1738 case GL_VERTEX_PROGRAM_ARB:
1739 {
1740 struct st_vertex_program *stvp = (struct st_vertex_program *) target;
1741 struct st_vp_variant *vpv, **prevPtr = &stvp->variants;
1742
1743 for (vpv = stvp->variants; vpv; ) {
1744 struct st_vp_variant *next = vpv->next;
1745 if (vpv->key.st == st) {
1746 /* unlink from list */
1747 *prevPtr = next;
1748 /* destroy this variant */
1749 delete_vp_variant(st, vpv);
1750 }
1751 else {
1752 prevPtr = &vpv->next;
1753 }
1754 vpv = next;
1755 }
1756 }
1757 break;
1758 case GL_FRAGMENT_PROGRAM_ARB:
1759 {
1760 struct st_fragment_program *stfp =
1761 (struct st_fragment_program *) target;
1762 struct st_fp_variant *fpv, **prevPtr = &stfp->variants;
1763
1764 for (fpv = stfp->variants; fpv; ) {
1765 struct st_fp_variant *next = fpv->next;
1766 if (fpv->key.st == st) {
1767 /* unlink from list */
1768 *prevPtr = next;
1769 /* destroy this variant */
1770 delete_fp_variant(st, fpv);
1771 }
1772 else {
1773 prevPtr = &fpv->next;
1774 }
1775 fpv = next;
1776 }
1777 }
1778 break;
1779 case GL_GEOMETRY_PROGRAM_NV:
1780 case GL_TESS_CONTROL_PROGRAM_NV:
1781 case GL_TESS_EVALUATION_PROGRAM_NV:
1782 case GL_COMPUTE_PROGRAM_NV:
1783 {
1784 struct st_common_program *p = st_common_program(target);
1785 struct st_compute_program *cp = (struct st_compute_program*)target;
1786 struct st_basic_variant **variants =
1787 target->Target == GL_COMPUTE_PROGRAM_NV ? &cp->variants :
1788 &p->variants;
1789 struct st_basic_variant *v, **prevPtr = variants;
1790
1791 for (v = *variants; v; ) {
1792 struct st_basic_variant *next = v->next;
1793 if (v->key.st == st) {
1794 /* unlink from list */
1795 *prevPtr = next;
1796 /* destroy this variant */
1797 delete_basic_variant(st, v, target->Target);
1798 }
1799 else {
1800 prevPtr = &v->next;
1801 }
1802 v = next;
1803 }
1804 }
1805 break;
1806 default:
1807 _mesa_problem(NULL, "Unexpected program target 0x%x in "
1808 "destroy_program_variants_cb()", target->Target);
1809 }
1810 }
1811
1812
1813 /**
1814 * Callback for _mesa_HashWalk. Free all the shader's program variants
1815 * which match the given context.
1816 */
1817 static void
1818 destroy_shader_program_variants_cb(GLuint key, void *data, void *userData)
1819 {
1820 struct st_context *st = (struct st_context *) userData;
1821 struct gl_shader *shader = (struct gl_shader *) data;
1822
1823 switch (shader->Type) {
1824 case GL_SHADER_PROGRAM_MESA:
1825 {
1826 struct gl_shader_program *shProg = (struct gl_shader_program *) data;
1827 GLuint i;
1828
1829 for (i = 0; i < ARRAY_SIZE(shProg->_LinkedShaders); i++) {
1830 if (shProg->_LinkedShaders[i])
1831 destroy_program_variants(st, shProg->_LinkedShaders[i]->Program);
1832 }
1833 }
1834 break;
1835 case GL_VERTEX_SHADER:
1836 case GL_FRAGMENT_SHADER:
1837 case GL_GEOMETRY_SHADER:
1838 case GL_TESS_CONTROL_SHADER:
1839 case GL_TESS_EVALUATION_SHADER:
1840 case GL_COMPUTE_SHADER:
1841 break;
1842 default:
1843 assert(0);
1844 }
1845 }
1846
1847
1848 /**
1849 * Callback for _mesa_HashWalk. Free all the program variants which match
1850 * the given context.
1851 */
1852 static void
1853 destroy_program_variants_cb(GLuint key, void *data, void *userData)
1854 {
1855 struct st_context *st = (struct st_context *) userData;
1856 struct gl_program *program = (struct gl_program *) data;
1857 destroy_program_variants(st, program);
1858 }
1859
1860
1861 /**
1862 * Walk over all shaders and programs to delete any variants which
1863 * belong to the given context.
1864 * This is called during context tear-down.
1865 */
1866 void
1867 st_destroy_program_variants(struct st_context *st)
1868 {
1869 /* If shaders can be shared with other contexts, the last context will
1870 * call DeleteProgram on all shaders, releasing everything.
1871 */
1872 if (st->has_shareable_shaders)
1873 return;
1874
1875 /* ARB vert/frag program */
1876 _mesa_HashWalk(st->ctx->Shared->Programs,
1877 destroy_program_variants_cb, st);
1878
1879 /* GLSL vert/frag/geom shaders */
1880 _mesa_HashWalk(st->ctx->Shared->ShaderObjects,
1881 destroy_shader_program_variants_cb, st);
1882 }
1883
1884
1885 /**
1886 * For debugging, print/dump the current vertex program.
1887 */
1888 void
1889 st_print_current_vertex_program(void)
1890 {
1891 GET_CURRENT_CONTEXT(ctx);
1892
1893 if (ctx->VertexProgram._Current) {
1894 struct st_vertex_program *stvp =
1895 (struct st_vertex_program *) ctx->VertexProgram._Current;
1896 struct st_vp_variant *stv;
1897
1898 debug_printf("Vertex program %u\n", stvp->Base.Id);
1899
1900 for (stv = stvp->variants; stv; stv = stv->next) {
1901 debug_printf("variant %p\n", stv);
1902 tgsi_dump(stv->tgsi.tokens, 0);
1903 }
1904 }
1905 }
1906
1907
1908 /**
1909 * Compile one shader variant.
1910 */
1911 void
1912 st_precompile_shader_variant(struct st_context *st,
1913 struct gl_program *prog)
1914 {
1915 switch (prog->Target) {
1916 case GL_VERTEX_PROGRAM_ARB: {
1917 struct st_vertex_program *p = (struct st_vertex_program *)prog;
1918 struct st_vp_variant_key key;
1919
1920 memset(&key, 0, sizeof(key));
1921 key.st = st->has_shareable_shaders ? NULL : st;
1922 st_get_vp_variant(st, p, &key);
1923 break;
1924 }
1925
1926 case GL_TESS_CONTROL_PROGRAM_NV: {
1927 struct st_common_program *p = st_common_program(prog);
1928 st_get_basic_variant(st, PIPE_SHADER_TESS_CTRL, p);
1929 break;
1930 }
1931
1932 case GL_TESS_EVALUATION_PROGRAM_NV: {
1933 struct st_common_program *p = st_common_program(prog);
1934 st_get_basic_variant(st, PIPE_SHADER_TESS_EVAL, p);
1935 break;
1936 }
1937
1938 case GL_GEOMETRY_PROGRAM_NV: {
1939 struct st_common_program *p = st_common_program(prog);
1940 st_get_basic_variant(st, PIPE_SHADER_GEOMETRY, p);
1941 break;
1942 }
1943
1944 case GL_FRAGMENT_PROGRAM_ARB: {
1945 struct st_fragment_program *p = (struct st_fragment_program *)prog;
1946 struct st_fp_variant_key key;
1947
1948 memset(&key, 0, sizeof(key));
1949 key.st = st->has_shareable_shaders ? NULL : st;
1950 st_get_fp_variant(st, p, &key);
1951 break;
1952 }
1953
1954 case GL_COMPUTE_PROGRAM_NV: {
1955 struct st_compute_program *p = (struct st_compute_program *)prog;
1956 st_get_cp_variant(st, &p->tgsi, &p->variants);
1957 break;
1958 }
1959
1960 default:
1961 assert(0);
1962 }
1963 }