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 <stdint.h>
28 #include <stdbool.h>
29 
30 #define AC_MAX_INLINE_PUSH_CONSTS 8
31 
32 enum ac_arg_regfile {
33 	AC_ARG_SGPR,
34 	AC_ARG_VGPR,
35 };
36 
37 enum ac_arg_type {
38 	AC_ARG_FLOAT,
39 	AC_ARG_INT,
40 	AC_ARG_CONST_PTR, /* Pointer to i8 array */
41 	AC_ARG_CONST_FLOAT_PTR, /* Pointer to f32 array */
42 	AC_ARG_CONST_PTR_PTR, /* Pointer to pointer to i8 array */
43 	AC_ARG_CONST_DESC_PTR, /* Pointer to v4i32 array */
44 	AC_ARG_CONST_IMAGE_PTR, /* Pointer to v8i32 array */
45 };
46 
47 struct ac_arg {
48 	uint8_t arg_index;
49 	bool used;
50 };
51 
52 
53 #define AC_MAX_ARGS 128
54 
55 struct ac_shader_args {
56 	/* Info on how to declare arguments */
57 	struct {
58 		enum ac_arg_type type;
59 		enum ac_arg_regfile file;
60 		uint8_t offset;
61 		uint8_t size;
62 		bool skip;
63 	} args[AC_MAX_ARGS];
64 
65 	uint8_t arg_count;
66 	uint8_t sgpr_count;
67 	uint8_t num_sgprs_used;
68 	uint8_t num_vgprs_used;
69 
70 	struct ac_arg base_vertex;
71 	struct ac_arg start_instance;
72 	struct ac_arg draw_id;
73 	struct ac_arg vertex_id;
74 	struct ac_arg instance_id;
75 	struct ac_arg tcs_patch_id;
76 	struct ac_arg tcs_rel_ids;
77 	struct ac_arg tes_patch_id;
78 	struct ac_arg gs_prim_id;
79 	struct ac_arg gs_invocation_id;
80 
81 	/* PS */
82 	struct ac_arg frag_pos[4];
83 	struct ac_arg front_face;
84 	struct ac_arg ancillary;
85 	struct ac_arg sample_coverage;
86 	struct ac_arg prim_mask;
87 	struct ac_arg persp_sample;
88 	struct ac_arg persp_center;
89 	struct ac_arg persp_centroid;
90 	struct ac_arg pull_model;
91 	struct ac_arg linear_sample;
92 	struct ac_arg linear_center;
93 	struct ac_arg linear_centroid;
94 
95 	/* CS */
96 	struct ac_arg local_invocation_ids;
97 	struct ac_arg num_work_groups;
98 	struct ac_arg workgroup_ids[3];
99 	struct ac_arg tg_size;
100 
101 	/* Vulkan only */
102 	struct ac_arg push_constants;
103 	struct ac_arg inline_push_consts[AC_MAX_INLINE_PUSH_CONSTS];
104 	unsigned num_inline_push_consts;
105 	unsigned base_inline_push_consts;
106 	struct ac_arg view_index;
107 };
108 
109 void ac_add_arg(struct ac_shader_args *info, enum ac_arg_regfile regfile,
110 		unsigned registers, enum ac_arg_type type,
111 		struct ac_arg *arg);
112 
113 #endif
114 
115