spirv: Record the type of functions
[mesa.git] / src / compiler / spirv / vtn_private.h
1 /*
2 * Copyright © 2015 Intel 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 * Authors:
24 * Jason Ekstrand (jason@jlekstrand.net)
25 *
26 */
27
28 #ifndef _VTN_PRIVATE_H_
29 #define _VTN_PRIVATE_H_
30
31 #include <setjmp.h>
32
33 #include "nir/nir.h"
34 #include "nir/nir_builder.h"
35 #include "util/u_dynarray.h"
36 #include "nir_spirv.h"
37 #include "spirv.h"
38
39 struct vtn_builder;
40 struct vtn_decoration;
41
42 void vtn_log(struct vtn_builder *b, enum nir_spirv_debug_level level,
43 size_t spirv_offset, const char *message);
44
45 void vtn_logf(struct vtn_builder *b, enum nir_spirv_debug_level level,
46 size_t spirv_offset, const char *fmt, ...) PRINTFLIKE(4, 5);
47
48 #define vtn_info(...) vtn_logf(b, NIR_SPIRV_DEBUG_LEVEL_INFO, 0, __VA_ARGS__)
49
50 void _vtn_warn(struct vtn_builder *b, const char *file, unsigned line,
51 const char *fmt, ...) PRINTFLIKE(4, 5);
52 #define vtn_warn(...) _vtn_warn(b, __FILE__, __LINE__, __VA_ARGS__)
53
54 void _vtn_err(struct vtn_builder *b, const char *file, unsigned line,
55 const char *fmt, ...) PRINTFLIKE(4, 5);
56 #define vtn_err(...) _vtn_err(b, __FILE__, __LINE__, __VA_ARGS__)
57
58 /** Fail SPIR-V parsing
59 *
60 * This function logs an error and then bails out of the shader compile using
61 * longjmp. This being safe relies on two things:
62 *
63 * 1) We must guarantee that setjmp is called after allocating the builder
64 * and setting up b->debug (so that logging works) but before before any
65 * errors have a chance to occur.
66 *
67 * 2) While doing the SPIR-V -> NIR conversion, we need to be careful to
68 * ensure that all heap allocations happen through ralloc and are parented
69 * to the builder. This way they will get properly cleaned up on error.
70 *
71 * 3) We must ensure that _vtn_fail is never called while a mutex lock or a
72 * reference to any other resource is held with the exception of ralloc
73 * objects which are parented to the builder.
74 *
75 * So long as these two things continue to hold, we can easily longjmp back to
76 * spirv_to_nir(), clean up the builder, and return NULL.
77 */
78 NORETURN void
79 _vtn_fail(struct vtn_builder *b, const char *file, unsigned line,
80 const char *fmt, ...) PRINTFLIKE(4, 5);
81
82 #define vtn_fail(...) _vtn_fail(b, __FILE__, __LINE__, __VA_ARGS__)
83
84 /** Fail if the given expression evaluates to true */
85 #define vtn_fail_if(expr, ...) \
86 do { \
87 if (unlikely(expr)) \
88 vtn_fail(__VA_ARGS__); \
89 } while (0)
90
91 /** Assert that a condition is true and, if it isn't, vtn_fail
92 *
93 * This macro is transitional only and should not be used in new code. Use
94 * vtn_fail_if and provide a real message instead.
95 */
96 #define vtn_assert(expr) \
97 do { \
98 if (!likely(expr)) \
99 vtn_fail("%s", #expr); \
100 } while (0)
101
102 enum vtn_value_type {
103 vtn_value_type_invalid = 0,
104 vtn_value_type_undef,
105 vtn_value_type_string,
106 vtn_value_type_decoration_group,
107 vtn_value_type_type,
108 vtn_value_type_constant,
109 vtn_value_type_pointer,
110 vtn_value_type_function,
111 vtn_value_type_block,
112 vtn_value_type_ssa,
113 vtn_value_type_extension,
114 vtn_value_type_image_pointer,
115 vtn_value_type_sampled_image,
116 };
117
118 enum vtn_branch_type {
119 vtn_branch_type_none,
120 vtn_branch_type_switch_break,
121 vtn_branch_type_switch_fallthrough,
122 vtn_branch_type_loop_break,
123 vtn_branch_type_loop_continue,
124 vtn_branch_type_discard,
125 vtn_branch_type_return,
126 };
127
128 enum vtn_cf_node_type {
129 vtn_cf_node_type_block,
130 vtn_cf_node_type_if,
131 vtn_cf_node_type_loop,
132 vtn_cf_node_type_switch,
133 };
134
135 struct vtn_cf_node {
136 struct list_head link;
137 enum vtn_cf_node_type type;
138 };
139
140 struct vtn_loop {
141 struct vtn_cf_node node;
142
143 /* The main body of the loop */
144 struct list_head body;
145
146 /* The "continue" part of the loop. This gets executed after the body
147 * and is where you go when you hit a continue.
148 */
149 struct list_head cont_body;
150
151 SpvLoopControlMask control;
152 };
153
154 struct vtn_if {
155 struct vtn_cf_node node;
156
157 uint32_t condition;
158
159 enum vtn_branch_type then_type;
160 struct list_head then_body;
161
162 enum vtn_branch_type else_type;
163 struct list_head else_body;
164
165 SpvSelectionControlMask control;
166 };
167
168 struct vtn_case {
169 struct list_head link;
170
171 struct list_head body;
172
173 /* The block that starts this case */
174 struct vtn_block *start_block;
175
176 /* The fallthrough case, if any */
177 struct vtn_case *fallthrough;
178
179 /* The uint32_t values that map to this case */
180 struct util_dynarray values;
181
182 /* True if this is the default case */
183 bool is_default;
184
185 /* Initialized to false; used when sorting the list of cases */
186 bool visited;
187 };
188
189 struct vtn_switch {
190 struct vtn_cf_node node;
191
192 uint32_t selector;
193
194 struct list_head cases;
195 };
196
197 struct vtn_block {
198 struct vtn_cf_node node;
199
200 /** A pointer to the label instruction */
201 const uint32_t *label;
202
203 /** A pointer to the merge instruction (or NULL if non exists) */
204 const uint32_t *merge;
205
206 /** A pointer to the branch instruction that ends this block */
207 const uint32_t *branch;
208
209 enum vtn_branch_type branch_type;
210
211 /** Points to the loop that this block starts (if it starts a loop) */
212 struct vtn_loop *loop;
213
214 /** Points to the switch case started by this block (if any) */
215 struct vtn_case *switch_case;
216
217 /** Every block ends in a nop intrinsic so that we can find it again */
218 nir_intrinsic_instr *end_nop;
219 };
220
221 struct vtn_function {
222 struct exec_node node;
223
224 struct vtn_type *type;
225
226 bool referenced;
227 bool emitted;
228
229 nir_function_impl *impl;
230 struct vtn_block *start_block;
231
232 struct list_head body;
233
234 const uint32_t *end;
235
236 SpvFunctionControlMask control;
237 };
238
239 typedef bool (*vtn_instruction_handler)(struct vtn_builder *, SpvOp,
240 const uint32_t *, unsigned);
241
242 void vtn_build_cfg(struct vtn_builder *b, const uint32_t *words,
243 const uint32_t *end);
244 void vtn_function_emit(struct vtn_builder *b, struct vtn_function *func,
245 vtn_instruction_handler instruction_handler);
246
247 const uint32_t *
248 vtn_foreach_instruction(struct vtn_builder *b, const uint32_t *start,
249 const uint32_t *end, vtn_instruction_handler handler);
250
251 struct vtn_ssa_value {
252 union {
253 nir_ssa_def *def;
254 struct vtn_ssa_value **elems;
255 };
256
257 /* For matrices, if this is non-NULL, then this value is actually the
258 * transpose of some other value. The value that `transposed` points to
259 * always dominates this value.
260 */
261 struct vtn_ssa_value *transposed;
262
263 const struct glsl_type *type;
264 };
265
266 enum vtn_base_type {
267 vtn_base_type_void,
268 vtn_base_type_scalar,
269 vtn_base_type_vector,
270 vtn_base_type_matrix,
271 vtn_base_type_array,
272 vtn_base_type_struct,
273 vtn_base_type_pointer,
274 vtn_base_type_image,
275 vtn_base_type_sampler,
276 vtn_base_type_sampled_image,
277 vtn_base_type_function,
278 };
279
280 struct vtn_type {
281 enum vtn_base_type base_type;
282
283 const struct glsl_type *type;
284
285 /* The SPIR-V id of the given type. */
286 uint32_t id;
287
288 /* Specifies the length of complex types.
289 *
290 * For Workgroup pointers, this is the size of the referenced type.
291 */
292 unsigned length;
293
294 /* for arrays, matrices and pointers, the array stride */
295 unsigned stride;
296
297 union {
298 /* Members for scalar, vector, and array-like types */
299 struct {
300 /* for arrays, the vtn_type for the elements of the array */
301 struct vtn_type *array_element;
302
303 /* for matrices, whether the matrix is stored row-major */
304 bool row_major:1;
305
306 /* Whether this type, or a parent type, has been decorated as a
307 * builtin
308 */
309 bool is_builtin:1;
310
311 /* Which built-in to use */
312 SpvBuiltIn builtin;
313 };
314
315 /* Members for struct types */
316 struct {
317 /* for structures, the vtn_type for each member */
318 struct vtn_type **members;
319
320 /* for structs, the offset of each member */
321 unsigned *offsets;
322
323 /* for structs, whether it was decorated as a "non-SSBO-like" block */
324 bool block:1;
325
326 /* for structs, whether it was decorated as an "SSBO-like" block */
327 bool buffer_block:1;
328
329 /* for structs with block == true, whether this is a builtin block
330 * (i.e. a block that contains only builtins).
331 */
332 bool builtin_block:1;
333 };
334
335 /* Members for pointer types */
336 struct {
337 /* For pointers, the vtn_type for dereferenced type */
338 struct vtn_type *deref;
339
340 /* Storage class for pointers */
341 SpvStorageClass storage_class;
342
343 /* Required alignment for pointers */
344 uint32_t align;
345 };
346
347 /* Members for image types */
348 struct {
349 /* For images, indicates whether it's sampled or storage */
350 bool sampled;
351
352 /* Image format for image_load_store type images */
353 unsigned image_format;
354
355 /* Access qualifier for storage images */
356 SpvAccessQualifier access_qualifier;
357 };
358
359 /* Members for sampled image types */
360 struct {
361 /* For sampled images, the image type */
362 struct vtn_type *image;
363 };
364
365 /* Members for function types */
366 struct {
367 /* For functions, the vtn_type for each parameter */
368 struct vtn_type **params;
369
370 /* Return type for functions */
371 struct vtn_type *return_type;
372 };
373 };
374 };
375
376 bool vtn_types_compatible(struct vtn_builder *b,
377 struct vtn_type *t1, struct vtn_type *t2);
378
379 struct vtn_variable;
380
381 enum vtn_access_mode {
382 vtn_access_mode_id,
383 vtn_access_mode_literal,
384 };
385
386 struct vtn_access_link {
387 enum vtn_access_mode mode;
388 uint32_t id;
389 };
390
391 struct vtn_access_chain {
392 uint32_t length;
393
394 /** Whether or not to treat the base pointer as an array. This is only
395 * true if this access chain came from an OpPtrAccessChain.
396 */
397 bool ptr_as_array;
398
399 /** Struct elements and array offsets.
400 *
401 * This is an array of 1 so that it can conveniently be created on the
402 * stack but the real length is given by the length field.
403 */
404 struct vtn_access_link link[1];
405 };
406
407 enum vtn_variable_mode {
408 vtn_variable_mode_local,
409 vtn_variable_mode_global,
410 vtn_variable_mode_param,
411 vtn_variable_mode_uniform,
412 vtn_variable_mode_ubo,
413 vtn_variable_mode_ssbo,
414 vtn_variable_mode_push_constant,
415 vtn_variable_mode_workgroup,
416 vtn_variable_mode_input,
417 vtn_variable_mode_output,
418 };
419
420 struct vtn_pointer {
421 /** The variable mode for the referenced data */
422 enum vtn_variable_mode mode;
423
424 /** The dereferenced type of this pointer */
425 struct vtn_type *type;
426
427 /** The pointer type of this pointer
428 *
429 * This may be NULL for some temporary pointers constructed as part of a
430 * large load, store, or copy. It MUST be valid for all pointers which are
431 * stored as SPIR-V SSA values.
432 */
433 struct vtn_type *ptr_type;
434
435 /** The referenced variable, if known
436 *
437 * This field may be NULL if the pointer uses a (block_index, offset) pair
438 * instead of an access chain or if the access chain starts at a deref.
439 */
440 struct vtn_variable *var;
441
442 /** The deref at the base of the chain
443 *
444 * This field may be NULL if the pointer uses a (block_index, offset) pair
445 * instead of an access chain or if the access chain starts at a variable.
446 */
447 nir_deref_instr *deref;
448
449 /** An access chain describing how to get from var to the referenced data
450 *
451 * This field may be NULL if the pointer references the entire variable or
452 * if a (block_index, offset) pair is used instead of an access chain.
453 */
454 struct vtn_access_chain *chain;
455
456 /** A (block_index, offset) pair representing a UBO or SSBO position. */
457 struct nir_ssa_def *block_index;
458 struct nir_ssa_def *offset;
459 };
460
461 struct vtn_variable {
462 enum vtn_variable_mode mode;
463
464 struct vtn_type *type;
465
466 unsigned descriptor_set;
467 unsigned binding;
468 bool explicit_binding;
469 unsigned input_attachment_index;
470 bool patch;
471
472 nir_variable *var;
473
474 int shared_location;
475
476 /**
477 * In some early released versions of GLSLang, it implemented all function
478 * calls by making copies of all parameters into temporary variables and
479 * passing those variables into the function. It even did so for samplers
480 * and images which violates the SPIR-V spec. Unfortunately, two games
481 * (Talos Principle and Doom) shipped with this old version of GLSLang and
482 * also happen to pass samplers into functions. Talos Principle received
483 * an update fairly shortly after release with an updated GLSLang. Doom,
484 * on the other hand, has never received an update so we need to work
485 * around this GLSLang issue in SPIR-V -> NIR. Hopefully, we can drop this
486 * hack at some point in the future.
487 */
488 struct vtn_pointer *copy_prop_sampler;
489 };
490
491 struct vtn_image_pointer {
492 struct vtn_pointer *image;
493 nir_ssa_def *coord;
494 nir_ssa_def *sample;
495 };
496
497 struct vtn_sampled_image {
498 struct vtn_type *type;
499 struct vtn_pointer *image; /* Image or array of images */
500 struct vtn_pointer *sampler; /* Sampler */
501 };
502
503 struct vtn_value {
504 enum vtn_value_type value_type;
505 const char *name;
506 struct vtn_decoration *decoration;
507 struct vtn_type *type;
508 union {
509 void *ptr;
510 char *str;
511 nir_constant *constant;
512 struct vtn_pointer *pointer;
513 struct vtn_image_pointer *image;
514 struct vtn_sampled_image *sampled_image;
515 struct vtn_function *func;
516 struct vtn_block *block;
517 struct vtn_ssa_value *ssa;
518 vtn_instruction_handler ext_handler;
519 };
520 };
521
522 #define VTN_DEC_DECORATION -1
523 #define VTN_DEC_EXECUTION_MODE -2
524 #define VTN_DEC_STRUCT_MEMBER0 0
525
526 struct vtn_decoration {
527 struct vtn_decoration *next;
528
529 /* Specifies how to apply this decoration. Negative values represent a
530 * decoration or execution mode. (See the VTN_DEC_ #defines above.)
531 * Non-negative values specify that it applies to a structure member.
532 */
533 int scope;
534
535 const uint32_t *literals;
536 struct vtn_value *group;
537
538 union {
539 SpvDecoration decoration;
540 SpvExecutionMode exec_mode;
541 };
542 };
543
544 struct vtn_builder {
545 nir_builder nb;
546
547 /* Used by vtn_fail to jump back to the beginning of SPIR-V compilation */
548 jmp_buf fail_jump;
549
550 const uint32_t *spirv;
551 size_t spirv_word_count;
552
553 nir_shader *shader;
554 const struct spirv_to_nir_options *options;
555 struct vtn_block *block;
556
557 /* Current offset, file, line, and column. Useful for debugging. Set
558 * automatically by vtn_foreach_instruction.
559 */
560 size_t spirv_offset;
561 char *file;
562 int line, col;
563
564 /*
565 * In SPIR-V, constants are global, whereas in NIR, the load_const
566 * instruction we use is per-function. So while we parse each function, we
567 * keep a hash table of constants we've resolved to nir_ssa_value's so
568 * far, and we lazily resolve them when we see them used in a function.
569 */
570 struct hash_table *const_table;
571
572 /*
573 * Map from phi instructions (pointer to the start of the instruction)
574 * to the variable corresponding to it.
575 */
576 struct hash_table *phi_table;
577
578 unsigned num_specializations;
579 struct nir_spirv_specialization *specializations;
580
581 unsigned value_id_bound;
582 struct vtn_value *values;
583
584 gl_shader_stage entry_point_stage;
585 const char *entry_point_name;
586 struct vtn_value *entry_point;
587 bool origin_upper_left;
588 bool pixel_center_integer;
589
590 struct vtn_function *func;
591 struct exec_list functions;
592
593 /* Current function parameter index */
594 unsigned func_param_idx;
595
596 bool has_loop_continue;
597 };
598
599 nir_ssa_def *
600 vtn_pointer_to_ssa(struct vtn_builder *b, struct vtn_pointer *ptr);
601 struct vtn_pointer *
602 vtn_pointer_from_ssa(struct vtn_builder *b, nir_ssa_def *ssa,
603 struct vtn_type *ptr_type);
604
605 static inline struct vtn_value *
606 vtn_untyped_value(struct vtn_builder *b, uint32_t value_id)
607 {
608 vtn_fail_if(value_id >= b->value_id_bound,
609 "SPIR-V id %u is out-of-bounds", value_id);
610 return &b->values[value_id];
611 }
612
613 static inline struct vtn_value *
614 vtn_push_value(struct vtn_builder *b, uint32_t value_id,
615 enum vtn_value_type value_type)
616 {
617 struct vtn_value *val = vtn_untyped_value(b, value_id);
618
619 vtn_fail_if(val->value_type != vtn_value_type_invalid,
620 "SPIR-V id %u has already been written by another instruction",
621 value_id);
622
623 val->value_type = value_type;
624 return &b->values[value_id];
625 }
626
627 static inline struct vtn_value *
628 vtn_push_ssa(struct vtn_builder *b, uint32_t value_id,
629 struct vtn_type *type, struct vtn_ssa_value *ssa)
630 {
631 struct vtn_value *val;
632 if (type->base_type == vtn_base_type_pointer) {
633 val = vtn_push_value(b, value_id, vtn_value_type_pointer);
634 val->pointer = vtn_pointer_from_ssa(b, ssa->def, type);
635 } else {
636 val = vtn_push_value(b, value_id, vtn_value_type_ssa);
637 val->ssa = ssa;
638 }
639 return val;
640 }
641
642 static inline struct vtn_value *
643 vtn_value(struct vtn_builder *b, uint32_t value_id,
644 enum vtn_value_type value_type)
645 {
646 struct vtn_value *val = vtn_untyped_value(b, value_id);
647 vtn_fail_if(val->value_type != value_type,
648 "SPIR-V id %u is the wrong kind of value", value_id);
649 return val;
650 }
651
652 bool
653 vtn_set_instruction_result_type(struct vtn_builder *b, SpvOp opcode,
654 const uint32_t *w, unsigned count);
655
656 static inline nir_constant *
657 vtn_constant_value(struct vtn_builder *b, uint32_t value_id)
658 {
659 return vtn_value(b, value_id, vtn_value_type_constant)->constant;
660 }
661
662 struct vtn_ssa_value *vtn_ssa_value(struct vtn_builder *b, uint32_t value_id);
663
664 struct vtn_ssa_value *vtn_create_ssa_value(struct vtn_builder *b,
665 const struct glsl_type *type);
666
667 struct vtn_ssa_value *vtn_ssa_transpose(struct vtn_builder *b,
668 struct vtn_ssa_value *src);
669
670 nir_ssa_def *vtn_vector_extract(struct vtn_builder *b, nir_ssa_def *src,
671 unsigned index);
672 nir_ssa_def *vtn_vector_extract_dynamic(struct vtn_builder *b, nir_ssa_def *src,
673 nir_ssa_def *index);
674 nir_ssa_def *vtn_vector_insert(struct vtn_builder *b, nir_ssa_def *src,
675 nir_ssa_def *insert, unsigned index);
676 nir_ssa_def *vtn_vector_insert_dynamic(struct vtn_builder *b, nir_ssa_def *src,
677 nir_ssa_def *insert, nir_ssa_def *index);
678
679 nir_deref_instr *vtn_nir_deref(struct vtn_builder *b, uint32_t id);
680
681 struct vtn_pointer *vtn_pointer_for_variable(struct vtn_builder *b,
682 struct vtn_variable *var,
683 struct vtn_type *ptr_type);
684
685 nir_deref_var *vtn_pointer_to_deref_var(struct vtn_builder *b,
686 struct vtn_pointer *ptr);
687 nir_deref_instr *vtn_pointer_to_deref(struct vtn_builder *b,
688 struct vtn_pointer *ptr);
689 nir_ssa_def *
690 vtn_pointer_to_offset(struct vtn_builder *b, struct vtn_pointer *ptr,
691 nir_ssa_def **index_out);
692
693 struct vtn_ssa_value *
694 vtn_local_load(struct vtn_builder *b, nir_deref_instr *src);
695
696 void vtn_local_store(struct vtn_builder *b, struct vtn_ssa_value *src,
697 nir_deref_instr *dest);
698
699 struct vtn_ssa_value *
700 vtn_variable_load(struct vtn_builder *b, struct vtn_pointer *src);
701
702 void vtn_variable_store(struct vtn_builder *b, struct vtn_ssa_value *src,
703 struct vtn_pointer *dest);
704
705 void vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
706 const uint32_t *w, unsigned count);
707
708
709 typedef void (*vtn_decoration_foreach_cb)(struct vtn_builder *,
710 struct vtn_value *,
711 int member,
712 const struct vtn_decoration *,
713 void *);
714
715 void vtn_foreach_decoration(struct vtn_builder *b, struct vtn_value *value,
716 vtn_decoration_foreach_cb cb, void *data);
717
718 typedef void (*vtn_execution_mode_foreach_cb)(struct vtn_builder *,
719 struct vtn_value *,
720 const struct vtn_decoration *,
721 void *);
722
723 void vtn_foreach_execution_mode(struct vtn_builder *b, struct vtn_value *value,
724 vtn_execution_mode_foreach_cb cb, void *data);
725
726 nir_op vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
727 SpvOp opcode, bool *swap,
728 unsigned src_bit_size, unsigned dst_bit_size);
729
730 void vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
731 const uint32_t *w, unsigned count);
732
733 void vtn_handle_subgroup(struct vtn_builder *b, SpvOp opcode,
734 const uint32_t *w, unsigned count);
735
736 bool vtn_handle_glsl450_instruction(struct vtn_builder *b, SpvOp ext_opcode,
737 const uint32_t *words, unsigned count);
738
739 struct vtn_builder* vtn_create_builder(const uint32_t *words, size_t word_count,
740 gl_shader_stage stage, const char *entry_point_name,
741 const struct spirv_to_nir_options *options);
742
743 void vtn_handle_entry_point(struct vtn_builder *b, const uint32_t *w,
744 unsigned count);
745
746 void vtn_handle_decoration(struct vtn_builder *b, SpvOp opcode,
747 const uint32_t *w, unsigned count);
748
749 static inline uint32_t
750 vtn_align_u32(uint32_t v, uint32_t a)
751 {
752 assert(a != 0 && a == (a & -((int32_t) a)));
753 return (v + a - 1) & ~(a - 1);
754 }
755
756 static inline uint64_t
757 vtn_u64_literal(const uint32_t *w)
758 {
759 return (uint64_t)w[1] << 32 | w[0];
760 }
761
762 bool vtn_handle_amd_gcn_shader_instruction(struct vtn_builder *b, SpvOp ext_opcode,
763 const uint32_t *words, unsigned count);
764
765 bool vtn_handle_amd_shader_trinary_minmax_instruction(struct vtn_builder *b, SpvOp ext_opcode,
766 const uint32_t *words, unsigned count);
767 #endif /* _VTN_PRIVATE_H_ */