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"
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"
44 #include "compiler/nir/nir_serialize.h"
45 #include "draw/draw_context.h"
47 #include "pipe/p_context.h"
48 #include "pipe/p_defines.h"
49 #include "pipe/p_shader_tokens.h"
50 #include "draw/draw_context.h"
51 #include "tgsi/tgsi_dump.h"
52 #include "tgsi/tgsi_emulate.h"
53 #include "tgsi/tgsi_parse.h"
54 #include "tgsi/tgsi_ureg.h"
56 #include "util/u_memory.h"
59 #include "st_cb_bitmap.h"
60 #include "st_cb_drawpixels.h"
61 #include "st_context.h"
62 #include "st_tgsi_lower_depth_clamp.h"
63 #include "st_tgsi_lower_yuv.h"
64 #include "st_program.h"
65 #include "st_mesa_to_tgsi.h"
66 #include "st_atifs_to_tgsi.h"
68 #include "st_shader_cache.h"
70 #include "cso_cache/cso_context.h"
74 destroy_program_variants(struct st_context
*st
, struct gl_program
*target
);
77 set_affected_state_flags(uint64_t *states
,
78 struct gl_program
*prog
,
79 uint64_t new_constants
,
80 uint64_t new_sampler_views
,
81 uint64_t new_samplers
,
87 if (prog
->Parameters
->NumParameters
)
88 *states
|= new_constants
;
90 if (prog
->info
.num_textures
)
91 *states
|= new_sampler_views
| new_samplers
;
93 if (prog
->info
.num_images
)
94 *states
|= new_images
;
96 if (prog
->info
.num_ubos
)
99 if (prog
->info
.num_ssbos
)
100 *states
|= new_ssbos
;
102 if (prog
->info
.num_abos
)
103 *states
|= new_atomics
;
107 * This determines which states will be updated when the shader is bound.
110 st_set_prog_affected_state_flags(struct gl_program
*prog
)
114 switch (prog
->info
.stage
) {
115 case MESA_SHADER_VERTEX
:
116 states
= &((struct st_program
*)prog
)->affected_states
;
118 *states
= ST_NEW_VS_STATE
|
120 ST_NEW_VERTEX_ARRAYS
;
122 set_affected_state_flags(states
, prog
,
124 ST_NEW_VS_SAMPLER_VIEWS
,
132 case MESA_SHADER_TESS_CTRL
:
133 states
= &(st_program(prog
))->affected_states
;
135 *states
= ST_NEW_TCS_STATE
;
137 set_affected_state_flags(states
, prog
,
138 ST_NEW_TCS_CONSTANTS
,
139 ST_NEW_TCS_SAMPLER_VIEWS
,
147 case MESA_SHADER_TESS_EVAL
:
148 states
= &(st_program(prog
))->affected_states
;
150 *states
= ST_NEW_TES_STATE
|
153 set_affected_state_flags(states
, prog
,
154 ST_NEW_TES_CONSTANTS
,
155 ST_NEW_TES_SAMPLER_VIEWS
,
163 case MESA_SHADER_GEOMETRY
:
164 states
= &(st_program(prog
))->affected_states
;
166 *states
= ST_NEW_GS_STATE
|
169 set_affected_state_flags(states
, prog
,
171 ST_NEW_GS_SAMPLER_VIEWS
,
179 case MESA_SHADER_FRAGMENT
:
180 states
= &((struct st_program
*)prog
)->affected_states
;
182 /* gl_FragCoord and glDrawPixels always use constants. */
183 *states
= ST_NEW_FS_STATE
|
184 ST_NEW_SAMPLE_SHADING
|
187 set_affected_state_flags(states
, prog
,
189 ST_NEW_FS_SAMPLER_VIEWS
,
197 case MESA_SHADER_COMPUTE
:
198 states
= &((struct st_program
*)prog
)->affected_states
;
200 *states
= ST_NEW_CS_STATE
;
202 set_affected_state_flags(states
, prog
,
204 ST_NEW_CS_SAMPLER_VIEWS
,
213 unreachable("unhandled shader stage");
219 * Delete a shader variant. Note the caller must unlink the variant from
223 delete_variant(struct st_context
*st
, struct st_variant
*v
, GLenum target
)
225 if (v
->driver_shader
) {
226 if (target
== GL_VERTEX_PROGRAM_ARB
&&
227 ((struct st_common_variant
*)v
)->key
.is_draw_shader
) {
229 draw_delete_vertex_shader(st
->draw
, v
->driver_shader
);
230 } else if (st
->has_shareable_shaders
|| v
->st
== st
) {
231 /* The shader's context matches the calling context, or we
235 case GL_VERTEX_PROGRAM_ARB
:
236 st
->pipe
->delete_vs_state(st
->pipe
, v
->driver_shader
);
238 case GL_TESS_CONTROL_PROGRAM_NV
:
239 st
->pipe
->delete_tcs_state(st
->pipe
, v
->driver_shader
);
241 case GL_TESS_EVALUATION_PROGRAM_NV
:
242 st
->pipe
->delete_tes_state(st
->pipe
, v
->driver_shader
);
244 case GL_GEOMETRY_PROGRAM_NV
:
245 st
->pipe
->delete_gs_state(st
->pipe
, v
->driver_shader
);
247 case GL_FRAGMENT_PROGRAM_ARB
:
248 st
->pipe
->delete_fs_state(st
->pipe
, v
->driver_shader
);
250 case GL_COMPUTE_PROGRAM_NV
:
251 st
->pipe
->delete_compute_state(st
->pipe
, v
->driver_shader
);
254 unreachable("bad shader type in delete_basic_variant");
257 /* We can't delete a shader with a context different from the one
258 * that created it. Add it to the creating context's zombie list.
260 enum pipe_shader_type type
=
261 pipe_shader_type_from_mesa(_mesa_program_enum_to_shader_stage(target
));
263 st_save_zombie_shader(v
->st
, type
, v
->driver_shader
);
271 st_unbind_program(struct st_context
*st
, struct st_program
*p
)
273 /* Unbind the shader in cso_context and re-bind in st/mesa. */
274 switch (p
->Base
.info
.stage
) {
275 case MESA_SHADER_VERTEX
:
276 cso_set_vertex_shader_handle(st
->cso_context
, NULL
);
277 st
->dirty
|= ST_NEW_VS_STATE
;
279 case MESA_SHADER_TESS_CTRL
:
280 cso_set_tessctrl_shader_handle(st
->cso_context
, NULL
);
281 st
->dirty
|= ST_NEW_TCS_STATE
;
283 case MESA_SHADER_TESS_EVAL
:
284 cso_set_tesseval_shader_handle(st
->cso_context
, NULL
);
285 st
->dirty
|= ST_NEW_TES_STATE
;
287 case MESA_SHADER_GEOMETRY
:
288 cso_set_geometry_shader_handle(st
->cso_context
, NULL
);
289 st
->dirty
|= ST_NEW_GS_STATE
;
291 case MESA_SHADER_FRAGMENT
:
292 cso_set_fragment_shader_handle(st
->cso_context
, NULL
);
293 st
->dirty
|= ST_NEW_FS_STATE
;
295 case MESA_SHADER_COMPUTE
:
296 cso_set_compute_shader_handle(st
->cso_context
, NULL
);
297 st
->dirty
|= ST_NEW_CS_STATE
;
300 unreachable("invalid shader type");
305 * Free all basic program variants.
308 st_release_variants(struct st_context
*st
, struct st_program
*p
)
310 struct st_variant
*v
;
312 /* If we are releasing shaders, re-bind them, because we don't
313 * know which shaders are bound in the driver.
316 st_unbind_program(st
, p
);
318 for (v
= p
->variants
; v
; ) {
319 struct st_variant
*next
= v
->next
;
320 delete_variant(st
, v
, p
->Base
.Target
);
326 if (p
->state
.tokens
) {
327 ureg_free_tokens(p
->state
.tokens
);
328 p
->state
.tokens
= NULL
;
331 /* Note: Any setup of ->ir.nir that has had pipe->create_*_state called on
332 * it has resulted in the driver taking ownership of the NIR. Those
333 * callers should be NULLing out the nir field in any pipe_shader_state
334 * that might have this called in order to indicate that.
336 * GLSL IR and ARB programs will have set gl_program->nir to the same
337 * shader as ir->ir.nir, so it will be freed by _mesa_delete_program().
342 * Free all basic program variants and unref program.
345 st_release_program(struct st_context
*st
, struct st_program
**p
)
350 destroy_program_variants(st
, &((*p
)->Base
));
351 st_reference_prog(st
, p
, NULL
);
355 st_finalize_nir_before_variants(struct nir_shader
*nir
)
357 NIR_PASS_V(nir
, nir_opt_access
);
359 NIR_PASS_V(nir
, nir_split_var_copies
);
360 NIR_PASS_V(nir
, nir_lower_var_copies
);
361 if (nir
->options
->lower_all_io_to_temps
||
362 nir
->options
->lower_all_io_to_elements
||
363 nir
->info
.stage
== MESA_SHADER_VERTEX
||
364 nir
->info
.stage
== MESA_SHADER_GEOMETRY
) {
365 NIR_PASS_V(nir
, nir_lower_io_arrays_to_elements_no_indirects
, false);
366 } else if (nir
->info
.stage
== MESA_SHADER_FRAGMENT
) {
367 NIR_PASS_V(nir
, nir_lower_io_arrays_to_elements_no_indirects
, true);
370 st_nir_assign_vs_in_locations(nir
);
374 * Translate ARB (asm) program to NIR
377 st_translate_prog_to_nir(struct st_context
*st
, struct gl_program
*prog
,
378 gl_shader_stage stage
)
380 struct pipe_screen
*screen
= st
->pipe
->screen
;
381 const struct gl_shader_compiler_options
*options
=
382 &st
->ctx
->Const
.ShaderCompilerOptions
[stage
];
384 /* Translate to NIR */
385 nir_shader
*nir
= prog_to_nir(prog
, options
->NirOptions
);
386 NIR_PASS_V(nir
, nir_lower_regs_to_ssa
); /* turn registers into SSA */
387 nir_validate_shader(nir
, "after st/ptn lower_regs_to_ssa");
389 NIR_PASS_V(nir
, st_nir_lower_wpos_ytransform
, prog
, screen
);
390 NIR_PASS_V(nir
, nir_lower_system_values
);
393 NIR_PASS_V(nir
, nir_opt_constant_folding
);
395 st_finalize_nir_before_variants(nir
);
397 if (st
->allow_st_finalize_nir_twice
)
398 st_finalize_nir(st
, prog
, NULL
, nir
, true);
400 nir_validate_shader(nir
, "after st/glsl finalize_nir");
406 st_prepare_vertex_program(struct st_program
*stp
)
408 struct st_vertex_program
*stvp
= (struct st_vertex_program
*)stp
;
410 stvp
->num_inputs
= 0;
411 memset(stvp
->input_to_index
, ~0, sizeof(stvp
->input_to_index
));
412 memset(stvp
->result_to_output
, ~0, sizeof(stvp
->result_to_output
));
414 /* Determine number of inputs, the mappings between VERT_ATTRIB_x
415 * and TGSI generic input indexes, plus input attrib semantic info.
417 for (unsigned attr
= 0; attr
< VERT_ATTRIB_MAX
; attr
++) {
418 if ((stp
->Base
.info
.inputs_read
& BITFIELD64_BIT(attr
)) != 0) {
419 stvp
->input_to_index
[attr
] = stvp
->num_inputs
;
420 stvp
->index_to_input
[stvp
->num_inputs
] = attr
;
423 if ((stp
->Base
.DualSlotInputs
& BITFIELD64_BIT(attr
)) != 0) {
424 /* add placeholder for second part of a double attribute */
425 stvp
->index_to_input
[stvp
->num_inputs
] = ST_DOUBLE_ATTRIB_PLACEHOLDER
;
430 /* pre-setup potentially unused edgeflag input */
431 stvp
->input_to_index
[VERT_ATTRIB_EDGEFLAG
] = stvp
->num_inputs
;
432 stvp
->index_to_input
[stvp
->num_inputs
] = VERT_ATTRIB_EDGEFLAG
;
434 /* Compute mapping of vertex program outputs to slots. */
435 unsigned num_outputs
= 0;
436 for (unsigned attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
437 if (stp
->Base
.info
.outputs_written
& BITFIELD64_BIT(attr
))
438 stvp
->result_to_output
[attr
] = num_outputs
++;
440 /* pre-setup potentially unused edgeflag output */
441 stvp
->result_to_output
[VARYING_SLOT_EDGE
] = num_outputs
;
445 st_translate_stream_output_info(struct gl_program
*prog
)
447 struct gl_transform_feedback_info
*info
= prog
->sh
.LinkedTransformFeedback
;
451 /* Determine the (default) output register mapping for each output. */
452 unsigned num_outputs
= 0;
453 ubyte output_mapping
[VARYING_SLOT_TESS_MAX
];
454 memset(output_mapping
, 0, sizeof(output_mapping
));
456 for (unsigned attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
457 if (prog
->info
.outputs_written
& BITFIELD64_BIT(attr
))
458 output_mapping
[attr
] = num_outputs
++;
461 /* Translate stream output info. */
462 struct pipe_stream_output_info
*so_info
=
463 &((struct st_program
*)prog
)->state
.stream_output
;
465 for (unsigned i
= 0; i
< info
->NumOutputs
; i
++) {
466 so_info
->output
[i
].register_index
=
467 output_mapping
[info
->Outputs
[i
].OutputRegister
];
468 so_info
->output
[i
].start_component
= info
->Outputs
[i
].ComponentOffset
;
469 so_info
->output
[i
].num_components
= info
->Outputs
[i
].NumComponents
;
470 so_info
->output
[i
].output_buffer
= info
->Outputs
[i
].OutputBuffer
;
471 so_info
->output
[i
].dst_offset
= info
->Outputs
[i
].DstOffset
;
472 so_info
->output
[i
].stream
= info
->Outputs
[i
].StreamId
;
475 for (unsigned i
= 0; i
< PIPE_MAX_SO_BUFFERS
; i
++) {
476 so_info
->stride
[i
] = info
->Buffers
[i
].Stride
;
478 so_info
->num_outputs
= info
->NumOutputs
;
482 * Translate a vertex program.
485 st_translate_vertex_program(struct st_context
*st
,
486 struct st_program
*stp
)
488 struct ureg_program
*ureg
;
489 enum pipe_error error
;
490 unsigned num_outputs
= 0;
492 ubyte output_semantic_name
[VARYING_SLOT_MAX
] = {0};
493 ubyte output_semantic_index
[VARYING_SLOT_MAX
] = {0};
495 if (stp
->Base
.arb
.IsPositionInvariant
)
496 _mesa_insert_mvp_code(st
->ctx
, &stp
->Base
);
499 if (!stp
->glsl_to_tgsi
) {
500 _mesa_remove_output_reads(&stp
->Base
, PROGRAM_OUTPUT
);
502 /* This determines which states will be updated when the assembly
505 stp
->affected_states
= ST_NEW_VS_STATE
|
507 ST_NEW_VERTEX_ARRAYS
;
509 if (stp
->Base
.Parameters
->NumParameters
)
510 stp
->affected_states
|= ST_NEW_VS_CONSTANTS
;
512 /* Translate to NIR if preferred. */
513 if (st
->pipe
->screen
->get_shader_param(st
->pipe
->screen
,
515 PIPE_SHADER_CAP_PREFERRED_IR
)) {
516 assert(!stp
->glsl_to_tgsi
);
519 ralloc_free(stp
->Base
.nir
);
521 if (stp
->serialized_nir
) {
522 free(stp
->serialized_nir
);
523 stp
->serialized_nir
= NULL
;
526 stp
->state
.type
= PIPE_SHADER_IR_NIR
;
527 stp
->Base
.nir
= st_translate_prog_to_nir(st
, &stp
->Base
,
530 /* We must update stp->Base.info after translation and before
531 * st_prepare_vertex_program is called, because inputs_read
532 * may become outdated after NIR optimization passes.
534 * For ffvp/ARB_vp inputs_read is populated based
535 * on declared attributes without taking their usage into
536 * consideration. When creating shader variants we expect
537 * that their inputs_read would match the base ones for
538 * input mapping to work properly.
540 nir_shader_gather_info(stp
->Base
.nir
,
541 nir_shader_get_entrypoint(stp
->Base
.nir
));
542 st_nir_assign_vs_in_locations(stp
->Base
.nir
);
543 stp
->Base
.info
= stp
->Base
.nir
->info
;
545 /* For st_draw_feedback, we need to generate TGSI too if draw doesn't
548 if (draw_has_llvm()) {
549 st_prepare_vertex_program(stp
);
555 st_prepare_vertex_program(stp
);
557 /* Get semantic names and indices. */
558 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
559 if (stp
->Base
.info
.outputs_written
& BITFIELD64_BIT(attr
)) {
560 unsigned slot
= num_outputs
++;
561 unsigned semantic_name
, semantic_index
;
562 tgsi_get_gl_varying_semantic(attr
, st
->needs_texcoord_semantic
,
563 &semantic_name
, &semantic_index
);
564 output_semantic_name
[slot
] = semantic_name
;
565 output_semantic_index
[slot
] = semantic_index
;
568 /* pre-setup potentially unused edgeflag output */
569 output_semantic_name
[num_outputs
] = TGSI_SEMANTIC_EDGEFLAG
;
570 output_semantic_index
[num_outputs
] = 0;
572 ureg
= ureg_create_with_screen(PIPE_SHADER_VERTEX
, st
->pipe
->screen
);
576 if (stp
->Base
.info
.clip_distance_array_size
)
577 ureg_property(ureg
, TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
,
578 stp
->Base
.info
.clip_distance_array_size
);
579 if (stp
->Base
.info
.cull_distance_array_size
)
580 ureg_property(ureg
, TGSI_PROPERTY_NUM_CULLDIST_ENABLED
,
581 stp
->Base
.info
.cull_distance_array_size
);
583 if (ST_DEBUG
& DEBUG_MESA
) {
584 _mesa_print_program(&stp
->Base
);
585 _mesa_print_program_parameters(st
->ctx
, &stp
->Base
);
589 struct st_vertex_program
*stvp
= (struct st_vertex_program
*)stp
;
591 if (stp
->glsl_to_tgsi
) {
592 error
= st_translate_program(st
->ctx
,
599 stvp
->input_to_index
,
600 NULL
, /* inputSlotToAttr */
601 NULL
, /* input semantic name */
602 NULL
, /* input semantic index */
603 NULL
, /* interp mode */
606 stvp
->result_to_output
,
607 output_semantic_name
,
608 output_semantic_index
);
610 st_translate_stream_output_info(&stp
->Base
);
612 free_glsl_to_tgsi_visitor(stp
->glsl_to_tgsi
);
614 error
= st_translate_mesa_program(st
->ctx
,
620 stvp
->input_to_index
,
621 NULL
, /* input semantic name */
622 NULL
, /* input semantic index */
626 stvp
->result_to_output
,
627 output_semantic_name
,
628 output_semantic_index
);
631 debug_printf("%s: failed to translate Mesa program:\n", __func__
);
632 _mesa_print_program(&stp
->Base
);
637 stp
->state
.tokens
= ureg_get_tokens(ureg
, NULL
);
640 if (stp
->glsl_to_tgsi
) {
641 stp
->glsl_to_tgsi
= NULL
;
642 st_store_ir_in_disk_cache(st
, &stp
->Base
, false);
645 return stp
->state
.tokens
!= NULL
;
648 static struct nir_shader
*
649 get_nir_shader(struct st_context
*st
, struct st_program
*stp
)
652 nir_shader
*nir
= stp
->Base
.nir
;
654 /* The first shader variant takes ownership of NIR, so that there is
655 * no cloning. Additional shader variants are always generated from
656 * serialized NIR to save memory.
658 stp
->Base
.nir
= NULL
;
659 assert(stp
->serialized_nir
&& stp
->serialized_nir_size
);
663 struct blob_reader blob_reader
;
664 const struct nir_shader_compiler_options
*options
=
665 st
->ctx
->Const
.ShaderCompilerOptions
[stp
->Base
.info
.stage
].NirOptions
;
667 blob_reader_init(&blob_reader
, stp
->serialized_nir
, stp
->serialized_nir_size
);
668 return nir_deserialize(NULL
, options
, &blob_reader
);
671 static const gl_state_index16 depth_range_state
[STATE_LENGTH
] =
672 { STATE_DEPTH_RANGE
};
674 static struct st_common_variant
*
675 st_create_vp_variant(struct st_context
*st
,
676 struct st_program
*stvp
,
677 const struct st_common_variant_key
*key
)
679 struct st_common_variant
*vpv
= CALLOC_STRUCT(st_common_variant
);
680 struct pipe_context
*pipe
= st
->pipe
;
681 struct pipe_screen
*screen
= pipe
->screen
;
682 struct pipe_shader_state state
= {0};
684 static const gl_state_index16 point_size_state
[STATE_LENGTH
] =
685 { STATE_INTERNAL
, STATE_POINT_SIZE_CLAMPED
, 0 };
686 struct gl_program_parameter_list
*params
= stvp
->Base
.Parameters
;
690 state
.stream_output
= stvp
->state
.stream_output
;
692 if (stvp
->state
.type
== PIPE_SHADER_IR_NIR
&&
693 (!key
->is_draw_shader
|| draw_has_llvm())) {
694 bool finalize
= false;
696 state
.type
= PIPE_SHADER_IR_NIR
;
697 state
.ir
.nir
= get_nir_shader(st
, stvp
);
698 if (key
->clamp_color
) {
699 NIR_PASS_V(state
.ir
.nir
, nir_lower_clamp_color_outputs
);
702 if (key
->passthrough_edgeflags
) {
703 NIR_PASS_V(state
.ir
.nir
, nir_lower_passthrough_edgeflags
);
707 if (key
->lower_point_size
) {
708 _mesa_add_state_reference(params
, point_size_state
);
709 NIR_PASS_V(state
.ir
.nir
, nir_lower_point_size_mov
,
714 if (key
->lower_ucp
) {
715 bool can_compact
= screen
->get_param(screen
,
716 PIPE_CAP_NIR_COMPACT_ARRAYS
);
718 bool use_eye
= st
->ctx
->_Shader
->CurrentProgram
[MESA_SHADER_VERTEX
] != NULL
;
719 gl_state_index16 clipplane_state
[MAX_CLIP_PLANES
][STATE_LENGTH
];
720 for (int i
= 0; i
< MAX_CLIP_PLANES
; ++i
) {
722 clipplane_state
[i
][0] = STATE_CLIPPLANE
;
723 clipplane_state
[i
][1] = i
;
725 clipplane_state
[i
][0] = STATE_INTERNAL
;
726 clipplane_state
[i
][1] = STATE_CLIP_INTERNAL
;
727 clipplane_state
[i
][2] = i
;
729 _mesa_add_state_reference(params
, clipplane_state
[i
]);
732 NIR_PASS_V(state
.ir
.nir
, nir_lower_clip_vs
, key
->lower_ucp
,
733 true, can_compact
, clipplane_state
);
734 NIR_PASS_V(state
.ir
.nir
, nir_lower_io_to_temporaries
,
735 nir_shader_get_entrypoint(state
.ir
.nir
), true, false);
736 NIR_PASS_V(state
.ir
.nir
, nir_lower_global_vars_to_local
);
740 if (finalize
|| !st
->allow_st_finalize_nir_twice
) {
741 st_finalize_nir(st
, &stvp
->Base
, stvp
->shader_program
, state
.ir
.nir
,
744 /* Some of the lowering above may have introduced new varyings */
745 nir_shader_gather_info(state
.ir
.nir
,
746 nir_shader_get_entrypoint(state
.ir
.nir
));
749 if (ST_DEBUG
& DEBUG_PRINT_IR
)
750 nir_print_shader(state
.ir
.nir
, stderr
);
752 if (key
->is_draw_shader
)
753 vpv
->base
.driver_shader
= draw_create_vertex_shader(st
->draw
, &state
);
755 vpv
->base
.driver_shader
= pipe
->create_vs_state(pipe
, &state
);
760 state
.type
= PIPE_SHADER_IR_TGSI
;
761 state
.tokens
= tgsi_dup_tokens(stvp
->state
.tokens
);
763 /* Emulate features. */
764 if (key
->clamp_color
|| key
->passthrough_edgeflags
) {
765 const struct tgsi_token
*tokens
;
767 (key
->clamp_color
? TGSI_EMU_CLAMP_COLOR_OUTPUTS
: 0) |
768 (key
->passthrough_edgeflags
? TGSI_EMU_PASSTHROUGH_EDGEFLAG
: 0);
770 tokens
= tgsi_emulate(state
.tokens
, flags
);
773 tgsi_free_tokens(state
.tokens
);
774 state
.tokens
= tokens
;
776 fprintf(stderr
, "mesa: cannot emulate deprecated features\n");
780 if (key
->lower_depth_clamp
) {
781 unsigned depth_range_const
=
782 _mesa_add_state_reference(params
, depth_range_state
);
784 const struct tgsi_token
*tokens
;
785 tokens
= st_tgsi_lower_depth_clamp(state
.tokens
, depth_range_const
,
786 key
->clip_negative_one_to_one
);
787 if (tokens
!= state
.tokens
)
788 tgsi_free_tokens(state
.tokens
);
789 state
.tokens
= tokens
;
792 if (ST_DEBUG
& DEBUG_PRINT_IR
)
793 tgsi_dump(state
.tokens
, 0);
795 if (key
->is_draw_shader
)
796 vpv
->base
.driver_shader
= draw_create_vertex_shader(st
->draw
, &state
);
798 vpv
->base
.driver_shader
= pipe
->create_vs_state(pipe
, &state
);
801 tgsi_free_tokens(state
.tokens
);
809 * Find/create a vertex program variant.
811 struct st_common_variant
*
812 st_get_vp_variant(struct st_context
*st
,
813 struct st_program
*stp
,
814 const struct st_common_variant_key
*key
)
816 struct st_vertex_program
*stvp
= (struct st_vertex_program
*)stp
;
817 struct st_common_variant
*vpv
;
819 /* Search for existing variant */
820 for (vpv
= st_common_variant(stp
->variants
); vpv
;
821 vpv
= st_common_variant(vpv
->base
.next
)) {
822 if (memcmp(&vpv
->key
, key
, sizeof(*key
)) == 0) {
829 vpv
= st_create_vp_variant(st
, stp
, key
);
831 vpv
->base
.st
= key
->st
;
833 unsigned num_inputs
= stvp
->num_inputs
+ key
->passthrough_edgeflags
;
834 for (unsigned index
= 0; index
< num_inputs
; ++index
) {
835 unsigned attr
= stvp
->index_to_input
[index
];
836 if (attr
== ST_DOUBLE_ATTRIB_PLACEHOLDER
)
838 vpv
->vert_attrib_mask
|= 1u << attr
;
841 /* insert into list */
842 vpv
->base
.next
= stp
->variants
;
843 stp
->variants
= &vpv
->base
;
852 * Translate a Mesa fragment shader into a TGSI shader.
855 st_translate_fragment_program(struct st_context
*st
,
856 struct st_program
*stfp
)
858 /* Non-GLSL programs: */
859 if (!stfp
->glsl_to_tgsi
) {
860 _mesa_remove_output_reads(&stfp
->Base
, PROGRAM_OUTPUT
);
861 if (st
->ctx
->Const
.GLSLFragCoordIsSysVal
)
862 _mesa_program_fragment_position_to_sysval(&stfp
->Base
);
864 /* This determines which states will be updated when the assembly
867 * fragment.position and glDrawPixels always use constants.
869 stfp
->affected_states
= ST_NEW_FS_STATE
|
870 ST_NEW_SAMPLE_SHADING
|
874 /* Just set them for ATI_fs unconditionally. */
875 stfp
->affected_states
|= ST_NEW_FS_SAMPLER_VIEWS
|
879 if (stfp
->Base
.SamplersUsed
)
880 stfp
->affected_states
|= ST_NEW_FS_SAMPLER_VIEWS
|
884 /* Translate to NIR. */
886 st
->pipe
->screen
->get_shader_param(st
->pipe
->screen
,
887 PIPE_SHADER_FRAGMENT
,
888 PIPE_SHADER_CAP_PREFERRED_IR
)) {
890 st_translate_prog_to_nir(st
, &stfp
->Base
, MESA_SHADER_FRAGMENT
);
893 ralloc_free(stfp
->Base
.nir
);
894 if (stfp
->serialized_nir
) {
895 free(stfp
->serialized_nir
);
896 stfp
->serialized_nir
= NULL
;
898 stfp
->state
.type
= PIPE_SHADER_IR_NIR
;
899 stfp
->Base
.nir
= nir
;
904 ubyte outputMapping
[2 * FRAG_RESULT_MAX
];
905 ubyte inputMapping
[VARYING_SLOT_MAX
];
906 ubyte inputSlotToAttr
[VARYING_SLOT_MAX
];
907 ubyte interpMode
[PIPE_MAX_SHADER_INPUTS
]; /* XXX size? */
909 GLbitfield64 inputsRead
;
910 struct ureg_program
*ureg
;
912 GLboolean write_all
= GL_FALSE
;
914 ubyte input_semantic_name
[PIPE_MAX_SHADER_INPUTS
];
915 ubyte input_semantic_index
[PIPE_MAX_SHADER_INPUTS
];
916 uint fs_num_inputs
= 0;
918 ubyte fs_output_semantic_name
[PIPE_MAX_SHADER_OUTPUTS
];
919 ubyte fs_output_semantic_index
[PIPE_MAX_SHADER_OUTPUTS
];
920 uint fs_num_outputs
= 0;
922 memset(inputSlotToAttr
, ~0, sizeof(inputSlotToAttr
));
925 * Convert Mesa program inputs to TGSI input register semantics.
927 inputsRead
= stfp
->Base
.info
.inputs_read
;
928 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
929 if ((inputsRead
& BITFIELD64_BIT(attr
)) != 0) {
930 const GLuint slot
= fs_num_inputs
++;
932 inputMapping
[attr
] = slot
;
933 inputSlotToAttr
[slot
] = attr
;
936 case VARYING_SLOT_POS
:
937 input_semantic_name
[slot
] = TGSI_SEMANTIC_POSITION
;
938 input_semantic_index
[slot
] = 0;
939 interpMode
[slot
] = TGSI_INTERPOLATE_LINEAR
;
941 case VARYING_SLOT_COL0
:
942 input_semantic_name
[slot
] = TGSI_SEMANTIC_COLOR
;
943 input_semantic_index
[slot
] = 0;
944 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
945 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_COLOR
;
947 case VARYING_SLOT_COL1
:
948 input_semantic_name
[slot
] = TGSI_SEMANTIC_COLOR
;
949 input_semantic_index
[slot
] = 1;
950 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
951 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_COLOR
;
953 case VARYING_SLOT_FOGC
:
954 input_semantic_name
[slot
] = TGSI_SEMANTIC_FOG
;
955 input_semantic_index
[slot
] = 0;
956 interpMode
[slot
] = TGSI_INTERPOLATE_PERSPECTIVE
;
958 case VARYING_SLOT_FACE
:
959 input_semantic_name
[slot
] = TGSI_SEMANTIC_FACE
;
960 input_semantic_index
[slot
] = 0;
961 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
963 case VARYING_SLOT_PRIMITIVE_ID
:
964 input_semantic_name
[slot
] = TGSI_SEMANTIC_PRIMID
;
965 input_semantic_index
[slot
] = 0;
966 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
968 case VARYING_SLOT_LAYER
:
969 input_semantic_name
[slot
] = TGSI_SEMANTIC_LAYER
;
970 input_semantic_index
[slot
] = 0;
971 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
973 case VARYING_SLOT_VIEWPORT
:
974 input_semantic_name
[slot
] = TGSI_SEMANTIC_VIEWPORT_INDEX
;
975 input_semantic_index
[slot
] = 0;
976 interpMode
[slot
] = TGSI_INTERPOLATE_CONSTANT
;
978 case VARYING_SLOT_CLIP_DIST0
:
979 input_semantic_name
[slot
] = TGSI_SEMANTIC_CLIPDIST
;
980 input_semantic_index
[slot
] = 0;
981 interpMode
[slot
] = TGSI_INTERPOLATE_PERSPECTIVE
;
983 case VARYING_SLOT_CLIP_DIST1
:
984 input_semantic_name
[slot
] = TGSI_SEMANTIC_CLIPDIST
;
985 input_semantic_index
[slot
] = 1;
986 interpMode
[slot
] = TGSI_INTERPOLATE_PERSPECTIVE
;
988 case VARYING_SLOT_CULL_DIST0
:
989 case VARYING_SLOT_CULL_DIST1
:
990 /* these should have been lowered by GLSL */
993 /* In most cases, there is nothing special about these
994 * inputs, so adopt a convention to use the generic
995 * semantic name and the mesa VARYING_SLOT_ number as the
998 * All that is required is that the vertex shader labels
999 * its own outputs similarly, and that the vertex shader
1000 * generates at least every output required by the
1001 * fragment shader plus fixed-function hardware (such as
1004 * However, some drivers may need us to identify the PNTC and TEXi
1005 * varyings if, for example, their capability to replace them with
1006 * sprite coordinates is limited.
1008 case VARYING_SLOT_PNTC
:
1009 if (st
->needs_texcoord_semantic
) {
1010 input_semantic_name
[slot
] = TGSI_SEMANTIC_PCOORD
;
1011 input_semantic_index
[slot
] = 0;
1012 interpMode
[slot
] = TGSI_INTERPOLATE_LINEAR
;
1016 case VARYING_SLOT_TEX0
:
1017 case VARYING_SLOT_TEX1
:
1018 case VARYING_SLOT_TEX2
:
1019 case VARYING_SLOT_TEX3
:
1020 case VARYING_SLOT_TEX4
:
1021 case VARYING_SLOT_TEX5
:
1022 case VARYING_SLOT_TEX6
:
1023 case VARYING_SLOT_TEX7
:
1024 if (st
->needs_texcoord_semantic
) {
1025 input_semantic_name
[slot
] = TGSI_SEMANTIC_TEXCOORD
;
1026 input_semantic_index
[slot
] = attr
- VARYING_SLOT_TEX0
;
1027 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
1028 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_PERSPECTIVE
;
1032 case VARYING_SLOT_VAR0
:
1034 /* Semantic indices should be zero-based because drivers may choose
1035 * to assign a fixed slot determined by that index.
1036 * This is useful because ARB_separate_shader_objects uses location
1037 * qualifiers for linkage, and if the semantic index corresponds to
1038 * these locations, linkage passes in the driver become unecessary.
1040 * If needs_texcoord_semantic is true, no semantic indices will be
1041 * consumed for the TEXi varyings, and we can base the locations of
1042 * the user varyings on VAR0. Otherwise, we use TEX0 as base index.
1044 assert(attr
>= VARYING_SLOT_VAR0
|| attr
== VARYING_SLOT_PNTC
||
1045 (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
));
1046 input_semantic_name
[slot
] = TGSI_SEMANTIC_GENERIC
;
1047 input_semantic_index
[slot
] = st_get_generic_varying_index(st
, attr
);
1048 if (attr
== VARYING_SLOT_PNTC
)
1049 interpMode
[slot
] = TGSI_INTERPOLATE_LINEAR
;
1051 interpMode
[slot
] = stfp
->glsl_to_tgsi
?
1052 TGSI_INTERPOLATE_COUNT
: TGSI_INTERPOLATE_PERSPECTIVE
;
1058 inputMapping
[attr
] = -1;
1063 * Semantics and mapping for outputs
1065 GLbitfield64 outputsWritten
= stfp
->Base
.info
.outputs_written
;
1067 /* if z is written, emit that first */
1068 if (outputsWritten
& BITFIELD64_BIT(FRAG_RESULT_DEPTH
)) {
1069 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_POSITION
;
1070 fs_output_semantic_index
[fs_num_outputs
] = 0;
1071 outputMapping
[FRAG_RESULT_DEPTH
] = fs_num_outputs
;
1073 outputsWritten
&= ~(1 << FRAG_RESULT_DEPTH
);
1076 if (outputsWritten
& BITFIELD64_BIT(FRAG_RESULT_STENCIL
)) {
1077 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_STENCIL
;
1078 fs_output_semantic_index
[fs_num_outputs
] = 0;
1079 outputMapping
[FRAG_RESULT_STENCIL
] = fs_num_outputs
;
1081 outputsWritten
&= ~(1 << FRAG_RESULT_STENCIL
);
1084 if (outputsWritten
& BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK
)) {
1085 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_SAMPLEMASK
;
1086 fs_output_semantic_index
[fs_num_outputs
] = 0;
1087 outputMapping
[FRAG_RESULT_SAMPLE_MASK
] = fs_num_outputs
;
1089 outputsWritten
&= ~(1 << FRAG_RESULT_SAMPLE_MASK
);
1092 /* handle remaining outputs (color) */
1093 for (attr
= 0; attr
< ARRAY_SIZE(outputMapping
); attr
++) {
1094 const GLbitfield64 written
= attr
< FRAG_RESULT_MAX
? outputsWritten
:
1095 stfp
->Base
.SecondaryOutputsWritten
;
1096 const unsigned loc
= attr
% FRAG_RESULT_MAX
;
1098 if (written
& BITFIELD64_BIT(loc
)) {
1100 case FRAG_RESULT_DEPTH
:
1101 case FRAG_RESULT_STENCIL
:
1102 case FRAG_RESULT_SAMPLE_MASK
:
1106 case FRAG_RESULT_COLOR
:
1107 write_all
= GL_TRUE
; /* fallthrough */
1110 assert(loc
== FRAG_RESULT_COLOR
||
1111 (FRAG_RESULT_DATA0
<= loc
&& loc
< FRAG_RESULT_MAX
));
1113 index
= (loc
== FRAG_RESULT_COLOR
) ? 0 : (loc
- FRAG_RESULT_DATA0
);
1115 if (attr
>= FRAG_RESULT_MAX
) {
1116 /* Secondary color for dual source blending. */
1121 fs_output_semantic_name
[fs_num_outputs
] = TGSI_SEMANTIC_COLOR
;
1122 fs_output_semantic_index
[fs_num_outputs
] = index
;
1123 outputMapping
[attr
] = fs_num_outputs
;
1132 ureg
= ureg_create_with_screen(PIPE_SHADER_FRAGMENT
, st
->pipe
->screen
);
1136 if (ST_DEBUG
& DEBUG_MESA
) {
1137 _mesa_print_program(&stfp
->Base
);
1138 _mesa_print_program_parameters(st
->ctx
, &stfp
->Base
);
1141 if (write_all
== GL_TRUE
)
1142 ureg_property(ureg
, TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
, 1);
1144 if (stfp
->Base
.info
.fs
.depth_layout
!= FRAG_DEPTH_LAYOUT_NONE
) {
1145 switch (stfp
->Base
.info
.fs
.depth_layout
) {
1146 case FRAG_DEPTH_LAYOUT_ANY
:
1147 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1148 TGSI_FS_DEPTH_LAYOUT_ANY
);
1150 case FRAG_DEPTH_LAYOUT_GREATER
:
1151 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1152 TGSI_FS_DEPTH_LAYOUT_GREATER
);
1154 case FRAG_DEPTH_LAYOUT_LESS
:
1155 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1156 TGSI_FS_DEPTH_LAYOUT_LESS
);
1158 case FRAG_DEPTH_LAYOUT_UNCHANGED
:
1159 ureg_property(ureg
, TGSI_PROPERTY_FS_DEPTH_LAYOUT
,
1160 TGSI_FS_DEPTH_LAYOUT_UNCHANGED
);
1167 if (stfp
->glsl_to_tgsi
) {
1168 st_translate_program(st
->ctx
,
1169 PIPE_SHADER_FRAGMENT
,
1177 input_semantic_name
,
1178 input_semantic_index
,
1183 fs_output_semantic_name
,
1184 fs_output_semantic_index
);
1186 free_glsl_to_tgsi_visitor(stfp
->glsl_to_tgsi
);
1187 } else if (stfp
->ati_fs
)
1188 st_translate_atifs_program(ureg
,
1194 input_semantic_name
,
1195 input_semantic_index
,
1200 fs_output_semantic_name
,
1201 fs_output_semantic_index
);
1203 st_translate_mesa_program(st
->ctx
,
1204 PIPE_SHADER_FRAGMENT
,
1210 input_semantic_name
,
1211 input_semantic_index
,
1216 fs_output_semantic_name
,
1217 fs_output_semantic_index
);
1219 stfp
->state
.tokens
= ureg_get_tokens(ureg
, NULL
);
1222 if (stfp
->glsl_to_tgsi
) {
1223 stfp
->glsl_to_tgsi
= NULL
;
1224 st_store_ir_in_disk_cache(st
, &stfp
->Base
, false);
1227 return stfp
->state
.tokens
!= NULL
;
1230 static struct st_fp_variant
*
1231 st_create_fp_variant(struct st_context
*st
,
1232 struct st_program
*stfp
,
1233 const struct st_fp_variant_key
*key
)
1235 struct pipe_context
*pipe
= st
->pipe
;
1236 struct st_fp_variant
*variant
= CALLOC_STRUCT(st_fp_variant
);
1237 struct pipe_shader_state state
= {0};
1238 struct gl_program_parameter_list
*params
= stfp
->Base
.Parameters
;
1239 static const gl_state_index16 texcoord_state
[STATE_LENGTH
] =
1240 { STATE_INTERNAL
, STATE_CURRENT_ATTRIB
, VERT_ATTRIB_TEX0
};
1241 static const gl_state_index16 scale_state
[STATE_LENGTH
] =
1242 { STATE_INTERNAL
, STATE_PT_SCALE
};
1243 static const gl_state_index16 bias_state
[STATE_LENGTH
] =
1244 { STATE_INTERNAL
, STATE_PT_BIAS
};
1245 static const gl_state_index16 alpha_ref_state
[STATE_LENGTH
] =
1246 { STATE_INTERNAL
, STATE_ALPHA_REF
};
1251 if (stfp
->state
.type
== PIPE_SHADER_IR_NIR
) {
1252 bool finalize
= false;
1254 state
.type
= PIPE_SHADER_IR_NIR
;
1255 state
.ir
.nir
= get_nir_shader(st
, stfp
);
1257 if (key
->clamp_color
) {
1258 NIR_PASS_V(state
.ir
.nir
, nir_lower_clamp_color_outputs
);
1262 if (key
->lower_flatshade
) {
1263 NIR_PASS_V(state
.ir
.nir
, nir_lower_flatshade
);
1267 if (key
->lower_alpha_func
!= COMPARE_FUNC_NEVER
) {
1268 _mesa_add_state_reference(params
, alpha_ref_state
);
1269 NIR_PASS_V(state
.ir
.nir
, nir_lower_alpha_test
, key
->lower_alpha_func
,
1270 false, alpha_ref_state
);
1274 if (key
->lower_two_sided_color
) {
1275 NIR_PASS_V(state
.ir
.nir
, nir_lower_two_sided_color
);
1279 if (key
->persample_shading
) {
1280 nir_shader
*shader
= state
.ir
.nir
;
1281 nir_foreach_variable(var
, &shader
->inputs
)
1282 var
->data
.sample
= true;
1286 assert(!(key
->bitmap
&& key
->drawpixels
));
1290 nir_lower_bitmap_options options
= {0};
1292 variant
->bitmap_sampler
= ffs(~stfp
->Base
.SamplersUsed
) - 1;
1293 options
.sampler
= variant
->bitmap_sampler
;
1294 options
.swizzle_xxxx
= st
->bitmap
.tex_format
== PIPE_FORMAT_R8_UNORM
;
1296 NIR_PASS_V(state
.ir
.nir
, nir_lower_bitmap
, &options
);
1300 /* glDrawPixels (color only) */
1301 if (key
->drawpixels
) {
1302 nir_lower_drawpixels_options options
= {{0}};
1303 unsigned samplers_used
= stfp
->Base
.SamplersUsed
;
1305 /* Find the first unused slot. */
1306 variant
->drawpix_sampler
= ffs(~samplers_used
) - 1;
1307 options
.drawpix_sampler
= variant
->drawpix_sampler
;
1308 samplers_used
|= (1 << variant
->drawpix_sampler
);
1310 options
.pixel_maps
= key
->pixelMaps
;
1311 if (key
->pixelMaps
) {
1312 variant
->pixelmap_sampler
= ffs(~samplers_used
) - 1;
1313 options
.pixelmap_sampler
= variant
->pixelmap_sampler
;
1316 options
.scale_and_bias
= key
->scaleAndBias
;
1317 if (key
->scaleAndBias
) {
1318 _mesa_add_state_reference(params
, scale_state
);
1319 memcpy(options
.scale_state_tokens
, scale_state
,
1320 sizeof(options
.scale_state_tokens
));
1321 _mesa_add_state_reference(params
, bias_state
);
1322 memcpy(options
.bias_state_tokens
, bias_state
,
1323 sizeof(options
.bias_state_tokens
));
1326 _mesa_add_state_reference(params
, texcoord_state
);
1327 memcpy(options
.texcoord_state_tokens
, texcoord_state
,
1328 sizeof(options
.texcoord_state_tokens
));
1330 NIR_PASS_V(state
.ir
.nir
, nir_lower_drawpixels
, &options
);
1334 if (unlikely(key
->external
.lower_nv12
|| key
->external
.lower_iyuv
||
1335 key
->external
.lower_xy_uxvx
|| key
->external
.lower_yx_xuxv
||
1336 key
->external
.lower_ayuv
|| key
->external
.lower_xyuv
)) {
1338 st_nir_lower_samplers(pipe
->screen
, state
.ir
.nir
,
1339 stfp
->shader_program
, &stfp
->Base
);
1341 nir_lower_tex_options options
= {0};
1342 options
.lower_y_uv_external
= key
->external
.lower_nv12
;
1343 options
.lower_y_u_v_external
= key
->external
.lower_iyuv
;
1344 options
.lower_xy_uxvx_external
= key
->external
.lower_xy_uxvx
;
1345 options
.lower_yx_xuxv_external
= key
->external
.lower_yx_xuxv
;
1346 options
.lower_ayuv_external
= key
->external
.lower_ayuv
;
1347 options
.lower_xyuv_external
= key
->external
.lower_xyuv
;
1348 NIR_PASS_V(state
.ir
.nir
, nir_lower_tex
, &options
);
1352 if (finalize
|| !st
->allow_st_finalize_nir_twice
) {
1353 st_finalize_nir(st
, &stfp
->Base
, stfp
->shader_program
, state
.ir
.nir
,
1357 /* This pass needs to happen *after* nir_lower_sampler */
1358 if (unlikely(key
->external
.lower_nv12
|| key
->external
.lower_iyuv
||
1359 key
->external
.lower_xy_uxvx
|| key
->external
.lower_yx_xuxv
||
1360 key
->external
.lower_ayuv
|| key
->external
.lower_xyuv
)) {
1361 NIR_PASS_V(state
.ir
.nir
, st_nir_lower_tex_src_plane
,
1362 ~stfp
->Base
.SamplersUsed
,
1363 key
->external
.lower_nv12
|| key
->external
.lower_xy_uxvx
||
1364 key
->external
.lower_yx_xuxv
,
1365 key
->external
.lower_iyuv
);
1369 if (finalize
|| !st
->allow_st_finalize_nir_twice
) {
1370 /* Some of the lowering above may have introduced new varyings */
1371 nir_shader_gather_info(state
.ir
.nir
,
1372 nir_shader_get_entrypoint(state
.ir
.nir
));
1374 struct pipe_screen
*screen
= pipe
->screen
;
1375 if (screen
->finalize_nir
)
1376 screen
->finalize_nir(screen
, state
.ir
.nir
, false);
1379 if (ST_DEBUG
& DEBUG_PRINT_IR
)
1380 nir_print_shader(state
.ir
.nir
, stderr
);
1382 variant
->base
.driver_shader
= pipe
->create_fs_state(pipe
, &state
);
1383 variant
->key
= *key
;
1388 state
.tokens
= stfp
->state
.tokens
;
1390 assert(!(key
->bitmap
&& key
->drawpixels
));
1392 /* Fix texture targets and add fog for ATI_fs */
1394 const struct tgsi_token
*tokens
= st_fixup_atifs(state
.tokens
, key
);
1397 state
.tokens
= tokens
;
1399 fprintf(stderr
, "mesa: cannot post-process ATI_fs\n");
1402 /* Emulate features. */
1403 if (key
->clamp_color
|| key
->persample_shading
) {
1404 const struct tgsi_token
*tokens
;
1406 (key
->clamp_color
? TGSI_EMU_CLAMP_COLOR_OUTPUTS
: 0) |
1407 (key
->persample_shading
? TGSI_EMU_FORCE_PERSAMPLE_INTERP
: 0);
1409 tokens
= tgsi_emulate(state
.tokens
, flags
);
1412 if (state
.tokens
!= stfp
->state
.tokens
)
1413 tgsi_free_tokens(state
.tokens
);
1414 state
.tokens
= tokens
;
1416 fprintf(stderr
, "mesa: cannot emulate deprecated features\n");
1421 const struct tgsi_token
*tokens
;
1423 variant
->bitmap_sampler
= ffs(~stfp
->Base
.SamplersUsed
) - 1;
1425 tokens
= st_get_bitmap_shader(state
.tokens
,
1426 st
->internal_target
,
1427 variant
->bitmap_sampler
,
1428 st
->needs_texcoord_semantic
,
1429 st
->bitmap
.tex_format
==
1430 PIPE_FORMAT_R8_UNORM
);
1433 if (state
.tokens
!= stfp
->state
.tokens
)
1434 tgsi_free_tokens(state
.tokens
);
1435 state
.tokens
= tokens
;
1437 fprintf(stderr
, "mesa: cannot create a shader for glBitmap\n");
1440 /* glDrawPixels (color only) */
1441 if (key
->drawpixels
) {
1442 const struct tgsi_token
*tokens
;
1443 unsigned scale_const
= 0, bias_const
= 0, texcoord_const
= 0;
1445 /* Find the first unused slot. */
1446 variant
->drawpix_sampler
= ffs(~stfp
->Base
.SamplersUsed
) - 1;
1448 if (key
->pixelMaps
) {
1449 unsigned samplers_used
= stfp
->Base
.SamplersUsed
|
1450 (1 << variant
->drawpix_sampler
);
1452 variant
->pixelmap_sampler
= ffs(~samplers_used
) - 1;
1455 if (key
->scaleAndBias
) {
1456 scale_const
= _mesa_add_state_reference(params
, scale_state
);
1457 bias_const
= _mesa_add_state_reference(params
, bias_state
);
1460 texcoord_const
= _mesa_add_state_reference(params
, texcoord_state
);
1462 tokens
= st_get_drawpix_shader(state
.tokens
,
1463 st
->needs_texcoord_semantic
,
1464 key
->scaleAndBias
, scale_const
,
1465 bias_const
, key
->pixelMaps
,
1466 variant
->drawpix_sampler
,
1467 variant
->pixelmap_sampler
,
1468 texcoord_const
, st
->internal_target
);
1471 if (state
.tokens
!= stfp
->state
.tokens
)
1472 tgsi_free_tokens(state
.tokens
);
1473 state
.tokens
= tokens
;
1475 fprintf(stderr
, "mesa: cannot create a shader for glDrawPixels\n");
1478 if (unlikely(key
->external
.lower_nv12
|| key
->external
.lower_iyuv
||
1479 key
->external
.lower_xy_uxvx
|| key
->external
.lower_yx_xuxv
)) {
1480 const struct tgsi_token
*tokens
;
1482 /* samplers inserted would conflict, but this should be unpossible: */
1483 assert(!(key
->bitmap
|| key
->drawpixels
));
1485 tokens
= st_tgsi_lower_yuv(state
.tokens
,
1486 ~stfp
->Base
.SamplersUsed
,
1487 key
->external
.lower_nv12
||
1488 key
->external
.lower_xy_uxvx
||
1489 key
->external
.lower_yx_xuxv
,
1490 key
->external
.lower_iyuv
);
1492 if (state
.tokens
!= stfp
->state
.tokens
)
1493 tgsi_free_tokens(state
.tokens
);
1494 state
.tokens
= tokens
;
1496 fprintf(stderr
, "mesa: cannot create a shader for samplerExternalOES\n");
1500 if (key
->lower_depth_clamp
) {
1501 unsigned depth_range_const
= _mesa_add_state_reference(params
, depth_range_state
);
1503 const struct tgsi_token
*tokens
;
1504 tokens
= st_tgsi_lower_depth_clamp_fs(state
.tokens
, depth_range_const
);
1505 if (state
.tokens
!= stfp
->state
.tokens
)
1506 tgsi_free_tokens(state
.tokens
);
1507 state
.tokens
= tokens
;
1510 if (ST_DEBUG
& DEBUG_PRINT_IR
)
1511 tgsi_dump(state
.tokens
, 0);
1513 /* fill in variant */
1514 variant
->base
.driver_shader
= pipe
->create_fs_state(pipe
, &state
);
1515 variant
->key
= *key
;
1517 if (state
.tokens
!= stfp
->state
.tokens
)
1518 tgsi_free_tokens(state
.tokens
);
1523 * Translate fragment program if needed.
1525 struct st_fp_variant
*
1526 st_get_fp_variant(struct st_context
*st
,
1527 struct st_program
*stfp
,
1528 const struct st_fp_variant_key
*key
)
1530 struct st_fp_variant
*fpv
;
1532 /* Search for existing variant */
1533 for (fpv
= st_fp_variant(stfp
->variants
); fpv
;
1534 fpv
= st_fp_variant(fpv
->base
.next
)) {
1535 if (memcmp(&fpv
->key
, key
, sizeof(*key
)) == 0) {
1542 fpv
= st_create_fp_variant(st
, stfp
, key
);
1544 fpv
->base
.st
= key
->st
;
1546 if (key
->bitmap
|| key
->drawpixels
) {
1547 /* Regular variants should always come before the
1548 * bitmap & drawpixels variants, (unless there
1549 * are no regular variants) so that
1550 * st_update_fp can take a fast path when
1551 * shader_has_one_variant is set.
1553 if (!stfp
->variants
) {
1554 stfp
->variants
= &fpv
->base
;
1556 /* insert into list after the first one */
1557 fpv
->base
.next
= stfp
->variants
->next
;
1558 stfp
->variants
->next
= &fpv
->base
;
1561 /* insert into list */
1562 fpv
->base
.next
= stfp
->variants
;
1563 stfp
->variants
= &fpv
->base
;
1572 * Translate a program. This is common code for geometry and tessellation
1576 st_translate_common_program(struct st_context
*st
,
1577 struct st_program
*stp
)
1579 struct gl_program
*prog
= &stp
->Base
;
1580 enum pipe_shader_type stage
=
1581 pipe_shader_type_from_mesa(stp
->Base
.info
.stage
);
1582 struct ureg_program
*ureg
= ureg_create_with_screen(stage
, st
->pipe
->screen
);
1588 case PIPE_SHADER_TESS_CTRL
:
1589 ureg_property(ureg
, TGSI_PROPERTY_TCS_VERTICES_OUT
,
1590 stp
->Base
.info
.tess
.tcs_vertices_out
);
1593 case PIPE_SHADER_TESS_EVAL
:
1594 if (stp
->Base
.info
.tess
.primitive_mode
== GL_ISOLINES
)
1595 ureg_property(ureg
, TGSI_PROPERTY_TES_PRIM_MODE
, GL_LINES
);
1597 ureg_property(ureg
, TGSI_PROPERTY_TES_PRIM_MODE
,
1598 stp
->Base
.info
.tess
.primitive_mode
);
1600 STATIC_ASSERT((TESS_SPACING_EQUAL
+ 1) % 3 == PIPE_TESS_SPACING_EQUAL
);
1601 STATIC_ASSERT((TESS_SPACING_FRACTIONAL_ODD
+ 1) % 3 ==
1602 PIPE_TESS_SPACING_FRACTIONAL_ODD
);
1603 STATIC_ASSERT((TESS_SPACING_FRACTIONAL_EVEN
+ 1) % 3 ==
1604 PIPE_TESS_SPACING_FRACTIONAL_EVEN
);
1606 ureg_property(ureg
, TGSI_PROPERTY_TES_SPACING
,
1607 (stp
->Base
.info
.tess
.spacing
+ 1) % 3);
1609 ureg_property(ureg
, TGSI_PROPERTY_TES_VERTEX_ORDER_CW
,
1610 !stp
->Base
.info
.tess
.ccw
);
1611 ureg_property(ureg
, TGSI_PROPERTY_TES_POINT_MODE
,
1612 stp
->Base
.info
.tess
.point_mode
);
1615 case PIPE_SHADER_GEOMETRY
:
1616 ureg_property(ureg
, TGSI_PROPERTY_GS_INPUT_PRIM
,
1617 stp
->Base
.info
.gs
.input_primitive
);
1618 ureg_property(ureg
, TGSI_PROPERTY_GS_OUTPUT_PRIM
,
1619 stp
->Base
.info
.gs
.output_primitive
);
1620 ureg_property(ureg
, TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES
,
1621 stp
->Base
.info
.gs
.vertices_out
);
1622 ureg_property(ureg
, TGSI_PROPERTY_GS_INVOCATIONS
,
1623 stp
->Base
.info
.gs
.invocations
);
1630 ubyte inputSlotToAttr
[VARYING_SLOT_TESS_MAX
];
1631 ubyte inputMapping
[VARYING_SLOT_TESS_MAX
];
1632 ubyte outputMapping
[VARYING_SLOT_TESS_MAX
];
1635 ubyte input_semantic_name
[PIPE_MAX_SHADER_INPUTS
];
1636 ubyte input_semantic_index
[PIPE_MAX_SHADER_INPUTS
];
1637 uint num_inputs
= 0;
1639 ubyte output_semantic_name
[PIPE_MAX_SHADER_OUTPUTS
];
1640 ubyte output_semantic_index
[PIPE_MAX_SHADER_OUTPUTS
];
1641 uint num_outputs
= 0;
1645 memset(inputSlotToAttr
, 0, sizeof(inputSlotToAttr
));
1646 memset(inputMapping
, 0, sizeof(inputMapping
));
1647 memset(outputMapping
, 0, sizeof(outputMapping
));
1648 memset(&stp
->state
, 0, sizeof(stp
->state
));
1650 if (prog
->info
.clip_distance_array_size
)
1651 ureg_property(ureg
, TGSI_PROPERTY_NUM_CLIPDIST_ENABLED
,
1652 prog
->info
.clip_distance_array_size
);
1653 if (prog
->info
.cull_distance_array_size
)
1654 ureg_property(ureg
, TGSI_PROPERTY_NUM_CULLDIST_ENABLED
,
1655 prog
->info
.cull_distance_array_size
);
1658 * Convert Mesa program inputs to TGSI input register semantics.
1660 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
1661 if ((prog
->info
.inputs_read
& BITFIELD64_BIT(attr
)) == 0)
1664 unsigned slot
= num_inputs
++;
1666 inputMapping
[attr
] = slot
;
1667 inputSlotToAttr
[slot
] = attr
;
1669 unsigned semantic_name
, semantic_index
;
1670 tgsi_get_gl_varying_semantic(attr
, st
->needs_texcoord_semantic
,
1671 &semantic_name
, &semantic_index
);
1672 input_semantic_name
[slot
] = semantic_name
;
1673 input_semantic_index
[slot
] = semantic_index
;
1676 /* Also add patch inputs. */
1677 for (attr
= 0; attr
< 32; attr
++) {
1678 if (prog
->info
.patch_inputs_read
& (1u << attr
)) {
1679 GLuint slot
= num_inputs
++;
1680 GLuint patch_attr
= VARYING_SLOT_PATCH0
+ attr
;
1682 inputMapping
[patch_attr
] = slot
;
1683 inputSlotToAttr
[slot
] = patch_attr
;
1684 input_semantic_name
[slot
] = TGSI_SEMANTIC_PATCH
;
1685 input_semantic_index
[slot
] = attr
;
1689 /* initialize output semantics to defaults */
1690 for (i
= 0; i
< PIPE_MAX_SHADER_OUTPUTS
; i
++) {
1691 output_semantic_name
[i
] = TGSI_SEMANTIC_GENERIC
;
1692 output_semantic_index
[i
] = 0;
1696 * Determine number of outputs, the (default) output register
1697 * mapping and the semantic information for each output.
1699 for (attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
1700 if (prog
->info
.outputs_written
& BITFIELD64_BIT(attr
)) {
1701 GLuint slot
= num_outputs
++;
1703 outputMapping
[attr
] = slot
;
1705 unsigned semantic_name
, semantic_index
;
1706 tgsi_get_gl_varying_semantic(attr
, st
->needs_texcoord_semantic
,
1707 &semantic_name
, &semantic_index
);
1708 output_semantic_name
[slot
] = semantic_name
;
1709 output_semantic_index
[slot
] = semantic_index
;
1713 /* Also add patch outputs. */
1714 for (attr
= 0; attr
< 32; attr
++) {
1715 if (prog
->info
.patch_outputs_written
& (1u << attr
)) {
1716 GLuint slot
= num_outputs
++;
1717 GLuint patch_attr
= VARYING_SLOT_PATCH0
+ attr
;
1719 outputMapping
[patch_attr
] = slot
;
1720 output_semantic_name
[slot
] = TGSI_SEMANTIC_PATCH
;
1721 output_semantic_index
[slot
] = attr
;
1725 st_translate_program(st
->ctx
,
1734 input_semantic_name
,
1735 input_semantic_index
,
1740 output_semantic_name
,
1741 output_semantic_index
);
1743 stp
->state
.tokens
= ureg_get_tokens(ureg
, NULL
);
1747 st_translate_stream_output_info(prog
);
1749 st_store_ir_in_disk_cache(st
, prog
, false);
1751 if (ST_DEBUG
& DEBUG_PRINT_IR
&& ST_DEBUG
& DEBUG_MESA
)
1752 _mesa_print_program(prog
);
1754 free_glsl_to_tgsi_visitor(stp
->glsl_to_tgsi
);
1755 stp
->glsl_to_tgsi
= NULL
;
1761 * Get/create a basic program variant.
1764 st_get_common_variant(struct st_context
*st
,
1765 struct st_program
*prog
,
1766 const struct st_common_variant_key
*key
)
1768 struct pipe_context
*pipe
= st
->pipe
;
1769 struct st_variant
*v
;
1770 struct pipe_shader_state state
= {0};
1772 /* Search for existing variant */
1773 for (v
= prog
->variants
; v
; v
= v
->next
) {
1774 if (memcmp(&st_common_variant(v
)->key
, key
, sizeof(*key
)) == 0)
1780 v
= (struct st_variant
*)CALLOC_STRUCT(st_common_variant
);
1782 if (prog
->state
.type
== PIPE_SHADER_IR_NIR
) {
1783 bool finalize
= false;
1785 state
.type
= PIPE_SHADER_IR_NIR
;
1786 state
.ir
.nir
= get_nir_shader(st
, prog
);
1788 if (key
->clamp_color
) {
1789 NIR_PASS_V(state
.ir
.nir
, nir_lower_clamp_color_outputs
);
1793 state
.stream_output
= prog
->state
.stream_output
;
1795 if (finalize
|| !st
->allow_st_finalize_nir_twice
) {
1796 st_finalize_nir(st
, &prog
->Base
, prog
->shader_program
,
1797 state
.ir
.nir
, true);
1800 if (ST_DEBUG
& DEBUG_PRINT_IR
)
1801 nir_print_shader(state
.ir
.nir
, stderr
);
1803 if (key
->lower_depth_clamp
) {
1804 struct gl_program_parameter_list
*params
= prog
->Base
.Parameters
;
1806 unsigned depth_range_const
=
1807 _mesa_add_state_reference(params
, depth_range_state
);
1809 const struct tgsi_token
*tokens
;
1811 st_tgsi_lower_depth_clamp(prog
->state
.tokens
,
1813 key
->clip_negative_one_to_one
);
1815 if (tokens
!= prog
->state
.tokens
)
1816 tgsi_free_tokens(prog
->state
.tokens
);
1818 prog
->state
.tokens
= tokens
;
1820 state
= prog
->state
;
1822 if (ST_DEBUG
& DEBUG_PRINT_IR
)
1823 tgsi_dump(state
.tokens
, 0);
1825 /* fill in new variant */
1826 switch (prog
->Base
.info
.stage
) {
1827 case MESA_SHADER_TESS_CTRL
:
1828 v
->driver_shader
= pipe
->create_tcs_state(pipe
, &state
);
1830 case MESA_SHADER_TESS_EVAL
:
1831 v
->driver_shader
= pipe
->create_tes_state(pipe
, &state
);
1833 case MESA_SHADER_GEOMETRY
:
1834 v
->driver_shader
= pipe
->create_gs_state(pipe
, &state
);
1836 case MESA_SHADER_COMPUTE
: {
1837 struct pipe_compute_state cs
= {0};
1838 cs
.ir_type
= state
.type
;
1839 cs
.req_local_mem
= prog
->Base
.info
.cs
.shared_size
;
1841 if (state
.type
== PIPE_SHADER_IR_NIR
)
1842 cs
.prog
= state
.ir
.nir
;
1844 cs
.prog
= state
.tokens
;
1846 v
->driver_shader
= pipe
->create_compute_state(pipe
, &cs
);
1850 assert(!"unhandled shader type");
1855 st_common_variant(v
)->key
= *key
;
1858 /* insert into list */
1859 v
->next
= prog
->variants
;
1869 * Vert/Geom/Frag programs have per-context variants. Free all the
1870 * variants attached to the given program which match the given context.
1873 destroy_program_variants(struct st_context
*st
, struct gl_program
*target
)
1875 if (!target
|| target
== &_mesa_DummyProgram
)
1878 struct st_program
*p
= st_program(target
);
1879 struct st_variant
*v
, **prevPtr
= &p
->variants
;
1880 bool unbound
= false;
1882 for (v
= p
->variants
; v
; ) {
1883 struct st_variant
*next
= v
->next
;
1886 st_unbind_program(st
, p
);
1890 /* unlink from list */
1892 /* destroy this variant */
1893 delete_variant(st
, v
, target
->Target
);
1904 * Callback for _mesa_HashWalk. Free all the shader's program variants
1905 * which match the given context.
1908 destroy_shader_program_variants_cb(GLuint key
, void *data
, void *userData
)
1910 struct st_context
*st
= (struct st_context
*) userData
;
1911 struct gl_shader
*shader
= (struct gl_shader
*) data
;
1913 switch (shader
->Type
) {
1914 case GL_SHADER_PROGRAM_MESA
:
1916 struct gl_shader_program
*shProg
= (struct gl_shader_program
*) data
;
1919 for (i
= 0; i
< ARRAY_SIZE(shProg
->_LinkedShaders
); i
++) {
1920 if (shProg
->_LinkedShaders
[i
])
1921 destroy_program_variants(st
, shProg
->_LinkedShaders
[i
]->Program
);
1925 case GL_VERTEX_SHADER
:
1926 case GL_FRAGMENT_SHADER
:
1927 case GL_GEOMETRY_SHADER
:
1928 case GL_TESS_CONTROL_SHADER
:
1929 case GL_TESS_EVALUATION_SHADER
:
1930 case GL_COMPUTE_SHADER
:
1939 * Callback for _mesa_HashWalk. Free all the program variants which match
1940 * the given context.
1943 destroy_program_variants_cb(GLuint key
, void *data
, void *userData
)
1945 struct st_context
*st
= (struct st_context
*) userData
;
1946 struct gl_program
*program
= (struct gl_program
*) data
;
1947 destroy_program_variants(st
, program
);
1952 * Walk over all shaders and programs to delete any variants which
1953 * belong to the given context.
1954 * This is called during context tear-down.
1957 st_destroy_program_variants(struct st_context
*st
)
1959 /* If shaders can be shared with other contexts, the last context will
1960 * call DeleteProgram on all shaders, releasing everything.
1962 if (st
->has_shareable_shaders
)
1965 /* ARB vert/frag program */
1966 _mesa_HashWalk(st
->ctx
->Shared
->Programs
,
1967 destroy_program_variants_cb
, st
);
1969 /* GLSL vert/frag/geom shaders */
1970 _mesa_HashWalk(st
->ctx
->Shared
->ShaderObjects
,
1971 destroy_shader_program_variants_cb
, st
);
1976 * Compile one shader variant.
1979 st_precompile_shader_variant(struct st_context
*st
,
1980 struct gl_program
*prog
)
1982 switch (prog
->Target
) {
1983 case GL_VERTEX_PROGRAM_ARB
: {
1984 struct st_program
*p
= (struct st_program
*)prog
;
1985 struct st_common_variant_key key
;
1987 memset(&key
, 0, sizeof(key
));
1989 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
1990 st_get_vp_variant(st
, p
, &key
);
1994 case GL_FRAGMENT_PROGRAM_ARB
: {
1995 struct st_program
*p
= (struct st_program
*)prog
;
1996 struct st_fp_variant_key key
;
1998 memset(&key
, 0, sizeof(key
));
2000 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2001 st_get_fp_variant(st
, p
, &key
);
2005 case GL_TESS_CONTROL_PROGRAM_NV
:
2006 case GL_TESS_EVALUATION_PROGRAM_NV
:
2007 case GL_GEOMETRY_PROGRAM_NV
:
2008 case GL_COMPUTE_PROGRAM_NV
: {
2009 struct st_program
*p
= st_program(prog
);
2010 struct st_common_variant_key key
;
2012 memset(&key
, 0, sizeof(key
));
2014 key
.st
= st
->has_shareable_shaders
? NULL
: st
;
2015 st_get_common_variant(st
, p
, &key
);
2025 st_serialize_nir(struct st_program
*stp
)
2027 if (!stp
->serialized_nir
) {
2032 nir_serialize(&blob
, stp
->Base
.nir
, false);
2033 blob_finish_get_buffer(&blob
, &stp
->serialized_nir
, &size
);
2034 stp
->serialized_nir_size
= size
;
2039 st_finalize_program(struct st_context
*st
, struct gl_program
*prog
)
2041 if (st
->current_program
[prog
->info
.stage
] == prog
) {
2042 if (prog
->info
.stage
== MESA_SHADER_VERTEX
)
2043 st
->dirty
|= ST_NEW_VERTEX_PROGRAM(st
, (struct st_program
*)prog
);
2045 st
->dirty
|= ((struct st_program
*)prog
)->affected_states
;
2049 nir_sweep(prog
->nir
);
2051 /* This is only needed for ARB_vp/fp programs and when the disk cache
2052 * is disabled. If the disk cache is enabled, GLSL programs are
2053 * serialized in write_nir_to_cache.
2055 st_serialize_nir(st_program(prog
));
2058 /* Create Gallium shaders now instead of on demand. */
2059 if (ST_DEBUG
& DEBUG_PRECOMPILE
||
2060 st
->shader_has_one_variant
[prog
->info
.stage
])
2061 st_precompile_shader_variant(st
, prog
);