r600/sfn: replace hand-backed literal check by NIR function
Signed-off-by: Gert Wollny <gert.wollny@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6879>
This commit is contained in:
@@ -134,15 +134,6 @@ int EmitInstruction::lookup_register_index(const nir_dest& dst)
|
|||||||
return m_proc.lookup_register_index(dst);
|
return m_proc.lookup_register_index(dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
const nir_load_const_instr*
|
|
||||||
EmitInstruction::get_literal_register(const nir_src& src) const
|
|
||||||
{
|
|
||||||
if (src.is_ssa)
|
|
||||||
return m_proc.get_literal_constant(src.ssa->index);
|
|
||||||
else
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
PValue EmitInstruction::get_temp_register(int channel)
|
PValue EmitInstruction::get_temp_register(int channel)
|
||||||
{
|
{
|
||||||
return m_proc.get_temp_register(channel);
|
return m_proc.get_temp_register(channel);
|
||||||
|
@@ -59,8 +59,6 @@ protected:
|
|||||||
PValue from_nir(const nir_alu_dest& v, unsigned component);
|
PValue from_nir(const nir_alu_dest& v, unsigned component);
|
||||||
PValue from_nir(const nir_dest& v, unsigned component);
|
PValue from_nir(const nir_dest& v, unsigned component);
|
||||||
|
|
||||||
const nir_load_const_instr* get_literal_register(const nir_src& src) const;
|
|
||||||
|
|
||||||
int lookup_register_index(const nir_src& src) const;
|
int lookup_register_index(const nir_src& src) const;
|
||||||
int lookup_register_index(const nir_dest& dst);
|
int lookup_register_index(const nir_dest& dst);
|
||||||
PValue create_register_from_nir_src(const nir_src& src, unsigned comp);
|
PValue create_register_from_nir_src(const nir_src& src, unsigned comp);
|
||||||
|
@@ -682,7 +682,7 @@ bool EmitTexInstruction::emit_tex_tg4(nir_tex_instr* instr, TexInputs& src)
|
|||||||
|
|
||||||
bool literal_offset = false;
|
bool literal_offset = false;
|
||||||
if (src.offset) {
|
if (src.offset) {
|
||||||
literal_offset = src.offset->is_ssa && get_literal_register(*src.offset);
|
literal_offset = nir_src_as_const_value(*src.offset) != 0;
|
||||||
r600::sfn_log << SfnLog::tex << " really have offsets and they are " <<
|
r600::sfn_log << SfnLog::tex << " really have offsets and they are " <<
|
||||||
(literal_offset ? "literal" : "varying") <<
|
(literal_offset ? "literal" : "varying") <<
|
||||||
"\n";
|
"\n";
|
||||||
@@ -976,11 +976,11 @@ void EmitTexInstruction::set_offsets(TexInstruction* ir, nir_src *offset)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
assert(offset->is_ssa);
|
assert(offset->is_ssa);
|
||||||
auto literal = get_literal_register(*offset);
|
auto literal = nir_src_as_const_value(*offset);
|
||||||
assert(literal);
|
assert(literal);
|
||||||
|
|
||||||
for (int i = 0; i < offset->ssa->num_components; ++i) {
|
for (int i = 0; i < offset->ssa->num_components; ++i) {
|
||||||
ir->set_offset(i, literal->value[i].i32);
|
ir->set_offset(i, literal[i].i32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -246,8 +246,8 @@ bool ShaderFromNir::emit_instruction(nir_instr *instr)
|
|||||||
return impl->emit_deref_instruction(nir_instr_as_deref(instr));
|
return impl->emit_deref_instruction(nir_instr_as_deref(instr));
|
||||||
case nir_instr_type_intrinsic:
|
case nir_instr_type_intrinsic:
|
||||||
return impl->emit_intrinsic_instruction(nir_instr_as_intrinsic(instr));
|
return impl->emit_intrinsic_instruction(nir_instr_as_intrinsic(instr));
|
||||||
case nir_instr_type_load_const:
|
case nir_instr_type_load_const: /* const values are loaded when needed */
|
||||||
return impl->set_literal_constant(nir_instr_as_load_const(instr));
|
return true;
|
||||||
case nir_instr_type_tex:
|
case nir_instr_type_tex:
|
||||||
return impl->emit_tex_instruction(instr);
|
return impl->emit_tex_instruction(instr);
|
||||||
case nir_instr_type_jump:
|
case nir_instr_type_jump:
|
||||||
|
@@ -291,18 +291,15 @@ bool GeometryShaderFromNir::emit_load_from_array(nir_intrinsic_instr* instr,
|
|||||||
{
|
{
|
||||||
auto dest = vec_from_nir(instr->dest, instr->num_components);
|
auto dest = vec_from_nir(instr->dest, instr->num_components);
|
||||||
|
|
||||||
const nir_load_const_instr* literal_index = nullptr;
|
auto literal_index = nir_src_as_const_value(*array_deref.index);
|
||||||
|
|
||||||
if (array_deref.index->is_ssa)
|
|
||||||
literal_index = get_literal_constant(array_deref.index->ssa->index);
|
|
||||||
|
|
||||||
if (!literal_index) {
|
if (!literal_index) {
|
||||||
sfn_log << SfnLog::err << "GS: Indirect input addressing not (yet) supported\n";
|
sfn_log << SfnLog::err << "GS: Indirect input addressing not (yet) supported\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
assert(literal_index->value[0].u32 < 6);
|
assert(literal_index->u32 < 6);
|
||||||
PValue addr = m_per_vertex_offsets[literal_index->value[0].u32];
|
|
||||||
|
|
||||||
|
PValue addr = m_per_vertex_offsets[literal_index->u32];
|
||||||
auto fetch = new FetchInstruction(vc_fetch, no_index_offset, dest, addr,
|
auto fetch = new FetchInstruction(vc_fetch, no_index_offset, dest, addr,
|
||||||
16 * array_deref.var->data.driver_location,
|
16 * array_deref.var->data.driver_location,
|
||||||
R600_GS_RING_CONST_BUFFER, PValue(), bim_none, true);
|
R600_GS_RING_CONST_BUFFER, PValue(), bim_none, true);
|
||||||
|
@@ -113,18 +113,18 @@ PValue ValuePool::from_nir(const nir_src& v, unsigned component, unsigned swizzl
|
|||||||
return reg;
|
return reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto literal_val = nir_src_as_const_value(v);
|
||||||
auto literal_val = m_literal_constants.find(index);
|
if (literal_val) {
|
||||||
if (literal_val != m_literal_constants.end()) {
|
assert(v.is_ssa);
|
||||||
switch (literal_val->second->def.bit_size) {
|
switch (v.ssa->bit_size) {
|
||||||
case 1:
|
case 1:
|
||||||
return PValue(new LiteralValue(literal_val->second->value[swizzled].b ? 0xffffffff : 0, component));
|
return PValue(new LiteralValue(literal_val[swizzled].b ? 0xffffffff : 0, component));
|
||||||
case 32:
|
case 32:
|
||||||
return literal(literal_val->second->value[swizzled].u32);
|
return literal(literal_val[swizzled].u32);
|
||||||
default:
|
default:
|
||||||
sfn_log << SfnLog::reg << "Unsupported bit size " << literal_val->second->def.bit_size
|
sfn_log << SfnLog::reg << "Unsupported bit size " << v.ssa->bit_size
|
||||||
<< " fall back to 32\n";
|
<< " fall back to 32\n";
|
||||||
return PValue(new LiteralValue(literal_val->second->value[swizzled].u32, component));
|
return PValue(new LiteralValue(literal_val[swizzled].u32, component));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,38 +481,6 @@ bool ValuePool::create_undef(nir_ssa_undef_instr* instr)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ValuePool::set_literal_constant(nir_load_const_instr* instr)
|
|
||||||
{
|
|
||||||
sfn_log << SfnLog::reg << "Add literal " << instr->def.index << "\n";
|
|
||||||
m_literal_constants[instr->def.index] = instr;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const nir_load_const_instr* ValuePool::get_literal_constant(int index)
|
|
||||||
{
|
|
||||||
sfn_log << SfnLog::reg << "Try to locate literal " << index << "...";
|
|
||||||
auto literal = m_literal_constants.find(index);
|
|
||||||
if (literal == m_literal_constants.end()) {
|
|
||||||
sfn_log << SfnLog::reg << " not found\n";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
sfn_log << SfnLog::reg << " found\n";
|
|
||||||
return literal->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ValuePool::add_uniform(unsigned index, const PValue& value)
|
|
||||||
{
|
|
||||||
sfn_log << SfnLog::reg << "Reserve " << *value << " as " << index << "\n";
|
|
||||||
m_uniforms[index] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
PValue ValuePool::uniform(unsigned index)
|
|
||||||
{
|
|
||||||
sfn_log << SfnLog::reg << "Search index " << index << "\n";
|
|
||||||
auto i = m_uniforms.find(index);
|
|
||||||
return i == m_uniforms.end() ? PValue() : i->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ValuePool::allocate_with_mask(unsigned index, unsigned mask, bool pre_alloc)
|
int ValuePool::allocate_with_mask(unsigned index, unsigned mask, bool pre_alloc)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
@@ -159,9 +159,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool create_undef(nir_ssa_undef_instr* instr);
|
bool create_undef(nir_ssa_undef_instr* instr);
|
||||||
|
|
||||||
bool set_literal_constant(nir_load_const_instr* instr);
|
|
||||||
|
|
||||||
const nir_load_const_instr *get_literal_constant(int index);
|
|
||||||
|
|
||||||
void add_uniform(unsigned index, const PValue &value);
|
void add_uniform(unsigned index, const PValue &value);
|
||||||
|
|
||||||
@@ -225,8 +222,6 @@ private:
|
|||||||
|
|
||||||
std::set<unsigned> m_ssa_undef;
|
std::set<unsigned> m_ssa_undef;
|
||||||
|
|
||||||
LiteralBuffer m_literal_constants;
|
|
||||||
|
|
||||||
std::map<unsigned, unsigned> m_local_register_map;
|
std::map<unsigned, unsigned> m_local_register_map;
|
||||||
std::map<unsigned, unsigned> m_ssa_register_map;
|
std::map<unsigned, unsigned> m_ssa_register_map;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user