Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/microsoft/compiler/dxil_module.h
4564 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
/*
25
* See the DirectX Shader Compiler for documentation for DXIL details:
26
* https://github.com/Microsoft/DirectXShaderCompiler/blob/master/docs/DXIL.rst
27
*/
28
29
#ifndef DXIL_MODULE_H
30
#define DXIL_MODULE_H
31
32
#ifdef __cplusplus
33
extern "C" {
34
#endif
35
36
#include "dxil_buffer.h"
37
#include "dxil_signature.h"
38
39
#include "util/list.h"
40
41
42
#define DXIL_SHADER_MAX_IO_ROWS 80
43
44
enum dxil_shader_kind {
45
DXIL_PIXEL_SHADER = 0,
46
DXIL_VERTEX_SHADER = 1,
47
DXIL_GEOMETRY_SHADER = 2,
48
DXIL_HULL_SHADER = 3,
49
DXIL_DOMAIN_SHADER = 4,
50
DXIL_COMPUTE_SHADER = 5,
51
};
52
53
extern int debug_dxil;
54
55
enum dxil_debug_flags {
56
DXIL_DEBUG_VERBOSE = 1 << 0,
57
DXIL_DEBUG_DUMP_BLOB = 1 << 1,
58
DXIL_DEBUG_TRACE = 1 << 2,
59
DXIL_DEBUG_DUMP_MODULE = 1 << 3,
60
};
61
62
enum dxil_bin_opcode {
63
DXIL_BINOP_ADD = 0,
64
DXIL_BINOP_SUB = 1,
65
DXIL_BINOP_MUL = 2,
66
DXIL_BINOP_UDIV = 3,
67
DXIL_BINOP_SDIV = 4,
68
DXIL_BINOP_UREM = 5,
69
DXIL_BINOP_SREM = 6,
70
DXIL_BINOP_SHL = 7,
71
DXIL_BINOP_LSHR = 8,
72
DXIL_BINOP_ASHR = 9,
73
DXIL_BINOP_AND = 10,
74
DXIL_BINOP_OR = 11,
75
DXIL_BINOP_XOR = 12,
76
DXIL_BINOP_INSTR_COUNT
77
};
78
79
enum dxil_cast_opcode {
80
DXIL_CAST_TRUNC = 0,
81
DXIL_CAST_ZEXT = 1,
82
DXIL_CAST_SEXT = 2,
83
DXIL_CAST_FPTOUI = 3,
84
DXIL_CAST_FPTOSI = 4,
85
DXIL_CAST_UITOFP = 5,
86
DXIL_CAST_SITOFP = 6,
87
DXIL_CAST_FPTRUNC = 7,
88
DXIL_CAST_FPEXT = 8,
89
DXIL_CAST_PTRTOINT = 9,
90
DXIL_CAST_INTTOPTR = 10,
91
DXIL_CAST_BITCAST = 11,
92
DXIL_CAST_ADDRSPACECAST = 12,
93
DXIL_CAST_INSTR_COUNT
94
};
95
96
enum dxil_cmp_pred {
97
DXIL_FCMP_FALSE = 0,
98
DXIL_FCMP_OEQ = 1,
99
DXIL_FCMP_OGT = 2,
100
DXIL_FCMP_OGE = 3,
101
DXIL_FCMP_OLT = 4,
102
DXIL_FCMP_OLE = 5,
103
DXIL_FCMP_ONE = 6,
104
DXIL_FCMP_ORD = 7,
105
DXIL_FCMP_UNO = 8,
106
DXIL_FCMP_UEQ = 9,
107
DXIL_FCMP_UGT = 10,
108
DXIL_FCMP_UGE = 11,
109
DXIL_FCMP_ULT = 12,
110
DXIL_FCMP_ULE = 13,
111
DXIL_FCMP_UNE = 14,
112
DXIL_FCMP_TRUE = 15,
113
DXIL_ICMP_EQ = 32,
114
DXIL_ICMP_NE = 33,
115
DXIL_ICMP_UGT = 34,
116
DXIL_ICMP_UGE = 35,
117
DXIL_ICMP_ULT = 36,
118
DXIL_ICMP_ULE = 37,
119
DXIL_ICMP_SGT = 38,
120
DXIL_ICMP_SGE = 39,
121
DXIL_ICMP_SLT = 40,
122
DXIL_ICMP_SLE = 41,
123
DXIL_CMP_INSTR_COUNT
124
};
125
126
enum dxil_opt_flags {
127
DXIL_UNSAFE_ALGEBRA = (1 << 0),
128
DXIL_NO_NANS = (1 << 1),
129
DXIL_NO_INFS = (1 << 2),
130
DXIL_NO_SIGNED_ZEROS = (1 << 3),
131
DXIL_ALLOW_RECIPROCAL = (1 << 4)
132
};
133
134
struct dxil_features {
135
unsigned doubles : 1,
136
cs_4x_raw_sb : 1,
137
uavs_at_every_stage : 1,
138
use_64uavs : 1,
139
min_precision : 1,
140
dx11_1_double_extensions : 1,
141
dx11_1_shader_extensions : 1,
142
dx9_comparison_filtering : 1,
143
tiled_resources : 1,
144
stencil_ref : 1,
145
inner_coverage : 1,
146
typed_uav_load_additional_formats : 1,
147
rovs : 1,
148
array_layer_from_vs_or_ds : 1,
149
wave_ops : 1,
150
int64_ops : 1,
151
view_id : 1,
152
barycentrics : 1,
153
native_low_precision : 1,
154
shading_rate : 1,
155
raytracing_tier_1_1 : 1,
156
sampler_feedback : 1;
157
};
158
159
struct dxil_shader_info {
160
unsigned has_out_position:1;
161
unsigned has_out_depth:1;
162
};
163
164
struct dxil_module {
165
void *ralloc_ctx;
166
enum dxil_shader_kind shader_kind;
167
unsigned major_version, minor_version;
168
struct dxil_features feats;
169
unsigned raw_and_structured_buffers : 1;
170
struct dxil_shader_info info;
171
172
struct dxil_buffer buf;
173
174
unsigned num_sig_inputs;
175
unsigned num_sig_outputs;
176
unsigned num_psv_inputs;
177
unsigned num_psv_outputs;
178
179
struct dxil_signature_record inputs[DXIL_SHADER_MAX_IO_ROWS];
180
struct dxil_signature_record outputs[DXIL_SHADER_MAX_IO_ROWS];
181
182
struct dxil_psv_signature_element psv_inputs[DXIL_SHADER_MAX_IO_ROWS];
183
struct dxil_psv_signature_element psv_outputs[DXIL_SHADER_MAX_IO_ROWS];
184
185
struct _mesa_string_buffer *sem_string_table;
186
struct dxil_psv_sem_index_table sem_index_table;
187
188
struct {
189
unsigned abbrev_width;
190
intptr_t offset;
191
} blocks[16];
192
size_t num_blocks;
193
194
struct list_head type_list;
195
struct list_head gvar_list;
196
struct list_head func_list;
197
struct list_head attr_set_list;
198
struct list_head instr_list;
199
struct list_head const_list;
200
struct list_head mdnode_list;
201
struct list_head md_named_node_list;
202
const struct dxil_type *void_type;
203
const struct dxil_type *int1_type, *int8_type, *int16_type,
204
*int32_type, *int64_type;
205
const struct dxil_type *float16_type, *float32_type, *float64_type;
206
207
struct rb_tree *functions;
208
209
int *basic_block_ids; /* maps from "user" ids to LLVM ids */
210
size_t num_basic_block_ids;
211
unsigned curr_block;
212
};
213
214
struct dxil_instr;
215
struct dxil_value;
216
217
void
218
dxil_module_init(struct dxil_module *m, void *ralloc_ctx);
219
220
void
221
dxil_module_release(struct dxil_module *m);
222
223
const struct dxil_value *
224
dxil_add_global_var(struct dxil_module *m, const char *name,
225
const struct dxil_type *type,
226
enum dxil_address_space as, int align,
227
const struct dxil_value *value);
228
229
const struct dxil_value *
230
dxil_add_global_ptr_var(struct dxil_module *m, const char *name,
231
const struct dxil_type *type,
232
enum dxil_address_space as, int align,
233
const struct dxil_value *value);
234
235
const struct dxil_func *
236
dxil_add_function_def(struct dxil_module *m, const char *name,
237
const struct dxil_type *type);
238
239
const struct dxil_func *
240
dxil_add_function_decl(struct dxil_module *m, const char *name,
241
const struct dxil_type *type,
242
enum dxil_attr_kind attr);
243
244
const struct dxil_type *
245
dxil_module_get_void_type(struct dxil_module *m);
246
247
const struct dxil_type *
248
dxil_module_get_int_type(struct dxil_module *m, unsigned bit_size);
249
250
const struct dxil_type *
251
dxil_module_get_float_type(struct dxil_module *m, unsigned bit_size);
252
253
const struct dxil_type *
254
dxil_module_get_pointer_type(struct dxil_module *m,
255
const struct dxil_type *target);
256
257
const struct dxil_type *
258
dxil_get_overload_type(struct dxil_module *mod, enum overload_type overload);
259
260
const struct dxil_type *
261
dxil_module_get_handle_type(struct dxil_module *m);
262
263
const struct dxil_type *
264
dxil_module_get_cbuf_ret_type(struct dxil_module *mod, enum overload_type overload);
265
266
const struct dxil_type *
267
dxil_module_get_split_double_ret_type(struct dxil_module *mod);
268
269
const struct dxil_type *
270
dxil_module_get_res_type(struct dxil_module *m, enum dxil_resource_kind kind,
271
enum dxil_component_type comp_type, bool readwrite);
272
273
const struct dxil_type *
274
dxil_module_get_resret_type(struct dxil_module *m, enum overload_type overload);
275
276
const struct dxil_type *
277
dxil_module_get_dimret_type(struct dxil_module *m);
278
279
const struct dxil_type *
280
dxil_module_get_struct_type(struct dxil_module *m,
281
const char *name,
282
const struct dxil_type **elem_types,
283
size_t num_elem_types);
284
285
const struct dxil_type *
286
dxil_module_get_array_type(struct dxil_module *m,
287
const struct dxil_type *elem_type,
288
size_t num_elems);
289
290
const struct dxil_type *
291
dxil_module_get_vector_type(struct dxil_module *m,
292
const struct dxil_type *elem_type,
293
size_t num_elems);
294
295
const struct dxil_type *
296
dxil_module_add_function_type(struct dxil_module *m,
297
const struct dxil_type *ret_type,
298
const struct dxil_type **arg_types,
299
size_t num_arg_types);
300
301
nir_alu_type
302
dxil_type_to_nir_type(const struct dxil_type *type);
303
304
bool
305
dxil_value_type_equal_to(const struct dxil_value *value,
306
const struct dxil_type *lhs);
307
308
bool
309
dxil_value_type_bitsize_equal_to(const struct dxil_value *value, unsigned bitsize);
310
311
const struct dxil_type *
312
dxil_value_get_type(const struct dxil_value *value);
313
314
const struct dxil_value *
315
dxil_module_get_int1_const(struct dxil_module *m, bool value);
316
317
const struct dxil_value *
318
dxil_module_get_int8_const(struct dxil_module *m, int8_t value);
319
320
const struct dxil_value *
321
dxil_module_get_int16_const(struct dxil_module *m, int16_t value);
322
323
const struct dxil_value *
324
dxil_module_get_int32_const(struct dxil_module *m, int32_t value);
325
326
const struct dxil_value *
327
dxil_module_get_int64_const(struct dxil_module *m, int64_t value);
328
329
const struct dxil_value *
330
dxil_module_get_int_const(struct dxil_module *m, intmax_t value,
331
unsigned bit_size);
332
333
const struct dxil_value *
334
dxil_module_get_float16_const(struct dxil_module *m, uint16_t);
335
336
const struct dxil_value *
337
dxil_module_get_float_const(struct dxil_module *m, float value);
338
339
const struct dxil_value *
340
dxil_module_get_double_const(struct dxil_module *m, double value);
341
342
const struct dxil_value *
343
dxil_module_get_array_const(struct dxil_module *m, const struct dxil_type *type,
344
const struct dxil_value **values);
345
346
const struct dxil_value *
347
dxil_module_get_undef(struct dxil_module *m, const struct dxil_type *type);
348
349
const struct dxil_mdnode *
350
dxil_get_metadata_string(struct dxil_module *m, const char *str);
351
352
const struct dxil_mdnode *
353
dxil_get_metadata_value(struct dxil_module *m, const struct dxil_type *type,
354
const struct dxil_value *value);
355
356
const struct dxil_mdnode *
357
dxil_get_metadata_func(struct dxil_module *m, const struct dxil_func *func);
358
359
const struct dxil_mdnode *
360
dxil_get_metadata_int1(struct dxil_module *m, bool value);
361
362
const struct dxil_mdnode *
363
dxil_get_metadata_int8(struct dxil_module *m, int8_t value);
364
365
const struct dxil_mdnode *
366
dxil_get_metadata_int32(struct dxil_module *m, int32_t value);
367
368
const struct dxil_mdnode *
369
dxil_get_metadata_int64(struct dxil_module *m, int64_t value);
370
371
const struct dxil_mdnode *
372
dxil_get_metadata_node(struct dxil_module *m,
373
const struct dxil_mdnode *subnodes[],
374
size_t num_subnodes);
375
376
bool
377
dxil_add_metadata_named_node(struct dxil_module *m, const char *name,
378
const struct dxil_mdnode *subnodes[],
379
size_t num_subnodes);
380
381
const struct dxil_value *
382
dxil_emit_binop(struct dxil_module *m, enum dxil_bin_opcode opcode,
383
const struct dxil_value *op0, const struct dxil_value *op1,
384
enum dxil_opt_flags flags);
385
386
const struct dxil_value *
387
dxil_emit_cmp(struct dxil_module *m, enum dxil_cmp_pred pred,
388
const struct dxil_value *op0, const struct dxil_value *op1);
389
390
const struct dxil_value *
391
dxil_emit_select(struct dxil_module *m,
392
const struct dxil_value *op0,
393
const struct dxil_value *op1,
394
const struct dxil_value *op2);
395
396
const struct dxil_value *
397
dxil_emit_extractval(struct dxil_module *m, const struct dxil_value *src,
398
const unsigned int index);
399
400
const struct dxil_value *
401
dxil_emit_cast(struct dxil_module *m, enum dxil_cast_opcode opcode,
402
const struct dxil_type *type,
403
const struct dxil_value *value);
404
405
bool
406
dxil_emit_branch(struct dxil_module *m, const struct dxil_value *cond,
407
unsigned true_block, unsigned false_block);
408
409
const struct dxil_value *
410
dxil_instr_get_return_value(struct dxil_instr *instr);
411
412
struct dxil_instr *
413
dxil_emit_phi(struct dxil_module *m, const struct dxil_type *type);
414
415
void
416
dxil_phi_set_incoming(struct dxil_instr *instr,
417
const struct dxil_value *incoming_values[],
418
const unsigned incoming_blocks[],
419
size_t num_incoming);
420
421
const struct dxil_value *
422
dxil_emit_call(struct dxil_module *m,
423
const struct dxil_func *func,
424
const struct dxil_value **args, size_t num_args);
425
426
bool
427
dxil_emit_call_void(struct dxil_module *m,
428
const struct dxil_func *func,
429
const struct dxil_value **args, size_t num_args);
430
431
bool
432
dxil_emit_ret_void(struct dxil_module *m);
433
434
const struct dxil_value *
435
dxil_emit_alloca(struct dxil_module *m, const struct dxil_type *alloc_type,
436
const struct dxil_type *size_type,
437
const struct dxil_value *size,
438
unsigned int align);
439
440
const struct dxil_value *
441
dxil_emit_gep_inbounds(struct dxil_module *m,
442
const struct dxil_value **operands,
443
size_t num_operands);
444
445
const struct dxil_value *
446
dxil_emit_load(struct dxil_module *m, const struct dxil_value *ptr,
447
unsigned align,
448
bool is_volatile);
449
450
bool
451
dxil_emit_store(struct dxil_module *m, const struct dxil_value *value,
452
const struct dxil_value *ptr, unsigned align,
453
bool is_volatile);
454
455
const struct dxil_value *
456
dxil_emit_cmpxchg(struct dxil_module *m, const struct dxil_value *cmpval,
457
const struct dxil_value *newval,
458
const struct dxil_value *ptr, bool is_volatile,
459
enum dxil_atomic_ordering ordering,
460
enum dxil_sync_scope syncscope);
461
462
const struct dxil_value *
463
dxil_emit_atomicrmw(struct dxil_module *m, const struct dxil_value *value,
464
const struct dxil_value *ptr, enum dxil_rmw_op op,
465
bool is_volatile, enum dxil_atomic_ordering ordering,
466
enum dxil_sync_scope syncscope);
467
468
bool
469
dxil_emit_module(struct dxil_module *m);
470
471
#ifdef __cplusplus
472
}
473
#endif
474
475
#endif
476
477