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 "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_var_decl(nir_variable
*var
, print_state
*state
)
225 FILE *fp
= state
->fp
;
227 fprintf(fp
, "decl_var ");
229 const char *const cent
= (var
->data
.centroid
) ? "centroid " : "";
230 const char *const samp
= (var
->data
.sample
) ? "sample " : "";
231 const char *const patch
= (var
->data
.patch
) ? "patch " : "";
232 const char *const inv
= (var
->data
.invariant
) ? "invariant " : "";
233 const char *const mode
[] = { "shader_in ", "shader_out ", "", "",
234 "uniform ", "shader_storage", "system " };
236 fprintf(fp
, "%s%s%s%s%s%s ",
237 cent
, samp
, patch
, inv
, mode
[var
->data
.mode
],
238 glsl_interp_qualifier_name(var
->data
.interpolation
));
240 glsl_print_type(var
->type
, fp
);
242 struct set_entry
*entry
= NULL
;
244 entry
= _mesa_set_search(state
->syms
, var
->name
);
249 /* we have a collision with another name, append an @ + a unique index */
250 name
= ralloc_asprintf(state
->syms
, "%s@%u", var
->name
, state
->index
++);
255 fprintf(fp
, " %s", name
);
257 if (var
->data
.mode
== nir_var_shader_in
||
258 var
->data
.mode
== nir_var_shader_out
||
259 var
->data
.mode
== nir_var_uniform
||
260 var
->data
.mode
== nir_var_shader_storage
) {
261 const char *loc
= NULL
;
264 switch (state
->shader
->stage
) {
265 case MESA_SHADER_VERTEX
:
266 if (var
->data
.mode
== nir_var_shader_in
)
267 loc
= gl_vert_attrib_name(var
->data
.location
);
268 else if (var
->data
.mode
== nir_var_shader_out
)
269 loc
= gl_varying_slot_name(var
->data
.location
);
271 case MESA_SHADER_GEOMETRY
:
272 if ((var
->data
.mode
== nir_var_shader_in
) ||
273 (var
->data
.mode
== nir_var_shader_out
))
274 loc
= gl_varying_slot_name(var
->data
.location
);
276 case MESA_SHADER_FRAGMENT
:
277 if (var
->data
.mode
== nir_var_shader_in
)
278 loc
= gl_varying_slot_name(var
->data
.location
);
279 else if (var
->data
.mode
== nir_var_shader_out
)
280 loc
= gl_frag_result_name(var
->data
.location
);
282 case MESA_SHADER_TESS_CTRL
:
283 case MESA_SHADER_TESS_EVAL
:
284 case MESA_SHADER_COMPUTE
:
291 snprintf(buf
, sizeof(buf
), "%u", var
->data
.location
);
295 fprintf(fp
, " (%s, %u)", loc
, var
->data
.driver_location
);
301 _mesa_set_add(state
->syms
, name
);
302 _mesa_hash_table_insert(state
->ht
, var
, name
);
307 print_var(nir_variable
*var
, print_state
*state
)
309 FILE *fp
= state
->fp
;
312 struct hash_entry
*entry
= _mesa_hash_table_search(state
->ht
, var
);
314 assert(entry
!= NULL
);
320 fprintf(fp
, "%s", name
);
324 print_deref_var(nir_deref_var
*deref
, print_state
*state
)
326 print_var(deref
->var
, state
);
330 print_deref_array(nir_deref_array
*deref
, print_state
*state
)
332 FILE *fp
= state
->fp
;
334 switch (deref
->deref_array_type
) {
335 case nir_deref_array_type_direct
:
336 fprintf(fp
, "%u", deref
->base_offset
);
338 case nir_deref_array_type_indirect
:
339 if (deref
->base_offset
!= 0)
340 fprintf(fp
, "%u + ", deref
->base_offset
);
341 print_src(&deref
->indirect
, state
);
343 case nir_deref_array_type_wildcard
:
351 print_deref_struct(nir_deref_struct
*deref
, const struct glsl_type
*parent_type
,
354 FILE *fp
= state
->fp
;
355 fprintf(fp
, ".%s", glsl_get_struct_elem_name(parent_type
, deref
->index
));
359 print_deref(nir_deref_var
*deref
, print_state
*state
)
361 nir_deref
*tail
= &deref
->deref
;
362 nir_deref
*pretail
= NULL
;
363 while (tail
!= NULL
) {
364 switch (tail
->deref_type
) {
365 case nir_deref_type_var
:
366 assert(pretail
== NULL
);
367 assert(tail
== &deref
->deref
);
368 print_deref_var(deref
, state
);
371 case nir_deref_type_array
:
372 assert(pretail
!= NULL
);
373 print_deref_array(nir_deref_as_array(tail
), state
);
376 case nir_deref_type_struct
:
377 assert(pretail
!= NULL
);
378 print_deref_struct(nir_deref_as_struct(tail
),
379 pretail
->type
, state
);
383 unreachable("Invalid deref type");
387 tail
= pretail
->child
;
392 print_intrinsic_instr(nir_intrinsic_instr
*instr
, print_state
*state
)
394 unsigned num_srcs
= nir_intrinsic_infos
[instr
->intrinsic
].num_srcs
;
395 FILE *fp
= state
->fp
;
397 if (nir_intrinsic_infos
[instr
->intrinsic
].has_dest
) {
398 print_dest(&instr
->dest
, state
);
402 fprintf(fp
, "intrinsic %s (", nir_intrinsic_infos
[instr
->intrinsic
].name
);
404 for (unsigned i
= 0; i
< num_srcs
; i
++) {
408 print_src(&instr
->src
[i
], state
);
413 unsigned num_vars
= nir_intrinsic_infos
[instr
->intrinsic
].num_variables
;
415 for (unsigned i
= 0; i
< num_vars
; i
++) {
419 print_deref(instr
->variables
[i
], state
);
424 unsigned num_indices
= nir_intrinsic_infos
[instr
->intrinsic
].num_indices
;
426 for (unsigned i
= 0; i
< num_indices
; i
++) {
430 fprintf(fp
, "%u", instr
->const_index
[i
]);
438 struct exec_list
*var_list
= NULL
;
440 switch (instr
->intrinsic
) {
441 case nir_intrinsic_load_uniform
:
442 case nir_intrinsic_load_uniform_indirect
:
443 var_list
= &state
->shader
->uniforms
;
445 case nir_intrinsic_load_input
:
446 case nir_intrinsic_load_input_indirect
:
447 case nir_intrinsic_load_per_vertex_input
:
448 case nir_intrinsic_load_per_vertex_input_indirect
:
449 var_list
= &state
->shader
->inputs
;
451 case nir_intrinsic_load_output
:
452 case nir_intrinsic_load_output_indirect
:
453 case nir_intrinsic_store_output
:
454 case nir_intrinsic_store_output_indirect
:
455 case nir_intrinsic_store_per_vertex_output
:
456 case nir_intrinsic_store_per_vertex_output_indirect
:
457 var_list
= &state
->shader
->outputs
;
463 nir_foreach_variable(var
, var_list
) {
464 if ((var
->data
.driver_location
== instr
->const_index
[0]) &&
466 fprintf(fp
, "\t/* %s */", var
->name
);
473 print_tex_instr(nir_tex_instr
*instr
, print_state
*state
)
475 FILE *fp
= state
->fp
;
477 print_dest(&instr
->dest
, state
);
497 case nir_texop_txf_ms
:
498 fprintf(fp
, "txf_ms ");
509 case nir_texop_query_levels
:
510 fprintf(fp
, "query_levels ");
512 case nir_texop_texture_samples
:
513 fprintf(fp
, "texture_samples ");
517 unreachable("Invalid texture operation");
521 for (unsigned i
= 0; i
< instr
->num_srcs
; i
++) {
522 print_src(&instr
->src
[i
].src
, state
);
526 switch(instr
->src
[i
].src_type
) {
527 case nir_tex_src_coord
:
528 fprintf(fp
, "(coord)");
530 case nir_tex_src_projector
:
531 fprintf(fp
, "(projector)");
533 case nir_tex_src_comparitor
:
534 fprintf(fp
, "(comparitor)");
536 case nir_tex_src_offset
:
537 fprintf(fp
, "(offset)");
539 case nir_tex_src_bias
:
540 fprintf(fp
, "(bias)");
542 case nir_tex_src_lod
:
543 fprintf(fp
, "(lod)");
545 case nir_tex_src_ms_index
:
546 fprintf(fp
, "(ms_index)");
548 case nir_tex_src_ddx
:
549 fprintf(fp
, "(ddx)");
551 case nir_tex_src_ddy
:
552 fprintf(fp
, "(ddy)");
554 case nir_tex_src_texture_offset
:
555 fprintf(fp
, "(texture_offset)");
557 case nir_tex_src_sampler_offset
:
558 fprintf(fp
, "(sampler_offset)");
562 unreachable("Invalid texture source type");
569 bool has_nonzero_offset
= false;
570 for (unsigned i
= 0; i
< 4; i
++) {
571 if (instr
->const_offset
[i
] != 0) {
572 has_nonzero_offset
= true;
577 if (has_nonzero_offset
) {
578 fprintf(fp
, "[%i %i %i %i] (offset), ",
579 instr
->const_offset
[0], instr
->const_offset
[1],
580 instr
->const_offset
[2], instr
->const_offset
[3]);
583 if (instr
->op
== nir_texop_tg4
) {
584 fprintf(fp
, "%u (gather_component), ", instr
->component
);
587 if (instr
->texture
) {
588 assert(instr
->sampler
);
589 fprintf(fp
, " (texture)");
591 if (instr
->sampler
) {
592 print_deref(instr
->sampler
, state
);
593 fprintf(fp
, " (sampler)");
595 assert(instr
->texture
== NULL
);
596 fprintf(fp
, "%u (texture) %u (sampler)",
597 instr
->texture_index
, instr
->sampler_index
);
602 print_call_instr(nir_call_instr
*instr
, print_state
*state
)
604 FILE *fp
= state
->fp
;
606 fprintf(fp
, "call %s ", instr
->callee
->function
->name
);
608 for (unsigned i
= 0; i
< instr
->num_params
; i
++) {
612 print_deref(instr
->params
[i
], state
);
615 if (instr
->return_deref
!= NULL
) {
616 if (instr
->num_params
!= 0)
618 fprintf(fp
, "returning ");
619 print_deref(instr
->return_deref
, state
);
624 print_load_const_instr(nir_load_const_instr
*instr
, print_state
*state
)
626 FILE *fp
= state
->fp
;
628 print_ssa_def(&instr
->def
, state
);
630 fprintf(fp
, " = load_const (");
632 for (unsigned i
= 0; i
< instr
->def
.num_components
; i
++) {
637 * we don't really know the type of the constant (if it will be used as a
638 * float or an int), so just print the raw constant in hex for fidelity
639 * and then print the float in a comment for readability.
642 fprintf(fp
, "0x%08x /* %f */", instr
->value
.u
[i
], instr
->value
.f
[i
]);
649 print_jump_instr(nir_jump_instr
*instr
, print_state
*state
)
651 FILE *fp
= state
->fp
;
653 switch (instr
->type
) {
655 fprintf(fp
, "break");
658 case nir_jump_continue
:
659 fprintf(fp
, "continue");
662 case nir_jump_return
:
663 fprintf(fp
, "return");
669 print_ssa_undef_instr(nir_ssa_undef_instr
* instr
, print_state
*state
)
671 FILE *fp
= state
->fp
;
672 print_ssa_def(&instr
->def
, state
);
673 fprintf(fp
, " = undefined");
677 print_phi_instr(nir_phi_instr
*instr
, print_state
*state
)
679 FILE *fp
= state
->fp
;
680 print_dest(&instr
->dest
, state
);
681 fprintf(fp
, " = phi ");
682 nir_foreach_phi_src(instr
, src
) {
683 if (&src
->node
!= exec_list_get_head(&instr
->srcs
))
686 fprintf(fp
, "block_%u: ", src
->pred
->index
);
687 print_src(&src
->src
, state
);
692 print_parallel_copy_instr(nir_parallel_copy_instr
*instr
, print_state
*state
)
694 FILE *fp
= state
->fp
;
695 nir_foreach_parallel_copy_entry(instr
, entry
) {
696 if (&entry
->node
!= exec_list_get_head(&instr
->entries
))
699 print_dest(&entry
->dest
, state
);
701 print_src(&entry
->src
, state
);
706 print_instr(const nir_instr
*instr
, print_state
*state
, unsigned tabs
)
708 FILE *fp
= state
->fp
;
709 print_tabs(tabs
, fp
);
711 switch (instr
->type
) {
712 case nir_instr_type_alu
:
713 print_alu_instr(nir_instr_as_alu(instr
), state
);
716 case nir_instr_type_call
:
717 print_call_instr(nir_instr_as_call(instr
), state
);
720 case nir_instr_type_intrinsic
:
721 print_intrinsic_instr(nir_instr_as_intrinsic(instr
), state
);
724 case nir_instr_type_tex
:
725 print_tex_instr(nir_instr_as_tex(instr
), state
);
728 case nir_instr_type_load_const
:
729 print_load_const_instr(nir_instr_as_load_const(instr
), state
);
732 case nir_instr_type_jump
:
733 print_jump_instr(nir_instr_as_jump(instr
), state
);
736 case nir_instr_type_ssa_undef
:
737 print_ssa_undef_instr(nir_instr_as_ssa_undef(instr
), state
);
740 case nir_instr_type_phi
:
741 print_phi_instr(nir_instr_as_phi(instr
), state
);
744 case nir_instr_type_parallel_copy
:
745 print_parallel_copy_instr(nir_instr_as_parallel_copy(instr
), state
);
749 unreachable("Invalid instruction type");
755 compare_block_index(const void *p1
, const void *p2
)
757 const nir_block
*block1
= *((const nir_block
**) p1
);
758 const nir_block
*block2
= *((const nir_block
**) p2
);
760 return (int) block1
->index
- (int) block2
->index
;
763 static void print_cf_node(nir_cf_node
*node
, print_state
*state
,
767 print_block(nir_block
*block
, print_state
*state
, unsigned tabs
)
769 FILE *fp
= state
->fp
;
771 print_tabs(tabs
, fp
);
772 fprintf(fp
, "block block_%u:\n", block
->index
);
774 /* sort the predecessors by index so we consistently print the same thing */
777 malloc(block
->predecessors
->entries
* sizeof(nir_block
*));
779 struct set_entry
*entry
;
781 set_foreach(block
->predecessors
, entry
) {
782 preds
[i
++] = (nir_block
*) entry
->key
;
785 qsort(preds
, block
->predecessors
->entries
, sizeof(nir_block
*),
786 compare_block_index
);
788 print_tabs(tabs
, fp
);
789 fprintf(fp
, "/* preds: ");
790 for (unsigned i
= 0; i
< block
->predecessors
->entries
; i
++) {
791 fprintf(fp
, "block_%u ", preds
[i
]->index
);
797 nir_foreach_instr(block
, instr
) {
798 print_instr(instr
, state
, tabs
);
802 print_tabs(tabs
, fp
);
803 fprintf(fp
, "/* succs: ");
804 for (unsigned i
= 0; i
< 2; i
++)
805 if (block
->successors
[i
]) {
806 fprintf(fp
, "block_%u ", block
->successors
[i
]->index
);
812 print_if(nir_if
*if_stmt
, print_state
*state
, unsigned tabs
)
814 FILE *fp
= state
->fp
;
816 print_tabs(tabs
, fp
);
818 print_src(&if_stmt
->condition
, state
);
820 foreach_list_typed(nir_cf_node
, node
, node
, &if_stmt
->then_list
) {
821 print_cf_node(node
, state
, tabs
+ 1);
823 print_tabs(tabs
, fp
);
824 fprintf(fp
, "} else {\n");
825 foreach_list_typed(nir_cf_node
, node
, node
, &if_stmt
->else_list
) {
826 print_cf_node(node
, state
, tabs
+ 1);
828 print_tabs(tabs
, fp
);
833 print_loop(nir_loop
*loop
, print_state
*state
, unsigned tabs
)
835 FILE *fp
= state
->fp
;
837 print_tabs(tabs
, fp
);
838 fprintf(fp
, "loop {\n");
839 foreach_list_typed(nir_cf_node
, node
, node
, &loop
->body
) {
840 print_cf_node(node
, state
, tabs
+ 1);
842 print_tabs(tabs
, fp
);
847 print_cf_node(nir_cf_node
*node
, print_state
*state
, unsigned int tabs
)
849 switch (node
->type
) {
850 case nir_cf_node_block
:
851 print_block(nir_cf_node_as_block(node
), state
, tabs
);
855 print_if(nir_cf_node_as_if(node
), state
, tabs
);
858 case nir_cf_node_loop
:
859 print_loop(nir_cf_node_as_loop(node
), state
, tabs
);
863 unreachable("Invalid CFG node type");
868 print_function_impl(nir_function_impl
*impl
, print_state
*state
)
870 FILE *fp
= state
->fp
;
872 fprintf(fp
, "\nimpl %s ", impl
->overload
->function
->name
);
874 for (unsigned i
= 0; i
< impl
->num_params
; i
++) {
878 print_var(impl
->params
[i
], state
);
881 if (impl
->return_var
!= NULL
) {
882 if (impl
->num_params
!= 0)
884 fprintf(fp
, "returning ");
885 print_var(impl
->return_var
, state
);
890 nir_foreach_variable(var
, &impl
->locals
) {
892 print_var_decl(var
, state
);
895 foreach_list_typed(nir_register
, reg
, node
, &impl
->registers
) {
897 print_register_decl(reg
, state
);
900 nir_index_blocks(impl
);
902 foreach_list_typed(nir_cf_node
, node
, node
, &impl
->body
) {
903 print_cf_node(node
, state
, 1);
906 fprintf(fp
, "\tblock block_%u:\n}\n\n", impl
->end_block
->index
);
910 print_function_overload(nir_function_overload
*overload
,
913 FILE *fp
= state
->fp
;
915 fprintf(fp
, "decl_overload %s ", overload
->function
->name
);
917 for (unsigned i
= 0; i
< overload
->num_params
; i
++) {
921 switch (overload
->params
[i
].param_type
) {
922 case nir_parameter_in
:
925 case nir_parameter_out
:
928 case nir_parameter_inout
:
929 fprintf(fp
, "inout ");
932 unreachable("Invalid parameter type");
935 glsl_print_type(overload
->params
[i
].type
, fp
);
938 if (overload
->return_type
!= NULL
) {
939 if (overload
->num_params
!= 0)
941 fprintf(fp
, "returning ");
942 glsl_print_type(overload
->return_type
, fp
);
947 if (overload
->impl
!= NULL
) {
948 print_function_impl(overload
->impl
, state
);
954 print_function(nir_function
*func
, print_state
*state
)
956 foreach_list_typed(nir_function_overload
, overload
, node
, &func
->overload_list
) {
957 print_function_overload(overload
, state
);
962 init_print_state(print_state
*state
, nir_shader
*shader
, FILE *fp
)
965 state
->shader
= shader
;
966 state
->ht
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
967 _mesa_key_pointer_equal
);
968 state
->syms
= _mesa_set_create(NULL
, _mesa_key_hash_string
,
969 _mesa_key_string_equal
);
974 destroy_print_state(print_state
*state
)
976 _mesa_hash_table_destroy(state
->ht
, NULL
);
977 _mesa_set_destroy(state
->syms
, NULL
);
981 nir_print_shader(nir_shader
*shader
, FILE *fp
)
984 init_print_state(&state
, shader
, fp
);
986 fprintf(fp
, "shader: %s\n", gl_shader_stage_name(shader
->stage
));
988 nir_foreach_variable(var
, &shader
->uniforms
) {
989 print_var_decl(var
, &state
);
992 nir_foreach_variable(var
, &shader
->inputs
) {
993 print_var_decl(var
, &state
);
996 nir_foreach_variable(var
, &shader
->outputs
) {
997 print_var_decl(var
, &state
);
1000 nir_foreach_variable(var
, &shader
->globals
) {
1001 print_var_decl(var
, &state
);
1004 nir_foreach_variable(var
, &shader
->system_values
) {
1005 print_var_decl(var
, &state
);
1008 foreach_list_typed(nir_register
, reg
, node
, &shader
->registers
) {
1009 print_register_decl(reg
, &state
);
1012 foreach_list_typed(nir_function
, func
, node
, &shader
->functions
) {
1013 print_function(func
, &state
);
1016 destroy_print_state(&state
);
1020 nir_print_instr(const nir_instr
*instr
, FILE *fp
)
1022 print_state state
= {
1025 print_instr(instr
, &state
, 0);