2 * Copyright © 2015 Intel Corporation
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:
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
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
24 * Jason Ekstrand (jason@jlekstrand.net)
28 #ifndef _VTN_PRIVATE_H_
29 #define _VTN_PRIVATE_H_
34 #include "nir/nir_builder.h"
35 #include "util/u_dynarray.h"
36 #include "nir_spirv.h"
40 struct vtn_decoration
;
42 void vtn_log(struct vtn_builder
*b
, enum nir_spirv_debug_level level
,
43 size_t spirv_offset
, const char *message
);
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);
48 #define vtn_info(...) vtn_logf(b, NIR_SPIRV_DEBUG_LEVEL_INFO, 0, __VA_ARGS__)
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__)
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__)
58 /** Fail SPIR-V parsing
60 * This function logs an error and then bails out of the shader compile using
61 * longjmp. This being safe relies on two things:
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.
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.
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.
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.
79 _vtn_fail(struct vtn_builder
*b
, const char *file
, unsigned line
,
80 const char *fmt
, ...) PRINTFLIKE(4, 5);
82 #define vtn_fail(...) _vtn_fail(b, __FILE__, __LINE__, __VA_ARGS__)
84 /** Fail if the given expression evaluates to true */
85 #define vtn_fail_if(expr, ...) \
88 vtn_fail(__VA_ARGS__); \
91 #define _vtn_fail_with(t, msg, v) \
92 vtn_fail("%s: %s (%u)\n", msg, spirv_ ## t ## _to_string(v), v)
94 #define vtn_fail_with_decoration(msg, v) _vtn_fail_with(decoration, msg, v)
95 #define vtn_fail_with_opcode(msg, v) _vtn_fail_with(op, msg, v)
97 /** Assert that a condition is true and, if it isn't, vtn_fail
99 * This macro is transitional only and should not be used in new code. Use
100 * vtn_fail_if and provide a real message instead.
102 #define vtn_assert(expr) \
105 vtn_fail("%s", #expr); \
108 enum vtn_value_type
{
109 vtn_value_type_invalid
= 0,
110 vtn_value_type_undef
,
111 vtn_value_type_string
,
112 vtn_value_type_decoration_group
,
114 vtn_value_type_constant
,
115 vtn_value_type_pointer
,
116 vtn_value_type_function
,
117 vtn_value_type_block
,
119 vtn_value_type_extension
,
120 vtn_value_type_image_pointer
,
123 enum vtn_branch_type
{
124 vtn_branch_type_none
,
125 vtn_branch_type_if_merge
,
126 vtn_branch_type_switch_break
,
127 vtn_branch_type_switch_fallthrough
,
128 vtn_branch_type_loop_break
,
129 vtn_branch_type_loop_continue
,
130 vtn_branch_type_loop_back_edge
,
131 vtn_branch_type_discard
,
132 vtn_branch_type_return
,
135 enum vtn_cf_node_type
{
136 vtn_cf_node_type_block
,
138 vtn_cf_node_type_loop
,
139 vtn_cf_node_type_case
,
140 vtn_cf_node_type_switch
,
141 vtn_cf_node_type_function
,
145 struct list_head link
;
146 struct vtn_cf_node
*parent
;
147 enum vtn_cf_node_type type
;
151 struct vtn_cf_node node
;
153 /* The main body of the loop */
154 struct list_head body
;
156 /* The "continue" part of the loop. This gets executed after the body
157 * and is where you go when you hit a continue.
159 struct list_head cont_body
;
161 struct vtn_block
*header_block
;
162 struct vtn_block
*cont_block
;
163 struct vtn_block
*break_block
;
165 SpvLoopControlMask control
;
169 struct vtn_cf_node node
;
173 enum vtn_branch_type then_type
;
174 struct list_head then_body
;
176 enum vtn_branch_type else_type
;
177 struct list_head else_body
;
179 struct vtn_block
*merge_block
;
181 SpvSelectionControlMask control
;
185 struct vtn_cf_node node
;
187 struct vtn_block
*block
;
189 enum vtn_branch_type type
;
190 struct list_head body
;
192 /* The fallthrough case, if any */
193 struct vtn_case
*fallthrough
;
195 /* The uint32_t values that map to this case */
196 struct util_dynarray values
;
198 /* True if this is the default case */
201 /* Initialized to false; used when sorting the list of cases */
206 struct vtn_cf_node node
;
210 struct list_head cases
;
212 struct vtn_block
*break_block
;
216 struct vtn_cf_node node
;
218 /** A pointer to the label instruction */
219 const uint32_t *label
;
221 /** A pointer to the merge instruction (or NULL if non exists) */
222 const uint32_t *merge
;
224 /** A pointer to the branch instruction that ends this block */
225 const uint32_t *branch
;
227 enum vtn_branch_type branch_type
;
229 /* The CF node for which this is a merge target
231 * The SPIR-V spec requires that any given block can be the merge target
232 * for at most one merge instruction. If this block is a merge target,
233 * this points back to the block containing that merge instruction.
235 struct vtn_cf_node
*merge_cf_node
;
237 /** Points to the loop that this block starts (if it starts a loop) */
238 struct vtn_loop
*loop
;
240 /** Points to the switch case started by this block (if any) */
241 struct vtn_case
*switch_case
;
243 /** Every block ends in a nop intrinsic so that we can find it again */
244 nir_intrinsic_instr
*end_nop
;
246 /** attached nir_block */
247 struct nir_block
*block
;
250 struct vtn_function
{
251 struct vtn_cf_node node
;
253 struct vtn_type
*type
;
258 nir_function_impl
*impl
;
259 struct vtn_block
*start_block
;
261 struct list_head body
;
265 SpvFunctionControlMask control
;
268 #define VTN_DECL_CF_NODE_CAST(_type) \
269 static inline struct vtn_##_type * \
270 vtn_cf_node_as_##_type(struct vtn_cf_node *node) \
272 assert(node->type == vtn_cf_node_type_##_type); \
273 return (struct vtn_##_type *)node; \
276 VTN_DECL_CF_NODE_CAST(block
)
277 VTN_DECL_CF_NODE_CAST(loop
)
278 VTN_DECL_CF_NODE_CAST(if)
279 VTN_DECL_CF_NODE_CAST(case)
280 VTN_DECL_CF_NODE_CAST(switch)
281 VTN_DECL_CF_NODE_CAST(function
)
283 #define vtn_foreach_cf_node(node, cf_list) \
284 list_for_each_entry(struct vtn_cf_node, node, cf_list, link)
286 typedef bool (*vtn_instruction_handler
)(struct vtn_builder
*, SpvOp
,
287 const uint32_t *, unsigned);
289 void vtn_build_cfg(struct vtn_builder
*b
, const uint32_t *words
,
290 const uint32_t *end
);
291 void vtn_function_emit(struct vtn_builder
*b
, struct vtn_function
*func
,
292 vtn_instruction_handler instruction_handler
);
293 void vtn_handle_function_call(struct vtn_builder
*b
, SpvOp opcode
,
294 const uint32_t *w
, unsigned count
);
297 vtn_foreach_instruction(struct vtn_builder
*b
, const uint32_t *start
,
298 const uint32_t *end
, vtn_instruction_handler handler
);
300 struct vtn_ssa_value
{
303 struct vtn_ssa_value
**elems
;
306 /* For matrices, if this is non-NULL, then this value is actually the
307 * transpose of some other value. The value that `transposed` points to
308 * always dominates this value.
310 struct vtn_ssa_value
*transposed
;
312 const struct glsl_type
*type
;
317 vtn_base_type_scalar
,
318 vtn_base_type_vector
,
319 vtn_base_type_matrix
,
321 vtn_base_type_struct
,
322 vtn_base_type_pointer
,
324 vtn_base_type_sampler
,
325 vtn_base_type_sampled_image
,
326 vtn_base_type_function
,
330 enum vtn_base_type base_type
;
332 const struct glsl_type
*type
;
334 /* The SPIR-V id of the given type. */
337 /* Specifies the length of complex types.
339 * For Workgroup pointers, this is the size of the referenced type.
343 /* for arrays, matrices and pointers, the array stride */
346 /* Access qualifiers */
347 enum gl_access_qualifier access
;
350 /* Members for scalar, vector, and array-like types */
352 /* for arrays, the vtn_type for the elements of the array */
353 struct vtn_type
*array_element
;
355 /* for matrices, whether the matrix is stored row-major */
358 /* Whether this type, or a parent type, has been decorated as a
363 /* Which built-in to use */
367 /* Members for struct types */
369 /* for structures, the vtn_type for each member */
370 struct vtn_type
**members
;
372 /* for structs, the offset of each member */
375 /* for structs, whether it was decorated as a "non-SSBO-like" block */
378 /* for structs, whether it was decorated as an "SSBO-like" block */
381 /* for structs with block == true, whether this is a builtin block
382 * (i.e. a block that contains only builtins).
384 bool builtin_block
:1;
386 /* for structs and unions it specifies the minimum alignment of the
387 * members. 0 means packed.
389 * Set by CPacked and Alignment Decorations in kernels.
394 /* Members for pointer types */
396 /* For pointers, the vtn_type for dereferenced type */
397 struct vtn_type
*deref
;
399 /* Storage class for pointers */
400 SpvStorageClass storage_class
;
402 /* Required alignment for pointers */
406 /* Members for image types */
408 /* GLSL image type for this type. This is not to be confused with
409 * vtn_type::type which is actually going to be the GLSL type for a
410 * pointer to an image, likely a uint32_t.
412 const struct glsl_type
*glsl_image
;
414 /* Image format for image_load_store type images */
415 unsigned image_format
;
417 /* Access qualifier for storage images */
418 SpvAccessQualifier access_qualifier
;
421 /* Members for sampled image types */
423 /* For sampled images, the image type */
424 struct vtn_type
*image
;
427 /* Members for function types */
429 /* For functions, the vtn_type for each parameter */
430 struct vtn_type
**params
;
432 /* Return type for functions */
433 struct vtn_type
*return_type
;
438 bool vtn_type_contains_block(struct vtn_builder
*b
, struct vtn_type
*type
);
440 bool vtn_types_compatible(struct vtn_builder
*b
,
441 struct vtn_type
*t1
, struct vtn_type
*t2
);
443 struct vtn_type
*vtn_type_without_array(struct vtn_type
*type
);
447 enum vtn_access_mode
{
449 vtn_access_mode_literal
,
452 struct vtn_access_link
{
453 enum vtn_access_mode mode
;
457 struct vtn_access_chain
{
460 /** Whether or not to treat the base pointer as an array. This is only
461 * true if this access chain came from an OpPtrAccessChain.
465 /* Access qualifiers */
466 enum gl_access_qualifier access
;
468 /** Struct elements and array offsets.
470 * This is an array of 1 so that it can conveniently be created on the
471 * stack but the real length is given by the length field.
473 struct vtn_access_link link
[1];
476 enum vtn_variable_mode
{
477 vtn_variable_mode_function
,
478 vtn_variable_mode_private
,
479 vtn_variable_mode_uniform
,
480 vtn_variable_mode_atomic_counter
,
481 vtn_variable_mode_ubo
,
482 vtn_variable_mode_ssbo
,
483 vtn_variable_mode_phys_ssbo
,
484 vtn_variable_mode_push_constant
,
485 vtn_variable_mode_workgroup
,
486 vtn_variable_mode_cross_workgroup
,
487 vtn_variable_mode_constant
,
488 vtn_variable_mode_input
,
489 vtn_variable_mode_output
,
490 vtn_variable_mode_image
,
494 /** The variable mode for the referenced data */
495 enum vtn_variable_mode mode
;
497 /** The dereferenced type of this pointer */
498 struct vtn_type
*type
;
500 /** The pointer type of this pointer
502 * This may be NULL for some temporary pointers constructed as part of a
503 * large load, store, or copy. It MUST be valid for all pointers which are
504 * stored as SPIR-V SSA values.
506 struct vtn_type
*ptr_type
;
508 /** The referenced variable, if known
510 * This field may be NULL if the pointer uses a (block_index, offset) pair
511 * instead of an access chain or if the access chain starts at a deref.
513 struct vtn_variable
*var
;
515 /** The NIR deref corresponding to this pointer */
516 nir_deref_instr
*deref
;
518 /** A (block_index, offset) pair representing a UBO or SSBO position. */
519 struct nir_ssa_def
*block_index
;
520 struct nir_ssa_def
*offset
;
522 /* Access qualifiers */
523 enum gl_access_qualifier access
;
526 bool vtn_mode_uses_ssa_offset(struct vtn_builder
*b
,
527 enum vtn_variable_mode mode
);
529 static inline bool vtn_pointer_uses_ssa_offset(struct vtn_builder
*b
,
530 struct vtn_pointer
*ptr
)
532 return vtn_mode_uses_ssa_offset(b
, ptr
->mode
);
536 struct vtn_variable
{
537 enum vtn_variable_mode mode
;
539 struct vtn_type
*type
;
541 unsigned descriptor_set
;
543 bool explicit_binding
;
545 unsigned input_attachment_index
;
550 /* If the variable is a struct with a location set on it then this will be
551 * stored here. This will be used to calculate locations for members that
552 * don’t have their own explicit location.
557 * In some early released versions of GLSLang, it implemented all function
558 * calls by making copies of all parameters into temporary variables and
559 * passing those variables into the function. It even did so for samplers
560 * and images which violates the SPIR-V spec. Unfortunately, two games
561 * (Talos Principle and Doom) shipped with this old version of GLSLang and
562 * also happen to pass samplers into functions. Talos Principle received
563 * an update fairly shortly after release with an updated GLSLang. Doom,
564 * on the other hand, has never received an update so we need to work
565 * around this GLSLang issue in SPIR-V -> NIR. Hopefully, we can drop this
566 * hack at some point in the future.
568 struct vtn_pointer
*copy_prop_sampler
;
570 /* Access qualifiers. */
571 enum gl_access_qualifier access
;
574 const struct glsl_type
*
575 vtn_type_get_nir_type(struct vtn_builder
*b
, struct vtn_type
*type
,
576 enum vtn_variable_mode mode
);
578 struct vtn_image_pointer
{
579 nir_deref_instr
*image
;
586 enum vtn_value_type value_type
;
588 /* Workaround for https://gitlab.freedesktop.org/mesa/mesa/-/issues/3406
589 * Only set for OpImage / OpSampledImage. Note that this is in addition
590 * the existence of a NonUniform decoration on this value.*/
591 uint32_t propagated_non_uniform
: 1;
594 struct vtn_decoration
*decoration
;
595 struct vtn_type
*type
;
598 nir_constant
*constant
;
599 struct vtn_pointer
*pointer
;
600 struct vtn_image_pointer
*image
;
601 struct vtn_function
*func
;
602 struct vtn_block
*block
;
603 struct vtn_ssa_value
*ssa
;
604 vtn_instruction_handler ext_handler
;
608 #define VTN_DEC_DECORATION -1
609 #define VTN_DEC_EXECUTION_MODE -2
610 #define VTN_DEC_STRUCT_MEMBER0 0
612 struct vtn_decoration
{
613 struct vtn_decoration
*next
;
615 /* Specifies how to apply this decoration. Negative values represent a
616 * decoration or execution mode. (See the VTN_DEC_ #defines above.)
617 * Non-negative values specify that it applies to a structure member.
621 const uint32_t *operands
;
622 struct vtn_value
*group
;
625 SpvDecoration decoration
;
626 SpvExecutionMode exec_mode
;
633 /* Used by vtn_fail to jump back to the beginning of SPIR-V compilation */
636 const uint32_t *spirv
;
637 size_t spirv_word_count
;
640 struct spirv_to_nir_options
*options
;
641 struct vtn_block
*block
;
643 /* Current offset, file, line, and column. Useful for debugging. Set
644 * automatically by vtn_foreach_instruction.
651 * In SPIR-V, constants are global, whereas in NIR, the load_const
652 * instruction we use is per-function. So while we parse each function, we
653 * keep a hash table of constants we've resolved to nir_ssa_value's so
654 * far, and we lazily resolve them when we see them used in a function.
656 struct hash_table
*const_table
;
659 * Map from phi instructions (pointer to the start of the instruction)
660 * to the variable corresponding to it.
662 struct hash_table
*phi_table
;
664 unsigned num_specializations
;
665 struct nir_spirv_specialization
*specializations
;
667 unsigned value_id_bound
;
668 struct vtn_value
*values
;
670 /* True if we need to fix up CS OpControlBarrier */
671 bool wa_glslang_cs_barrier
;
673 gl_shader_stage entry_point_stage
;
674 const char *entry_point_name
;
675 struct vtn_value
*entry_point
;
676 struct vtn_value
*workgroup_size_builtin
;
677 bool variable_pointers
;
679 struct vtn_function
*func
;
680 struct list_head functions
;
682 /* Current function parameter index */
683 unsigned func_param_idx
;
685 bool has_loop_continue
;
687 /* false by default, set to true by the ContractionOff execution mode */
690 /* when a physical memory model is choosen */
693 /* memory model specified by OpMemoryModel */
698 vtn_pointer_to_ssa(struct vtn_builder
*b
, struct vtn_pointer
*ptr
);
700 vtn_pointer_from_ssa(struct vtn_builder
*b
, nir_ssa_def
*ssa
,
701 struct vtn_type
*ptr_type
);
703 static inline struct vtn_value
*
704 vtn_untyped_value(struct vtn_builder
*b
, uint32_t value_id
)
706 vtn_fail_if(value_id
>= b
->value_id_bound
,
707 "SPIR-V id %u is out-of-bounds", value_id
);
708 return &b
->values
[value_id
];
711 /* Consider not using this function directly and instead use
712 * vtn_push_ssa/vtn_push_pointer so that appropriate applying of
713 * decorations is handled by common code.
715 static inline struct vtn_value
*
716 vtn_push_value(struct vtn_builder
*b
, uint32_t value_id
,
717 enum vtn_value_type value_type
)
719 struct vtn_value
*val
= vtn_untyped_value(b
, value_id
);
721 vtn_fail_if(value_type
== vtn_value_type_ssa
,
722 "Do not call vtn_push_value for value_type_ssa. Use "
723 "vtn_push_ssa_value instead.");
725 vtn_fail_if(val
->value_type
!= vtn_value_type_invalid
,
726 "SPIR-V id %u has already been written by another instruction",
729 val
->value_type
= value_type
;
731 return &b
->values
[value_id
];
734 static inline struct vtn_value
*
735 vtn_value(struct vtn_builder
*b
, uint32_t value_id
,
736 enum vtn_value_type value_type
)
738 struct vtn_value
*val
= vtn_untyped_value(b
, value_id
);
739 vtn_fail_if(val
->value_type
!= value_type
,
740 "SPIR-V id %u is the wrong kind of value", value_id
);
745 vtn_set_instruction_result_type(struct vtn_builder
*b
, SpvOp opcode
,
746 const uint32_t *w
, unsigned count
);
748 static inline uint64_t
749 vtn_constant_uint(struct vtn_builder
*b
, uint32_t value_id
)
751 struct vtn_value
*val
= vtn_value(b
, value_id
, vtn_value_type_constant
);
753 vtn_fail_if(val
->type
->base_type
!= vtn_base_type_scalar
||
754 !glsl_type_is_integer(val
->type
->type
),
755 "Expected id %u to be an integer constant", value_id
);
757 switch (glsl_get_bit_size(val
->type
->type
)) {
758 case 8: return val
->constant
->values
[0].u8
;
759 case 16: return val
->constant
->values
[0].u16
;
760 case 32: return val
->constant
->values
[0].u32
;
761 case 64: return val
->constant
->values
[0].u64
;
762 default: unreachable("Invalid bit size");
766 static inline int64_t
767 vtn_constant_int(struct vtn_builder
*b
, uint32_t value_id
)
769 struct vtn_value
*val
= vtn_value(b
, value_id
, vtn_value_type_constant
);
771 vtn_fail_if(val
->type
->base_type
!= vtn_base_type_scalar
||
772 !glsl_type_is_integer(val
->type
->type
),
773 "Expected id %u to be an integer constant", value_id
);
775 switch (glsl_get_bit_size(val
->type
->type
)) {
776 case 8: return val
->constant
->values
[0].i8
;
777 case 16: return val
->constant
->values
[0].i16
;
778 case 32: return val
->constant
->values
[0].i32
;
779 case 64: return val
->constant
->values
[0].i64
;
780 default: unreachable("Invalid bit size");
784 static inline struct vtn_type
*
785 vtn_get_value_type(struct vtn_builder
*b
, uint32_t value_id
)
787 struct vtn_value
*val
= vtn_untyped_value(b
, value_id
);
788 vtn_fail_if(val
->type
== NULL
, "Value %u does not have a type", value_id
);
792 static inline struct vtn_type
*
793 vtn_get_type(struct vtn_builder
*b
, uint32_t value_id
)
795 return vtn_value(b
, value_id
, vtn_value_type_type
)->type
;
798 struct vtn_ssa_value
*vtn_ssa_value(struct vtn_builder
*b
, uint32_t value_id
);
799 struct vtn_value
*vtn_push_ssa_value(struct vtn_builder
*b
, uint32_t value_id
,
800 struct vtn_ssa_value
*ssa
);
802 nir_ssa_def
*vtn_get_nir_ssa(struct vtn_builder
*b
, uint32_t value_id
);
803 struct vtn_value
*vtn_push_nir_ssa(struct vtn_builder
*b
, uint32_t value_id
,
806 struct vtn_value
*vtn_push_pointer(struct vtn_builder
*b
,
808 struct vtn_pointer
*ptr
);
810 struct vtn_sampled_image
{
811 nir_deref_instr
*image
;
812 nir_deref_instr
*sampler
;
815 nir_ssa_def
*vtn_sampled_image_to_nir_ssa(struct vtn_builder
*b
,
816 struct vtn_sampled_image si
);
819 vtn_copy_value(struct vtn_builder
*b
, uint32_t src_value_id
,
820 uint32_t dst_value_id
);
822 struct vtn_ssa_value
*vtn_create_ssa_value(struct vtn_builder
*b
,
823 const struct glsl_type
*type
);
825 struct vtn_ssa_value
*vtn_ssa_transpose(struct vtn_builder
*b
,
826 struct vtn_ssa_value
*src
);
828 nir_deref_instr
*vtn_nir_deref(struct vtn_builder
*b
, uint32_t id
);
830 nir_deref_instr
*vtn_pointer_to_deref(struct vtn_builder
*b
,
831 struct vtn_pointer
*ptr
);
833 vtn_pointer_to_offset(struct vtn_builder
*b
, struct vtn_pointer
*ptr
,
834 nir_ssa_def
**index_out
);
836 struct vtn_ssa_value
*
837 vtn_local_load(struct vtn_builder
*b
, nir_deref_instr
*src
,
838 enum gl_access_qualifier access
);
840 void vtn_local_store(struct vtn_builder
*b
, struct vtn_ssa_value
*src
,
841 nir_deref_instr
*dest
,
842 enum gl_access_qualifier access
);
844 struct vtn_ssa_value
*
845 vtn_variable_load(struct vtn_builder
*b
, struct vtn_pointer
*src
,
846 enum gl_access_qualifier access
);
848 void vtn_variable_store(struct vtn_builder
*b
, struct vtn_ssa_value
*src
,
849 struct vtn_pointer
*dest
, enum gl_access_qualifier access
);
851 void vtn_handle_variables(struct vtn_builder
*b
, SpvOp opcode
,
852 const uint32_t *w
, unsigned count
);
855 typedef void (*vtn_decoration_foreach_cb
)(struct vtn_builder
*,
858 const struct vtn_decoration
*,
861 void vtn_foreach_decoration(struct vtn_builder
*b
, struct vtn_value
*value
,
862 vtn_decoration_foreach_cb cb
, void *data
);
864 typedef void (*vtn_execution_mode_foreach_cb
)(struct vtn_builder
*,
866 const struct vtn_decoration
*,
869 void vtn_foreach_execution_mode(struct vtn_builder
*b
, struct vtn_value
*value
,
870 vtn_execution_mode_foreach_cb cb
, void *data
);
872 nir_op
vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder
*b
,
873 SpvOp opcode
, bool *swap
,
874 unsigned src_bit_size
, unsigned dst_bit_size
);
876 void vtn_handle_alu(struct vtn_builder
*b
, SpvOp opcode
,
877 const uint32_t *w
, unsigned count
);
879 void vtn_handle_bitcast(struct vtn_builder
*b
, const uint32_t *w
,
882 void vtn_handle_subgroup(struct vtn_builder
*b
, SpvOp opcode
,
883 const uint32_t *w
, unsigned count
);
885 bool vtn_handle_glsl450_instruction(struct vtn_builder
*b
, SpvOp ext_opcode
,
886 const uint32_t *words
, unsigned count
);
888 bool vtn_handle_opencl_instruction(struct vtn_builder
*b
, SpvOp ext_opcode
,
889 const uint32_t *words
, unsigned count
);
891 struct vtn_builder
* vtn_create_builder(const uint32_t *words
, size_t word_count
,
892 gl_shader_stage stage
, const char *entry_point_name
,
893 const struct spirv_to_nir_options
*options
);
895 void vtn_handle_entry_point(struct vtn_builder
*b
, const uint32_t *w
,
898 void vtn_handle_decoration(struct vtn_builder
*b
, SpvOp opcode
,
899 const uint32_t *w
, unsigned count
);
901 enum vtn_variable_mode
vtn_storage_class_to_mode(struct vtn_builder
*b
,
902 SpvStorageClass
class,
903 struct vtn_type
*interface_type
,
904 nir_variable_mode
*nir_mode_out
);
906 nir_address_format
vtn_mode_to_address_format(struct vtn_builder
*b
,
907 enum vtn_variable_mode
);
909 static inline uint32_t
910 vtn_align_u32(uint32_t v
, uint32_t a
)
912 assert(a
!= 0 && a
== (a
& -((int32_t) a
)));
913 return (v
+ a
- 1) & ~(a
- 1);
916 static inline uint64_t
917 vtn_u64_literal(const uint32_t *w
)
919 return (uint64_t)w
[1] << 32 | w
[0];
922 bool vtn_handle_amd_gcn_shader_instruction(struct vtn_builder
*b
, SpvOp ext_opcode
,
923 const uint32_t *words
, unsigned count
);
925 bool vtn_handle_amd_shader_ballot_instruction(struct vtn_builder
*b
, SpvOp ext_opcode
,
926 const uint32_t *w
, unsigned count
);
928 bool vtn_handle_amd_shader_trinary_minmax_instruction(struct vtn_builder
*b
, SpvOp ext_opcode
,
929 const uint32_t *words
, unsigned count
);
931 bool vtn_handle_amd_shader_explicit_vertex_parameter_instruction(struct vtn_builder
*b
,
933 const uint32_t *words
,
936 SpvMemorySemanticsMask
vtn_mode_to_memory_semantics(enum vtn_variable_mode mode
);
938 void vtn_emit_memory_barrier(struct vtn_builder
*b
, SpvScope scope
,
939 SpvMemorySemanticsMask semantics
);
941 #endif /* _VTN_PRIVATE_H_ */