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_nir.h" 11 #include "si_shader.h" 12 13 #define SI_SPI_PS_INPUT_ADDR_FOR_PROLOG ( \ 14 S_0286D0_PERSP_SAMPLE_ENA(1) | \ 15 S_0286D0_PERSP_CENTER_ENA(1) | \ 16 S_0286D0_PERSP_CENTROID_ENA(1) | \ 17 S_0286D0_LINEAR_SAMPLE_ENA(1) | \ 18 S_0286D0_LINEAR_CENTER_ENA(1) | \ 19 S_0286D0_LINEAR_CENTROID_ENA(1) | \ 20 S_0286D0_FRONT_FACE_ENA(1) | \ 21 S_0286D0_ANCILLARY_ENA(1) | \ 22 S_0286D0_SAMPLE_COVERAGE_ENA(1) | \ 23 S_0286D0_POS_FIXED_PT_ENA(1)) 24 25 struct util_debug_callback; 26 27 struct si_shader_args { 28 struct ac_shader_args ac; 29 30 struct ac_arg const_and_shader_buffers; 31 struct ac_arg samplers_and_images; 32 33 /* For merged shaders, the per-stage descriptors for the stage other 34 * than the one we're processing, used to pass them through from the 35 * first stage to the second. 36 */ 37 struct ac_arg other_const_and_shader_buffers; 38 struct ac_arg other_samplers_and_images; 39 40 struct ac_arg internal_bindings; 41 struct ac_arg bindless_samplers_and_images; 42 struct ac_arg small_prim_cull_info; 43 struct ac_arg gs_attr_address; 44 /* API VS */ 45 struct ac_arg vb_descriptors[5]; 46 /* VS state bits. See the VS_STATE_* and GS_STATE_* definitions. */ 47 struct ac_arg vs_state_bits; 48 struct ac_arg vs_blit_inputs; 49 50 /* API TCS & TES */ 51 /* Layout of TCS outputs in the offchip buffer 52 * # 7 bits 53 * [0:6] = the number of patches per threadgroup - 1, max = 127 54 * # 5 bits 55 * [7:11] = the number of output vertices per patch - 1, max = 31 56 * # 5 bits 57 * [12:16] = the number of input vertices per patch - 1, max = 31 (TCS only) 58 * # 6 bits 59 * [17:22] = the number of LS outputs in LDS, max = 63 60 * # 6 bits 61 * [23:28] = the number of HS per-vertex outputs in memory, max = 63 62 * # 2 bits 63 * [29:30] = TES output primitive type 64 * # 1 bit 65 * [31] = whether TES reads tess factor outputs from TCS 66 */ 67 struct ac_arg tcs_offchip_layout; 68 69 /* API TCS & TES */ 70 struct ac_arg tes_offchip_addr; 71 /* PS */ 72 struct ac_arg sample_locs[2]; 73 struct ac_arg alpha_reference; 74 struct ac_arg color_start; 75 /* CS */ 76 struct ac_arg block_size; 77 struct ac_arg cs_user_data[2]; 78 struct ac_arg cs_shaderbuf[3]; 79 struct ac_arg cs_image[3]; 80 }; 81 82 struct si_gs_output_info { 83 uint8_t streams[64]; 84 uint8_t streams_16bit_lo[16]; 85 uint8_t streams_16bit_hi[16]; 86 87 uint8_t usage_mask[64]; 88 uint8_t usage_mask_16bit_lo[16]; 89 uint8_t usage_mask_16bit_hi[16]; 90 91 ac_nir_gs_output_info info; 92 }; 93 94 struct si_nir_shader_ctx { 95 struct si_shader *shader; 96 struct si_shader_args args; 97 struct si_gs_output_info legacy_gs_output_info; 98 nir_shader *nir; 99 bool free_nir; 100 }; 101 102 #define SI_NUM_LINKED_SHADERS 2 103 104 struct si_linked_shaders { 105 /* Temporary si_shader for the first shader of merged shaders. */ 106 struct si_shader producer_shader; 107 108 union { 109 struct { 110 struct si_nir_shader_ctx producer; 111 struct si_nir_shader_ctx consumer; 112 }; 113 struct si_nir_shader_ctx shader[SI_NUM_LINKED_SHADERS]; 114 }; 115 }; 116 117 struct nir_builder; 118 typedef struct nir_builder nir_builder; 119 120 struct nir_shader; 121 typedef struct nir_shader nir_shader; 122 123 /* si_shader.c */ 124 bool si_is_multi_part_shader(struct si_shader *shader); 125 bool si_is_merged_shader(struct si_shader *shader); 126 unsigned si_get_max_workgroup_size(const struct si_shader *shader); 127 enum ac_hw_stage si_select_hw_stage(const gl_shader_stage stage, const union si_shader_key *const key, 128 const enum amd_gfx_level gfx_level); 129 void si_get_ps_prolog_args(struct si_shader_args *args, 130 const union si_shader_part_key *key); 131 void si_get_ps_epilog_args(struct si_shader_args *args, 132 const union si_shader_part_key *key, 133 struct ac_arg colors[MAX_DRAW_BUFFERS], 134 struct ac_arg *depth, struct ac_arg *stencil, 135 struct ac_arg *sample_mask); 136 137 /* gfx10_shader_ngg.c */ 138 bool gfx10_ngg_export_prim_early(struct si_shader *shader); 139 unsigned gfx10_ngg_get_scratch_dw_size(struct si_shader *shader); 140 bool gfx10_ngg_calculate_subgroup_info(struct si_shader *shader); 141 142 struct nir_def; 143 typedef struct nir_def nir_def; 144 145 /* si_nir_lower_abi.c */ 146 nir_def *si_nir_load_internal_binding(nir_builder *b, struct si_shader_args *args, 147 unsigned slot, unsigned num_components); 148 bool si_nir_lower_abi(nir_shader *nir, struct si_shader *shader, struct si_shader_args *args); 149 150 /* si_nir_lower_resource.c */ 151 bool si_nir_lower_resource(nir_shader *nir, struct si_shader *shader, 152 struct si_shader_args *args); 153 154 /* si_nir_lower_vs_inputs.c */ 155 bool si_nir_lower_vs_inputs(nir_shader *nir, struct si_shader *shader, 156 struct si_shader_args *args); 157 158 /* si_shader_llvm.c */ 159 bool si_llvm_compile_shader(struct si_screen *sscreen, struct ac_llvm_compiler *compiler, 160 struct si_shader *shader, struct si_linked_shaders *linked, 161 struct util_debug_callback *debug); 162 bool si_llvm_build_shader_part(struct si_screen *sscreen, gl_shader_stage stage, 163 bool prolog, struct ac_llvm_compiler *compiler, 164 struct util_debug_callback *debug, const char *name, 165 struct si_shader_part *result); 166 167 /* si_shader_aco.c */ 168 bool si_aco_compile_shader(struct si_shader *shader, struct si_linked_shaders *linked, 169 struct util_debug_callback *debug); 170 void si_aco_resolve_symbols(struct si_shader *shader, uint32_t *code_for_write, 171 const uint32_t *code_for_read, uint64_t scratch_va, 172 uint32_t const_offset); 173 bool si_aco_build_shader_part(struct si_screen *screen, gl_shader_stage stage, bool prolog, 174 struct util_debug_callback *debug, const char *name, 175 struct si_shader_part *result); 176 177 #endif 178