Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/zink/nir_to_spirv/spirv_builder.h
4574 views
1
/*
2
* Copyright 2018 Collabora Ltd.
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 SPIRV_BUILDER_H
25
#define SPIRV_BUILDER_H
26
27
#include "compiler/spirv/spirv.h"
28
#include "compiler/spirv/GLSL.std.450.h"
29
30
#include <stdbool.h>
31
#include <stdint.h>
32
#include <stdlib.h>
33
34
struct hash_table;
35
struct set;
36
37
struct spirv_buffer {
38
uint32_t *words;
39
size_t num_words, room;
40
};
41
42
struct spirv_builder {
43
void *mem_ctx;
44
45
struct set *caps;
46
47
struct spirv_buffer extensions;
48
struct spirv_buffer imports;
49
struct spirv_buffer memory_model;
50
struct spirv_buffer entry_points;
51
struct spirv_buffer exec_modes;
52
struct spirv_buffer debug_names;
53
struct spirv_buffer decorations;
54
55
struct spirv_buffer types_const_defs;
56
struct hash_table *types;
57
struct hash_table *consts;
58
59
struct spirv_buffer instructions;
60
SpvId prev_id;
61
};
62
63
static inline SpvId
64
spirv_builder_new_id(struct spirv_builder *b)
65
{
66
return ++b->prev_id;
67
}
68
69
void
70
spirv_builder_emit_cap(struct spirv_builder *b, SpvCapability cap);
71
72
void
73
spirv_builder_emit_extension(struct spirv_builder *b, const char *ext);
74
75
void
76
spirv_builder_emit_source(struct spirv_builder *b, SpvSourceLanguage lang,
77
uint32_t version);
78
79
void
80
spirv_builder_emit_mem_model(struct spirv_builder *b,
81
SpvAddressingModel addr_model,
82
SpvMemoryModel mem_model);
83
84
void
85
spirv_builder_emit_name(struct spirv_builder *b, SpvId target,
86
const char *name);
87
88
void
89
spirv_builder_emit_decoration(struct spirv_builder *b, SpvId target,
90
SpvDecoration decoration);
91
92
void
93
spirv_builder_emit_specid(struct spirv_builder *b, SpvId target, uint32_t id);
94
95
void
96
spirv_builder_emit_location(struct spirv_builder *b, SpvId target,
97
uint32_t location);
98
99
void
100
spirv_builder_emit_component(struct spirv_builder *b, SpvId target,
101
uint32_t component);
102
103
void
104
spirv_builder_emit_builtin(struct spirv_builder *b, SpvId target,
105
SpvBuiltIn builtin);
106
107
void
108
spirv_builder_emit_index(struct spirv_builder *b, SpvId target, int index);
109
110
void
111
spirv_builder_emit_stream(struct spirv_builder *b, SpvId target, int stream);
112
113
void
114
spirv_builder_emit_descriptor_set(struct spirv_builder *b, SpvId target,
115
uint32_t descriptor_set);
116
117
void
118
spirv_builder_emit_binding(struct spirv_builder *b, SpvId target,
119
uint32_t binding);
120
121
void
122
spirv_builder_emit_array_stride(struct spirv_builder *b, SpvId target,
123
uint32_t stride);
124
125
void
126
spirv_builder_emit_offset(struct spirv_builder *b, SpvId target,
127
uint32_t offset);
128
129
void
130
spirv_builder_emit_xfb_buffer(struct spirv_builder *b, SpvId target,
131
uint32_t buffer);
132
133
void
134
spirv_builder_emit_xfb_stride(struct spirv_builder *b, SpvId target,
135
uint32_t stride);
136
137
void
138
spirv_builder_emit_member_offset(struct spirv_builder *b, SpvId target,
139
uint32_t member, uint32_t offset);
140
141
void
142
spirv_builder_emit_entry_point(struct spirv_builder *b,
143
SpvExecutionModel exec_model, SpvId entry_point,
144
const char *name, const SpvId interfaces[],
145
size_t num_interfaces);
146
void
147
spirv_builder_emit_exec_mode_literal(struct spirv_builder *b, SpvId entry_point,
148
SpvExecutionMode exec_mode, uint32_t param);
149
void
150
spirv_builder_emit_exec_mode_literal3(struct spirv_builder *b, SpvId entry_point,
151
SpvExecutionMode exec_mode, uint32_t param[3]);
152
void
153
spirv_builder_emit_exec_mode(struct spirv_builder *b, SpvId entry_point,
154
SpvExecutionMode exec_mode);
155
156
void
157
spirv_builder_function(struct spirv_builder *b, SpvId result,
158
SpvId return_type,
159
SpvFunctionControlMask function_control,
160
SpvId function_type);
161
162
void
163
spirv_builder_function_end(struct spirv_builder *b);
164
165
void
166
spirv_builder_label(struct spirv_builder *b, SpvId label);
167
168
void
169
spirv_builder_return(struct spirv_builder *b);
170
171
SpvId
172
spirv_builder_emit_undef(struct spirv_builder *b, SpvId result_type);
173
174
SpvId
175
spirv_builder_emit_load(struct spirv_builder *b, SpvId result_type,
176
SpvId pointer);
177
178
void
179
spirv_builder_emit_atomic_store(struct spirv_builder *b, SpvId pointer, SpvScope scope,
180
SpvMemorySemanticsMask semantics, SpvId object);
181
182
void
183
spirv_builder_emit_store(struct spirv_builder *b, SpvId pointer, SpvId object);
184
185
SpvId
186
spirv_builder_emit_access_chain(struct spirv_builder *b, SpvId result_type,
187
SpvId base, const SpvId indexes[],
188
size_t num_indexes);
189
190
void
191
spirv_builder_emit_interlock(struct spirv_builder *b, bool end);
192
193
SpvId
194
spirv_builder_emit_unop_const(struct spirv_builder *b, SpvOp op, SpvId result_type, uint64_t operand);
195
196
SpvId
197
spirv_builder_emit_unop(struct spirv_builder *b, SpvOp op, SpvId result_type,
198
SpvId operand);
199
200
SpvId
201
spirv_builder_emit_binop(struct spirv_builder *b, SpvOp op, SpvId result_type,
202
SpvId operand0, SpvId operand1);
203
204
SpvId
205
spirv_builder_emit_triop(struct spirv_builder *b, SpvOp op, SpvId result_type,
206
SpvId operand0, SpvId operand1, SpvId operand2);
207
208
SpvId
209
spirv_builder_emit_quadop(struct spirv_builder *b, SpvOp op, SpvId result_type,
210
SpvId operand0, SpvId operand1, SpvId operand2, SpvId operand3);
211
212
SpvId
213
spirv_builder_emit_hexop(struct spirv_builder *b, SpvOp op, SpvId result_type,
214
SpvId operand0, SpvId operand1, SpvId operand2, SpvId operand3,
215
SpvId operand4, SpvId operand5);
216
217
SpvId
218
spirv_builder_emit_composite_extract(struct spirv_builder *b, SpvId result_type,
219
SpvId composite, const uint32_t indexes[],
220
size_t num_indexes);
221
222
SpvId
223
spirv_builder_emit_composite_construct(struct spirv_builder *b,
224
SpvId result_type,
225
const SpvId constituents[],
226
size_t num_constituents);
227
228
SpvId
229
spirv_builder_emit_vector_shuffle(struct spirv_builder *b, SpvId result_type,
230
SpvId vector_1, SpvId vector_2,
231
const uint32_t components[],
232
size_t num_components);
233
SpvId
234
spirv_builder_emit_vector_extract(struct spirv_builder *b, SpvId result_type,
235
SpvId vector_1,
236
uint32_t component);
237
SpvId
238
spirv_builder_emit_vector_insert(struct spirv_builder *b, SpvId result_type,
239
SpvId vector_1,
240
SpvId component,
241
uint32_t index);
242
void
243
spirv_builder_emit_branch(struct spirv_builder *b, SpvId label);
244
245
void
246
spirv_builder_emit_selection_merge(struct spirv_builder *b, SpvId merge_block,
247
SpvSelectionControlMask selection_control);
248
249
void
250
spirv_builder_loop_merge(struct spirv_builder *b, SpvId merge_block,
251
SpvId cont_target, SpvLoopControlMask loop_control);
252
253
void
254
spirv_builder_emit_branch_conditional(struct spirv_builder *b, SpvId condition,
255
SpvId true_label, SpvId false_label);
256
257
SpvId
258
spirv_builder_emit_phi(struct spirv_builder *b, SpvId result_type,
259
size_t num_vars, size_t *position);
260
261
void
262
spirv_builder_set_phi_operand(struct spirv_builder *b, size_t position,
263
size_t index, SpvId variable, SpvId parent);
264
265
void
266
spirv_builder_emit_kill(struct spirv_builder *b);
267
268
SpvId
269
spirv_builder_emit_vote(struct spirv_builder *b, SpvOp op, SpvId src);
270
271
SpvId
272
spirv_builder_emit_image_sample(struct spirv_builder *b,
273
SpvId result_type,
274
SpvId sampled_image,
275
SpvId coordinate,
276
bool proj,
277
SpvId lod,
278
SpvId bias,
279
SpvId dref,
280
SpvId dx,
281
SpvId dy,
282
SpvId const_offset,
283
SpvId offset);
284
285
SpvId
286
spirv_builder_emit_image(struct spirv_builder *b, SpvId result_type,
287
SpvId sampled_image);
288
289
SpvId
290
spirv_builder_emit_image_texel_pointer(struct spirv_builder *b,
291
SpvId result_type,
292
SpvId image,
293
SpvId coordinate,
294
SpvId sample);
295
296
SpvId
297
spirv_builder_emit_image_read(struct spirv_builder *b,
298
SpvId result_type,
299
SpvId image,
300
SpvId coordinate,
301
SpvId lod,
302
SpvId sample,
303
SpvId offset);
304
305
void
306
spirv_builder_emit_image_write(struct spirv_builder *b,
307
SpvId image,
308
SpvId coordinate,
309
SpvId texel,
310
SpvId lod,
311
SpvId sample,
312
SpvId offset);
313
314
SpvId
315
spirv_builder_emit_image_fetch(struct spirv_builder *b,
316
SpvId result_type,
317
SpvId image,
318
SpvId coordinate,
319
SpvId lod,
320
SpvId sample,
321
SpvId const_offset,
322
SpvId offset);
323
SpvId
324
spirv_builder_emit_image_gather(struct spirv_builder *b,
325
SpvId result_type,
326
SpvId image,
327
SpvId coordinate,
328
SpvId component,
329
SpvId lod,
330
SpvId sample,
331
SpvId const_offset,
332
SpvId offset,
333
SpvId dref);
334
335
SpvId
336
spirv_builder_emit_image_query_size(struct spirv_builder *b,
337
SpvId result_type,
338
SpvId image,
339
SpvId lod);
340
341
SpvId
342
spirv_builder_emit_image_query_levels(struct spirv_builder *b,
343
SpvId result_type,
344
SpvId image);
345
346
SpvId
347
spirv_builder_emit_image_query_lod(struct spirv_builder *b,
348
SpvId result_type,
349
SpvId image,
350
SpvId coords);
351
352
SpvId
353
spirv_builder_emit_ext_inst(struct spirv_builder *b, SpvId result_type,
354
SpvId set, uint32_t instruction,
355
const SpvId args[], size_t num_args);
356
357
SpvId
358
spirv_builder_type_void(struct spirv_builder *b);
359
360
SpvId
361
spirv_builder_type_bool(struct spirv_builder *b);
362
363
SpvId
364
spirv_builder_type_int(struct spirv_builder *b, unsigned width);
365
366
SpvId
367
spirv_builder_type_uint(struct spirv_builder *b, unsigned width);
368
369
SpvId
370
spirv_builder_type_float(struct spirv_builder *b, unsigned width);
371
372
SpvId
373
spirv_builder_type_image(struct spirv_builder *b, SpvId sampled_type,
374
SpvDim dim, bool depth, bool arrayed, bool ms,
375
unsigned sampled, SpvImageFormat image_format);
376
377
SpvId
378
spirv_builder_type_sampled_image(struct spirv_builder *b, SpvId image_type);
379
380
SpvId
381
spirv_builder_type_pointer(struct spirv_builder *b,
382
SpvStorageClass storage_class, SpvId type);
383
384
SpvId
385
spirv_builder_type_vector(struct spirv_builder *b, SpvId component_type,
386
unsigned component_count);
387
388
SpvId
389
spirv_builder_type_matrix(struct spirv_builder *b, SpvId component_type,
390
unsigned component_count);
391
392
SpvId
393
spirv_builder_type_runtime_array(struct spirv_builder *b, SpvId component_type);
394
395
SpvId
396
spirv_builder_type_array(struct spirv_builder *b, SpvId component_type,
397
SpvId length);
398
399
SpvId
400
spirv_builder_type_struct(struct spirv_builder *b, const SpvId member_types[],
401
size_t num_member_types);
402
403
SpvId
404
spirv_builder_type_function(struct spirv_builder *b, SpvId return_type,
405
const SpvId parameter_types[],
406
size_t num_parameter_types);
407
408
SpvId
409
spirv_builder_const_bool(struct spirv_builder *b, bool val);
410
411
SpvId
412
spirv_builder_const_int(struct spirv_builder *b, int width, int64_t val);
413
414
SpvId
415
spirv_builder_const_uint(struct spirv_builder *b, int width, uint64_t val);
416
417
SpvId
418
spirv_builder_spec_const_uint(struct spirv_builder *b, int width);
419
420
SpvId
421
spirv_builder_const_float(struct spirv_builder *b, int width, double val);
422
423
SpvId
424
spirv_builder_const_composite(struct spirv_builder *b, SpvId result_type,
425
const SpvId constituents[],
426
size_t num_constituents);
427
428
SpvId
429
spirv_builder_spec_const_composite(struct spirv_builder *b, SpvId result_type,
430
const SpvId constituents[],
431
size_t num_constituents);
432
433
SpvId
434
spirv_builder_emit_var(struct spirv_builder *b, SpvId type,
435
SpvStorageClass storage_class);
436
437
void
438
spirv_builder_emit_memory_barrier(struct spirv_builder *b, SpvScope scope, SpvMemorySemanticsMask semantics);
439
440
void
441
spirv_builder_emit_control_barrier(struct spirv_builder *b, SpvScope scope, SpvScope mem_scope, SpvMemorySemanticsMask semantics);
442
443
SpvId
444
spirv_builder_import(struct spirv_builder *b, const char *name);
445
446
size_t
447
spirv_builder_get_num_words(struct spirv_builder *b);
448
449
size_t
450
spirv_builder_get_words(struct spirv_builder *b, uint32_t *words,
451
size_t num_words, uint32_t spirv_version);
452
453
void
454
spirv_builder_emit_vertex(struct spirv_builder *b, uint32_t stream);
455
void
456
spirv_builder_end_primitive(struct spirv_builder *b, uint32_t stream);
457
#endif
458
459