spirv/nir: handle location decorations on block interface members
[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 void vtn_handle_function_call(struct vtn_builder *b, SpvOp opcode,
247 const uint32_t *w, unsigned count);
248
249 const uint32_t *
250 vtn_foreach_instruction(struct vtn_builder *b, const uint32_t *start,
251 const uint32_t *end, vtn_instruction_handler handler);
252
253 struct vtn_ssa_value {
254 union {
255 nir_ssa_def *def;
256 struct vtn_ssa_value **elems;
257 };
258
259 /* For matrices, if this is non-NULL, then this value is actually the
260 * transpose of some other value. The value that `transposed` points to
261 * always dominates this value.
262 */
263 struct vtn_ssa_value *transposed;
264
265 const struct glsl_type *type;
266 };
267
268 enum vtn_base_type {
269 vtn_base_type_void,
270 vtn_base_type_scalar,
271 vtn_base_type_vector,
272 vtn_base_type_matrix,
273 vtn_base_type_array,
274 vtn_base_type_struct,
275 vtn_base_type_pointer,
276 vtn_base_type_image,
277 vtn_base_type_sampler,
278 vtn_base_type_sampled_image,
279 vtn_base_type_function,
280 };
281
282 struct vtn_type {
283 enum vtn_base_type base_type;
284
285 const struct glsl_type *type;
286
287 /* The SPIR-V id of the given type. */
288 uint32_t id;
289
290 /* Specifies the length of complex types.
291 *
292 * For Workgroup pointers, this is the size of the referenced type.
293 */
294 unsigned length;
295
296 /* for arrays, matrices and pointers, the array stride */
297 unsigned stride;
298
299 /* Access qualifiers */
300 enum gl_access_qualifier access;
301
302 union {
303 /* Members for scalar, vector, and array-like types */
304 struct {
305 /* for arrays, the vtn_type for the elements of the array */
306 struct vtn_type *array_element;
307
308 /* for matrices, whether the matrix is stored row-major */
309 bool row_major:1;
310
311 /* Whether this type, or a parent type, has been decorated as a
312 * builtin
313 */
314 bool is_builtin:1;
315
316 /* Which built-in to use */
317 SpvBuiltIn builtin;
318 };
319
320 /* Members for struct types */
321 struct {
322 /* for structures, the vtn_type for each member */
323 struct vtn_type **members;
324
325 /* for structs, the offset of each member */
326 unsigned *offsets;
327
328 /* for structs, whether it was decorated as a "non-SSBO-like" block */
329 bool block:1;
330
331 /* for structs, whether it was decorated as an "SSBO-like" block */
332 bool buffer_block:1;
333
334 /* for structs with block == true, whether this is a builtin block
335 * (i.e. a block that contains only builtins).
336 */
337 bool builtin_block:1;
338 };
339
340 /* Members for pointer types */
341 struct {
342 /* For pointers, the vtn_type for dereferenced type */
343 struct vtn_type *deref;
344
345 /* Storage class for pointers */
346 SpvStorageClass storage_class;
347
348 /* Required alignment for pointers */
349 uint32_t align;
350 };
351
352 /* Members for image types */
353 struct {
354 /* For images, indicates whether it's sampled or storage */
355 bool sampled;
356
357 /* Image format for image_load_store type images */
358 unsigned image_format;
359
360 /* Access qualifier for storage images */
361 SpvAccessQualifier access_qualifier;
362 };
363
364 /* Members for sampled image types */
365 struct {
366 /* For sampled images, the image type */
367 struct vtn_type *image;
368 };
369
370 /* Members for function types */
371 struct {
372 /* For functions, the vtn_type for each parameter */
373 struct vtn_type **params;
374
375 /* Return type for functions */
376 struct vtn_type *return_type;
377 };
378 };
379 };
380
381 bool vtn_type_contains_block(struct vtn_builder *b, struct vtn_type *type);
382
383 bool vtn_types_compatible(struct vtn_builder *b,
384 struct vtn_type *t1, struct vtn_type *t2);
385
386 struct vtn_variable;
387
388 enum vtn_access_mode {
389 vtn_access_mode_id,
390 vtn_access_mode_literal,
391 };
392
393 struct vtn_access_link {
394 enum vtn_access_mode mode;
395 int64_t id;
396 };
397
398 struct vtn_access_chain {
399 uint32_t length;
400
401 /** Whether or not to treat the base pointer as an array. This is only
402 * true if this access chain came from an OpPtrAccessChain.
403 */
404 bool ptr_as_array;
405
406 /** Struct elements and array offsets.
407 *
408 * This is an array of 1 so that it can conveniently be created on the
409 * stack but the real length is given by the length field.
410 */
411 struct vtn_access_link link[1];
412 };
413
414 enum vtn_variable_mode {
415 vtn_variable_mode_function,
416 vtn_variable_mode_private,
417 vtn_variable_mode_uniform,
418 vtn_variable_mode_ubo,
419 vtn_variable_mode_ssbo,
420 vtn_variable_mode_phys_ssbo,
421 vtn_variable_mode_push_constant,
422 vtn_variable_mode_workgroup,
423 vtn_variable_mode_cross_workgroup,
424 vtn_variable_mode_input,
425 vtn_variable_mode_output,
426 };
427
428 struct vtn_pointer {
429 /** The variable mode for the referenced data */
430 enum vtn_variable_mode mode;
431
432 /** The dereferenced type of this pointer */
433 struct vtn_type *type;
434
435 /** The pointer type of this pointer
436 *
437 * This may be NULL for some temporary pointers constructed as part of a
438 * large load, store, or copy. It MUST be valid for all pointers which are
439 * stored as SPIR-V SSA values.
440 */
441 struct vtn_type *ptr_type;
442
443 /** The referenced variable, if known
444 *
445 * This field may be NULL if the pointer uses a (block_index, offset) pair
446 * instead of an access chain or if the access chain starts at a deref.
447 */
448 struct vtn_variable *var;
449
450 /** The NIR deref corresponding to this pointer */
451 nir_deref_instr *deref;
452
453 /** A (block_index, offset) pair representing a UBO or SSBO position. */
454 struct nir_ssa_def *block_index;
455 struct nir_ssa_def *offset;
456
457 /* Access qualifiers */
458 enum gl_access_qualifier access;
459 };
460
461 bool vtn_pointer_uses_ssa_offset(struct vtn_builder *b,
462 struct vtn_pointer *ptr);
463
464 struct vtn_variable {
465 enum vtn_variable_mode mode;
466
467 struct vtn_type *type;
468
469 unsigned descriptor_set;
470 unsigned binding;
471 bool explicit_binding;
472 unsigned offset;
473 unsigned input_attachment_index;
474 bool patch;
475
476 nir_variable *var;
477
478 /* If the variable is a struct with a location set on it then this will be
479 * stored here. This will be used to calculate locations for members that
480 * don’t have their own explicit location.
481 */
482 int base_location;
483
484 int shared_location;
485
486 /**
487 * In some early released versions of GLSLang, it implemented all function
488 * calls by making copies of all parameters into temporary variables and
489 * passing those variables into the function. It even did so for samplers
490 * and images which violates the SPIR-V spec. Unfortunately, two games
491 * (Talos Principle and Doom) shipped with this old version of GLSLang and
492 * also happen to pass samplers into functions. Talos Principle received
493 * an update fairly shortly after release with an updated GLSLang. Doom,
494 * on the other hand, has never received an update so we need to work
495 * around this GLSLang issue in SPIR-V -> NIR. Hopefully, we can drop this
496 * hack at some point in the future.
497 */
498 struct vtn_pointer *copy_prop_sampler;
499
500 /* Access qualifiers. */
501 enum gl_access_qualifier access;
502 };
503
504 struct vtn_image_pointer {
505 struct vtn_pointer *image;
506 nir_ssa_def *coord;
507 nir_ssa_def *sample;
508 };
509
510 struct vtn_sampled_image {
511 struct vtn_type *type;
512 struct vtn_pointer *image; /* Image or array of images */
513 struct vtn_pointer *sampler; /* Sampler */
514 };
515
516 struct vtn_value {
517 enum vtn_value_type value_type;
518 const char *name;
519 struct vtn_decoration *decoration;
520 struct vtn_type *type;
521 union {
522 void *ptr;
523 char *str;
524 nir_constant *constant;
525 struct vtn_pointer *pointer;
526 struct vtn_image_pointer *image;
527 struct vtn_sampled_image *sampled_image;
528 struct vtn_function *func;
529 struct vtn_block *block;
530 struct vtn_ssa_value *ssa;
531 vtn_instruction_handler ext_handler;
532 };
533 };
534
535 #define VTN_DEC_DECORATION -1
536 #define VTN_DEC_EXECUTION_MODE -2
537 #define VTN_DEC_STRUCT_MEMBER0 0
538
539 struct vtn_decoration {
540 struct vtn_decoration *next;
541
542 /* Specifies how to apply this decoration. Negative values represent a
543 * decoration or execution mode. (See the VTN_DEC_ #defines above.)
544 * Non-negative values specify that it applies to a structure member.
545 */
546 int scope;
547
548 const uint32_t *literals;
549 struct vtn_value *group;
550
551 union {
552 SpvDecoration decoration;
553 SpvExecutionMode exec_mode;
554 };
555 };
556
557 struct vtn_builder {
558 nir_builder nb;
559
560 /* Used by vtn_fail to jump back to the beginning of SPIR-V compilation */
561 jmp_buf fail_jump;
562
563 const uint32_t *spirv;
564 size_t spirv_word_count;
565
566 nir_shader *shader;
567 const struct spirv_to_nir_options *options;
568 struct vtn_block *block;
569
570 /* Current offset, file, line, and column. Useful for debugging. Set
571 * automatically by vtn_foreach_instruction.
572 */
573 size_t spirv_offset;
574 char *file;
575 int line, col;
576
577 /*
578 * In SPIR-V, constants are global, whereas in NIR, the load_const
579 * instruction we use is per-function. So while we parse each function, we
580 * keep a hash table of constants we've resolved to nir_ssa_value's so
581 * far, and we lazily resolve them when we see them used in a function.
582 */
583 struct hash_table *const_table;
584
585 /*
586 * Map from phi instructions (pointer to the start of the instruction)
587 * to the variable corresponding to it.
588 */
589 struct hash_table *phi_table;
590
591 unsigned num_specializations;
592 struct nir_spirv_specialization *specializations;
593
594 unsigned value_id_bound;
595 struct vtn_value *values;
596
597 /* True if we should watch out for GLSLang issue #179 */
598 bool wa_glslang_179;
599
600 gl_shader_stage entry_point_stage;
601 const char *entry_point_name;
602 struct vtn_value *entry_point;
603 bool origin_upper_left;
604 bool pixel_center_integer;
605 bool variable_pointers;
606
607 struct vtn_function *func;
608 struct exec_list functions;
609
610 /* Current function parameter index */
611 unsigned func_param_idx;
612
613 bool has_loop_continue;
614
615 /* false by default, set to true by the ContractionOff execution mode */
616 bool exact;
617 };
618
619 nir_ssa_def *
620 vtn_pointer_to_ssa(struct vtn_builder *b, struct vtn_pointer *ptr);
621 struct vtn_pointer *
622 vtn_pointer_from_ssa(struct vtn_builder *b, nir_ssa_def *ssa,
623 struct vtn_type *ptr_type);
624
625 static inline struct vtn_value *
626 vtn_untyped_value(struct vtn_builder *b, uint32_t value_id)
627 {
628 vtn_fail_if(value_id >= b->value_id_bound,
629 "SPIR-V id %u is out-of-bounds", value_id);
630 return &b->values[value_id];
631 }
632
633 static inline struct vtn_value *
634 vtn_push_value(struct vtn_builder *b, uint32_t value_id,
635 enum vtn_value_type value_type)
636 {
637 struct vtn_value *val = vtn_untyped_value(b, value_id);
638
639 vtn_fail_if(val->value_type != vtn_value_type_invalid,
640 "SPIR-V id %u has already been written by another instruction",
641 value_id);
642
643 val->value_type = value_type;
644 return &b->values[value_id];
645 }
646
647 static inline struct vtn_value *
648 vtn_push_ssa(struct vtn_builder *b, uint32_t value_id,
649 struct vtn_type *type, struct vtn_ssa_value *ssa)
650 {
651 struct vtn_value *val;
652 if (type->base_type == vtn_base_type_pointer) {
653 val = vtn_push_value(b, value_id, vtn_value_type_pointer);
654 val->pointer = vtn_pointer_from_ssa(b, ssa->def, type);
655 } else {
656 val = vtn_push_value(b, value_id, vtn_value_type_ssa);
657 val->ssa = ssa;
658 }
659 return val;
660 }
661
662 static inline struct vtn_value *
663 vtn_value(struct vtn_builder *b, uint32_t value_id,
664 enum vtn_value_type value_type)
665 {
666 struct vtn_value *val = vtn_untyped_value(b, value_id);
667 vtn_fail_if(val->value_type != value_type,
668 "SPIR-V id %u is the wrong kind of value", value_id);
669 return val;
670 }
671
672 bool
673 vtn_set_instruction_result_type(struct vtn_builder *b, SpvOp opcode,
674 const uint32_t *w, unsigned count);
675
676 static inline nir_constant *
677 vtn_constant_value(struct vtn_builder *b, uint32_t value_id)
678 {
679 return vtn_value(b, value_id, vtn_value_type_constant)->constant;
680 }
681
682 struct vtn_ssa_value *vtn_ssa_value(struct vtn_builder *b, uint32_t value_id);
683
684 struct vtn_ssa_value *vtn_create_ssa_value(struct vtn_builder *b,
685 const struct glsl_type *type);
686
687 struct vtn_ssa_value *vtn_ssa_transpose(struct vtn_builder *b,
688 struct vtn_ssa_value *src);
689
690 nir_ssa_def *vtn_vector_extract(struct vtn_builder *b, nir_ssa_def *src,
691 unsigned index);
692 nir_ssa_def *vtn_vector_extract_dynamic(struct vtn_builder *b, nir_ssa_def *src,
693 nir_ssa_def *index);
694 nir_ssa_def *vtn_vector_insert(struct vtn_builder *b, nir_ssa_def *src,
695 nir_ssa_def *insert, unsigned index);
696 nir_ssa_def *vtn_vector_insert_dynamic(struct vtn_builder *b, nir_ssa_def *src,
697 nir_ssa_def *insert, nir_ssa_def *index);
698
699 nir_deref_instr *vtn_nir_deref(struct vtn_builder *b, uint32_t id);
700
701 struct vtn_pointer *vtn_pointer_for_variable(struct vtn_builder *b,
702 struct vtn_variable *var,
703 struct vtn_type *ptr_type);
704
705 nir_deref_instr *vtn_pointer_to_deref(struct vtn_builder *b,
706 struct vtn_pointer *ptr);
707 nir_ssa_def *
708 vtn_pointer_to_offset(struct vtn_builder *b, struct vtn_pointer *ptr,
709 nir_ssa_def **index_out);
710
711 struct vtn_ssa_value *
712 vtn_local_load(struct vtn_builder *b, nir_deref_instr *src);
713
714 void vtn_local_store(struct vtn_builder *b, struct vtn_ssa_value *src,
715 nir_deref_instr *dest);
716
717 struct vtn_ssa_value *
718 vtn_variable_load(struct vtn_builder *b, struct vtn_pointer *src);
719
720 void vtn_variable_store(struct vtn_builder *b, struct vtn_ssa_value *src,
721 struct vtn_pointer *dest);
722
723 void vtn_handle_variables(struct vtn_builder *b, SpvOp opcode,
724 const uint32_t *w, unsigned count);
725
726
727 typedef void (*vtn_decoration_foreach_cb)(struct vtn_builder *,
728 struct vtn_value *,
729 int member,
730 const struct vtn_decoration *,
731 void *);
732
733 void vtn_foreach_decoration(struct vtn_builder *b, struct vtn_value *value,
734 vtn_decoration_foreach_cb cb, void *data);
735
736 typedef void (*vtn_execution_mode_foreach_cb)(struct vtn_builder *,
737 struct vtn_value *,
738 const struct vtn_decoration *,
739 void *);
740
741 void vtn_foreach_execution_mode(struct vtn_builder *b, struct vtn_value *value,
742 vtn_execution_mode_foreach_cb cb, void *data);
743
744 nir_op vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
745 SpvOp opcode, bool *swap,
746 unsigned src_bit_size, unsigned dst_bit_size);
747
748 void vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
749 const uint32_t *w, unsigned count);
750
751 void vtn_handle_subgroup(struct vtn_builder *b, SpvOp opcode,
752 const uint32_t *w, unsigned count);
753
754 bool vtn_handle_glsl450_instruction(struct vtn_builder *b, SpvOp ext_opcode,
755 const uint32_t *words, unsigned count);
756
757 struct vtn_builder* vtn_create_builder(const uint32_t *words, size_t word_count,
758 gl_shader_stage stage, const char *entry_point_name,
759 const struct spirv_to_nir_options *options);
760
761 void vtn_handle_entry_point(struct vtn_builder *b, const uint32_t *w,
762 unsigned count);
763
764 void vtn_handle_decoration(struct vtn_builder *b, SpvOp opcode,
765 const uint32_t *w, unsigned count);
766
767 static inline uint32_t
768 vtn_align_u32(uint32_t v, uint32_t a)
769 {
770 assert(a != 0 && a == (a & -((int32_t) a)));
771 return (v + a - 1) & ~(a - 1);
772 }
773
774 static inline uint64_t
775 vtn_u64_literal(const uint32_t *w)
776 {
777 return (uint64_t)w[1] << 32 | w[0];
778 }
779
780 bool vtn_handle_amd_gcn_shader_instruction(struct vtn_builder *b, SpvOp ext_opcode,
781 const uint32_t *words, unsigned count);
782
783 bool vtn_handle_amd_shader_trinary_minmax_instruction(struct vtn_builder *b, SpvOp ext_opcode,
784 const uint32_t *words, unsigned count);
785 #endif /* _VTN_PRIVATE_H_ */