#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. */
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,
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);
}
/**
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;
}
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;
}
}
- 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
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;
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++;
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 *
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;