r600/sfn: Validate ALU dst writes in emit_alu_op

Assisted-by: Copilot (auto mode)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41945>
This commit is contained in:
Gert Wollny 2026-05-01 00:14:40 +02:00 committed by Marge Bot
parent 021cbaba7d
commit 3c2e75573e
3 changed files with 15 additions and 16 deletions

View file

@ -296,6 +296,17 @@ AssemblerVisitor::emit_alu_op(const AluInstr& ai)
m_last_addr = nullptr;
}
if (ai.has_alu_flag(alu_write) &&
dst &&
dst->sel() > g_clause_local_end &&
dst->sel() != g_registers_unused) {
R600_ASM_ERR("shader_from_nir: Don't support more then 123 GPRs + 4 clause "
"local, but try using %d\n",
dst->sel());
m_result = false;
return;
}
if (m_legacy_math_rules)
opcode = translate_for_mathrules(opcode);
@ -324,10 +335,7 @@ AssemblerVisitor::emit_alu_op(const AluInstr& ai)
if (ai.bank_swizzle() != alu_vec_unknown)
alu.bank_swizzle_force = ai.bank_swizzle();
if (!fill_alu_dst(alu, ai, m_bc)) {
m_result = false;
return;
}
fill_alu_dst(alu, ai, m_bc);
fill_alu_src_operands(alu, ai, m_bc);

View file

@ -548,25 +548,17 @@ fill_alu_src_operands(r600_bytecode_alu& alu, const AluInstr& ai, r600_bytecode&
}
}
bool
void
fill_alu_dst(r600_bytecode_alu& alu, const AluInstr& ai, r600_bytecode& bc)
{
auto dst = ai.dest();
if (dst) {
sfn_log << SfnLog::assembly << " Current dst register is " << *dst << "\n";
if (ai.opcode() != op1_mova_int) {
bool write = ai.has_alu_flag(alu_write);
if (write && dst->sel() > g_clause_local_end &&
dst->sel() != g_registers_unused) {
R600_ASM_ERR("shader_from_nir: Don't support more then 123 GPRs + 4 clause "
"local, but try using %d\n",
dst->sel());
return false;
}
alu.dst.sel = dst->sel() != g_registers_unused ? dst->sel() : g_registers_end;
alu.dst.chan = dst->chan();
alu.dst.write = write;
alu.dst.write = ai.has_alu_flag(alu_write);
alu.dst.rel = dst->addr() ? 1 : 0;
} else if (bc.gfx_level == CAYMAN && dst->sel() > 0) {
alu.dst.sel = dst->sel() + 1;
@ -576,7 +568,6 @@ fill_alu_dst(r600_bytecode_alu& alu, const AluInstr& ai, r600_bytecode& bc)
}
alu.dst.clamp = ai.has_alu_flag(alu_dst_clamp);
return true;
}
} // namespace r600

View file

@ -55,7 +55,7 @@ void fill_alu_src_operands(r600_bytecode_alu& alu,
const AluInstr& ai,
r600_bytecode& bc);
bool fill_alu_dst(r600_bytecode_alu& alu,
void fill_alu_dst(r600_bytecode_alu& alu,
const AluInstr& ai,
r600_bytecode& bc);