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, max = 63 62 * # 6 bits 63 * [23:28] = the number of HS per-vertex outputs, 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 void si_add_arg_checked(struct ac_shader_args *args, enum ac_arg_regfile file, unsigned registers, 96 enum ac_arg_type type, struct ac_arg *arg, unsigned idx); 97 void si_init_shader_args(struct si_shader *shader, struct si_shader_args *args); 98 unsigned si_get_max_workgroup_size(const struct si_shader *shader); 99 struct nir_shader *si_get_nir_shader(struct si_shader *shader, struct si_shader_args *args, 100 bool *free_nir, uint64_t tcs_vgpr_only_inputs, 101 ac_nir_gs_output_info *output_info); 102 bool si_need_ps_prolog(const union si_shader_part_key *key); 103 void si_get_ps_prolog_key(struct si_shader *shader, union si_shader_part_key *key); 104 void si_get_ps_epilog_key(struct si_shader *shader, union si_shader_part_key *key); 105 enum ac_hw_stage si_select_hw_stage(const gl_shader_stage stage, const union si_shader_key *const key, 106 const enum amd_gfx_level gfx_level); 107 nir_shader *si_get_prev_stage_nir_shader(struct si_shader *shader, 108 struct si_shader *prev_shader, 109 struct si_shader_args *args, 110 bool *free_nir); 111 unsigned si_get_tcs_out_patch_stride(const struct si_shader_info *info); 112 void si_get_ps_prolog_args(struct si_shader_args *args, 113 const union si_shader_part_key *key); 114 void si_get_ps_epilog_args(struct si_shader_args *args, 115 const union si_shader_part_key *key, 116 struct ac_arg colors[MAX_DRAW_BUFFERS], 117 struct ac_arg *depth, struct ac_arg *stencil, 118 struct ac_arg *sample_mask); 119 120 /* gfx10_shader_ngg.c */ 121 unsigned gfx10_ngg_get_vertices_per_prim(struct si_shader *shader); 122 bool gfx10_ngg_export_prim_early(struct si_shader *shader); 123 unsigned gfx10_ngg_get_scratch_dw_size(struct si_shader *shader); 124 bool gfx10_ngg_calculate_subgroup_info(struct si_shader *shader); 125 126 /* si_nir_lower_abi.c */ 127 nir_def *si_nir_load_internal_binding(nir_builder *b, struct si_shader_args *args, 128 unsigned slot, unsigned num_components); 129 bool si_nir_lower_abi(nir_shader *nir, struct si_shader *shader, struct si_shader_args *args); 130 131 /* si_nir_lower_resource.c */ 132 bool si_nir_lower_resource(nir_shader *nir, struct si_shader *shader, 133 struct si_shader_args *args); 134 135 /* si_nir_lower_vs_inputs.c */ 136 bool si_nir_lower_vs_inputs(nir_shader *nir, struct si_shader *shader, 137 struct si_shader_args *args); 138 139 /* si_shader_llvm.c */ 140 bool si_llvm_compile_shader(struct si_screen *sscreen, struct ac_llvm_compiler *compiler, 141 struct si_shader *shader, struct si_shader_args *args, 142 struct util_debug_callback *debug, struct nir_shader *nir); 143 bool si_llvm_build_shader_part(struct si_screen *sscreen, gl_shader_stage stage, 144 bool prolog, struct ac_llvm_compiler *compiler, 145 struct util_debug_callback *debug, const char *name, 146 struct si_shader_part *result); 147 148 /* si_shader_aco.c */ 149 bool si_aco_compile_shader(struct si_shader *shader, 150 struct si_shader_args *args, 151 struct nir_shader *nir, 152 struct util_debug_callback *debug); 153 void si_aco_resolve_symbols(struct si_shader *shader, uint32_t *code_for_write, 154 const uint32_t *code_for_read, uint64_t scratch_va, 155 uint32_t const_offset); 156 bool si_aco_build_shader_part(struct si_screen *screen, gl_shader_stage stage, bool prolog, 157 struct util_debug_callback *debug, const char *name, 158 struct si_shader_part *result); 159 160 #endif 161