1 /* 2 * Copyright © 2016 Red Hat. 3 * Copyright © 2016 Bas Nieuwenhuizen 4 * 5 * based in part on anv driver which is: 6 * Copyright © 2015 Intel Corporation 7 * 8 * SPDX-License-Identifier: MIT 9 */ 10 11 #ifndef RADV_PIPELINE_H 12 #define RADV_PIPELINE_H 13 14 #include "util/mesa-sha1.h" 15 16 #include "nir.h" 17 18 #include "vk_pipeline.h" 19 #include "vk_pipeline_cache.h" 20 21 #include "radv_radeon_winsys.h" 22 23 struct radv_device; 24 struct radv_shader_stage_key; 25 struct radv_shader_stage; 26 struct radv_pipeline_layout; 27 struct radv_graphics_state_key; 28 struct radv_shader_layout; 29 30 enum radv_pipeline_type { 31 RADV_PIPELINE_GRAPHICS, 32 RADV_PIPELINE_GRAPHICS_LIB, 33 /* Compute pipeline */ 34 RADV_PIPELINE_COMPUTE, 35 /* Raytracing pipeline */ 36 RADV_PIPELINE_RAY_TRACING, 37 RADV_PIPELINE_TYPE_COUNT, 38 }; 39 40 struct radv_pipeline { 41 struct vk_object_base base; 42 uint8_t sha1[SHA1_DIGEST_LENGTH]; 43 enum radv_pipeline_type type; 44 45 VkPipelineCreateFlags2 create_flags; 46 47 struct vk_pipeline_cache_object *cache_object; 48 49 bool is_internal; 50 bool need_indirect_descriptor_sets; 51 struct radv_shader *shaders[MESA_VULKAN_SHADER_STAGES]; 52 struct radv_shader *gs_copy_shader; 53 54 uint32_t user_data_0[MESA_VULKAN_SHADER_STAGES]; 55 56 /* Unique pipeline hash identifier. */ 57 uint64_t pipeline_hash; 58 59 /* Pipeline layout info. */ 60 uint32_t push_constant_size; 61 uint32_t dynamic_offset_count; 62 }; 63 64 VK_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline, base, VkPipeline, VK_OBJECT_TYPE_PIPELINE) 65 66 #define RADV_DECL_PIPELINE_DOWNCAST(pipe_type, pipe_enum) \ 67 static inline struct radv_##pipe_type##_pipeline *radv_pipeline_to_##pipe_type(struct radv_pipeline *pipeline) \ 68 { \ 69 assert(pipeline->type == pipe_enum); \ 70 return (struct radv_##pipe_type##_pipeline *)pipeline; \ 71 } 72 73 bool radv_pipeline_capture_shaders(const struct radv_device *device, VkPipelineCreateFlags2 flags); 74 75 bool radv_shader_need_indirect_descriptor_sets(const struct radv_shader *shader); 76 77 bool radv_pipeline_capture_shader_stats(const struct radv_device *device, VkPipelineCreateFlags2 flags); 78 79 bool radv_pipeline_skip_shaders_cache(const struct radv_device *device, const struct radv_pipeline *pipeline); 80 81 void radv_pipeline_init(struct radv_device *device, struct radv_pipeline *pipeline, enum radv_pipeline_type type); 82 83 void radv_pipeline_destroy(struct radv_device *device, struct radv_pipeline *pipeline, 84 const VkAllocationCallbacks *allocator); 85 86 struct radv_shader_stage_key radv_pipeline_get_shader_key(const struct radv_device *device, 87 const VkPipelineShaderStageCreateInfo *stage, 88 VkPipelineCreateFlags2 flags, const void *pNext); 89 90 void radv_pipeline_stage_init(VkPipelineCreateFlags2 pipeline_flags, const VkPipelineShaderStageCreateInfo *sinfo, 91 const struct radv_pipeline_layout *layout, const struct radv_shader_stage_key *stage_key, 92 struct radv_shader_stage *out_stage); 93 94 void radv_shader_layout_init(const struct radv_pipeline_layout *pipeline_layout, gl_shader_stage stage, 95 struct radv_shader_layout *layout); 96 97 void radv_postprocess_nir(struct radv_device *device, const struct radv_graphics_state_key *gfx_state, 98 struct radv_shader_stage *stage); 99 100 bool radv_shader_should_clear_lds(const struct radv_device *device, const nir_shader *shader); 101 102 VkPipelineShaderStageCreateInfo *radv_copy_shader_stage_create_info(struct radv_device *device, uint32_t stageCount, 103 const VkPipelineShaderStageCreateInfo *pStages, 104 void *mem_ctx); 105 106 void radv_pipeline_hash(const struct radv_device *device, const struct radv_pipeline_layout *pipeline_layout, 107 struct mesa_sha1 *ctx); 108 109 void radv_pipeline_hash_shader_stage(VkPipelineCreateFlags2 pipeline_flags, 110 const VkPipelineShaderStageCreateInfo *sinfo, 111 const struct radv_shader_stage_key *stage_key, struct mesa_sha1 *ctx); 112 113 #endif /* RADV_PIPELINE_H */ 114