xref: /aosp_15_r20/external/mesa3d/src/amd/vulkan/radv_pipeline.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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    VkPipelineCreateFlags2KHR 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, VkPipelineCreateFlags2KHR 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, VkPipelineCreateFlags2KHR flags);
78 
79 void radv_pipeline_init(struct radv_device *device, struct radv_pipeline *pipeline, enum radv_pipeline_type type);
80 
81 void radv_pipeline_destroy(struct radv_device *device, struct radv_pipeline *pipeline,
82                            const VkAllocationCallbacks *allocator);
83 
84 struct radv_shader_stage_key radv_pipeline_get_shader_key(const struct radv_device *device,
85                                                           const VkPipelineShaderStageCreateInfo *stage,
86                                                           VkPipelineCreateFlags2KHR flags, const void *pNext);
87 
88 void radv_pipeline_stage_init(VkPipelineCreateFlags2KHR pipeline_flags,
89                               const VkPipelineShaderStageCreateInfo *sinfo, const struct radv_pipeline_layout *layout,
90                               const struct radv_shader_stage_key *stage_key, struct radv_shader_stage *out_stage);
91 
92 void radv_shader_layout_init(const struct radv_pipeline_layout *pipeline_layout, gl_shader_stage stage,
93                              struct radv_shader_layout *layout);
94 
95 void radv_postprocess_nir(struct radv_device *device, const struct radv_graphics_state_key *gfx_state,
96                           struct radv_shader_stage *stage);
97 
98 bool radv_shader_should_clear_lds(const struct radv_device *device, const nir_shader *shader);
99 
100 VkPipelineShaderStageCreateInfo *radv_copy_shader_stage_create_info(struct radv_device *device, uint32_t stageCount,
101                                                                     const VkPipelineShaderStageCreateInfo *pStages,
102                                                                     void *mem_ctx);
103 
104 void radv_pipeline_hash(const struct radv_device *device, const struct radv_pipeline_layout *pipeline_layout,
105                         struct mesa_sha1 *ctx);
106 
107 void radv_pipeline_hash_shader_stage(VkPipelineCreateFlags2KHR pipeline_flags,
108                                      const VkPipelineShaderStageCreateInfo *sinfo,
109                                      const struct radv_shader_stage_key *stage_key, struct mesa_sha1 *ctx);
110 
111 #endif /* RADV_PIPELINE_H */
112