bool use_same = true;
GPRVector::Values v;
+ std::array<bool,4> used_swizzles = {false, false, false, false};
+
+ /* Check whether all sources come from a GPR, and,
+ * if requested, whether they are swizzled as epected */
+
for (int i = 0; i < 4 && use_same; ++i) {
if ((1 << i) & mask) {
if (swizzle[i] < 4) {
v[i] = from_nir(src, swizzle[i]);
assert(v[i]);
- if (v[i]->type() != Value::gpr)
- use_same = false;
- if (match && (v[i]->chan() != swizzle[i]))
- use_same = false;
+ use_same &= (v[i]->type() == Value::gpr);
+ if (match) {
+ use_same &= (v[i]->chan() == swizzle[i]);
+ }
+ used_swizzles[v[i]->chan()] = true;
}
}
}
+
+ /* Now check whether all inputs come from the same GPR, and fill
+ * empty slots in the vector with unused swizzles, bail out if
+ * the sources are not from the same GPR
+ */
+
if (use_same) {
+ int next_free_swizzle = 0;
+ while (used_swizzles[next_free_swizzle] && next_free_swizzle < 4)
+ next_free_swizzle++;
+
+ /* Find the first GPR index used */
int i = 0;
while (!v[i] && i < 4) ++i;
assert(i < 4);
-
unsigned sel = v[i]->sel();
+
+
for (i = 0; i < 4 && use_same; ++i) {
- if (!v[i])
- v[i] = PValue(new GPRValue(sel, swizzle[i]));
+ if (!v[i]) {
+ if (swizzle[i] >= 4)
+ v[i] = PValue(new GPRValue(sel, swizzle[i]));
+ else {
+ assert(next_free_swizzle < 4);
+ v[i] = PValue(new GPRValue(sel, next_free_swizzle));
+ }
+
+ if (swizzle[i] < 4) {
+ used_swizzles[next_free_swizzle] = true;
+ while (next_free_swizzle < 4 && used_swizzles[swizzle[next_free_swizzle]])
+ next_free_swizzle++;
+ }
+ }
else
use_same &= v[i]->sel() == sel;
}
}
+ /* We can't re-use the source data because they either need re-swizzling, or
+ * they didn't come all from a GPR or the same GPR, so copy to a new vector
+ */
if (!use_same) {
AluInstruction *ir = nullptr;
- int sel = allocate_temp_register();
+ GPRVector result(allocate_temp_register(), swizzle);
for (int i = 0; i < 4; ++i) {
- v[i] = PValue(new GPRValue(sel, swizzle[i]));
if (swizzle[i] < 4 && (mask & (1 << i))) {
- ir = new AluInstruction(op1_mov, v[i], from_nir(src, swizzle[i]),
+ ir = new AluInstruction(op1_mov, result[i], from_nir(src, swizzle[i]),
EmitInstruction::write);
emit_instruction(ir);
+ } else {
+
}
}
if (ir)
ir->set_flag(alu_last_instr);
- }
- return GPRVector(v);;
+ return result;
+ } else
+ return GPRVector(v);;
}
bool ShaderFromNirProcessor::emit_load_ubo(nir_intrinsic_instr* instr)
return ir;
}
-PValue ShaderFromNirProcessor::from_nir_with_fetch_constant(const nir_src& src, unsigned component)
+PValue ShaderFromNirProcessor::from_nir_with_fetch_constant(const nir_src& src, unsigned component, int channel)
{
PValue value = from_nir(src, component);
if (value->type() != Value::gpr &&
value->type() != Value::gpr_vector &&
value->type() != Value::gpr_array_value) {
- PValue retval = get_temp_register();
+ PValue retval = get_temp_register(channel);
emit_instruction(new AluInstruction(op1_mov, retval, value,
EmitInstruction::last_write));
value = retval;