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_depth_clamp.h"
59 #include "st_tgsi_lower_yuv.h"
60 #include "st_program.h"
61 #include "st_mesa_to_tgsi.h"
62 #include "st_atifs_to_tgsi.h"
64 #include "st_shader_cache.h"
65 #include "cso_cache/cso_context.h"
70 set_affected_state_flags(uint64_t *states
,
71 struct gl_program
*prog
,
72 uint64_t new_constants
,
73 uint64_t new_sampler_views
,
74 uint64_t new_samplers
,
80 if (prog
->Parameters
->NumParameters
)
81 *states
|= new_constants
;
83 if (prog
->info
.num_textures
)
84 *states
|= new_sampler_views
| new_samplers
;
86 if (prog
->info
.num_images
)
87 *states
|= new_images
;
89 if (prog
->info
.num_ubos
)
92 if (prog
->info
.num_ssbos
)
95 if (prog
->info
.num_abos
)
96 *states
|= new_atomics
;
100 * This determines which states will be updated when the shader is bound.
103 st_set_prog_affected_state_flags(struct gl_program
*prog
)
107 switch (prog
->info
.stage
) {
108 case MESA_SHADER_VERTEX
:
109 states
= &((struct st_vertex_program
*)prog
)->affected_states
;
111 *states
= ST_NEW_VS_STATE
|
113 ST_NEW_VERTEX_ARRAYS
;
115 set_affected_state_flags(states
, prog
,
117 ST_NEW_VS_SAMPLER_VIEWS
,
125 case MESA_SHADER_TESS_CTRL
:
126 states
= &(st_common_program(prog
))->affected_states
;
128 *states
= ST_NEW_TCS_STATE
;
130 set_affected_state_flags(states
, prog
,
131 ST_NEW_TCS_CONSTANTS
,
132 ST_NEW_TCS_SAMPLER_VIEWS
,
140 case MESA_SHADER_TESS_EVAL
:
141 states
= &(st_common_program(prog
))->affected_states
;
143 *states
= ST_NEW_TES_STATE
|
146 set_affected_state_flags(states
, prog
,
147 ST_NEW_TES_CONSTANTS
,
148 ST_NEW_TES_SAMPLER_VIEWS
,
156 case MESA_SHADER_GEOMETRY
:
157 states
= &(st_common_program(prog
))->affected_states
;
159 *states
= ST_NEW_GS_STATE
|
162 set_affected_state_flags(states
, prog
,
164 ST_NEW_GS_SAMPLER_VIEWS
,
172 case MESA_SHADER_FRAGMENT
:
173 states
= &((struct st_fragment_program
*)prog
)->affected_states
;
175 /* gl_FragCoord and glDrawPixels always use constants. */
176 *states
= ST_NEW_FS_STATE
|
177 ST_NEW_SAMPLE_SHADING
|
180 set_affected_state_flags(states
, prog
,
182 ST_NEW_FS_SAMPLER_VIEWS
,
190 case MESA_SHADER_COMPUTE
:
191 states
= &((struct st_compute_program
*)prog
)->affected_states
;
193 *states
= ST_NEW_CS_STATE
;
195 set_affected_state_flags(states
, prog
,
197 ST_NEW_CS_SAMPLER_VIEWS
,
206 unreachable("unhandled shader stage");
211 delete_ir(struct pipe_shader_state
*ir
)
214 ureg_free_tokens(ir
->tokens
);
216 /* Note: Any setup of ->ir.nir that has had pipe->create_*_state called on
217 * it has resulted in the driver taking ownership of the NIR. Those
218 * callers should be NULLing out the nir field in any pipe_shader_state
219 * that might have this called in order to indicate that.
221 * GLSL IR and ARB programs will have set gl_program->nir to the same
222 * shader as ir->ir.nir, so it will be freed by _mesa_delete_program().
227 * Delete a vertex program variant. Note the caller must unlink
228 * the variant from the linked list.
231 delete_vp_variant(struct st_context
*st
, struct st_vp_variant
*vpv
)
233 if (vpv
->driver_shader
) {
234 if (st
->has_shareable_shaders
|| vpv
->key
.st
== st
) {
235 cso_delete_vertex_shader(st
->cso_context
, vpv
->driver_shader
);
237 st_save_zombie_shader(vpv
->key
.st
, PIPE_SHADER_VERTEX
,
242 if (vpv
->draw_shader
)
243 draw_delete_vertex_shader( st
->draw
, vpv
->draw_shader
);
245 delete_ir(&vpv
->tgsi
);
253 * Clean out any old compilations:
256 st_release_vp_variants( struct st_context
*st
,
257 struct st_vertex_program
*stvp
)
259 struct st_vp_variant
*vpv
;
261 for (vpv
= stvp
->variants
; vpv
; ) {
262 struct st_vp_variant
*next
= vpv
->next
;
263 delete_vp_variant(st
, vpv
);
267 stvp
->variants
= NULL
;
269 delete_ir(&stvp
->tgsi
);
275 * Delete a fragment program variant. Note the caller must unlink
276 * the variant from the linked list.
279 delete_fp_variant(struct st_context
*st
, struct st_fp_variant
*fpv
)
281 if (fpv
->driver_shader
) {
282 if (st
->has_shareable_shaders
|| fpv
->key
.st
== st
) {
283 cso_delete_fragment_shader(st
->cso_context
, fpv
->driver_shader
);
285 st_save_zombie_shader(fpv
->key
.st
, PIPE_SHADER_FRAGMENT
,
295 * Free all variants of a fragment program.
298 st_release_fp_variants(struct st_context
*st
, struct st_fragment_program
*stfp
)
300 struct st_fp_variant
*fpv
;
302 for (fpv
= stfp
->variants
; fpv
; ) {
303 struct st_fp_variant
*next
= fpv
->next
;
304 delete_fp_variant(st
, fpv
);
308 stfp
->variants
= NULL
;
310 delete_ir(&stfp
->tgsi
);
315 * Delete a basic program variant. Note the caller must unlink
316 * the variant from the linked list.
319 delete_basic_variant(struct st_context
*st
, struct st_basic_variant
*v
,
322 if (v
->driver_shader
) {
323 if (st
->has_shareable_shaders
|| v
->key
.st
== st
) {
324 /* The shader's context matches the calling context, or we
328 case GL_TESS_CONTROL_PROGRAM_NV
:
329 cso_delete_tessctrl_shader(st
->cso_context
, v
->driver_shader
);
331 case GL_TESS_EVALUATION_PROGRAM_NV
:
332 cso_delete_tesseval_shader(st
->cso_context
, v
->driver_shader
);
334 case GL_GEOMETRY_PROGRAM_NV
:
335 cso_delete_geometry_shader(st
->cso_context
, v
->driver_shader
);
337 case GL_COMPUTE_PROGRAM_NV
:
338 cso_delete_compute_shader(st
->cso_context
, v
->driver_shader
);
341 unreachable("bad shader type in delete_basic_variant");
344 /* We can't delete a shader with a context different from the one
345 * that created it. Add it to the creating context's zombie list.
347 enum pipe_shader_type type
;
349 case GL_TESS_CONTROL_PROGRAM_NV
:
350 type
= PIPE_SHADER_TESS_CTRL
;
352 case GL_TESS_EVALUATION_PROGRAM_NV
:
353 type
= PIPE_SHADER_TESS_EVAL
;
355 case GL_GEOMETRY_PROGRAM_NV
:
356 type
= PIPE_SHADER_GEOMETRY
;
361 st_save_zombie_shader(v
->key
.st
, type
, v
->driver_shader
);
370 * Free all basic program variants.
373 st_release_basic_variants(struct st_context
*st
, GLenum target
,
374 struct st_basic_variant
**variants
,
375 struct pipe_shader_state
*tgsi
)
377 struct st_basic_variant
*v
;
379 for (v
= *variants
; v
; ) {
380 struct st_basic_variant
*next
= v
->next
;
381 delete_basic_variant(st
, v
, target
);
392 * Free all variants of a compute program.
395 st_release_cp_variants(struct st_context
*st
, struct st_compute_program
*stcp
)
397 struct st_basic_variant
**variants
= &stcp
->variants
;
398 struct st_basic_variant
*v
;
400 for (v
= *variants
; v
; ) {
401 struct st_basic_variant
*next
= v
->next
;
402 delete_basic_variant(st
, v
, stcp
->Base
.Target
);
408 if (stcp
->tgsi
.prog
) {
409 switch (stcp
->tgsi
.ir_type
) {
410 case PIPE_SHADER_IR_TGSI
:
411 ureg_free_tokens(stcp
->tgsi
.prog
);
412 stcp
->tgsi
.prog
= NULL
;
414 case PIPE_SHADER_IR_NIR
:
415 /* pipe driver took ownership of prog */
417 case PIPE_SHADER_IR_NATIVE
:
419 stcp
->tgsi
.prog
= NULL
;
426 * Translate ARB (asm) program to NIR
429 st_translate_prog_to_nir(struct st_context
*st
, struct gl_program
*prog
,
430 gl_shader_stage stage
)
432 enum pipe_shader_type p_stage
= pipe_shader_type_from_mesa(stage
);
433 const bool is_scalar
=
434 st
->pipe
->screen
->get_shader_param(st
->pipe
->screen
, p_stage
,
435 PIPE_SHADER_CAP_SCALAR_ISA
);
437 const struct gl_shader_compiler_options
*options
=
438 &st
->ctx
->Const
.ShaderCompilerOptions
[stage
];
440 /* Translate to NIR */
441 nir_shader
*nir
= prog_to_nir(prog
, options
->NirOptions
);
442 NIR_PASS_V(nir
, nir_lower_regs_to_ssa
); /* turn registers into SSA */
443 nir_validate_shader(nir
, "after st/ptn lower_regs_to_ssa");
445 NIR_PASS_V(nir
, st_nir_lower_wpos_ytransform
, prog
, st
->pipe
->screen
);
446 NIR_PASS_V(nir
, nir_lower_system_values
);
449 NIR_PASS_V(nir
, nir_opt_constant_folding
);
450 st_nir_opts(nir
, is_scalar
);
451 nir_validate_shader(nir
, "after st/ptn NIR opts");
457 * Translate a vertex program.
460 st_translate_vertex_program(struct st_context
*st
,
461 struct st_vertex_program
*stvp
)
463 struct ureg_program
*ureg
;
464 enum pipe_error error
;
465 unsigned num_outputs
= 0;
467 ubyte output_semantic_name
[VARYING_SLOT_MAX
] = {0};
468 ubyte output_semantic_index
[VARYING_SLOT_MAX
] = {0};
470 stvp
->num_inputs
= 0;
471 memset(stvp
->input_to_index
, ~0, sizeof(stvp
->input_to_index
));
473 if (stvp
->Base
.arb
.IsPositionInvariant
)
474 _mesa_insert_mvp_code(st
->ctx
, &stvp
->Base
);
477 * Determine number of inputs, the mappings between VERT_ATTRIB_x
478 * and TGSI generic input indexes, plus input attrib semantic info.
480 for (attr
= 0; attr
< VERT_ATTRIB_MAX
; attr
++) {
481 if ((stvp
->Base
.info
.inputs_read
& BITFIELD64_BIT(attr
)) != 0) {
482 stvp
->input_to_index
[attr
] = stvp
->num_inputs
;
483 stvp
->index_to_input
[stvp
->num_inputs
] = attr
;
485 if ((stvp
->Base
.DualSlotInputs
& BITFIELD64_BIT(attr
)) != 0) {
486 /* add placeholder for second part of a double attribute */
487 stvp
->index_to_input
[stvp
->num_inputs
] = ST_DOUBLE_ATTRIB_PLACEHOLDER
;
492 /* bit of a hack, presetup potentially unused edgeflag input */
493 stvp
->input_to_index
[VERT_ATTRIB_EDGEFLAG
] = stvp
->num_inputs
;
494 stvp
->index_to_input
[stvp
->num_inputs
] = VERT_ATTRIB_EDGEFLAG
;
496 /* Compute mapping of vertex program outputs to slots.
498 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
499 if ((stvp
->Base
.info
.outputs_written
& BITFIELD64_BIT(attr
)) == 0) {
500 stvp
->result_to_output
[attr
] = ~0;
503 unsigned slot
= num_outputs
++;
505 stvp
->result_to_output
[attr
] = slot
;
507 unsigned semantic_name
, semantic_index
;
508 tgsi_get_gl_varying_semantic(attr
, st
->needs_texcoord_semantic
,
509 &semantic_name
, &semantic_index
);
510 output_semantic_name
[slot
] = semantic_name
;
511 output_semantic_index
[slot
] = semantic_index
;
514 /* similar hack to above, presetup potentially unused edgeflag output */
515 stvp
->result_to_output
[VARYING_SLOT_EDGE
] = num_outputs
;
516 output_semantic_name
[num_outputs
] = TGSI_SEMANTIC_EDGEFLAG
;
517 output_semantic_index
[num_outputs
] = 0;
520 if (!stvp
->glsl_to_tgsi
&& !stvp
->shader_program
) {
521 _mesa_remove_output_reads(&stvp
->Base
, PROGRAM_OUTPUT
);
523 /* This determines which states will be updated when the assembly
526 stvp
->affected_states
= ST_NEW_VS_STATE
|
528 ST_NEW_VERTEX_ARRAYS
;
530 if (stvp
->Base
.Parameters
->NumParameters
)
531 stvp
->affected_states
|= ST_NEW_VS_CONSTANTS
;
533 /* No samplers are allowed in ARB_vp. */
536 if (stvp
->shader_program
) {
537 st_translate_stream_output_info(stvp
->Base
.sh
.LinkedTransformFeedback
,
538 stvp
->result_to_output
,
539 &stvp
->tgsi
.stream_output
);
541 st_store_ir_in_disk_cache(st
, &stvp
->Base
, true);
545 ureg
= ureg_create_with_screen(PIPE_SHADER_VERTEX
, st
->pipe
->screen
);
549 if (stvp
->Base
.info
.clip_distance_array_size
)
550 ureg_property(ureg
, TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
,
551 stvp
->Base
.info
.clip_distance_array_size
);
552 if (stvp
->Base
.info
.cull_distance_array_size
)
553 ureg_property(ureg
, TGSI_PROPERTY_NUM_CULLDIST_ENABLED
,
554 stvp
->Base
.info
.cull_distance_array_size
);
556 if (ST_DEBUG
& DEBUG_MESA
) {
557 _mesa_print_program(&stvp
->Base
);
558 _mesa_print_program_parameters(st
->ctx
, &stvp
->Base
);
562 if (stvp
->glsl_to_tgsi
) {
563 error
= st_translate_program(st
->ctx
,
570 stvp
->input_to_index
,
571 NULL
, /* inputSlotToAttr */
572 NULL
, /* input semantic name */
573 NULL
, /* input semantic index */
574 NULL
, /* interp mode */
577 stvp
->result_to_output
,
578 output_semantic_name
,
579 output_semantic_index
);
581 st_translate_stream_output_info(stvp
->Base
.sh
.LinkedTransformFeedback
,
582 stvp
->result_to_output
,
583 &stvp
->tgsi
.stream_output
);
585 free_glsl_to_tgsi_visitor(stvp
->glsl_to_tgsi
);
587 error
= st_translate_mesa_program(st
->ctx
,
593 stvp
->input_to_index
,
594 NULL
, /* input semantic name */
595 NULL
, /* input semantic index */
599 stvp
->result_to_output
,
600 output_semantic_name
,
601 output_semantic_index
);
604 debug_printf("%s: failed to translate Mesa program:\n", __func__
);
605 _mesa_print_program(&stvp
->Base
);
610 stvp
->tgsi
.tokens
= ureg_get_tokens(ureg
, &stvp
->num_tgsi_tokens
);
613 if (stvp
->glsl_to_tgsi
) {
614 stvp
->glsl_to_tgsi
= NULL
;
615 st_store_ir_in_disk_cache(st
, &stvp
->Base
, false);
618 bool use_nir
= PIPE_SHADER_IR_NIR
==
619 st
->pipe
->screen
->get_shader_param(st
->pipe
->screen
, PIPE_SHADER_VERTEX
,
620 PIPE_SHADER_CAP_PREFERRED_IR
);
624 st_translate_prog_to_nir(st
, &stvp
->Base
, MESA_SHADER_VERTEX
);
626 if (stvp
->tgsi
.ir
.nir
)
627 ralloc_free(stvp
->tgsi
.ir
.nir
);
628 stvp
->tgsi
.type
= PIPE_SHADER_IR_NIR
;
629 stvp
->tgsi
.ir
.nir
= nir
;
630 stvp
->Base
.nir
= nir
;
634 return stvp
->tgsi
.tokens
!= NULL
;
637 static const gl_state_index16 depth_range_state
[STATE_LENGTH
] =
638 { STATE_DEPTH_RANGE
};
640 static struct st_vp_variant
*
641 st_create_vp_variant(struct st_context
*st
,
642 struct st_vertex_program
*stvp
,
643 const struct st_vp_variant_key
*key
)
645 struct st_vp_variant
*vpv
= CALLOC_STRUCT(st_vp_variant
);
646 struct pipe_context
*pipe
= st
->pipe
;
647 struct gl_program_parameter_list
*params
= stvp
->Base
.Parameters
;
650 vpv
->tgsi
.stream_output
= stvp
->tgsi
.stream_output
;
651 vpv
->num_inputs
= stvp
->num_inputs
;
653 /* When generating a NIR program, we usually don't have TGSI tokens.
654 * However, we do create them for ARB_vertex_program / fixed-function VS
655 * programs which we may need to use with the draw module for legacy
656 * feedback/select emulation. If they exist, copy them.
658 if (stvp
->tgsi
.tokens
)
659 vpv
->tgsi
.tokens
= tgsi_dup_tokens(stvp
->tgsi
.tokens
);
661 if (stvp
->tgsi
.type
== PIPE_SHADER_IR_NIR
) {
662 vpv
->tgsi
.type
= PIPE_SHADER_IR_NIR
;
663 vpv
->tgsi
.ir
.nir
= nir_shader_clone(NULL
, stvp
->tgsi
.ir
.nir
);
664 if (key
->clamp_color
)
665 NIR_PASS_V(vpv
->tgsi
.ir
.nir
, nir_lower_clamp_color_outputs
);
666 if (key
->passthrough_edgeflags
) {
667 NIR_PASS_V(vpv
->tgsi
.ir
.nir
, nir_lower_passthrough_edgeflags
);
671 st_finalize_nir(st
, &stvp
->Base
, stvp
->shader_program
,
674 vpv
->driver_shader
= pipe
->create_vs_state(pipe
, &vpv
->tgsi
);
675 /* driver takes ownership of IR: */
676 vpv
->tgsi
.ir
.nir
= NULL
;
680 /* Emulate features. */
681 if (key
->clamp_color
|| key
->passthrough_edgeflags
) {
682 const struct tgsi_token
*tokens
;
684 (key
->clamp_color
? TGSI_EMU_CLAMP_COLOR_OUTPUTS
: 0) |
685 (key
->passthrough_edgeflags
? TGSI_EMU_PASSTHROUGH_EDGEFLAG
: 0);
687 tokens
= tgsi_emulate(vpv
->tgsi
.tokens
, flags
);
690 tgsi_free_tokens(vpv
->tgsi
.tokens
);
691 vpv
->tgsi
.tokens
= tokens
;
693 if (key
->passthrough_edgeflags
)
696 fprintf(stderr
, "mesa: cannot emulate deprecated features\n");
699 if (key
->lower_depth_clamp
) {
700 unsigned depth_range_const
=
701 _mesa_add_state_reference(params
, depth_range_state
);
703 const struct tgsi_token
*tokens
;
704 tokens
= st_tgsi_lower_depth_clamp(vpv
->tgsi
.tokens
, depth_range_const
,
705 key
->clip_negative_one_to_one
);
706 if (tokens
!= vpv
->tgsi
.tokens
)
707 tgsi_free_tokens(vpv
->tgsi
.tokens
);
708 vpv
->tgsi
.tokens
= tokens
;
711 if (ST_DEBUG
& DEBUG_TGSI
) {
712 tgsi_dump(vpv
->tgsi
.tokens
, 0);
716 vpv
->driver_shader
= pipe
->create_vs_state(pipe
, &vpv
->tgsi
);
722 * Find/create a vertex program variant.
724 struct st_vp_variant
*
725 st_get_vp_variant(struct st_context
*st
,
726 struct st_vertex_program
*stvp
,
727 const struct st_vp_variant_key
*key
)
729 struct st_vp_variant
*vpv
;
731 /* Search for existing variant */
732 for (vpv
= stvp
->variants
; vpv
; vpv
= vpv
->next
) {
733 if (memcmp(&vpv
->key
, key
, sizeof(*key
)) == 0) {
740 vpv
= st_create_vp_variant(st
, stvp
, key
);
742 for (unsigned index
= 0; index
< vpv
->num_inputs
; ++index
) {
743 unsigned attr
= stvp
->index_to_input
[index
];
744 if (attr
== ST_DOUBLE_ATTRIB_PLACEHOLDER
)
746 vpv
->vert_attrib_mask
|= 1u << attr
;
749 /* insert into list */
750 vpv
->next
= stvp
->variants
;
751 stvp
->variants
= vpv
;
760 * Translate a Mesa fragment shader into a TGSI shader.
763 st_translate_fragment_program(struct st_context
*st
,
764 struct st_fragment_program
*stfp
)
766 /* We have already compiled to NIR so just return */
767 if (stfp
->shader_program
) {
768 st_store_ir_in_disk_cache(st
, &stfp
->Base
, true);
772 ubyte outputMapping
[2 * FRAG_RESULT_MAX
];
773 ubyte inputMapping
[VARYING_SLOT_MAX
];
774 ubyte inputSlotToAttr
[VARYING_SLOT_MAX
];
775 ubyte interpMode
[PIPE_MAX_SHADER_INPUTS
]; /* XXX size? */
777 GLbitfield64 inputsRead
;
778 struct ureg_program
*ureg
;
780 GLboolean write_all
= GL_FALSE
;
782 ubyte input_semantic_name
[PIPE_MAX_SHADER_INPUTS
];
783 ubyte input_semantic_index
[PIPE_MAX_SHADER_INPUTS
];
784 uint fs_num_inputs
= 0;
786 ubyte fs_output_semantic_name
[PIPE_MAX_SHADER_OUTPUTS
];
787 ubyte fs_output_semantic_index
[PIPE_MAX_SHADER_OUTPUTS
];
788 uint fs_num_outputs
= 0;
790 memset(inputSlotToAttr
, ~0, sizeof(inputSlotToAttr
));
792 /* Non-GLSL programs: */
793 if (!stfp
->glsl_to_tgsi
&& !stfp
->shader_program
) {
794 _mesa_remove_output_reads(&stfp
->Base
, PROGRAM_OUTPUT
);
795 if (st
->ctx
->Const
.GLSLFragCoordIsSysVal
)
796 _mesa_program_fragment_position_to_sysval(&stfp
->Base
);
798 /* This determines which states will be updated when the assembly
801 * fragment.position and glDrawPixels always use constants.
803 stfp
->affected_states
= ST_NEW_FS_STATE
|
804 ST_NEW_SAMPLE_SHADING
|
808 /* Just set them for ATI_fs unconditionally. */
809 stfp
->affected_states
|= ST_NEW_FS_SAMPLER_VIEWS
|
813 if (stfp
->Base
.SamplersUsed
)
814 stfp
->affected_states
|= ST_NEW_FS_SAMPLER_VIEWS
|
820 bool use_nir
= PIPE_SHADER_IR_NIR
==
821 st
->pipe
->screen
->get_shader_param(st
->pipe
->screen
,
822 PIPE_SHADER_FRAGMENT
,
823 PIPE_SHADER_CAP_PREFERRED_IR
);
825 if (use_nir
&& !stfp
->ati_fs
) {
827 st_translate_prog_to_nir(st
, &stfp
->Base
, MESA_SHADER_FRAGMENT
);
829 if (stfp
->tgsi
.ir
.nir
)
830 ralloc_free(stfp
->tgsi
.ir
.nir
);
831 stfp
->tgsi
.type
= PIPE_SHADER_IR_NIR
;
832 stfp
->tgsi
.ir
.nir
= nir
;
833 stfp
->Base
.nir
= nir
;
838 * Convert Mesa program inputs to TGSI input register semantics.
840 inputsRead
= stfp
->Base
.info
.inputs_read
;
841 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
842 if ((inputsRead
& BITFIELD64_BIT(attr
)) != 0) {
843 const GLuint slot
= fs_num_inputs
++;
845 inputMapping
[attr
] = slot
;
846 inputSlotToAttr
[slot
] = attr
;
849 case VARYING_SLOT_POS
:
850 input_semantic_name
[slot
] = TGSI_SEMANTIC_POSITION
;
851 input_semantic_index
[slot
] = 0;
852 interpMode
[slot
] = TGSI_INTERPOLATE_LINEAR
;
854 case VARYING_SLOT_COL0
:
855 input_semantic_name
[slot
] = TGSI_SEMANTIC_COLOR
;
856 input_semantic_index
[slot
] = 0;
857 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
858 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_COLOR
;
860 case VARYING_SLOT_COL1
:
861 input_semantic_name
[slot
] = TGSI_SEMANTIC_COLOR
;
862 input_semantic_index
[slot
] = 1;
863 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
864 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_COLOR
;
866 case VARYING_SLOT_FOGC
:
867 input_semantic_name
[slot
] = TGSI_SEMANTIC_FOG
;
868 input_semantic_index
[slot
] = 0;
869 interpMode
[slot
] = TGSI_INTERPOLATE_PERSPECTIVE
;
871 case VARYING_SLOT_FACE
:
872 input_semantic_name
[slot
] = TGSI_SEMANTIC_FACE
;
873 input_semantic_index
[slot
] = 0;
874 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
876 case VARYING_SLOT_PRIMITIVE_ID
:
877 input_semantic_name
[slot
] = TGSI_SEMANTIC_PRIMID
;
878 input_semantic_index
[slot
] = 0;
879 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
881 case VARYING_SLOT_LAYER
:
882 input_semantic_name
[slot
] = TGSI_SEMANTIC_LAYER
;
883 input_semantic_index
[slot
] = 0;
884 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
886 case VARYING_SLOT_VIEWPORT
:
887 input_semantic_name
[slot
] = TGSI_SEMANTIC_VIEWPORT_INDEX
;
888 input_semantic_index
[slot
] = 0;
889 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
891 case VARYING_SLOT_CLIP_DIST0
:
892 input_semantic_name
[slot
] = TGSI_SEMANTIC_CLIPDIST
;
893 input_semantic_index
[slot
] = 0;
894 interpMode
[slot
] = TGSI_INTERPOLATE_PERSPECTIVE
;
896 case VARYING_SLOT_CLIP_DIST1
:
897 input_semantic_name
[slot
] = TGSI_SEMANTIC_CLIPDIST
;
898 input_semantic_index
[slot
] = 1;
899 interpMode
[slot
] = TGSI_INTERPOLATE_PERSPECTIVE
;
901 case VARYING_SLOT_CULL_DIST0
:
902 case VARYING_SLOT_CULL_DIST1
:
903 /* these should have been lowered by GLSL */
906 /* In most cases, there is nothing special about these
907 * inputs, so adopt a convention to use the generic
908 * semantic name and the mesa VARYING_SLOT_ number as the
911 * All that is required is that the vertex shader labels
912 * its own outputs similarly, and that the vertex shader
913 * generates at least every output required by the
914 * fragment shader plus fixed-function hardware (such as
917 * However, some drivers may need us to identify the PNTC and TEXi
918 * varyings if, for example, their capability to replace them with
919 * sprite coordinates is limited.
921 case VARYING_SLOT_PNTC
:
922 if (st
->needs_texcoord_semantic
) {
923 input_semantic_name
[slot
] = TGSI_SEMANTIC_PCOORD
;
924 input_semantic_index
[slot
] = 0;
925 interpMode
[slot
] = TGSI_INTERPOLATE_LINEAR
;
929 case VARYING_SLOT_TEX0
:
930 case VARYING_SLOT_TEX1
:
931 case VARYING_SLOT_TEX2
:
932 case VARYING_SLOT_TEX3
:
933 case VARYING_SLOT_TEX4
:
934 case VARYING_SLOT_TEX5
:
935 case VARYING_SLOT_TEX6
:
936 case VARYING_SLOT_TEX7
:
937 if (st
->needs_texcoord_semantic
) {
938 input_semantic_name
[slot
] = TGSI_SEMANTIC_TEXCOORD
;
939 input_semantic_index
[slot
] = attr
- VARYING_SLOT_TEX0
;
940 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
941 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_PERSPECTIVE
;
945 case VARYING_SLOT_VAR0
:
947 /* Semantic indices should be zero-based because drivers may choose
948 * to assign a fixed slot determined by that index.
949 * This is useful because ARB_separate_shader_objects uses location
950 * qualifiers for linkage, and if the semantic index corresponds to
951 * these locations, linkage passes in the driver become unecessary.
953 * If needs_texcoord_semantic is true, no semantic indices will be
954 * consumed for the TEXi varyings, and we can base the locations of
955 * the user varyings on VAR0. Otherwise, we use TEX0 as base index.
957 assert(attr
>= VARYING_SLOT_VAR0
|| attr
== VARYING_SLOT_PNTC
||
958 (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
));
959 input_semantic_name
[slot
] = TGSI_SEMANTIC_GENERIC
;
960 input_semantic_index
[slot
] = st_get_generic_varying_index(st
, attr
);
961 if (attr
== VARYING_SLOT_PNTC
)
962 interpMode
[slot
] = TGSI_INTERPOLATE_LINEAR
;
964 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
965 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_PERSPECTIVE
;
971 inputMapping
[attr
] = -1;
976 * Semantics and mapping for outputs
978 GLbitfield64 outputsWritten
= stfp
->Base
.info
.outputs_written
;
980 /* if z is written, emit that first */
981 if (outputsWritten
& BITFIELD64_BIT(FRAG_RESULT_DEPTH
)) {
982 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_POSITION
;
983 fs_output_semantic_index
[fs_num_outputs
] = 0;
984 outputMapping
[FRAG_RESULT_DEPTH
] = fs_num_outputs
;
986 outputsWritten
&= ~(1 << FRAG_RESULT_DEPTH
);
989 if (outputsWritten
& BITFIELD64_BIT(FRAG_RESULT_STENCIL
)) {
990 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_STENCIL
;
991 fs_output_semantic_index
[fs_num_outputs
] = 0;
992 outputMapping
[FRAG_RESULT_STENCIL
] = fs_num_outputs
;
994 outputsWritten
&= ~(1 << FRAG_RESULT_STENCIL
);
997 if (outputsWritten
& BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK
)) {
998 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_SAMPLEMASK
;
999 fs_output_semantic_index
[fs_num_outputs
] = 0;
1000 outputMapping
[FRAG_RESULT_SAMPLE_MASK
] = fs_num_outputs
;
1002 outputsWritten
&= ~(1 << FRAG_RESULT_SAMPLE_MASK
);
1005 /* handle remaining outputs (color) */
1006 for (attr
= 0; attr
< ARRAY_SIZE(outputMapping
); attr
++) {
1007 const GLbitfield64 written
= attr
< FRAG_RESULT_MAX
? outputsWritten
:
1008 stfp
->Base
.SecondaryOutputsWritten
;
1009 const unsigned loc
= attr
% FRAG_RESULT_MAX
;
1011 if (written
& BITFIELD64_BIT(loc
)) {
1013 case FRAG_RESULT_DEPTH
:
1014 case FRAG_RESULT_STENCIL
:
1015 case FRAG_RESULT_SAMPLE_MASK
:
1019 case FRAG_RESULT_COLOR
:
1020 write_all
= GL_TRUE
; /* fallthrough */
1023 assert(loc
== FRAG_RESULT_COLOR
||
1024 (FRAG_RESULT_DATA0
<= loc
&& loc
< FRAG_RESULT_MAX
));
1026 index
= (loc
== FRAG_RESULT_COLOR
) ? 0 : (loc
- FRAG_RESULT_DATA0
);
1028 if (attr
>= FRAG_RESULT_MAX
) {
1029 /* Secondary color for dual source blending. */
1034 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_COLOR
;
1035 fs_output_semantic_index
[fs_num_outputs
] = index
;
1036 outputMapping
[attr
] = fs_num_outputs
;
1045 ureg
= ureg_create_with_screen(PIPE_SHADER_FRAGMENT
, st
->pipe
->screen
);
1049 if (ST_DEBUG
& DEBUG_MESA
) {
1050 _mesa_print_program(&stfp
->Base
);
1051 _mesa_print_program_parameters(st
->ctx
, &stfp
->Base
);
1054 if (write_all
== GL_TRUE
)
1055 ureg_property(ureg
, TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
, 1);
1057 if (stfp
->Base
.info
.fs
.depth_layout
!= FRAG_DEPTH_LAYOUT_NONE
) {
1058 switch (stfp
->Base
.info
.fs
.depth_layout
) {
1059 case FRAG_DEPTH_LAYOUT_ANY
:
1060 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1061 TGSI_FS_DEPTH_LAYOUT_ANY
);
1063 case FRAG_DEPTH_LAYOUT_GREATER
:
1064 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1065 TGSI_FS_DEPTH_LAYOUT_GREATER
);
1067 case FRAG_DEPTH_LAYOUT_LESS
:
1068 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1069 TGSI_FS_DEPTH_LAYOUT_LESS
);
1071 case FRAG_DEPTH_LAYOUT_UNCHANGED
:
1072 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1073 TGSI_FS_DEPTH_LAYOUT_UNCHANGED
);
1080 if (stfp
->glsl_to_tgsi
) {
1081 st_translate_program(st
->ctx
,
1082 PIPE_SHADER_FRAGMENT
,
1090 input_semantic_name
,
1091 input_semantic_index
,
1096 fs_output_semantic_name
,
1097 fs_output_semantic_index
);
1099 free_glsl_to_tgsi_visitor(stfp
->glsl_to_tgsi
);
1100 } else if (stfp
->ati_fs
)
1101 st_translate_atifs_program(ureg
,
1107 input_semantic_name
,
1108 input_semantic_index
,
1113 fs_output_semantic_name
,
1114 fs_output_semantic_index
);
1116 st_translate_mesa_program(st
->ctx
,
1117 PIPE_SHADER_FRAGMENT
,
1123 input_semantic_name
,
1124 input_semantic_index
,
1129 fs_output_semantic_name
,
1130 fs_output_semantic_index
);
1132 stfp
->tgsi
.tokens
= ureg_get_tokens(ureg
, &stfp
->num_tgsi_tokens
);
1135 if (stfp
->glsl_to_tgsi
) {
1136 stfp
->glsl_to_tgsi
= NULL
;
1137 st_store_ir_in_disk_cache(st
, &stfp
->Base
, false);
1140 return stfp
->tgsi
.tokens
!= NULL
;
1143 static struct st_fp_variant
*
1144 st_create_fp_variant(struct st_context
*st
,
1145 struct st_fragment_program
*stfp
,
1146 const struct st_fp_variant_key
*key
)
1148 struct pipe_context
*pipe
= st
->pipe
;
1149 struct st_fp_variant
*variant
= CALLOC_STRUCT(st_fp_variant
);
1150 struct pipe_shader_state tgsi
= {0};
1151 struct gl_program_parameter_list
*params
= stfp
->Base
.Parameters
;
1152 static const gl_state_index16 texcoord_state
[STATE_LENGTH
] =
1153 { STATE_INTERNAL
, STATE_CURRENT_ATTRIB
, VERT_ATTRIB_TEX0
};
1154 static const gl_state_index16 scale_state
[STATE_LENGTH
] =
1155 { STATE_INTERNAL
, STATE_PT_SCALE
};
1156 static const gl_state_index16 bias_state
[STATE_LENGTH
] =
1157 { STATE_INTERNAL
, STATE_PT_BIAS
};
1162 if (stfp
->tgsi
.type
== PIPE_SHADER_IR_NIR
) {
1163 tgsi
.type
= PIPE_SHADER_IR_NIR
;
1164 tgsi
.ir
.nir
= nir_shader_clone(NULL
, stfp
->tgsi
.ir
.nir
);
1166 if (key
->clamp_color
)
1167 NIR_PASS_V(tgsi
.ir
.nir
, nir_lower_clamp_color_outputs
);
1169 if (key
->persample_shading
) {
1170 nir_shader
*shader
= tgsi
.ir
.nir
;
1171 nir_foreach_variable(var
, &shader
->inputs
)
1172 var
->data
.sample
= true;
1175 assert(!(key
->bitmap
&& key
->drawpixels
));
1179 nir_lower_bitmap_options options
= {0};
1181 variant
->bitmap_sampler
= ffs(~stfp
->Base
.SamplersUsed
) - 1;
1182 options
.sampler
= variant
->bitmap_sampler
;
1183 options
.swizzle_xxxx
= (st
->bitmap
.tex_format
== PIPE_FORMAT_L8_UNORM
);
1185 NIR_PASS_V(tgsi
.ir
.nir
, nir_lower_bitmap
, &options
);
1188 /* glDrawPixels (color only) */
1189 if (key
->drawpixels
) {
1190 nir_lower_drawpixels_options options
= {{0}};
1191 unsigned samplers_used
= stfp
->Base
.SamplersUsed
;
1193 /* Find the first unused slot. */
1194 variant
->drawpix_sampler
= ffs(~samplers_used
) - 1;
1195 options
.drawpix_sampler
= variant
->drawpix_sampler
;
1196 samplers_used
|= (1 << variant
->drawpix_sampler
);
1198 options
.pixel_maps
= key
->pixelMaps
;
1199 if (key
->pixelMaps
) {
1200 variant
->pixelmap_sampler
= ffs(~samplers_used
) - 1;
1201 options
.pixelmap_sampler
= variant
->pixelmap_sampler
;
1204 options
.scale_and_bias
= key
->scaleAndBias
;
1205 if (key
->scaleAndBias
) {
1206 _mesa_add_state_reference(params
, scale_state
);
1207 memcpy(options
.scale_state_tokens
, scale_state
,
1208 sizeof(options
.scale_state_tokens
));
1209 _mesa_add_state_reference(params
, bias_state
);
1210 memcpy(options
.bias_state_tokens
, bias_state
,
1211 sizeof(options
.bias_state_tokens
));
1214 _mesa_add_state_reference(params
, texcoord_state
);
1215 memcpy(options
.texcoord_state_tokens
, texcoord_state
,
1216 sizeof(options
.texcoord_state_tokens
));
1218 NIR_PASS_V(tgsi
.ir
.nir
, nir_lower_drawpixels
, &options
);
1221 if (unlikely(key
->external
.lower_nv12
|| key
->external
.lower_iyuv
||
1222 key
->external
.lower_xy_uxvx
|| key
->external
.lower_yx_xuxv
||
1223 key
->external
.lower_ayuv
|| key
->external
.lower_xyuv
)) {
1224 nir_lower_tex_options options
= {0};
1225 options
.lower_y_uv_external
= key
->external
.lower_nv12
;
1226 options
.lower_y_u_v_external
= key
->external
.lower_iyuv
;
1227 options
.lower_xy_uxvx_external
= key
->external
.lower_xy_uxvx
;
1228 options
.lower_yx_xuxv_external
= key
->external
.lower_yx_xuxv
;
1229 options
.lower_ayuv_external
= key
->external
.lower_ayuv
;
1230 options
.lower_xyuv_external
= key
->external
.lower_xyuv
;
1231 NIR_PASS_V(tgsi
.ir
.nir
, nir_lower_tex
, &options
);
1234 st_finalize_nir(st
, &stfp
->Base
, stfp
->shader_program
, tgsi
.ir
.nir
);
1236 if (unlikely(key
->external
.lower_nv12
|| key
->external
.lower_iyuv
||
1237 key
->external
.lower_xy_uxvx
|| key
->external
.lower_yx_xuxv
)) {
1238 /* This pass needs to happen *after* nir_lower_sampler */
1239 NIR_PASS_V(tgsi
.ir
.nir
, st_nir_lower_tex_src_plane
,
1240 ~stfp
->Base
.SamplersUsed
,
1241 key
->external
.lower_nv12
|| key
->external
.lower_xy_uxvx
||
1242 key
->external
.lower_yx_xuxv
,
1243 key
->external
.lower_iyuv
);
1246 /* Some of the lowering above may have introduced new varyings */
1247 nir_shader_gather_info(tgsi
.ir
.nir
,
1248 nir_shader_get_entrypoint(tgsi
.ir
.nir
));
1250 variant
->driver_shader
= pipe
->create_fs_state(pipe
, &tgsi
);
1251 variant
->key
= *key
;
1256 tgsi
.tokens
= stfp
->tgsi
.tokens
;
1258 assert(!(key
->bitmap
&& key
->drawpixels
));
1260 /* Fix texture targets and add fog for ATI_fs */
1262 const struct tgsi_token
*tokens
= st_fixup_atifs(tgsi
.tokens
, key
);
1265 tgsi
.tokens
= tokens
;
1267 fprintf(stderr
, "mesa: cannot post-process ATI_fs\n");
1270 /* Emulate features. */
1271 if (key
->clamp_color
|| key
->persample_shading
) {
1272 const struct tgsi_token
*tokens
;
1274 (key
->clamp_color
? TGSI_EMU_CLAMP_COLOR_OUTPUTS
: 0) |
1275 (key
->persample_shading
? TGSI_EMU_FORCE_PERSAMPLE_INTERP
: 0);
1277 tokens
= tgsi_emulate(tgsi
.tokens
, flags
);
1280 if (tgsi
.tokens
!= stfp
->tgsi
.tokens
)
1281 tgsi_free_tokens(tgsi
.tokens
);
1282 tgsi
.tokens
= tokens
;
1284 fprintf(stderr
, "mesa: cannot emulate deprecated features\n");
1289 const struct tgsi_token
*tokens
;
1291 variant
->bitmap_sampler
= ffs(~stfp
->Base
.SamplersUsed
) - 1;
1293 tokens
= st_get_bitmap_shader(tgsi
.tokens
,
1294 st
->internal_target
,
1295 variant
->bitmap_sampler
,
1296 st
->needs_texcoord_semantic
,
1297 st
->bitmap
.tex_format
==
1298 PIPE_FORMAT_L8_UNORM
);
1301 if (tgsi
.tokens
!= stfp
->tgsi
.tokens
)
1302 tgsi_free_tokens(tgsi
.tokens
);
1303 tgsi
.tokens
= tokens
;
1305 fprintf(stderr
, "mesa: cannot create a shader for glBitmap\n");
1308 /* glDrawPixels (color only) */
1309 if (key
->drawpixels
) {
1310 const struct tgsi_token
*tokens
;
1311 unsigned scale_const
= 0, bias_const
= 0, texcoord_const
= 0;
1313 /* Find the first unused slot. */
1314 variant
->drawpix_sampler
= ffs(~stfp
->Base
.SamplersUsed
) - 1;
1316 if (key
->pixelMaps
) {
1317 unsigned samplers_used
= stfp
->Base
.SamplersUsed
|
1318 (1 << variant
->drawpix_sampler
);
1320 variant
->pixelmap_sampler
= ffs(~samplers_used
) - 1;
1323 if (key
->scaleAndBias
) {
1324 scale_const
= _mesa_add_state_reference(params
, scale_state
);
1325 bias_const
= _mesa_add_state_reference(params
, bias_state
);
1328 texcoord_const
= _mesa_add_state_reference(params
, texcoord_state
);
1330 tokens
= st_get_drawpix_shader(tgsi
.tokens
,
1331 st
->needs_texcoord_semantic
,
1332 key
->scaleAndBias
, scale_const
,
1333 bias_const
, key
->pixelMaps
,
1334 variant
->drawpix_sampler
,
1335 variant
->pixelmap_sampler
,
1336 texcoord_const
, st
->internal_target
);
1339 if (tgsi
.tokens
!= stfp
->tgsi
.tokens
)
1340 tgsi_free_tokens(tgsi
.tokens
);
1341 tgsi
.tokens
= tokens
;
1343 fprintf(stderr
, "mesa: cannot create a shader for glDrawPixels\n");
1346 if (unlikely(key
->external
.lower_nv12
|| key
->external
.lower_iyuv
||
1347 key
->external
.lower_xy_uxvx
|| key
->external
.lower_yx_xuxv
)) {
1348 const struct tgsi_token
*tokens
;
1350 /* samplers inserted would conflict, but this should be unpossible: */
1351 assert(!(key
->bitmap
|| key
->drawpixels
));
1353 tokens
= st_tgsi_lower_yuv(tgsi
.tokens
,
1354 ~stfp
->Base
.SamplersUsed
,
1355 key
->external
.lower_nv12
||
1356 key
->external
.lower_xy_uxvx
||
1357 key
->external
.lower_yx_xuxv
,
1358 key
->external
.lower_iyuv
);
1360 if (tgsi
.tokens
!= stfp
->tgsi
.tokens
)
1361 tgsi_free_tokens(tgsi
.tokens
);
1362 tgsi
.tokens
= tokens
;
1364 fprintf(stderr
, "mesa: cannot create a shader for samplerExternalOES\n");
1368 if (key
->lower_depth_clamp
) {
1369 unsigned depth_range_const
= _mesa_add_state_reference(params
, depth_range_state
);
1371 const struct tgsi_token
*tokens
;
1372 tokens
= st_tgsi_lower_depth_clamp_fs(tgsi
.tokens
, depth_range_const
);
1373 if (tgsi
.tokens
!= stfp
->tgsi
.tokens
)
1374 tgsi_free_tokens(tgsi
.tokens
);
1375 tgsi
.tokens
= tokens
;
1378 if (ST_DEBUG
& DEBUG_TGSI
) {
1379 tgsi_dump(tgsi
.tokens
, 0);
1383 /* fill in variant */
1384 variant
->driver_shader
= pipe
->create_fs_state(pipe
, &tgsi
);
1385 variant
->key
= *key
;
1387 if (tgsi
.tokens
!= stfp
->tgsi
.tokens
)
1388 tgsi_free_tokens(tgsi
.tokens
);
1393 * Translate fragment program if needed.
1395 struct st_fp_variant
*
1396 st_get_fp_variant(struct st_context
*st
,
1397 struct st_fragment_program
*stfp
,
1398 const struct st_fp_variant_key
*key
)
1400 struct st_fp_variant
*fpv
;
1402 /* Search for existing variant */
1403 for (fpv
= stfp
->variants
; fpv
; fpv
= fpv
->next
) {
1404 if (memcmp(&fpv
->key
, key
, sizeof(*key
)) == 0) {
1411 fpv
= st_create_fp_variant(st
, stfp
, key
);
1413 if (key
->bitmap
|| key
->drawpixels
) {
1414 /* Regular variants should always come before the
1415 * bitmap & drawpixels variants, (unless there
1416 * are no regular variants) so that
1417 * st_update_fp can take a fast path when
1418 * shader_has_one_variant is set.
1420 if (!stfp
->variants
) {
1421 stfp
->variants
= fpv
;
1423 /* insert into list after the first one */
1424 fpv
->next
= stfp
->variants
->next
;
1425 stfp
->variants
->next
= fpv
;
1428 /* insert into list */
1429 fpv
->next
= stfp
->variants
;
1430 stfp
->variants
= fpv
;
1440 * Translate a program. This is common code for geometry and tessellation
1444 st_translate_program_common(struct st_context
*st
,
1445 struct gl_program
*prog
,
1446 struct glsl_to_tgsi_visitor
*glsl_to_tgsi
,
1447 struct ureg_program
*ureg
,
1448 unsigned tgsi_processor
,
1449 struct pipe_shader_state
*out_state
)
1451 ubyte inputSlotToAttr
[VARYING_SLOT_TESS_MAX
];
1452 ubyte inputMapping
[VARYING_SLOT_TESS_MAX
];
1453 ubyte outputMapping
[VARYING_SLOT_TESS_MAX
];
1456 ubyte input_semantic_name
[PIPE_MAX_SHADER_INPUTS
];
1457 ubyte input_semantic_index
[PIPE_MAX_SHADER_INPUTS
];
1458 uint num_inputs
= 0;
1460 ubyte output_semantic_name
[PIPE_MAX_SHADER_OUTPUTS
];
1461 ubyte output_semantic_index
[PIPE_MAX_SHADER_OUTPUTS
];
1462 uint num_outputs
= 0;
1466 memset(inputSlotToAttr
, 0, sizeof(inputSlotToAttr
));
1467 memset(inputMapping
, 0, sizeof(inputMapping
));
1468 memset(outputMapping
, 0, sizeof(outputMapping
));
1469 memset(out_state
, 0, sizeof(*out_state
));
1471 if (prog
->info
.clip_distance_array_size
)
1472 ureg_property(ureg
, TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
,
1473 prog
->info
.clip_distance_array_size
);
1474 if (prog
->info
.cull_distance_array_size
)
1475 ureg_property(ureg
, TGSI_PROPERTY_NUM_CULLDIST_ENABLED
,
1476 prog
->info
.cull_distance_array_size
);
1479 * Convert Mesa program inputs to TGSI input register semantics.
1481 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
1482 if ((prog
->info
.inputs_read
& BITFIELD64_BIT(attr
)) == 0)
1485 unsigned slot
= num_inputs
++;
1487 inputMapping
[attr
] = slot
;
1488 inputSlotToAttr
[slot
] = attr
;
1490 unsigned semantic_name
, semantic_index
;
1491 tgsi_get_gl_varying_semantic(attr
, st
->needs_texcoord_semantic
,
1492 &semantic_name
, &semantic_index
);
1493 input_semantic_name
[slot
] = semantic_name
;
1494 input_semantic_index
[slot
] = semantic_index
;
1497 /* Also add patch inputs. */
1498 for (attr
= 0; attr
< 32; attr
++) {
1499 if (prog
->info
.patch_inputs_read
& (1u << attr
)) {
1500 GLuint slot
= num_inputs
++;
1501 GLuint patch_attr
= VARYING_SLOT_PATCH0
+ attr
;
1503 inputMapping
[patch_attr
] = slot
;
1504 inputSlotToAttr
[slot
] = patch_attr
;
1505 input_semantic_name
[slot
] = TGSI_SEMANTIC_PATCH
;
1506 input_semantic_index
[slot
] = attr
;
1510 /* initialize output semantics to defaults */
1511 for (i
= 0; i
< PIPE_MAX_SHADER_OUTPUTS
; i
++) {
1512 output_semantic_name
[i
] = TGSI_SEMANTIC_GENERIC
;
1513 output_semantic_index
[i
] = 0;
1517 * Determine number of outputs, the (default) output register
1518 * mapping and the semantic information for each output.
1520 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
1521 if (prog
->info
.outputs_written
& BITFIELD64_BIT(attr
)) {
1522 GLuint slot
= num_outputs
++;
1524 outputMapping
[attr
] = slot
;
1526 unsigned semantic_name
, semantic_index
;
1527 tgsi_get_gl_varying_semantic(attr
, st
->needs_texcoord_semantic
,
1528 &semantic_name
, &semantic_index
);
1529 output_semantic_name
[slot
] = semantic_name
;
1530 output_semantic_index
[slot
] = semantic_index
;
1534 /* Also add patch outputs. */
1535 for (attr
= 0; attr
< 32; attr
++) {
1536 if (prog
->info
.patch_outputs_written
& (1u << attr
)) {
1537 GLuint slot
= num_outputs
++;
1538 GLuint patch_attr
= VARYING_SLOT_PATCH0
+ attr
;
1540 outputMapping
[patch_attr
] = slot
;
1541 output_semantic_name
[slot
] = TGSI_SEMANTIC_PATCH
;
1542 output_semantic_index
[slot
] = attr
;
1546 st_translate_program(st
->ctx
,
1555 input_semantic_name
,
1556 input_semantic_index
,
1561 output_semantic_name
,
1562 output_semantic_index
);
1564 if (tgsi_processor
== PIPE_SHADER_COMPUTE
) {
1565 struct st_compute_program
*stcp
= (struct st_compute_program
*) prog
;
1566 out_state
->tokens
= ureg_get_tokens(ureg
, &stcp
->num_tgsi_tokens
);
1567 stcp
->tgsi
.prog
= out_state
->tokens
;
1569 struct st_common_program
*stcp
= (struct st_common_program
*) prog
;
1570 out_state
->tokens
= ureg_get_tokens(ureg
, &stcp
->num_tgsi_tokens
);
1574 st_translate_stream_output_info(prog
->sh
.LinkedTransformFeedback
,
1576 &out_state
->stream_output
);
1578 st_store_ir_in_disk_cache(st
, prog
, false);
1580 if ((ST_DEBUG
& DEBUG_TGSI
) && (ST_DEBUG
& DEBUG_MESA
)) {
1581 _mesa_print_program(prog
);
1585 if (ST_DEBUG
& DEBUG_TGSI
) {
1586 tgsi_dump(out_state
->tokens
, 0);
1592 * Update stream-output info for GS/TCS/TES. Normally this is done in
1593 * st_translate_program_common() but that is not called for glsl_to_nir
1597 st_translate_program_stream_output(struct gl_program
*prog
,
1598 struct pipe_stream_output_info
*stream_output
)
1600 if (!prog
->sh
.LinkedTransformFeedback
)
1603 ubyte outputMapping
[VARYING_SLOT_TESS_MAX
];
1605 uint num_outputs
= 0;
1607 memset(outputMapping
, 0, sizeof(outputMapping
));
1610 * Determine number of outputs, the (default) output register
1611 * mapping and the semantic information for each output.
1613 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
1614 if (prog
->info
.outputs_written
& BITFIELD64_BIT(attr
)) {
1615 GLuint slot
= num_outputs
++;
1617 outputMapping
[attr
] = slot
;
1621 st_translate_stream_output_info(prog
->sh
.LinkedTransformFeedback
,
1627 * Translate a geometry program to create a new variant.
1630 st_translate_geometry_program(struct st_context
*st
,
1631 struct st_common_program
*stgp
)
1633 struct ureg_program
*ureg
;
1635 /* We have already compiled to NIR so just return */
1636 if (stgp
->shader_program
) {
1638 st_finalize_nir(st
, &stgp
->Base
, stgp
->shader_program
,
1640 st_translate_program_stream_output(&stgp
->Base
, &stgp
->tgsi
.stream_output
);
1641 st_store_ir_in_disk_cache(st
, &stgp
->Base
, true);
1645 ureg
= ureg_create_with_screen(PIPE_SHADER_GEOMETRY
, st
->pipe
->screen
);
1649 ureg_property(ureg
, TGSI_PROPERTY_GS_INPUT_PRIM
,
1650 stgp
->Base
.info
.gs
.input_primitive
);
1651 ureg_property(ureg
, TGSI_PROPERTY_GS_OUTPUT_PRIM
,
1652 stgp
->Base
.info
.gs
.output_primitive
);
1653 ureg_property(ureg
, TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
,
1654 stgp
->Base
.info
.gs
.vertices_out
);
1655 ureg_property(ureg
, TGSI_PROPERTY_GS_INVOCATIONS
,
1656 stgp
->Base
.info
.gs
.invocations
);
1658 st_translate_program_common(st
, &stgp
->Base
, stgp
->glsl_to_tgsi
, ureg
,
1659 PIPE_SHADER_GEOMETRY
, &stgp
->tgsi
);
1661 free_glsl_to_tgsi_visitor(stgp
->glsl_to_tgsi
);
1662 stgp
->glsl_to_tgsi
= NULL
;
1668 * Get/create a basic program variant.
1670 struct st_basic_variant
*
1671 st_get_basic_variant(struct st_context
*st
,
1672 unsigned pipe_shader
,
1673 struct st_common_program
*prog
,
1674 const struct st_basic_variant_key
*key
)
1676 struct pipe_context
*pipe
= st
->pipe
;
1677 struct st_basic_variant
*v
;
1678 struct pipe_shader_state tgsi
= {0};
1680 /* Search for existing variant */
1681 for (v
= prog
->variants
; v
; v
= v
->next
) {
1682 if (memcmp(&v
->key
, key
, sizeof(*key
)) == 0) {
1689 v
= CALLOC_STRUCT(st_basic_variant
);
1692 if (prog
->tgsi
.type
== PIPE_SHADER_IR_NIR
) {
1693 tgsi
.type
= PIPE_SHADER_IR_NIR
;
1694 tgsi
.ir
.nir
= nir_shader_clone(NULL
, prog
->tgsi
.ir
.nir
);
1696 if (key
->clamp_color
)
1697 NIR_PASS_V(tgsi
.ir
.nir
, nir_lower_clamp_color_outputs
);
1699 tgsi
.stream_output
= prog
->tgsi
.stream_output
;
1701 if (key
->lower_depth_clamp
) {
1702 struct gl_program_parameter_list
*params
= prog
->Base
.Parameters
;
1704 unsigned depth_range_const
=
1705 _mesa_add_state_reference(params
, depth_range_state
);
1707 const struct tgsi_token
*tokens
;
1709 st_tgsi_lower_depth_clamp(prog
->tgsi
.tokens
,
1711 key
->clip_negative_one_to_one
);
1713 if (tokens
!= prog
->tgsi
.tokens
)
1714 tgsi_free_tokens(prog
->tgsi
.tokens
);
1716 prog
->tgsi
.tokens
= tokens
;
1717 prog
->num_tgsi_tokens
= tgsi_num_tokens(tokens
);
1721 /* fill in new variant */
1722 switch (pipe_shader
) {
1723 case PIPE_SHADER_TESS_CTRL
:
1724 v
->driver_shader
= pipe
->create_tcs_state(pipe
, &tgsi
);
1726 case PIPE_SHADER_TESS_EVAL
:
1727 v
->driver_shader
= pipe
->create_tes_state(pipe
, &tgsi
);
1729 case PIPE_SHADER_GEOMETRY
:
1730 v
->driver_shader
= pipe
->create_gs_state(pipe
, &tgsi
);
1733 assert(!"unhandled shader type");
1740 /* insert into list */
1741 v
->next
= prog
->variants
;
1751 * Translate a tessellation control program to create a new variant.
1754 st_translate_tessctrl_program(struct st_context
*st
,
1755 struct st_common_program
*sttcp
)
1757 struct ureg_program
*ureg
;
1759 /* We have already compiled to NIR so just return */
1760 if (sttcp
->shader_program
) {
1762 st_finalize_nir(st
, &sttcp
->Base
, sttcp
->shader_program
,
1763 sttcp
->tgsi
.ir
.nir
);
1764 st_store_ir_in_disk_cache(st
, &sttcp
->Base
, true);
1768 ureg
= ureg_create_with_screen(PIPE_SHADER_TESS_CTRL
, st
->pipe
->screen
);
1772 ureg_property(ureg
, TGSI_PROPERTY_TCS_VERTICES_OUT
,
1773 sttcp
->Base
.info
.tess
.tcs_vertices_out
);
1775 st_translate_program_common(st
, &sttcp
->Base
, sttcp
->glsl_to_tgsi
, ureg
,
1776 PIPE_SHADER_TESS_CTRL
, &sttcp
->tgsi
);
1778 free_glsl_to_tgsi_visitor(sttcp
->glsl_to_tgsi
);
1779 sttcp
->glsl_to_tgsi
= NULL
;
1785 * Translate a tessellation evaluation program to create a new variant.
1788 st_translate_tesseval_program(struct st_context
*st
,
1789 struct st_common_program
*sttep
)
1791 struct ureg_program
*ureg
;
1793 /* We have already compiled to NIR so just return */
1794 if (sttep
->shader_program
) {
1796 st_finalize_nir(st
, &sttep
->Base
, sttep
->shader_program
,
1797 sttep
->tgsi
.ir
.nir
);
1798 st_translate_program_stream_output(&sttep
->Base
, &sttep
->tgsi
.stream_output
);
1799 st_store_ir_in_disk_cache(st
, &sttep
->Base
, true);
1803 ureg
= ureg_create_with_screen(PIPE_SHADER_TESS_EVAL
, st
->pipe
->screen
);
1807 if (sttep
->Base
.info
.tess
.primitive_mode
== GL_ISOLINES
)
1808 ureg_property(ureg
, TGSI_PROPERTY_TES_PRIM_MODE
, GL_LINES
);
1810 ureg_property(ureg
, TGSI_PROPERTY_TES_PRIM_MODE
,
1811 sttep
->Base
.info
.tess
.primitive_mode
);
1813 STATIC_ASSERT((TESS_SPACING_EQUAL
+ 1) % 3 == PIPE_TESS_SPACING_EQUAL
);
1814 STATIC_ASSERT((TESS_SPACING_FRACTIONAL_ODD
+ 1) % 3 ==
1815 PIPE_TESS_SPACING_FRACTIONAL_ODD
);
1816 STATIC_ASSERT((TESS_SPACING_FRACTIONAL_EVEN
+ 1) % 3 ==
1817 PIPE_TESS_SPACING_FRACTIONAL_EVEN
);
1819 ureg_property(ureg
, TGSI_PROPERTY_TES_SPACING
,
1820 (sttep
->Base
.info
.tess
.spacing
+ 1) % 3);
1822 ureg_property(ureg
, TGSI_PROPERTY_TES_VERTEX_ORDER_CW
,
1823 !sttep
->Base
.info
.tess
.ccw
);
1824 ureg_property(ureg
, TGSI_PROPERTY_TES_POINT_MODE
,
1825 sttep
->Base
.info
.tess
.point_mode
);
1827 st_translate_program_common(st
, &sttep
->Base
, sttep
->glsl_to_tgsi
,
1828 ureg
, PIPE_SHADER_TESS_EVAL
, &sttep
->tgsi
);
1830 free_glsl_to_tgsi_visitor(sttep
->glsl_to_tgsi
);
1831 sttep
->glsl_to_tgsi
= NULL
;
1837 * Translate a compute program to create a new variant.
1840 st_translate_compute_program(struct st_context
*st
,
1841 struct st_compute_program
*stcp
)
1843 struct ureg_program
*ureg
;
1844 struct pipe_shader_state prog
;
1846 stcp
->tgsi
.req_local_mem
= stcp
->Base
.info
.cs
.shared_size
;
1848 if (stcp
->shader_program
) {
1849 /* no compute variants: */
1850 st_finalize_nir(st
, &stcp
->Base
, stcp
->shader_program
,
1851 (struct nir_shader
*) stcp
->tgsi
.prog
);
1852 st_store_ir_in_disk_cache(st
, &stcp
->Base
, true);
1856 ureg
= ureg_create_with_screen(PIPE_SHADER_COMPUTE
, st
->pipe
->screen
);
1860 st_translate_program_common(st
, &stcp
->Base
, stcp
->glsl_to_tgsi
, ureg
,
1861 PIPE_SHADER_COMPUTE
, &prog
);
1863 stcp
->tgsi
.ir_type
= PIPE_SHADER_IR_TGSI
;
1864 stcp
->tgsi
.req_private_mem
= 0;
1865 stcp
->tgsi
.req_input_mem
= 0;
1867 free_glsl_to_tgsi_visitor(stcp
->glsl_to_tgsi
);
1868 stcp
->glsl_to_tgsi
= NULL
;
1874 * Get/create compute program variant.
1876 struct st_basic_variant
*
1877 st_get_cp_variant(struct st_context
*st
,
1878 struct pipe_compute_state
*tgsi
,
1879 struct st_basic_variant
**variants
)
1881 struct pipe_context
*pipe
= st
->pipe
;
1882 struct st_basic_variant
*v
;
1883 struct st_basic_variant_key key
;
1885 /* use memset, not an initializer to be sure all memory is zeroed */
1886 memset(&key
, 0, sizeof(key
));
1888 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
1890 /* Search for existing variant */
1891 for (v
= *variants
; v
; v
= v
->next
) {
1892 if (memcmp(&v
->key
, &key
, sizeof(key
)) == 0) {
1899 v
= CALLOC_STRUCT(st_basic_variant
);
1901 /* fill in new variant */
1902 struct pipe_compute_state cs
= *tgsi
;
1903 if (tgsi
->ir_type
== PIPE_SHADER_IR_NIR
)
1904 cs
.prog
= nir_shader_clone(NULL
, tgsi
->prog
);
1905 v
->driver_shader
= pipe
->create_compute_state(pipe
, &cs
);
1908 /* insert into list */
1909 v
->next
= *variants
;
1919 * Vert/Geom/Frag programs have per-context variants. Free all the
1920 * variants attached to the given program which match the given context.
1923 destroy_program_variants(struct st_context
*st
, struct gl_program
*target
)
1925 if (!target
|| target
== &_mesa_DummyProgram
)
1928 switch (target
->Target
) {
1929 case GL_VERTEX_PROGRAM_ARB
:
1931 struct st_vertex_program
*stvp
= (struct st_vertex_program
*) target
;
1932 struct st_vp_variant
*vpv
, **prevPtr
= &stvp
->variants
;
1934 for (vpv
= stvp
->variants
; vpv
; ) {
1935 struct st_vp_variant
*next
= vpv
->next
;
1936 if (vpv
->key
.st
== st
) {
1937 /* unlink from list */
1939 /* destroy this variant */
1940 delete_vp_variant(st
, vpv
);
1943 prevPtr
= &vpv
->next
;
1949 case GL_FRAGMENT_PROGRAM_ARB
:
1951 struct st_fragment_program
*stfp
=
1952 (struct st_fragment_program
*) target
;
1953 struct st_fp_variant
*fpv
, **prevPtr
= &stfp
->variants
;
1955 for (fpv
= stfp
->variants
; fpv
; ) {
1956 struct st_fp_variant
*next
= fpv
->next
;
1957 if (fpv
->key
.st
== st
) {
1958 /* unlink from list */
1960 /* destroy this variant */
1961 delete_fp_variant(st
, fpv
);
1964 prevPtr
= &fpv
->next
;
1970 case GL_GEOMETRY_PROGRAM_NV
:
1971 case GL_TESS_CONTROL_PROGRAM_NV
:
1972 case GL_TESS_EVALUATION_PROGRAM_NV
:
1973 case GL_COMPUTE_PROGRAM_NV
:
1975 struct st_common_program
*p
= st_common_program(target
);
1976 struct st_compute_program
*cp
= (struct st_compute_program
*)target
;
1977 struct st_basic_variant
**variants
=
1978 target
->Target
== GL_COMPUTE_PROGRAM_NV
? &cp
->variants
:
1980 struct st_basic_variant
*v
, **prevPtr
= variants
;
1982 for (v
= *variants
; v
; ) {
1983 struct st_basic_variant
*next
= v
->next
;
1984 if (v
->key
.st
== st
) {
1985 /* unlink from list */
1987 /* destroy this variant */
1988 delete_basic_variant(st
, v
, target
->Target
);
1998 _mesa_problem(NULL
, "Unexpected program target 0x%x in "
1999 "destroy_program_variants_cb()", target
->Target
);
2005 * Callback for _mesa_HashWalk. Free all the shader's program variants
2006 * which match the given context.
2009 destroy_shader_program_variants_cb(GLuint key
, void *data
, void *userData
)
2011 struct st_context
*st
= (struct st_context
*) userData
;
2012 struct gl_shader
*shader
= (struct gl_shader
*) data
;
2014 switch (shader
->Type
) {
2015 case GL_SHADER_PROGRAM_MESA
:
2017 struct gl_shader_program
*shProg
= (struct gl_shader_program
*) data
;
2020 for (i
= 0; i
< ARRAY_SIZE(shProg
->_LinkedShaders
); i
++) {
2021 if (shProg
->_LinkedShaders
[i
])
2022 destroy_program_variants(st
, shProg
->_LinkedShaders
[i
]->Program
);
2026 case GL_VERTEX_SHADER
:
2027 case GL_FRAGMENT_SHADER
:
2028 case GL_GEOMETRY_SHADER
:
2029 case GL_TESS_CONTROL_SHADER
:
2030 case GL_TESS_EVALUATION_SHADER
:
2031 case GL_COMPUTE_SHADER
:
2040 * Callback for _mesa_HashWalk. Free all the program variants which match
2041 * the given context.
2044 destroy_program_variants_cb(GLuint key
, void *data
, void *userData
)
2046 struct st_context
*st
= (struct st_context
*) userData
;
2047 struct gl_program
*program
= (struct gl_program
*) data
;
2048 destroy_program_variants(st
, program
);
2053 * Walk over all shaders and programs to delete any variants which
2054 * belong to the given context.
2055 * This is called during context tear-down.
2058 st_destroy_program_variants(struct st_context
*st
)
2060 /* If shaders can be shared with other contexts, the last context will
2061 * call DeleteProgram on all shaders, releasing everything.
2063 if (st
->has_shareable_shaders
)
2066 /* ARB vert/frag program */
2067 _mesa_HashWalk(st
->ctx
->Shared
->Programs
,
2068 destroy_program_variants_cb
, st
);
2070 /* GLSL vert/frag/geom shaders */
2071 _mesa_HashWalk(st
->ctx
->Shared
->ShaderObjects
,
2072 destroy_shader_program_variants_cb
, st
);
2077 * For debugging, print/dump the current vertex program.
2080 st_print_current_vertex_program(void)
2082 GET_CURRENT_CONTEXT(ctx
);
2084 if (ctx
->VertexProgram
._Current
) {
2085 struct st_vertex_program
*stvp
=
2086 (struct st_vertex_program
*) ctx
->VertexProgram
._Current
;
2087 struct st_vp_variant
*stv
;
2089 debug_printf("Vertex program %u\n", stvp
->Base
.Id
);
2091 for (stv
= stvp
->variants
; stv
; stv
= stv
->next
) {
2092 debug_printf("variant %p\n", stv
);
2093 tgsi_dump(stv
->tgsi
.tokens
, 0);
2100 * Compile one shader variant.
2103 st_precompile_shader_variant(struct st_context
*st
,
2104 struct gl_program
*prog
)
2106 switch (prog
->Target
) {
2107 case GL_VERTEX_PROGRAM_ARB
: {
2108 struct st_vertex_program
*p
= (struct st_vertex_program
*)prog
;
2109 struct st_vp_variant_key key
;
2111 memset(&key
, 0, sizeof(key
));
2113 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2114 st_get_vp_variant(st
, p
, &key
);
2118 case GL_TESS_CONTROL_PROGRAM_NV
: {
2119 struct st_common_program
*p
= st_common_program(prog
);
2120 struct st_basic_variant_key key
;
2122 memset(&key
, 0, sizeof(key
));
2124 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2125 st_get_basic_variant(st
, PIPE_SHADER_TESS_CTRL
, p
, &key
);
2129 case GL_TESS_EVALUATION_PROGRAM_NV
: {
2130 struct st_common_program
*p
= st_common_program(prog
);
2131 struct st_basic_variant_key key
;
2133 memset(&key
, 0, sizeof(key
));
2135 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2136 st_get_basic_variant(st
, PIPE_SHADER_TESS_EVAL
, p
, &key
);
2140 case GL_GEOMETRY_PROGRAM_NV
: {
2141 struct st_common_program
*p
= st_common_program(prog
);
2142 struct st_basic_variant_key key
;
2144 memset(&key
, 0, sizeof(key
));
2146 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2147 st_get_basic_variant(st
, PIPE_SHADER_GEOMETRY
, p
, &key
);
2151 case GL_FRAGMENT_PROGRAM_ARB
: {
2152 struct st_fragment_program
*p
= (struct st_fragment_program
*)prog
;
2153 struct st_fp_variant_key key
;
2155 memset(&key
, 0, sizeof(key
));
2157 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2158 st_get_fp_variant(st
, p
, &key
);
2162 case GL_COMPUTE_PROGRAM_NV
: {
2163 struct st_compute_program
*p
= (struct st_compute_program
*)prog
;
2164 st_get_cp_variant(st
, &p
->tgsi
, &p
->variants
);