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