r600/sfn: copy-propagate single source texture values

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18619>
This commit is contained in:
Gert Wollny 2022-09-05 17:38:33 +02:00 committed by Marge Bot
parent 1fc76aae10
commit c23604324b
4 changed files with 56 additions and 13 deletions

View file

@ -357,6 +357,28 @@ bool TexInstr::from_nir(nir_tex_instr *tex, Shader& shader)
return true;
}
bool TexInstr::replace_source(PRegister old_src, PVirtualValue new_src)
{
if (old_src->pin() != pin_free)
return false;
if (!new_src->as_register())
return false;
bool success = false;
for (int i = 0; i < 4; ++i) {
if (m_src[i]->equal_to(*old_src)) {
m_src.set_value(i, new_src->as_register());
success = true;
}
}
if (success) {
old_src->del_use(this);
new_src->as_register()->add_use(this);
}
return success;
}
struct SamplerId {
int id;
bool indirect;

View file

@ -154,6 +154,8 @@ public:
auto prepare_instr() const { return m_prepare_instr;}
bool replace_source(PRegister old_src, PVirtualValue new_src) override;
private:
bool do_ready() const override;

View file

@ -522,7 +522,20 @@ void SimplifySourceVecVisitor::visit(TexInstr *instr)
{
if (instr->opcode() != TexInstr::get_resinfo) {
replace_src(instr, instr->src());
auto& src = instr->src();
replace_src(instr, src);
int nvals = 0;
for (int i = 0; i < 4; ++i)
if (src[i]->chan() < 4)
++nvals;
if (nvals == 1) {
for (int i = 0; i < 4; ++i)
if (src[i]->chan() < 4)
src[i]->set_pin(pin_free);
}
}
for (auto& prep : instr->prepare_instr()) {
prep->accept(*this);
}
}

View file

@ -272,21 +272,27 @@ public:
return m_values[i]->value();
}
PRegister operator [] (int i) {
return m_values[i]->value();
}
PRegister operator [] (int i) {
return m_values[i]->value();
}
void set_value(int i, PRegister reg) {
assert(reg->sel() == m_sel);
m_swz[i] = reg->chan();
m_values[i]->set_value(reg);
}
void set_value(int i, PRegister reg) {
if (reg->chan() < 4) {
for (int k = 0; k < 4; ++k) {
assert(i == k || m_values[k]->value()->chan() > 3 ||
m_values[k]->value()->sel() == reg->sel());
}
m_sel = reg->sel();
}
m_swz[i] = reg->chan();
m_values[i]->set_value(reg);
}
bool ready(int block_id, int index) const;
bool ready(int block_id, int index) const;
private:
int m_sel;
Swizzle m_swz;
std::array<R600_POINTER_TYPE(Element), 4> m_values;
int m_sel;
Swizzle m_swz;
std::array<R600_POINTER_TYPE(Element), 4> m_values;
};
bool operator == (const RegisterVec4& lhs, const RegisterVec4& rhs);