}
static void
-print_alu_src(nir_alu_src *src, FILE *fp)
+print_alu_src(nir_alu_instr *instr, unsigned src, FILE *fp)
{
- if (src->negate)
+ if (instr->src[src].negate)
fprintf(fp, "-");
- if (src->abs)
+ if (instr->src[src].abs)
fprintf(fp, "abs(");
- print_src(&src->src, fp);
+ print_src(&instr->src[src].src, fp);
- if (src->swizzle[0] != 0 ||
- src->swizzle[1] != 1 ||
- src->swizzle[2] != 2 ||
- src->swizzle[3] != 3) {
+ bool print_swizzle = false;
+ for (unsigned i = 0; i < 4; i++) {
+ if (!nir_alu_instr_channel_used(instr, src, i))
+ continue;
+
+ if (instr->src[src].swizzle[i] != i) {
+ print_swizzle = true;
+ break;
+ }
+ }
+
+ if (print_swizzle) {
fprintf(fp, ".");
- for (unsigned i = 0; i < 4; i++)
- fprintf(fp, "%c", "xyzw"[src->swizzle[i]]);
+ for (unsigned i = 0; i < 4; i++) {
+ if (!nir_alu_instr_channel_used(instr, src, i))
+ continue;
+
+ fprintf(fp, "%c", "xyzw"[instr->src[src].swizzle[i]]);
+ }
}
- if (src->abs)
+ if (instr->src[src].abs)
fprintf(fp, ")");
}
static void
print_alu_instr(nir_alu_instr *instr, FILE *fp)
{
- if (instr->has_predicate) {
- fprintf(fp, "(");
- print_src(&instr->predicate, fp);
- fprintf(fp, ") ");
- }
-
print_alu_dest(&instr->dest, fp);
fprintf(fp, " = %s", nir_op_infos[instr->op].name);
fprintf(fp, ".sat");
fprintf(fp, " ");
- bool first = true;
for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++) {
- if (!first)
+ if (i != 0)
fprintf(fp, ", ");
- print_alu_src(&instr->src[i], fp);
-
- first = false;
+ print_alu_src(instr, i, fp);
}
}
const char *const samp = (var->data.sample) ? "sample " : "";
const char *const inv = (var->data.invariant) ? "invariant " : "";
const char *const mode[] = { "shader_in ", "shader_out ", "", "",
- "uniform ", "system " };
+ "uniform ", "shader_storage", "system " };
const char *const interp[] = { "", "smooth", "flat", "noperspective" };
fprintf(fp, "%s%s%s%s%s ",
glsl_print_type(var->type, fp);
- struct set_entry *entry =
- _mesa_set_search(state->syms, _mesa_hash_string(var->name), var->name);
+ struct set_entry *entry = NULL;
+ if (state)
+ entry = _mesa_set_search(state->syms, var->name);
char *name;
if (var->data.mode == nir_var_shader_in ||
var->data.mode == nir_var_shader_out ||
- var->data.mode == nir_var_uniform) {
- fprintf(fp, " (%u)", var->data.driver_location);
+ var->data.mode == nir_var_uniform ||
+ var->data.mode == nir_var_shader_storage) {
+ fprintf(fp, " (%u, %u)", var->data.location, var->data.driver_location);
}
fprintf(fp, "\n");
- _mesa_set_add(state->syms, _mesa_hash_string(name), name);
- _mesa_hash_table_insert(state->ht, var, name);
+ if (state) {
+ _mesa_set_add(state->syms, name);
+ _mesa_hash_table_insert(state->ht, var, name);
+ }
}
static void
print_var(nir_variable *var, print_var_state *state, FILE *fp)
{
- struct hash_entry *entry = _mesa_hash_table_search(state->ht, var);
+ const char *name;
+ if (state) {
+ struct hash_entry *entry = _mesa_hash_table_search(state->ht, var);
- assert(entry != NULL);
+ assert(entry != NULL);
+ name = entry->data;
+ } else {
+ name = var->name;
+ }
- fprintf(fp, "%s", (char *) entry->data);
+ fprintf(fp, "%s", name);
}
static void
{
unsigned num_srcs = nir_intrinsic_infos[instr->intrinsic].num_srcs;
- if (instr->has_predicate) {
- fprintf(fp, "(");
- print_src(&instr->predicate, fp);
- fprintf(fp, ") ");
- }
-
if (nir_intrinsic_infos[instr->intrinsic].has_dest) {
print_dest(&instr->dest, fp);
fprintf(fp, " = ");
fprintf(fp, "intrinsic %s (", nir_intrinsic_infos[instr->intrinsic].name);
- bool first = true;
for (unsigned i = 0; i < num_srcs; i++) {
- if (!first)
+ if (i != 0)
fprintf(fp, ", ");
print_src(&instr->src[i], fp);
-
- first = false;
}
fprintf(fp, ") (");
unsigned num_vars = nir_intrinsic_infos[instr->intrinsic].num_variables;
- first = true;
for (unsigned i = 0; i < num_vars; i++) {
- if (!first)
+ if (i != 0)
fprintf(fp, ", ");
print_deref(instr->variables[i], state, fp);
-
- first = false;
}
fprintf(fp, ") (");
unsigned num_indices = nir_intrinsic_infos[instr->intrinsic].num_indices;
- first = true;
for (unsigned i = 0; i < num_indices; i++) {
- if (!first)
+ if (i != 0)
fprintf(fp, ", ");
fprintf(fp, "%u", instr->const_index[i]);
-
- first = false;
}
fprintf(fp, ")");
static void
print_tex_instr(nir_tex_instr *instr, print_var_state *state, FILE *fp)
{
- if (instr->has_predicate) {
- fprintf(fp, "(");
- print_src(&instr->predicate, fp);
- fprintf(fp, ") ");
- }
-
print_dest(&instr->dest, fp);
fprintf(fp, " = ");
}
for (unsigned i = 0; i < instr->num_srcs; i++) {
- print_src(&instr->src[i], fp);
+ print_src(&instr->src[i].src, fp);
fprintf(fp, " ");
- switch(instr->src_type[i]) {
+ switch(instr->src[i].src_type) {
case nir_tex_src_coord:
fprintf(fp, "(coord)");
break;
case nir_tex_src_ddy:
fprintf(fp, "(ddy)");
break;
- case nir_tex_src_sampler_index:
- fprintf(fp, "(sampler_index)");
+ case nir_tex_src_sampler_offset:
+ fprintf(fp, "(sampler_offset)");
break;
default:
fprintf(fp, ", ");
}
- bool offset_nonzero = false;
- for (unsigned i = 0; i < 4; i++)
+ bool has_nonzero_offset = false;
+ for (unsigned i = 0; i < 4; i++) {
if (instr->const_offset[i] != 0) {
- offset_nonzero = true;
+ has_nonzero_offset = true;
break;
}
+ }
- if (offset_nonzero) {
+ if (has_nonzero_offset) {
fprintf(fp, "[%i %i %i %i] (offset), ",
instr->const_offset[0], instr->const_offset[1],
instr->const_offset[2], instr->const_offset[3]);
static void
print_call_instr(nir_call_instr *instr, print_var_state *state, FILE *fp)
{
- if (instr->has_predicate) {
- fprintf(fp, "(");
- print_src(&instr->predicate, fp);
- fprintf(fp, ") ");
- }
-
fprintf(fp, "call %s ", instr->callee->function->name);
for (unsigned i = 0; i < instr->num_params; i++) {
}
static void
-print_const_value(nir_const_value value, unsigned num_components, FILE *fp)
+print_load_const_instr(nir_load_const_instr *instr, unsigned tabs, FILE *fp)
{
- fprintf(fp, "(");
+ print_ssa_def(&instr->def, fp);
+
+ fprintf(fp, " = load_const (");
- bool first = true;
- for (unsigned i = 0; i < num_components; i++) {
- if (!first)
+ for (unsigned i = 0; i < instr->def.num_components; i++) {
+ if (i != 0)
fprintf(fp, ", ");
/*
* and then print the float in a comment for readability.
*/
- fprintf(fp, "0x%08x /* %f */", value.u[i], value.f[i]);
-
- first = false;
+ fprintf(fp, "0x%08x /* %f */", instr->value.u[i], instr->value.f[i]);
}
fprintf(fp, ")");
}
-static void
-print_load_const_instr(nir_load_const_instr *instr, unsigned tabs, FILE *fp)
-{
- if (instr->has_predicate) {
- fprintf(fp, "(");
- print_src(&instr->predicate, fp);
- fprintf(fp, ") ");
- }
-
- print_dest(&instr->dest, fp);
-
- fprintf(fp, " = load_const ");
-
- if (instr->array_elems == 0) {
- print_const_value(instr->value, instr->num_components, fp);
- } else {
- fprintf(fp, "{\n");
- for (unsigned i = 0; i < instr->array_elems; i++) {
- print_tabs(tabs + 1, fp);
- print_const_value(instr->array[i], instr->num_components, fp);
- fprintf(fp, ", \n");
- }
- fprintf(fp, "}");
- }
-}
-
static void
print_jump_instr(nir_jump_instr *instr, FILE *fp)
{
{
print_dest(&instr->dest, fp);
fprintf(fp, " = phi ");
- bool first = true;
- foreach_list_typed(nir_phi_src, src, node, &instr->srcs) {
- if (!first)
+ nir_foreach_phi_src(instr, src) {
+ if (&src->node != exec_list_get_head(&instr->srcs))
fprintf(fp, ", ");
fprintf(fp, "block_%u: ", src->pred->index);
print_src(&src->src, fp);
-
- first = false;
}
}
static void
print_parallel_copy_instr(nir_parallel_copy_instr *instr, FILE *fp)
{
- bool first = true;
- fprintf(fp, "pcopy: ");
- foreach_list_typed(nir_parallel_copy_copy, copy, node, &instr->copies) {
- if (!first)
+ nir_foreach_parallel_copy_entry(instr, entry) {
+ if (&entry->node != exec_list_get_head(&instr->entries))
fprintf(fp, "; ");
- print_dest(©->dest, fp);
+ print_dest(&entry->dest, fp);
fprintf(fp, " = ");
- print_src(©->src, fp);
-
- first = false;
+ print_src(&entry->src, fp);
}
}
static void
-print_instr(nir_instr *instr, print_var_state *state, unsigned tabs, FILE *fp)
+print_instr(const nir_instr *instr, print_var_state *state, unsigned tabs, FILE *fp)
{
print_tabs(tabs, fp);
print_intrinsic_instr(nir_instr_as_intrinsic(instr), state, fp);
break;
- case nir_instr_type_texture:
- print_tex_instr(nir_instr_as_texture(instr), state, fp);
+ case nir_instr_type_tex:
+ print_tex_instr(nir_instr_as_tex(instr), state, fp);
break;
case nir_instr_type_load_const:
unreachable("Invalid instruction type");
break;
}
-
- fprintf(fp, "\n");
}
static int
nir_foreach_instr(block, instr) {
print_instr(instr, state, tabs, fp);
+ fprintf(fp, "\n");
}
print_tabs(tabs, fp);
{
state->ht = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal);
- state->syms = _mesa_set_create(NULL, _mesa_key_string_equal);
+ state->syms = _mesa_set_create(NULL, _mesa_key_hash_string,
+ _mesa_key_string_equal);
state->index = 0;
}
print_var_state state;
init_print_state(&state);
- for (unsigned i = 0; i < shader->num_user_structures; i++) {
- glsl_print_struct(shader->user_structures[i], fp);
- }
-
- struct hash_entry *entry;
-
- hash_table_foreach(shader->uniforms, entry) {
- print_var_decl((nir_variable *) entry->data, &state, fp);
+ foreach_list_typed(nir_variable, var, node, &shader->uniforms) {
+ print_var_decl(var, &state, fp);
}
- hash_table_foreach(shader->inputs, entry) {
- print_var_decl((nir_variable *) entry->data, &state, fp);
+ foreach_list_typed(nir_variable, var, node, &shader->inputs) {
+ print_var_decl(var, &state, fp);
}
- hash_table_foreach(shader->outputs, entry) {
- print_var_decl((nir_variable *) entry->data, &state, fp);
+ foreach_list_typed(nir_variable, var, node, &shader->outputs) {
+ print_var_decl(var, &state, fp);
}
foreach_list_typed(nir_variable, var, node, &shader->globals) {
destroy_print_state(&state);
}
+
+void
+nir_print_instr(const nir_instr *instr, FILE *fp)
+{
+ print_instr(instr, NULL, 0, fp);
+}