1 /* 2 * Copyright 2019 Valve Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * on the rights to use, copy, modify, merge, publish, distribute, sub 8 * license, and/or sell copies of the Software, and to permit persons to whom 9 * the Software is 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 NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 * USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24 #ifndef AC_SHADER_ARGS_H 25 #define AC_SHADER_ARGS_H 26 27 #include <stdbool.h> 28 #include <stdint.h> 29 30 #define AC_MAX_INLINE_PUSH_CONSTS 8 31 32 enum ac_arg_regfile 33 { 34 AC_ARG_SGPR, 35 AC_ARG_VGPR, 36 }; 37 38 enum ac_arg_type 39 { 40 AC_ARG_FLOAT, 41 AC_ARG_INT, 42 AC_ARG_CONST_PTR, /* Pointer to i8 array */ 43 AC_ARG_CONST_FLOAT_PTR, /* Pointer to f32 array */ 44 AC_ARG_CONST_PTR_PTR, /* Pointer to pointer to i8 array */ 45 AC_ARG_CONST_DESC_PTR, /* Pointer to v4i32 array */ 46 AC_ARG_CONST_IMAGE_PTR, /* Pointer to v8i32 array */ 47 }; 48 49 struct ac_arg { 50 uint16_t arg_index; 51 bool used; 52 }; 53 54 #define AC_MAX_ARGS 384 /* including all VS->TCS IO */ 55 56 struct ac_shader_args { 57 /* Info on how to declare arguments */ 58 struct { 59 enum ac_arg_type type; 60 enum ac_arg_regfile file; 61 uint8_t offset; 62 uint8_t size; 63 bool skip; 64 } args[AC_MAX_ARGS]; 65 66 uint16_t arg_count; 67 uint16_t num_sgprs_used; 68 uint16_t num_vgprs_used; 69 70 uint16_t return_count; 71 uint16_t num_sgprs_returned; 72 uint16_t num_vgprs_returned; 73 74 /* VS */ 75 struct ac_arg base_vertex; 76 struct ac_arg start_instance; 77 struct ac_arg draw_id; 78 struct ac_arg vertex_buffers; 79 struct ac_arg vertex_id; 80 struct ac_arg vs_rel_patch_id; 81 struct ac_arg vs_prim_id; 82 struct ac_arg instance_id; 83 84 /* Merged shaders */ 85 struct ac_arg tess_offchip_offset; 86 struct ac_arg merged_wave_info; 87 /* On gfx10: 88 * - bits 0..11: ordered_wave_id 89 * - bits 12..20: number of vertices in group 90 * - bits 22..30: number of primitives in group 91 */ 92 struct ac_arg gs_tg_info; 93 struct ac_arg scratch_offset; 94 95 /* TCS */ 96 struct ac_arg tcs_factor_offset; 97 struct ac_arg tcs_patch_id; 98 struct ac_arg tcs_rel_ids; 99 100 /* TES */ 101 struct ac_arg tes_u; 102 struct ac_arg tes_v; 103 struct ac_arg tes_rel_patch_id; 104 struct ac_arg tes_patch_id; 105 106 /* GS */ 107 struct ac_arg es2gs_offset; /* separate legacy ES */ 108 struct ac_arg gs2vs_offset; /* legacy GS */ 109 struct ac_arg gs_wave_id; /* legacy GS */ 110 struct ac_arg gs_vtx_offset[6]; /* GFX6-8: [0-5], GFX9+: [0-2] packed */ 111 struct ac_arg gs_prim_id; 112 struct ac_arg gs_invocation_id; 113 114 /* Streamout */ 115 struct ac_arg streamout_config; 116 struct ac_arg streamout_write_index; 117 struct ac_arg streamout_offset[4]; 118 119 /* PS */ 120 struct ac_arg frag_pos[4]; 121 struct ac_arg front_face; 122 struct ac_arg ancillary; 123 struct ac_arg sample_coverage; 124 struct ac_arg prim_mask; 125 struct ac_arg persp_sample; 126 struct ac_arg persp_center; 127 struct ac_arg persp_centroid; 128 struct ac_arg pull_model; 129 struct ac_arg linear_sample; 130 struct ac_arg linear_center; 131 struct ac_arg linear_centroid; 132 133 /* CS */ 134 struct ac_arg local_invocation_ids; 135 struct ac_arg num_work_groups; 136 struct ac_arg workgroup_ids[3]; 137 struct ac_arg tg_size; 138 139 /* Vulkan only */ 140 struct ac_arg push_constants; 141 struct ac_arg inline_push_consts[AC_MAX_INLINE_PUSH_CONSTS]; 142 unsigned base_inline_push_consts; 143 struct ac_arg view_index; 144 struct ac_arg sbt_descriptors; 145 struct ac_arg ray_launch_size; 146 }; 147 148 void ac_add_arg(struct ac_shader_args *info, enum ac_arg_regfile regfile, unsigned registers, 149 enum ac_arg_type type, struct ac_arg *arg); 150 void ac_add_return(struct ac_shader_args *info, enum ac_arg_regfile regfile); 151 152 #endif 153