• 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     * # 7 bits
55     *   [0:6] = the number of patches per threadgroup - 1, max = 127
56     * # 5 bits
57     *   [7:11] = the number of output vertices per patch - 1, max = 31
58     * # 5 bits
59     *   [12:16] = the number of input vertices per patch - 1, max = 31 (TCS only)
60     * # 6 bits
61     *   [17:22] = the number of LS outputs in LDS, max = 63
62     * # 6 bits
63     *   [23:28] = the number of HS per-vertex outputs in memory, max = 63
64     * # 2 bits
65     *   [29:30] = TES output primitive type
66     * # 1 bit
67     *   [31] = whether TES reads tess factor outputs from TCS
68     */
69    struct ac_arg tcs_offchip_layout;
70 
71    /* API TCS & TES */
72    struct ac_arg tes_offchip_addr;
73    /* PS */
74    struct ac_arg alpha_reference;
75    struct ac_arg color_start;
76    /* CS */
77    struct ac_arg block_size;
78    struct ac_arg cs_user_data[2];
79    struct ac_arg cs_shaderbuf[3];
80    struct ac_arg cs_image[3];
81 };
82 
83 struct ac_nir_gs_output_info;
84 typedef struct ac_nir_gs_output_info ac_nir_gs_output_info;
85 
86 struct nir_builder;
87 typedef struct nir_builder nir_builder;
88 
89 struct nir_shader;
90 typedef struct nir_shader nir_shader;
91 
92 /* si_shader.c */
93 bool si_is_multi_part_shader(struct si_shader *shader);
94 bool si_is_merged_shader(struct si_shader *shader);
95 unsigned si_get_max_workgroup_size(const struct si_shader *shader);
96 enum ac_hw_stage si_select_hw_stage(const gl_shader_stage stage, const union si_shader_key *const key,
97                                     const enum amd_gfx_level gfx_level);
98 nir_shader *si_get_prev_stage_nir_shader(struct si_shader *shader,
99                                          struct si_shader *prev_shader,
100                                          struct si_shader_args *args,
101                                          bool *free_nir);
102 void si_get_ps_prolog_args(struct si_shader_args *args,
103                            const union si_shader_part_key *key);
104 void si_get_ps_epilog_args(struct si_shader_args *args,
105                            const union si_shader_part_key *key,
106                            struct ac_arg colors[MAX_DRAW_BUFFERS],
107                            struct ac_arg *depth, struct ac_arg *stencil,
108                            struct ac_arg *sample_mask);
109 
110 /* gfx10_shader_ngg.c */
111 bool gfx10_ngg_export_prim_early(struct si_shader *shader);
112 unsigned gfx10_ngg_get_scratch_dw_size(struct si_shader *shader);
113 bool gfx10_ngg_calculate_subgroup_info(struct si_shader *shader);
114 
115 struct nir_def;
116 typedef struct nir_def nir_def;
117 
118 /* si_nir_lower_abi.c */
119 nir_def *si_nir_load_internal_binding(nir_builder *b, struct si_shader_args *args,
120                                           unsigned slot, unsigned num_components);
121 bool si_nir_lower_abi(nir_shader *nir, struct si_shader *shader, struct si_shader_args *args);
122 
123 /* si_nir_lower_resource.c */
124 bool si_nir_lower_resource(nir_shader *nir, struct si_shader *shader,
125                            struct si_shader_args *args);
126 
127 /* si_nir_lower_vs_inputs.c */
128 bool si_nir_lower_vs_inputs(nir_shader *nir, struct si_shader *shader,
129                             struct si_shader_args *args);
130 
131 /* si_shader_llvm.c */
132 bool si_llvm_compile_shader(struct si_screen *sscreen, struct ac_llvm_compiler *compiler,
133                             struct si_shader *shader, struct si_shader_args *args,
134                             struct util_debug_callback *debug, struct nir_shader *nir);
135 bool si_llvm_build_shader_part(struct si_screen *sscreen, gl_shader_stage stage,
136                                bool prolog, struct ac_llvm_compiler *compiler,
137                                struct util_debug_callback *debug, const char *name,
138                                struct si_shader_part *result);
139 
140 /* si_shader_aco.c */
141 bool si_aco_compile_shader(struct si_shader *shader,
142                            struct si_shader_args *args,
143                            struct nir_shader *nir,
144                            struct util_debug_callback *debug);
145 void si_aco_resolve_symbols(struct si_shader *shader, uint32_t *code_for_write,
146                             const uint32_t *code_for_read, uint64_t scratch_va,
147                             uint32_t const_offset);
148 bool si_aco_build_shader_part(struct si_screen *screen, gl_shader_stage stage, bool prolog,
149                               struct util_debug_callback *debug, const char *name,
150                               struct si_shader_part *result);
151 
152 #endif
153