1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2016 Red Hat. 3bf215546Sopenharmony_ci * Copyright © 2016 Bas Nieuwenhuizen 4bf215546Sopenharmony_ci * SPDX-License-Identifier: MIT 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * based in part on anv driver which is: 7bf215546Sopenharmony_ci * Copyright © 2015 Intel Corporation 8bf215546Sopenharmony_ci */ 9bf215546Sopenharmony_ci 10bf215546Sopenharmony_ci#ifndef TU_PIPELINE_H 11bf215546Sopenharmony_ci#define TU_PIPELINE_H 12bf215546Sopenharmony_ci 13bf215546Sopenharmony_ci#include "tu_common.h" 14bf215546Sopenharmony_ci 15bf215546Sopenharmony_ci#include "tu_cs.h" 16bf215546Sopenharmony_ci#include "tu_descriptor_set.h" 17bf215546Sopenharmony_ci#include "tu_shader.h" 18bf215546Sopenharmony_ci#include "tu_suballoc.h" 19bf215546Sopenharmony_ci 20bf215546Sopenharmony_cienum tu_dynamic_state 21bf215546Sopenharmony_ci{ 22bf215546Sopenharmony_ci /* re-use VK_DYNAMIC_STATE_ enums for non-extended dynamic states */ 23bf215546Sopenharmony_ci TU_DYNAMIC_STATE_SAMPLE_LOCATIONS = VK_DYNAMIC_STATE_STENCIL_REFERENCE + 1, 24bf215546Sopenharmony_ci TU_DYNAMIC_STATE_RB_DEPTH_CNTL, 25bf215546Sopenharmony_ci TU_DYNAMIC_STATE_RB_STENCIL_CNTL, 26bf215546Sopenharmony_ci TU_DYNAMIC_STATE_VB_STRIDE, 27bf215546Sopenharmony_ci TU_DYNAMIC_STATE_RASTERIZER_DISCARD, 28bf215546Sopenharmony_ci TU_DYNAMIC_STATE_BLEND, 29bf215546Sopenharmony_ci TU_DYNAMIC_STATE_COUNT, 30bf215546Sopenharmony_ci /* no associated draw state: */ 31bf215546Sopenharmony_ci TU_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY = TU_DYNAMIC_STATE_COUNT, 32bf215546Sopenharmony_ci TU_DYNAMIC_STATE_PRIMITIVE_RESTART_ENABLE, 33bf215546Sopenharmony_ci TU_DYNAMIC_STATE_LOGIC_OP, 34bf215546Sopenharmony_ci TU_DYNAMIC_STATE_COLOR_WRITE_ENABLE, 35bf215546Sopenharmony_ci /* re-use the line width enum as it uses GRAS_SU_CNTL: */ 36bf215546Sopenharmony_ci TU_DYNAMIC_STATE_GRAS_SU_CNTL = VK_DYNAMIC_STATE_LINE_WIDTH, 37bf215546Sopenharmony_ci}; 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_cistruct cache_entry; 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_cistruct tu_pipeline_cache 42bf215546Sopenharmony_ci{ 43bf215546Sopenharmony_ci struct vk_object_base base; 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci struct tu_device *device; 46bf215546Sopenharmony_ci pthread_mutex_t mutex; 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci uint32_t total_size; 49bf215546Sopenharmony_ci uint32_t table_size; 50bf215546Sopenharmony_ci uint32_t kernel_count; 51bf215546Sopenharmony_ci struct cache_entry **hash_table; 52bf215546Sopenharmony_ci bool modified; 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci VkAllocationCallbacks alloc; 55bf215546Sopenharmony_ci}; 56bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline_cache, base, VkPipelineCache, 57bf215546Sopenharmony_ci VK_OBJECT_TYPE_PIPELINE_CACHE) 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_cistruct tu_lrz_pipeline 60bf215546Sopenharmony_ci{ 61bf215546Sopenharmony_ci uint32_t force_disable_mask; 62bf215546Sopenharmony_ci bool fs_has_kill; 63bf215546Sopenharmony_ci bool force_late_z; 64bf215546Sopenharmony_ci bool early_fragment_tests; 65bf215546Sopenharmony_ci}; 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_cistruct tu_compiled_shaders 68bf215546Sopenharmony_ci{ 69bf215546Sopenharmony_ci struct vk_pipeline_cache_object base; 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ci struct tu_push_constant_range push_consts[MESA_SHADER_STAGES]; 72bf215546Sopenharmony_ci uint8_t active_desc_sets; 73bf215546Sopenharmony_ci bool multi_pos_output; 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci struct ir3_shader_variant *variants[MESA_SHADER_STAGES]; 76bf215546Sopenharmony_ci}; 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ciextern const struct vk_pipeline_cache_object_ops tu_shaders_ops; 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_cistatic bool inline 81bf215546Sopenharmony_citu6_shared_constants_enable(const struct tu_pipeline_layout *layout, 82bf215546Sopenharmony_ci const struct ir3_compiler *compiler) 83bf215546Sopenharmony_ci{ 84bf215546Sopenharmony_ci return layout->push_constant_size > 0 && 85bf215546Sopenharmony_ci layout->push_constant_size <= (compiler->shared_consts_size * 16); 86bf215546Sopenharmony_ci} 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_cistruct tu_program_descriptor_linkage 89bf215546Sopenharmony_ci{ 90bf215546Sopenharmony_ci struct ir3_const_state const_state; 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci uint32_t constlen; 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ci struct tu_push_constant_range push_consts; 95bf215546Sopenharmony_ci}; 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_cistruct tu_pipeline_executable { 98bf215546Sopenharmony_ci gl_shader_stage stage; 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_ci struct ir3_info stats; 101bf215546Sopenharmony_ci bool is_binning; 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci char *nir_from_spirv; 104bf215546Sopenharmony_ci char *nir_final; 105bf215546Sopenharmony_ci char *disasm; 106bf215546Sopenharmony_ci}; 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_cistruct tu_pipeline 109bf215546Sopenharmony_ci{ 110bf215546Sopenharmony_ci struct vk_object_base base; 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci struct tu_cs cs; 113bf215546Sopenharmony_ci struct tu_suballoc_bo bo; 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci /* Separate BO for private memory since it should GPU writable */ 116bf215546Sopenharmony_ci struct tu_bo *pvtmem_bo; 117bf215546Sopenharmony_ci 118bf215546Sopenharmony_ci bool need_indirect_descriptor_sets; 119bf215546Sopenharmony_ci VkShaderStageFlags active_stages; 120bf215546Sopenharmony_ci uint32_t active_desc_sets; 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci /* mask of enabled dynamic states 123bf215546Sopenharmony_ci * if BIT(i) is set, pipeline->dynamic_state[i] is *NOT* used 124bf215546Sopenharmony_ci */ 125bf215546Sopenharmony_ci uint32_t dynamic_state_mask; 126bf215546Sopenharmony_ci struct tu_draw_state dynamic_state[TU_DYNAMIC_STATE_COUNT]; 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_ci /* for dynamic states which use the same register: */ 129bf215546Sopenharmony_ci uint32_t gras_su_cntl, gras_su_cntl_mask; 130bf215546Sopenharmony_ci uint32_t rb_depth_cntl, rb_depth_cntl_mask; 131bf215546Sopenharmony_ci uint32_t rb_stencil_cntl, rb_stencil_cntl_mask; 132bf215546Sopenharmony_ci uint32_t pc_raster_cntl, pc_raster_cntl_mask; 133bf215546Sopenharmony_ci uint32_t vpc_unknown_9107, vpc_unknown_9107_mask; 134bf215546Sopenharmony_ci uint32_t stencil_wrmask; 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_ci unsigned num_rts; 137bf215546Sopenharmony_ci uint32_t rb_mrt_control[MAX_RTS], rb_mrt_control_mask; 138bf215546Sopenharmony_ci uint32_t rb_mrt_blend_control[MAX_RTS]; 139bf215546Sopenharmony_ci uint32_t sp_blend_cntl, sp_blend_cntl_mask; 140bf215546Sopenharmony_ci uint32_t rb_blend_cntl, rb_blend_cntl_mask; 141bf215546Sopenharmony_ci uint32_t color_write_enable, blend_enable; 142bf215546Sopenharmony_ci bool logic_op_enabled, rop_reads_dst; 143bf215546Sopenharmony_ci bool rasterizer_discard; 144bf215546Sopenharmony_ci 145bf215546Sopenharmony_ci bool rb_depth_cntl_disable; 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci enum a5xx_line_mode line_mode; 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci /* draw states for the pipeline */ 150bf215546Sopenharmony_ci struct tu_draw_state load_state, rast_state; 151bf215546Sopenharmony_ci struct tu_draw_state prim_order_state_sysmem, prim_order_state_gmem; 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_ci /* for vertex buffers state */ 154bf215546Sopenharmony_ci uint32_t num_vbs; 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_ci struct tu_push_constant_range shared_consts; 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci struct 159bf215546Sopenharmony_ci { 160bf215546Sopenharmony_ci struct tu_draw_state config_state; 161bf215546Sopenharmony_ci struct tu_draw_state state; 162bf215546Sopenharmony_ci struct tu_draw_state binning_state; 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci struct tu_program_descriptor_linkage link[MESA_SHADER_STAGES]; 165bf215546Sopenharmony_ci } program; 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_ci struct 168bf215546Sopenharmony_ci { 169bf215546Sopenharmony_ci struct tu_draw_state state; 170bf215546Sopenharmony_ci struct tu_draw_state binning_state; 171bf215546Sopenharmony_ci } vi; 172bf215546Sopenharmony_ci 173bf215546Sopenharmony_ci struct 174bf215546Sopenharmony_ci { 175bf215546Sopenharmony_ci enum pc_di_primtype primtype; 176bf215546Sopenharmony_ci bool primitive_restart; 177bf215546Sopenharmony_ci } ia; 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_ci struct 180bf215546Sopenharmony_ci { 181bf215546Sopenharmony_ci uint32_t patch_type; 182bf215546Sopenharmony_ci uint32_t param_stride; 183bf215546Sopenharmony_ci bool upper_left_domain_origin; 184bf215546Sopenharmony_ci } tess; 185bf215546Sopenharmony_ci 186bf215546Sopenharmony_ci struct 187bf215546Sopenharmony_ci { 188bf215546Sopenharmony_ci uint32_t local_size[3]; 189bf215546Sopenharmony_ci uint32_t subgroup_size; 190bf215546Sopenharmony_ci } compute; 191bf215546Sopenharmony_ci 192bf215546Sopenharmony_ci bool provoking_vertex_last; 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_ci struct tu_lrz_pipeline lrz; 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci /* In other words - framebuffer fetch support */ 197bf215546Sopenharmony_ci bool raster_order_attachment_access; 198bf215546Sopenharmony_ci bool subpass_feedback_loop_ds; 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_ci bool z_negative_one_to_one; 201bf215546Sopenharmony_ci 202bf215546Sopenharmony_ci /* memory bandwidth cost (in bytes) for color attachments */ 203bf215546Sopenharmony_ci uint32_t color_bandwidth_per_sample; 204bf215546Sopenharmony_ci 205bf215546Sopenharmony_ci uint32_t depth_cpp_per_sample; 206bf215546Sopenharmony_ci uint32_t stencil_cpp_per_sample; 207bf215546Sopenharmony_ci 208bf215546Sopenharmony_ci void *executables_mem_ctx; 209bf215546Sopenharmony_ci /* tu_pipeline_executable */ 210bf215546Sopenharmony_ci struct util_dynarray executables; 211bf215546Sopenharmony_ci}; 212bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(tu_pipeline, base, VkPipeline, 213bf215546Sopenharmony_ci VK_OBJECT_TYPE_PIPELINE) 214bf215546Sopenharmony_ci 215bf215546Sopenharmony_civoid 216bf215546Sopenharmony_citu6_emit_viewport(struct tu_cs *cs, const VkViewport *viewport, uint32_t num_viewport, 217bf215546Sopenharmony_ci bool z_negative_one_to_one); 218bf215546Sopenharmony_ci 219bf215546Sopenharmony_civoid 220bf215546Sopenharmony_citu6_emit_scissor(struct tu_cs *cs, const VkRect2D *scs, uint32_t scissor_count); 221bf215546Sopenharmony_ci 222bf215546Sopenharmony_civoid 223bf215546Sopenharmony_citu6_emit_sample_locations(struct tu_cs *cs, const VkSampleLocationsInfoEXT *samp_loc); 224bf215546Sopenharmony_ci 225bf215546Sopenharmony_civoid 226bf215546Sopenharmony_citu6_emit_depth_bias(struct tu_cs *cs, 227bf215546Sopenharmony_ci float constant_factor, 228bf215546Sopenharmony_ci float clamp, 229bf215546Sopenharmony_ci float slope_factor); 230bf215546Sopenharmony_ci 231bf215546Sopenharmony_ciuint32_t tu6_rb_mrt_control_rop(VkLogicOp op, bool *rop_reads_dst); 232bf215546Sopenharmony_ci 233bf215546Sopenharmony_cistruct tu_pvtmem_config { 234bf215546Sopenharmony_ci uint64_t iova; 235bf215546Sopenharmony_ci uint32_t per_fiber_size; 236bf215546Sopenharmony_ci uint32_t per_sp_size; 237bf215546Sopenharmony_ci bool per_wave; 238bf215546Sopenharmony_ci}; 239bf215546Sopenharmony_ci 240bf215546Sopenharmony_civoid 241bf215546Sopenharmony_citu6_emit_xs_config(struct tu_cs *cs, 242bf215546Sopenharmony_ci gl_shader_stage stage, 243bf215546Sopenharmony_ci const struct ir3_shader_variant *xs); 244bf215546Sopenharmony_ci 245bf215546Sopenharmony_civoid 246bf215546Sopenharmony_citu6_emit_xs(struct tu_cs *cs, 247bf215546Sopenharmony_ci gl_shader_stage stage, 248bf215546Sopenharmony_ci const struct ir3_shader_variant *xs, 249bf215546Sopenharmony_ci const struct tu_pvtmem_config *pvtmem, 250bf215546Sopenharmony_ci uint64_t binary_iova); 251bf215546Sopenharmony_ci 252bf215546Sopenharmony_civoid 253bf215546Sopenharmony_citu6_emit_vpc(struct tu_cs *cs, 254bf215546Sopenharmony_ci const struct ir3_shader_variant *vs, 255bf215546Sopenharmony_ci const struct ir3_shader_variant *hs, 256bf215546Sopenharmony_ci const struct ir3_shader_variant *ds, 257bf215546Sopenharmony_ci const struct ir3_shader_variant *gs, 258bf215546Sopenharmony_ci const struct ir3_shader_variant *fs, 259bf215546Sopenharmony_ci uint32_t patch_control_points); 260bf215546Sopenharmony_ci 261bf215546Sopenharmony_civoid 262bf215546Sopenharmony_citu6_emit_fs_inputs(struct tu_cs *cs, const struct ir3_shader_variant *fs); 263bf215546Sopenharmony_ci 264bf215546Sopenharmony_ci#endif /* TU_PIPELINE_H */ 265