e74caeda68da23c953f35570b1932995a09ca890
[platform/upstream/mesa.git] / src / amd / common / ac_shader_args.h
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 /* Maximum dwords of inline push constants when the indirect path is still used */
31 #define AC_MAX_INLINE_PUSH_CONSTS_WITH_INDIRECT 8
32 /* Maximum dwords of inline push constants when the indirect path is not used */
33 #define AC_MAX_INLINE_PUSH_CONSTS 32
34
35 enum ac_arg_regfile
36 {
37    AC_ARG_SGPR,
38    AC_ARG_VGPR,
39 };
40
41 enum ac_arg_type
42 {
43    AC_ARG_FLOAT,
44    AC_ARG_INT,
45    AC_ARG_CONST_PTR,       /* Pointer to i8 array */
46    AC_ARG_CONST_FLOAT_PTR, /* Pointer to f32 array */
47    AC_ARG_CONST_PTR_PTR,   /* Pointer to pointer to i8 array */
48    AC_ARG_CONST_DESC_PTR,  /* Pointer to v4i32 array */
49    AC_ARG_CONST_IMAGE_PTR, /* Pointer to v8i32 array */
50 };
51
52 struct ac_arg {
53    uint16_t arg_index;
54    bool used;
55 };
56
57 #define AC_MAX_ARGS 384 /* including all VS->TCS IO */
58
59 struct ac_shader_args {
60    /* Info on how to declare arguments */
61    struct {
62       enum ac_arg_type type;
63       enum ac_arg_regfile file;
64       uint8_t offset;
65       uint8_t size;
66       bool skip;
67    } args[AC_MAX_ARGS];
68
69    uint16_t arg_count;
70    uint16_t num_sgprs_used;
71    uint16_t num_vgprs_used;
72
73    uint16_t return_count;
74    uint16_t num_sgprs_returned;
75    uint16_t num_vgprs_returned;
76
77    /* VS */
78    struct ac_arg base_vertex;
79    struct ac_arg start_instance;
80    struct ac_arg draw_id;
81    struct ac_arg vertex_buffers;
82    struct ac_arg vertex_id;
83    struct ac_arg vs_rel_patch_id;
84    struct ac_arg vs_prim_id;
85    struct ac_arg instance_id;
86
87    /* Merged shaders */
88    struct ac_arg tess_offchip_offset;
89    struct ac_arg merged_wave_info;
90    /* On gfx10:
91     *  - bits 0..11: ordered_wave_id
92     *  - bits 12..20: number of vertices in group
93     *  - bits 22..30: number of primitives in group
94     */
95    struct ac_arg gs_tg_info;
96    struct ac_arg scratch_offset;
97
98    /* TCS */
99    struct ac_arg tcs_factor_offset;
100    struct ac_arg tcs_wave_id; /* gfx11+ */
101    struct ac_arg tcs_patch_id;
102    struct ac_arg tcs_rel_ids;
103
104    /* TES */
105    struct ac_arg tes_u;
106    struct ac_arg tes_v;
107    struct ac_arg tes_rel_patch_id;
108    struct ac_arg tes_patch_id;
109
110    /* GS */
111    struct ac_arg es2gs_offset;      /* separate legacy ES */
112    struct ac_arg gs2vs_offset;      /* legacy GS */
113    struct ac_arg gs_wave_id;        /* legacy GS */
114    struct ac_arg gs_attr_offset;    /* gfx11+: attribute ring offset in 512B increments */
115    struct ac_arg gs_vtx_offset[6];  /* GFX6-8: [0-5], GFX9+: [0-2] packed */
116    struct ac_arg gs_prim_id;
117    struct ac_arg gs_invocation_id;
118
119    /* Streamout */
120    struct ac_arg streamout_config;
121    struct ac_arg streamout_write_index;
122    struct ac_arg streamout_offset[4];
123
124    /* PS */
125    struct ac_arg frag_pos[4];
126    struct ac_arg front_face;
127    struct ac_arg ancillary;
128    struct ac_arg sample_coverage;
129    struct ac_arg prim_mask;
130    struct ac_arg persp_sample;
131    struct ac_arg persp_center;
132    struct ac_arg persp_centroid;
133    struct ac_arg pull_model;
134    struct ac_arg linear_sample;
135    struct ac_arg linear_center;
136    struct ac_arg linear_centroid;
137
138    /* CS */
139    struct ac_arg local_invocation_ids;
140    struct ac_arg num_work_groups;
141    struct ac_arg workgroup_ids[3];
142    struct ac_arg tg_size;
143
144    /* Mesh and task shaders */
145    struct ac_arg task_ring_entry; /* Pointer into the draw and payload rings. */
146
147    /* Vulkan only */
148    struct ac_arg push_constants;
149    struct ac_arg inline_push_consts[AC_MAX_INLINE_PUSH_CONSTS];
150    uint64_t inline_push_const_mask;
151    struct ac_arg view_index;
152    struct ac_arg sbt_descriptors;
153    struct ac_arg ray_launch_size;
154    struct ac_arg force_vrs_rates;
155 };
156
157 void ac_add_arg(struct ac_shader_args *info, enum ac_arg_regfile regfile, unsigned registers,
158                 enum ac_arg_type type, struct ac_arg *arg);
159 void ac_add_return(struct ac_shader_args *info, enum ac_arg_regfile regfile);
160
161 #endif