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_build_data.h" 33 34 /** 35 * \file pvr_hardcode.h 36 * 37 * \brief Contains hard coding functions. 38 * This should eventually be deleted as the compiler becomes more capable. 39 */ 40 41 struct pvr_compute_pipeline_shader_state; 42 struct pvr_device; 43 struct pvr_fragment_shader_state; 44 struct pvr_hard_coding_data; 45 struct pvr_vertex_shader_state; 46 47 struct pvr_explicit_constant_usage { 48 /* Hardware register number assigned to the explicit constant with the lower 49 * pre_assigned offset. 50 */ 51 uint32_t start_offset; 52 }; 53 54 struct pvr_hard_code_compute_build_info { 55 struct rogue_ubo_data ubo_data; 56 struct rogue_compile_time_consts_data compile_time_consts_data; 57 58 uint32_t local_invocation_regs[2]; 59 uint32_t work_group_regs[3]; 60 uint32_t barrier_reg; 61 uint32_t usc_temps; 62 63 struct pvr_explicit_constant_usage explicit_conts_usage; 64 }; 65 66 struct pvr_hard_code_graphics_build_info { 67 struct rogue_build_data stage_data; 68 69 struct rogue_common_build_data vert_common_data; 70 struct rogue_common_build_data frag_common_data; 71 72 struct pvr_explicit_constant_usage vert_explicit_conts_usage; 73 struct pvr_explicit_constant_usage frag_explicit_conts_usage; 74 }; 75 76 /* Returns true if the shader for the currently running program requires hard 77 * coded shaders. 78 */ 79 bool pvr_hard_code_shader_required(const struct pvr_device_info *const dev_info); 80 81 VkResult pvr_hard_code_compute_pipeline( 82 struct pvr_device *const device, 83 struct pvr_compute_pipeline_shader_state *const shader_state_out, 84 struct pvr_hard_code_compute_build_info *const build_info_out); 85 86 /* Returns a mask of MESA_SHADER_* (gl_shader_stage) indicating which stage 87 * needs to be hard coded. 88 */ 89 uint32_t 90 pvr_hard_code_graphics_get_flags(const struct pvr_device_info *const dev_info); 91 92 /* pipeline_n: 93 * The pipeline number. Each pipeline created requires unique hard 94 * coding so a pipeline number is necessary to identify which data to use. 95 * This pipeline number to request data for the first pipeline to be created 96 * is 0 and should be incremented for each subsequent pipeline. 97 */ 98 void pvr_hard_code_graphics_shader( 99 const struct pvr_device_info *const dev_info, 100 uint32_t pipeline_n, 101 gl_shader_stage stage, 102 struct rogue_shader_binary **const 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 struct rogue_common_build_data *const common_build_data, 119 struct 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 const struct rogue_shader_binary **const program_out, 125 uint32_t *usc_shareds_out, 126 uint32_t *usc_temps_out); 127 128 #endif /* PVR_HARDCODE_SHADERS_H */ 129