Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/microsoft/clc/clc_compiler.h
4560 views
1
/*
2
* Copyright © Microsoft 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
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* 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 NONINFRINGEMENT.  IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
* IN THE SOFTWARE.
22
*/
23
24
#ifndef CLC_COMPILER_H
25
#define CLC_COMPILER_H
26
27
#ifdef __cplusplus
28
extern "C" {
29
#endif
30
31
#include <stddef.h>
32
#include <stdint.h>
33
34
struct clc_named_value {
35
const char *name;
36
const char *value;
37
};
38
39
struct clc_compile_args {
40
const struct clc_named_value *headers;
41
unsigned num_headers;
42
struct clc_named_value source;
43
const char * const *args;
44
unsigned num_args;
45
};
46
47
struct clc_linker_args {
48
const struct clc_object * const *in_objs;
49
unsigned num_in_objs;
50
unsigned create_library;
51
};
52
53
typedef void (*clc_msg_callback)(void *priv, const char *msg);
54
55
struct clc_logger {
56
void *priv;
57
clc_msg_callback error;
58
clc_msg_callback warning;
59
};
60
61
struct spirv_binary {
62
uint32_t *data;
63
size_t size;
64
};
65
66
enum clc_kernel_arg_type_qualifier {
67
CLC_KERNEL_ARG_TYPE_CONST = 1 << 0,
68
CLC_KERNEL_ARG_TYPE_RESTRICT = 1 << 1,
69
CLC_KERNEL_ARG_TYPE_VOLATILE = 1 << 2,
70
};
71
72
enum clc_kernel_arg_access_qualifier {
73
CLC_KERNEL_ARG_ACCESS_READ = 1 << 0,
74
CLC_KERNEL_ARG_ACCESS_WRITE = 1 << 1,
75
};
76
77
enum clc_kernel_arg_address_qualifier {
78
CLC_KERNEL_ARG_ADDRESS_PRIVATE,
79
CLC_KERNEL_ARG_ADDRESS_CONSTANT,
80
CLC_KERNEL_ARG_ADDRESS_LOCAL,
81
CLC_KERNEL_ARG_ADDRESS_GLOBAL,
82
};
83
84
struct clc_kernel_arg {
85
const char *name;
86
const char *type_name;
87
unsigned type_qualifier;
88
unsigned access_qualifier;
89
enum clc_kernel_arg_address_qualifier address_qualifier;
90
};
91
92
enum clc_vec_hint_type {
93
CLC_VEC_HINT_TYPE_CHAR = 0,
94
CLC_VEC_HINT_TYPE_SHORT = 1,
95
CLC_VEC_HINT_TYPE_INT = 2,
96
CLC_VEC_HINT_TYPE_LONG = 3,
97
CLC_VEC_HINT_TYPE_HALF = 4,
98
CLC_VEC_HINT_TYPE_FLOAT = 5,
99
CLC_VEC_HINT_TYPE_DOUBLE = 6
100
};
101
102
struct clc_kernel_info {
103
const char *name;
104
size_t num_args;
105
const struct clc_kernel_arg *args;
106
107
unsigned vec_hint_size;
108
enum clc_vec_hint_type vec_hint_type;
109
};
110
111
struct clc_object {
112
struct spirv_binary spvbin;
113
const struct clc_kernel_info *kernels;
114
unsigned num_kernels;
115
};
116
117
#define CLC_MAX_CONSTS 32
118
#define CLC_MAX_BINDINGS_PER_ARG 3
119
#define CLC_MAX_SAMPLERS 16
120
121
struct clc_printf_info {
122
unsigned num_args;
123
unsigned *arg_sizes;
124
char *str;
125
};
126
127
struct clc_dxil_metadata {
128
struct {
129
unsigned offset;
130
unsigned size;
131
union {
132
struct {
133
unsigned buf_ids[CLC_MAX_BINDINGS_PER_ARG];
134
unsigned num_buf_ids;
135
} image;
136
struct {
137
unsigned sampler_id;
138
} sampler;
139
struct {
140
unsigned buf_id;
141
} globconstptr;
142
struct {
143
unsigned sharedmem_offset;
144
} localptr;
145
};
146
} *args;
147
unsigned kernel_inputs_cbv_id;
148
unsigned kernel_inputs_buf_size;
149
unsigned work_properties_cbv_id;
150
size_t num_uavs;
151
size_t num_srvs;
152
size_t num_samplers;
153
154
struct {
155
void *data;
156
size_t size;
157
unsigned uav_id;
158
} consts[CLC_MAX_CONSTS];
159
size_t num_consts;
160
161
struct {
162
unsigned sampler_id;
163
unsigned addressing_mode;
164
unsigned normalized_coords;
165
unsigned filter_mode;
166
} const_samplers[CLC_MAX_SAMPLERS];
167
size_t num_const_samplers;
168
size_t local_mem_size;
169
size_t priv_mem_size;
170
171
uint16_t local_size[3];
172
uint16_t local_size_hint[3];
173
174
struct {
175
unsigned info_count;
176
struct clc_printf_info *infos;
177
int uav_id;
178
} printf;
179
};
180
181
struct clc_dxil_object {
182
const struct clc_kernel_info *kernel;
183
struct clc_dxil_metadata metadata;
184
struct {
185
void *data;
186
size_t size;
187
} binary;
188
};
189
190
struct clc_context {
191
const void *libclc_nir;
192
};
193
194
struct clc_context_options {
195
unsigned optimize;
196
};
197
198
struct clc_context *clc_context_new(const struct clc_logger *logger, const struct clc_context_options *options);
199
200
void clc_free_context(struct clc_context *ctx);
201
202
void clc_context_serialize(struct clc_context *ctx, void **serialized, size_t *size);
203
void clc_context_free_serialized(void *serialized);
204
struct clc_context *clc_context_deserialize(void *serialized, size_t size);
205
206
struct clc_object *
207
clc_compile(struct clc_context *ctx,
208
const struct clc_compile_args *args,
209
const struct clc_logger *logger);
210
211
struct clc_object *
212
clc_link(struct clc_context *ctx,
213
const struct clc_linker_args *args,
214
const struct clc_logger *logger);
215
216
void clc_free_object(struct clc_object *obj);
217
218
struct clc_runtime_arg_info {
219
union {
220
struct {
221
unsigned size;
222
} localptr;
223
struct {
224
unsigned normalized_coords;
225
unsigned addressing_mode; /* See SPIR-V spec for value meanings */
226
unsigned linear_filtering;
227
} sampler;
228
};
229
};
230
231
struct clc_runtime_kernel_conf {
232
uint16_t local_size[3];
233
struct clc_runtime_arg_info *args;
234
unsigned lower_bit_size;
235
unsigned support_global_work_id_offsets;
236
unsigned support_workgroup_id_offsets;
237
};
238
239
struct clc_dxil_object *
240
clc_to_dxil(struct clc_context *ctx,
241
const struct clc_object *obj,
242
const char *entrypoint,
243
const struct clc_runtime_kernel_conf *conf,
244
const struct clc_logger *logger);
245
246
void clc_free_dxil_object(struct clc_dxil_object *dxil);
247
248
/* This struct describes the layout of data expected in the CB bound at global_work_offset_cbv_id */
249
struct clc_work_properties_data {
250
/* Returned from get_global_offset(), and added into get_global_id() */
251
unsigned global_offset_x;
252
unsigned global_offset_y;
253
unsigned global_offset_z;
254
/* Returned from get_work_dim() */
255
unsigned work_dim;
256
/* The number of work groups being launched (i.e. the parameters to Dispatch).
257
* If the requested global size doesn't fit in a single Dispatch, these values should
258
* indicate the total number of groups that *should* have been launched. */
259
unsigned group_count_total_x;
260
unsigned group_count_total_y;
261
unsigned group_count_total_z;
262
unsigned padding;
263
/* If the requested global size doesn't fit in a single Dispatch, subsequent dispatches
264
* should fill out these offsets to indicate how many groups have already been launched */
265
unsigned group_id_offset_x;
266
unsigned group_id_offset_y;
267
unsigned group_id_offset_z;
268
};
269
270
uint64_t clc_compiler_get_version();
271
272
#ifdef __cplusplus
273
}
274
#endif
275
276
#endif
277
278