summaryrefslogtreecommitdiffstats
path: root/src/mesa/program
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/program')
-rw-r--r--src/mesa/program/ir_to_mesa.cpp82
1 files changed, 34 insertions, 48 deletions
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 8f790af09ac..5510440475d 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -53,11 +53,30 @@ extern "C" {
#include "program/prog_parameter.h"
}
+static int swizzle_for_size(int size);
+
/**
* This struct is a corresponding struct to Mesa prog_src_register, with
* wider fields.
*/
typedef struct ir_to_mesa_src_reg {
+ ir_to_mesa_src_reg(int file, int index, const glsl_type *type)
+ {
+ this->file = file;
+ this->index = index;
+ if (type && (type->is_scalar() || type->is_vector() || type->is_matrix()))
+ this->swizzle = swizzle_for_size(type->vector_elements);
+ else
+ this->swizzle = SWIZZLE_XYZW;
+ this->negate = 0;
+ this->reladdr = NULL;
+ }
+
+ ir_to_mesa_src_reg()
+ {
+ this->file = PROGRAM_UNDEFINED;
+ }
+
int file; /**< PROGRAM_* from Mesa */
int index; /**< temporary index, VERT_ATTRIB_*, FRAG_ATTRIB_*, etc. */
GLuint swizzle; /**< SWIZZLE_XYZWONEZERO swizzles from Mesa. */
@@ -242,9 +261,7 @@ public:
void *mem_ctx;
};
-ir_to_mesa_src_reg ir_to_mesa_undef = {
- PROGRAM_UNDEFINED, 0, SWIZZLE_NOOP, NEGATE_NONE, NULL,
-};
+ir_to_mesa_src_reg ir_to_mesa_undef = ir_to_mesa_src_reg(PROGRAM_UNDEFINED, 0, NULL);
ir_to_mesa_dst_reg ir_to_mesa_undef_dst = {
PROGRAM_UNDEFINED, 0, SWIZZLE_NOOP, COND_TR, NULL,
@@ -379,15 +396,7 @@ ir_to_mesa_dst_reg_from_src(ir_to_mesa_src_reg reg)
inline ir_to_mesa_src_reg
ir_to_mesa_src_reg_from_dst(ir_to_mesa_dst_reg reg)
{
- ir_to_mesa_src_reg src_reg;
-
- src_reg.file = reg.file;
- src_reg.index = reg.index;
- src_reg.swizzle = SWIZZLE_XYZW;
- src_reg.negate = 0;
- src_reg.reladdr = reg.reladdr;
-
- return src_reg;
+ return ir_to_mesa_src_reg(reg.file, reg.index, NULL);
}
/**
@@ -460,13 +469,10 @@ ir_to_mesa_visitor::ir_to_mesa_emit_scalar_op1(ir_instruction *ir,
struct ir_to_mesa_src_reg
ir_to_mesa_visitor::src_reg_for_float(float val)
{
- ir_to_mesa_src_reg src_reg;
+ ir_to_mesa_src_reg src_reg(PROGRAM_CONSTANT, -1, NULL);
- src_reg.file = PROGRAM_CONSTANT;
src_reg.index = _mesa_add_unnamed_constant(this->prog->Parameters,
&val, 1, &src_reg.swizzle);
- src_reg.reladdr = NULL;
- src_reg.negate = 0;
return src_reg;
}
@@ -1238,7 +1244,6 @@ get_builtin_matrix_ref(void *mem_ctx, struct gl_program *prog, ir_variable *var,
void
ir_to_mesa_visitor::visit(ir_dereference_variable *ir)
{
- ir_to_mesa_src_reg src_reg;
variable_storage *entry = find_variable_storage(ir->var);
unsigned int loc;
int len;
@@ -1340,17 +1345,7 @@ ir_to_mesa_visitor::visit(ir_dereference_variable *ir)
}
}
- src_reg.file = entry->file;
- src_reg.index = entry->index;
- /* If the type is smaller than a vec4, replicate the last channel out. */
- if (ir->type->is_scalar() || ir->type->is_vector())
- src_reg.swizzle = swizzle_for_size(ir->var->type->vector_elements);
- else
- src_reg.swizzle = SWIZZLE_NOOP;
- src_reg.reladdr = NULL;
- src_reg.negate = 0;
-
- this->result = src_reg;
+ this->result = ir_to_mesa_src_reg(entry->file, entry->index, ir->var->type);
}
void
@@ -1367,17 +1362,13 @@ ir_to_mesa_visitor::visit(ir_dereference_array *ir)
if (deref_var && strncmp(deref_var->var->name,
"gl_TextureMatrix",
strlen("gl_TextureMatrix")) == 0) {
- ir_to_mesa_src_reg src_reg;
struct variable_storage *entry;
entry = get_builtin_matrix_ref(this->mem_ctx, this->prog, deref_var->var,
ir->array_index);
assert(entry);
- src_reg.file = entry->file;
- src_reg.index = entry->index;
- src_reg.swizzle = swizzle_for_size(ir->type->vector_elements);
- src_reg.negate = 0;
+ ir_to_mesa_src_reg src_reg(entry->file, entry->index, ir->type);
if (index) {
src_reg.reladdr = NULL;
@@ -1646,17 +1637,14 @@ ir_to_mesa_visitor::visit(ir_constant *ir)
ir_to_mesa_dst_reg mat_column = ir_to_mesa_dst_reg_from_src(mat);
for (i = 0; i < ir->type->matrix_columns; i++) {
- src_reg.file = PROGRAM_CONSTANT;
-
assert(ir->type->base_type == GLSL_TYPE_FLOAT);
values = &ir->value.f[i * ir->type->vector_elements];
+ src_reg = ir_to_mesa_src_reg(PROGRAM_CONSTANT, -1, NULL);
src_reg.index = _mesa_add_unnamed_constant(this->prog->Parameters,
- values,
- ir->type->vector_elements,
- &src_reg.swizzle);
- src_reg.reladdr = NULL;
- src_reg.negate = 0;
+ values,
+ ir->type->vector_elements,
+ &src_reg.swizzle);
ir_to_mesa_emit_op1(ir, OPCODE_MOV, mat_column, src_reg);
mat_column.index++;
@@ -1689,13 +1677,11 @@ ir_to_mesa_visitor::visit(ir_constant *ir)
assert(!"Non-float/uint/int/bool constant");
}
- src_reg.index = _mesa_add_unnamed_constant(this->prog->Parameters,
- values, ir->type->vector_elements,
- &src_reg.swizzle);
- src_reg.reladdr = NULL;
- src_reg.negate = 0;
-
- this->result = src_reg;
+ this->result = ir_to_mesa_src_reg(PROGRAM_CONSTANT, -1, ir->type);
+ this->result.index = _mesa_add_unnamed_constant(this->prog->Parameters,
+ values,
+ ir->type->vector_elements,
+ &this->result.swizzle);
}
function_entry *
@@ -1825,7 +1811,7 @@ ir_to_mesa_visitor::visit(ir_call *ir)
void
ir_to_mesa_visitor::visit(ir_texture *ir)
{
- ir_to_mesa_src_reg result_src, coord, lod_info = { 0 }, projector;
+ ir_to_mesa_src_reg result_src, coord, lod_info, projector;
ir_to_mesa_dst_reg result_dst, coord_dst;
ir_to_mesa_instruction *inst = NULL;
prog_opcode opcode = OPCODE_NOP;