2 * Copyright © 2014 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 * Connor Abbott (cwabbott0@gmail.com)
29 #include "compiler/shader_enums.h"
30 #include "util/half_float.h"
31 #include "vulkan/vulkan_core.h"
34 #include <inttypes.h> /* for PRIx64 macro */
37 print_tabs(unsigned num_tabs
, FILE *fp
)
39 for (unsigned i
= 0; i
< num_tabs
; i
++)
46 /** map from nir_variable -> printable name */
47 struct hash_table
*ht
;
49 /** set of names used so far for nir_variables */
52 /* an index used to make new non-conflicting names */
56 * Optional table of annotations mapping nir object
57 * (such as instr or var) to message to print.
59 struct hash_table
*annotations
;
63 print_annotation(print_state
*state
, void *obj
)
67 if (!state
->annotations
)
70 struct hash_entry
*entry
= _mesa_hash_table_search(state
->annotations
, obj
);
74 const char *note
= entry
->data
;
75 _mesa_hash_table_remove(state
->annotations
, entry
);
77 fprintf(fp
, "%s\n\n", note
);
81 print_register(nir_register
*reg
, print_state
*state
)
84 if (reg
->name
!= NULL
)
85 fprintf(fp
, "/* %s */ ", reg
->name
);
86 fprintf(fp
, "r%u", reg
->index
);
89 static const char *sizes
[] = { "error", "vec1", "vec2", "vec3", "vec4",
90 "error", "error", "error", "vec8",
91 "error", "error", "error", "error",
92 "error", "error", "error", "vec16"};
95 print_register_decl(nir_register
*reg
, print_state
*state
)
98 fprintf(fp
, "decl_reg %s %u ", sizes
[reg
->num_components
], reg
->bit_size
);
99 print_register(reg
, state
);
100 if (reg
->num_array_elems
!= 0)
101 fprintf(fp
, "[%u]", reg
->num_array_elems
);
106 print_ssa_def(nir_ssa_def
*def
, print_state
*state
)
108 FILE *fp
= state
->fp
;
109 if (def
->name
!= NULL
)
110 fprintf(fp
, "/* %s */ ", def
->name
);
111 fprintf(fp
, "%s %u ssa_%u", sizes
[def
->num_components
], def
->bit_size
,
116 print_ssa_use(nir_ssa_def
*def
, print_state
*state
)
118 FILE *fp
= state
->fp
;
119 if (def
->name
!= NULL
)
120 fprintf(fp
, "/* %s */ ", def
->name
);
121 fprintf(fp
, "ssa_%u", def
->index
);
124 static void print_src(const nir_src
*src
, print_state
*state
);
127 print_reg_src(const nir_reg_src
*src
, print_state
*state
)
129 FILE *fp
= state
->fp
;
130 print_register(src
->reg
, state
);
131 if (src
->reg
->num_array_elems
!= 0) {
132 fprintf(fp
, "[%u", src
->base_offset
);
133 if (src
->indirect
!= NULL
) {
135 print_src(src
->indirect
, state
);
142 print_reg_dest(nir_reg_dest
*dest
, print_state
*state
)
144 FILE *fp
= state
->fp
;
145 print_register(dest
->reg
, state
);
146 if (dest
->reg
->num_array_elems
!= 0) {
147 fprintf(fp
, "[%u", dest
->base_offset
);
148 if (dest
->indirect
!= NULL
) {
150 print_src(dest
->indirect
, state
);
157 print_src(const nir_src
*src
, print_state
*state
)
160 print_ssa_use(src
->ssa
, state
);
162 print_reg_src(&src
->reg
, state
);
166 print_dest(nir_dest
*dest
, print_state
*state
)
169 print_ssa_def(&dest
->ssa
, state
);
171 print_reg_dest(&dest
->reg
, state
);
175 comp_mask_string(unsigned num_components
)
177 return (num_components
> 4) ? "abcdefghijklmnop" : "xyzw";
181 print_alu_src(nir_alu_instr
*instr
, unsigned src
, print_state
*state
)
183 FILE *fp
= state
->fp
;
185 if (instr
->src
[src
].negate
)
187 if (instr
->src
[src
].abs
)
190 print_src(&instr
->src
[src
].src
, state
);
192 bool print_swizzle
= false;
193 nir_component_mask_t used_channels
= 0;
195 for (unsigned i
= 0; i
< NIR_MAX_VEC_COMPONENTS
; i
++) {
196 if (!nir_alu_instr_channel_used(instr
, src
, i
))
201 if (instr
->src
[src
].swizzle
[i
] != i
) {
202 print_swizzle
= true;
207 unsigned live_channels
= nir_src_num_components(instr
->src
[src
].src
);
209 if (print_swizzle
|| used_channels
!= live_channels
) {
211 for (unsigned i
= 0; i
< NIR_MAX_VEC_COMPONENTS
; i
++) {
212 if (!nir_alu_instr_channel_used(instr
, src
, i
))
215 fprintf(fp
, "%c", comp_mask_string(live_channels
)[instr
->src
[src
].swizzle
[i
]]);
219 if (instr
->src
[src
].abs
)
224 print_alu_dest(nir_alu_dest
*dest
, print_state
*state
)
226 FILE *fp
= state
->fp
;
227 /* we're going to print the saturate modifier later, after the opcode */
229 print_dest(&dest
->dest
, state
);
231 if (!dest
->dest
.is_ssa
&&
232 dest
->write_mask
!= (1 << dest
->dest
.reg
.reg
->num_components
) - 1) {
233 unsigned live_channels
= dest
->dest
.reg
.reg
->num_components
;
235 for (unsigned i
= 0; i
< NIR_MAX_VEC_COMPONENTS
; i
++)
236 if ((dest
->write_mask
>> i
) & 1)
237 fprintf(fp
, "%c", comp_mask_string(live_channels
)[i
]);
242 print_alu_instr(nir_alu_instr
*instr
, print_state
*state
)
244 FILE *fp
= state
->fp
;
246 print_alu_dest(&instr
->dest
, state
);
248 fprintf(fp
, " = %s", nir_op_infos
[instr
->op
].name
);
251 if (instr
->dest
.saturate
)
253 if (instr
->no_signed_wrap
)
255 if (instr
->no_unsigned_wrap
)
259 for (unsigned i
= 0; i
< nir_op_infos
[instr
->op
].num_inputs
; i
++) {
263 print_alu_src(instr
, i
, state
);
268 get_var_name(nir_variable
*var
, print_state
*state
)
270 if (state
->ht
== NULL
)
271 return var
->name
? var
->name
: "unnamed";
275 struct hash_entry
*entry
= _mesa_hash_table_search(state
->ht
, var
);
280 if (var
->name
== NULL
) {
281 name
= ralloc_asprintf(state
->syms
, "@%u", state
->index
++);
283 struct set_entry
*set_entry
= _mesa_set_search(state
->syms
, var
->name
);
284 if (set_entry
!= NULL
) {
285 /* we have a collision with another name, append an @ + a unique
287 name
= ralloc_asprintf(state
->syms
, "%s@%u", var
->name
,
290 /* Mark this one as seen */
291 _mesa_set_add(state
->syms
, var
->name
);
296 _mesa_hash_table_insert(state
->ht
, var
, name
);
302 print_constant(nir_constant
*c
, const struct glsl_type
*type
, print_state
*state
)
304 FILE *fp
= state
->fp
;
305 const unsigned rows
= glsl_get_vector_elements(type
);
306 const unsigned cols
= glsl_get_matrix_columns(type
);
309 switch (glsl_get_base_type(type
)) {
311 /* Only float base types can be matrices. */
314 for (i
= 0; i
< rows
; i
++) {
315 if (i
> 0) fprintf(fp
, ", ");
316 fprintf(fp
, "%s", c
->values
[i
].b
? "true" : "false");
320 case GLSL_TYPE_UINT8
:
322 /* Only float base types can be matrices. */
325 for (i
= 0; i
< rows
; i
++) {
326 if (i
> 0) fprintf(fp
, ", ");
327 fprintf(fp
, "0x%02x", c
->values
[i
].u8
);
331 case GLSL_TYPE_UINT16
:
332 case GLSL_TYPE_INT16
:
333 /* Only float base types can be matrices. */
336 for (i
= 0; i
< rows
; i
++) {
337 if (i
> 0) fprintf(fp
, ", ");
338 fprintf(fp
, "0x%04x", c
->values
[i
].u16
);
344 /* Only float base types can be matrices. */
347 for (i
= 0; i
< rows
; i
++) {
348 if (i
> 0) fprintf(fp
, ", ");
349 fprintf(fp
, "0x%08x", c
->values
[i
].u32
);
353 case GLSL_TYPE_FLOAT16
:
354 case GLSL_TYPE_FLOAT
:
355 case GLSL_TYPE_DOUBLE
:
357 for (i
= 0; i
< cols
; i
++) {
358 if (i
> 0) fprintf(fp
, ", ");
359 print_constant(c
->elements
[i
], glsl_get_column_type(type
), state
);
362 switch (glsl_get_base_type(type
)) {
363 case GLSL_TYPE_FLOAT16
:
364 for (i
= 0; i
< rows
; i
++) {
365 if (i
> 0) fprintf(fp
, ", ");
366 fprintf(fp
, "%f", _mesa_half_to_float(c
->values
[i
].u16
));
370 case GLSL_TYPE_FLOAT
:
371 for (i
= 0; i
< rows
; i
++) {
372 if (i
> 0) fprintf(fp
, ", ");
373 fprintf(fp
, "%f", c
->values
[i
].f32
);
377 case GLSL_TYPE_DOUBLE
:
378 for (i
= 0; i
< rows
; i
++) {
379 if (i
> 0) fprintf(fp
, ", ");
380 fprintf(fp
, "%f", c
->values
[i
].f64
);
385 unreachable("Cannot get here from the first level switch");
390 case GLSL_TYPE_UINT64
:
391 case GLSL_TYPE_INT64
:
392 /* Only float base types can be matrices. */
395 for (i
= 0; i
< cols
; i
++) {
396 if (i
> 0) fprintf(fp
, ", ");
397 fprintf(fp
, "0x%08" PRIx64
, c
->values
[i
].u64
);
401 case GLSL_TYPE_STRUCT
:
402 for (i
= 0; i
< c
->num_elements
; i
++) {
403 if (i
> 0) fprintf(fp
, ", ");
405 print_constant(c
->elements
[i
], glsl_get_struct_field(type
, i
), state
);
410 case GLSL_TYPE_ARRAY
:
411 for (i
= 0; i
< c
->num_elements
; i
++) {
412 if (i
> 0) fprintf(fp
, ", ");
414 print_constant(c
->elements
[i
], glsl_get_array_element(type
), state
);
420 unreachable("not reached");
425 get_variable_mode_str(nir_variable_mode mode
, bool want_local_global_mode
)
428 case nir_var_shader_in
:
430 case nir_var_shader_out
:
432 case nir_var_uniform
:
434 case nir_var_mem_ubo
:
436 case nir_var_system_value
:
438 case nir_var_mem_ssbo
:
440 case nir_var_mem_shared
:
442 case nir_var_mem_global
:
444 case nir_var_shader_temp
:
445 return want_local_global_mode
? "shader_temp" : "";
446 case nir_var_function_temp
:
447 return want_local_global_mode
? "function_temp" : "";
454 print_var_decl(nir_variable
*var
, print_state
*state
)
456 FILE *fp
= state
->fp
;
458 fprintf(fp
, "decl_var ");
460 const char *const cent
= (var
->data
.centroid
) ? "centroid " : "";
461 const char *const samp
= (var
->data
.sample
) ? "sample " : "";
462 const char *const patch
= (var
->data
.patch
) ? "patch " : "";
463 const char *const inv
= (var
->data
.invariant
) ? "invariant " : "";
464 fprintf(fp
, "%s%s%s%s%s %s ",
465 cent
, samp
, patch
, inv
, get_variable_mode_str(var
->data
.mode
, false),
466 glsl_interp_mode_name(var
->data
.interpolation
));
468 enum gl_access_qualifier access
= var
->data
.access
;
469 const char *const coher
= (access
& ACCESS_COHERENT
) ? "coherent " : "";
470 const char *const volat
= (access
& ACCESS_VOLATILE
) ? "volatile " : "";
471 const char *const restr
= (access
& ACCESS_RESTRICT
) ? "restrict " : "";
472 const char *const ronly
= (access
& ACCESS_NON_WRITEABLE
) ? "readonly " : "";
473 const char *const wonly
= (access
& ACCESS_NON_READABLE
) ? "writeonly " : "";
474 const char *const reorder
= (access
& ACCESS_CAN_REORDER
) ? "reorderable " : "";
475 fprintf(fp
, "%s%s%s%s%s%s", coher
, volat
, restr
, ronly
, wonly
, reorder
);
477 if (glsl_get_base_type(glsl_without_array(var
->type
)) == GLSL_TYPE_IMAGE
) {
478 #define FORMAT_CASE(x) case x: fprintf(fp, #x " "); break
479 switch (var
->data
.image
.format
) {
480 FORMAT_CASE(GL_RGBA32F
);
481 FORMAT_CASE(GL_RGBA32UI
);
482 FORMAT_CASE(GL_RGBA32I
);
483 FORMAT_CASE(GL_R32F
);
484 FORMAT_CASE(GL_R32UI
);
485 FORMAT_CASE(GL_R32I
);
486 FORMAT_CASE(GL_RG32F
);
487 FORMAT_CASE(GL_RG32UI
);
488 FORMAT_CASE(GL_RG32I
);
491 FORMAT_CASE(GL_RGBA8
);
492 FORMAT_CASE(GL_R8_SNORM
);
493 FORMAT_CASE(GL_RG8_SNORM
);
494 FORMAT_CASE(GL_RGBA8_SNORM
);
496 FORMAT_CASE(GL_RG16
);
497 FORMAT_CASE(GL_RGBA16
);
498 FORMAT_CASE(GL_R16_SNORM
);
499 FORMAT_CASE(GL_RG16_SNORM
);
500 FORMAT_CASE(GL_RGBA16_SNORM
);
501 FORMAT_CASE(GL_R16F
);
502 FORMAT_CASE(GL_RG16F
);
503 FORMAT_CASE(GL_RGBA16F
);
504 FORMAT_CASE(GL_R8UI
);
506 FORMAT_CASE(GL_RG8UI
);
507 FORMAT_CASE(GL_RG8I
);
508 FORMAT_CASE(GL_RGBA8UI
);
509 FORMAT_CASE(GL_RGBA8I
);
510 FORMAT_CASE(GL_R16UI
);
511 FORMAT_CASE(GL_R16I
);
512 FORMAT_CASE(GL_RG16UI
);
513 FORMAT_CASE(GL_RG16I
);
514 FORMAT_CASE(GL_RGBA16UI
);
515 FORMAT_CASE(GL_RGBA16I
);
516 FORMAT_CASE(GL_R11F_G11F_B10F
);
517 FORMAT_CASE(GL_RGB9_E5
);
518 FORMAT_CASE(GL_RGB10_A2
);
519 FORMAT_CASE(GL_RGB10_A2UI
);
520 default: /* Including the normal GL_NONE */
526 fprintf(fp
, "%s %s", glsl_get_type_name(var
->type
),
527 get_var_name(var
, state
));
529 if (var
->data
.mode
== nir_var_shader_in
||
530 var
->data
.mode
== nir_var_shader_out
||
531 var
->data
.mode
== nir_var_uniform
||
532 var
->data
.mode
== nir_var_mem_ubo
||
533 var
->data
.mode
== nir_var_mem_ssbo
) {
534 const char *loc
= NULL
;
537 switch (state
->shader
->info
.stage
) {
538 case MESA_SHADER_VERTEX
:
539 if (var
->data
.mode
== nir_var_shader_in
)
540 loc
= gl_vert_attrib_name(var
->data
.location
);
541 else if (var
->data
.mode
== nir_var_shader_out
)
542 loc
= gl_varying_slot_name(var
->data
.location
);
544 case MESA_SHADER_GEOMETRY
:
545 if ((var
->data
.mode
== nir_var_shader_in
) ||
546 (var
->data
.mode
== nir_var_shader_out
))
547 loc
= gl_varying_slot_name(var
->data
.location
);
549 case MESA_SHADER_FRAGMENT
:
550 if (var
->data
.mode
== nir_var_shader_in
)
551 loc
= gl_varying_slot_name(var
->data
.location
);
552 else if (var
->data
.mode
== nir_var_shader_out
)
553 loc
= gl_frag_result_name(var
->data
.location
);
555 case MESA_SHADER_TESS_CTRL
:
556 case MESA_SHADER_TESS_EVAL
:
557 case MESA_SHADER_COMPUTE
:
558 case MESA_SHADER_KERNEL
:
565 snprintf(buf
, sizeof(buf
), "%u", var
->data
.location
);
569 /* For shader I/O vars that have been split to components or packed,
570 * print the fractional location within the input/output.
572 unsigned int num_components
=
573 glsl_get_components(glsl_without_array(var
->type
));
574 const char *components
= NULL
;
575 char components_local
[18] = {'.' /* the rest is 0-filled */};
576 switch (var
->data
.mode
) {
577 case nir_var_shader_in
:
578 case nir_var_shader_out
:
579 if (num_components
< 16 && num_components
!= 0) {
580 const char *xyzw
= comp_mask_string(num_components
);
581 for (int i
= 0; i
< num_components
; i
++)
582 components_local
[i
+ 1] = xyzw
[i
+ var
->data
.location_frac
];
584 components
= components_local
;
591 fprintf(fp
, " (%s%s, %u, %u)%s", loc
,
592 components
? components
: "",
593 var
->data
.driver_location
, var
->data
.binding
,
594 var
->data
.compact
? " compact" : "");
597 if (var
->constant_initializer
) {
598 fprintf(fp
, " = { ");
599 print_constant(var
->constant_initializer
, var
->type
, state
);
604 print_annotation(state
, var
);
608 print_deref_link(const nir_deref_instr
*instr
, bool whole_chain
, print_state
*state
)
610 FILE *fp
= state
->fp
;
612 if (instr
->deref_type
== nir_deref_type_var
) {
613 fprintf(fp
, "%s", get_var_name(instr
->var
, state
));
615 } else if (instr
->deref_type
== nir_deref_type_cast
) {
616 fprintf(fp
, "(%s *)", glsl_get_type_name(instr
->type
));
617 print_src(&instr
->parent
, state
);
621 assert(instr
->parent
.is_ssa
);
622 nir_deref_instr
*parent
=
623 nir_instr_as_deref(instr
->parent
.ssa
->parent_instr
);
625 /* Is the parent we're going to print a bare cast? */
626 const bool is_parent_cast
=
627 whole_chain
&& parent
->deref_type
== nir_deref_type_cast
;
629 /* If we're not printing the whole chain, the parent we print will be a SSA
630 * value that represents a pointer. The only deref type that naturally
631 * gives a pointer is a cast.
633 const bool is_parent_pointer
=
634 !whole_chain
|| parent
->deref_type
== nir_deref_type_cast
;
636 /* Struct derefs have a nice syntax that works on pointers, arrays derefs
639 const bool need_deref
=
640 is_parent_pointer
&& instr
->deref_type
!= nir_deref_type_struct
;
642 /* Cast need extra parens and so * dereferences */
643 if (is_parent_cast
|| need_deref
)
650 print_deref_link(parent
, whole_chain
, state
);
652 print_src(&instr
->parent
, state
);
655 if (is_parent_cast
|| need_deref
)
658 switch (instr
->deref_type
) {
659 case nir_deref_type_struct
:
660 fprintf(fp
, "%s%s", is_parent_pointer
? "->" : ".",
661 glsl_get_struct_elem_name(parent
->type
, instr
->strct
.index
));
664 case nir_deref_type_array
:
665 case nir_deref_type_ptr_as_array
: {
666 if (nir_src_is_const(instr
->arr
.index
)) {
667 fprintf(fp
, "[%"PRId64
"]", nir_src_as_int(instr
->arr
.index
));
670 print_src(&instr
->arr
.index
, state
);
676 case nir_deref_type_array_wildcard
:
681 unreachable("Invalid deref instruction type");
686 print_deref_instr(nir_deref_instr
*instr
, print_state
*state
)
688 FILE *fp
= state
->fp
;
690 print_dest(&instr
->dest
, state
);
692 switch (instr
->deref_type
) {
693 case nir_deref_type_var
:
694 fprintf(fp
, " = deref_var ");
696 case nir_deref_type_array
:
697 case nir_deref_type_array_wildcard
:
698 fprintf(fp
, " = deref_array ");
700 case nir_deref_type_struct
:
701 fprintf(fp
, " = deref_struct ");
703 case nir_deref_type_cast
:
704 fprintf(fp
, " = deref_cast ");
706 case nir_deref_type_ptr_as_array
:
707 fprintf(fp
, " = deref_ptr_as_array ");
710 unreachable("Invalid deref instruction type");
713 /* Only casts naturally return a pointer type */
714 if (instr
->deref_type
!= nir_deref_type_cast
)
717 print_deref_link(instr
, false, state
);
719 fprintf(fp
, " (%s %s) ",
720 get_variable_mode_str(instr
->mode
, true),
721 glsl_get_type_name(instr
->type
));
723 if (instr
->deref_type
!= nir_deref_type_var
&&
724 instr
->deref_type
!= nir_deref_type_cast
) {
725 /* Print the entire chain as a comment */
727 print_deref_link(instr
, true, state
);
731 if (instr
->deref_type
== nir_deref_type_cast
) {
732 fprintf(fp
, " /* ptr_stride=%u */", instr
->cast
.ptr_stride
);
737 vulkan_descriptor_type_name(VkDescriptorType type
)
740 case VK_DESCRIPTOR_TYPE_SAMPLER
: return "sampler";
741 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
: return "texture+sampler";
742 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
: return "texture";
743 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
: return "image";
744 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
: return "texture-buffer";
745 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
: return "image-buffer";
746 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
: return "UBO";
747 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
: return "SSBO";
748 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
: return "UBO";
749 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
: return "SSBO";
750 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
: return "input-att";
751 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT
: return "inline-UBO";
752 default: return "unknown";
757 print_intrinsic_instr(nir_intrinsic_instr
*instr
, print_state
*state
)
759 const nir_intrinsic_info
*info
= &nir_intrinsic_infos
[instr
->intrinsic
];
760 unsigned num_srcs
= info
->num_srcs
;
761 FILE *fp
= state
->fp
;
763 if (info
->has_dest
) {
764 print_dest(&instr
->dest
, state
);
768 fprintf(fp
, "intrinsic %s (", info
->name
);
770 for (unsigned i
= 0; i
< num_srcs
; i
++) {
774 print_src(&instr
->src
[i
], state
);
779 for (unsigned i
= 0; i
< info
->num_indices
; i
++) {
783 fprintf(fp
, "%d", instr
->const_index
[i
]);
788 static const char *index_name
[NIR_INTRINSIC_NUM_INDEX_FLAGS
] = {
789 [NIR_INTRINSIC_BASE
] = "base",
790 [NIR_INTRINSIC_WRMASK
] = "wrmask",
791 [NIR_INTRINSIC_STREAM_ID
] = "stream-id",
792 [NIR_INTRINSIC_UCP_ID
] = "ucp-id",
793 [NIR_INTRINSIC_RANGE
] = "range",
794 [NIR_INTRINSIC_DESC_SET
] = "desc-set",
795 [NIR_INTRINSIC_BINDING
] = "binding",
796 [NIR_INTRINSIC_COMPONENT
] = "component",
797 [NIR_INTRINSIC_INTERP_MODE
] = "interp_mode",
798 [NIR_INTRINSIC_REDUCTION_OP
] = "reduction_op",
799 [NIR_INTRINSIC_CLUSTER_SIZE
] = "cluster_size",
800 [NIR_INTRINSIC_PARAM_IDX
] = "param_idx",
801 [NIR_INTRINSIC_IMAGE_DIM
] = "image_dim",
802 [NIR_INTRINSIC_IMAGE_ARRAY
] = "image_array",
803 [NIR_INTRINSIC_ACCESS
] = "access",
804 [NIR_INTRINSIC_SRC_ACCESS
] = "src-access",
805 [NIR_INTRINSIC_DST_ACCESS
] = "dst-access",
806 [NIR_INTRINSIC_FORMAT
] = "format",
807 [NIR_INTRINSIC_ALIGN_MUL
] = "align_mul",
808 [NIR_INTRINSIC_ALIGN_OFFSET
] = "align_offset",
809 [NIR_INTRINSIC_DESC_TYPE
] = "desc_type",
810 [NIR_INTRINSIC_TYPE
] = "type",
811 [NIR_INTRINSIC_SWIZZLE_MASK
] = "swizzle_mask",
812 [NIR_INTRINSIC_DRIVER_LOCATION
] = "driver_location",
813 [NIR_INTRINSIC_MEMORY_SEMANTICS
] = "mem_semantics",
814 [NIR_INTRINSIC_MEMORY_MODES
] = "mem_modes",
815 [NIR_INTRINSIC_MEMORY_SCOPE
] = "mem_scope",
817 for (unsigned idx
= 1; idx
< NIR_INTRINSIC_NUM_INDEX_FLAGS
; idx
++) {
818 if (!info
->index_map
[idx
])
822 case NIR_INTRINSIC_WRMASK
: {
823 /* special case wrmask to show it as a writemask.. */
824 unsigned wrmask
= nir_intrinsic_write_mask(instr
);
825 fprintf(fp
, " wrmask=");
826 for (unsigned i
= 0; i
< instr
->num_components
; i
++)
827 if ((wrmask
>> i
) & 1)
828 fprintf(fp
, "%c", comp_mask_string(instr
->num_components
)[i
]);
832 case NIR_INTRINSIC_REDUCTION_OP
: {
833 nir_op reduction_op
= nir_intrinsic_reduction_op(instr
);
834 fprintf(fp
, " reduction_op=%s", nir_op_infos
[reduction_op
].name
);
838 case NIR_INTRINSIC_IMAGE_DIM
: {
839 static const char *dim_name
[] = {
840 [GLSL_SAMPLER_DIM_1D
] = "1D",
841 [GLSL_SAMPLER_DIM_2D
] = "2D",
842 [GLSL_SAMPLER_DIM_3D
] = "3D",
843 [GLSL_SAMPLER_DIM_CUBE
] = "Cube",
844 [GLSL_SAMPLER_DIM_RECT
] = "Rect",
845 [GLSL_SAMPLER_DIM_BUF
] = "Buf",
846 [GLSL_SAMPLER_DIM_MS
] = "2D-MSAA",
847 [GLSL_SAMPLER_DIM_SUBPASS
] = "Subpass",
848 [GLSL_SAMPLER_DIM_SUBPASS_MS
] = "Subpass-MSAA",
850 enum glsl_sampler_dim dim
= nir_intrinsic_image_dim(instr
);
851 assert(dim
< ARRAY_SIZE(dim_name
) && dim_name
[dim
]);
852 fprintf(fp
, " image_dim=%s", dim_name
[dim
]);
856 case NIR_INTRINSIC_IMAGE_ARRAY
: {
857 bool array
= nir_intrinsic_image_array(instr
);
858 fprintf(fp
, " image_array=%s", array
? "true" : "false");
862 case NIR_INTRINSIC_DESC_TYPE
: {
863 VkDescriptorType desc_type
= nir_intrinsic_desc_type(instr
);
864 fprintf(fp
, " desc_type=%s", vulkan_descriptor_type_name(desc_type
));
868 case NIR_INTRINSIC_TYPE
: {
869 nir_alu_type type
= nir_intrinsic_type(instr
);
870 unsigned size
= nir_alu_type_get_type_size(type
);
872 switch (nir_alu_type_get_base_type(type
)) {
873 case nir_type_int
: name
= "int"; break;
874 case nir_type_uint
: name
= "uint"; break;
875 case nir_type_bool
: name
= "bool"; break;
876 case nir_type_float
: name
= "float"; break;
877 default: name
= "invalid";
880 fprintf(fp
, " type=%s%u", name
, size
);
882 fprintf(fp
, " type=%s", name
);
886 case NIR_INTRINSIC_SWIZZLE_MASK
: {
887 fprintf(fp
, " swizzle_mask=");
888 unsigned mask
= nir_intrinsic_swizzle_mask(instr
);
889 if (instr
->intrinsic
== nir_intrinsic_quad_swizzle_amd
) {
890 for (unsigned i
= 0; i
< 4; i
++)
891 fprintf(fp
, "%d", (mask
>> (i
* 2) & 3));
892 } else if (instr
->intrinsic
== nir_intrinsic_masked_swizzle_amd
) {
893 fprintf(fp
, "((id & %d) | %d) ^ %d", mask
& 0x1F,
895 (mask
>> 10) & 0x1F);
897 fprintf(fp
, "%d", mask
);
902 case NIR_INTRINSIC_MEMORY_SEMANTICS
: {
903 nir_memory_semantics semantics
= nir_intrinsic_memory_semantics(instr
);
904 fprintf(fp
, " mem_semantics=");
905 switch (semantics
& (NIR_MEMORY_ACQUIRE
| NIR_MEMORY_RELEASE
)) {
906 case 0: fprintf(fp
, "NONE"); break;
907 case NIR_MEMORY_ACQUIRE
: fprintf(fp
, "ACQ"); break;
908 case NIR_MEMORY_RELEASE
: fprintf(fp
, "REL"); break;
909 default: fprintf(fp
, "ACQ|REL"); break;
911 if (semantics
& (NIR_MEMORY_MAKE_AVAILABLE
)) fprintf(fp
, "|AVAILABLE");
912 if (semantics
& (NIR_MEMORY_MAKE_VISIBLE
)) fprintf(fp
, "|VISIBLE");
916 case NIR_INTRINSIC_MEMORY_MODES
: {
917 fprintf(fp
, " mem_modes=");
918 unsigned int modes
= nir_intrinsic_memory_modes(instr
);
920 nir_variable_mode m
= u_bit_scan(&modes
);
921 fprintf(fp
, "%s%s", get_variable_mode_str(1 << m
, true), modes
? "|" : "");
926 case NIR_INTRINSIC_MEMORY_SCOPE
: {
927 fprintf(fp
, " mem_scope=");
928 switch (nir_intrinsic_memory_scope(instr
)) {
929 case NIR_SCOPE_DEVICE
: fprintf(fp
, "DEVICE"); break;
930 case NIR_SCOPE_QUEUE_FAMILY
: fprintf(fp
, "QUEUE_FAMILY"); break;
931 case NIR_SCOPE_WORKGROUP
: fprintf(fp
, "WORKGROUP"); break;
932 case NIR_SCOPE_SUBGROUP
: fprintf(fp
, "SUBGROUP"); break;
933 case NIR_SCOPE_INVOCATION
: fprintf(fp
, "INVOCATION"); break;
939 unsigned off
= info
->index_map
[idx
] - 1;
940 assert(index_name
[idx
]); /* forgot to update index_name table? */
941 fprintf(fp
, " %s=%d", index_name
[idx
], instr
->const_index
[off
]);
951 struct exec_list
*var_list
= NULL
;
953 switch (instr
->intrinsic
) {
954 case nir_intrinsic_load_uniform
:
955 var_list
= &state
->shader
->uniforms
;
957 case nir_intrinsic_load_input
:
958 case nir_intrinsic_load_interpolated_input
:
959 case nir_intrinsic_load_per_vertex_input
:
960 var_list
= &state
->shader
->inputs
;
962 case nir_intrinsic_load_output
:
963 case nir_intrinsic_store_output
:
964 case nir_intrinsic_store_per_vertex_output
:
965 var_list
= &state
->shader
->outputs
;
971 nir_foreach_variable(var
, var_list
) {
972 if ((var
->data
.driver_location
== nir_intrinsic_base(instr
)) &&
973 (instr
->intrinsic
== nir_intrinsic_load_uniform
||
974 (nir_intrinsic_component(instr
) >= var
->data
.location_frac
&&
975 nir_intrinsic_component(instr
) <
976 (var
->data
.location_frac
+ glsl_get_components(var
->type
)))) &&
978 fprintf(fp
, "\t/* %s */", var
->name
);
985 print_tex_instr(nir_tex_instr
*instr
, print_state
*state
)
987 FILE *fp
= state
->fp
;
989 print_dest(&instr
->dest
, state
);
1001 fprintf(fp
, "txl ");
1004 fprintf(fp
, "txd ");
1007 fprintf(fp
, "txf ");
1009 case nir_texop_txf_ms
:
1010 fprintf(fp
, "txf_ms ");
1012 case nir_texop_txf_ms_fb
:
1013 fprintf(fp
, "txf_ms_fb ");
1015 case nir_texop_txf_ms_mcs
:
1016 fprintf(fp
, "txf_ms_mcs ");
1019 fprintf(fp
, "txs ");
1022 fprintf(fp
, "lod ");
1025 fprintf(fp
, "tg4 ");
1027 case nir_texop_query_levels
:
1028 fprintf(fp
, "query_levels ");
1030 case nir_texop_texture_samples
:
1031 fprintf(fp
, "texture_samples ");
1033 case nir_texop_samples_identical
:
1034 fprintf(fp
, "samples_identical ");
1036 case nir_texop_tex_prefetch
:
1037 fprintf(fp
, "tex (pre-dispatchable) ");
1040 unreachable("Invalid texture operation");
1044 bool has_texture_deref
= false, has_sampler_deref
= false;
1045 for (unsigned i
= 0; i
< instr
->num_srcs
; i
++) {
1050 print_src(&instr
->src
[i
].src
, state
);
1053 switch(instr
->src
[i
].src_type
) {
1054 case nir_tex_src_coord
:
1055 fprintf(fp
, "(coord)");
1057 case nir_tex_src_projector
:
1058 fprintf(fp
, "(projector)");
1060 case nir_tex_src_comparator
:
1061 fprintf(fp
, "(comparator)");
1063 case nir_tex_src_offset
:
1064 fprintf(fp
, "(offset)");
1066 case nir_tex_src_bias
:
1067 fprintf(fp
, "(bias)");
1069 case nir_tex_src_lod
:
1070 fprintf(fp
, "(lod)");
1072 case nir_tex_src_min_lod
:
1073 fprintf(fp
, "(min_lod)");
1075 case nir_tex_src_ms_index
:
1076 fprintf(fp
, "(ms_index)");
1078 case nir_tex_src_ms_mcs
:
1079 fprintf(fp
, "(ms_mcs)");
1081 case nir_tex_src_ddx
:
1082 fprintf(fp
, "(ddx)");
1084 case nir_tex_src_ddy
:
1085 fprintf(fp
, "(ddy)");
1087 case nir_tex_src_texture_deref
:
1088 has_texture_deref
= true;
1089 fprintf(fp
, "(texture_deref)");
1091 case nir_tex_src_sampler_deref
:
1092 has_sampler_deref
= true;
1093 fprintf(fp
, "(sampler_deref)");
1095 case nir_tex_src_texture_offset
:
1096 fprintf(fp
, "(texture_offset)");
1098 case nir_tex_src_sampler_offset
:
1099 fprintf(fp
, "(sampler_offset)");
1101 case nir_tex_src_texture_handle
:
1102 fprintf(fp
, "(texture_handle)");
1104 case nir_tex_src_sampler_handle
:
1105 fprintf(fp
, "(sampler_handle)");
1107 case nir_tex_src_plane
:
1108 fprintf(fp
, "(plane)");
1112 unreachable("Invalid texture source type");
1117 if (instr
->op
== nir_texop_tg4
) {
1118 fprintf(fp
, ", %u (gather_component)", instr
->component
);
1121 if (nir_tex_instr_has_explicit_tg4_offsets(instr
)) {
1122 fprintf(fp
, ", { (%i, %i)", instr
->tg4_offsets
[0][0], instr
->tg4_offsets
[0][1]);
1123 for (unsigned i
= 1; i
< 4; ++i
)
1124 fprintf(fp
, ", (%i, %i)", instr
->tg4_offsets
[i
][0],
1125 instr
->tg4_offsets
[i
][1]);
1126 fprintf(fp
, " } (offsets)");
1129 if (instr
->op
!= nir_texop_txf_ms_fb
) {
1130 if (!has_texture_deref
) {
1131 fprintf(fp
, ", %u (texture)", instr
->texture_index
);
1134 if (!has_sampler_deref
) {
1135 fprintf(fp
, ", %u (sampler)", instr
->sampler_index
);
1139 if (instr
->texture_non_uniform
) {
1140 fprintf(fp
, ", texture non-uniform");
1143 if (instr
->sampler_non_uniform
) {
1144 fprintf(fp
, ", sampler non-uniform");
1149 print_call_instr(nir_call_instr
*instr
, print_state
*state
)
1151 FILE *fp
= state
->fp
;
1153 fprintf(fp
, "call %s ", instr
->callee
->name
);
1155 for (unsigned i
= 0; i
< instr
->num_params
; i
++) {
1159 print_src(&instr
->params
[i
], state
);
1164 print_load_const_instr(nir_load_const_instr
*instr
, print_state
*state
)
1166 FILE *fp
= state
->fp
;
1168 print_ssa_def(&instr
->def
, state
);
1170 fprintf(fp
, " = load_const (");
1172 for (unsigned i
= 0; i
< instr
->def
.num_components
; i
++) {
1177 * we don't really know the type of the constant (if it will be used as a
1178 * float or an int), so just print the raw constant in hex for fidelity
1179 * and then print the float in a comment for readability.
1182 switch (instr
->def
.bit_size
) {
1184 fprintf(fp
, "0x%16" PRIx64
" /* %f */", instr
->value
[i
].u64
,
1185 instr
->value
[i
].f64
);
1188 fprintf(fp
, "0x%08x /* %f */", instr
->value
[i
].u32
, instr
->value
[i
].f32
);
1191 fprintf(fp
, "0x%04x /* %f */", instr
->value
[i
].u16
,
1192 _mesa_half_to_float(instr
->value
[i
].u16
));
1195 fprintf(fp
, "0x%02x", instr
->value
[i
].u8
);
1198 fprintf(fp
, "%s", instr
->value
[i
].b
? "true" : "false");
1207 print_jump_instr(nir_jump_instr
*instr
, print_state
*state
)
1209 FILE *fp
= state
->fp
;
1211 switch (instr
->type
) {
1212 case nir_jump_break
:
1213 fprintf(fp
, "break");
1216 case nir_jump_continue
:
1217 fprintf(fp
, "continue");
1220 case nir_jump_return
:
1221 fprintf(fp
, "return");
1227 print_ssa_undef_instr(nir_ssa_undef_instr
* instr
, print_state
*state
)
1229 FILE *fp
= state
->fp
;
1230 print_ssa_def(&instr
->def
, state
);
1231 fprintf(fp
, " = undefined");
1235 print_phi_instr(nir_phi_instr
*instr
, print_state
*state
)
1237 FILE *fp
= state
->fp
;
1238 print_dest(&instr
->dest
, state
);
1239 fprintf(fp
, " = phi ");
1240 nir_foreach_phi_src(src
, instr
) {
1241 if (&src
->node
!= exec_list_get_head(&instr
->srcs
))
1244 fprintf(fp
, "block_%u: ", src
->pred
->index
);
1245 print_src(&src
->src
, state
);
1250 print_parallel_copy_instr(nir_parallel_copy_instr
*instr
, print_state
*state
)
1252 FILE *fp
= state
->fp
;
1253 nir_foreach_parallel_copy_entry(entry
, instr
) {
1254 if (&entry
->node
!= exec_list_get_head(&instr
->entries
))
1257 print_dest(&entry
->dest
, state
);
1259 print_src(&entry
->src
, state
);
1264 print_instr(const nir_instr
*instr
, print_state
*state
, unsigned tabs
)
1266 FILE *fp
= state
->fp
;
1267 print_tabs(tabs
, fp
);
1269 switch (instr
->type
) {
1270 case nir_instr_type_alu
:
1271 print_alu_instr(nir_instr_as_alu(instr
), state
);
1274 case nir_instr_type_deref
:
1275 print_deref_instr(nir_instr_as_deref(instr
), state
);
1278 case nir_instr_type_call
:
1279 print_call_instr(nir_instr_as_call(instr
), state
);
1282 case nir_instr_type_intrinsic
:
1283 print_intrinsic_instr(nir_instr_as_intrinsic(instr
), state
);
1286 case nir_instr_type_tex
:
1287 print_tex_instr(nir_instr_as_tex(instr
), state
);
1290 case nir_instr_type_load_const
:
1291 print_load_const_instr(nir_instr_as_load_const(instr
), state
);
1294 case nir_instr_type_jump
:
1295 print_jump_instr(nir_instr_as_jump(instr
), state
);
1298 case nir_instr_type_ssa_undef
:
1299 print_ssa_undef_instr(nir_instr_as_ssa_undef(instr
), state
);
1302 case nir_instr_type_phi
:
1303 print_phi_instr(nir_instr_as_phi(instr
), state
);
1306 case nir_instr_type_parallel_copy
:
1307 print_parallel_copy_instr(nir_instr_as_parallel_copy(instr
), state
);
1311 unreachable("Invalid instruction type");
1317 compare_block_index(const void *p1
, const void *p2
)
1319 const nir_block
*block1
= *((const nir_block
**) p1
);
1320 const nir_block
*block2
= *((const nir_block
**) p2
);
1322 return (int) block1
->index
- (int) block2
->index
;
1325 static void print_cf_node(nir_cf_node
*node
, print_state
*state
,
1329 print_block(nir_block
*block
, print_state
*state
, unsigned tabs
)
1331 FILE *fp
= state
->fp
;
1333 print_tabs(tabs
, fp
);
1334 fprintf(fp
, "block block_%u:\n", block
->index
);
1336 /* sort the predecessors by index so we consistently print the same thing */
1339 malloc(block
->predecessors
->entries
* sizeof(nir_block
*));
1342 set_foreach(block
->predecessors
, entry
) {
1343 preds
[i
++] = (nir_block
*) entry
->key
;
1346 qsort(preds
, block
->predecessors
->entries
, sizeof(nir_block
*),
1347 compare_block_index
);
1349 print_tabs(tabs
, fp
);
1350 fprintf(fp
, "/* preds: ");
1351 for (unsigned i
= 0; i
< block
->predecessors
->entries
; i
++) {
1352 fprintf(fp
, "block_%u ", preds
[i
]->index
);
1354 fprintf(fp
, "*/\n");
1358 nir_foreach_instr(instr
, block
) {
1359 print_instr(instr
, state
, tabs
);
1361 print_annotation(state
, instr
);
1364 print_tabs(tabs
, fp
);
1365 fprintf(fp
, "/* succs: ");
1366 for (unsigned i
= 0; i
< 2; i
++)
1367 if (block
->successors
[i
]) {
1368 fprintf(fp
, "block_%u ", block
->successors
[i
]->index
);
1370 fprintf(fp
, "*/\n");
1374 print_if(nir_if
*if_stmt
, print_state
*state
, unsigned tabs
)
1376 FILE *fp
= state
->fp
;
1378 print_tabs(tabs
, fp
);
1380 print_src(&if_stmt
->condition
, state
);
1381 fprintf(fp
, " {\n");
1382 foreach_list_typed(nir_cf_node
, node
, node
, &if_stmt
->then_list
) {
1383 print_cf_node(node
, state
, tabs
+ 1);
1385 print_tabs(tabs
, fp
);
1386 fprintf(fp
, "} else {\n");
1387 foreach_list_typed(nir_cf_node
, node
, node
, &if_stmt
->else_list
) {
1388 print_cf_node(node
, state
, tabs
+ 1);
1390 print_tabs(tabs
, fp
);
1395 print_loop(nir_loop
*loop
, print_state
*state
, unsigned tabs
)
1397 FILE *fp
= state
->fp
;
1399 print_tabs(tabs
, fp
);
1400 fprintf(fp
, "loop {\n");
1401 foreach_list_typed(nir_cf_node
, node
, node
, &loop
->body
) {
1402 print_cf_node(node
, state
, tabs
+ 1);
1404 print_tabs(tabs
, fp
);
1409 print_cf_node(nir_cf_node
*node
, print_state
*state
, unsigned int tabs
)
1411 switch (node
->type
) {
1412 case nir_cf_node_block
:
1413 print_block(nir_cf_node_as_block(node
), state
, tabs
);
1416 case nir_cf_node_if
:
1417 print_if(nir_cf_node_as_if(node
), state
, tabs
);
1420 case nir_cf_node_loop
:
1421 print_loop(nir_cf_node_as_loop(node
), state
, tabs
);
1425 unreachable("Invalid CFG node type");
1430 print_function_impl(nir_function_impl
*impl
, print_state
*state
)
1432 FILE *fp
= state
->fp
;
1434 fprintf(fp
, "\nimpl %s ", impl
->function
->name
);
1438 nir_foreach_variable(var
, &impl
->locals
) {
1440 print_var_decl(var
, state
);
1443 foreach_list_typed(nir_register
, reg
, node
, &impl
->registers
) {
1445 print_register_decl(reg
, state
);
1448 nir_index_blocks(impl
);
1450 foreach_list_typed(nir_cf_node
, node
, node
, &impl
->body
) {
1451 print_cf_node(node
, state
, 1);
1454 fprintf(fp
, "\tblock block_%u:\n}\n\n", impl
->end_block
->index
);
1458 print_function(nir_function
*function
, print_state
*state
)
1460 FILE *fp
= state
->fp
;
1462 fprintf(fp
, "decl_function %s (%d params)", function
->name
,
1463 function
->num_params
);
1467 if (function
->impl
!= NULL
) {
1468 print_function_impl(function
->impl
, state
);
1474 init_print_state(print_state
*state
, nir_shader
*shader
, FILE *fp
)
1477 state
->shader
= shader
;
1478 state
->ht
= _mesa_pointer_hash_table_create(NULL
);
1479 state
->syms
= _mesa_set_create(NULL
, _mesa_key_hash_string
,
1480 _mesa_key_string_equal
);
1485 destroy_print_state(print_state
*state
)
1487 _mesa_hash_table_destroy(state
->ht
, NULL
);
1488 _mesa_set_destroy(state
->syms
, NULL
);
1492 nir_print_shader_annotated(nir_shader
*shader
, FILE *fp
,
1493 struct hash_table
*annotations
)
1496 init_print_state(&state
, shader
, fp
);
1498 state
.annotations
= annotations
;
1500 fprintf(fp
, "shader: %s\n", gl_shader_stage_name(shader
->info
.stage
));
1502 if (shader
->info
.name
)
1503 fprintf(fp
, "name: %s\n", shader
->info
.name
);
1505 if (shader
->info
.label
)
1506 fprintf(fp
, "label: %s\n", shader
->info
.label
);
1508 if (gl_shader_stage_is_compute(shader
->info
.stage
)) {
1509 fprintf(fp
, "local-size: %u, %u, %u%s\n",
1510 shader
->info
.cs
.local_size
[0],
1511 shader
->info
.cs
.local_size
[1],
1512 shader
->info
.cs
.local_size
[2],
1513 shader
->info
.cs
.local_size_variable
? " (variable)" : "");
1514 fprintf(fp
, "shared-size: %u\n", shader
->info
.cs
.shared_size
);
1517 fprintf(fp
, "inputs: %u\n", shader
->num_inputs
);
1518 fprintf(fp
, "outputs: %u\n", shader
->num_outputs
);
1519 fprintf(fp
, "uniforms: %u\n", shader
->num_uniforms
);
1520 fprintf(fp
, "shared: %u\n", shader
->num_shared
);
1521 if (shader
->scratch_size
)
1522 fprintf(fp
, "scratch: %u\n", shader
->scratch_size
);
1524 nir_foreach_variable(var
, &shader
->uniforms
) {
1525 print_var_decl(var
, &state
);
1528 nir_foreach_variable(var
, &shader
->inputs
) {
1529 print_var_decl(var
, &state
);
1532 nir_foreach_variable(var
, &shader
->outputs
) {
1533 print_var_decl(var
, &state
);
1536 nir_foreach_variable(var
, &shader
->shared
) {
1537 print_var_decl(var
, &state
);
1540 nir_foreach_variable(var
, &shader
->globals
) {
1541 print_var_decl(var
, &state
);
1544 nir_foreach_variable(var
, &shader
->system_values
) {
1545 print_var_decl(var
, &state
);
1548 foreach_list_typed(nir_function
, func
, node
, &shader
->functions
) {
1549 print_function(func
, &state
);
1552 destroy_print_state(&state
);
1556 nir_print_shader(nir_shader
*shader
, FILE *fp
)
1558 nir_print_shader_annotated(shader
, fp
, NULL
);
1563 nir_print_instr(const nir_instr
*instr
, FILE *fp
)
1565 print_state state
= {
1568 print_instr(instr
, &state
, 0);
1573 nir_print_deref(const nir_deref_instr
*deref
, FILE *fp
)
1575 print_state state
= {
1578 print_deref_link(deref
, true, &state
);