xref: /aosp_15_r20/external/mesa3d/src/amd/vulkan/radv_pipeline_rt.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_RT_H
12 #define RADV_PIPELINE_RT_H
13 
14 #include "radv_pipeline_compute.h"
15 #include "radv_shader.h"
16 
17 struct radv_ray_tracing_pipeline {
18    struct radv_compute_pipeline base;
19 
20    struct radv_shader *prolog;
21 
22    struct radv_ray_tracing_stage *stages;
23    struct radv_ray_tracing_group *groups;
24    unsigned stage_count;
25    unsigned non_imported_stage_count;
26    unsigned group_count;
27 
28    uint32_t stack_size;
29 
30    /* set if any shaders from this pipeline require robustness2 in the merged traversal shader */
31    bool traversal_storage_robustness2 : 1;
32    bool traversal_uniform_robustness2 : 1;
33 };
34 
35 RADV_DECL_PIPELINE_DOWNCAST(ray_tracing, RADV_PIPELINE_RAY_TRACING)
36 
37 struct radv_pipeline_group_handle {
38    uint64_t recursive_shader_ptr;
39 
40    union {
41       uint32_t general_index;
42       uint32_t closest_hit_index;
43    };
44    union {
45       uint32_t intersection_index;
46       uint32_t any_hit_index;
47    };
48 };
49 
50 struct radv_rt_capture_replay_handle {
51    struct radv_serialized_shader_arena_block recursive_shader_alloc;
52    uint32_t non_recursive_idx;
53 };
54 
55 struct radv_ray_tracing_group {
56    VkRayTracingShaderGroupTypeKHR type;
57    uint32_t recursive_shader; /* generalShader or closestHitShader */
58    uint32_t any_hit_shader;
59    uint32_t intersection_shader;
60    struct radv_pipeline_group_handle handle;
61 };
62 
63 enum radv_rt_const_arg_state {
64    RADV_RT_CONST_ARG_STATE_UNINITIALIZED,
65    RADV_RT_CONST_ARG_STATE_VALID,
66    RADV_RT_CONST_ARG_STATE_INVALID,
67 };
68 
69 struct radv_rt_const_arg_info {
70    enum radv_rt_const_arg_state state;
71    uint32_t value;
72 };
73 
74 struct radv_ray_tracing_stage_info {
75    bool can_inline;
76 
77    BITSET_DECLARE(unused_args, AC_MAX_ARGS);
78 
79    struct radv_rt_const_arg_info tmin;
80    struct radv_rt_const_arg_info tmax;
81 
82    struct radv_rt_const_arg_info sbt_offset;
83    struct radv_rt_const_arg_info sbt_stride;
84 
85    struct radv_rt_const_arg_info miss_index;
86 
87    uint32_t set_flags;
88    uint32_t unset_flags;
89 };
90 
91 struct radv_ray_tracing_stage {
92    struct vk_pipeline_cache_object *nir;
93    struct radv_shader *shader;
94    gl_shader_stage stage;
95    uint32_t stack_size;
96 
97    struct radv_ray_tracing_stage_info info;
98 
99    uint8_t sha1[SHA1_DIGEST_LENGTH];
100 };
101 
102 struct radv_ray_tracing_state_key {
103    uint32_t stage_count;
104    struct radv_ray_tracing_stage *stages;
105 
106    uint32_t group_count;
107    struct radv_ray_tracing_group *groups;
108 
109    struct radv_shader_stage_key stage_keys[MESA_VULKAN_SHADER_STAGES];
110 };
111 
112 void radv_destroy_ray_tracing_pipeline(struct radv_device *device, struct radv_ray_tracing_pipeline *pipeline);
113 
114 void radv_ray_tracing_pipeline_hash(const struct radv_device *device,
115                                     const VkRayTracingPipelineCreateInfoKHR *pCreateInfo,
116                                     const struct radv_ray_tracing_state_key *rt_state, unsigned char *hash);
117 
118 VkResult radv_generate_ray_tracing_state_key(struct radv_device *device,
119                                              const VkRayTracingPipelineCreateInfoKHR *pCreateInfo,
120                                              struct radv_ray_tracing_state_key *rt_state);
121 
122 void radv_ray_tracing_state_key_finish(struct radv_ray_tracing_state_key *rt_state);
123 
124 struct radv_ray_tracing_binary_header {
125    uint32_t is_traversal_shader : 1;
126    uint32_t has_shader : 1;
127    uint32_t has_nir : 1;
128    uint8_t stage_sha1[SHA1_DIGEST_LENGTH];
129    uint32_t stack_size;
130    struct radv_ray_tracing_stage_info stage_info;
131 };
132 
133 #endif /* RADV_PIPELINE_RT */
134