3 * Copyright (c) 2019 Collabora LTD
5 * Author: Gert Wollny <gert.wollny@collabora.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "sfn_instruction_gds.h"
28 #include "sfn_liverange.h"
32 GDSInstr::GDSInstr(ESDOp op
, const GPRVector
& dest
, const PValue
& value
,
33 const PValue
& value2
, const PValue
& uav_id
, int uav_base
):
39 m_dest_swizzle({PIPE_SWIZZLE_X
,7,7,7}),
40 m_src_swizzle({PIPE_SWIZZLE_0
, PIPE_SWIZZLE_X
, PIPE_SWIZZLE_0
}),
41 m_buffer_index_mode(bim_none
),
46 add_remappable_src_value(&m_src
);
47 add_remappable_src_value(&m_src2
);
48 add_remappable_src_value(&m_uav_id
);
49 add_remappable_dst_value(&m_dest
);
50 m_dest_swizzle
[0] = m_dest
.chan_i(0);
53 GDSInstr::GDSInstr(ESDOp op
, const GPRVector
& dest
, const PValue
& value
,
54 const PValue
& uav_id
, int uav_base
):
55 GDSInstr(op
, dest
, value
, PValue(), uav_id
, uav_base
)
58 m_src_swizzle
[1] = value
->chan();
59 m_src_swizzle
[2] = PIPE_SWIZZLE_0
;
62 GDSInstr::GDSInstr(ESDOp op
, const GPRVector
& dest
,
63 const PValue
& uav_id
, int uav_base
):
64 GDSInstr(op
, dest
, PValue(), PValue(), uav_id
, uav_base
)
66 m_src_swizzle
[1] = PIPE_SWIZZLE_0
;
69 bool GDSInstr::is_equal_to(UNUSED
const Instruction
& lhs
) const
74 void GDSInstr::do_print(std::ostream
& os
) const
76 const char *swz
= "xyzw01?_";
77 os
<< lds_ops
.at(m_op
).name
<< " R" << m_dest
.sel() << ".";
78 for (int i
= 0; i
< 4; ++i
) {
79 os
<< swz
[m_dest_swizzle
[i
]];
84 os
<< " UAV:" << *m_uav_id
;
87 RatInstruction::RatInstruction(ECFOpCode cf_opcode
, ERatOp rat_op
,
88 const GPRVector
& data
, const GPRVector
& index
,
89 int rat_id
, const PValue
& rat_id_offset
,
90 int burst_count
, int comp_mask
, int element_size
, bool ack
):
92 m_cf_opcode(cf_opcode
),
97 m_rat_id_offset(rat_id_offset
),
98 m_burst_count(burst_count
),
99 m_comp_mask(comp_mask
),
100 m_element_size(element_size
),
103 add_remappable_src_value(&m_data
);
104 add_remappable_src_value(&m_rat_id_offset
);
105 add_remappable_src_value(&m_index
);
108 bool RatInstruction::is_equal_to(UNUSED
const Instruction
& lhs
) const
113 void RatInstruction::do_print(std::ostream
& os
) const
115 os
<< "MEM_RAT RAT(" << m_rat_id
;
117 os
<< "+" << *m_rat_id_offset
;
118 os
<< ") @" << m_index
;
119 os
<< " OP:" << m_rat_op
<< " " << m_data
;
120 os
<< " BC:" << m_burst_count
121 << " MASK:" << m_comp_mask
122 << " ES:" << m_element_size
;
127 RatInstruction::ERatOp
RatInstruction::opcode(nir_intrinsic_op opcode
)
130 case nir_intrinsic_ssbo_atomic_add
:
132 case nir_intrinsic_ssbo_atomic_and
:
134 case nir_intrinsic_ssbo_atomic_exchange
:
136 case nir_intrinsic_ssbo_atomic_umax
:
138 case nir_intrinsic_ssbo_atomic_umin
:
140 case nir_intrinsic_ssbo_atomic_imax
:
142 case nir_intrinsic_ssbo_atomic_imin
:
144 case nir_intrinsic_ssbo_atomic_xor
:
151 GDSStoreTessFactor::GDSStoreTessFactor(GPRVector
& value
):
152 Instruction(tf_write
),
155 add_remappable_src_value(&m_value
);
158 void GDSStoreTessFactor::replace_values(const ValueSet
& candiates
, PValue new_value
)
160 for (auto& c
: candiates
) {
161 for (int i
= 0; i
< 4; ++i
) {
162 if (*c
== *m_value
[i
])
163 m_value
[i
] = new_value
;
169 bool GDSStoreTessFactor::is_equal_to(const Instruction
& lhs
) const
171 auto& other
= static_cast<const GDSStoreTessFactor
&>(lhs
);
172 return m_value
== other
.m_value
;
175 void GDSStoreTessFactor::do_print(std::ostream
& os
) const
177 os
<< "TF_WRITE " << m_value
;