1 /**************************************************************************
3 * Copyright 2007 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 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.
26 **************************************************************************/
29 * Keith Whitwell <keithw@vmware.com>
34 #include "main/errors.h"
35 #include "main/imports.h"
36 #include "main/hash.h"
37 #include "main/mtypes.h"
38 #include "program/prog_parameter.h"
39 #include "program/prog_print.h"
40 #include "program/prog_to_nir.h"
41 #include "program/programopt.h"
43 #include "compiler/nir/nir.h"
45 #include "pipe/p_context.h"
46 #include "pipe/p_defines.h"
47 #include "pipe/p_shader_tokens.h"
48 #include "draw/draw_context.h"
49 #include "tgsi/tgsi_dump.h"
50 #include "tgsi/tgsi_emulate.h"
51 #include "tgsi/tgsi_parse.h"
52 #include "tgsi/tgsi_ureg.h"
55 #include "st_cb_bitmap.h"
56 #include "st_cb_drawpixels.h"
57 #include "st_context.h"
58 #include "st_tgsi_lower_yuv.h"
59 #include "st_program.h"
60 #include "st_mesa_to_tgsi.h"
61 #include "st_atifs_to_tgsi.h"
63 #include "st_shader_cache.h"
64 #include "cso_cache/cso_context.h"
69 set_affected_state_flags(uint64_t *states
,
70 struct gl_program
*prog
,
71 uint64_t new_constants
,
72 uint64_t new_sampler_views
,
73 uint64_t new_samplers
,
79 if (prog
->Parameters
->NumParameters
)
80 *states
|= new_constants
;
82 if (prog
->info
.num_textures
)
83 *states
|= new_sampler_views
| new_samplers
;
85 if (prog
->info
.num_images
)
86 *states
|= new_images
;
88 if (prog
->info
.num_ubos
)
91 if (prog
->info
.num_ssbos
)
94 if (prog
->info
.num_abos
)
95 *states
|= new_atomics
;
99 * This determines which states will be updated when the shader is bound.
102 st_set_prog_affected_state_flags(struct gl_program
*prog
)
106 switch (prog
->info
.stage
) {
107 case MESA_SHADER_VERTEX
:
108 states
= &((struct st_vertex_program
*)prog
)->affected_states
;
110 *states
= ST_NEW_VS_STATE
|
112 ST_NEW_VERTEX_ARRAYS
;
114 set_affected_state_flags(states
, prog
,
116 ST_NEW_VS_SAMPLER_VIEWS
,
124 case MESA_SHADER_TESS_CTRL
:
125 states
= &(st_common_program(prog
))->affected_states
;
127 *states
= ST_NEW_TCS_STATE
;
129 set_affected_state_flags(states
, prog
,
130 ST_NEW_TCS_CONSTANTS
,
131 ST_NEW_TCS_SAMPLER_VIEWS
,
139 case MESA_SHADER_TESS_EVAL
:
140 states
= &(st_common_program(prog
))->affected_states
;
142 *states
= ST_NEW_TES_STATE
|
145 set_affected_state_flags(states
, prog
,
146 ST_NEW_TES_CONSTANTS
,
147 ST_NEW_TES_SAMPLER_VIEWS
,
155 case MESA_SHADER_GEOMETRY
:
156 states
= &(st_common_program(prog
))->affected_states
;
158 *states
= ST_NEW_GS_STATE
|
161 set_affected_state_flags(states
, prog
,
163 ST_NEW_GS_SAMPLER_VIEWS
,
171 case MESA_SHADER_FRAGMENT
:
172 states
= &((struct st_fragment_program
*)prog
)->affected_states
;
174 /* gl_FragCoord and glDrawPixels always use constants. */
175 *states
= ST_NEW_FS_STATE
|
176 ST_NEW_SAMPLE_SHADING
|
179 set_affected_state_flags(states
, prog
,
181 ST_NEW_FS_SAMPLER_VIEWS
,
189 case MESA_SHADER_COMPUTE
:
190 states
= &((struct st_compute_program
*)prog
)->affected_states
;
192 *states
= ST_NEW_CS_STATE
;
194 set_affected_state_flags(states
, prog
,
196 ST_NEW_CS_SAMPLER_VIEWS
,
205 unreachable("unhandled shader stage");
210 delete_ir(struct pipe_shader_state
*ir
)
213 ureg_free_tokens(ir
->tokens
);
215 /* Note: Any setup of ->ir.nir that has had pipe->create_*_state called on
216 * it has resulted in the driver taking ownership of the NIR. Those
217 * callers should be NULLing out the nir field in any pipe_shader_state
218 * that might have this called in order to indicate that.
220 * GLSL IR and ARB programs will have set gl_program->nir to the same
221 * shader as ir->ir.nir, so it will be freed by _mesa_delete_program().
226 * Delete a vertex program variant. Note the caller must unlink
227 * the variant from the linked list.
230 delete_vp_variant(struct st_context
*st
, struct st_vp_variant
*vpv
)
232 if (vpv
->driver_shader
) {
233 if (st
->has_shareable_shaders
|| vpv
->key
.st
== st
) {
234 cso_delete_vertex_shader(st
->cso_context
, vpv
->driver_shader
);
236 st_save_zombie_shader(vpv
->key
.st
, PIPE_SHADER_VERTEX
,
241 if (vpv
->draw_shader
)
242 draw_delete_vertex_shader( st
->draw
, vpv
->draw_shader
);
244 delete_ir(&vpv
->tgsi
);
252 * Clean out any old compilations:
255 st_release_vp_variants( struct st_context
*st
,
256 struct st_vertex_program
*stvp
)
258 struct st_vp_variant
*vpv
;
260 for (vpv
= stvp
->variants
; vpv
; ) {
261 struct st_vp_variant
*next
= vpv
->next
;
262 delete_vp_variant(st
, vpv
);
266 stvp
->variants
= NULL
;
268 delete_ir(&stvp
->tgsi
);
274 * Delete a fragment program variant. Note the caller must unlink
275 * the variant from the linked list.
278 delete_fp_variant(struct st_context
*st
, struct st_fp_variant
*fpv
)
280 if (fpv
->driver_shader
) {
281 if (st
->has_shareable_shaders
|| fpv
->key
.st
== st
) {
282 cso_delete_fragment_shader(st
->cso_context
, fpv
->driver_shader
);
284 st_save_zombie_shader(fpv
->key
.st
, PIPE_SHADER_FRAGMENT
,
294 * Free all variants of a fragment program.
297 st_release_fp_variants(struct st_context
*st
, struct st_fragment_program
*stfp
)
299 struct st_fp_variant
*fpv
;
301 for (fpv
= stfp
->variants
; fpv
; ) {
302 struct st_fp_variant
*next
= fpv
->next
;
303 delete_fp_variant(st
, fpv
);
307 stfp
->variants
= NULL
;
309 delete_ir(&stfp
->tgsi
);
314 * Delete a basic program variant. Note the caller must unlink
315 * the variant from the linked list.
318 delete_basic_variant(struct st_context
*st
, struct st_basic_variant
*v
,
321 if (v
->driver_shader
) {
322 if (st
->has_shareable_shaders
|| v
->key
.st
== st
) {
323 /* The shader's context matches the calling context, or we
327 case GL_TESS_CONTROL_PROGRAM_NV
:
328 cso_delete_tessctrl_shader(st
->cso_context
, v
->driver_shader
);
330 case GL_TESS_EVALUATION_PROGRAM_NV
:
331 cso_delete_tesseval_shader(st
->cso_context
, v
->driver_shader
);
333 case GL_GEOMETRY_PROGRAM_NV
:
334 cso_delete_geometry_shader(st
->cso_context
, v
->driver_shader
);
336 case GL_COMPUTE_PROGRAM_NV
:
337 cso_delete_compute_shader(st
->cso_context
, v
->driver_shader
);
340 unreachable("bad shader type in delete_basic_variant");
343 /* We can't delete a shader with a context different from the one
344 * that created it. Add it to the creating context's zombie list.
346 enum pipe_shader_type type
;
348 case GL_TESS_CONTROL_PROGRAM_NV
:
349 type
= PIPE_SHADER_TESS_CTRL
;
351 case GL_TESS_EVALUATION_PROGRAM_NV
:
352 type
= PIPE_SHADER_TESS_EVAL
;
354 case GL_GEOMETRY_PROGRAM_NV
:
355 type
= PIPE_SHADER_GEOMETRY
;
360 st_save_zombie_shader(v
->key
.st
, type
, v
->driver_shader
);
369 * Free all basic program variants.
372 st_release_basic_variants(struct st_context
*st
, GLenum target
,
373 struct st_basic_variant
**variants
,
374 struct pipe_shader_state
*tgsi
)
376 struct st_basic_variant
*v
;
378 for (v
= *variants
; v
; ) {
379 struct st_basic_variant
*next
= v
->next
;
380 delete_basic_variant(st
, v
, target
);
391 * Free all variants of a compute program.
394 st_release_cp_variants(struct st_context
*st
, struct st_compute_program
*stcp
)
396 struct st_basic_variant
**variants
= &stcp
->variants
;
397 struct st_basic_variant
*v
;
399 for (v
= *variants
; v
; ) {
400 struct st_basic_variant
*next
= v
->next
;
401 delete_basic_variant(st
, v
, stcp
->Base
.Target
);
407 if (stcp
->tgsi
.prog
) {
408 switch (stcp
->tgsi
.ir_type
) {
409 case PIPE_SHADER_IR_TGSI
:
410 ureg_free_tokens(stcp
->tgsi
.prog
);
411 stcp
->tgsi
.prog
= NULL
;
413 case PIPE_SHADER_IR_NIR
:
414 /* pipe driver took ownership of prog */
416 case PIPE_SHADER_IR_NATIVE
:
418 stcp
->tgsi
.prog
= NULL
;
425 * Translate ARB (asm) program to NIR
428 st_translate_prog_to_nir(struct st_context
*st
, struct gl_program
*prog
,
429 gl_shader_stage stage
)
431 enum pipe_shader_type p_stage
= pipe_shader_type_from_mesa(stage
);
432 const bool is_scalar
=
433 st
->pipe
->screen
->get_shader_param(st
->pipe
->screen
, p_stage
,
434 PIPE_SHADER_CAP_SCALAR_ISA
);
436 const struct gl_shader_compiler_options
*options
=
437 &st
->ctx
->Const
.ShaderCompilerOptions
[stage
];
439 /* Translate to NIR */
440 nir_shader
*nir
= prog_to_nir(prog
, options
->NirOptions
);
441 NIR_PASS_V(nir
, nir_lower_regs_to_ssa
); /* turn registers into SSA */
442 nir_validate_shader(nir
, "after st/ptn lower_regs_to_ssa");
444 NIR_PASS_V(nir
, st_nir_lower_wpos_ytransform
, prog
, st
->pipe
->screen
);
445 NIR_PASS_V(nir
, nir_lower_system_values
);
448 NIR_PASS_V(nir
, nir_opt_constant_folding
);
449 st_nir_opts(nir
, is_scalar
);
450 nir_validate_shader(nir
, "after st/ptn NIR opts");
456 * Translate a vertex program.
459 st_translate_vertex_program(struct st_context
*st
,
460 struct st_vertex_program
*stvp
)
462 struct ureg_program
*ureg
;
463 enum pipe_error error
;
464 unsigned num_outputs
= 0;
466 ubyte output_semantic_name
[VARYING_SLOT_MAX
] = {0};
467 ubyte output_semantic_index
[VARYING_SLOT_MAX
] = {0};
469 stvp
->num_inputs
= 0;
470 memset(stvp
->input_to_index
, ~0, sizeof(stvp
->input_to_index
));
472 if (stvp
->Base
.arb
.IsPositionInvariant
)
473 _mesa_insert_mvp_code(st
->ctx
, &stvp
->Base
);
476 * Determine number of inputs, the mappings between VERT_ATTRIB_x
477 * and TGSI generic input indexes, plus input attrib semantic info.
479 for (attr
= 0; attr
< VERT_ATTRIB_MAX
; attr
++) {
480 if ((stvp
->Base
.info
.inputs_read
& BITFIELD64_BIT(attr
)) != 0) {
481 stvp
->input_to_index
[attr
] = stvp
->num_inputs
;
482 stvp
->index_to_input
[stvp
->num_inputs
] = attr
;
484 if ((stvp
->Base
.DualSlotInputs
& BITFIELD64_BIT(attr
)) != 0) {
485 /* add placeholder for second part of a double attribute */
486 stvp
->index_to_input
[stvp
->num_inputs
] = ST_DOUBLE_ATTRIB_PLACEHOLDER
;
491 /* bit of a hack, presetup potentially unused edgeflag input */
492 stvp
->input_to_index
[VERT_ATTRIB_EDGEFLAG
] = stvp
->num_inputs
;
493 stvp
->index_to_input
[stvp
->num_inputs
] = VERT_ATTRIB_EDGEFLAG
;
495 /* Compute mapping of vertex program outputs to slots.
497 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
498 if ((stvp
->Base
.info
.outputs_written
& BITFIELD64_BIT(attr
)) == 0) {
499 stvp
->result_to_output
[attr
] = ~0;
502 unsigned slot
= num_outputs
++;
504 stvp
->result_to_output
[attr
] = slot
;
506 unsigned semantic_name
, semantic_index
;
507 tgsi_get_gl_varying_semantic(attr
, st
->needs_texcoord_semantic
,
508 &semantic_name
, &semantic_index
);
509 output_semantic_name
[slot
] = semantic_name
;
510 output_semantic_index
[slot
] = semantic_index
;
513 /* similar hack to above, presetup potentially unused edgeflag output */
514 stvp
->result_to_output
[VARYING_SLOT_EDGE
] = num_outputs
;
515 output_semantic_name
[num_outputs
] = TGSI_SEMANTIC_EDGEFLAG
;
516 output_semantic_index
[num_outputs
] = 0;
519 if (!stvp
->glsl_to_tgsi
&& !stvp
->shader_program
) {
520 _mesa_remove_output_reads(&stvp
->Base
, PROGRAM_OUTPUT
);
522 /* This determines which states will be updated when the assembly
525 stvp
->affected_states
= ST_NEW_VS_STATE
|
527 ST_NEW_VERTEX_ARRAYS
;
529 if (stvp
->Base
.Parameters
->NumParameters
)
530 stvp
->affected_states
|= ST_NEW_VS_CONSTANTS
;
532 /* No samplers are allowed in ARB_vp. */
535 if (stvp
->shader_program
) {
536 st_translate_stream_output_info(stvp
->Base
.sh
.LinkedTransformFeedback
,
537 stvp
->result_to_output
,
538 &stvp
->tgsi
.stream_output
);
540 st_store_ir_in_disk_cache(st
, &stvp
->Base
, true);
544 ureg
= ureg_create_with_screen(PIPE_SHADER_VERTEX
, st
->pipe
->screen
);
548 if (stvp
->Base
.info
.clip_distance_array_size
)
549 ureg_property(ureg
, TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
,
550 stvp
->Base
.info
.clip_distance_array_size
);
551 if (stvp
->Base
.info
.cull_distance_array_size
)
552 ureg_property(ureg
, TGSI_PROPERTY_NUM_CULLDIST_ENABLED
,
553 stvp
->Base
.info
.cull_distance_array_size
);
555 if (ST_DEBUG
& DEBUG_MESA
) {
556 _mesa_print_program(&stvp
->Base
);
557 _mesa_print_program_parameters(st
->ctx
, &stvp
->Base
);
561 if (stvp
->glsl_to_tgsi
) {
562 error
= st_translate_program(st
->ctx
,
569 stvp
->input_to_index
,
570 NULL
, /* inputSlotToAttr */
571 NULL
, /* input semantic name */
572 NULL
, /* input semantic index */
573 NULL
, /* interp mode */
576 stvp
->result_to_output
,
577 output_semantic_name
,
578 output_semantic_index
);
580 st_translate_stream_output_info(stvp
->Base
.sh
.LinkedTransformFeedback
,
581 stvp
->result_to_output
,
582 &stvp
->tgsi
.stream_output
);
584 free_glsl_to_tgsi_visitor(stvp
->glsl_to_tgsi
);
586 error
= st_translate_mesa_program(st
->ctx
,
592 stvp
->input_to_index
,
593 NULL
, /* input semantic name */
594 NULL
, /* input semantic index */
598 stvp
->result_to_output
,
599 output_semantic_name
,
600 output_semantic_index
);
603 debug_printf("%s: failed to translate Mesa program:\n", __func__
);
604 _mesa_print_program(&stvp
->Base
);
609 stvp
->tgsi
.tokens
= ureg_get_tokens(ureg
, &stvp
->num_tgsi_tokens
);
612 if (stvp
->glsl_to_tgsi
) {
613 stvp
->glsl_to_tgsi
= NULL
;
614 st_store_ir_in_disk_cache(st
, &stvp
->Base
, false);
617 bool use_nir
= PIPE_SHADER_IR_NIR
==
618 st
->pipe
->screen
->get_shader_param(st
->pipe
->screen
, PIPE_SHADER_VERTEX
,
619 PIPE_SHADER_CAP_PREFERRED_IR
);
623 st_translate_prog_to_nir(st
, &stvp
->Base
, MESA_SHADER_VERTEX
);
625 if (stvp
->tgsi
.ir
.nir
)
626 ralloc_free(stvp
->tgsi
.ir
.nir
);
627 stvp
->tgsi
.type
= PIPE_SHADER_IR_NIR
;
628 stvp
->tgsi
.ir
.nir
= nir
;
629 stvp
->Base
.nir
= nir
;
633 return stvp
->tgsi
.tokens
!= NULL
;
636 static struct st_vp_variant
*
637 st_create_vp_variant(struct st_context
*st
,
638 struct st_vertex_program
*stvp
,
639 const struct st_vp_variant_key
*key
)
641 struct st_vp_variant
*vpv
= CALLOC_STRUCT(st_vp_variant
);
642 struct pipe_context
*pipe
= st
->pipe
;
645 vpv
->tgsi
.stream_output
= stvp
->tgsi
.stream_output
;
646 vpv
->num_inputs
= stvp
->num_inputs
;
648 /* When generating a NIR program, we usually don't have TGSI tokens.
649 * However, we do create them for ARB_vertex_program / fixed-function VS
650 * programs which we may need to use with the draw module for legacy
651 * feedback/select emulation. If they exist, copy them.
653 if (stvp
->tgsi
.tokens
)
654 vpv
->tgsi
.tokens
= tgsi_dup_tokens(stvp
->tgsi
.tokens
);
656 if (stvp
->tgsi
.type
== PIPE_SHADER_IR_NIR
) {
657 vpv
->tgsi
.type
= PIPE_SHADER_IR_NIR
;
658 vpv
->tgsi
.ir
.nir
= nir_shader_clone(NULL
, stvp
->tgsi
.ir
.nir
);
659 if (key
->clamp_color
)
660 NIR_PASS_V(vpv
->tgsi
.ir
.nir
, nir_lower_clamp_color_outputs
);
661 if (key
->passthrough_edgeflags
) {
662 NIR_PASS_V(vpv
->tgsi
.ir
.nir
, nir_lower_passthrough_edgeflags
);
666 st_finalize_nir(st
, &stvp
->Base
, stvp
->shader_program
,
669 vpv
->driver_shader
= pipe
->create_vs_state(pipe
, &vpv
->tgsi
);
670 /* driver takes ownership of IR: */
671 vpv
->tgsi
.ir
.nir
= NULL
;
675 /* Emulate features. */
676 if (key
->clamp_color
|| key
->passthrough_edgeflags
) {
677 const struct tgsi_token
*tokens
;
679 (key
->clamp_color
? TGSI_EMU_CLAMP_COLOR_OUTPUTS
: 0) |
680 (key
->passthrough_edgeflags
? TGSI_EMU_PASSTHROUGH_EDGEFLAG
: 0);
682 tokens
= tgsi_emulate(vpv
->tgsi
.tokens
, flags
);
685 tgsi_free_tokens(vpv
->tgsi
.tokens
);
686 vpv
->tgsi
.tokens
= tokens
;
688 if (key
->passthrough_edgeflags
)
691 fprintf(stderr
, "mesa: cannot emulate deprecated features\n");
694 if (ST_DEBUG
& DEBUG_TGSI
) {
695 tgsi_dump(vpv
->tgsi
.tokens
, 0);
699 vpv
->driver_shader
= pipe
->create_vs_state(pipe
, &vpv
->tgsi
);
705 * Find/create a vertex program variant.
707 struct st_vp_variant
*
708 st_get_vp_variant(struct st_context
*st
,
709 struct st_vertex_program
*stvp
,
710 const struct st_vp_variant_key
*key
)
712 struct st_vp_variant
*vpv
;
714 /* Search for existing variant */
715 for (vpv
= stvp
->variants
; vpv
; vpv
= vpv
->next
) {
716 if (memcmp(&vpv
->key
, key
, sizeof(*key
)) == 0) {
723 vpv
= st_create_vp_variant(st
, stvp
, key
);
725 for (unsigned index
= 0; index
< vpv
->num_inputs
; ++index
) {
726 unsigned attr
= stvp
->index_to_input
[index
];
727 if (attr
== ST_DOUBLE_ATTRIB_PLACEHOLDER
)
729 vpv
->vert_attrib_mask
|= 1u << attr
;
732 /* insert into list */
733 vpv
->next
= stvp
->variants
;
734 stvp
->variants
= vpv
;
743 * Translate a Mesa fragment shader into a TGSI shader.
746 st_translate_fragment_program(struct st_context
*st
,
747 struct st_fragment_program
*stfp
)
749 /* We have already compiled to NIR so just return */
750 if (stfp
->shader_program
) {
751 st_store_ir_in_disk_cache(st
, &stfp
->Base
, true);
755 ubyte outputMapping
[2 * FRAG_RESULT_MAX
];
756 ubyte inputMapping
[VARYING_SLOT_MAX
];
757 ubyte inputSlotToAttr
[VARYING_SLOT_MAX
];
758 ubyte interpMode
[PIPE_MAX_SHADER_INPUTS
]; /* XXX size? */
760 GLbitfield64 inputsRead
;
761 struct ureg_program
*ureg
;
763 GLboolean write_all
= GL_FALSE
;
765 ubyte input_semantic_name
[PIPE_MAX_SHADER_INPUTS
];
766 ubyte input_semantic_index
[PIPE_MAX_SHADER_INPUTS
];
767 uint fs_num_inputs
= 0;
769 ubyte fs_output_semantic_name
[PIPE_MAX_SHADER_OUTPUTS
];
770 ubyte fs_output_semantic_index
[PIPE_MAX_SHADER_OUTPUTS
];
771 uint fs_num_outputs
= 0;
773 memset(inputSlotToAttr
, ~0, sizeof(inputSlotToAttr
));
775 /* Non-GLSL programs: */
776 if (!stfp
->glsl_to_tgsi
&& !stfp
->shader_program
) {
777 _mesa_remove_output_reads(&stfp
->Base
, PROGRAM_OUTPUT
);
778 if (st
->ctx
->Const
.GLSLFragCoordIsSysVal
)
779 _mesa_program_fragment_position_to_sysval(&stfp
->Base
);
781 /* This determines which states will be updated when the assembly
784 * fragment.position and glDrawPixels always use constants.
786 stfp
->affected_states
= ST_NEW_FS_STATE
|
787 ST_NEW_SAMPLE_SHADING
|
791 /* Just set them for ATI_fs unconditionally. */
792 stfp
->affected_states
|= ST_NEW_FS_SAMPLER_VIEWS
|
796 if (stfp
->Base
.SamplersUsed
)
797 stfp
->affected_states
|= ST_NEW_FS_SAMPLER_VIEWS
|
803 bool use_nir
= PIPE_SHADER_IR_NIR
==
804 st
->pipe
->screen
->get_shader_param(st
->pipe
->screen
,
805 PIPE_SHADER_FRAGMENT
,
806 PIPE_SHADER_CAP_PREFERRED_IR
);
808 if (use_nir
&& !stfp
->ati_fs
) {
810 st_translate_prog_to_nir(st
, &stfp
->Base
, MESA_SHADER_FRAGMENT
);
812 if (stfp
->tgsi
.ir
.nir
)
813 ralloc_free(stfp
->tgsi
.ir
.nir
);
814 stfp
->tgsi
.type
= PIPE_SHADER_IR_NIR
;
815 stfp
->tgsi
.ir
.nir
= nir
;
816 stfp
->Base
.nir
= nir
;
821 * Convert Mesa program inputs to TGSI input register semantics.
823 inputsRead
= stfp
->Base
.info
.inputs_read
;
824 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
825 if ((inputsRead
& BITFIELD64_BIT(attr
)) != 0) {
826 const GLuint slot
= fs_num_inputs
++;
828 inputMapping
[attr
] = slot
;
829 inputSlotToAttr
[slot
] = attr
;
832 case VARYING_SLOT_POS
:
833 input_semantic_name
[slot
] = TGSI_SEMANTIC_POSITION
;
834 input_semantic_index
[slot
] = 0;
835 interpMode
[slot
] = TGSI_INTERPOLATE_LINEAR
;
837 case VARYING_SLOT_COL0
:
838 input_semantic_name
[slot
] = TGSI_SEMANTIC_COLOR
;
839 input_semantic_index
[slot
] = 0;
840 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
841 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_COLOR
;
843 case VARYING_SLOT_COL1
:
844 input_semantic_name
[slot
] = TGSI_SEMANTIC_COLOR
;
845 input_semantic_index
[slot
] = 1;
846 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
847 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_COLOR
;
849 case VARYING_SLOT_FOGC
:
850 input_semantic_name
[slot
] = TGSI_SEMANTIC_FOG
;
851 input_semantic_index
[slot
] = 0;
852 interpMode
[slot
] = TGSI_INTERPOLATE_PERSPECTIVE
;
854 case VARYING_SLOT_FACE
:
855 input_semantic_name
[slot
] = TGSI_SEMANTIC_FACE
;
856 input_semantic_index
[slot
] = 0;
857 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
859 case VARYING_SLOT_PRIMITIVE_ID
:
860 input_semantic_name
[slot
] = TGSI_SEMANTIC_PRIMID
;
861 input_semantic_index
[slot
] = 0;
862 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
864 case VARYING_SLOT_LAYER
:
865 input_semantic_name
[slot
] = TGSI_SEMANTIC_LAYER
;
866 input_semantic_index
[slot
] = 0;
867 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
869 case VARYING_SLOT_VIEWPORT
:
870 input_semantic_name
[slot
] = TGSI_SEMANTIC_VIEWPORT_INDEX
;
871 input_semantic_index
[slot
] = 0;
872 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
874 case VARYING_SLOT_CLIP_DIST0
:
875 input_semantic_name
[slot
] = TGSI_SEMANTIC_CLIPDIST
;
876 input_semantic_index
[slot
] = 0;
877 interpMode
[slot
] = TGSI_INTERPOLATE_PERSPECTIVE
;
879 case VARYING_SLOT_CLIP_DIST1
:
880 input_semantic_name
[slot
] = TGSI_SEMANTIC_CLIPDIST
;
881 input_semantic_index
[slot
] = 1;
882 interpMode
[slot
] = TGSI_INTERPOLATE_PERSPECTIVE
;
884 case VARYING_SLOT_CULL_DIST0
:
885 case VARYING_SLOT_CULL_DIST1
:
886 /* these should have been lowered by GLSL */
889 /* In most cases, there is nothing special about these
890 * inputs, so adopt a convention to use the generic
891 * semantic name and the mesa VARYING_SLOT_ number as the
894 * All that is required is that the vertex shader labels
895 * its own outputs similarly, and that the vertex shader
896 * generates at least every output required by the
897 * fragment shader plus fixed-function hardware (such as
900 * However, some drivers may need us to identify the PNTC and TEXi
901 * varyings if, for example, their capability to replace them with
902 * sprite coordinates is limited.
904 case VARYING_SLOT_PNTC
:
905 if (st
->needs_texcoord_semantic
) {
906 input_semantic_name
[slot
] = TGSI_SEMANTIC_PCOORD
;
907 input_semantic_index
[slot
] = 0;
908 interpMode
[slot
] = TGSI_INTERPOLATE_LINEAR
;
912 case VARYING_SLOT_TEX0
:
913 case VARYING_SLOT_TEX1
:
914 case VARYING_SLOT_TEX2
:
915 case VARYING_SLOT_TEX3
:
916 case VARYING_SLOT_TEX4
:
917 case VARYING_SLOT_TEX5
:
918 case VARYING_SLOT_TEX6
:
919 case VARYING_SLOT_TEX7
:
920 if (st
->needs_texcoord_semantic
) {
921 input_semantic_name
[slot
] = TGSI_SEMANTIC_TEXCOORD
;
922 input_semantic_index
[slot
] = attr
- VARYING_SLOT_TEX0
;
923 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
924 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_PERSPECTIVE
;
928 case VARYING_SLOT_VAR0
:
930 /* Semantic indices should be zero-based because drivers may choose
931 * to assign a fixed slot determined by that index.
932 * This is useful because ARB_separate_shader_objects uses location
933 * qualifiers for linkage, and if the semantic index corresponds to
934 * these locations, linkage passes in the driver become unecessary.
936 * If needs_texcoord_semantic is true, no semantic indices will be
937 * consumed for the TEXi varyings, and we can base the locations of
938 * the user varyings on VAR0. Otherwise, we use TEX0 as base index.
940 assert(attr
>= VARYING_SLOT_VAR0
|| attr
== VARYING_SLOT_PNTC
||
941 (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
));
942 input_semantic_name
[slot
] = TGSI_SEMANTIC_GENERIC
;
943 input_semantic_index
[slot
] = st_get_generic_varying_index(st
, attr
);
944 if (attr
== VARYING_SLOT_PNTC
)
945 interpMode
[slot
] = TGSI_INTERPOLATE_LINEAR
;
947 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
948 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_PERSPECTIVE
;
954 inputMapping
[attr
] = -1;
959 * Semantics and mapping for outputs
961 GLbitfield64 outputsWritten
= stfp
->Base
.info
.outputs_written
;
963 /* if z is written, emit that first */
964 if (outputsWritten
& BITFIELD64_BIT(FRAG_RESULT_DEPTH
)) {
965 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_POSITION
;
966 fs_output_semantic_index
[fs_num_outputs
] = 0;
967 outputMapping
[FRAG_RESULT_DEPTH
] = fs_num_outputs
;
969 outputsWritten
&= ~(1 << FRAG_RESULT_DEPTH
);
972 if (outputsWritten
& BITFIELD64_BIT(FRAG_RESULT_STENCIL
)) {
973 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_STENCIL
;
974 fs_output_semantic_index
[fs_num_outputs
] = 0;
975 outputMapping
[FRAG_RESULT_STENCIL
] = fs_num_outputs
;
977 outputsWritten
&= ~(1 << FRAG_RESULT_STENCIL
);
980 if (outputsWritten
& BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK
)) {
981 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_SAMPLEMASK
;
982 fs_output_semantic_index
[fs_num_outputs
] = 0;
983 outputMapping
[FRAG_RESULT_SAMPLE_MASK
] = fs_num_outputs
;
985 outputsWritten
&= ~(1 << FRAG_RESULT_SAMPLE_MASK
);
988 /* handle remaining outputs (color) */
989 for (attr
= 0; attr
< ARRAY_SIZE(outputMapping
); attr
++) {
990 const GLbitfield64 written
= attr
< FRAG_RESULT_MAX
? outputsWritten
:
991 stfp
->Base
.SecondaryOutputsWritten
;
992 const unsigned loc
= attr
% FRAG_RESULT_MAX
;
994 if (written
& BITFIELD64_BIT(loc
)) {
996 case FRAG_RESULT_DEPTH
:
997 case FRAG_RESULT_STENCIL
:
998 case FRAG_RESULT_SAMPLE_MASK
:
1002 case FRAG_RESULT_COLOR
:
1003 write_all
= GL_TRUE
; /* fallthrough */
1006 assert(loc
== FRAG_RESULT_COLOR
||
1007 (FRAG_RESULT_DATA0
<= loc
&& loc
< FRAG_RESULT_MAX
));
1009 index
= (loc
== FRAG_RESULT_COLOR
) ? 0 : (loc
- FRAG_RESULT_DATA0
);
1011 if (attr
>= FRAG_RESULT_MAX
) {
1012 /* Secondary color for dual source blending. */
1017 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_COLOR
;
1018 fs_output_semantic_index
[fs_num_outputs
] = index
;
1019 outputMapping
[attr
] = fs_num_outputs
;
1028 ureg
= ureg_create_with_screen(PIPE_SHADER_FRAGMENT
, st
->pipe
->screen
);
1032 if (ST_DEBUG
& DEBUG_MESA
) {
1033 _mesa_print_program(&stfp
->Base
);
1034 _mesa_print_program_parameters(st
->ctx
, &stfp
->Base
);
1037 if (write_all
== GL_TRUE
)
1038 ureg_property(ureg
, TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
, 1);
1040 if (stfp
->Base
.info
.fs
.depth_layout
!= FRAG_DEPTH_LAYOUT_NONE
) {
1041 switch (stfp
->Base
.info
.fs
.depth_layout
) {
1042 case FRAG_DEPTH_LAYOUT_ANY
:
1043 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1044 TGSI_FS_DEPTH_LAYOUT_ANY
);
1046 case FRAG_DEPTH_LAYOUT_GREATER
:
1047 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1048 TGSI_FS_DEPTH_LAYOUT_GREATER
);
1050 case FRAG_DEPTH_LAYOUT_LESS
:
1051 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1052 TGSI_FS_DEPTH_LAYOUT_LESS
);
1054 case FRAG_DEPTH_LAYOUT_UNCHANGED
:
1055 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1056 TGSI_FS_DEPTH_LAYOUT_UNCHANGED
);
1063 if (stfp
->glsl_to_tgsi
) {
1064 st_translate_program(st
->ctx
,
1065 PIPE_SHADER_FRAGMENT
,
1073 input_semantic_name
,
1074 input_semantic_index
,
1079 fs_output_semantic_name
,
1080 fs_output_semantic_index
);
1082 free_glsl_to_tgsi_visitor(stfp
->glsl_to_tgsi
);
1083 } else if (stfp
->ati_fs
)
1084 st_translate_atifs_program(ureg
,
1090 input_semantic_name
,
1091 input_semantic_index
,
1096 fs_output_semantic_name
,
1097 fs_output_semantic_index
);
1099 st_translate_mesa_program(st
->ctx
,
1100 PIPE_SHADER_FRAGMENT
,
1106 input_semantic_name
,
1107 input_semantic_index
,
1112 fs_output_semantic_name
,
1113 fs_output_semantic_index
);
1115 stfp
->tgsi
.tokens
= ureg_get_tokens(ureg
, &stfp
->num_tgsi_tokens
);
1118 if (stfp
->glsl_to_tgsi
) {
1119 stfp
->glsl_to_tgsi
= NULL
;
1120 st_store_ir_in_disk_cache(st
, &stfp
->Base
, false);
1123 return stfp
->tgsi
.tokens
!= NULL
;
1126 static struct st_fp_variant
*
1127 st_create_fp_variant(struct st_context
*st
,
1128 struct st_fragment_program
*stfp
,
1129 const struct st_fp_variant_key
*key
)
1131 struct pipe_context
*pipe
= st
->pipe
;
1132 struct st_fp_variant
*variant
= CALLOC_STRUCT(st_fp_variant
);
1133 struct pipe_shader_state tgsi
= {0};
1134 struct gl_program_parameter_list
*params
= stfp
->Base
.Parameters
;
1135 static const gl_state_index16 texcoord_state
[STATE_LENGTH
] =
1136 { STATE_INTERNAL
, STATE_CURRENT_ATTRIB
, VERT_ATTRIB_TEX0
};
1137 static const gl_state_index16 scale_state
[STATE_LENGTH
] =
1138 { STATE_INTERNAL
, STATE_PT_SCALE
};
1139 static const gl_state_index16 bias_state
[STATE_LENGTH
] =
1140 { STATE_INTERNAL
, STATE_PT_BIAS
};
1145 if (stfp
->tgsi
.type
== PIPE_SHADER_IR_NIR
) {
1146 tgsi
.type
= PIPE_SHADER_IR_NIR
;
1147 tgsi
.ir
.nir
= nir_shader_clone(NULL
, stfp
->tgsi
.ir
.nir
);
1149 if (key
->clamp_color
)
1150 NIR_PASS_V(tgsi
.ir
.nir
, nir_lower_clamp_color_outputs
);
1152 if (key
->persample_shading
) {
1153 nir_shader
*shader
= tgsi
.ir
.nir
;
1154 nir_foreach_variable(var
, &shader
->inputs
)
1155 var
->data
.sample
= true;
1158 assert(!(key
->bitmap
&& key
->drawpixels
));
1162 nir_lower_bitmap_options options
= {0};
1164 variant
->bitmap_sampler
= ffs(~stfp
->Base
.SamplersUsed
) - 1;
1165 options
.sampler
= variant
->bitmap_sampler
;
1166 options
.swizzle_xxxx
= (st
->bitmap
.tex_format
== PIPE_FORMAT_L8_UNORM
);
1168 NIR_PASS_V(tgsi
.ir
.nir
, nir_lower_bitmap
, &options
);
1171 /* glDrawPixels (color only) */
1172 if (key
->drawpixels
) {
1173 nir_lower_drawpixels_options options
= {{0}};
1174 unsigned samplers_used
= stfp
->Base
.SamplersUsed
;
1176 /* Find the first unused slot. */
1177 variant
->drawpix_sampler
= ffs(~samplers_used
) - 1;
1178 options
.drawpix_sampler
= variant
->drawpix_sampler
;
1179 samplers_used
|= (1 << variant
->drawpix_sampler
);
1181 options
.pixel_maps
= key
->pixelMaps
;
1182 if (key
->pixelMaps
) {
1183 variant
->pixelmap_sampler
= ffs(~samplers_used
) - 1;
1184 options
.pixelmap_sampler
= variant
->pixelmap_sampler
;
1187 options
.scale_and_bias
= key
->scaleAndBias
;
1188 if (key
->scaleAndBias
) {
1189 _mesa_add_state_reference(params
, scale_state
);
1190 memcpy(options
.scale_state_tokens
, scale_state
,
1191 sizeof(options
.scale_state_tokens
));
1192 _mesa_add_state_reference(params
, bias_state
);
1193 memcpy(options
.bias_state_tokens
, bias_state
,
1194 sizeof(options
.bias_state_tokens
));
1197 _mesa_add_state_reference(params
, texcoord_state
);
1198 memcpy(options
.texcoord_state_tokens
, texcoord_state
,
1199 sizeof(options
.texcoord_state_tokens
));
1201 NIR_PASS_V(tgsi
.ir
.nir
, nir_lower_drawpixels
, &options
);
1204 if (unlikely(key
->external
.lower_nv12
|| key
->external
.lower_iyuv
||
1205 key
->external
.lower_xy_uxvx
|| key
->external
.lower_yx_xuxv
||
1206 key
->external
.lower_ayuv
|| key
->external
.lower_xyuv
)) {
1207 nir_lower_tex_options options
= {0};
1208 options
.lower_y_uv_external
= key
->external
.lower_nv12
;
1209 options
.lower_y_u_v_external
= key
->external
.lower_iyuv
;
1210 options
.lower_xy_uxvx_external
= key
->external
.lower_xy_uxvx
;
1211 options
.lower_yx_xuxv_external
= key
->external
.lower_yx_xuxv
;
1212 options
.lower_ayuv_external
= key
->external
.lower_ayuv
;
1213 options
.lower_xyuv_external
= key
->external
.lower_xyuv
;
1214 NIR_PASS_V(tgsi
.ir
.nir
, nir_lower_tex
, &options
);
1217 st_finalize_nir(st
, &stfp
->Base
, stfp
->shader_program
, tgsi
.ir
.nir
);
1219 if (unlikely(key
->external
.lower_nv12
|| key
->external
.lower_iyuv
||
1220 key
->external
.lower_xy_uxvx
|| key
->external
.lower_yx_xuxv
)) {
1221 /* This pass needs to happen *after* nir_lower_sampler */
1222 NIR_PASS_V(tgsi
.ir
.nir
, st_nir_lower_tex_src_plane
,
1223 ~stfp
->Base
.SamplersUsed
,
1224 key
->external
.lower_nv12
|| key
->external
.lower_xy_uxvx
||
1225 key
->external
.lower_yx_xuxv
,
1226 key
->external
.lower_iyuv
);
1229 /* Some of the lowering above may have introduced new varyings */
1230 nir_shader_gather_info(tgsi
.ir
.nir
,
1231 nir_shader_get_entrypoint(tgsi
.ir
.nir
));
1233 variant
->driver_shader
= pipe
->create_fs_state(pipe
, &tgsi
);
1234 variant
->key
= *key
;
1239 tgsi
.tokens
= stfp
->tgsi
.tokens
;
1241 assert(!(key
->bitmap
&& key
->drawpixels
));
1243 /* Fix texture targets and add fog for ATI_fs */
1245 const struct tgsi_token
*tokens
= st_fixup_atifs(tgsi
.tokens
, key
);
1248 tgsi
.tokens
= tokens
;
1250 fprintf(stderr
, "mesa: cannot post-process ATI_fs\n");
1253 /* Emulate features. */
1254 if (key
->clamp_color
|| key
->persample_shading
) {
1255 const struct tgsi_token
*tokens
;
1257 (key
->clamp_color
? TGSI_EMU_CLAMP_COLOR_OUTPUTS
: 0) |
1258 (key
->persample_shading
? TGSI_EMU_FORCE_PERSAMPLE_INTERP
: 0);
1260 tokens
= tgsi_emulate(tgsi
.tokens
, flags
);
1263 if (tgsi
.tokens
!= stfp
->tgsi
.tokens
)
1264 tgsi_free_tokens(tgsi
.tokens
);
1265 tgsi
.tokens
= tokens
;
1267 fprintf(stderr
, "mesa: cannot emulate deprecated features\n");
1272 const struct tgsi_token
*tokens
;
1274 variant
->bitmap_sampler
= ffs(~stfp
->Base
.SamplersUsed
) - 1;
1276 tokens
= st_get_bitmap_shader(tgsi
.tokens
,
1277 st
->internal_target
,
1278 variant
->bitmap_sampler
,
1279 st
->needs_texcoord_semantic
,
1280 st
->bitmap
.tex_format
==
1281 PIPE_FORMAT_L8_UNORM
);
1284 if (tgsi
.tokens
!= stfp
->tgsi
.tokens
)
1285 tgsi_free_tokens(tgsi
.tokens
);
1286 tgsi
.tokens
= tokens
;
1288 fprintf(stderr
, "mesa: cannot create a shader for glBitmap\n");
1291 /* glDrawPixels (color only) */
1292 if (key
->drawpixels
) {
1293 const struct tgsi_token
*tokens
;
1294 unsigned scale_const
= 0, bias_const
= 0, texcoord_const
= 0;
1296 /* Find the first unused slot. */
1297 variant
->drawpix_sampler
= ffs(~stfp
->Base
.SamplersUsed
) - 1;
1299 if (key
->pixelMaps
) {
1300 unsigned samplers_used
= stfp
->Base
.SamplersUsed
|
1301 (1 << variant
->drawpix_sampler
);
1303 variant
->pixelmap_sampler
= ffs(~samplers_used
) - 1;
1306 if (key
->scaleAndBias
) {
1307 scale_const
= _mesa_add_state_reference(params
, scale_state
);
1308 bias_const
= _mesa_add_state_reference(params
, bias_state
);
1311 texcoord_const
= _mesa_add_state_reference(params
, texcoord_state
);
1313 tokens
= st_get_drawpix_shader(tgsi
.tokens
,
1314 st
->needs_texcoord_semantic
,
1315 key
->scaleAndBias
, scale_const
,
1316 bias_const
, key
->pixelMaps
,
1317 variant
->drawpix_sampler
,
1318 variant
->pixelmap_sampler
,
1319 texcoord_const
, st
->internal_target
);
1322 if (tgsi
.tokens
!= stfp
->tgsi
.tokens
)
1323 tgsi_free_tokens(tgsi
.tokens
);
1324 tgsi
.tokens
= tokens
;
1326 fprintf(stderr
, "mesa: cannot create a shader for glDrawPixels\n");
1329 if (unlikely(key
->external
.lower_nv12
|| key
->external
.lower_iyuv
||
1330 key
->external
.lower_xy_uxvx
|| key
->external
.lower_yx_xuxv
)) {
1331 const struct tgsi_token
*tokens
;
1333 /* samplers inserted would conflict, but this should be unpossible: */
1334 assert(!(key
->bitmap
|| key
->drawpixels
));
1336 tokens
= st_tgsi_lower_yuv(tgsi
.tokens
,
1337 ~stfp
->Base
.SamplersUsed
,
1338 key
->external
.lower_nv12
||
1339 key
->external
.lower_xy_uxvx
||
1340 key
->external
.lower_yx_xuxv
,
1341 key
->external
.lower_iyuv
);
1343 if (tgsi
.tokens
!= stfp
->tgsi
.tokens
)
1344 tgsi_free_tokens(tgsi
.tokens
);
1345 tgsi
.tokens
= tokens
;
1347 fprintf(stderr
, "mesa: cannot create a shader for samplerExternalOES\n");
1351 if (ST_DEBUG
& DEBUG_TGSI
) {
1352 tgsi_dump(tgsi
.tokens
, 0);
1356 /* fill in variant */
1357 variant
->driver_shader
= pipe
->create_fs_state(pipe
, &tgsi
);
1358 variant
->key
= *key
;
1360 if (tgsi
.tokens
!= stfp
->tgsi
.tokens
)
1361 tgsi_free_tokens(tgsi
.tokens
);
1366 * Translate fragment program if needed.
1368 struct st_fp_variant
*
1369 st_get_fp_variant(struct st_context
*st
,
1370 struct st_fragment_program
*stfp
,
1371 const struct st_fp_variant_key
*key
)
1373 struct st_fp_variant
*fpv
;
1375 /* Search for existing variant */
1376 for (fpv
= stfp
->variants
; fpv
; fpv
= fpv
->next
) {
1377 if (memcmp(&fpv
->key
, key
, sizeof(*key
)) == 0) {
1384 fpv
= st_create_fp_variant(st
, stfp
, key
);
1386 if (key
->bitmap
|| key
->drawpixels
) {
1387 /* Regular variants should always come before the
1388 * bitmap & drawpixels variants, (unless there
1389 * are no regular variants) so that
1390 * st_update_fp can take a fast path when
1391 * shader_has_one_variant is set.
1393 if (!stfp
->variants
) {
1394 stfp
->variants
= fpv
;
1396 /* insert into list after the first one */
1397 fpv
->next
= stfp
->variants
->next
;
1398 stfp
->variants
->next
= fpv
;
1401 /* insert into list */
1402 fpv
->next
= stfp
->variants
;
1403 stfp
->variants
= fpv
;
1413 * Translate a program. This is common code for geometry and tessellation
1417 st_translate_program_common(struct st_context
*st
,
1418 struct gl_program
*prog
,
1419 struct glsl_to_tgsi_visitor
*glsl_to_tgsi
,
1420 struct ureg_program
*ureg
,
1421 unsigned tgsi_processor
,
1422 struct pipe_shader_state
*out_state
)
1424 ubyte inputSlotToAttr
[VARYING_SLOT_TESS_MAX
];
1425 ubyte inputMapping
[VARYING_SLOT_TESS_MAX
];
1426 ubyte outputMapping
[VARYING_SLOT_TESS_MAX
];
1429 ubyte input_semantic_name
[PIPE_MAX_SHADER_INPUTS
];
1430 ubyte input_semantic_index
[PIPE_MAX_SHADER_INPUTS
];
1431 uint num_inputs
= 0;
1433 ubyte output_semantic_name
[PIPE_MAX_SHADER_OUTPUTS
];
1434 ubyte output_semantic_index
[PIPE_MAX_SHADER_OUTPUTS
];
1435 uint num_outputs
= 0;
1439 memset(inputSlotToAttr
, 0, sizeof(inputSlotToAttr
));
1440 memset(inputMapping
, 0, sizeof(inputMapping
));
1441 memset(outputMapping
, 0, sizeof(outputMapping
));
1442 memset(out_state
, 0, sizeof(*out_state
));
1444 if (prog
->info
.clip_distance_array_size
)
1445 ureg_property(ureg
, TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
,
1446 prog
->info
.clip_distance_array_size
);
1447 if (prog
->info
.cull_distance_array_size
)
1448 ureg_property(ureg
, TGSI_PROPERTY_NUM_CULLDIST_ENABLED
,
1449 prog
->info
.cull_distance_array_size
);
1452 * Convert Mesa program inputs to TGSI input register semantics.
1454 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
1455 if ((prog
->info
.inputs_read
& BITFIELD64_BIT(attr
)) == 0)
1458 unsigned slot
= num_inputs
++;
1460 inputMapping
[attr
] = slot
;
1461 inputSlotToAttr
[slot
] = attr
;
1463 unsigned semantic_name
, semantic_index
;
1464 tgsi_get_gl_varying_semantic(attr
, st
->needs_texcoord_semantic
,
1465 &semantic_name
, &semantic_index
);
1466 input_semantic_name
[slot
] = semantic_name
;
1467 input_semantic_index
[slot
] = semantic_index
;
1470 /* Also add patch inputs. */
1471 for (attr
= 0; attr
< 32; attr
++) {
1472 if (prog
->info
.patch_inputs_read
& (1u << attr
)) {
1473 GLuint slot
= num_inputs
++;
1474 GLuint patch_attr
= VARYING_SLOT_PATCH0
+ attr
;
1476 inputMapping
[patch_attr
] = slot
;
1477 inputSlotToAttr
[slot
] = patch_attr
;
1478 input_semantic_name
[slot
] = TGSI_SEMANTIC_PATCH
;
1479 input_semantic_index
[slot
] = attr
;
1483 /* initialize output semantics to defaults */
1484 for (i
= 0; i
< PIPE_MAX_SHADER_OUTPUTS
; i
++) {
1485 output_semantic_name
[i
] = TGSI_SEMANTIC_GENERIC
;
1486 output_semantic_index
[i
] = 0;
1490 * Determine number of outputs, the (default) output register
1491 * mapping and the semantic information for each output.
1493 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
1494 if (prog
->info
.outputs_written
& BITFIELD64_BIT(attr
)) {
1495 GLuint slot
= num_outputs
++;
1497 outputMapping
[attr
] = slot
;
1499 unsigned semantic_name
, semantic_index
;
1500 tgsi_get_gl_varying_semantic(attr
, st
->needs_texcoord_semantic
,
1501 &semantic_name
, &semantic_index
);
1502 output_semantic_name
[slot
] = semantic_name
;
1503 output_semantic_index
[slot
] = semantic_index
;
1507 /* Also add patch outputs. */
1508 for (attr
= 0; attr
< 32; attr
++) {
1509 if (prog
->info
.patch_outputs_written
& (1u << attr
)) {
1510 GLuint slot
= num_outputs
++;
1511 GLuint patch_attr
= VARYING_SLOT_PATCH0
+ attr
;
1513 outputMapping
[patch_attr
] = slot
;
1514 output_semantic_name
[slot
] = TGSI_SEMANTIC_PATCH
;
1515 output_semantic_index
[slot
] = attr
;
1519 st_translate_program(st
->ctx
,
1528 input_semantic_name
,
1529 input_semantic_index
,
1534 output_semantic_name
,
1535 output_semantic_index
);
1537 if (tgsi_processor
== PIPE_SHADER_COMPUTE
) {
1538 struct st_compute_program
*stcp
= (struct st_compute_program
*) prog
;
1539 out_state
->tokens
= ureg_get_tokens(ureg
, &stcp
->num_tgsi_tokens
);
1540 stcp
->tgsi
.prog
= out_state
->tokens
;
1542 struct st_common_program
*stcp
= (struct st_common_program
*) prog
;
1543 out_state
->tokens
= ureg_get_tokens(ureg
, &stcp
->num_tgsi_tokens
);
1547 st_translate_stream_output_info(prog
->sh
.LinkedTransformFeedback
,
1549 &out_state
->stream_output
);
1551 st_store_ir_in_disk_cache(st
, prog
, false);
1553 if ((ST_DEBUG
& DEBUG_TGSI
) && (ST_DEBUG
& DEBUG_MESA
)) {
1554 _mesa_print_program(prog
);
1558 if (ST_DEBUG
& DEBUG_TGSI
) {
1559 tgsi_dump(out_state
->tokens
, 0);
1565 * Update stream-output info for GS/TCS/TES. Normally this is done in
1566 * st_translate_program_common() but that is not called for glsl_to_nir
1570 st_translate_program_stream_output(struct gl_program
*prog
,
1571 struct pipe_stream_output_info
*stream_output
)
1573 if (!prog
->sh
.LinkedTransformFeedback
)
1576 ubyte outputMapping
[VARYING_SLOT_TESS_MAX
];
1578 uint num_outputs
= 0;
1580 memset(outputMapping
, 0, sizeof(outputMapping
));
1583 * Determine number of outputs, the (default) output register
1584 * mapping and the semantic information for each output.
1586 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
1587 if (prog
->info
.outputs_written
& BITFIELD64_BIT(attr
)) {
1588 GLuint slot
= num_outputs
++;
1590 outputMapping
[attr
] = slot
;
1594 st_translate_stream_output_info(prog
->sh
.LinkedTransformFeedback
,
1600 * Translate a geometry program to create a new variant.
1603 st_translate_geometry_program(struct st_context
*st
,
1604 struct st_common_program
*stgp
)
1606 struct ureg_program
*ureg
;
1608 /* We have already compiled to NIR so just return */
1609 if (stgp
->shader_program
) {
1611 st_finalize_nir(st
, &stgp
->Base
, stgp
->shader_program
,
1613 st_translate_program_stream_output(&stgp
->Base
, &stgp
->tgsi
.stream_output
);
1614 st_store_ir_in_disk_cache(st
, &stgp
->Base
, true);
1618 ureg
= ureg_create_with_screen(PIPE_SHADER_GEOMETRY
, st
->pipe
->screen
);
1622 ureg_property(ureg
, TGSI_PROPERTY_GS_INPUT_PRIM
,
1623 stgp
->Base
.info
.gs
.input_primitive
);
1624 ureg_property(ureg
, TGSI_PROPERTY_GS_OUTPUT_PRIM
,
1625 stgp
->Base
.info
.gs
.output_primitive
);
1626 ureg_property(ureg
, TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
,
1627 stgp
->Base
.info
.gs
.vertices_out
);
1628 ureg_property(ureg
, TGSI_PROPERTY_GS_INVOCATIONS
,
1629 stgp
->Base
.info
.gs
.invocations
);
1631 st_translate_program_common(st
, &stgp
->Base
, stgp
->glsl_to_tgsi
, ureg
,
1632 PIPE_SHADER_GEOMETRY
, &stgp
->tgsi
);
1634 free_glsl_to_tgsi_visitor(stgp
->glsl_to_tgsi
);
1635 stgp
->glsl_to_tgsi
= NULL
;
1641 * Get/create a basic program variant.
1643 struct st_basic_variant
*
1644 st_get_basic_variant(struct st_context
*st
,
1645 unsigned pipe_shader
,
1646 struct st_common_program
*prog
,
1647 const struct st_basic_variant_key
*key
)
1649 struct pipe_context
*pipe
= st
->pipe
;
1650 struct st_basic_variant
*v
;
1651 struct pipe_shader_state tgsi
= {0};
1653 /* Search for existing variant */
1654 for (v
= prog
->variants
; v
; v
= v
->next
) {
1655 if (memcmp(&v
->key
, key
, sizeof(*key
)) == 0) {
1662 v
= CALLOC_STRUCT(st_basic_variant
);
1665 if (prog
->tgsi
.type
== PIPE_SHADER_IR_NIR
) {
1666 tgsi
.type
= PIPE_SHADER_IR_NIR
;
1667 tgsi
.ir
.nir
= nir_shader_clone(NULL
, prog
->tgsi
.ir
.nir
);
1669 if (key
->clamp_color
)
1670 NIR_PASS_V(tgsi
.ir
.nir
, nir_lower_clamp_color_outputs
);
1672 tgsi
.stream_output
= prog
->tgsi
.stream_output
;
1675 /* fill in new variant */
1676 switch (pipe_shader
) {
1677 case PIPE_SHADER_TESS_CTRL
:
1678 v
->driver_shader
= pipe
->create_tcs_state(pipe
, &tgsi
);
1680 case PIPE_SHADER_TESS_EVAL
:
1681 v
->driver_shader
= pipe
->create_tes_state(pipe
, &tgsi
);
1683 case PIPE_SHADER_GEOMETRY
:
1684 v
->driver_shader
= pipe
->create_gs_state(pipe
, &tgsi
);
1687 assert(!"unhandled shader type");
1694 /* insert into list */
1695 v
->next
= prog
->variants
;
1705 * Translate a tessellation control program to create a new variant.
1708 st_translate_tessctrl_program(struct st_context
*st
,
1709 struct st_common_program
*sttcp
)
1711 struct ureg_program
*ureg
;
1713 /* We have already compiled to NIR so just return */
1714 if (sttcp
->shader_program
) {
1716 st_finalize_nir(st
, &sttcp
->Base
, sttcp
->shader_program
,
1717 sttcp
->tgsi
.ir
.nir
);
1718 st_store_ir_in_disk_cache(st
, &sttcp
->Base
, true);
1722 ureg
= ureg_create_with_screen(PIPE_SHADER_TESS_CTRL
, st
->pipe
->screen
);
1726 ureg_property(ureg
, TGSI_PROPERTY_TCS_VERTICES_OUT
,
1727 sttcp
->Base
.info
.tess
.tcs_vertices_out
);
1729 st_translate_program_common(st
, &sttcp
->Base
, sttcp
->glsl_to_tgsi
, ureg
,
1730 PIPE_SHADER_TESS_CTRL
, &sttcp
->tgsi
);
1732 free_glsl_to_tgsi_visitor(sttcp
->glsl_to_tgsi
);
1733 sttcp
->glsl_to_tgsi
= NULL
;
1739 * Translate a tessellation evaluation program to create a new variant.
1742 st_translate_tesseval_program(struct st_context
*st
,
1743 struct st_common_program
*sttep
)
1745 struct ureg_program
*ureg
;
1747 /* We have already compiled to NIR so just return */
1748 if (sttep
->shader_program
) {
1750 st_finalize_nir(st
, &sttep
->Base
, sttep
->shader_program
,
1751 sttep
->tgsi
.ir
.nir
);
1752 st_translate_program_stream_output(&sttep
->Base
, &sttep
->tgsi
.stream_output
);
1753 st_store_ir_in_disk_cache(st
, &sttep
->Base
, true);
1757 ureg
= ureg_create_with_screen(PIPE_SHADER_TESS_EVAL
, st
->pipe
->screen
);
1761 if (sttep
->Base
.info
.tess
.primitive_mode
== GL_ISOLINES
)
1762 ureg_property(ureg
, TGSI_PROPERTY_TES_PRIM_MODE
, GL_LINES
);
1764 ureg_property(ureg
, TGSI_PROPERTY_TES_PRIM_MODE
,
1765 sttep
->Base
.info
.tess
.primitive_mode
);
1767 STATIC_ASSERT((TESS_SPACING_EQUAL
+ 1) % 3 == PIPE_TESS_SPACING_EQUAL
);
1768 STATIC_ASSERT((TESS_SPACING_FRACTIONAL_ODD
+ 1) % 3 ==
1769 PIPE_TESS_SPACING_FRACTIONAL_ODD
);
1770 STATIC_ASSERT((TESS_SPACING_FRACTIONAL_EVEN
+ 1) % 3 ==
1771 PIPE_TESS_SPACING_FRACTIONAL_EVEN
);
1773 ureg_property(ureg
, TGSI_PROPERTY_TES_SPACING
,
1774 (sttep
->Base
.info
.tess
.spacing
+ 1) % 3);
1776 ureg_property(ureg
, TGSI_PROPERTY_TES_VERTEX_ORDER_CW
,
1777 !sttep
->Base
.info
.tess
.ccw
);
1778 ureg_property(ureg
, TGSI_PROPERTY_TES_POINT_MODE
,
1779 sttep
->Base
.info
.tess
.point_mode
);
1781 st_translate_program_common(st
, &sttep
->Base
, sttep
->glsl_to_tgsi
,
1782 ureg
, PIPE_SHADER_TESS_EVAL
, &sttep
->tgsi
);
1784 free_glsl_to_tgsi_visitor(sttep
->glsl_to_tgsi
);
1785 sttep
->glsl_to_tgsi
= NULL
;
1791 * Translate a compute program to create a new variant.
1794 st_translate_compute_program(struct st_context
*st
,
1795 struct st_compute_program
*stcp
)
1797 struct ureg_program
*ureg
;
1798 struct pipe_shader_state prog
;
1800 stcp
->tgsi
.req_local_mem
= stcp
->Base
.info
.cs
.shared_size
;
1802 if (stcp
->shader_program
) {
1803 /* no compute variants: */
1804 st_finalize_nir(st
, &stcp
->Base
, stcp
->shader_program
,
1805 (struct nir_shader
*) stcp
->tgsi
.prog
);
1806 st_store_ir_in_disk_cache(st
, &stcp
->Base
, true);
1810 ureg
= ureg_create_with_screen(PIPE_SHADER_COMPUTE
, st
->pipe
->screen
);
1814 st_translate_program_common(st
, &stcp
->Base
, stcp
->glsl_to_tgsi
, ureg
,
1815 PIPE_SHADER_COMPUTE
, &prog
);
1817 stcp
->tgsi
.ir_type
= PIPE_SHADER_IR_TGSI
;
1818 stcp
->tgsi
.req_private_mem
= 0;
1819 stcp
->tgsi
.req_input_mem
= 0;
1821 free_glsl_to_tgsi_visitor(stcp
->glsl_to_tgsi
);
1822 stcp
->glsl_to_tgsi
= NULL
;
1828 * Get/create compute program variant.
1830 struct st_basic_variant
*
1831 st_get_cp_variant(struct st_context
*st
,
1832 struct pipe_compute_state
*tgsi
,
1833 struct st_basic_variant
**variants
)
1835 struct pipe_context
*pipe
= st
->pipe
;
1836 struct st_basic_variant
*v
;
1837 struct st_basic_variant_key key
;
1839 /* use memset, not an initializer to be sure all memory is zeroed */
1840 memset(&key
, 0, sizeof(key
));
1842 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
1844 /* Search for existing variant */
1845 for (v
= *variants
; v
; v
= v
->next
) {
1846 if (memcmp(&v
->key
, &key
, sizeof(key
)) == 0) {
1853 v
= CALLOC_STRUCT(st_basic_variant
);
1855 /* fill in new variant */
1856 struct pipe_compute_state cs
= *tgsi
;
1857 if (tgsi
->ir_type
== PIPE_SHADER_IR_NIR
)
1858 cs
.prog
= nir_shader_clone(NULL
, tgsi
->prog
);
1859 v
->driver_shader
= pipe
->create_compute_state(pipe
, &cs
);
1862 /* insert into list */
1863 v
->next
= *variants
;
1873 * Vert/Geom/Frag programs have per-context variants. Free all the
1874 * variants attached to the given program which match the given context.
1877 destroy_program_variants(struct st_context
*st
, struct gl_program
*target
)
1879 if (!target
|| target
== &_mesa_DummyProgram
)
1882 switch (target
->Target
) {
1883 case GL_VERTEX_PROGRAM_ARB
:
1885 struct st_vertex_program
*stvp
= (struct st_vertex_program
*) target
;
1886 struct st_vp_variant
*vpv
, **prevPtr
= &stvp
->variants
;
1888 for (vpv
= stvp
->variants
; vpv
; ) {
1889 struct st_vp_variant
*next
= vpv
->next
;
1890 if (vpv
->key
.st
== st
) {
1891 /* unlink from list */
1893 /* destroy this variant */
1894 delete_vp_variant(st
, vpv
);
1897 prevPtr
= &vpv
->next
;
1903 case GL_FRAGMENT_PROGRAM_ARB
:
1905 struct st_fragment_program
*stfp
=
1906 (struct st_fragment_program
*) target
;
1907 struct st_fp_variant
*fpv
, **prevPtr
= &stfp
->variants
;
1909 for (fpv
= stfp
->variants
; fpv
; ) {
1910 struct st_fp_variant
*next
= fpv
->next
;
1911 if (fpv
->key
.st
== st
) {
1912 /* unlink from list */
1914 /* destroy this variant */
1915 delete_fp_variant(st
, fpv
);
1918 prevPtr
= &fpv
->next
;
1924 case GL_GEOMETRY_PROGRAM_NV
:
1925 case GL_TESS_CONTROL_PROGRAM_NV
:
1926 case GL_TESS_EVALUATION_PROGRAM_NV
:
1927 case GL_COMPUTE_PROGRAM_NV
:
1929 struct st_common_program
*p
= st_common_program(target
);
1930 struct st_compute_program
*cp
= (struct st_compute_program
*)target
;
1931 struct st_basic_variant
**variants
=
1932 target
->Target
== GL_COMPUTE_PROGRAM_NV
? &cp
->variants
:
1934 struct st_basic_variant
*v
, **prevPtr
= variants
;
1936 for (v
= *variants
; v
; ) {
1937 struct st_basic_variant
*next
= v
->next
;
1938 if (v
->key
.st
== st
) {
1939 /* unlink from list */
1941 /* destroy this variant */
1942 delete_basic_variant(st
, v
, target
->Target
);
1952 _mesa_problem(NULL
, "Unexpected program target 0x%x in "
1953 "destroy_program_variants_cb()", target
->Target
);
1959 * Callback for _mesa_HashWalk. Free all the shader's program variants
1960 * which match the given context.
1963 destroy_shader_program_variants_cb(GLuint key
, void *data
, void *userData
)
1965 struct st_context
*st
= (struct st_context
*) userData
;
1966 struct gl_shader
*shader
= (struct gl_shader
*) data
;
1968 switch (shader
->Type
) {
1969 case GL_SHADER_PROGRAM_MESA
:
1971 struct gl_shader_program
*shProg
= (struct gl_shader_program
*) data
;
1974 for (i
= 0; i
< ARRAY_SIZE(shProg
->_LinkedShaders
); i
++) {
1975 if (shProg
->_LinkedShaders
[i
])
1976 destroy_program_variants(st
, shProg
->_LinkedShaders
[i
]->Program
);
1980 case GL_VERTEX_SHADER
:
1981 case GL_FRAGMENT_SHADER
:
1982 case GL_GEOMETRY_SHADER
:
1983 case GL_TESS_CONTROL_SHADER
:
1984 case GL_TESS_EVALUATION_SHADER
:
1985 case GL_COMPUTE_SHADER
:
1994 * Callback for _mesa_HashWalk. Free all the program variants which match
1995 * the given context.
1998 destroy_program_variants_cb(GLuint key
, void *data
, void *userData
)
2000 struct st_context
*st
= (struct st_context
*) userData
;
2001 struct gl_program
*program
= (struct gl_program
*) data
;
2002 destroy_program_variants(st
, program
);
2007 * Walk over all shaders and programs to delete any variants which
2008 * belong to the given context.
2009 * This is called during context tear-down.
2012 st_destroy_program_variants(struct st_context
*st
)
2014 /* If shaders can be shared with other contexts, the last context will
2015 * call DeleteProgram on all shaders, releasing everything.
2017 if (st
->has_shareable_shaders
)
2020 /* ARB vert/frag program */
2021 _mesa_HashWalk(st
->ctx
->Shared
->Programs
,
2022 destroy_program_variants_cb
, st
);
2024 /* GLSL vert/frag/geom shaders */
2025 _mesa_HashWalk(st
->ctx
->Shared
->ShaderObjects
,
2026 destroy_shader_program_variants_cb
, st
);
2031 * For debugging, print/dump the current vertex program.
2034 st_print_current_vertex_program(void)
2036 GET_CURRENT_CONTEXT(ctx
);
2038 if (ctx
->VertexProgram
._Current
) {
2039 struct st_vertex_program
*stvp
=
2040 (struct st_vertex_program
*) ctx
->VertexProgram
._Current
;
2041 struct st_vp_variant
*stv
;
2043 debug_printf("Vertex program %u\n", stvp
->Base
.Id
);
2045 for (stv
= stvp
->variants
; stv
; stv
= stv
->next
) {
2046 debug_printf("variant %p\n", stv
);
2047 tgsi_dump(stv
->tgsi
.tokens
, 0);
2054 * Compile one shader variant.
2057 st_precompile_shader_variant(struct st_context
*st
,
2058 struct gl_program
*prog
)
2060 switch (prog
->Target
) {
2061 case GL_VERTEX_PROGRAM_ARB
: {
2062 struct st_vertex_program
*p
= (struct st_vertex_program
*)prog
;
2063 struct st_vp_variant_key key
;
2065 memset(&key
, 0, sizeof(key
));
2067 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2068 st_get_vp_variant(st
, p
, &key
);
2072 case GL_TESS_CONTROL_PROGRAM_NV
: {
2073 struct st_common_program
*p
= st_common_program(prog
);
2074 struct st_basic_variant_key key
;
2076 memset(&key
, 0, sizeof(key
));
2078 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2079 st_get_basic_variant(st
, PIPE_SHADER_TESS_CTRL
, p
, &key
);
2083 case GL_TESS_EVALUATION_PROGRAM_NV
: {
2084 struct st_common_program
*p
= st_common_program(prog
);
2085 struct st_basic_variant_key key
;
2087 memset(&key
, 0, sizeof(key
));
2089 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2090 st_get_basic_variant(st
, PIPE_SHADER_TESS_EVAL
, p
, &key
);
2094 case GL_GEOMETRY_PROGRAM_NV
: {
2095 struct st_common_program
*p
= st_common_program(prog
);
2096 struct st_basic_variant_key key
;
2098 memset(&key
, 0, sizeof(key
));
2100 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2101 st_get_basic_variant(st
, PIPE_SHADER_GEOMETRY
, p
, &key
);
2105 case GL_FRAGMENT_PROGRAM_ARB
: {
2106 struct st_fragment_program
*p
= (struct st_fragment_program
*)prog
;
2107 struct st_fp_variant_key key
;
2109 memset(&key
, 0, sizeof(key
));
2111 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2112 st_get_fp_variant(st
, p
, &key
);
2116 case GL_COMPUTE_PROGRAM_NV
: {
2117 struct st_compute_program
*p
= (struct st_compute_program
*)prog
;
2118 st_get_cp_variant(st
, &p
->tgsi
, &p
->variants
);