xref: /aosp_15_r20/external/mesa3d/src/imagination/vulkan/pvr_hardcode.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2022 Imagination Technologies Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #ifndef PVR_HARDCODE_SHADERS_H
25 #define PVR_HARDCODE_SHADERS_H
26 
27 #include <stdbool.h>
28 #include <stdint.h>
29 #include <vulkan/vulkan_core.h>
30 
31 #include "compiler/shader_enums.h"
32 #include "rogue/rogue.h"
33 #include "util/u_dynarray.h"
34 
35 /**
36  * \file pvr_hardcode.h
37  *
38  * \brief Contains hard coding functions.
39  * This should eventually be deleted as the compiler becomes more capable.
40  */
41 
42 struct pvr_compute_shader_state;
43 struct pvr_device;
44 struct pvr_fragment_shader_state;
45 struct pvr_hard_coding_data;
46 struct pvr_vertex_shader_state;
47 
48 struct pvr_explicit_constant_usage {
49    /* Hardware register number assigned to the explicit constant with the lower
50     * pre_assigned offset.
51     */
52    uint32_t start_offset;
53 };
54 
55 struct pvr_hard_code_compute_build_info {
56    rogue_ubo_data ubo_data;
57    rogue_compile_time_consts_data compile_time_consts_data;
58 
59    uint32_t local_invocation_regs[2];
60    uint32_t work_group_regs[3];
61    uint32_t barrier_reg;
62    uint32_t usc_temps;
63 
64    struct pvr_explicit_constant_usage explicit_conts_usage;
65 };
66 
67 struct pvr_hard_code_graphics_build_info {
68    rogue_build_data stage_data;
69 
70    rogue_common_build_data vert_common_data;
71    rogue_common_build_data frag_common_data;
72 
73    struct pvr_explicit_constant_usage vert_explicit_conts_usage;
74    struct pvr_explicit_constant_usage frag_explicit_conts_usage;
75 };
76 
77 /* Returns true if the shader for the currently running program has a hard coded
78  * shader.
79  */
80 bool pvr_has_hard_coded_shaders(const struct pvr_device_info *const dev_info);
81 
82 VkResult pvr_hard_code_compute_pipeline(
83    struct pvr_device *const device,
84    struct pvr_compute_shader_state *const shader_state_out,
85    struct pvr_hard_code_compute_build_info *const build_info_out);
86 
87 /* Returns a mask of MESA_SHADER_* (gl_shader_stage) indicating which stage
88  * needs to be hard coded.
89  */
90 uint32_t
91 pvr_hard_code_graphics_get_flags(const struct pvr_device_info *const dev_info);
92 
93 /* pipeline_n:
94  *    The pipeline number. Each pipeline created requires unique hard
95  *    coding so a pipeline number is necessary to identify which data to use.
96  *    This pipeline number to request data for the first pipeline to be created
97  *    is 0 and should be incremented for each subsequent pipeline.
98  */
99 void pvr_hard_code_graphics_shader(const struct pvr_device_info *const dev_info,
100                                    uint32_t pipeline_n,
101                                    gl_shader_stage stage,
102                                    struct util_dynarray *shader_out);
103 
104 void pvr_hard_code_graphics_vertex_state(
105    const struct pvr_device_info *const dev_info,
106    uint32_t pipeline_n,
107    struct pvr_vertex_shader_state *const vert_state_out);
108 
109 void pvr_hard_code_graphics_fragment_state(
110    const struct pvr_device_info *const dev_info,
111    uint32_t pipeline_n,
112    struct pvr_fragment_shader_state *const frag_state_out);
113 
114 void pvr_hard_code_graphics_get_build_info(
115    const struct pvr_device_info *const dev_info,
116    uint32_t pipeline_n,
117    gl_shader_stage stage,
118    rogue_common_build_data *const common_build_data,
119    rogue_build_data *const build_data,
120    struct pvr_explicit_constant_usage *const explicit_const_usage);
121 
122 void pvr_hard_code_get_idfwdf_program(
123    const struct pvr_device_info *const dev_info,
124    struct util_dynarray *program_out,
125    uint32_t *usc_shareds_out,
126    uint32_t *usc_temps_out);
127 
128 void pvr_hard_code_get_passthrough_vertex_shader(
129    const struct pvr_device_info *const dev_info,
130    struct util_dynarray *program_out);
131 void pvr_hard_code_get_passthrough_rta_vertex_shader(
132    const struct pvr_device_info *const dev_info,
133    struct util_dynarray *program_out);
134 
135 #endif /* PVR_HARDCODE_SHADERS_H */
136