r600/sfn: factor out resource as extra class

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24638>
This commit is contained in:
Gert Wollny 2023-08-10 16:02:48 +02:00 committed by Marge Bot
parent 0dea86e886
commit e9f60482fb
7 changed files with 45 additions and 29 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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);

View file

@ -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),

View file

@ -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; }

View file

@ -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)
{

View file

@ -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);