2 * Copyright 2012 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Tom Stellard <thomas.stellard@amd.com>
25 * Michel Dänzer <michel.daenzer@amd.com>
26 * Christian König <christian.koenig@amd.com>
29 /* The compiler middle-end architecture: Explaining (non-)monolithic shaders
30 * -------------------------------------------------------------------------
32 * Typically, there is one-to-one correspondence between API and HW shaders,
33 * that is, for every API shader, there is exactly one shader binary in
36 * The problem with that is that we also have to emulate some API states
37 * (e.g. alpha-test, and many others) in shaders too. The two obvious ways
38 * to deal with it are:
39 * - each shader has multiple variants for each combination of emulated states,
40 * and the variants are compiled on demand, possibly relying on a shader
41 * cache for good performance
42 * - patch shaders at the binary level
44 * This driver uses something completely different. The emulated states are
45 * usually implemented at the beginning or end of shaders. Therefore, we can
46 * split the shader into 3 parts:
47 * - prolog part (shader code dependent on states)
48 * - main part (the API shader)
49 * - epilog part (shader code dependent on states)
51 * Each part is compiled as a separate shader and the final binaries are
52 * concatenated. This type of shader is called non-monolithic, because it
53 * consists of multiple independent binaries. Creating a new shader variant
54 * is therefore only a concatenation of shader parts (binaries) and doesn't
55 * involve any compilation. The main shader parts are the only parts that are
56 * compiled when applications create shader objects. The prolog and epilog
57 * parts are compiled on the first use and saved, so that their binaries can
58 * be reused by many other shaders.
60 * One of the roles of the prolog part is to compute vertex buffer addresses
61 * for vertex shaders. A few of the roles of the epilog part are color buffer
62 * format conversions in pixel shaders that we have to do manually, and write
63 * tessellation factors in tessellation control shaders. The prolog and epilog
64 * have many other important responsibilities in various shader stages.
65 * They don't just "emulate legacy stuff".
67 * Monolithic shaders are shaders where the parts are combined before LLVM
68 * compilation, and the whole thing is compiled and optimized as one unit with
69 * one binary on the output. The result is the same as the non-monolithic
70 * shader, but the final code can be better, because LLVM can optimize across
71 * all shader parts. Monolithic shaders aren't usually used except for these
74 * 1) Some rarely-used states require modification of the main shader part
75 * itself, and in such cases, only the monolithic shader variant is
76 * compiled, and that's always done on the first use.
78 * 2) When we do cross-stage optimizations for separate shader objects and
79 * e.g. eliminate unused shader varyings, the resulting optimized shader
80 * variants are always compiled as monolithic shaders, and always
81 * asynchronously (i.e. not stalling ongoing rendering). We call them
82 * "optimized monolithic" shaders. The important property here is that
83 * the non-monolithic unoptimized shader variant is always available for use
84 * when the asynchronous compilation of the optimized shader is not done
87 * Starting with GFX9 chips, some shader stages are merged, and the number of
88 * shader parts per shader increased. The complete new list of shader parts is:
89 * - 1st shader: prolog part
90 * - 1st shader: main part
91 * - 2nd shader: prolog part
92 * - 2nd shader: main part
93 * - 2nd shader: epilog part
96 /* How linking shader inputs and outputs between vertex, tessellation, and
97 * geometry shaders works.
99 * Inputs and outputs between shaders are stored in a buffer. This buffer
100 * lives in LDS (typical case for tessellation), but it can also live
101 * in memory (ESGS). Each input or output has a fixed location within a vertex.
102 * The highest used input or output determines the stride between vertices.
104 * Since GS and tessellation are only possible in the OpenGL core profile,
105 * only these semantics are valid for per-vertex data:
112 * CULLDIST0..1 (not implemented)
115 * For example, a shader only writing GENERIC0 has the output stride of 5.
117 * Only these semantics are valid for per-patch data:
125 * That's how independent shaders agree on input and output locations.
126 * The si_shader_io_get_unique_index function assigns the locations.
128 * For tessellation, other required information for calculating the input and
129 * output addresses like the vertex stride, the patch stride, and the offsets
130 * where per-vertex and per-patch data start, is passed to the shader via
131 * user data SGPRs. The offsets and strides are calculated at draw time and
132 * aren't available at compile time.
138 #include <llvm-c/Core.h> /* LLVMModuleRef */
139 #include <llvm-c/TargetMachine.h>
140 #include "tgsi/tgsi_scan.h"
141 #include "util/u_queue.h"
143 #include "ac_binary.h"
144 #include "si_state.h"
148 #define SI_MAX_VS_OUTPUTS 40
150 /* Shader IO unique indices are supported for TGSI_SEMANTIC_GENERIC with an
151 * index smaller than this.
153 #define SI_MAX_IO_GENERIC 46
155 /* SGPR user data indices */
157 /* GFX9 merged shaders have RW_BUFFERS among the first 8 system SGPRs,
158 * and these two are used for other purposes.
160 SI_SGPR_RW_BUFFERS
, /* rings (& stream-out, VS only) */
161 SI_SGPR_RW_BUFFERS_HI
,
162 SI_SGPR_BINDLESS_SAMPLERS_AND_IMAGES
,
163 SI_SGPR_BINDLESS_SAMPLERS_AND_IMAGES_HI
,
164 SI_SGPR_CONST_AND_SHADER_BUFFERS
, /* or just a constant buffer 0 pointer */
165 SI_SGPR_CONST_AND_SHADER_BUFFERS_HI
,
166 SI_SGPR_SAMPLERS_AND_IMAGES
,
167 SI_SGPR_SAMPLERS_AND_IMAGES_HI
,
168 SI_NUM_RESOURCE_SGPRS
,
170 /* all VS variants */
171 SI_SGPR_VERTEX_BUFFERS
= SI_NUM_RESOURCE_SGPRS
,
172 SI_SGPR_VERTEX_BUFFERS_HI
,
174 SI_SGPR_START_INSTANCE
,
176 SI_SGPR_VS_STATE_BITS
,
179 SI_SGPR_VS_BLIT_DATA
= SI_SGPR_CONST_AND_SHADER_BUFFERS
,
182 SI_SGPR_TES_OFFCHIP_LAYOUT
= SI_NUM_RESOURCE_SGPRS
,
183 SI_SGPR_TES_OFFCHIP_ADDR_BASE64K
,
184 SI_TES_NUM_USER_SGPR
,
186 /* GFX6-8: TCS only */
187 GFX6_SGPR_TCS_OFFCHIP_LAYOUT
= SI_NUM_RESOURCE_SGPRS
,
188 GFX6_SGPR_TCS_OUT_OFFSETS
,
189 GFX6_SGPR_TCS_OUT_LAYOUT
,
190 GFX6_SGPR_TCS_IN_LAYOUT
,
191 GFX6_SGPR_TCS_OFFCHIP_ADDR_BASE64K
,
192 GFX6_SGPR_TCS_FACTOR_ADDR_BASE64K
,
193 GFX6_TCS_NUM_USER_SGPR
,
195 /* GFX9: Merged LS-HS (VS-TCS) only. */
196 GFX9_SGPR_TCS_OFFCHIP_LAYOUT
= SI_VS_NUM_USER_SGPR
,
197 GFX9_SGPR_TCS_OUT_OFFSETS
,
198 GFX9_SGPR_TCS_OUT_LAYOUT
,
199 GFX9_SGPR_TCS_OFFCHIP_ADDR_BASE64K
,
200 GFX9_SGPR_TCS_FACTOR_ADDR_BASE64K
,
201 GFX9_SGPR_unused_to_align_the_next_pointer
,
202 GFX9_SGPR_TCS_CONST_AND_SHADER_BUFFERS
,
203 GFX9_SGPR_TCS_CONST_AND_SHADER_BUFFERS_HI
,
204 GFX9_SGPR_TCS_SAMPLERS_AND_IMAGES
,
205 GFX9_SGPR_TCS_SAMPLERS_AND_IMAGES_HI
,
206 GFX9_TCS_NUM_USER_SGPR
,
208 /* GFX9: Merged ES-GS (VS-GS or TES-GS). */
209 GFX9_SGPR_GS_CONST_AND_SHADER_BUFFERS
= SI_VS_NUM_USER_SGPR
,
210 GFX9_SGPR_GS_CONST_AND_SHADER_BUFFERS_HI
,
211 GFX9_SGPR_GS_SAMPLERS_AND_IMAGES
,
212 GFX9_SGPR_GS_SAMPLERS_AND_IMAGES_HI
,
213 GFX9_GS_NUM_USER_SGPR
,
216 GFX6_GS_NUM_USER_SGPR
= SI_NUM_RESOURCE_SGPRS
,
217 SI_GSCOPY_NUM_USER_SGPR
= SI_SGPR_RW_BUFFERS_HI
+ 1,
220 SI_SGPR_ALPHA_REF
= SI_NUM_RESOURCE_SGPRS
,
224 /* LLVM function parameter indices */
226 SI_NUM_RESOURCE_PARAMS
= 4,
228 /* PS only parameters */
229 SI_PARAM_ALPHA_REF
= SI_NUM_RESOURCE_PARAMS
,
231 SI_PARAM_PERSP_SAMPLE
,
232 SI_PARAM_PERSP_CENTER
,
233 SI_PARAM_PERSP_CENTROID
,
234 SI_PARAM_PERSP_PULL_MODEL
,
235 SI_PARAM_LINEAR_SAMPLE
,
236 SI_PARAM_LINEAR_CENTER
,
237 SI_PARAM_LINEAR_CENTROID
,
238 SI_PARAM_LINE_STIPPLE_TEX
,
239 SI_PARAM_POS_X_FLOAT
,
240 SI_PARAM_POS_Y_FLOAT
,
241 SI_PARAM_POS_Z_FLOAT
,
242 SI_PARAM_POS_W_FLOAT
,
245 SI_PARAM_SAMPLE_COVERAGE
,
246 SI_PARAM_POS_FIXED_PT
,
248 SI_NUM_PARAMS
= SI_PARAM_POS_FIXED_PT
+ 9, /* +8 for COLOR[0..1] */
251 /* Fields of driver-defined VS state SGPR. */
252 /* Clamp vertex color output (only used in VS as VS). */
253 #define S_VS_STATE_CLAMP_VERTEX_COLOR(x) (((unsigned)(x) & 0x1) << 0)
254 #define C_VS_STATE_CLAMP_VERTEX_COLOR 0xFFFFFFFE
255 #define S_VS_STATE_INDEXED(x) (((unsigned)(x) & 0x1) << 1)
256 #define C_VS_STATE_INDEXED 0xFFFFFFFD
257 #define S_VS_STATE_LS_OUT_PATCH_SIZE(x) (((unsigned)(x) & 0x1FFF) << 8)
258 #define C_VS_STATE_LS_OUT_PATCH_SIZE 0xFFE000FF
259 #define S_VS_STATE_LS_OUT_VERTEX_SIZE(x) (((unsigned)(x) & 0xFF) << 24)
260 #define C_VS_STATE_LS_OUT_VERTEX_SIZE 0x00FFFFFF
262 /* SI-specific system values. */
264 TGSI_SEMANTIC_DEFAULT_TESSOUTER_SI
= TGSI_SEMANTIC_COUNT
,
265 TGSI_SEMANTIC_DEFAULT_TESSINNER_SI
,
269 /* Use a property enum that VS wouldn't use. */
270 TGSI_PROPERTY_VS_BLIT_SGPRS
= TGSI_PROPERTY_FS_COORD_ORIGIN
,
272 /* These represent the number of SGPRs the shader uses. */
273 SI_VS_BLIT_SGPRS_POS
= 3,
274 SI_VS_BLIT_SGPRS_POS_COLOR
= 7,
275 SI_VS_BLIT_SGPRS_POS_TEXCOORD
= 9,
278 /* For VS shader key fix_fetch. */
280 SI_FIX_FETCH_NONE
= 0,
281 SI_FIX_FETCH_A2_SNORM
,
282 SI_FIX_FETCH_A2_SSCALED
,
283 SI_FIX_FETCH_A2_SINT
,
284 SI_FIX_FETCH_RGBA_32_UNORM
,
285 SI_FIX_FETCH_RGBX_32_UNORM
,
286 SI_FIX_FETCH_RGBA_32_SNORM
,
287 SI_FIX_FETCH_RGBX_32_SNORM
,
288 SI_FIX_FETCH_RGBA_32_USCALED
,
289 SI_FIX_FETCH_RGBA_32_SSCALED
,
290 SI_FIX_FETCH_RGBA_32_FIXED
,
291 SI_FIX_FETCH_RGBX_32_FIXED
,
292 SI_FIX_FETCH_RG_64_FLOAT
,
293 SI_FIX_FETCH_RGB_64_FLOAT
,
294 SI_FIX_FETCH_RGBA_64_FLOAT
,
295 SI_FIX_FETCH_RGB_8
, /* A = 1.0 */
296 SI_FIX_FETCH_RGB_8_INT
, /* A = 1 */
298 SI_FIX_FETCH_RGB_16_INT
,
303 /* State of the context creating the shader object. */
304 struct si_compiler_ctx_state
{
305 /* Should only be used by si_init_shader_selector_async and
306 * si_build_shader_variant if thread_index == -1 (non-threaded). */
307 LLVMTargetMachineRef tm
;
309 /* Used if thread_index == -1 or if debug.async is true. */
310 struct pipe_debug_callback debug
;
312 /* Used for creating the log string for gallium/ddebug. */
313 bool is_debug_context
;
316 /* A shader selector is a gallium CSO and contains shader variants and
317 * binaries for one TGSI program. This can be shared by multiple contexts.
319 struct si_shader_selector
{
320 struct pipe_reference reference
;
321 struct si_screen
*screen
;
322 struct util_queue_fence ready
;
323 struct si_compiler_ctx_state compiler_ctx_state
;
326 struct si_shader
*first_variant
; /* immutable after the first variant */
327 struct si_shader
*last_variant
; /* mutable */
329 /* The compiled TGSI shader expecting a prolog and/or epilog (not
330 * uploaded to a buffer).
332 struct si_shader
*main_shader_part
;
333 struct si_shader
*main_shader_part_ls
; /* as_ls is set in the key */
334 struct si_shader
*main_shader_part_es
; /* as_es is set in the key */
336 struct si_shader
*gs_copy_shader
;
338 struct tgsi_token
*tokens
;
339 struct nir_shader
*nir
;
340 struct pipe_stream_output_info so
;
341 struct tgsi_shader_info info
;
342 struct tgsi_tessctrl_info tcs_info
;
344 /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */
346 bool vs_needs_prolog
;
347 unsigned pa_cl_vs_out_cntl
;
352 unsigned esgs_itemsize
;
353 unsigned gs_input_verts_per_prim
;
354 unsigned gs_output_prim
;
355 unsigned gs_max_out_vertices
;
356 unsigned gs_num_invocations
;
357 unsigned max_gs_stream
; /* count - 1 */
358 unsigned gsvs_vertex_size
;
359 unsigned max_gsvs_emit_size
;
360 unsigned enabled_streamout_buffer_mask
;
363 unsigned color_attr_index
[2];
364 unsigned db_shader_control
;
365 /* Set 0xf or 0x0 (4 bits) per each written output.
366 * ANDed with spi_shader_col_format.
368 unsigned colors_written_4bit
;
373 uint64_t outputs_written
; /* "get_unique_index" bits */
374 uint32_t patch_outputs_written
; /* "get_unique_index_patch" bits */
376 uint64_t inputs_read
; /* "get_unique_index" bits */
378 /* bitmasks of used descriptor slots */
379 uint32_t active_const_and_shader_buffers
;
380 uint64_t active_samplers_and_images
;
383 /* Valid shader configurations:
385 * API shaders VS | TCS | TES | GS |pass| PS
386 * are compiled as: | | | |thru|
388 * Only VS & PS: VS | | | | | PS
389 * GFX6 - with GS: ES | | | GS | VS | PS
390 * - with tess: LS | HS | VS | | | PS
391 * - with both: LS | HS | ES | GS | VS | PS
392 * GFX9 - with GS: -> | | | GS | VS | PS
393 * - with tess: -> | HS | VS | | | PS
394 * - with both: -> | HS | -> | GS | VS | PS
396 * -> = merged with the next stage
399 /* Use the byte alignment for all following structure members for optimal
400 * shader key memory footprint.
402 #pragma pack(push, 1)
404 /* Common VS bits between the shader key and the prolog key. */
405 struct si_vs_prolog_bits
{
406 /* - If neither "is_one" nor "is_fetched" has a bit set, the instance
408 * - If "is_one" has a bit set, the instance divisor is 1.
409 * - If "is_fetched" has a bit set, the instance divisor will be loaded
410 * from the constant buffer.
412 uint16_t instance_divisor_is_one
; /* bitmask of inputs */
413 uint16_t instance_divisor_is_fetched
; /* bitmask of inputs */
414 unsigned ls_vgpr_fix
:1;
417 /* Common TCS bits between the shader key and the epilog key. */
418 struct si_tcs_epilog_bits
{
419 unsigned prim_mode
:3;
420 unsigned invoc0_tess_factors_are_def
:1;
421 unsigned tes_reads_tess_factors
:1;
424 struct si_gs_prolog_bits
{
425 unsigned tri_strip_adj_fix
:1;
428 /* Common PS bits between the shader key and the prolog key. */
429 struct si_ps_prolog_bits
{
430 unsigned color_two_side
:1;
431 unsigned flatshade_colors
:1;
432 unsigned poly_stipple
:1;
433 unsigned force_persp_sample_interp
:1;
434 unsigned force_linear_sample_interp
:1;
435 unsigned force_persp_center_interp
:1;
436 unsigned force_linear_center_interp
:1;
437 unsigned bc_optimize_for_persp
:1;
438 unsigned bc_optimize_for_linear
:1;
439 unsigned samplemask_log_ps_iter
:3;
442 /* Common PS bits between the shader key and the epilog key. */
443 struct si_ps_epilog_bits
{
444 unsigned spi_shader_col_format
;
445 unsigned color_is_int8
:8;
446 unsigned color_is_int10
:8;
447 unsigned last_cbuf
:3;
448 unsigned alpha_func
:3;
449 unsigned alpha_to_one
:1;
450 unsigned poly_line_smoothing
:1;
451 unsigned clamp_color
:1;
454 union si_shader_part_key
{
456 struct si_vs_prolog_bits states
;
457 unsigned num_input_sgprs
:6;
458 /* For merged stages such as LS-HS, HS input VGPRs are first. */
459 unsigned num_merged_next_stage_vgprs
:3;
460 unsigned last_input
:4;
462 /* Prologs for monolithic shaders shouldn't set EXEC. */
463 unsigned is_monolithic
:1;
466 struct si_tcs_epilog_bits states
;
469 struct si_gs_prolog_bits states
;
470 /* Prologs of monolithic shaders shouldn't set EXEC. */
471 unsigned is_monolithic
:1;
474 struct si_ps_prolog_bits states
;
475 unsigned num_input_sgprs
:6;
476 unsigned num_input_vgprs
:5;
477 /* Color interpolation and two-side color selection. */
478 unsigned colors_read
:8; /* color input components read */
479 unsigned num_interp_inputs
:5; /* BCOLOR is at this location */
480 unsigned face_vgpr_index
:5;
481 unsigned ancillary_vgpr_index
:5;
483 char color_attr_index
[2];
484 char color_interp_vgpr_index
[2]; /* -1 == constant */
487 struct si_ps_epilog_bits states
;
488 unsigned colors_written
:8;
490 unsigned writes_stencil
:1;
491 unsigned writes_samplemask
:1;
495 struct si_shader_key
{
496 /* Prolog and epilog flags. */
499 struct si_vs_prolog_bits prolog
;
502 struct si_vs_prolog_bits ls_prolog
; /* for merged LS-HS */
503 struct si_shader_selector
*ls
; /* for merged LS-HS */
504 struct si_tcs_epilog_bits epilog
;
505 } tcs
; /* tessellation control shader */
507 struct si_vs_prolog_bits vs_prolog
; /* for merged ES-GS */
508 struct si_shader_selector
*es
; /* for merged ES-GS */
509 struct si_gs_prolog_bits prolog
;
512 struct si_ps_prolog_bits prolog
;
513 struct si_ps_epilog_bits epilog
;
517 /* These two are initially set according to the NEXT_SHADER property,
518 * or guessed if the property doesn't seem correct.
520 unsigned as_es
:1; /* export shader, which precedes GS */
521 unsigned as_ls
:1; /* local shader, which precedes TCS */
523 /* Flags for monolithic compilation only. */
525 /* One byte for every input: SI_FIX_FETCH_* enums. */
526 uint8_t vs_fix_fetch
[SI_MAX_ATTRIBS
];
529 uint64_t ff_tcs_inputs_to_copy
; /* for fixed-func TCS */
530 /* When PS needs PrimID and GS is disabled. */
531 unsigned vs_export_prim_id
:1;
533 unsigned interpolate_at_sample_force_center
:1;
538 /* Optimization flags for asynchronous compilation only. */
540 /* For HW VS (it can be VS, TES, GS) */
541 uint64_t kill_outputs
; /* "get_unique_index" bits */
542 unsigned clip_disable
:1;
544 /* For shaders where monolithic variants have better code.
546 * This is a flag that has no effect on code generation,
547 * but forces monolithic shaders to be used as soon as
548 * possible, because it's in the "opt" group.
550 unsigned prefer_mono
:1;
554 /* Restore the pack alignment to default. */
557 struct si_shader_config
{
560 unsigned spilled_sgprs
;
561 unsigned spilled_vgprs
;
562 unsigned private_mem_vgprs
;
564 unsigned spi_ps_input_ena
;
565 unsigned spi_ps_input_addr
;
567 unsigned scratch_bytes_per_wave
;
572 /* GCN-specific shader info. */
573 struct si_shader_info
{
574 ubyte vs_output_param_offset
[SI_MAX_VS_OUTPUTS
];
575 ubyte num_input_sgprs
;
576 ubyte num_input_vgprs
;
577 signed char face_vgpr_index
;
578 signed char ancillary_vgpr_index
;
579 bool uses_instanceid
;
580 ubyte nr_pos_exports
;
581 ubyte nr_param_exports
;
585 struct si_compiler_ctx_state compiler_ctx_state
;
587 struct si_shader_selector
*selector
;
588 struct si_shader_selector
*previous_stage_sel
; /* for refcounting */
589 struct si_shader
*next_variant
;
591 struct si_shader_part
*prolog
;
592 struct si_shader
*previous_stage
; /* for GFX9 */
593 struct si_shader_part
*prolog2
;
594 struct si_shader_part
*epilog
;
596 struct si_pm4_state
*pm4
;
597 struct r600_resource
*bo
;
598 struct r600_resource
*scratch_bo
;
599 struct si_shader_key key
;
600 struct util_queue_fence optimized_ready
;
601 bool compilation_failed
;
604 bool is_binary_shared
;
605 bool is_gs_copy_shader
;
607 /* The following data is all that's needed for binary shaders. */
608 struct ac_shader_binary binary
;
609 struct si_shader_config config
;
610 struct si_shader_info info
;
612 /* Shader key + LLVM IR + disassembly + statistics.
613 * Generated for debug contexts only.
616 size_t shader_log_size
;
619 struct si_shader_part
{
620 struct si_shader_part
*next
;
621 union si_shader_part_key key
;
622 struct ac_shader_binary binary
;
623 struct si_shader_config config
;
628 si_generate_gs_copy_shader(struct si_screen
*sscreen
,
629 LLVMTargetMachineRef tm
,
630 struct si_shader_selector
*gs_selector
,
631 struct pipe_debug_callback
*debug
);
632 int si_compile_tgsi_shader(struct si_screen
*sscreen
,
633 LLVMTargetMachineRef tm
,
634 struct si_shader
*shader
,
636 struct pipe_debug_callback
*debug
);
637 int si_shader_create(struct si_screen
*sscreen
, LLVMTargetMachineRef tm
,
638 struct si_shader
*shader
,
639 struct pipe_debug_callback
*debug
);
640 void si_shader_destroy(struct si_shader
*shader
);
641 unsigned si_shader_io_get_unique_index_patch(unsigned semantic_name
, unsigned index
);
642 unsigned si_shader_io_get_unique_index(unsigned semantic_name
, unsigned index
);
643 int si_shader_binary_upload(struct si_screen
*sscreen
, struct si_shader
*shader
);
644 void si_shader_dump(struct si_screen
*sscreen
, const struct si_shader
*shader
,
645 struct pipe_debug_callback
*debug
, unsigned processor
,
646 FILE *f
, bool check_debug_option
);
647 void si_multiwave_lds_size_workaround(struct si_screen
*sscreen
,
649 void si_shader_apply_scratch_relocs(struct si_shader
*shader
,
650 uint64_t scratch_va
);
651 void si_shader_binary_read_config(struct ac_shader_binary
*binary
,
652 struct si_shader_config
*conf
,
653 unsigned symbol_offset
);
654 unsigned si_get_spi_shader_z_format(bool writes_z
, bool writes_stencil
,
655 bool writes_samplemask
);
656 const char *si_get_shader_name(const struct si_shader
*shader
, unsigned processor
);
658 /* si_shader_nir.c */
659 void si_nir_scan_shader(const struct nir_shader
*nir
,
660 struct tgsi_shader_info
*info
);
661 void si_lower_nir(struct si_shader_selector
*sel
);
663 /* Inline helpers. */
665 /* Return the pointer to the main shader part's pointer. */
666 static inline struct si_shader
**
667 si_get_main_shader_part(struct si_shader_selector
*sel
,
668 struct si_shader_key
*key
)
671 return &sel
->main_shader_part_ls
;
673 return &sel
->main_shader_part_es
;
674 return &sel
->main_shader_part
;
678 si_shader_uses_bindless_samplers(struct si_shader_selector
*selector
)
680 return selector
? selector
->info
.uses_bindless_samplers
: false;
684 si_shader_uses_bindless_images(struct si_shader_selector
*selector
)
686 return selector
? selector
->info
.uses_bindless_images
: false;
689 void si_destroy_shader_selector(struct si_context
*sctx
,
690 struct si_shader_selector
*sel
);
693 si_shader_selector_reference(struct si_context
*sctx
,
694 struct si_shader_selector
**dst
,
695 struct si_shader_selector
*src
)
697 if (pipe_reference(&(*dst
)->reference
, &src
->reference
))
698 si_destroy_shader_selector(sctx
, *dst
);