#include "compiler/shader_enums.h"
#include <stdio.h>
#include <stdlib.h>
+#include <inttypes.h> /* for PRIx64 macro */
+
+#if defined(_WIN32) && !defined(snprintf)
+#define snprintf _snprintf
+#endif
static void
print_tabs(unsigned num_tabs, FILE *fp)
/* an index used to make new non-conflicting names */
unsigned index;
+
+ /**
+ * Optional table of annotations mapping nir object
+ * (such as instr or var) to message to print.
+ */
+ struct hash_table *annotations;
} print_state;
+static void
+print_annotation(print_state *state, void *obj)
+{
+ if (!state->annotations)
+ return;
+
+ struct hash_entry *entry = _mesa_hash_table_search(state->annotations, obj);
+ if (!entry)
+ return;
+
+ const char *note = entry->data;
+ _mesa_hash_table_remove(state->annotations, entry);
+
+ fprintf(stderr, "%s\n\n", note);
+}
+
static void
print_register(nir_register *reg, print_state *state)
{
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_src(&instr->src[src].src, state);
bool print_swizzle = false;
+ unsigned used_channels = 0;
+
for (unsigned i = 0; i < 4; i++) {
if (!nir_alu_instr_channel_used(instr, src, i))
continue;
+ used_channels++;
+
if (instr->src[src].swizzle[i] != i) {
print_swizzle = true;
break;
}
}
- if (print_swizzle) {
+ unsigned live_channels = instr->src[src].src.is_ssa
+ ? instr->src[src].src.ssa->num_components
+ : instr->src[src].src.reg.reg->num_components;
+
+ if (print_swizzle || used_channels != live_channels) {
fprintf(fp, ".");
for (unsigned i = 0; i < 4; i++) {
if (!nir_alu_instr_channel_used(instr, src, i))
}
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, ", ");
}
}
+static const char *
+get_variable_mode_str(nir_variable_mode mode)
+{
+ switch (mode) {
+ case nir_var_shader_in:
+ return "shader_in";
+ case nir_var_shader_out:
+ return "shader_out";
+ case nir_var_uniform:
+ return "uniform";
+ case nir_var_shader_storage:
+ return "shader_storage";
+ case nir_var_system_value:
+ return "system";
+ case nir_var_shared:
+ return "shared";
+ case nir_var_param:
+ case nir_var_global:
+ case nir_var_local:
+ default:
+ return "";
+ }
+}
+
static void
print_var_decl(nir_variable *var, print_state *state)
{
const char *const samp = (var->data.sample) ? "sample " : "";
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 ", "shared ",
- "system "};
+ fprintf(fp, "%s%s%s%s%s %s ",
+ cent, samp, patch, inv, get_variable_mode_str(var->data.mode),
+ glsl_interp_mode_name(var->data.interpolation));
- fprintf(fp, "%s%s%s%s%s%s ",
- cent, samp, patch, inv, mode[var->data.mode],
- glsl_interp_qualifier_name(var->data.interpolation));
+ const char *const coher = (var->data.image.coherent) ? "coherent " : "";
+ const char *const volat = (var->data.image._volatile) ? "volatile " : "";
+ const char *const restr = (var->data.image.restrict_flag) ? "restrict " : "";
+ const char *const ronly = (var->data.image.read_only) ? "readonly " : "";
+ const char *const wonly = (var->data.image.write_only) ? "writeonly " : "";
+ fprintf(fp, "%s%s%s%s%s", coher, volat, restr, ronly, wonly);
glsl_print_type(var->type, fp);
}
fprintf(fp, "\n");
+ print_annotation(state, var);
}
static void
[NIR_INTRINSIC_RANGE] = "range",
[NIR_INTRINSIC_DESC_SET] = "desc-set",
[NIR_INTRINSIC_BINDING] = "binding",
+ [NIR_INTRINSIC_COMPONENT] = "component",
+ [NIR_INTRINSIC_INTERP_MODE] = "interp_mode",
};
for (unsigned idx = 1; idx < NIR_INTRINSIC_NUM_INDEX_FLAGS; idx++) {
if (!info->index_map[idx])
nir_foreach_variable(var, var_list) {
if ((var->data.driver_location == nir_intrinsic_base(instr)) &&
+ (instr->intrinsic == nir_intrinsic_load_uniform ||
+ var->data.location_frac == nir_intrinsic_component(instr)) &&
var->name) {
fprintf(fp, "\t/* %s */", var->name);
break;
case nir_texop_txf_ms:
fprintf(fp, "txf_ms ");
break;
+ case nir_texop_txf_ms_mcs:
+ fprintf(fp, "txf_ms_mcs ");
+ break;
case nir_texop_txs:
fprintf(fp, "txs ");
break;
case nir_tex_src_ms_index:
fprintf(fp, "(ms_index)");
break;
+ case nir_tex_src_ms_mcs:
+ fprintf(fp, "(ms_mcs)");
+ break;
case nir_tex_src_ddx:
fprintf(fp, "(ddx)");
break;
case nir_tex_src_sampler_offset:
fprintf(fp, "(sampler_offset)");
break;
+ case nir_tex_src_plane:
+ fprintf(fp, "(plane)");
+ break;
default:
unreachable("Invalid texture source type");
* and then print the float in a comment for readability.
*/
- fprintf(fp, "0x%08x /* %f */", instr->value.u32[i], instr->value.f32[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, ")");
FILE *fp = state->fp;
print_dest(&instr->dest, state);
fprintf(fp, " = phi ");
- nir_foreach_phi_src(instr, src) {
+ nir_foreach_phi_src(src, instr) {
if (&src->node != exec_list_get_head(&instr->srcs))
fprintf(fp, ", ");
print_parallel_copy_instr(nir_parallel_copy_instr *instr, print_state *state)
{
FILE *fp = state->fp;
- nir_foreach_parallel_copy_entry(instr, entry) {
+ nir_foreach_parallel_copy_entry(entry, instr) {
if (&entry->node != exec_list_get_head(&instr->entries))
fprintf(fp, "; ");
free(preds);
- nir_foreach_instr(block, instr) {
+ nir_foreach_instr(instr, block) {
print_instr(instr, state, tabs);
fprintf(fp, "\n");
+ print_annotation(state, instr);
}
print_tabs(tabs, fp);
fprintf(fp, "{\n");
- for (unsigned i = 0; i < impl->num_params; i++) {
- fprintf(fp, "\t");
- print_var_decl(impl->params[i], state);
- }
-
- if (impl->return_var) {
- fprintf(fp, "\t");
- print_var_decl(impl->return_var, state);
- }
-
nir_foreach_variable(var, &impl->locals) {
fprintf(fp, "\t");
print_var_decl(var, state);
}
void
-nir_print_shader(nir_shader *shader, FILE *fp)
+nir_print_shader_annotated(nir_shader *shader, FILE *fp,
+ struct hash_table *annotations)
{
print_state state;
init_print_state(&state, shader, fp);
+ state.annotations = annotations;
+
fprintf(fp, "shader: %s\n", gl_shader_stage_name(shader->stage));
if (shader->info.name)
destroy_print_state(&state);
}
+void
+nir_print_shader(nir_shader *shader, FILE *fp)
+{
+ nir_print_shader_annotated(shader, fp, NULL);
+}
+
void
nir_print_instr(const nir_instr *instr, FILE *fp)
{