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"
34 print_tabs(unsigned num_tabs
, FILE *fp
)
36 for (unsigned i
= 0; i
< num_tabs
; i
++)
43 /** map from nir_variable -> printable name */
44 struct hash_table
*ht
;
46 /** set of names used so far for nir_variables */
49 /* an index used to make new non-conflicting names */
54 print_register(nir_register
*reg
, print_state
*state
)
57 if (reg
->name
!= NULL
)
58 fprintf(fp
, "/* %s */ ", reg
->name
);
60 fprintf(fp
, "gr%u", reg
->index
);
62 fprintf(fp
, "r%u", reg
->index
);
65 static const char *sizes
[] = { "error", "vec1", "vec2", "vec3", "vec4" };
68 print_register_decl(nir_register
*reg
, print_state
*state
)
71 fprintf(fp
, "decl_reg %s ", sizes
[reg
->num_components
]);
73 fprintf(fp
, "(packed) ");
74 print_register(reg
, state
);
75 if (reg
->num_array_elems
!= 0)
76 fprintf(fp
, "[%u]", reg
->num_array_elems
);
81 print_ssa_def(nir_ssa_def
*def
, print_state
*state
)
84 if (def
->name
!= NULL
)
85 fprintf(fp
, "/* %s */ ", def
->name
);
86 fprintf(fp
, "%s ssa_%u", sizes
[def
->num_components
], def
->index
);
90 print_ssa_use(nir_ssa_def
*def
, print_state
*state
)
93 if (def
->name
!= NULL
)
94 fprintf(fp
, "/* %s */ ", def
->name
);
95 fprintf(fp
, "ssa_%u", def
->index
);
98 static void print_src(nir_src
*src
, print_state
*state
);
101 print_reg_src(nir_reg_src
*src
, print_state
*state
)
103 FILE *fp
= state
->fp
;
104 print_register(src
->reg
, state
);
105 if (src
->reg
->num_array_elems
!= 0) {
106 fprintf(fp
, "[%u", src
->base_offset
);
107 if (src
->indirect
!= NULL
) {
109 print_src(src
->indirect
, state
);
116 print_reg_dest(nir_reg_dest
*dest
, print_state
*state
)
118 FILE *fp
= state
->fp
;
119 print_register(dest
->reg
, state
);
120 if (dest
->reg
->num_array_elems
!= 0) {
121 fprintf(fp
, "[%u", dest
->base_offset
);
122 if (dest
->indirect
!= NULL
) {
124 print_src(dest
->indirect
, state
);
131 print_src(nir_src
*src
, print_state
*state
)
134 print_ssa_use(src
->ssa
, state
);
136 print_reg_src(&src
->reg
, state
);
140 print_dest(nir_dest
*dest
, print_state
*state
)
143 print_ssa_def(&dest
->ssa
, state
);
145 print_reg_dest(&dest
->reg
, state
);
149 print_alu_src(nir_alu_instr
*instr
, unsigned src
, print_state
*state
)
151 FILE *fp
= state
->fp
;
153 if (instr
->src
[src
].negate
)
155 if (instr
->src
[src
].abs
)
158 print_src(&instr
->src
[src
].src
, state
);
160 bool print_swizzle
= false;
161 for (unsigned i
= 0; i
< 4; i
++) {
162 if (!nir_alu_instr_channel_used(instr
, src
, i
))
165 if (instr
->src
[src
].swizzle
[i
] != i
) {
166 print_swizzle
= true;
173 for (unsigned i
= 0; i
< 4; i
++) {
174 if (!nir_alu_instr_channel_used(instr
, src
, i
))
177 fprintf(fp
, "%c", "xyzw"[instr
->src
[src
].swizzle
[i
]]);
181 if (instr
->src
[src
].abs
)
186 print_alu_dest(nir_alu_dest
*dest
, print_state
*state
)
188 FILE *fp
= state
->fp
;
189 /* we're going to print the saturate modifier later, after the opcode */
191 print_dest(&dest
->dest
, state
);
193 if (!dest
->dest
.is_ssa
&&
194 dest
->write_mask
!= (1 << dest
->dest
.reg
.reg
->num_components
) - 1) {
196 for (unsigned i
= 0; i
< 4; i
++)
197 if ((dest
->write_mask
>> i
) & 1)
198 fprintf(fp
, "%c", "xyzw"[i
]);
203 print_alu_instr(nir_alu_instr
*instr
, print_state
*state
)
205 FILE *fp
= state
->fp
;
207 print_alu_dest(&instr
->dest
, state
);
209 fprintf(fp
, " = %s", nir_op_infos
[instr
->op
].name
);
212 if (instr
->dest
.saturate
)
216 for (unsigned i
= 0; i
< nir_op_infos
[instr
->op
].num_inputs
; i
++) {
220 print_alu_src(instr
, i
, state
);
225 get_var_name(nir_variable
*var
, print_state
*state
)
227 if (state
->ht
== NULL
)
232 struct hash_entry
*entry
= _mesa_hash_table_search(state
->ht
, var
);
237 if (var
->name
== NULL
) {
238 name
= ralloc_asprintf(state
->syms
, "@%u", state
->index
++);
240 struct set_entry
*set_entry
= _mesa_set_search(state
->syms
, var
->name
);
241 if (set_entry
!= NULL
) {
242 /* we have a collision with another name, append an @ + a unique
244 name
= ralloc_asprintf(state
->syms
, "%s@%u", var
->name
,
247 /* Mark this one as seen */
248 _mesa_set_add(state
->syms
, var
->name
);
253 _mesa_hash_table_insert(state
->ht
, var
, name
);
259 print_constant(nir_constant
*c
, const struct glsl_type
*type
, print_state
*state
)
261 FILE *fp
= state
->fp
;
262 unsigned total_elems
= glsl_get_components(type
);
265 switch (glsl_get_base_type(type
)) {
269 for (i
= 0; i
< total_elems
; i
++) {
270 if (i
> 0) fprintf(fp
, ", ");
271 fprintf(fp
, "0x%08x", c
->value
.u
[i
]);
275 case GLSL_TYPE_FLOAT
:
276 for (i
= 0; i
< total_elems
; i
++) {
277 if (i
> 0) fprintf(fp
, ", ");
278 fprintf(fp
, "%f", c
->value
.f
[i
]);
282 case GLSL_TYPE_STRUCT
:
283 for (i
= 0; i
< c
->num_elements
; i
++) {
284 if (i
> 0) fprintf(fp
, ", ");
286 print_constant(c
->elements
[i
], glsl_get_struct_field(type
, i
), state
);
291 case GLSL_TYPE_ARRAY
:
292 for (i
= 0; i
< c
->num_elements
; i
++) {
293 if (i
> 0) fprintf(fp
, ", ");
295 print_constant(c
->elements
[i
], glsl_get_array_element(type
), state
);
301 unreachable("not reached");
306 print_var_decl(nir_variable
*var
, print_state
*state
)
308 FILE *fp
= state
->fp
;
310 fprintf(fp
, "decl_var ");
312 const char *const cent
= (var
->data
.centroid
) ? "centroid " : "";
313 const char *const samp
= (var
->data
.sample
) ? "sample " : "";
314 const char *const patch
= (var
->data
.patch
) ? "patch " : "";
315 const char *const inv
= (var
->data
.invariant
) ? "invariant " : "";
316 const char *const mode
[] = { "shader_in ", "shader_out ", "", "",
317 "uniform ", "shader_storage ", "shared ",
320 fprintf(fp
, "%s%s%s%s%s%s ",
321 cent
, samp
, patch
, inv
, mode
[var
->data
.mode
],
322 glsl_interp_qualifier_name(var
->data
.interpolation
));
324 glsl_print_type(var
->type
, fp
);
326 fprintf(fp
, " %s", get_var_name(var
, state
));
328 if (var
->data
.mode
== nir_var_shader_in
||
329 var
->data
.mode
== nir_var_shader_out
||
330 var
->data
.mode
== nir_var_uniform
||
331 var
->data
.mode
== nir_var_shader_storage
) {
332 const char *loc
= NULL
;
335 switch (state
->shader
->stage
) {
336 case MESA_SHADER_VERTEX
:
337 if (var
->data
.mode
== nir_var_shader_in
)
338 loc
= gl_vert_attrib_name(var
->data
.location
);
339 else if (var
->data
.mode
== nir_var_shader_out
)
340 loc
= gl_varying_slot_name(var
->data
.location
);
342 case MESA_SHADER_GEOMETRY
:
343 if ((var
->data
.mode
== nir_var_shader_in
) ||
344 (var
->data
.mode
== nir_var_shader_out
))
345 loc
= gl_varying_slot_name(var
->data
.location
);
347 case MESA_SHADER_FRAGMENT
:
348 if (var
->data
.mode
== nir_var_shader_in
)
349 loc
= gl_varying_slot_name(var
->data
.location
);
350 else if (var
->data
.mode
== nir_var_shader_out
)
351 loc
= gl_frag_result_name(var
->data
.location
);
353 case MESA_SHADER_TESS_CTRL
:
354 case MESA_SHADER_TESS_EVAL
:
355 case MESA_SHADER_COMPUTE
:
362 snprintf(buf
, sizeof(buf
), "%u", var
->data
.location
);
366 fprintf(fp
, " (%s, %u)", loc
, var
->data
.driver_location
);
369 if (var
->constant_initializer
) {
370 fprintf(fp
, " = { ");
371 print_constant(var
->constant_initializer
, var
->type
, state
);
379 print_var(nir_variable
*var
, print_state
*state
)
381 FILE *fp
= state
->fp
;
382 fprintf(fp
, "%s", get_var_name(var
, state
));
386 print_arg(nir_variable
*var
, print_state
*state
)
388 FILE *fp
= state
->fp
;
389 glsl_print_type(var
->type
, fp
);
390 fprintf(fp
, " %s", get_var_name(var
, state
));
394 print_deref_var(nir_deref_var
*deref
, print_state
*state
)
396 print_var(deref
->var
, state
);
400 print_deref_array(nir_deref_array
*deref
, print_state
*state
)
402 FILE *fp
= state
->fp
;
404 switch (deref
->deref_array_type
) {
405 case nir_deref_array_type_direct
:
406 fprintf(fp
, "%u", deref
->base_offset
);
408 case nir_deref_array_type_indirect
:
409 if (deref
->base_offset
!= 0)
410 fprintf(fp
, "%u + ", deref
->base_offset
);
411 print_src(&deref
->indirect
, state
);
413 case nir_deref_array_type_wildcard
:
421 print_deref_struct(nir_deref_struct
*deref
, const struct glsl_type
*parent_type
,
424 FILE *fp
= state
->fp
;
425 fprintf(fp
, ".%s", glsl_get_struct_elem_name(parent_type
, deref
->index
));
429 print_deref(nir_deref_var
*deref
, print_state
*state
)
431 nir_deref
*tail
= &deref
->deref
;
432 nir_deref
*pretail
= NULL
;
433 while (tail
!= NULL
) {
434 switch (tail
->deref_type
) {
435 case nir_deref_type_var
:
436 assert(pretail
== NULL
);
437 assert(tail
== &deref
->deref
);
438 print_deref_var(deref
, state
);
441 case nir_deref_type_array
:
442 assert(pretail
!= NULL
);
443 print_deref_array(nir_deref_as_array(tail
), state
);
446 case nir_deref_type_struct
:
447 assert(pretail
!= NULL
);
448 print_deref_struct(nir_deref_as_struct(tail
),
449 pretail
->type
, state
);
453 unreachable("Invalid deref type");
457 tail
= pretail
->child
;
462 print_intrinsic_instr(nir_intrinsic_instr
*instr
, print_state
*state
)
464 const nir_intrinsic_info
*info
= &nir_intrinsic_infos
[instr
->intrinsic
];
465 unsigned num_srcs
= info
->num_srcs
;
466 FILE *fp
= state
->fp
;
468 if (info
->has_dest
) {
469 print_dest(&instr
->dest
, state
);
473 fprintf(fp
, "intrinsic %s (", info
->name
);
475 for (unsigned i
= 0; i
< num_srcs
; i
++) {
479 print_src(&instr
->src
[i
], state
);
484 for (unsigned i
= 0; i
< info
->num_variables
; i
++) {
488 print_deref(instr
->variables
[i
], state
);
493 for (unsigned i
= 0; i
< info
->num_indices
; i
++) {
497 fprintf(fp
, "%d", instr
->const_index
[i
]);
502 static const char *index_name
[NIR_INTRINSIC_NUM_INDEX_FLAGS
] = {
503 [NIR_INTRINSIC_BASE
] = "base",
504 [NIR_INTRINSIC_WRMASK
] = "wrmask",
505 [NIR_INTRINSIC_STREAM_ID
] = "stream-id",
506 [NIR_INTRINSIC_UCP_ID
] = "ucp-id",
507 [NIR_INTRINSIC_RANGE
] = "range",
508 [NIR_INTRINSIC_DESC_SET
] = "desc-set",
509 [NIR_INTRINSIC_BINDING
] = "binding",
511 for (unsigned idx
= 1; idx
< NIR_INTRINSIC_NUM_INDEX_FLAGS
; idx
++) {
512 if (!info
->index_map
[idx
])
515 if (idx
== NIR_INTRINSIC_WRMASK
) {
516 /* special case wrmask to show it as a writemask.. */
517 unsigned wrmask
= nir_intrinsic_write_mask(instr
);
518 fprintf(fp
, " wrmask=");
519 for (unsigned i
= 0; i
< 4; i
++)
520 if ((wrmask
>> i
) & 1)
521 fprintf(fp
, "%c", "xyzw"[i
]);
523 unsigned off
= info
->index_map
[idx
] - 1;
524 assert(index_name
[idx
]); /* forgot to update index_name table? */
525 fprintf(fp
, " %s=%d", index_name
[idx
], instr
->const_index
[off
]);
533 struct exec_list
*var_list
= NULL
;
535 switch (instr
->intrinsic
) {
536 case nir_intrinsic_load_uniform
:
537 var_list
= &state
->shader
->uniforms
;
539 case nir_intrinsic_load_input
:
540 case nir_intrinsic_load_per_vertex_input
:
541 var_list
= &state
->shader
->inputs
;
543 case nir_intrinsic_load_output
:
544 case nir_intrinsic_store_output
:
545 case nir_intrinsic_store_per_vertex_output
:
546 var_list
= &state
->shader
->outputs
;
552 nir_foreach_variable(var
, var_list
) {
553 if ((var
->data
.driver_location
== nir_intrinsic_base(instr
)) &&
555 fprintf(fp
, "\t/* %s */", var
->name
);
562 print_tex_instr(nir_tex_instr
*instr
, print_state
*state
)
564 FILE *fp
= state
->fp
;
566 print_dest(&instr
->dest
, state
);
586 case nir_texop_txf_ms
:
587 fprintf(fp
, "txf_ms ");
598 case nir_texop_query_levels
:
599 fprintf(fp
, "query_levels ");
601 case nir_texop_texture_samples
:
602 fprintf(fp
, "texture_samples ");
604 case nir_texop_samples_identical
:
605 fprintf(fp
, "samples_identical ");
608 unreachable("Invalid texture operation");
612 for (unsigned i
= 0; i
< instr
->num_srcs
; i
++) {
613 print_src(&instr
->src
[i
].src
, state
);
617 switch(instr
->src
[i
].src_type
) {
618 case nir_tex_src_coord
:
619 fprintf(fp
, "(coord)");
621 case nir_tex_src_projector
:
622 fprintf(fp
, "(projector)");
624 case nir_tex_src_comparitor
:
625 fprintf(fp
, "(comparitor)");
627 case nir_tex_src_offset
:
628 fprintf(fp
, "(offset)");
630 case nir_tex_src_bias
:
631 fprintf(fp
, "(bias)");
633 case nir_tex_src_lod
:
634 fprintf(fp
, "(lod)");
636 case nir_tex_src_ms_index
:
637 fprintf(fp
, "(ms_index)");
639 case nir_tex_src_ddx
:
640 fprintf(fp
, "(ddx)");
642 case nir_tex_src_ddy
:
643 fprintf(fp
, "(ddy)");
645 case nir_tex_src_texture_offset
:
646 fprintf(fp
, "(texture_offset)");
648 case nir_tex_src_sampler_offset
:
649 fprintf(fp
, "(sampler_offset)");
653 unreachable("Invalid texture source type");
660 if (instr
->op
== nir_texop_tg4
) {
661 fprintf(fp
, "%u (gather_component), ", instr
->component
);
664 if (instr
->texture
) {
665 print_deref(instr
->texture
, state
);
666 fprintf(fp
, " (texture)");
667 if (instr
->sampler
) {
668 print_deref(instr
->sampler
, state
);
669 fprintf(fp
, " (sampler)");
672 assert(instr
->sampler
== NULL
);
673 fprintf(fp
, "%u (texture) %u (sampler)",
674 instr
->texture_index
, instr
->sampler_index
);
679 print_call_instr(nir_call_instr
*instr
, print_state
*state
)
681 FILE *fp
= state
->fp
;
683 fprintf(fp
, "call %s ", instr
->callee
->name
);
685 for (unsigned i
= 0; i
< instr
->num_params
; i
++) {
689 print_deref(instr
->params
[i
], state
);
692 if (instr
->return_deref
!= NULL
) {
693 if (instr
->num_params
!= 0)
695 fprintf(fp
, "returning ");
696 print_deref(instr
->return_deref
, state
);
701 print_load_const_instr(nir_load_const_instr
*instr
, print_state
*state
)
703 FILE *fp
= state
->fp
;
705 print_ssa_def(&instr
->def
, state
);
707 fprintf(fp
, " = load_const (");
709 for (unsigned i
= 0; i
< instr
->def
.num_components
; i
++) {
714 * we don't really know the type of the constant (if it will be used as a
715 * float or an int), so just print the raw constant in hex for fidelity
716 * and then print the float in a comment for readability.
719 fprintf(fp
, "0x%08x /* %f */", instr
->value
.u32
[i
], instr
->value
.f32
[i
]);
726 print_jump_instr(nir_jump_instr
*instr
, print_state
*state
)
728 FILE *fp
= state
->fp
;
730 switch (instr
->type
) {
732 fprintf(fp
, "break");
735 case nir_jump_continue
:
736 fprintf(fp
, "continue");
739 case nir_jump_return
:
740 fprintf(fp
, "return");
746 print_ssa_undef_instr(nir_ssa_undef_instr
* instr
, print_state
*state
)
748 FILE *fp
= state
->fp
;
749 print_ssa_def(&instr
->def
, state
);
750 fprintf(fp
, " = undefined");
754 print_phi_instr(nir_phi_instr
*instr
, print_state
*state
)
756 FILE *fp
= state
->fp
;
757 print_dest(&instr
->dest
, state
);
758 fprintf(fp
, " = phi ");
759 nir_foreach_phi_src(instr
, src
) {
760 if (&src
->node
!= exec_list_get_head(&instr
->srcs
))
763 fprintf(fp
, "block_%u: ", src
->pred
->index
);
764 print_src(&src
->src
, state
);
769 print_parallel_copy_instr(nir_parallel_copy_instr
*instr
, print_state
*state
)
771 FILE *fp
= state
->fp
;
772 nir_foreach_parallel_copy_entry(instr
, entry
) {
773 if (&entry
->node
!= exec_list_get_head(&instr
->entries
))
776 print_dest(&entry
->dest
, state
);
778 print_src(&entry
->src
, state
);
783 print_instr(const nir_instr
*instr
, print_state
*state
, unsigned tabs
)
785 FILE *fp
= state
->fp
;
786 print_tabs(tabs
, fp
);
788 switch (instr
->type
) {
789 case nir_instr_type_alu
:
790 print_alu_instr(nir_instr_as_alu(instr
), state
);
793 case nir_instr_type_call
:
794 print_call_instr(nir_instr_as_call(instr
), state
);
797 case nir_instr_type_intrinsic
:
798 print_intrinsic_instr(nir_instr_as_intrinsic(instr
), state
);
801 case nir_instr_type_tex
:
802 print_tex_instr(nir_instr_as_tex(instr
), state
);
805 case nir_instr_type_load_const
:
806 print_load_const_instr(nir_instr_as_load_const(instr
), state
);
809 case nir_instr_type_jump
:
810 print_jump_instr(nir_instr_as_jump(instr
), state
);
813 case nir_instr_type_ssa_undef
:
814 print_ssa_undef_instr(nir_instr_as_ssa_undef(instr
), state
);
817 case nir_instr_type_phi
:
818 print_phi_instr(nir_instr_as_phi(instr
), state
);
821 case nir_instr_type_parallel_copy
:
822 print_parallel_copy_instr(nir_instr_as_parallel_copy(instr
), state
);
826 unreachable("Invalid instruction type");
832 compare_block_index(const void *p1
, const void *p2
)
834 const nir_block
*block1
= *((const nir_block
**) p1
);
835 const nir_block
*block2
= *((const nir_block
**) p2
);
837 return (int) block1
->index
- (int) block2
->index
;
840 static void print_cf_node(nir_cf_node
*node
, print_state
*state
,
844 print_block(nir_block
*block
, print_state
*state
, unsigned tabs
)
846 FILE *fp
= state
->fp
;
848 print_tabs(tabs
, fp
);
849 fprintf(fp
, "block block_%u:\n", block
->index
);
851 /* sort the predecessors by index so we consistently print the same thing */
854 malloc(block
->predecessors
->entries
* sizeof(nir_block
*));
856 struct set_entry
*entry
;
858 set_foreach(block
->predecessors
, entry
) {
859 preds
[i
++] = (nir_block
*) entry
->key
;
862 qsort(preds
, block
->predecessors
->entries
, sizeof(nir_block
*),
863 compare_block_index
);
865 print_tabs(tabs
, fp
);
866 fprintf(fp
, "/* preds: ");
867 for (unsigned i
= 0; i
< block
->predecessors
->entries
; i
++) {
868 fprintf(fp
, "block_%u ", preds
[i
]->index
);
874 nir_foreach_instr(block
, instr
) {
875 print_instr(instr
, state
, tabs
);
879 print_tabs(tabs
, fp
);
880 fprintf(fp
, "/* succs: ");
881 for (unsigned i
= 0; i
< 2; i
++)
882 if (block
->successors
[i
]) {
883 fprintf(fp
, "block_%u ", block
->successors
[i
]->index
);
889 print_if(nir_if
*if_stmt
, print_state
*state
, unsigned tabs
)
891 FILE *fp
= state
->fp
;
893 print_tabs(tabs
, fp
);
895 print_src(&if_stmt
->condition
, state
);
897 foreach_list_typed(nir_cf_node
, node
, node
, &if_stmt
->then_list
) {
898 print_cf_node(node
, state
, tabs
+ 1);
900 print_tabs(tabs
, fp
);
901 fprintf(fp
, "} else {\n");
902 foreach_list_typed(nir_cf_node
, node
, node
, &if_stmt
->else_list
) {
903 print_cf_node(node
, state
, tabs
+ 1);
905 print_tabs(tabs
, fp
);
910 print_loop(nir_loop
*loop
, print_state
*state
, unsigned tabs
)
912 FILE *fp
= state
->fp
;
914 print_tabs(tabs
, fp
);
915 fprintf(fp
, "loop {\n");
916 foreach_list_typed(nir_cf_node
, node
, node
, &loop
->body
) {
917 print_cf_node(node
, state
, tabs
+ 1);
919 print_tabs(tabs
, fp
);
924 print_cf_node(nir_cf_node
*node
, print_state
*state
, unsigned int tabs
)
926 switch (node
->type
) {
927 case nir_cf_node_block
:
928 print_block(nir_cf_node_as_block(node
), state
, tabs
);
932 print_if(nir_cf_node_as_if(node
), state
, tabs
);
935 case nir_cf_node_loop
:
936 print_loop(nir_cf_node_as_loop(node
), state
, tabs
);
940 unreachable("Invalid CFG node type");
945 print_function_impl(nir_function_impl
*impl
, print_state
*state
)
947 FILE *fp
= state
->fp
;
949 fprintf(fp
, "\nimpl %s ", impl
->function
->name
);
951 for (unsigned i
= 0; i
< impl
->num_params
; i
++) {
955 print_arg(impl
->params
[i
], state
);
958 if (impl
->return_var
!= NULL
) {
959 if (impl
->num_params
!= 0)
961 fprintf(fp
, "returning ");
962 print_arg(impl
->return_var
, state
);
967 for (unsigned i
= 0; i
< impl
->num_params
; i
++) {
969 print_var_decl(impl
->params
[i
], state
);
972 if (impl
->return_var
) {
974 print_var_decl(impl
->return_var
, state
);
977 nir_foreach_variable(var
, &impl
->locals
) {
979 print_var_decl(var
, state
);
982 foreach_list_typed(nir_register
, reg
, node
, &impl
->registers
) {
984 print_register_decl(reg
, state
);
987 nir_index_blocks(impl
);
989 foreach_list_typed(nir_cf_node
, node
, node
, &impl
->body
) {
990 print_cf_node(node
, state
, 1);
993 fprintf(fp
, "\tblock block_%u:\n}\n\n", impl
->end_block
->index
);
997 print_function(nir_function
*function
, print_state
*state
)
999 FILE *fp
= state
->fp
;
1001 fprintf(fp
, "decl_function %s ", function
->name
);
1003 for (unsigned i
= 0; i
< function
->num_params
; i
++) {
1007 switch (function
->params
[i
].param_type
) {
1008 case nir_parameter_in
:
1011 case nir_parameter_out
:
1012 fprintf(fp
, "out ");
1014 case nir_parameter_inout
:
1015 fprintf(fp
, "inout ");
1018 unreachable("Invalid parameter type");
1021 glsl_print_type(function
->params
[i
].type
, fp
);
1024 if (function
->return_type
!= NULL
) {
1025 if (function
->num_params
!= 0)
1027 fprintf(fp
, "returning ");
1028 glsl_print_type(function
->return_type
, fp
);
1033 if (function
->impl
!= NULL
) {
1034 print_function_impl(function
->impl
, state
);
1040 init_print_state(print_state
*state
, nir_shader
*shader
, FILE *fp
)
1043 state
->shader
= shader
;
1044 state
->ht
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
1045 _mesa_key_pointer_equal
);
1046 state
->syms
= _mesa_set_create(NULL
, _mesa_key_hash_string
,
1047 _mesa_key_string_equal
);
1052 destroy_print_state(print_state
*state
)
1054 _mesa_hash_table_destroy(state
->ht
, NULL
);
1055 _mesa_set_destroy(state
->syms
, NULL
);
1059 nir_print_shader(nir_shader
*shader
, FILE *fp
)
1062 init_print_state(&state
, shader
, fp
);
1064 fprintf(fp
, "shader: %s\n", gl_shader_stage_name(shader
->stage
));
1066 if (shader
->info
.name
)
1067 fprintf(fp
, "name: %s\n", shader
->info
.name
);
1069 if (shader
->info
.label
)
1070 fprintf(fp
, "label: %s\n", shader
->info
.label
);
1072 fprintf(fp
, "inputs: %u\n", shader
->num_inputs
);
1073 fprintf(fp
, "outputs: %u\n", shader
->num_outputs
);
1074 fprintf(fp
, "uniforms: %u\n", shader
->num_uniforms
);
1075 fprintf(fp
, "shared: %u\n", shader
->num_shared
);
1077 nir_foreach_variable(var
, &shader
->uniforms
) {
1078 print_var_decl(var
, &state
);
1081 nir_foreach_variable(var
, &shader
->inputs
) {
1082 print_var_decl(var
, &state
);
1085 nir_foreach_variable(var
, &shader
->outputs
) {
1086 print_var_decl(var
, &state
);
1089 nir_foreach_variable(var
, &shader
->shared
) {
1090 print_var_decl(var
, &state
);
1093 nir_foreach_variable(var
, &shader
->globals
) {
1094 print_var_decl(var
, &state
);
1097 nir_foreach_variable(var
, &shader
->system_values
) {
1098 print_var_decl(var
, &state
);
1101 foreach_list_typed(nir_register
, reg
, node
, &shader
->registers
) {
1102 print_register_decl(reg
, &state
);
1105 foreach_list_typed(nir_function
, func
, node
, &shader
->functions
) {
1106 print_function(func
, &state
);
1109 destroy_print_state(&state
);
1113 nir_print_instr(const nir_instr
*instr
, FILE *fp
)
1115 print_state state
= {
1118 print_instr(instr
, &state
, 0);