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; 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 struct { 96 uint32_t status; 97 bool force_late_z; 98 } lrz; 99 } fs; 100 }; 101 }; 102 103 struct tu_shader_key { 104 unsigned multiview_mask; 105 bool force_sample_interp; 106 bool fragment_density_map; 107 uint8_t unscaled_input_fragcoord; 108 enum ir3_wavesize_option api_wavesize, real_wavesize; 109 }; 110 111 extern const struct vk_pipeline_cache_object_ops tu_shader_ops; 112 bool 113 tu_nir_lower_multiview(nir_shader *nir, uint32_t mask, struct tu_device *dev); 114 115 nir_shader * 116 tu_spirv_to_nir(struct tu_device *dev, 117 void *mem_ctx, 118 VkPipelineCreateFlags2KHR pipeline_flags, 119 const VkPipelineShaderStageCreateInfo *stage_info, 120 gl_shader_stage stage); 121 122 void 123 tu6_emit_xs(struct tu_cs *cs, 124 gl_shader_stage stage, 125 const struct ir3_shader_variant *xs, 126 const struct tu_pvtmem_config *pvtmem, 127 uint64_t binary_iova); 128 129 template <chip CHIP> 130 void 131 tu6_emit_vs(struct tu_cs *cs, const struct ir3_shader_variant *vs, 132 uint32_t view_mask); 133 134 template <chip CHIP> 135 void 136 tu6_emit_hs(struct tu_cs *cs, const struct ir3_shader_variant *hs); 137 138 template <chip CHIP> 139 void 140 tu6_emit_ds(struct tu_cs *cs, const struct ir3_shader_variant *hs); 141 142 template <chip CHIP> 143 void 144 tu6_emit_gs(struct tu_cs *cs, const struct ir3_shader_variant *hs); 145 146 template <chip CHIP> 147 void 148 tu6_emit_fs(struct tu_cs *cs, const struct ir3_shader_variant *fs); 149 150 VkResult 151 tu_shader_create(struct tu_device *dev, 152 struct tu_shader **shader_out, 153 nir_shader *nir, 154 const struct tu_shader_key *key, 155 const struct ir3_shader_key *ir3_key, 156 const void *key_data, 157 size_t key_size, 158 struct tu_pipeline_layout *layout, 159 bool executable_info); 160 161 void 162 tu_shader_key_subgroup_size(struct tu_shader_key *key, 163 bool allow_varying_subgroup_size, 164 bool require_full_subgroups, 165 const VkPipelineShaderStageRequiredSubgroupSizeCreateInfo *subgroup_info, 166 struct tu_device *dev); 167 168 VkResult 169 tu_compile_shaders(struct tu_device *device, 170 VkPipelineCreateFlags2KHR pipeline_flags, 171 const VkPipelineShaderStageCreateInfo **stage_infos, 172 nir_shader **nir, 173 const struct tu_shader_key *keys, 174 struct tu_pipeline_layout *layout, 175 const unsigned char *pipeline_sha1, 176 struct tu_shader **shaders, 177 char **nir_initial_disasm, 178 void *nir_initial_disasm_mem_ctx, 179 nir_shader **nir_out, 180 VkPipelineCreationFeedback *stage_feedbacks); 181 182 VkResult 183 tu_init_empty_shaders(struct tu_device *device); 184 185 void 186 tu_destroy_empty_shaders(struct tu_device *device); 187 188 void 189 tu_shader_destroy(struct tu_device *dev, 190 struct tu_shader *shader); 191 192 #endif /* TU_SHADER_H */ 193