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
);
210 if (instr
->dest
.saturate
)
214 for (unsigned i
= 0; i
< nir_op_infos
[instr
->op
].num_inputs
; i
++) {
218 print_alu_src(instr
, i
, state
);
223 print_constant(nir_constant
*c
, const struct glsl_type
*type
, print_state
*state
)
225 FILE *fp
= state
->fp
;
226 unsigned total_elems
= glsl_get_components(type
);
229 switch (glsl_get_base_type(type
)) {
233 for (i
= 0; i
< total_elems
; i
++) {
234 if (i
> 0) fprintf(fp
, ", ");
235 fprintf(fp
, "0x%08x", c
->value
.u
[i
]);
239 case GLSL_TYPE_FLOAT
:
240 for (i
= 0; i
< total_elems
; i
++) {
241 if (i
> 0) fprintf(fp
, ", ");
242 fprintf(fp
, "%f", c
->value
.f
[i
]);
246 case GLSL_TYPE_STRUCT
:
247 for (i
= 0; i
< c
->num_elements
; i
++) {
248 if (i
> 0) fprintf(fp
, ", ");
250 print_constant(c
->elements
[i
], glsl_get_struct_field(type
, i
), state
);
255 case GLSL_TYPE_ARRAY
:
256 for (i
= 0; i
< c
->num_elements
; i
++) {
257 if (i
> 0) fprintf(fp
, ", ");
259 print_constant(c
->elements
[i
], glsl_get_array_element(type
), state
);
265 unreachable("not reached");
270 print_var_decl(nir_variable
*var
, print_state
*state
)
272 FILE *fp
= state
->fp
;
274 fprintf(fp
, "decl_var ");
276 const char *const cent
= (var
->data
.centroid
) ? "centroid " : "";
277 const char *const samp
= (var
->data
.sample
) ? "sample " : "";
278 const char *const patch
= (var
->data
.patch
) ? "patch " : "";
279 const char *const inv
= (var
->data
.invariant
) ? "invariant " : "";
280 const char *const mode
[] = { "shader_in ", "shader_out ", "", "",
281 "uniform ", "shader_storage", "system " };
283 fprintf(fp
, "%s%s%s%s%s%s ",
284 cent
, samp
, patch
, inv
, mode
[var
->data
.mode
],
285 glsl_interp_qualifier_name(var
->data
.interpolation
));
287 glsl_print_type(var
->type
, fp
);
289 struct set_entry
*entry
= NULL
;
291 entry
= _mesa_set_search(state
->syms
, var
->name
);
296 /* we have a collision with another name, append an @ + a unique index */
297 name
= ralloc_asprintf(state
->syms
, "%s@%u", var
->name
, state
->index
++);
302 fprintf(fp
, " %s", name
);
304 if (var
->data
.mode
== nir_var_shader_in
||
305 var
->data
.mode
== nir_var_shader_out
||
306 var
->data
.mode
== nir_var_uniform
||
307 var
->data
.mode
== nir_var_shader_storage
) {
308 const char *loc
= NULL
;
311 switch (state
->shader
->stage
) {
312 case MESA_SHADER_VERTEX
:
313 if (var
->data
.mode
== nir_var_shader_in
)
314 loc
= gl_vert_attrib_name(var
->data
.location
);
315 else if (var
->data
.mode
== nir_var_shader_out
)
316 loc
= gl_varying_slot_name(var
->data
.location
);
318 case MESA_SHADER_GEOMETRY
:
319 if ((var
->data
.mode
== nir_var_shader_in
) ||
320 (var
->data
.mode
== nir_var_shader_out
))
321 loc
= gl_varying_slot_name(var
->data
.location
);
323 case MESA_SHADER_FRAGMENT
:
324 if (var
->data
.mode
== nir_var_shader_in
)
325 loc
= gl_varying_slot_name(var
->data
.location
);
326 else if (var
->data
.mode
== nir_var_shader_out
)
327 loc
= gl_frag_result_name(var
->data
.location
);
329 case MESA_SHADER_TESS_CTRL
:
330 case MESA_SHADER_TESS_EVAL
:
331 case MESA_SHADER_COMPUTE
:
338 snprintf(buf
, sizeof(buf
), "%u", var
->data
.location
);
342 fprintf(fp
, " (%s, %u)", loc
, var
->data
.driver_location
);
345 if (var
->constant_initializer
) {
346 fprintf(fp
, " = { ");
347 print_constant(var
->constant_initializer
, var
->type
, state
);
354 _mesa_set_add(state
->syms
, name
);
355 _mesa_hash_table_insert(state
->ht
, var
, name
);
360 print_var(nir_variable
*var
, print_state
*state
)
362 FILE *fp
= state
->fp
;
365 struct hash_entry
*entry
= _mesa_hash_table_search(state
->ht
, var
);
367 assert(entry
!= NULL
);
373 fprintf(fp
, "%s", name
);
377 print_deref_var(nir_deref_var
*deref
, print_state
*state
)
379 print_var(deref
->var
, state
);
383 print_deref_array(nir_deref_array
*deref
, print_state
*state
)
385 FILE *fp
= state
->fp
;
387 switch (deref
->deref_array_type
) {
388 case nir_deref_array_type_direct
:
389 fprintf(fp
, "%u", deref
->base_offset
);
391 case nir_deref_array_type_indirect
:
392 if (deref
->base_offset
!= 0)
393 fprintf(fp
, "%u + ", deref
->base_offset
);
394 print_src(&deref
->indirect
, state
);
396 case nir_deref_array_type_wildcard
:
404 print_deref_struct(nir_deref_struct
*deref
, const struct glsl_type
*parent_type
,
407 FILE *fp
= state
->fp
;
408 fprintf(fp
, ".%s", glsl_get_struct_elem_name(parent_type
, deref
->index
));
412 print_deref(nir_deref_var
*deref
, print_state
*state
)
414 nir_deref
*tail
= &deref
->deref
;
415 nir_deref
*pretail
= NULL
;
416 while (tail
!= NULL
) {
417 switch (tail
->deref_type
) {
418 case nir_deref_type_var
:
419 assert(pretail
== NULL
);
420 assert(tail
== &deref
->deref
);
421 print_deref_var(deref
, state
);
424 case nir_deref_type_array
:
425 assert(pretail
!= NULL
);
426 print_deref_array(nir_deref_as_array(tail
), state
);
429 case nir_deref_type_struct
:
430 assert(pretail
!= NULL
);
431 print_deref_struct(nir_deref_as_struct(tail
),
432 pretail
->type
, state
);
436 unreachable("Invalid deref type");
440 tail
= pretail
->child
;
445 print_intrinsic_instr(nir_intrinsic_instr
*instr
, print_state
*state
)
447 const nir_intrinsic_info
*info
= &nir_intrinsic_infos
[instr
->intrinsic
];
448 unsigned num_srcs
= info
->num_srcs
;
449 FILE *fp
= state
->fp
;
451 if (info
->has_dest
) {
452 print_dest(&instr
->dest
, state
);
456 fprintf(fp
, "intrinsic %s (", info
->name
);
458 for (unsigned i
= 0; i
< num_srcs
; i
++) {
462 print_src(&instr
->src
[i
], state
);
467 for (unsigned i
= 0; i
< info
->num_variables
; i
++) {
471 print_deref(instr
->variables
[i
], state
);
476 for (unsigned i
= 0; i
< info
->num_indices
; i
++) {
480 fprintf(fp
, "%d", instr
->const_index
[i
]);
485 static const char *index_name
[NIR_INTRINSIC_NUM_INDEX_FLAGS
] = {
486 [NIR_INTRINSIC_BASE
] = "base",
487 [NIR_INTRINSIC_WRMASK
] = "wrmask",
488 [NIR_INTRINSIC_STREAM_ID
] = "stream-id",
489 [NIR_INTRINSIC_UCP_ID
] = "ucp-id",
491 for (unsigned idx
= 1; idx
< NIR_INTRINSIC_NUM_INDEX_FLAGS
; idx
++) {
492 if (!info
->index_map
[idx
])
495 if (idx
== NIR_INTRINSIC_WRMASK
) {
496 /* special case wrmask to show it as a writemask.. */
497 unsigned wrmask
= nir_intrinsic_write_mask(instr
);
498 fprintf(fp
, " wrmask=");
499 for (unsigned i
= 0; i
< 4; i
++)
500 if ((wrmask
>> i
) & 1)
501 fprintf(fp
, "%c", "xyzw"[i
]);
503 unsigned off
= info
->index_map
[idx
] - 1;
504 assert(index_name
[idx
]); /* forgot to update index_name table? */
505 fprintf(fp
, " %s=%d", index_name
[idx
], instr
->const_index
[off
]);
513 struct exec_list
*var_list
= NULL
;
515 switch (instr
->intrinsic
) {
516 case nir_intrinsic_load_uniform
:
517 var_list
= &state
->shader
->uniforms
;
519 case nir_intrinsic_load_input
:
520 case nir_intrinsic_load_per_vertex_input
:
521 var_list
= &state
->shader
->inputs
;
523 case nir_intrinsic_load_output
:
524 case nir_intrinsic_store_output
:
525 case nir_intrinsic_store_per_vertex_output
:
526 var_list
= &state
->shader
->outputs
;
532 nir_foreach_variable(var
, var_list
) {
533 if ((var
->data
.driver_location
== nir_intrinsic_base(instr
)) &&
535 fprintf(fp
, "\t/* %s */", var
->name
);
542 print_tex_instr(nir_tex_instr
*instr
, print_state
*state
)
544 FILE *fp
= state
->fp
;
546 print_dest(&instr
->dest
, state
);
566 case nir_texop_txf_ms
:
567 fprintf(fp
, "txf_ms ");
578 case nir_texop_query_levels
:
579 fprintf(fp
, "query_levels ");
581 case nir_texop_texture_samples
:
582 fprintf(fp
, "texture_samples ");
584 case nir_texop_samples_identical
:
585 fprintf(fp
, "samples_identical ");
588 unreachable("Invalid texture operation");
592 for (unsigned i
= 0; i
< instr
->num_srcs
; i
++) {
593 print_src(&instr
->src
[i
].src
, state
);
597 switch(instr
->src
[i
].src_type
) {
598 case nir_tex_src_coord
:
599 fprintf(fp
, "(coord)");
601 case nir_tex_src_projector
:
602 fprintf(fp
, "(projector)");
604 case nir_tex_src_comparitor
:
605 fprintf(fp
, "(comparitor)");
607 case nir_tex_src_offset
:
608 fprintf(fp
, "(offset)");
610 case nir_tex_src_bias
:
611 fprintf(fp
, "(bias)");
613 case nir_tex_src_lod
:
614 fprintf(fp
, "(lod)");
616 case nir_tex_src_ms_index
:
617 fprintf(fp
, "(ms_index)");
619 case nir_tex_src_ddx
:
620 fprintf(fp
, "(ddx)");
622 case nir_tex_src_ddy
:
623 fprintf(fp
, "(ddy)");
625 case nir_tex_src_texture_offset
:
626 fprintf(fp
, "(texture_offset)");
628 case nir_tex_src_sampler_offset
:
629 fprintf(fp
, "(sampler_offset)");
633 unreachable("Invalid texture source type");
640 if (instr
->op
== nir_texop_tg4
) {
641 fprintf(fp
, "%u (gather_component), ", instr
->component
);
644 if (instr
->texture
) {
645 print_deref(instr
->texture
, state
);
646 fprintf(fp
, " (texture)");
647 if (instr
->sampler
) {
648 print_deref(instr
->sampler
, state
);
649 fprintf(fp
, " (sampler)");
652 assert(instr
->sampler
== NULL
);
653 fprintf(fp
, "%u (texture) %u (sampler)",
654 instr
->texture_index
, instr
->sampler_index
);
659 print_call_instr(nir_call_instr
*instr
, print_state
*state
)
661 FILE *fp
= state
->fp
;
663 fprintf(fp
, "call %s ", instr
->callee
->name
);
665 for (unsigned i
= 0; i
< instr
->num_params
; i
++) {
669 print_deref(instr
->params
[i
], state
);
672 if (instr
->return_deref
!= NULL
) {
673 if (instr
->num_params
!= 0)
675 fprintf(fp
, "returning ");
676 print_deref(instr
->return_deref
, state
);
681 print_load_const_instr(nir_load_const_instr
*instr
, print_state
*state
)
683 FILE *fp
= state
->fp
;
685 print_ssa_def(&instr
->def
, state
);
687 fprintf(fp
, " = load_const (");
689 for (unsigned i
= 0; i
< instr
->def
.num_components
; i
++) {
694 * we don't really know the type of the constant (if it will be used as a
695 * float or an int), so just print the raw constant in hex for fidelity
696 * and then print the float in a comment for readability.
699 fprintf(fp
, "0x%08x /* %f */", instr
->value
.u
[i
], instr
->value
.f
[i
]);
706 print_jump_instr(nir_jump_instr
*instr
, print_state
*state
)
708 FILE *fp
= state
->fp
;
710 switch (instr
->type
) {
712 fprintf(fp
, "break");
715 case nir_jump_continue
:
716 fprintf(fp
, "continue");
719 case nir_jump_return
:
720 fprintf(fp
, "return");
726 print_ssa_undef_instr(nir_ssa_undef_instr
* instr
, print_state
*state
)
728 FILE *fp
= state
->fp
;
729 print_ssa_def(&instr
->def
, state
);
730 fprintf(fp
, " = undefined");
734 print_phi_instr(nir_phi_instr
*instr
, print_state
*state
)
736 FILE *fp
= state
->fp
;
737 print_dest(&instr
->dest
, state
);
738 fprintf(fp
, " = phi ");
739 nir_foreach_phi_src(instr
, src
) {
740 if (&src
->node
!= exec_list_get_head(&instr
->srcs
))
743 fprintf(fp
, "block_%u: ", src
->pred
->index
);
744 print_src(&src
->src
, state
);
749 print_parallel_copy_instr(nir_parallel_copy_instr
*instr
, print_state
*state
)
751 FILE *fp
= state
->fp
;
752 nir_foreach_parallel_copy_entry(instr
, entry
) {
753 if (&entry
->node
!= exec_list_get_head(&instr
->entries
))
756 print_dest(&entry
->dest
, state
);
758 print_src(&entry
->src
, state
);
763 print_instr(const nir_instr
*instr
, print_state
*state
, unsigned tabs
)
765 FILE *fp
= state
->fp
;
766 print_tabs(tabs
, fp
);
768 switch (instr
->type
) {
769 case nir_instr_type_alu
:
770 print_alu_instr(nir_instr_as_alu(instr
), state
);
773 case nir_instr_type_call
:
774 print_call_instr(nir_instr_as_call(instr
), state
);
777 case nir_instr_type_intrinsic
:
778 print_intrinsic_instr(nir_instr_as_intrinsic(instr
), state
);
781 case nir_instr_type_tex
:
782 print_tex_instr(nir_instr_as_tex(instr
), state
);
785 case nir_instr_type_load_const
:
786 print_load_const_instr(nir_instr_as_load_const(instr
), state
);
789 case nir_instr_type_jump
:
790 print_jump_instr(nir_instr_as_jump(instr
), state
);
793 case nir_instr_type_ssa_undef
:
794 print_ssa_undef_instr(nir_instr_as_ssa_undef(instr
), state
);
797 case nir_instr_type_phi
:
798 print_phi_instr(nir_instr_as_phi(instr
), state
);
801 case nir_instr_type_parallel_copy
:
802 print_parallel_copy_instr(nir_instr_as_parallel_copy(instr
), state
);
806 unreachable("Invalid instruction type");
812 compare_block_index(const void *p1
, const void *p2
)
814 const nir_block
*block1
= *((const nir_block
**) p1
);
815 const nir_block
*block2
= *((const nir_block
**) p2
);
817 return (int) block1
->index
- (int) block2
->index
;
820 static void print_cf_node(nir_cf_node
*node
, print_state
*state
,
824 print_block(nir_block
*block
, print_state
*state
, unsigned tabs
)
826 FILE *fp
= state
->fp
;
828 print_tabs(tabs
, fp
);
829 fprintf(fp
, "block block_%u:\n", block
->index
);
831 /* sort the predecessors by index so we consistently print the same thing */
834 malloc(block
->predecessors
->entries
* sizeof(nir_block
*));
836 struct set_entry
*entry
;
838 set_foreach(block
->predecessors
, entry
) {
839 preds
[i
++] = (nir_block
*) entry
->key
;
842 qsort(preds
, block
->predecessors
->entries
, sizeof(nir_block
*),
843 compare_block_index
);
845 print_tabs(tabs
, fp
);
846 fprintf(fp
, "/* preds: ");
847 for (unsigned i
= 0; i
< block
->predecessors
->entries
; i
++) {
848 fprintf(fp
, "block_%u ", preds
[i
]->index
);
854 nir_foreach_instr(block
, instr
) {
855 print_instr(instr
, state
, tabs
);
859 print_tabs(tabs
, fp
);
860 fprintf(fp
, "/* succs: ");
861 for (unsigned i
= 0; i
< 2; i
++)
862 if (block
->successors
[i
]) {
863 fprintf(fp
, "block_%u ", block
->successors
[i
]->index
);
869 print_if(nir_if
*if_stmt
, print_state
*state
, unsigned tabs
)
871 FILE *fp
= state
->fp
;
873 print_tabs(tabs
, fp
);
875 print_src(&if_stmt
->condition
, state
);
877 foreach_list_typed(nir_cf_node
, node
, node
, &if_stmt
->then_list
) {
878 print_cf_node(node
, state
, tabs
+ 1);
880 print_tabs(tabs
, fp
);
881 fprintf(fp
, "} else {\n");
882 foreach_list_typed(nir_cf_node
, node
, node
, &if_stmt
->else_list
) {
883 print_cf_node(node
, state
, tabs
+ 1);
885 print_tabs(tabs
, fp
);
890 print_loop(nir_loop
*loop
, print_state
*state
, unsigned tabs
)
892 FILE *fp
= state
->fp
;
894 print_tabs(tabs
, fp
);
895 fprintf(fp
, "loop {\n");
896 foreach_list_typed(nir_cf_node
, node
, node
, &loop
->body
) {
897 print_cf_node(node
, state
, tabs
+ 1);
899 print_tabs(tabs
, fp
);
904 print_cf_node(nir_cf_node
*node
, print_state
*state
, unsigned int tabs
)
906 switch (node
->type
) {
907 case nir_cf_node_block
:
908 print_block(nir_cf_node_as_block(node
), state
, tabs
);
912 print_if(nir_cf_node_as_if(node
), state
, tabs
);
915 case nir_cf_node_loop
:
916 print_loop(nir_cf_node_as_loop(node
), state
, tabs
);
920 unreachable("Invalid CFG node type");
925 print_function_impl(nir_function_impl
*impl
, print_state
*state
)
927 FILE *fp
= state
->fp
;
929 fprintf(fp
, "\nimpl %s ", impl
->function
->name
);
931 for (unsigned i
= 0; i
< impl
->num_params
; i
++) {
935 print_var(impl
->params
[i
], state
);
938 if (impl
->return_var
!= NULL
) {
939 if (impl
->num_params
!= 0)
941 fprintf(fp
, "returning ");
942 print_var(impl
->return_var
, state
);
947 nir_foreach_variable(var
, &impl
->locals
) {
949 print_var_decl(var
, state
);
952 foreach_list_typed(nir_register
, reg
, node
, &impl
->registers
) {
954 print_register_decl(reg
, state
);
957 nir_index_blocks(impl
);
959 foreach_list_typed(nir_cf_node
, node
, node
, &impl
->body
) {
960 print_cf_node(node
, state
, 1);
963 fprintf(fp
, "\tblock block_%u:\n}\n\n", impl
->end_block
->index
);
967 print_function(nir_function
*function
, print_state
*state
)
969 FILE *fp
= state
->fp
;
971 fprintf(fp
, "decl_function %s ", function
->name
);
973 for (unsigned i
= 0; i
< function
->num_params
; i
++) {
977 switch (function
->params
[i
].param_type
) {
978 case nir_parameter_in
:
981 case nir_parameter_out
:
984 case nir_parameter_inout
:
985 fprintf(fp
, "inout ");
988 unreachable("Invalid parameter type");
991 glsl_print_type(function
->params
[i
].type
, fp
);
994 if (function
->return_type
!= NULL
) {
995 if (function
->num_params
!= 0)
997 fprintf(fp
, "returning ");
998 glsl_print_type(function
->return_type
, fp
);
1003 if (function
->impl
!= NULL
) {
1004 print_function_impl(function
->impl
, state
);
1010 init_print_state(print_state
*state
, nir_shader
*shader
, FILE *fp
)
1013 state
->shader
= shader
;
1014 state
->ht
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
1015 _mesa_key_pointer_equal
);
1016 state
->syms
= _mesa_set_create(NULL
, _mesa_key_hash_string
,
1017 _mesa_key_string_equal
);
1022 destroy_print_state(print_state
*state
)
1024 _mesa_hash_table_destroy(state
->ht
, NULL
);
1025 _mesa_set_destroy(state
->syms
, NULL
);
1029 nir_print_shader(nir_shader
*shader
, FILE *fp
)
1032 init_print_state(&state
, shader
, fp
);
1034 fprintf(fp
, "shader: %s\n", gl_shader_stage_name(shader
->stage
));
1036 if (shader
->info
.name
)
1037 fprintf(fp
, "name: %s\n", shader
->info
.name
);
1039 if (shader
->info
.label
)
1040 fprintf(fp
, "label: %s\n", shader
->info
.label
);
1042 fprintf(fp
, "inputs: %u\n", shader
->num_inputs
);
1043 fprintf(fp
, "outputs: %u\n", shader
->num_outputs
);
1044 fprintf(fp
, "uniforms: %u\n", shader
->num_uniforms
);
1046 nir_foreach_variable(var
, &shader
->uniforms
) {
1047 print_var_decl(var
, &state
);
1050 nir_foreach_variable(var
, &shader
->inputs
) {
1051 print_var_decl(var
, &state
);
1054 nir_foreach_variable(var
, &shader
->outputs
) {
1055 print_var_decl(var
, &state
);
1058 nir_foreach_variable(var
, &shader
->globals
) {
1059 print_var_decl(var
, &state
);
1062 nir_foreach_variable(var
, &shader
->system_values
) {
1063 print_var_decl(var
, &state
);
1066 foreach_list_typed(nir_register
, reg
, node
, &shader
->registers
) {
1067 print_register_decl(reg
, &state
);
1070 foreach_list_typed(nir_function
, func
, node
, &shader
->functions
) {
1071 print_function(func
, &state
);
1074 destroy_print_state(&state
);
1078 nir_print_instr(const nir_instr
*instr
, FILE *fp
)
1080 print_state state
= {
1083 print_instr(instr
, &state
, 0);