From 31e42fb780f32665ac1dd69d662d4c5dd32b1916 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Sun, 27 Sep 2020 16:24:56 +0200 Subject: [PATCH] r600/sfn: replace hand-backed literal check by NIR function Signed-off-by: Gert Wollny Part-of: --- .../drivers/r600/sfn/sfn_emitinstruction.cpp | 9 ---- src/gallium/drivers/r600/sfn/sfn_emitinstruction.h | 2 - .../drivers/r600/sfn/sfn_emittexinstruction.cpp | 6 +-- src/gallium/drivers/r600/sfn/sfn_nir.cpp | 4 +- .../drivers/r600/sfn/sfn_shader_geometry.cpp | 9 ++-- src/gallium/drivers/r600/sfn/sfn_valuepool.cpp | 48 ++++------------------ src/gallium/drivers/r600/sfn/sfn_valuepool.h | 5 --- 7 files changed, 16 insertions(+), 67 deletions(-) diff --git a/src/gallium/drivers/r600/sfn/sfn_emitinstruction.cpp b/src/gallium/drivers/r600/sfn/sfn_emitinstruction.cpp index f1ddd7a..06bf690 100644 --- a/src/gallium/drivers/r600/sfn/sfn_emitinstruction.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_emitinstruction.cpp @@ -134,15 +134,6 @@ int EmitInstruction::lookup_register_index(const nir_dest& 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) { return m_proc.get_temp_register(channel); diff --git a/src/gallium/drivers/r600/sfn/sfn_emitinstruction.h b/src/gallium/drivers/r600/sfn/sfn_emitinstruction.h index 9c7614f..5cfb9f6 100644 --- a/src/gallium/drivers/r600/sfn/sfn_emitinstruction.h +++ b/src/gallium/drivers/r600/sfn/sfn_emitinstruction.h @@ -59,8 +59,6 @@ protected: PValue from_nir(const nir_alu_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_dest& dst); PValue create_register_from_nir_src(const nir_src& src, unsigned comp); diff --git a/src/gallium/drivers/r600/sfn/sfn_emittexinstruction.cpp b/src/gallium/drivers/r600/sfn/sfn_emittexinstruction.cpp index 1df96f6..adb10fc 100644 --- a/src/gallium/drivers/r600/sfn/sfn_emittexinstruction.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_emittexinstruction.cpp @@ -682,7 +682,7 @@ bool EmitTexInstruction::emit_tex_tg4(nir_tex_instr* instr, TexInputs& src) bool literal_offset = false; 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 " << (literal_offset ? "literal" : "varying") << "\n"; @@ -976,11 +976,11 @@ void EmitTexInstruction::set_offsets(TexInstruction* ir, nir_src *offset) return; assert(offset->is_ssa); - auto literal = get_literal_register(*offset); + auto literal = nir_src_as_const_value(*offset); assert(literal); 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); } } diff --git a/src/gallium/drivers/r600/sfn/sfn_nir.cpp b/src/gallium/drivers/r600/sfn/sfn_nir.cpp index 0a19324..82cd417 100644 --- a/src/gallium/drivers/r600/sfn/sfn_nir.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_nir.cpp @@ -246,8 +246,8 @@ bool ShaderFromNir::emit_instruction(nir_instr *instr) return impl->emit_deref_instruction(nir_instr_as_deref(instr)); case nir_instr_type_intrinsic: return impl->emit_intrinsic_instruction(nir_instr_as_intrinsic(instr)); - case nir_instr_type_load_const: - return impl->set_literal_constant(nir_instr_as_load_const(instr)); + case nir_instr_type_load_const: /* const values are loaded when needed */ + return true; case nir_instr_type_tex: return impl->emit_tex_instruction(instr); case nir_instr_type_jump: diff --git a/src/gallium/drivers/r600/sfn/sfn_shader_geometry.cpp b/src/gallium/drivers/r600/sfn/sfn_shader_geometry.cpp index 5ebeec6..3862986 100644 --- a/src/gallium/drivers/r600/sfn/sfn_shader_geometry.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_shader_geometry.cpp @@ -291,18 +291,15 @@ bool GeometryShaderFromNir::emit_load_from_array(nir_intrinsic_instr* instr, { auto dest = vec_from_nir(instr->dest, instr->num_components); - const nir_load_const_instr* literal_index = nullptr; - - if (array_deref.index->is_ssa) - literal_index = get_literal_constant(array_deref.index->ssa->index); + auto literal_index = nir_src_as_const_value(*array_deref.index); if (!literal_index) { sfn_log << SfnLog::err << "GS: Indirect input addressing not (yet) supported\n"; return false; } - assert(literal_index->value[0].u32 < 6); - PValue addr = m_per_vertex_offsets[literal_index->value[0].u32]; + assert(literal_index->u32 < 6); + PValue addr = m_per_vertex_offsets[literal_index->u32]; auto fetch = new FetchInstruction(vc_fetch, no_index_offset, dest, addr, 16 * array_deref.var->data.driver_location, R600_GS_RING_CONST_BUFFER, PValue(), bim_none, true); diff --git a/src/gallium/drivers/r600/sfn/sfn_valuepool.cpp b/src/gallium/drivers/r600/sfn/sfn_valuepool.cpp index 6b91312..87b459f 100644 --- a/src/gallium/drivers/r600/sfn/sfn_valuepool.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_valuepool.cpp @@ -113,18 +113,18 @@ PValue ValuePool::from_nir(const nir_src& v, unsigned component, unsigned swizzl return reg; } - - auto literal_val = m_literal_constants.find(index); - if (literal_val != m_literal_constants.end()) { - switch (literal_val->second->def.bit_size) { + auto literal_val = nir_src_as_const_value(v); + if (literal_val) { + assert(v.is_ssa); + switch (v.ssa->bit_size) { 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: - return literal(literal_val->second->value[swizzled].u32); + return literal(literal_val[swizzled].u32); 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"; - 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; } -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 retval; diff --git a/src/gallium/drivers/r600/sfn/sfn_valuepool.h b/src/gallium/drivers/r600/sfn/sfn_valuepool.h index dc44777..f6fbfa1 100644 --- a/src/gallium/drivers/r600/sfn/sfn_valuepool.h +++ b/src/gallium/drivers/r600/sfn/sfn_valuepool.h @@ -159,9 +159,6 @@ public: */ 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); @@ -225,8 +222,6 @@ private: std::set m_ssa_undef; - LiteralBuffer m_literal_constants; - std::map m_local_register_map; std::map m_ssa_register_map; -- 2.7.4