#include "st_glsl_to_tgsi_private.h"
#include <tgsi/tgsi_info.h>
#include <mesa/program/prog_instruction.h>
+#include <mesa/program/prog_print.h>
static int swizzle_for_type(const glsl_type *type, int component = 0)
{
return reg;
}
+bool operator == (const st_src_reg& lhs, const st_src_reg& rhs)
+{
+ bool result;
+
+ if (lhs.type != rhs.type ||
+ lhs.file != rhs.file ||
+ lhs.index != rhs.index ||
+ lhs.swizzle != rhs.swizzle ||
+ lhs.index2D != rhs.index2D ||
+ lhs.has_index2 != rhs.has_index2 ||
+ lhs.array_id != rhs.array_id ||
+ lhs.negate != rhs.negate ||
+ lhs.abs != rhs.abs ||
+ lhs.double_reg2 != rhs.double_reg2 ||
+ lhs.is_double_vertex_input != rhs.is_double_vertex_input)
+ return false;
+
+ if (lhs.reladdr) {
+ if (!rhs.reladdr)
+ return false;
+ result = (*lhs.reladdr == *rhs.reladdr);
+ } else {
+ result = !rhs.reladdr;
+ }
+
+ if (lhs.reladdr2) {
+ if (!rhs.reladdr2)
+ return false;
+ result &= (*lhs.reladdr2 == *rhs.reladdr2);
+ } else {
+ result &= !rhs.reladdr2;
+ }
+
+ return result;
+}
+
+static const char swz_txt[] = "xyzw";
+
+std::ostream& operator << (std::ostream& os, const st_src_reg& reg)
+{
+ if (reg.negate)
+ os << "-";
+ if (reg.abs)
+ os << "|";
+
+ os << _mesa_register_file_name(reg.file);
+
+ if (reg.file == PROGRAM_ARRAY) {
+ os << "(" << reg.array_id << ")";
+ }
+ if (reg.has_index2) {
+ os << "[";
+ if (reg.reladdr2) {
+ os << *reg.reladdr2;
+ }
+ os << "+" << reg.index2D << "]";
+ }
+ os << "[";
+ if (reg.reladdr) {
+ os << *reg.reladdr;
+ }
+ os << reg.index << "].";
+ for (int i = 0; i < 4; ++i) {
+ int swz = GET_SWZ(reg.swizzle, i);
+ if (swz < 4)
+ os << swz_txt[swz];
+ else
+ os << "_";
+ }
+ if (reg.abs)
+ os << "|";
+ return os;
+}
+
st_dst_reg::st_dst_reg(st_src_reg reg)
{
this->type = reg.type;
this->has_index2 = reg.has_index2;
this->array_id = reg.array_id;
}
+
+bool operator == (const st_dst_reg& lhs, const st_dst_reg& rhs)
+{
+ bool result;
+
+ if (lhs.type != rhs.type ||
+ lhs.file != rhs.file ||
+ lhs.index != rhs.index ||
+ lhs.writemask != rhs.writemask ||
+ lhs.index2D != rhs.index2D ||
+ lhs.has_index2 != rhs.has_index2 ||
+ lhs.array_id != rhs.array_id)
+ return false;
+
+ if (lhs.reladdr) {
+ if (!rhs.reladdr)
+ return false;
+ result = (*lhs.reladdr == *rhs.reladdr);
+ } else {
+ result = !rhs.reladdr;
+ }
+
+ if (lhs.reladdr2) {
+ if (!rhs.reladdr2)
+ return false;
+ result &= (*lhs.reladdr2 == *rhs.reladdr2);
+ } else {
+ result &= !rhs.reladdr2;
+ }
+
+ return result;
+}
+
+std::ostream& operator << (std::ostream& os, const st_dst_reg& reg)
+{
+ os << _mesa_register_file_name(reg.file);
+ if (reg.file == PROGRAM_ARRAY) {
+ os << "(" << reg.array_id << ")";
+ }
+ if (reg.has_index2) {
+ os << "[";
+ if (reg.reladdr2) {
+ os << *reg.reladdr2;
+ }
+ os << "+" << reg.index2D << "]";
+ }
+ os << "[";
+ if (reg.reladdr) {
+ os << *reg.reladdr;
+ }
+ os << reg.index << "].";
+ for (int i = 0; i < 4; ++i) {
+ if (1 << i & reg.writemask)
+ os << swz_txt[i];
+ else
+ os << "_";
+ }
+
+ return os;
+}
+
+void glsl_to_tgsi_instruction::print(std::ostream& os) const
+{
+ os << tgsi_get_opcode_name(info->opcode) << " ";
+
+ bool has_operators = false;
+ for (unsigned j = 0; j < num_inst_dst_regs(this); j++) {
+ has_operators = true;
+ if (j > 0)
+ os << ", ";
+ os << dst[j];
+ }
+
+ if (has_operators)
+ os << " := ";
+
+ for (unsigned j = 0; j < num_inst_src_regs(this); j++) {
+ if (j > 0)
+ os << ", ";
+ os << src[j];
+ }
+
+ if (tex_offset_num_offset > 0) {
+ os << ", TEXOFS: ";
+ for (unsigned j = 0; j < tex_offset_num_offset; j++) {
+ if (j > 0)
+ os << ", ";
+ os << tex_offsets[j];
+ }
+ }
+}
#include "util/debug.h"
using std::cerr;
using std::setw;
+using std::ostream;
#endif
/* If <windows.h> is included this is defined and clashes with
#endif
#ifndef NDEBUG
+/* Prepare to make it possible to specify log file */
+static std::ostream& debug_log = cerr;
+
/* Helper function to check whether we want to seen debugging output */
static inline bool is_debug_enabled ()
{
#ifndef NDEBUG
/* Function used for debugging. */
-static void dump_instruction(int line, prog_scope *scope,
+static void dump_instruction(ostream& os, int line, prog_scope *scope,
const glsl_to_tgsi_instruction& inst);
#endif
prog_scope *cur_scope = scopes.create(nullptr, outer_scope, 0, 0, line);
- RENAME_DEBUG(cerr << "========= Begin shader ============\n");
+ RENAME_DEBUG(debug_log << "========= Begin shader ============\n");
foreach_in_list(glsl_to_tgsi_instruction, inst, instructions) {
if (is_at_end) {
break;
}
- RENAME_DEBUG(dump_instruction(line, cur_scope, *inst));
+ RENAME_DEBUG(dump_instruction(debug_log, line, cur_scope, *inst));
switch (inst->op) {
case TGSI_OPCODE_BGNLOOP: {
++line;
}
- RENAME_DEBUG(cerr << "==================================\n\n");
+ RENAME_DEBUG(debug_log << "==================================\n\n");
/* Make sure last scope is closed, even though no
* TGSI_OPCODE_END was given.
if (cur_scope->end() < 0)
cur_scope->set_end(line - 1);
- RENAME_DEBUG(cerr << "========= lifetimes ==============\n");
+ RENAME_DEBUG(debug_log << "========= lifetimes ==============\n");
for(int i = 0; i < ntemps; ++i) {
- RENAME_DEBUG(cerr << setw(4) << i);
+ RENAME_DEBUG(debug_log << setw(4) << i);
lifetimes[i] = acc[i].get_required_lifetime();
- RENAME_DEBUG(cerr << ": [" << lifetimes[i].begin << ", "
+ RENAME_DEBUG(debug_log << ": [" << lifetimes[i].begin << ", "
<< lifetimes[i].end << "]\n");
}
- RENAME_DEBUG(cerr << "==================================\n\n");
+ RENAME_DEBUG(debug_log << "==================================\n\n");
out:
delete[] acc;
/* Code below used for debugging */
#ifndef NDEBUG
-static const char swizzle_txt[] = "xyzw";
-
-static const char *tgsi_file_names[PROGRAM_FILE_MAX] = {
- "TEMP", "ARRAY", "IN", "OUT", "STATE", "CONST",
- "UNIFORM", "WO", "ADDR", "SAMPLER", "SV", "UNDEF",
- "IMM", "BUF", "MEM", "IMAGE"
-};
-
static
-void dump_instruction(int line, prog_scope *scope,
+void dump_instruction(ostream& os, int line, prog_scope *scope,
const glsl_to_tgsi_instruction& inst)
{
- const struct tgsi_opcode_info *info = tgsi_get_opcode_info(inst.op);
-
+ const struct tgsi_opcode_info *info = inst.info;
int indent = scope->nesting_depth();
if ((scope->type() == switch_case_branch ||
scope->type() == switch_default_branch) &&
info->opcode == TGSI_OPCODE_ENDSWITCH)
--indent;
- cerr << setw(4) << line << ": ";
- for (int i = 0; i < indent; ++i)
- cerr << " ";
- cerr << tgsi_get_opcode_name(info->opcode) << " ";
-
- bool has_operators = false;
- for (unsigned j = 0; j < num_inst_dst_regs(&inst); j++) {
- has_operators = true;
- if (j > 0)
- cerr << ", ";
-
- const st_dst_reg& dst = inst.dst[j];
- cerr << tgsi_file_names[dst.file];
-
- if (dst.file == PROGRAM_ARRAY)
- cerr << "(" << dst.array_id << ")";
-
- cerr << "[" << dst.index << "]";
-
- if (dst.writemask != TGSI_WRITEMASK_XYZW) {
- cerr << ".";
- if (dst.writemask & TGSI_WRITEMASK_X) cerr << "x";
- if (dst.writemask & TGSI_WRITEMASK_Y) cerr << "y";
- if (dst.writemask & TGSI_WRITEMASK_Z) cerr << "z";
- if (dst.writemask & TGSI_WRITEMASK_W) cerr << "w";
- }
- }
- if (has_operators)
- cerr << " := ";
-
- for (unsigned j = 0; j < num_inst_src_regs(&inst); j++) {
- if (j > 0)
- cerr << ", ";
-
- const st_src_reg& src = inst.src[j];
- cerr << tgsi_file_names[src.file]
- << "[" << src.index << "]";
- if (src.swizzle != SWIZZLE_XYZW) {
- cerr << ".";
- for (int idx = 0; idx < 4; ++idx) {
- int swz = GET_SWZ(src.swizzle, idx);
- if (swz < 4) {
- cerr << swizzle_txt[swz];
- }
- }
- }
- }
-
- if (inst.tex_offset_num_offset > 0) {
- cerr << ", TEXOFS: ";
- for (unsigned j = 0; j < inst.tex_offset_num_offset; j++) {
- if (j > 0)
- cerr << ", ";
-
- const st_src_reg& src = inst.tex_offsets[j];
- cerr << tgsi_file_names[src.file]
- << "[" << src.index << "]";
- if (src.swizzle != SWIZZLE_XYZW) {
- cerr << ".";
- for (int idx = 0; idx < 4; ++idx) {
- int swz = GET_SWZ(src.swizzle, idx);
- if (swz < 4) {
- cerr << swizzle_txt[swz];
- }
- }
- }
- }
- }
- cerr << "\n";
+ os << setw(4) << line << ": ";
+ os << setw(indent * 4) << " ";
+ os << inst << "\n";
}
#endif