1 /* 2 * Copyright © 2016 Red Hat. 3 * Copyright © 2016 Bas Nieuwenhuizen 4 * SPDX-License-Identifier: MIT 5 * 6 * based in part on anv driver which is: 7 * Copyright © 2015 Intel Corporation 8 */ 9 10 #ifndef TU_SHADER_H 11 #define TU_SHADER_H 12 13 #include "tu_common.h" 14 #include "tu_cs.h" 15 #include "tu_suballoc.h" 16 #include "tu_descriptor_set.h" 17 18 struct tu_inline_ubo 19 { 20 /* Push the data at BINDLESS_BASE[base] + offset */ 21 unsigned base; 22 unsigned offset; 23 24 /* If true, push the base address instead */ 25 bool push_address; 26 27 /* Push it to this location in the const file, in vec4s */ 28 unsigned const_offset_vec4; 29 30 /* How much to push */ 31 unsigned size_vec4; 32 }; 33 34 /* The meaning of the range depends on "type". If it's 35 * IR3_PUSH_CONSTS_PER_STAGE, then it's the range used by this shader. If 36 * it's IR3_PUSH_CONSTS_SHARED then it's the overall range as provided by 37 * the pipeline layout and must match between shaders where it's non-zero. 38 */ 39 struct tu_push_constant_range 40 { 41 uint32_t lo_dwords; 42 uint32_t dwords; 43 enum ir3_push_consts_type type; 44 }; 45 46 struct tu_const_state 47 { 48 struct tu_push_constant_range push_consts; 49 uint32_t dynamic_offset_loc; 50 unsigned num_inline_ubos; 51 struct tu_inline_ubo ubos[MAX_INLINE_UBOS]; 52 53 struct ir3_driver_ubo fdm_ubo; 54 struct ir3_driver_ubo dynamic_offsets_ubo; 55 struct ir3_driver_ubo inline_uniforms_ubo; 56 }; 57 58 struct tu_shader 59 { 60 struct vk_pipeline_cache_object base; 61 62 const struct ir3_shader_variant *variant; 63 const struct ir3_shader_variant *safe_const_variant; 64 65 struct tu_suballoc_bo bo; 66 struct tu_cs cs; 67 struct tu_bo *pvtmem_bo; 68 69 struct tu_draw_state state; 70 struct tu_draw_state safe_const_state; 71 struct tu_draw_state binning_state; 72 73 struct tu_const_state const_state; 74 uint32_t view_mask; 75 uint8_t active_desc_sets; 76 77 /* The dynamic buffer descriptor size for descriptor sets that we know 78 * about. This is used when linking to piece together the sizes and from 79 * there calculate the offsets. It's -1 if we don't know because the 80 * descriptor set layout is NULL. 81 */ 82 int dynamic_descriptor_sizes[MAX_SETS]; 83 84 union { 85 struct { 86 unsigned patch_type; 87 enum a6xx_tess_output tess_output_upper_left, tess_output_lower_left; 88 enum a6xx_tess_spacing tess_spacing; 89 } tes; 90 91 struct { 92 bool per_samp; 93 bool has_fdm; 94 95 uint16_t dynamic_input_attachments_used; 96 97 struct { 98 uint32_t status; 99 bool force_late_z; 100 } lrz; 101 } fs; 102 }; 103 }; 104 105 struct tu_shader_key { 106 unsigned multiview_mask; 107 uint16_t read_only_input_attachments; 108 bool force_sample_interp; 109 bool fragment_density_map; 110 bool dynamic_renderpass; 111 uint8_t unscaled_input_fragcoord; 112 bool robust_storage_access2; 113 bool robust_uniform_access2; 114 bool lower_view_index_to_device_index; 115 enum ir3_wavesize_option api_wavesize, real_wavesize; 116 }; 117 118 extern const struct vk_pipeline_cache_object_ops tu_shader_ops; 119 bool 120 tu_nir_lower_multiview(nir_shader *nir, uint32_t mask, struct tu_device *dev); 121 122 bool 123 tu_nir_lower_ray_queries(nir_shader *nir); 124 125 nir_shader * 126 tu_spirv_to_nir(struct tu_device *dev, 127 void *mem_ctx, 128 VkPipelineCreateFlags2KHR pipeline_flags, 129 const VkPipelineShaderStageCreateInfo *stage_info, 130 const struct tu_shader_key *key, 131 gl_shader_stage stage); 132 133 void 134 tu6_emit_xs(struct tu_cs *cs, 135 gl_shader_stage stage, 136 const struct ir3_shader_variant *xs, 137 const struct tu_pvtmem_config *pvtmem, 138 uint64_t binary_iova); 139 140 template <chip CHIP> 141 void 142 tu6_emit_vs(struct tu_cs *cs, const struct ir3_shader_variant *vs, 143 uint32_t view_mask); 144 145 template <chip CHIP> 146 void 147 tu6_emit_hs(struct tu_cs *cs, const struct ir3_shader_variant *hs); 148 149 template <chip CHIP> 150 void 151 tu6_emit_ds(struct tu_cs *cs, const struct ir3_shader_variant *hs); 152 153 template <chip CHIP> 154 void 155 tu6_emit_gs(struct tu_cs *cs, const struct ir3_shader_variant *hs); 156 157 template <chip CHIP> 158 void 159 tu6_emit_fs(struct tu_cs *cs, const struct ir3_shader_variant *fs); 160 161 VkResult 162 tu_shader_create(struct tu_device *dev, 163 struct tu_shader **shader_out, 164 nir_shader *nir, 165 const struct tu_shader_key *key, 166 const struct ir3_shader_key *ir3_key, 167 const void *key_data, 168 size_t key_size, 169 struct tu_pipeline_layout *layout, 170 bool executable_info); 171 172 void 173 tu_shader_key_subgroup_size(struct tu_shader_key *key, 174 bool allow_varying_subgroup_size, 175 bool require_full_subgroups, 176 const VkPipelineShaderStageRequiredSubgroupSizeCreateInfo *subgroup_info, 177 struct tu_device *dev); 178 179 void 180 tu_shader_key_robustness(struct tu_shader_key *key, 181 const struct vk_pipeline_robustness_state *rs); 182 183 VkResult 184 tu_compile_shaders(struct tu_device *device, 185 VkPipelineCreateFlags2KHR pipeline_flags, 186 const VkPipelineShaderStageCreateInfo **stage_infos, 187 nir_shader **nir, 188 const struct tu_shader_key *keys, 189 struct tu_pipeline_layout *layout, 190 const unsigned char *pipeline_sha1, 191 struct tu_shader **shaders, 192 char **nir_initial_disasm, 193 void *nir_initial_disasm_mem_ctx, 194 nir_shader **nir_out, 195 VkPipelineCreationFeedback *stage_feedbacks); 196 197 VkResult 198 tu_init_empty_shaders(struct tu_device *device); 199 200 void 201 tu_destroy_empty_shaders(struct tu_device *device); 202 203 void 204 tu_shader_destroy(struct tu_device *dev, 205 struct tu_shader *shader); 206 207 #endif /* TU_SHADER_H */ 208