src/compiler: use new hash table and set creation helpers
[mesa.git] / src / compiler / nir / nir_print.c
1 /*
2 * Copyright © 2014 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 * Connor Abbott (cwabbott0@gmail.com)
25 *
26 */
27
28 #include "nir.h"
29 #include "compiler/shader_enums.h"
30 #include "util/half_float.h"
31 #include "vulkan/vulkan_core.h"
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <inttypes.h> /* for PRIx64 macro */
35
36 static void
37 print_tabs(unsigned num_tabs, FILE *fp)
38 {
39 for (unsigned i = 0; i < num_tabs; i++)
40 fprintf(fp, "\t");
41 }
42
43 typedef struct {
44 FILE *fp;
45 nir_shader *shader;
46 /** map from nir_variable -> printable name */
47 struct hash_table *ht;
48
49 /** set of names used so far for nir_variables */
50 struct set *syms;
51
52 /* an index used to make new non-conflicting names */
53 unsigned index;
54
55 /**
56 * Optional table of annotations mapping nir object
57 * (such as instr or var) to message to print.
58 */
59 struct hash_table *annotations;
60 } print_state;
61
62 static void
63 print_annotation(print_state *state, void *obj)
64 {
65 if (!state->annotations)
66 return;
67
68 struct hash_entry *entry = _mesa_hash_table_search(state->annotations, obj);
69 if (!entry)
70 return;
71
72 const char *note = entry->data;
73 _mesa_hash_table_remove(state->annotations, entry);
74
75 fprintf(stderr, "%s\n\n", note);
76 }
77
78 static void
79 print_register(nir_register *reg, print_state *state)
80 {
81 FILE *fp = state->fp;
82 if (reg->name != NULL)
83 fprintf(fp, "/* %s */ ", reg->name);
84 if (reg->is_global)
85 fprintf(fp, "gr%u", reg->index);
86 else
87 fprintf(fp, "r%u", reg->index);
88 }
89
90 static const char *sizes[] = { "error", "vec1", "vec2", "vec3", "vec4",
91 "error", "error", "error", "vec8",
92 "error", "error", "error", "error",
93 "error", "error", "error", "vec16"};
94
95 static void
96 print_register_decl(nir_register *reg, print_state *state)
97 {
98 FILE *fp = state->fp;
99 fprintf(fp, "decl_reg %s %u ", sizes[reg->num_components], reg->bit_size);
100 if (reg->is_packed)
101 fprintf(fp, "(packed) ");
102 print_register(reg, state);
103 if (reg->num_array_elems != 0)
104 fprintf(fp, "[%u]", reg->num_array_elems);
105 fprintf(fp, "\n");
106 }
107
108 static void
109 print_ssa_def(nir_ssa_def *def, print_state *state)
110 {
111 FILE *fp = state->fp;
112 if (def->name != NULL)
113 fprintf(fp, "/* %s */ ", def->name);
114 fprintf(fp, "%s %u ssa_%u", sizes[def->num_components], def->bit_size,
115 def->index);
116 }
117
118 static void
119 print_ssa_use(nir_ssa_def *def, print_state *state)
120 {
121 FILE *fp = state->fp;
122 if (def->name != NULL)
123 fprintf(fp, "/* %s */ ", def->name);
124 fprintf(fp, "ssa_%u", def->index);
125 }
126
127 static void print_src(const nir_src *src, print_state *state);
128
129 static void
130 print_reg_src(const nir_reg_src *src, print_state *state)
131 {
132 FILE *fp = state->fp;
133 print_register(src->reg, state);
134 if (src->reg->num_array_elems != 0) {
135 fprintf(fp, "[%u", src->base_offset);
136 if (src->indirect != NULL) {
137 fprintf(fp, " + ");
138 print_src(src->indirect, state);
139 }
140 fprintf(fp, "]");
141 }
142 }
143
144 static void
145 print_reg_dest(nir_reg_dest *dest, print_state *state)
146 {
147 FILE *fp = state->fp;
148 print_register(dest->reg, state);
149 if (dest->reg->num_array_elems != 0) {
150 fprintf(fp, "[%u", dest->base_offset);
151 if (dest->indirect != NULL) {
152 fprintf(fp, " + ");
153 print_src(dest->indirect, state);
154 }
155 fprintf(fp, "]");
156 }
157 }
158
159 static void
160 print_src(const nir_src *src, print_state *state)
161 {
162 if (src->is_ssa)
163 print_ssa_use(src->ssa, state);
164 else
165 print_reg_src(&src->reg, state);
166 }
167
168 static void
169 print_dest(nir_dest *dest, print_state *state)
170 {
171 if (dest->is_ssa)
172 print_ssa_def(&dest->ssa, state);
173 else
174 print_reg_dest(&dest->reg, state);
175 }
176
177 static void
178 print_alu_src(nir_alu_instr *instr, unsigned src, print_state *state)
179 {
180 FILE *fp = state->fp;
181
182 if (instr->src[src].negate)
183 fprintf(fp, "-");
184 if (instr->src[src].abs)
185 fprintf(fp, "abs(");
186
187 print_src(&instr->src[src].src, state);
188
189 bool print_swizzle = false;
190 nir_component_mask_t used_channels = 0;
191
192 for (unsigned i = 0; i < NIR_MAX_VEC_COMPONENTS; i++) {
193 if (!nir_alu_instr_channel_used(instr, src, i))
194 continue;
195
196 used_channels++;
197
198 if (instr->src[src].swizzle[i] != i) {
199 print_swizzle = true;
200 break;
201 }
202 }
203
204 unsigned live_channels = nir_src_num_components(instr->src[src].src);
205
206 if (print_swizzle || used_channels != live_channels) {
207 fprintf(fp, ".");
208 for (unsigned i = 0; i < NIR_MAX_VEC_COMPONENTS; i++) {
209 if (!nir_alu_instr_channel_used(instr, src, i))
210 continue;
211
212 fprintf(fp, "%c", "xyzw"[instr->src[src].swizzle[i]]);
213 }
214 }
215
216 if (instr->src[src].abs)
217 fprintf(fp, ")");
218 }
219
220 static void
221 print_alu_dest(nir_alu_dest *dest, print_state *state)
222 {
223 FILE *fp = state->fp;
224 /* we're going to print the saturate modifier later, after the opcode */
225
226 print_dest(&dest->dest, state);
227
228 if (!dest->dest.is_ssa &&
229 dest->write_mask != (1 << dest->dest.reg.reg->num_components) - 1) {
230 fprintf(fp, ".");
231 for (unsigned i = 0; i < NIR_MAX_VEC_COMPONENTS; i++)
232 if ((dest->write_mask >> i) & 1)
233 fprintf(fp, "%c", "xyzw"[i]);
234 }
235 }
236
237 static void
238 print_alu_instr(nir_alu_instr *instr, print_state *state)
239 {
240 FILE *fp = state->fp;
241
242 print_alu_dest(&instr->dest, state);
243
244 fprintf(fp, " = %s", nir_op_infos[instr->op].name);
245 if (instr->exact)
246 fprintf(fp, "!");
247 if (instr->dest.saturate)
248 fprintf(fp, ".sat");
249 fprintf(fp, " ");
250
251 for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++) {
252 if (i != 0)
253 fprintf(fp, ", ");
254
255 print_alu_src(instr, i, state);
256 }
257 }
258
259 static const char *
260 get_var_name(nir_variable *var, print_state *state)
261 {
262 if (state->ht == NULL)
263 return var->name ? var->name : "unnamed";
264
265 assert(state->syms);
266
267 struct hash_entry *entry = _mesa_hash_table_search(state->ht, var);
268 if (entry)
269 return entry->data;
270
271 char *name;
272 if (var->name == NULL) {
273 name = ralloc_asprintf(state->syms, "@%u", state->index++);
274 } else {
275 struct set_entry *set_entry = _mesa_set_search(state->syms, var->name);
276 if (set_entry != NULL) {
277 /* we have a collision with another name, append an @ + a unique
278 * index */
279 name = ralloc_asprintf(state->syms, "%s@%u", var->name,
280 state->index++);
281 } else {
282 /* Mark this one as seen */
283 _mesa_set_add(state->syms, var->name);
284 name = var->name;
285 }
286 }
287
288 _mesa_hash_table_insert(state->ht, var, name);
289
290 return name;
291 }
292
293 static void
294 print_constant(nir_constant *c, const struct glsl_type *type, print_state *state)
295 {
296 FILE *fp = state->fp;
297 const unsigned rows = glsl_get_vector_elements(type);
298 const unsigned cols = glsl_get_matrix_columns(type);
299 unsigned i, j;
300
301 switch (glsl_get_base_type(type)) {
302 case GLSL_TYPE_BOOL:
303 /* Only float base types can be matrices. */
304 assert(cols == 1);
305
306 for (i = 0; i < rows; i++) {
307 if (i > 0) fprintf(fp, ", ");
308 fprintf(fp, "%s", c->values[0].b[i] ? "true" : "false");
309 }
310 break;
311
312 case GLSL_TYPE_UINT8:
313 case GLSL_TYPE_INT8:
314 /* Only float base types can be matrices. */
315 assert(cols == 1);
316
317 for (i = 0; i < rows; i++) {
318 if (i > 0) fprintf(fp, ", ");
319 fprintf(fp, "0x%02x", c->values[0].u8[i]);
320 }
321 break;
322
323 case GLSL_TYPE_UINT16:
324 case GLSL_TYPE_INT16:
325 /* Only float base types can be matrices. */
326 assert(cols == 1);
327
328 for (i = 0; i < rows; i++) {
329 if (i > 0) fprintf(fp, ", ");
330 fprintf(fp, "0x%04x", c->values[0].u16[i]);
331 }
332 break;
333
334 case GLSL_TYPE_UINT:
335 case GLSL_TYPE_INT:
336 /* Only float base types can be matrices. */
337 assert(cols == 1);
338
339 for (i = 0; i < rows; i++) {
340 if (i > 0) fprintf(fp, ", ");
341 fprintf(fp, "0x%08x", c->values[0].u32[i]);
342 }
343 break;
344
345 case GLSL_TYPE_FLOAT16:
346 for (i = 0; i < cols; i++) {
347 for (j = 0; j < rows; j++) {
348 if (i + j > 0) fprintf(fp, ", ");
349 fprintf(fp, "%f", _mesa_half_to_float(c->values[i].u16[j]));
350 }
351 }
352 break;
353
354 case GLSL_TYPE_FLOAT:
355 for (i = 0; i < cols; i++) {
356 for (j = 0; j < rows; j++) {
357 if (i + j > 0) fprintf(fp, ", ");
358 fprintf(fp, "%f", c->values[i].f32[j]);
359 }
360 }
361 break;
362
363 case GLSL_TYPE_DOUBLE:
364 for (i = 0; i < cols; i++) {
365 for (j = 0; j < rows; j++) {
366 if (i + j > 0) fprintf(fp, ", ");
367 fprintf(fp, "%f", c->values[i].f64[j]);
368 }
369 }
370 break;
371
372 case GLSL_TYPE_UINT64:
373 case GLSL_TYPE_INT64:
374 /* Only float base types can be matrices. */
375 assert(cols == 1);
376
377 for (i = 0; i < cols; i++) {
378 if (i > 0) fprintf(fp, ", ");
379 fprintf(fp, "0x%08" PRIx64, c->values[0].u64[i]);
380 }
381 break;
382
383 case GLSL_TYPE_STRUCT:
384 for (i = 0; i < c->num_elements; i++) {
385 if (i > 0) fprintf(fp, ", ");
386 fprintf(fp, "{ ");
387 print_constant(c->elements[i], glsl_get_struct_field(type, i), state);
388 fprintf(fp, " }");
389 }
390 break;
391
392 case GLSL_TYPE_ARRAY:
393 for (i = 0; i < c->num_elements; i++) {
394 if (i > 0) fprintf(fp, ", ");
395 fprintf(fp, "{ ");
396 print_constant(c->elements[i], glsl_get_array_element(type), state);
397 fprintf(fp, " }");
398 }
399 break;
400
401 default:
402 unreachable("not reached");
403 }
404 }
405
406 static const char *
407 get_variable_mode_str(nir_variable_mode mode, bool want_local_global_mode)
408 {
409 switch (mode) {
410 case nir_var_shader_in:
411 return "shader_in";
412 case nir_var_shader_out:
413 return "shader_out";
414 case nir_var_uniform:
415 return "uniform";
416 case nir_var_ubo:
417 return "ubo";
418 case nir_var_system_value:
419 return "system";
420 case nir_var_ssbo:
421 return "ssbo";
422 case nir_var_shared:
423 return "shared";
424 case nir_var_private:
425 return want_local_global_mode ? "private" : "";
426 case nir_var_function:
427 return want_local_global_mode ? "function" : "";
428 default:
429 return "";
430 }
431 }
432
433 static void
434 print_var_decl(nir_variable *var, print_state *state)
435 {
436 FILE *fp = state->fp;
437
438 fprintf(fp, "decl_var ");
439
440 const char *const cent = (var->data.centroid) ? "centroid " : "";
441 const char *const samp = (var->data.sample) ? "sample " : "";
442 const char *const patch = (var->data.patch) ? "patch " : "";
443 const char *const inv = (var->data.invariant) ? "invariant " : "";
444 fprintf(fp, "%s%s%s%s%s %s ",
445 cent, samp, patch, inv, get_variable_mode_str(var->data.mode, false),
446 glsl_interp_mode_name(var->data.interpolation));
447
448 enum gl_access_qualifier access = var->data.image.access;
449 const char *const coher = (access & ACCESS_COHERENT) ? "coherent " : "";
450 const char *const volat = (access & ACCESS_VOLATILE) ? "volatile " : "";
451 const char *const restr = (access & ACCESS_RESTRICT) ? "restrict " : "";
452 const char *const ronly = (access & ACCESS_NON_WRITEABLE) ? "readonly " : "";
453 const char *const wonly = (access & ACCESS_NON_READABLE) ? "writeonly " : "";
454 fprintf(fp, "%s%s%s%s%s", coher, volat, restr, ronly, wonly);
455
456 #define FORMAT_CASE(x) case x: fprintf(stderr, #x " "); break
457 switch (var->data.image.format) {
458 FORMAT_CASE(GL_RGBA32F);
459 FORMAT_CASE(GL_RGBA32UI);
460 FORMAT_CASE(GL_RGBA32I);
461 FORMAT_CASE(GL_R32F);
462 FORMAT_CASE(GL_R32UI);
463 FORMAT_CASE(GL_R32I);
464 FORMAT_CASE(GL_RG32F);
465 FORMAT_CASE(GL_RG32UI);
466 FORMAT_CASE(GL_RG32I);
467 FORMAT_CASE(GL_R8);
468 FORMAT_CASE(GL_RG8);
469 FORMAT_CASE(GL_RGBA8);
470 FORMAT_CASE(GL_R8_SNORM);
471 FORMAT_CASE(GL_RG8_SNORM);
472 FORMAT_CASE(GL_RGBA8_SNORM);
473 FORMAT_CASE(GL_R16);
474 FORMAT_CASE(GL_RG16);
475 FORMAT_CASE(GL_RGBA16);
476 FORMAT_CASE(GL_R16_SNORM);
477 FORMAT_CASE(GL_RG16_SNORM);
478 FORMAT_CASE(GL_RGBA16_SNORM);
479 FORMAT_CASE(GL_R16F);
480 FORMAT_CASE(GL_RG16F);
481 FORMAT_CASE(GL_RGBA16F);
482 FORMAT_CASE(GL_R8UI);
483 FORMAT_CASE(GL_R8I);
484 FORMAT_CASE(GL_RG8UI);
485 FORMAT_CASE(GL_RG8I);
486 FORMAT_CASE(GL_RGBA8UI);
487 FORMAT_CASE(GL_RGBA8I);
488 FORMAT_CASE(GL_R16UI);
489 FORMAT_CASE(GL_R16I);
490 FORMAT_CASE(GL_RG16UI);
491 FORMAT_CASE(GL_RG16I);
492 FORMAT_CASE(GL_RGBA16UI);
493 FORMAT_CASE(GL_RGBA16I);
494 FORMAT_CASE(GL_R11F_G11F_B10F);
495 FORMAT_CASE(GL_RGB9_E5);
496 FORMAT_CASE(GL_RGB10_A2);
497 FORMAT_CASE(GL_RGB10_A2UI);
498 default: /* Including the normal GL_NONE */
499 break;
500 }
501 #undef FORMAT_CASE
502
503 fprintf(fp, "%s %s", glsl_get_type_name(var->type),
504 get_var_name(var, state));
505
506 if (var->data.mode == nir_var_shader_in ||
507 var->data.mode == nir_var_shader_out ||
508 var->data.mode == nir_var_uniform ||
509 var->data.mode == nir_var_ubo ||
510 var->data.mode == nir_var_ssbo) {
511 const char *loc = NULL;
512 char buf[4];
513
514 switch (state->shader->info.stage) {
515 case MESA_SHADER_VERTEX:
516 if (var->data.mode == nir_var_shader_in)
517 loc = gl_vert_attrib_name(var->data.location);
518 else if (var->data.mode == nir_var_shader_out)
519 loc = gl_varying_slot_name(var->data.location);
520 break;
521 case MESA_SHADER_GEOMETRY:
522 if ((var->data.mode == nir_var_shader_in) ||
523 (var->data.mode == nir_var_shader_out))
524 loc = gl_varying_slot_name(var->data.location);
525 break;
526 case MESA_SHADER_FRAGMENT:
527 if (var->data.mode == nir_var_shader_in)
528 loc = gl_varying_slot_name(var->data.location);
529 else if (var->data.mode == nir_var_shader_out)
530 loc = gl_frag_result_name(var->data.location);
531 break;
532 case MESA_SHADER_TESS_CTRL:
533 case MESA_SHADER_TESS_EVAL:
534 case MESA_SHADER_COMPUTE:
535 default:
536 /* TODO */
537 break;
538 }
539
540 if (!loc) {
541 snprintf(buf, sizeof(buf), "%u", var->data.location);
542 loc = buf;
543 }
544
545 /* For shader I/O vars that have been split to components or packed,
546 * print the fractional location within the input/output.
547 */
548 unsigned int num_components =
549 glsl_get_components(glsl_without_array(var->type));
550 const char *components = NULL;
551 char components_local[6] = {'.' /* the rest is 0-filled */};
552 switch (var->data.mode) {
553 case nir_var_shader_in:
554 case nir_var_shader_out:
555 if (num_components < 4 && num_components != 0) {
556 const char *xyzw = "xyzw";
557 for (int i = 0; i < num_components; i++)
558 components_local[i + 1] = xyzw[i + var->data.location_frac];
559
560 components = components_local;
561 }
562 break;
563 default:
564 break;
565 }
566
567 fprintf(fp, " (%s%s, %u, %u)%s", loc,
568 components ? components : "",
569 var->data.driver_location, var->data.binding,
570 var->data.compact ? " compact" : "");
571 }
572
573 if (var->constant_initializer) {
574 fprintf(fp, " = { ");
575 print_constant(var->constant_initializer, var->type, state);
576 fprintf(fp, " }");
577 }
578
579 fprintf(fp, "\n");
580 print_annotation(state, var);
581 }
582
583 static void
584 print_deref_link(const nir_deref_instr *instr, bool whole_chain, print_state *state)
585 {
586 FILE *fp = state->fp;
587
588 if (instr->deref_type == nir_deref_type_var) {
589 fprintf(fp, "%s", get_var_name(instr->var, state));
590 return;
591 } else if (instr->deref_type == nir_deref_type_cast) {
592 fprintf(fp, "(%s *)", glsl_get_type_name(instr->type));
593 print_src(&instr->parent, state);
594 return;
595 }
596
597 assert(instr->parent.is_ssa);
598 nir_deref_instr *parent =
599 nir_instr_as_deref(instr->parent.ssa->parent_instr);
600
601 /* Is the parent we're going to print a bare cast? */
602 const bool is_parent_cast =
603 whole_chain && parent->deref_type == nir_deref_type_cast;
604
605 /* If we're not printing the whole chain, the parent we print will be a SSA
606 * value that represents a pointer. The only deref type that naturally
607 * gives a pointer is a cast.
608 */
609 const bool is_parent_pointer =
610 !whole_chain || parent->deref_type == nir_deref_type_cast;
611
612 /* Struct derefs have a nice syntax that works on pointers, arrays derefs
613 * do not.
614 */
615 const bool need_deref =
616 is_parent_pointer && instr->deref_type != nir_deref_type_struct;
617
618 /* Cast need extra parens and so * dereferences */
619 if (is_parent_cast || need_deref)
620 fprintf(fp, "(");
621
622 if (need_deref)
623 fprintf(fp, "*");
624
625 if (whole_chain) {
626 print_deref_link(parent, whole_chain, state);
627 } else {
628 print_src(&instr->parent, state);
629 }
630
631 if (is_parent_cast || need_deref)
632 fprintf(fp, ")");
633
634 switch (instr->deref_type) {
635 case nir_deref_type_struct:
636 fprintf(fp, "%s%s", is_parent_pointer ? "->" : ".",
637 glsl_get_struct_elem_name(parent->type, instr->strct.index));
638 break;
639
640 case nir_deref_type_array:
641 case nir_deref_type_ptr_as_array: {
642 nir_const_value *const_index = nir_src_as_const_value(instr->arr.index);
643 if (const_index) {
644 fprintf(fp, "[%u]", const_index->u32[0]);
645 } else {
646 fprintf(fp, "[");
647 print_src(&instr->arr.index, state);
648 fprintf(fp, "]");
649 }
650 break;
651 }
652
653 case nir_deref_type_array_wildcard:
654 fprintf(fp, "[*]");
655 break;
656
657 default:
658 unreachable("Invalid deref instruction type");
659 }
660 }
661
662 static void
663 print_deref_instr(nir_deref_instr *instr, print_state *state)
664 {
665 FILE *fp = state->fp;
666
667 print_dest(&instr->dest, state);
668
669 switch (instr->deref_type) {
670 case nir_deref_type_var:
671 fprintf(fp, " = deref_var ");
672 break;
673 case nir_deref_type_array:
674 case nir_deref_type_array_wildcard:
675 fprintf(fp, " = deref_array ");
676 break;
677 case nir_deref_type_struct:
678 fprintf(fp, " = deref_struct ");
679 break;
680 case nir_deref_type_cast:
681 fprintf(fp, " = deref_cast ");
682 break;
683 case nir_deref_type_ptr_as_array:
684 fprintf(fp, " = deref_ptr_as_array ");
685 break;
686 default:
687 unreachable("Invalid deref instruction type");
688 }
689
690 /* Only casts naturally return a pointer type */
691 if (instr->deref_type != nir_deref_type_cast)
692 fprintf(fp, "&");
693
694 print_deref_link(instr, false, state);
695
696 fprintf(fp, " (%s %s) ",
697 get_variable_mode_str(instr->mode, true),
698 glsl_get_type_name(instr->type));
699
700 if (instr->deref_type != nir_deref_type_var &&
701 instr->deref_type != nir_deref_type_cast) {
702 /* Print the entire chain as a comment */
703 fprintf(fp, "/* &");
704 print_deref_link(instr, true, state);
705 fprintf(fp, " */");
706 }
707 }
708
709 static const char *
710 vulkan_descriptor_type_name(VkDescriptorType type)
711 {
712 switch (type) {
713 case VK_DESCRIPTOR_TYPE_SAMPLER: return "sampler";
714 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: return "texture+sampler";
715 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: return "texture";
716 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: return "image";
717 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: return "texture-buffer";
718 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: return "image-buffer";
719 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: return "UBO";
720 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: return "SSBO";
721 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: return "UBO";
722 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: return "SSBO";
723 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: return "input-att";
724 case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT: return "inline-UBO";
725 default: return "unknown";
726 }
727 }
728
729 static void
730 print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state)
731 {
732 const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];
733 unsigned num_srcs = info->num_srcs;
734 FILE *fp = state->fp;
735
736 if (info->has_dest) {
737 print_dest(&instr->dest, state);
738 fprintf(fp, " = ");
739 }
740
741 fprintf(fp, "intrinsic %s (", info->name);
742
743 for (unsigned i = 0; i < num_srcs; i++) {
744 if (i != 0)
745 fprintf(fp, ", ");
746
747 print_src(&instr->src[i], state);
748 }
749
750 fprintf(fp, ") (");
751
752 for (unsigned i = 0; i < info->num_indices; i++) {
753 if (i != 0)
754 fprintf(fp, ", ");
755
756 fprintf(fp, "%d", instr->const_index[i]);
757 }
758
759 fprintf(fp, ")");
760
761 static const char *index_name[NIR_INTRINSIC_NUM_INDEX_FLAGS] = {
762 [NIR_INTRINSIC_BASE] = "base",
763 [NIR_INTRINSIC_WRMASK] = "wrmask",
764 [NIR_INTRINSIC_STREAM_ID] = "stream-id",
765 [NIR_INTRINSIC_UCP_ID] = "ucp-id",
766 [NIR_INTRINSIC_RANGE] = "range",
767 [NIR_INTRINSIC_DESC_SET] = "desc-set",
768 [NIR_INTRINSIC_BINDING] = "binding",
769 [NIR_INTRINSIC_COMPONENT] = "component",
770 [NIR_INTRINSIC_INTERP_MODE] = "interp_mode",
771 [NIR_INTRINSIC_REDUCTION_OP] = "reduction_op",
772 [NIR_INTRINSIC_CLUSTER_SIZE] = "cluster_size",
773 [NIR_INTRINSIC_PARAM_IDX] = "param_idx",
774 [NIR_INTRINSIC_IMAGE_DIM] = "image_dim",
775 [NIR_INTRINSIC_IMAGE_ARRAY] = "image_array",
776 [NIR_INTRINSIC_ACCESS] = "access",
777 [NIR_INTRINSIC_FORMAT] = "format",
778 [NIR_INTRINSIC_ALIGN_MUL] = "align_mul",
779 [NIR_INTRINSIC_ALIGN_OFFSET] = "align_offset",
780 [NIR_INTRINSIC_DESC_TYPE] = "desc_type",
781 };
782 for (unsigned idx = 1; idx < NIR_INTRINSIC_NUM_INDEX_FLAGS; idx++) {
783 if (!info->index_map[idx])
784 continue;
785 fprintf(fp, " /*");
786 if (idx == NIR_INTRINSIC_WRMASK) {
787 /* special case wrmask to show it as a writemask.. */
788 unsigned wrmask = nir_intrinsic_write_mask(instr);
789 fprintf(fp, " wrmask=");
790 for (unsigned i = 0; i < 4; i++)
791 if ((wrmask >> i) & 1)
792 fprintf(fp, "%c", "xyzw"[i]);
793 } else if (idx == NIR_INTRINSIC_REDUCTION_OP) {
794 nir_op reduction_op = nir_intrinsic_reduction_op(instr);
795 fprintf(fp, " reduction_op=%s", nir_op_infos[reduction_op].name);
796 } else if (idx == NIR_INTRINSIC_IMAGE_DIM) {
797 static const char *dim_name[] = {
798 [GLSL_SAMPLER_DIM_1D] = "1D",
799 [GLSL_SAMPLER_DIM_2D] = "2D",
800 [GLSL_SAMPLER_DIM_3D] = "3D",
801 [GLSL_SAMPLER_DIM_CUBE] = "Cube",
802 [GLSL_SAMPLER_DIM_RECT] = "Rect",
803 [GLSL_SAMPLER_DIM_BUF] = "Buf",
804 [GLSL_SAMPLER_DIM_MS] = "2D-MSAA",
805 [GLSL_SAMPLER_DIM_SUBPASS] = "Subpass",
806 [GLSL_SAMPLER_DIM_SUBPASS_MS] = "Subpass-MSAA",
807 };
808 enum glsl_sampler_dim dim = nir_intrinsic_image_dim(instr);
809 assert(dim < ARRAY_SIZE(dim_name) && dim_name[dim]);
810 fprintf(fp, " image_dim=%s", dim_name[dim]);
811 } else if (idx == NIR_INTRINSIC_IMAGE_ARRAY) {
812 bool array = nir_intrinsic_image_dim(instr);
813 fprintf(fp, " image_dim=%s", array ? "true" : "false");
814 } else if (idx == NIR_INTRINSIC_DESC_TYPE) {
815 VkDescriptorType desc_type = nir_intrinsic_desc_type(instr);
816 fprintf(fp, " desc_type=%s", vulkan_descriptor_type_name(desc_type));
817 } else {
818 unsigned off = info->index_map[idx] - 1;
819 assert(index_name[idx]); /* forgot to update index_name table? */
820 fprintf(fp, " %s=%d", index_name[idx], instr->const_index[off]);
821 }
822 fprintf(fp, " */");
823 }
824
825 if (!state->shader)
826 return;
827
828 struct exec_list *var_list = NULL;
829
830 switch (instr->intrinsic) {
831 case nir_intrinsic_load_uniform:
832 var_list = &state->shader->uniforms;
833 break;
834 case nir_intrinsic_load_input:
835 case nir_intrinsic_load_per_vertex_input:
836 var_list = &state->shader->inputs;
837 break;
838 case nir_intrinsic_load_output:
839 case nir_intrinsic_store_output:
840 case nir_intrinsic_store_per_vertex_output:
841 var_list = &state->shader->outputs;
842 break;
843 default:
844 return;
845 }
846
847 nir_foreach_variable(var, var_list) {
848 if ((var->data.driver_location == nir_intrinsic_base(instr)) &&
849 (instr->intrinsic == nir_intrinsic_load_uniform ||
850 var->data.location_frac == nir_intrinsic_component(instr)) &&
851 var->name) {
852 fprintf(fp, "\t/* %s */", var->name);
853 break;
854 }
855 }
856 }
857
858 static void
859 print_tex_instr(nir_tex_instr *instr, print_state *state)
860 {
861 FILE *fp = state->fp;
862
863 print_dest(&instr->dest, state);
864
865 fprintf(fp, " = ");
866
867 switch (instr->op) {
868 case nir_texop_tex:
869 fprintf(fp, "tex ");
870 break;
871 case nir_texop_txb:
872 fprintf(fp, "txb ");
873 break;
874 case nir_texop_txl:
875 fprintf(fp, "txl ");
876 break;
877 case nir_texop_txd:
878 fprintf(fp, "txd ");
879 break;
880 case nir_texop_txf:
881 fprintf(fp, "txf ");
882 break;
883 case nir_texop_txf_ms:
884 fprintf(fp, "txf_ms ");
885 break;
886 case nir_texop_txf_ms_mcs:
887 fprintf(fp, "txf_ms_mcs ");
888 break;
889 case nir_texop_txs:
890 fprintf(fp, "txs ");
891 break;
892 case nir_texop_lod:
893 fprintf(fp, "lod ");
894 break;
895 case nir_texop_tg4:
896 fprintf(fp, "tg4 ");
897 break;
898 case nir_texop_query_levels:
899 fprintf(fp, "query_levels ");
900 break;
901 case nir_texop_texture_samples:
902 fprintf(fp, "texture_samples ");
903 break;
904 case nir_texop_samples_identical:
905 fprintf(fp, "samples_identical ");
906 break;
907 default:
908 unreachable("Invalid texture operation");
909 break;
910 }
911
912 bool has_texture_deref = false, has_sampler_deref = false;
913 for (unsigned i = 0; i < instr->num_srcs; i++) {
914 print_src(&instr->src[i].src, state);
915
916 fprintf(fp, " ");
917
918 switch(instr->src[i].src_type) {
919 case nir_tex_src_coord:
920 fprintf(fp, "(coord)");
921 break;
922 case nir_tex_src_projector:
923 fprintf(fp, "(projector)");
924 break;
925 case nir_tex_src_comparator:
926 fprintf(fp, "(comparator)");
927 break;
928 case nir_tex_src_offset:
929 fprintf(fp, "(offset)");
930 break;
931 case nir_tex_src_bias:
932 fprintf(fp, "(bias)");
933 break;
934 case nir_tex_src_lod:
935 fprintf(fp, "(lod)");
936 break;
937 case nir_tex_src_min_lod:
938 fprintf(fp, "(min_lod)");
939 break;
940 case nir_tex_src_ms_index:
941 fprintf(fp, "(ms_index)");
942 break;
943 case nir_tex_src_ms_mcs:
944 fprintf(fp, "(ms_mcs)");
945 break;
946 case nir_tex_src_ddx:
947 fprintf(fp, "(ddx)");
948 break;
949 case nir_tex_src_ddy:
950 fprintf(fp, "(ddy)");
951 break;
952 case nir_tex_src_texture_deref:
953 has_texture_deref = true;
954 fprintf(fp, "(texture_deref)");
955 break;
956 case nir_tex_src_sampler_deref:
957 has_sampler_deref = true;
958 fprintf(fp, "(sampler_deref)");
959 break;
960 case nir_tex_src_texture_offset:
961 fprintf(fp, "(texture_offset)");
962 break;
963 case nir_tex_src_sampler_offset:
964 fprintf(fp, "(sampler_offset)");
965 break;
966 case nir_tex_src_plane:
967 fprintf(fp, "(plane)");
968 break;
969
970 default:
971 unreachable("Invalid texture source type");
972 break;
973 }
974
975 fprintf(fp, ", ");
976 }
977
978 if (instr->op == nir_texop_tg4) {
979 fprintf(fp, "%u (gather_component), ", instr->component);
980 }
981
982 if (!has_texture_deref) {
983 fprintf(fp, "%u (texture), ", instr->texture_index);
984 }
985
986 if (!has_sampler_deref) {
987 fprintf(fp, "%u (sampler), ", instr->sampler_index);
988 }
989 }
990
991 static void
992 print_call_instr(nir_call_instr *instr, print_state *state)
993 {
994 FILE *fp = state->fp;
995
996 fprintf(fp, "call %s ", instr->callee->name);
997
998 for (unsigned i = 0; i < instr->num_params; i++) {
999 if (i != 0)
1000 fprintf(fp, ", ");
1001
1002 print_src(&instr->params[i], state);
1003 }
1004 }
1005
1006 static void
1007 print_load_const_instr(nir_load_const_instr *instr, print_state *state)
1008 {
1009 FILE *fp = state->fp;
1010
1011 print_ssa_def(&instr->def, state);
1012
1013 fprintf(fp, " = load_const (");
1014
1015 for (unsigned i = 0; i < instr->def.num_components; i++) {
1016 if (i != 0)
1017 fprintf(fp, ", ");
1018
1019 /*
1020 * we don't really know the type of the constant (if it will be used as a
1021 * float or an int), so just print the raw constant in hex for fidelity
1022 * and then print the float in a comment for readability.
1023 */
1024
1025 switch (instr->def.bit_size) {
1026 case 64:
1027 fprintf(fp, "0x%16" PRIx64 " /* %f */", instr->value.u64[i],
1028 instr->value.f64[i]);
1029 break;
1030 case 32:
1031 fprintf(fp, "0x%08x /* %f */", instr->value.u32[i], instr->value.f32[i]);
1032 break;
1033 case 16:
1034 fprintf(fp, "0x%04x /* %f */", instr->value.u16[i],
1035 _mesa_half_to_float(instr->value.u16[i]));
1036 break;
1037 case 8:
1038 fprintf(fp, "0x%02x", instr->value.u8[i]);
1039 break;
1040 case 1:
1041 fprintf(fp, "%s", instr->value.b[i] ? "true" : "false");
1042 break;
1043 }
1044 }
1045
1046 fprintf(fp, ")");
1047 }
1048
1049 static void
1050 print_jump_instr(nir_jump_instr *instr, print_state *state)
1051 {
1052 FILE *fp = state->fp;
1053
1054 switch (instr->type) {
1055 case nir_jump_break:
1056 fprintf(fp, "break");
1057 break;
1058
1059 case nir_jump_continue:
1060 fprintf(fp, "continue");
1061 break;
1062
1063 case nir_jump_return:
1064 fprintf(fp, "return");
1065 break;
1066 }
1067 }
1068
1069 static void
1070 print_ssa_undef_instr(nir_ssa_undef_instr* instr, print_state *state)
1071 {
1072 FILE *fp = state->fp;
1073 print_ssa_def(&instr->def, state);
1074 fprintf(fp, " = undefined");
1075 }
1076
1077 static void
1078 print_phi_instr(nir_phi_instr *instr, print_state *state)
1079 {
1080 FILE *fp = state->fp;
1081 print_dest(&instr->dest, state);
1082 fprintf(fp, " = phi ");
1083 nir_foreach_phi_src(src, instr) {
1084 if (&src->node != exec_list_get_head(&instr->srcs))
1085 fprintf(fp, ", ");
1086
1087 fprintf(fp, "block_%u: ", src->pred->index);
1088 print_src(&src->src, state);
1089 }
1090 }
1091
1092 static void
1093 print_parallel_copy_instr(nir_parallel_copy_instr *instr, print_state *state)
1094 {
1095 FILE *fp = state->fp;
1096 nir_foreach_parallel_copy_entry(entry, instr) {
1097 if (&entry->node != exec_list_get_head(&instr->entries))
1098 fprintf(fp, "; ");
1099
1100 print_dest(&entry->dest, state);
1101 fprintf(fp, " = ");
1102 print_src(&entry->src, state);
1103 }
1104 }
1105
1106 static void
1107 print_instr(const nir_instr *instr, print_state *state, unsigned tabs)
1108 {
1109 FILE *fp = state->fp;
1110 print_tabs(tabs, fp);
1111
1112 switch (instr->type) {
1113 case nir_instr_type_alu:
1114 print_alu_instr(nir_instr_as_alu(instr), state);
1115 break;
1116
1117 case nir_instr_type_deref:
1118 print_deref_instr(nir_instr_as_deref(instr), state);
1119 break;
1120
1121 case nir_instr_type_call:
1122 print_call_instr(nir_instr_as_call(instr), state);
1123 break;
1124
1125 case nir_instr_type_intrinsic:
1126 print_intrinsic_instr(nir_instr_as_intrinsic(instr), state);
1127 break;
1128
1129 case nir_instr_type_tex:
1130 print_tex_instr(nir_instr_as_tex(instr), state);
1131 break;
1132
1133 case nir_instr_type_load_const:
1134 print_load_const_instr(nir_instr_as_load_const(instr), state);
1135 break;
1136
1137 case nir_instr_type_jump:
1138 print_jump_instr(nir_instr_as_jump(instr), state);
1139 break;
1140
1141 case nir_instr_type_ssa_undef:
1142 print_ssa_undef_instr(nir_instr_as_ssa_undef(instr), state);
1143 break;
1144
1145 case nir_instr_type_phi:
1146 print_phi_instr(nir_instr_as_phi(instr), state);
1147 break;
1148
1149 case nir_instr_type_parallel_copy:
1150 print_parallel_copy_instr(nir_instr_as_parallel_copy(instr), state);
1151 break;
1152
1153 default:
1154 unreachable("Invalid instruction type");
1155 break;
1156 }
1157 }
1158
1159 static int
1160 compare_block_index(const void *p1, const void *p2)
1161 {
1162 const nir_block *block1 = *((const nir_block **) p1);
1163 const nir_block *block2 = *((const nir_block **) p2);
1164
1165 return (int) block1->index - (int) block2->index;
1166 }
1167
1168 static void print_cf_node(nir_cf_node *node, print_state *state,
1169 unsigned tabs);
1170
1171 static void
1172 print_block(nir_block *block, print_state *state, unsigned tabs)
1173 {
1174 FILE *fp = state->fp;
1175
1176 print_tabs(tabs, fp);
1177 fprintf(fp, "block block_%u:\n", block->index);
1178
1179 /* sort the predecessors by index so we consistently print the same thing */
1180
1181 nir_block **preds =
1182 malloc(block->predecessors->entries * sizeof(nir_block *));
1183
1184 unsigned i = 0;
1185 set_foreach(block->predecessors, entry) {
1186 preds[i++] = (nir_block *) entry->key;
1187 }
1188
1189 qsort(preds, block->predecessors->entries, sizeof(nir_block *),
1190 compare_block_index);
1191
1192 print_tabs(tabs, fp);
1193 fprintf(fp, "/* preds: ");
1194 for (unsigned i = 0; i < block->predecessors->entries; i++) {
1195 fprintf(fp, "block_%u ", preds[i]->index);
1196 }
1197 fprintf(fp, "*/\n");
1198
1199 free(preds);
1200
1201 nir_foreach_instr(instr, block) {
1202 print_instr(instr, state, tabs);
1203 fprintf(fp, "\n");
1204 print_annotation(state, instr);
1205 }
1206
1207 print_tabs(tabs, fp);
1208 fprintf(fp, "/* succs: ");
1209 for (unsigned i = 0; i < 2; i++)
1210 if (block->successors[i]) {
1211 fprintf(fp, "block_%u ", block->successors[i]->index);
1212 }
1213 fprintf(fp, "*/\n");
1214 }
1215
1216 static void
1217 print_if(nir_if *if_stmt, print_state *state, unsigned tabs)
1218 {
1219 FILE *fp = state->fp;
1220
1221 print_tabs(tabs, fp);
1222 fprintf(fp, "if ");
1223 print_src(&if_stmt->condition, state);
1224 fprintf(fp, " {\n");
1225 foreach_list_typed(nir_cf_node, node, node, &if_stmt->then_list) {
1226 print_cf_node(node, state, tabs + 1);
1227 }
1228 print_tabs(tabs, fp);
1229 fprintf(fp, "} else {\n");
1230 foreach_list_typed(nir_cf_node, node, node, &if_stmt->else_list) {
1231 print_cf_node(node, state, tabs + 1);
1232 }
1233 print_tabs(tabs, fp);
1234 fprintf(fp, "}\n");
1235 }
1236
1237 static void
1238 print_loop(nir_loop *loop, print_state *state, unsigned tabs)
1239 {
1240 FILE *fp = state->fp;
1241
1242 print_tabs(tabs, fp);
1243 fprintf(fp, "loop {\n");
1244 foreach_list_typed(nir_cf_node, node, node, &loop->body) {
1245 print_cf_node(node, state, tabs + 1);
1246 }
1247 print_tabs(tabs, fp);
1248 fprintf(fp, "}\n");
1249 }
1250
1251 static void
1252 print_cf_node(nir_cf_node *node, print_state *state, unsigned int tabs)
1253 {
1254 switch (node->type) {
1255 case nir_cf_node_block:
1256 print_block(nir_cf_node_as_block(node), state, tabs);
1257 break;
1258
1259 case nir_cf_node_if:
1260 print_if(nir_cf_node_as_if(node), state, tabs);
1261 break;
1262
1263 case nir_cf_node_loop:
1264 print_loop(nir_cf_node_as_loop(node), state, tabs);
1265 break;
1266
1267 default:
1268 unreachable("Invalid CFG node type");
1269 }
1270 }
1271
1272 static void
1273 print_function_impl(nir_function_impl *impl, print_state *state)
1274 {
1275 FILE *fp = state->fp;
1276
1277 fprintf(fp, "\nimpl %s ", impl->function->name);
1278
1279 fprintf(fp, "{\n");
1280
1281 nir_foreach_variable(var, &impl->locals) {
1282 fprintf(fp, "\t");
1283 print_var_decl(var, state);
1284 }
1285
1286 foreach_list_typed(nir_register, reg, node, &impl->registers) {
1287 fprintf(fp, "\t");
1288 print_register_decl(reg, state);
1289 }
1290
1291 nir_index_blocks(impl);
1292
1293 foreach_list_typed(nir_cf_node, node, node, &impl->body) {
1294 print_cf_node(node, state, 1);
1295 }
1296
1297 fprintf(fp, "\tblock block_%u:\n}\n\n", impl->end_block->index);
1298 }
1299
1300 static void
1301 print_function(nir_function *function, print_state *state)
1302 {
1303 FILE *fp = state->fp;
1304
1305 fprintf(fp, "decl_function %s (%d params)", function->name,
1306 function->num_params);
1307
1308 fprintf(fp, "\n");
1309
1310 if (function->impl != NULL) {
1311 print_function_impl(function->impl, state);
1312 return;
1313 }
1314 }
1315
1316 static void
1317 init_print_state(print_state *state, nir_shader *shader, FILE *fp)
1318 {
1319 state->fp = fp;
1320 state->shader = shader;
1321 state->ht = _mesa_pointer_hash_table_create(NULL);
1322 state->syms = _mesa_set_create(NULL, _mesa_key_hash_string,
1323 _mesa_key_string_equal);
1324 state->index = 0;
1325 }
1326
1327 static void
1328 destroy_print_state(print_state *state)
1329 {
1330 _mesa_hash_table_destroy(state->ht, NULL);
1331 _mesa_set_destroy(state->syms, NULL);
1332 }
1333
1334 void
1335 nir_print_shader_annotated(nir_shader *shader, FILE *fp,
1336 struct hash_table *annotations)
1337 {
1338 print_state state;
1339 init_print_state(&state, shader, fp);
1340
1341 state.annotations = annotations;
1342
1343 fprintf(fp, "shader: %s\n", gl_shader_stage_name(shader->info.stage));
1344
1345 if (shader->info.name)
1346 fprintf(fp, "name: %s\n", shader->info.name);
1347
1348 if (shader->info.label)
1349 fprintf(fp, "label: %s\n", shader->info.label);
1350
1351 switch (shader->info.stage) {
1352 case MESA_SHADER_COMPUTE:
1353 fprintf(fp, "local-size: %u, %u, %u%s\n",
1354 shader->info.cs.local_size[0],
1355 shader->info.cs.local_size[1],
1356 shader->info.cs.local_size[2],
1357 shader->info.cs.local_size_variable ? " (variable)" : "");
1358 fprintf(fp, "shared-size: %u\n", shader->info.cs.shared_size);
1359 break;
1360 default:
1361 break;
1362 }
1363
1364 fprintf(fp, "inputs: %u\n", shader->num_inputs);
1365 fprintf(fp, "outputs: %u\n", shader->num_outputs);
1366 fprintf(fp, "uniforms: %u\n", shader->num_uniforms);
1367 fprintf(fp, "shared: %u\n", shader->num_shared);
1368
1369 nir_foreach_variable(var, &shader->uniforms) {
1370 print_var_decl(var, &state);
1371 }
1372
1373 nir_foreach_variable(var, &shader->inputs) {
1374 print_var_decl(var, &state);
1375 }
1376
1377 nir_foreach_variable(var, &shader->outputs) {
1378 print_var_decl(var, &state);
1379 }
1380
1381 nir_foreach_variable(var, &shader->shared) {
1382 print_var_decl(var, &state);
1383 }
1384
1385 nir_foreach_variable(var, &shader->globals) {
1386 print_var_decl(var, &state);
1387 }
1388
1389 nir_foreach_variable(var, &shader->system_values) {
1390 print_var_decl(var, &state);
1391 }
1392
1393 foreach_list_typed(nir_register, reg, node, &shader->registers) {
1394 print_register_decl(reg, &state);
1395 }
1396
1397 foreach_list_typed(nir_function, func, node, &shader->functions) {
1398 print_function(func, &state);
1399 }
1400
1401 destroy_print_state(&state);
1402 }
1403
1404 void
1405 nir_print_shader(nir_shader *shader, FILE *fp)
1406 {
1407 nir_print_shader_annotated(shader, fp, NULL);
1408 fflush(fp);
1409 }
1410
1411 void
1412 nir_print_instr(const nir_instr *instr, FILE *fp)
1413 {
1414 print_state state = {
1415 .fp = fp,
1416 };
1417 print_instr(instr, &state, 0);
1418
1419 }
1420
1421 void
1422 nir_print_deref(const nir_deref_instr *deref, FILE *fp)
1423 {
1424 print_state state = {
1425 .fp = fp,
1426 };
1427 print_deref_link(deref, true, &state);
1428 }