From e9f60482fba70ed2b1d80dd1dc2cb8cf6e7419ca Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Thu, 10 Aug 2023 16:02:48 +0200 Subject: [PATCH] r600/sfn: factor out resource as extra class Signed-off-by: Gert Wollny Part-of: --- src/gallium/drivers/r600/sfn/sfn_assembler.cpp | 10 ++++---- src/gallium/drivers/r600/sfn/sfn_instr.cpp | 9 ++++++-- src/gallium/drivers/r600/sfn/sfn_instr.h | 29 ++++++++++++------------ src/gallium/drivers/r600/sfn/sfn_instr_fetch.cpp | 2 +- src/gallium/drivers/r600/sfn/sfn_instr_fetch.h | 2 -- src/gallium/drivers/r600/sfn/sfn_instr_mem.cpp | 14 ++++++++++-- src/gallium/drivers/r600/sfn/sfn_instr_mem.h | 8 +++++-- 7 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/gallium/drivers/r600/sfn/sfn_assembler.cpp b/src/gallium/drivers/r600/sfn/sfn_assembler.cpp index 208ec68..3bf92b7 100644 --- a/src/gallium/drivers/r600/sfn/sfn_assembler.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_assembler.cpp @@ -81,7 +81,7 @@ public: PVirtualValue copy_src(r600_bytecode_alu_src& src, const VirtualValue& s); EBufferIndexMode emit_index_reg(const VirtualValue& addr, unsigned idx); - EBufferIndexMode get_index_mode(const InstrWithResource& instr, + EBufferIndexMode get_index_mode(const Resource& res, unsigned idx); void emit_endif(); @@ -1240,13 +1240,13 @@ AssamblerVisitor::copy_dst(r600_bytecode_alu_dst& dst, const Register& d, bool w return true; } -EBufferIndexMode AssamblerVisitor::get_index_mode(const InstrWithResource& instr, +EBufferIndexMode AssamblerVisitor::get_index_mode(const Resource& res, unsigned idx) { - EBufferIndexMode index_mode = instr.buffer_index_mode(); + EBufferIndexMode index_mode = res.buffer_index_mode(); - if (index_mode == bim_none && instr.resource_offset()) - index_mode = emit_index_reg(*instr.resource_offset(), idx); + if (index_mode == bim_none && res.resource_offset()) + index_mode = emit_index_reg(*res.resource_offset(), idx); return index_mode; } diff --git a/src/gallium/drivers/r600/sfn/sfn_instr.cpp b/src/gallium/drivers/r600/sfn/sfn_instr.cpp index 21b5e3a..17e76ba 100644 --- a/src/gallium/drivers/r600/sfn/sfn_instr.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_instr.cpp @@ -216,7 +216,7 @@ InstrWithVectorResult::InstrWithVectorResult(const RegisterVec4& dest, const RegisterVec4::Swizzle& dest_swizzle, int resource_base, PRegister resource_offset): - InstrWithResource(resource_base, resource_offset), + Resource(this, resource_base, resource_offset), m_dest(dest), m_dest_swizzle(dest_swizzle) { @@ -504,12 +504,17 @@ Block::lds_group_end() } InstrWithVectorResult::InstrWithVectorResult(const InstrWithVectorResult& orig): - InstrWithResource(orig), + Resource(orig), m_dest(orig.m_dest), m_dest_swizzle(orig.m_dest_swizzle) { } +void InstrWithVectorResult::update_indirect_addr(PRegister addr) +{ + set_resource_offset(addr); +} + class InstrComparer : public ConstInstrVisitor { public: InstrComparer() = default; diff --git a/src/gallium/drivers/r600/sfn/sfn_instr.h b/src/gallium/drivers/r600/sfn/sfn_instr.h index cf9166c..e66156b 100644 --- a/src/gallium/drivers/r600/sfn/sfn_instr.h +++ b/src/gallium/drivers/r600/sfn/sfn_instr.h @@ -263,22 +263,23 @@ private: uint32_t m_expected_ar_uses{0}; }; -class InstrWithResource : public Instr { +class Resource { public: - InstrWithResource(int base, PRegister offset): + Resource(Instr *user, int base, PRegister offset): m_base(base), - m_offset(offset) + m_offset(offset), + m_user(user) { if (m_offset) { - m_offset->add_use(this); + m_offset->add_use(m_user); } } bool replace_resource_offset(PRegister old_offset, PRegister new_offset) { if (m_offset && old_offset->equal_to(*m_offset)) { - m_offset->del_use(this); + m_offset->del_use(m_user); m_offset = new_offset; - m_offset->add_use(this); + m_offset->add_use(m_user); return true; } return false; @@ -286,14 +287,14 @@ public: void set_resource_offset(PRegister offset) { if (m_offset) - m_offset->del_use(this); + m_offset->del_use(m_user); m_offset = offset; if (m_offset) { - m_offset->add_use(this); + m_offset->add_use(m_user); } } - bool resource_is_equal(const InstrWithResource& other) const + bool resource_is_equal(const Resource& other) const { if (m_base != other.m_base) return false; @@ -326,11 +327,6 @@ public: return !m_offset || m_offset->ready(block_id, index); } - void update_indirect_addr(PRegister addr) override - { - set_resource_offset(addr); - } - protected: void print_resource_offset(std::ostream& os) const { @@ -341,9 +337,10 @@ protected: private: int m_base{0}; PRegister m_offset{nullptr}; + Instr *m_user; }; -class InstrWithVectorResult : public InstrWithResource { +class InstrWithVectorResult : public Instr, public Resource { public: InstrWithVectorResult(const RegisterVec4& dest, const RegisterVec4::Swizzle& dest_swizzle, @@ -355,6 +352,8 @@ public: const RegisterVec4::Swizzle& all_dest_swizzle() const { return m_dest_swizzle; } const RegisterVec4& dst() const { return m_dest; } + void update_indirect_addr(PRegister addr) override; + protected: InstrWithVectorResult(const InstrWithVectorResult& orig); diff --git a/src/gallium/drivers/r600/sfn/sfn_instr_fetch.cpp b/src/gallium/drivers/r600/sfn/sfn_instr_fetch.cpp index ba03d47..3b819a3 100644 --- a/src/gallium/drivers/r600/sfn/sfn_instr_fetch.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_instr_fetch.cpp @@ -48,7 +48,7 @@ FetchInstr::FetchInstr(EVFetchInstr opcode, EVFetchEndianSwap endian_swap, uint32_t resource_id, PRegister resource_offset): - InstrWithVectorResult(dst, dest_swizzle, resource_id, resource_offset), + InstrWithVectorResult(dst, dest_swizzle, resource_id, resource_offset), m_opcode(opcode), m_src(src), m_src_offset(src_offset), diff --git a/src/gallium/drivers/r600/sfn/sfn_instr_fetch.h b/src/gallium/drivers/r600/sfn/sfn_instr_fetch.h index be3dd74..3ec4888 100644 --- a/src/gallium/drivers/r600/sfn/sfn_instr_fetch.h +++ b/src/gallium/drivers/r600/sfn/sfn_instr_fetch.h @@ -81,8 +81,6 @@ public: } uint32_t src_offset() const { return m_src_offset; } - uint32_t resource_id() const __attribute__((deprecated)) { return resource_base(); } - EVFetchType fetch_type() const { return m_fetch_type; } EVTXDataFormat data_format() const { return m_data_format; } void set_num_format(EVFetchNumFormat nf) { m_num_format = nf; } diff --git a/src/gallium/drivers/r600/sfn/sfn_instr_mem.cpp b/src/gallium/drivers/r600/sfn/sfn_instr_mem.cpp index 395a4c2..1ce19e3 100644 --- a/src/gallium/drivers/r600/sfn/sfn_instr_mem.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_instr_mem.cpp @@ -39,7 +39,7 @@ namespace r600 { GDSInstr::GDSInstr( ESDOp op, Register *dest, const RegisterVec4& src, int uav_base, PRegister uav_id): - InstrWithResource(uav_base, uav_id), + Resource(this, uav_base, uav_id), m_op(op), m_dest(dest), m_src(src) @@ -373,6 +373,11 @@ GDSInstr::emit_atomic_pre_dec(nir_intrinsic_instr *instr, Shader& shader) return true; } +void GDSInstr::update_indirect_addr(PRegister addr) +{ + set_resource_offset(addr); +} + RatInstr::RatInstr(ECFOpCode cf_opcode, ERatOp rat_op, const RegisterVec4& data, @@ -382,7 +387,7 @@ RatInstr::RatInstr(ECFOpCode cf_opcode, int burst_count, int comp_mask, int element_size): - InstrWithResource(rat_id, rat_id_offset), + Resource(this, rat_id, rat_id_offset), m_cf_opcode(cf_opcode), m_rat_op(rat_op), m_data(data), @@ -442,6 +447,11 @@ RatInstr::do_print(std::ostream& os) const os << " ACK"; } +void RatInstr::update_indirect_addr(PRegister addr) +{ + set_resource_offset(addr); +} + static RatInstr::ERatOp get_rat_opcode(const nir_atomic_op opcode) { diff --git a/src/gallium/drivers/r600/sfn/sfn_instr_mem.h b/src/gallium/drivers/r600/sfn/sfn_instr_mem.h index 65c2b4b..a741a11 100644 --- a/src/gallium/drivers/r600/sfn/sfn_instr_mem.h +++ b/src/gallium/drivers/r600/sfn/sfn_instr_mem.h @@ -34,7 +34,7 @@ namespace r600 { class Shader; -class GDSInstr : public InstrWithResource { +class GDSInstr : public Instr, public Resource { public: GDSInstr( ESDOp op, Register *dest, const RegisterVec4& src, int uav_base, PRegister uav_id); @@ -59,6 +59,8 @@ public: uint32_t slots() const override { return 1; }; uint8_t allowed_src_chan_mask() const override; + void update_indirect_addr(PRegister addr) override; + private: static bool emit_atomic_read(nir_intrinsic_instr *intr, Shader& shader); static bool emit_atomic_op2(nir_intrinsic_instr *intr, Shader& shader); @@ -75,7 +77,7 @@ private: std::bitset<8> m_tex_flags; }; -class RatInstr : public InstrWithResource { +class RatInstr : public Instr, public Resource { public: enum ERatOp { @@ -166,6 +168,8 @@ public: static bool emit(nir_intrinsic_instr *intr, Shader& shader); + void update_indirect_addr(PRegister addr) override; + private: static bool emit_global_store(nir_intrinsic_instr *intr, Shader& shader); -- 2.7.4