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 get_var_name(nir_variable
*var
, print_state
*state
)
225 if (state
->ht
== NULL
)
230 struct hash_entry
*entry
= _mesa_hash_table_search(state
->ht
, var
);
235 if (var
->name
== NULL
) {
236 name
= ralloc_asprintf(state
->syms
, "@%u", state
->index
++);
238 struct set_entry
*set_entry
= _mesa_set_search(state
->syms
, var
->name
);
239 if (set_entry
!= NULL
) {
240 /* we have a collision with another name, append an @ + a unique
242 name
= ralloc_asprintf(state
->syms
, "%s@%u", var
->name
,
245 /* Mark this one as seen */
246 _mesa_set_add(state
->syms
, var
->name
);
251 _mesa_hash_table_insert(state
->ht
, var
, name
);
257 print_constant(nir_constant
*c
, const struct glsl_type
*type
, print_state
*state
)
259 FILE *fp
= state
->fp
;
260 unsigned total_elems
= glsl_get_components(type
);
263 switch (glsl_get_base_type(type
)) {
267 for (i
= 0; i
< total_elems
; i
++) {
268 if (i
> 0) fprintf(fp
, ", ");
269 fprintf(fp
, "0x%08x", c
->value
.u
[i
]);
273 case GLSL_TYPE_FLOAT
:
274 for (i
= 0; i
< total_elems
; i
++) {
275 if (i
> 0) fprintf(fp
, ", ");
276 fprintf(fp
, "%f", c
->value
.f
[i
]);
280 case GLSL_TYPE_STRUCT
:
281 for (i
= 0; i
< c
->num_elements
; i
++) {
282 if (i
> 0) fprintf(fp
, ", ");
284 print_constant(c
->elements
[i
], glsl_get_struct_field(type
, i
), state
);
289 case GLSL_TYPE_ARRAY
:
290 for (i
= 0; i
< c
->num_elements
; i
++) {
291 if (i
> 0) fprintf(fp
, ", ");
293 print_constant(c
->elements
[i
], glsl_get_array_element(type
), state
);
299 unreachable("not reached");
304 print_var_decl(nir_variable
*var
, print_state
*state
)
306 FILE *fp
= state
->fp
;
308 fprintf(fp
, "decl_var ");
310 const char *const cent
= (var
->data
.centroid
) ? "centroid " : "";
311 const char *const samp
= (var
->data
.sample
) ? "sample " : "";
312 const char *const patch
= (var
->data
.patch
) ? "patch " : "";
313 const char *const inv
= (var
->data
.invariant
) ? "invariant " : "";
314 const char *const mode
[] = { "shader_in ", "shader_out ", "", "",
315 "uniform ", "shader_storage ", "shared ",
318 fprintf(fp
, "%s%s%s%s%s%s ",
319 cent
, samp
, patch
, inv
, mode
[var
->data
.mode
],
320 glsl_interp_qualifier_name(var
->data
.interpolation
));
322 glsl_print_type(var
->type
, fp
);
324 fprintf(fp
, " %s", get_var_name(var
, state
));
326 if (var
->data
.mode
== nir_var_shader_in
||
327 var
->data
.mode
== nir_var_shader_out
||
328 var
->data
.mode
== nir_var_uniform
||
329 var
->data
.mode
== nir_var_shader_storage
) {
330 const char *loc
= NULL
;
333 switch (state
->shader
->stage
) {
334 case MESA_SHADER_VERTEX
:
335 if (var
->data
.mode
== nir_var_shader_in
)
336 loc
= gl_vert_attrib_name(var
->data
.location
);
337 else if (var
->data
.mode
== nir_var_shader_out
)
338 loc
= gl_varying_slot_name(var
->data
.location
);
340 case MESA_SHADER_GEOMETRY
:
341 if ((var
->data
.mode
== nir_var_shader_in
) ||
342 (var
->data
.mode
== nir_var_shader_out
))
343 loc
= gl_varying_slot_name(var
->data
.location
);
345 case MESA_SHADER_FRAGMENT
:
346 if (var
->data
.mode
== nir_var_shader_in
)
347 loc
= gl_varying_slot_name(var
->data
.location
);
348 else if (var
->data
.mode
== nir_var_shader_out
)
349 loc
= gl_frag_result_name(var
->data
.location
);
351 case MESA_SHADER_TESS_CTRL
:
352 case MESA_SHADER_TESS_EVAL
:
353 case MESA_SHADER_COMPUTE
:
360 snprintf(buf
, sizeof(buf
), "%u", var
->data
.location
);
364 fprintf(fp
, " (%s, %u)", loc
, var
->data
.driver_location
);
367 if (var
->constant_initializer
) {
368 fprintf(fp
, " = { ");
369 print_constant(var
->constant_initializer
, var
->type
, state
);
377 print_var(nir_variable
*var
, print_state
*state
)
379 FILE *fp
= state
->fp
;
380 fprintf(fp
, "%s", get_var_name(var
, state
));
384 print_arg(nir_variable
*var
, print_state
*state
)
386 FILE *fp
= state
->fp
;
387 glsl_print_type(var
->type
, fp
);
388 fprintf(fp
, " %s", get_var_name(var
, state
));
392 print_deref_var(nir_deref_var
*deref
, print_state
*state
)
394 print_var(deref
->var
, state
);
398 print_deref_array(nir_deref_array
*deref
, print_state
*state
)
400 FILE *fp
= state
->fp
;
402 switch (deref
->deref_array_type
) {
403 case nir_deref_array_type_direct
:
404 fprintf(fp
, "%u", deref
->base_offset
);
406 case nir_deref_array_type_indirect
:
407 if (deref
->base_offset
!= 0)
408 fprintf(fp
, "%u + ", deref
->base_offset
);
409 print_src(&deref
->indirect
, state
);
411 case nir_deref_array_type_wildcard
:
419 print_deref_struct(nir_deref_struct
*deref
, const struct glsl_type
*parent_type
,
422 FILE *fp
= state
->fp
;
423 fprintf(fp
, ".%s", glsl_get_struct_elem_name(parent_type
, deref
->index
));
427 print_deref(nir_deref_var
*deref
, print_state
*state
)
429 nir_deref
*tail
= &deref
->deref
;
430 nir_deref
*pretail
= NULL
;
431 while (tail
!= NULL
) {
432 switch (tail
->deref_type
) {
433 case nir_deref_type_var
:
434 assert(pretail
== NULL
);
435 assert(tail
== &deref
->deref
);
436 print_deref_var(deref
, state
);
439 case nir_deref_type_array
:
440 assert(pretail
!= NULL
);
441 print_deref_array(nir_deref_as_array(tail
), state
);
444 case nir_deref_type_struct
:
445 assert(pretail
!= NULL
);
446 print_deref_struct(nir_deref_as_struct(tail
),
447 pretail
->type
, state
);
451 unreachable("Invalid deref type");
455 tail
= pretail
->child
;
460 print_intrinsic_instr(nir_intrinsic_instr
*instr
, print_state
*state
)
462 const nir_intrinsic_info
*info
= &nir_intrinsic_infos
[instr
->intrinsic
];
463 unsigned num_srcs
= info
->num_srcs
;
464 FILE *fp
= state
->fp
;
466 if (info
->has_dest
) {
467 print_dest(&instr
->dest
, state
);
471 fprintf(fp
, "intrinsic %s (", info
->name
);
473 for (unsigned i
= 0; i
< num_srcs
; i
++) {
477 print_src(&instr
->src
[i
], state
);
482 for (unsigned i
= 0; i
< info
->num_variables
; i
++) {
486 print_deref(instr
->variables
[i
], state
);
491 for (unsigned i
= 0; i
< info
->num_indices
; i
++) {
495 fprintf(fp
, "%d", instr
->const_index
[i
]);
500 static const char *index_name
[NIR_INTRINSIC_NUM_INDEX_FLAGS
] = {
501 [NIR_INTRINSIC_BASE
] = "base",
502 [NIR_INTRINSIC_WRMASK
] = "wrmask",
503 [NIR_INTRINSIC_STREAM_ID
] = "stream-id",
504 [NIR_INTRINSIC_UCP_ID
] = "ucp-id",
505 [NIR_INTRINSIC_RANGE
] = "range",
506 [NIR_INTRINSIC_DESC_SET
] = "desc-set",
507 [NIR_INTRINSIC_BINDING
] = "binding",
509 for (unsigned idx
= 1; idx
< NIR_INTRINSIC_NUM_INDEX_FLAGS
; idx
++) {
510 if (!info
->index_map
[idx
])
513 if (idx
== NIR_INTRINSIC_WRMASK
) {
514 /* special case wrmask to show it as a writemask.. */
515 unsigned wrmask
= nir_intrinsic_write_mask(instr
);
516 fprintf(fp
, " wrmask=");
517 for (unsigned i
= 0; i
< 4; i
++)
518 if ((wrmask
>> i
) & 1)
519 fprintf(fp
, "%c", "xyzw"[i
]);
521 unsigned off
= info
->index_map
[idx
] - 1;
522 assert(index_name
[idx
]); /* forgot to update index_name table? */
523 fprintf(fp
, " %s=%d", index_name
[idx
], instr
->const_index
[off
]);
531 struct exec_list
*var_list
= NULL
;
533 switch (instr
->intrinsic
) {
534 case nir_intrinsic_load_uniform
:
535 var_list
= &state
->shader
->uniforms
;
537 case nir_intrinsic_load_input
:
538 case nir_intrinsic_load_per_vertex_input
:
539 var_list
= &state
->shader
->inputs
;
541 case nir_intrinsic_load_output
:
542 case nir_intrinsic_store_output
:
543 case nir_intrinsic_store_per_vertex_output
:
544 var_list
= &state
->shader
->outputs
;
550 nir_foreach_variable(var
, var_list
) {
551 if ((var
->data
.driver_location
== nir_intrinsic_base(instr
)) &&
553 fprintf(fp
, "\t/* %s */", var
->name
);
560 print_tex_instr(nir_tex_instr
*instr
, print_state
*state
)
562 FILE *fp
= state
->fp
;
564 print_dest(&instr
->dest
, state
);
584 case nir_texop_txf_ms
:
585 fprintf(fp
, "txf_ms ");
596 case nir_texop_query_levels
:
597 fprintf(fp
, "query_levels ");
599 case nir_texop_texture_samples
:
600 fprintf(fp
, "texture_samples ");
602 case nir_texop_samples_identical
:
603 fprintf(fp
, "samples_identical ");
606 unreachable("Invalid texture operation");
610 for (unsigned i
= 0; i
< instr
->num_srcs
; i
++) {
611 print_src(&instr
->src
[i
].src
, state
);
615 switch(instr
->src
[i
].src_type
) {
616 case nir_tex_src_coord
:
617 fprintf(fp
, "(coord)");
619 case nir_tex_src_projector
:
620 fprintf(fp
, "(projector)");
622 case nir_tex_src_comparitor
:
623 fprintf(fp
, "(comparitor)");
625 case nir_tex_src_offset
:
626 fprintf(fp
, "(offset)");
628 case nir_tex_src_bias
:
629 fprintf(fp
, "(bias)");
631 case nir_tex_src_lod
:
632 fprintf(fp
, "(lod)");
634 case nir_tex_src_ms_index
:
635 fprintf(fp
, "(ms_index)");
637 case nir_tex_src_ddx
:
638 fprintf(fp
, "(ddx)");
640 case nir_tex_src_ddy
:
641 fprintf(fp
, "(ddy)");
643 case nir_tex_src_texture_offset
:
644 fprintf(fp
, "(texture_offset)");
646 case nir_tex_src_sampler_offset
:
647 fprintf(fp
, "(sampler_offset)");
651 unreachable("Invalid texture source type");
658 if (instr
->op
== nir_texop_tg4
) {
659 fprintf(fp
, "%u (gather_component), ", instr
->component
);
662 if (instr
->texture
) {
663 print_deref(instr
->texture
, state
);
664 fprintf(fp
, " (texture)");
665 if (instr
->sampler
) {
666 print_deref(instr
->sampler
, state
);
667 fprintf(fp
, " (sampler)");
670 assert(instr
->sampler
== NULL
);
671 fprintf(fp
, "%u (texture) %u (sampler)",
672 instr
->texture_index
, instr
->sampler_index
);
677 print_call_instr(nir_call_instr
*instr
, print_state
*state
)
679 FILE *fp
= state
->fp
;
681 fprintf(fp
, "call %s ", instr
->callee
->name
);
683 for (unsigned i
= 0; i
< instr
->num_params
; i
++) {
687 print_deref(instr
->params
[i
], state
);
690 if (instr
->return_deref
!= NULL
) {
691 if (instr
->num_params
!= 0)
693 fprintf(fp
, "returning ");
694 print_deref(instr
->return_deref
, state
);
699 print_load_const_instr(nir_load_const_instr
*instr
, print_state
*state
)
701 FILE *fp
= state
->fp
;
703 print_ssa_def(&instr
->def
, state
);
705 fprintf(fp
, " = load_const (");
707 for (unsigned i
= 0; i
< instr
->def
.num_components
; i
++) {
712 * we don't really know the type of the constant (if it will be used as a
713 * float or an int), so just print the raw constant in hex for fidelity
714 * and then print the float in a comment for readability.
717 fprintf(fp
, "0x%08x /* %f */", instr
->value
.u
[i
], instr
->value
.f
[i
]);
724 print_jump_instr(nir_jump_instr
*instr
, print_state
*state
)
726 FILE *fp
= state
->fp
;
728 switch (instr
->type
) {
730 fprintf(fp
, "break");
733 case nir_jump_continue
:
734 fprintf(fp
, "continue");
737 case nir_jump_return
:
738 fprintf(fp
, "return");
744 print_ssa_undef_instr(nir_ssa_undef_instr
* instr
, print_state
*state
)
746 FILE *fp
= state
->fp
;
747 print_ssa_def(&instr
->def
, state
);
748 fprintf(fp
, " = undefined");
752 print_phi_instr(nir_phi_instr
*instr
, print_state
*state
)
754 FILE *fp
= state
->fp
;
755 print_dest(&instr
->dest
, state
);
756 fprintf(fp
, " = phi ");
757 nir_foreach_phi_src(instr
, src
) {
758 if (&src
->node
!= exec_list_get_head(&instr
->srcs
))
761 fprintf(fp
, "block_%u: ", src
->pred
->index
);
762 print_src(&src
->src
, state
);
767 print_parallel_copy_instr(nir_parallel_copy_instr
*instr
, print_state
*state
)
769 FILE *fp
= state
->fp
;
770 nir_foreach_parallel_copy_entry(instr
, entry
) {
771 if (&entry
->node
!= exec_list_get_head(&instr
->entries
))
774 print_dest(&entry
->dest
, state
);
776 print_src(&entry
->src
, state
);
781 print_instr(const nir_instr
*instr
, print_state
*state
, unsigned tabs
)
783 FILE *fp
= state
->fp
;
784 print_tabs(tabs
, fp
);
786 switch (instr
->type
) {
787 case nir_instr_type_alu
:
788 print_alu_instr(nir_instr_as_alu(instr
), state
);
791 case nir_instr_type_call
:
792 print_call_instr(nir_instr_as_call(instr
), state
);
795 case nir_instr_type_intrinsic
:
796 print_intrinsic_instr(nir_instr_as_intrinsic(instr
), state
);
799 case nir_instr_type_tex
:
800 print_tex_instr(nir_instr_as_tex(instr
), state
);
803 case nir_instr_type_load_const
:
804 print_load_const_instr(nir_instr_as_load_const(instr
), state
);
807 case nir_instr_type_jump
:
808 print_jump_instr(nir_instr_as_jump(instr
), state
);
811 case nir_instr_type_ssa_undef
:
812 print_ssa_undef_instr(nir_instr_as_ssa_undef(instr
), state
);
815 case nir_instr_type_phi
:
816 print_phi_instr(nir_instr_as_phi(instr
), state
);
819 case nir_instr_type_parallel_copy
:
820 print_parallel_copy_instr(nir_instr_as_parallel_copy(instr
), state
);
824 unreachable("Invalid instruction type");
830 compare_block_index(const void *p1
, const void *p2
)
832 const nir_block
*block1
= *((const nir_block
**) p1
);
833 const nir_block
*block2
= *((const nir_block
**) p2
);
835 return (int) block1
->index
- (int) block2
->index
;
838 static void print_cf_node(nir_cf_node
*node
, print_state
*state
,
842 print_block(nir_block
*block
, print_state
*state
, unsigned tabs
)
844 FILE *fp
= state
->fp
;
846 print_tabs(tabs
, fp
);
847 fprintf(fp
, "block block_%u:\n", block
->index
);
849 /* sort the predecessors by index so we consistently print the same thing */
852 malloc(block
->predecessors
->entries
* sizeof(nir_block
*));
854 struct set_entry
*entry
;
856 set_foreach(block
->predecessors
, entry
) {
857 preds
[i
++] = (nir_block
*) entry
->key
;
860 qsort(preds
, block
->predecessors
->entries
, sizeof(nir_block
*),
861 compare_block_index
);
863 print_tabs(tabs
, fp
);
864 fprintf(fp
, "/* preds: ");
865 for (unsigned i
= 0; i
< block
->predecessors
->entries
; i
++) {
866 fprintf(fp
, "block_%u ", preds
[i
]->index
);
872 nir_foreach_instr(block
, instr
) {
873 print_instr(instr
, state
, tabs
);
877 print_tabs(tabs
, fp
);
878 fprintf(fp
, "/* succs: ");
879 for (unsigned i
= 0; i
< 2; i
++)
880 if (block
->successors
[i
]) {
881 fprintf(fp
, "block_%u ", block
->successors
[i
]->index
);
887 print_if(nir_if
*if_stmt
, print_state
*state
, unsigned tabs
)
889 FILE *fp
= state
->fp
;
891 print_tabs(tabs
, fp
);
893 print_src(&if_stmt
->condition
, state
);
895 foreach_list_typed(nir_cf_node
, node
, node
, &if_stmt
->then_list
) {
896 print_cf_node(node
, state
, tabs
+ 1);
898 print_tabs(tabs
, fp
);
899 fprintf(fp
, "} else {\n");
900 foreach_list_typed(nir_cf_node
, node
, node
, &if_stmt
->else_list
) {
901 print_cf_node(node
, state
, tabs
+ 1);
903 print_tabs(tabs
, fp
);
908 print_loop(nir_loop
*loop
, print_state
*state
, unsigned tabs
)
910 FILE *fp
= state
->fp
;
912 print_tabs(tabs
, fp
);
913 fprintf(fp
, "loop {\n");
914 foreach_list_typed(nir_cf_node
, node
, node
, &loop
->body
) {
915 print_cf_node(node
, state
, tabs
+ 1);
917 print_tabs(tabs
, fp
);
922 print_cf_node(nir_cf_node
*node
, print_state
*state
, unsigned int tabs
)
924 switch (node
->type
) {
925 case nir_cf_node_block
:
926 print_block(nir_cf_node_as_block(node
), state
, tabs
);
930 print_if(nir_cf_node_as_if(node
), state
, tabs
);
933 case nir_cf_node_loop
:
934 print_loop(nir_cf_node_as_loop(node
), state
, tabs
);
938 unreachable("Invalid CFG node type");
943 print_function_impl(nir_function_impl
*impl
, print_state
*state
)
945 FILE *fp
= state
->fp
;
947 fprintf(fp
, "\nimpl %s ", impl
->function
->name
);
949 for (unsigned i
= 0; i
< impl
->num_params
; i
++) {
953 print_arg(impl
->params
[i
], state
);
956 if (impl
->return_var
!= NULL
) {
957 if (impl
->num_params
!= 0)
959 fprintf(fp
, "returning ");
960 print_arg(impl
->return_var
, state
);
965 for (unsigned i
= 0; i
< impl
->num_params
; i
++) {
967 print_var_decl(impl
->params
[i
], state
);
970 if (impl
->return_var
) {
972 print_var_decl(impl
->return_var
, state
);
975 nir_foreach_variable(var
, &impl
->locals
) {
977 print_var_decl(var
, state
);
980 foreach_list_typed(nir_register
, reg
, node
, &impl
->registers
) {
982 print_register_decl(reg
, state
);
985 nir_index_blocks(impl
);
987 foreach_list_typed(nir_cf_node
, node
, node
, &impl
->body
) {
988 print_cf_node(node
, state
, 1);
991 fprintf(fp
, "\tblock block_%u:\n}\n\n", impl
->end_block
->index
);
995 print_function(nir_function
*function
, print_state
*state
)
997 FILE *fp
= state
->fp
;
999 fprintf(fp
, "decl_function %s ", function
->name
);
1001 for (unsigned i
= 0; i
< function
->num_params
; i
++) {
1005 switch (function
->params
[i
].param_type
) {
1006 case nir_parameter_in
:
1009 case nir_parameter_out
:
1010 fprintf(fp
, "out ");
1012 case nir_parameter_inout
:
1013 fprintf(fp
, "inout ");
1016 unreachable("Invalid parameter type");
1019 glsl_print_type(function
->params
[i
].type
, fp
);
1022 if (function
->return_type
!= NULL
) {
1023 if (function
->num_params
!= 0)
1025 fprintf(fp
, "returning ");
1026 glsl_print_type(function
->return_type
, fp
);
1031 if (function
->impl
!= NULL
) {
1032 print_function_impl(function
->impl
, state
);
1038 init_print_state(print_state
*state
, nir_shader
*shader
, FILE *fp
)
1041 state
->shader
= shader
;
1042 state
->ht
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
1043 _mesa_key_pointer_equal
);
1044 state
->syms
= _mesa_set_create(NULL
, _mesa_key_hash_string
,
1045 _mesa_key_string_equal
);
1050 destroy_print_state(print_state
*state
)
1052 _mesa_hash_table_destroy(state
->ht
, NULL
);
1053 _mesa_set_destroy(state
->syms
, NULL
);
1057 nir_print_shader(nir_shader
*shader
, FILE *fp
)
1060 init_print_state(&state
, shader
, fp
);
1062 fprintf(fp
, "shader: %s\n", gl_shader_stage_name(shader
->stage
));
1064 if (shader
->info
.name
)
1065 fprintf(fp
, "name: %s\n", shader
->info
.name
);
1067 if (shader
->info
.label
)
1068 fprintf(fp
, "label: %s\n", shader
->info
.label
);
1070 fprintf(fp
, "inputs: %u\n", shader
->num_inputs
);
1071 fprintf(fp
, "outputs: %u\n", shader
->num_outputs
);
1072 fprintf(fp
, "uniforms: %u\n", shader
->num_uniforms
);
1073 fprintf(fp
, "shared: %u\n", shader
->num_shared
);
1075 nir_foreach_variable(var
, &shader
->uniforms
) {
1076 print_var_decl(var
, &state
);
1079 nir_foreach_variable(var
, &shader
->inputs
) {
1080 print_var_decl(var
, &state
);
1083 nir_foreach_variable(var
, &shader
->outputs
) {
1084 print_var_decl(var
, &state
);
1087 nir_foreach_variable(var
, &shader
->shared
) {
1088 print_var_decl(var
, &state
);
1091 nir_foreach_variable(var
, &shader
->globals
) {
1092 print_var_decl(var
, &state
);
1095 nir_foreach_variable(var
, &shader
->system_values
) {
1096 print_var_decl(var
, &state
);
1099 foreach_list_typed(nir_register
, reg
, node
, &shader
->registers
) {
1100 print_register_decl(reg
, &state
);
1103 foreach_list_typed(nir_function
, func
, node
, &shader
->functions
) {
1104 print_function(func
, &state
);
1107 destroy_print_state(&state
);
1111 nir_print_instr(const nir_instr
*instr
, FILE *fp
)
1113 print_state state
= {
1116 print_instr(instr
, &state
, 0);