• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Advanced Micro Devices, Inc.
3  *
4  * SPDX-License-Identifier: MIT
5  */
6 
7 #ifndef SI_SHADER_PRIVATE_H
8 #define SI_SHADER_PRIVATE_H
9 
10 #include "ac_hw_stage.h"
11 #include "ac_shader_args.h"
12 #include "ac_shader_util.h"
13 #include "si_shader.h"
14 
15 #define SI_SPI_PS_INPUT_ADDR_FOR_PROLOG (       \
16    S_0286D0_PERSP_SAMPLE_ENA(1) |               \
17    S_0286D0_PERSP_CENTER_ENA(1) |               \
18    S_0286D0_PERSP_CENTROID_ENA(1) |             \
19    S_0286D0_LINEAR_SAMPLE_ENA(1) |              \
20    S_0286D0_LINEAR_CENTER_ENA(1) |              \
21    S_0286D0_LINEAR_CENTROID_ENA(1) |            \
22    S_0286D0_FRONT_FACE_ENA(1) |                 \
23    S_0286D0_ANCILLARY_ENA(1) |                  \
24    S_0286D0_SAMPLE_COVERAGE_ENA(1) |            \
25    S_0286D0_POS_FIXED_PT_ENA(1))
26 
27 struct util_debug_callback;
28 
29 struct si_shader_args {
30    struct ac_shader_args ac;
31 
32    struct ac_arg const_and_shader_buffers;
33    struct ac_arg samplers_and_images;
34 
35    /* For merged shaders, the per-stage descriptors for the stage other
36     * than the one we're processing, used to pass them through from the
37     * first stage to the second.
38     */
39    struct ac_arg other_const_and_shader_buffers;
40    struct ac_arg other_samplers_and_images;
41 
42    struct ac_arg internal_bindings;
43    struct ac_arg bindless_samplers_and_images;
44    struct ac_arg small_prim_cull_info;
45    struct ac_arg gs_attr_address;
46    /* API VS */
47    struct ac_arg vb_descriptors[5];
48    /* VS state bits. See the VS_STATE_* and GS_STATE_* definitions. */
49    struct ac_arg vs_state_bits;
50    struct ac_arg vs_blit_inputs;
51 
52    /* API TCS & TES */
53    /* Layout of TCS outputs in the offchip buffer
54     * # 6 bits
55     *   [0:5] = the number of patches per threadgroup - 1, max = 63
56     * # 5 bits
57     *   [6:10] = the number of output vertices per patch - 1, max = 31
58     * # 5 bits
59     *   [11:15] = the number of input vertices per patch - 1, max = 31 (TCS only)
60     * # 16 bits
61     *   [16:31] = the offset of per patch attributes in the buffer in bytes.
62     *       64 outputs are implied by SI_UNIQUE_SLOT_* values.
63     *       max = 32(CPs) * 64(outputs) * 16(vec4) * 64(num_patches) = 2M,
64     *       clamped to 32K(LDS limit) = 32K
65     */
66    struct ac_arg tcs_offchip_layout;
67 
68    /* API TCS & TES */
69    struct ac_arg tes_offchip_addr;
70    /* PS */
71    struct ac_arg alpha_reference;
72    struct ac_arg color_start;
73    /* CS */
74    struct ac_arg block_size;
75    struct ac_arg cs_user_data;
76    struct ac_arg cs_shaderbuf[3];
77    struct ac_arg cs_image[3];
78 };
79 
80 struct ac_nir_gs_output_info;
81 typedef struct ac_nir_gs_output_info ac_nir_gs_output_info;
82 
83 struct nir_builder;
84 typedef struct nir_builder nir_builder;
85 
86 struct nir_shader;
87 typedef struct nir_shader nir_shader;
88 
89 /* si_shader.c */
90 bool si_is_multi_part_shader(struct si_shader *shader);
91 bool si_is_merged_shader(struct si_shader *shader);
92 void si_add_arg_checked(struct ac_shader_args *args, enum ac_arg_regfile file, unsigned registers,
93                         enum ac_arg_type type, struct ac_arg *arg, unsigned idx);
94 void si_init_shader_args(struct si_shader *shader, struct si_shader_args *args);
95 unsigned si_get_max_workgroup_size(const struct si_shader *shader);
96 struct nir_shader *si_get_nir_shader(struct si_shader *shader, struct si_shader_args *args,
97                                      bool *free_nir, uint64_t tcs_vgpr_only_inputs,
98                                      ac_nir_gs_output_info *output_info);
99 void si_get_tcs_epilog_key(struct si_shader *shader, union si_shader_part_key *key);
100 bool si_need_ps_prolog(const union si_shader_part_key *key);
101 void si_get_ps_prolog_key(struct si_shader *shader, union si_shader_part_key *key);
102 void si_get_ps_epilog_key(struct si_shader *shader, union si_shader_part_key *key);
103 enum ac_hw_stage si_select_hw_stage(const gl_shader_stage stage, const union si_shader_key *const key,
104                                     const enum amd_gfx_level gfx_level);
105 nir_shader *si_get_prev_stage_nir_shader(struct si_shader *shader,
106                                          struct si_shader *prev_shader,
107                                          struct si_shader_args *args,
108                                          bool *free_nir);
109 unsigned si_get_tcs_out_patch_stride(const struct si_shader_info *info);
110 void si_get_tcs_epilog_args(enum amd_gfx_level gfx_level,
111                             struct si_shader_args *args,
112                             struct ac_arg *rel_patch_id,
113                             struct ac_arg *invocation_id,
114                             struct ac_arg *tf_lds_offset,
115                             struct ac_arg tess_factors[6]);
116 void si_get_ps_prolog_args(struct si_shader_args *args,
117                            const union si_shader_part_key *key);
118 void si_get_ps_epilog_args(struct si_shader_args *args,
119                            const union si_shader_part_key *key,
120                            struct ac_arg colors[MAX_DRAW_BUFFERS],
121                            struct ac_arg *depth, struct ac_arg *stencil,
122                            struct ac_arg *sample_mask);
123 
124 /* gfx10_shader_ngg.c */
125 unsigned gfx10_ngg_get_vertices_per_prim(struct si_shader *shader);
126 bool gfx10_ngg_export_prim_early(struct si_shader *shader);
127 unsigned gfx10_ngg_get_scratch_dw_size(struct si_shader *shader);
128 bool gfx10_ngg_calculate_subgroup_info(struct si_shader *shader);
129 
130 /* si_nir_lower_abi.c */
131 nir_def *si_nir_load_internal_binding(nir_builder *b, struct si_shader_args *args,
132                                           unsigned slot, unsigned num_components);
133 bool si_nir_lower_abi(nir_shader *nir, struct si_shader *shader, struct si_shader_args *args);
134 
135 /* si_nir_lower_resource.c */
136 bool si_nir_lower_resource(nir_shader *nir, struct si_shader *shader,
137                            struct si_shader_args *args);
138 
139 /* si_nir_lower_vs_inputs.c */
140 bool si_nir_lower_vs_inputs(nir_shader *nir, struct si_shader *shader,
141                             struct si_shader_args *args);
142 
143 /* si_shader_llvm.c */
144 bool si_llvm_compile_shader(struct si_screen *sscreen, struct ac_llvm_compiler *compiler,
145                             struct si_shader *shader, struct si_shader_args *args,
146                             struct util_debug_callback *debug, struct nir_shader *nir);
147 bool si_llvm_build_shader_part(struct si_screen *sscreen, gl_shader_stage stage,
148                                bool prolog, struct ac_llvm_compiler *compiler,
149                                struct util_debug_callback *debug, const char *name,
150                                struct si_shader_part *result);
151 
152 /* si_shader_aco.c */
153 bool si_aco_compile_shader(struct si_shader *shader,
154                            struct si_shader_args *args,
155                            struct nir_shader *nir,
156                            struct util_debug_callback *debug);
157 void si_aco_resolve_symbols(struct si_shader *shader, uint32_t *code_for_write,
158                             const uint32_t *code_for_read, uint64_t scratch_va,
159                             uint32_t const_offset);
160 bool si_aco_build_shader_part(struct si_screen *screen, gl_shader_stage stage, bool prolog,
161                               struct util_debug_callback *debug, const char *name,
162                               struct si_shader_part *result);
163 
164 #endif
165