#include "compiler/shader_enums.h"
#include <stdio.h>
#include <stdlib.h>
+#include <inttypes.h> /* for PRIx64 macro */
static void
print_tabs(unsigned num_tabs, FILE *fp)
print_register_decl(nir_register *reg, print_state *state)
{
FILE *fp = state->fp;
- fprintf(fp, "decl_reg %s ", sizes[reg->num_components]);
+ fprintf(fp, "decl_reg %s %u ", sizes[reg->num_components], reg->bit_size);
if (reg->is_packed)
fprintf(fp, "(packed) ");
print_register(reg, state);
FILE *fp = state->fp;
if (def->name != NULL)
fprintf(fp, "/* %s */ ", def->name);
- fprintf(fp, "%s ssa_%u", sizes[def->num_components], def->index);
+ fprintf(fp, "%s %u ssa_%u", sizes[def->num_components], def->bit_size,
+ def->index);
}
static void
print_alu_dest(&instr->dest, state);
fprintf(fp, " = %s", nir_op_infos[instr->op].name);
+ if (instr->exact)
+ fprintf(fp, "!");
if (instr->dest.saturate)
fprintf(fp, ".sat");
fprintf(fp, " ");
}
}
+static const char *
+get_var_name(nir_variable *var, print_state *state)
+{
+ if (state->ht == NULL)
+ return var->name;
+
+ assert(state->syms);
+
+ struct hash_entry *entry = _mesa_hash_table_search(state->ht, var);
+ if (entry)
+ return entry->data;
+
+ char *name;
+ if (var->name == NULL) {
+ name = ralloc_asprintf(state->syms, "@%u", state->index++);
+ } else {
+ struct set_entry *set_entry = _mesa_set_search(state->syms, var->name);
+ if (set_entry != NULL) {
+ /* we have a collision with another name, append an @ + a unique
+ * index */
+ name = ralloc_asprintf(state->syms, "%s@%u", var->name,
+ state->index++);
+ } else {
+ /* Mark this one as seen */
+ _mesa_set_add(state->syms, var->name);
+ name = var->name;
+ }
+ }
+
+ _mesa_hash_table_insert(state->ht, var, name);
+
+ return name;
+}
+
static void
print_constant(nir_constant *c, const struct glsl_type *type, print_state *state)
{
}
break;
+ case GLSL_TYPE_DOUBLE:
+ for (i = 0; i < total_elems; i++) {
+ if (i > 0) fprintf(fp, ", ");
+ fprintf(fp, "%f", c->value.d[i]);
+ }
+ break;
+
case GLSL_TYPE_STRUCT:
for (i = 0; i < c->num_elements; i++) {
if (i > 0) fprintf(fp, ", ");
const char *const patch = (var->data.patch) ? "patch " : "";
const char *const inv = (var->data.invariant) ? "invariant " : "";
const char *const mode[] = { "shader_in ", "shader_out ", "", "",
- "uniform ", "shader_storage", "system " };
+ "uniform ", "shader_storage ", "shared ",
+ "system "};
fprintf(fp, "%s%s%s%s%s%s ",
cent, samp, patch, inv, mode[var->data.mode],
glsl_print_type(var->type, fp);
- struct set_entry *entry = NULL;
- if (state->syms)
- entry = _mesa_set_search(state->syms, var->name);
-
- char *name;
-
- if (entry != NULL) {
- /* we have a collision with another name, append an @ + a unique index */
- name = ralloc_asprintf(state->syms, "%s@%u", var->name, state->index++);
- } else {
- name = var->name;
- }
-
- fprintf(fp, " %s", name);
+ fprintf(fp, " %s", get_var_name(var, state));
if (var->data.mode == nir_var_shader_in ||
var->data.mode == nir_var_shader_out ||
}
fprintf(fp, "\n");
-
- if (state->syms) {
- _mesa_set_add(state->syms, name);
- _mesa_hash_table_insert(state->ht, var, name);
- }
}
static void
print_var(nir_variable *var, print_state *state)
{
FILE *fp = state->fp;
- const char *name;
- if (state->ht) {
- struct hash_entry *entry = _mesa_hash_table_search(state->ht, var);
-
- assert(entry != NULL);
- name = entry->data;
- } else {
- name = var->name;
- }
+ fprintf(fp, "%s", get_var_name(var, state));
+}
- fprintf(fp, "%s", name);
+static void
+print_arg(nir_variable *var, print_state *state)
+{
+ FILE *fp = state->fp;
+ glsl_print_type(var->type, fp);
+ fprintf(fp, " %s", get_var_name(var, state));
}
static void
static void
print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state)
{
- unsigned num_srcs = nir_intrinsic_infos[instr->intrinsic].num_srcs;
+ const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];
+ unsigned num_srcs = info->num_srcs;
FILE *fp = state->fp;
- if (nir_intrinsic_infos[instr->intrinsic].has_dest) {
+ if (info->has_dest) {
print_dest(&instr->dest, state);
fprintf(fp, " = ");
}
- fprintf(fp, "intrinsic %s (", nir_intrinsic_infos[instr->intrinsic].name);
+ fprintf(fp, "intrinsic %s (", info->name);
for (unsigned i = 0; i < num_srcs; i++) {
if (i != 0)
fprintf(fp, ") (");
- unsigned num_vars = nir_intrinsic_infos[instr->intrinsic].num_variables;
-
- for (unsigned i = 0; i < num_vars; i++) {
+ for (unsigned i = 0; i < info->num_variables; i++) {
if (i != 0)
fprintf(fp, ", ");
fprintf(fp, ") (");
- unsigned num_indices = nir_intrinsic_infos[instr->intrinsic].num_indices;
-
- for (unsigned i = 0; i < num_indices; i++) {
+ for (unsigned i = 0; i < info->num_indices; i++) {
if (i != 0)
fprintf(fp, ", ");
fprintf(fp, ")");
+ static const char *index_name[NIR_INTRINSIC_NUM_INDEX_FLAGS] = {
+ [NIR_INTRINSIC_BASE] = "base",
+ [NIR_INTRINSIC_WRMASK] = "wrmask",
+ [NIR_INTRINSIC_STREAM_ID] = "stream-id",
+ [NIR_INTRINSIC_UCP_ID] = "ucp-id",
+ };
+ for (unsigned idx = 1; idx < NIR_INTRINSIC_NUM_INDEX_FLAGS; idx++) {
+ if (!info->index_map[idx])
+ continue;
+ fprintf(fp, " /*");
+ if (idx == NIR_INTRINSIC_WRMASK) {
+ /* special case wrmask to show it as a writemask.. */
+ unsigned wrmask = nir_intrinsic_write_mask(instr);
+ fprintf(fp, " wrmask=");
+ for (unsigned i = 0; i < 4; i++)
+ if ((wrmask >> i) & 1)
+ fprintf(fp, "%c", "xyzw"[i]);
+ } else {
+ unsigned off = info->index_map[idx] - 1;
+ assert(index_name[idx]); /* forgot to update index_name table? */
+ fprintf(fp, " %s=%d", index_name[idx], instr->const_index[off]);
+ }
+ fprintf(fp, " */");
+ }
+
if (!state->shader)
return;
}
nir_foreach_variable(var, var_list) {
- if ((var->data.driver_location == instr->const_index[0]) &&
+ if ((var->data.driver_location == nir_intrinsic_base(instr)) &&
var->name) {
fprintf(fp, "\t/* %s */", var->name);
break;
case nir_tex_src_ddy:
fprintf(fp, "(ddy)");
break;
+ case nir_tex_src_texture_offset:
+ fprintf(fp, "(texture_offset)");
+ break;
case nir_tex_src_sampler_offset:
fprintf(fp, "(sampler_offset)");
break;
fprintf(fp, ", ");
}
- bool has_nonzero_offset = false;
- for (unsigned i = 0; i < 4; i++) {
- if (instr->const_offset[i] != 0) {
- has_nonzero_offset = true;
- break;
- }
- }
-
- 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]);
- }
-
if (instr->op == nir_texop_tg4) {
fprintf(fp, "%u (gather_component), ", instr->component);
}
- if (instr->sampler) {
- print_deref(instr->sampler, state);
+ if (instr->texture) {
+ print_deref(instr->texture, state);
+ fprintf(fp, " (texture)");
+ if (instr->sampler) {
+ print_deref(instr->sampler, state);
+ fprintf(fp, " (sampler)");
+ }
} else {
- fprintf(fp, "%u", instr->sampler_index);
+ assert(instr->sampler == NULL);
+ fprintf(fp, "%u (texture) %u (sampler)",
+ instr->texture_index, instr->sampler_index);
}
-
- fprintf(fp, " (sampler)");
}
static void
* and then print the float in a comment for readability.
*/
- fprintf(fp, "0x%08x /* %f */", instr->value.u[i], instr->value.f[i]);
+ if (instr->def.bit_size == 64)
+ fprintf(fp, "0x%16" PRIx64 " /* %f */", instr->value.u64[i],
+ instr->value.f64[i]);
+ else
+ fprintf(fp, "0x%08x /* %f */", instr->value.u32[i], instr->value.f32[i]);
}
fprintf(fp, ")");
if (i != 0)
fprintf(fp, ", ");
- print_var(impl->params[i], state);
+ print_arg(impl->params[i], state);
}
if (impl->return_var != NULL) {
if (impl->num_params != 0)
fprintf(fp, ", ");
fprintf(fp, "returning ");
- print_var(impl->return_var, state);
+ print_arg(impl->return_var, state);
}
fprintf(fp, "{\n");
fprintf(fp, "inputs: %u\n", shader->num_inputs);
fprintf(fp, "outputs: %u\n", shader->num_outputs);
fprintf(fp, "uniforms: %u\n", shader->num_uniforms);
+ fprintf(fp, "shared: %u\n", shader->num_shared);
nir_foreach_variable(var, &shader->uniforms) {
print_var_decl(var, &state);
print_var_decl(var, &state);
}
+ nir_foreach_variable(var, &shader->shared) {
+ print_var_decl(var, &state);
+ }
+
nir_foreach_variable(var, &shader->globals) {
print_var_decl(var, &state);
}