r600/sfn: Move removing of unused variables
[mesa.git] / src / gallium / drivers / r600 / sfn / sfn_shader_compute.cpp
1 /* -*- mesa-c++ -*-
2 *
3 * Copyright (c) 2018 Collabora LTD
4 *
5 * Author: Gert Wollny <gert.wollny@collabora.com>
6 *
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:
13 *
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
16 * Software.
17 *
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.
25 */
26
27 #include "sfn_shader_compute.h"
28 #include "sfn_instruction_fetch.h"
29
30 namespace r600 {
31
32 ComputeShaderFromNir::ComputeShaderFromNir(r600_pipe_shader *sh,
33 r600_pipe_shader_selector& sel,
34 UNUSED const r600_shader_key& key):
35 ShaderFromNirProcessor (PIPE_SHADER_COMPUTE, sel, sh->shader,
36 sh->scratch_space_needed),
37 m_reserved_registers(0)
38 {
39 }
40
41 bool ComputeShaderFromNir::scan_sysvalue_access(UNUSED nir_instr *instr)
42 {
43 return true;
44 }
45 bool ComputeShaderFromNir::allocate_reserved_registers()
46 {
47 int thread_id_sel = m_reserved_registers++;
48 int wg_id_sel = m_reserved_registers++;
49
50 for (int i = 0; i < 3; ++i) {
51 auto tmp = new GPRValue(thread_id_sel, i);
52 tmp->set_as_input();
53 m_local_invocation_id[i] = PValue(tmp);
54 inject_register(tmp->sel(), i, m_local_invocation_id[i], false);
55
56 tmp = new GPRValue(wg_id_sel, i);
57 tmp->set_as_input();
58 m_workgroup_id[i] = PValue(tmp);
59 inject_register(tmp->sel(), i, m_workgroup_id[i], false);
60 }
61 return true;
62 }
63
64 bool ComputeShaderFromNir::emit_intrinsic_instruction_override(nir_intrinsic_instr* instr)
65 {
66 switch (instr->intrinsic) {
67 case nir_intrinsic_load_local_invocation_id:
68 return emit_load_3vec(instr, m_local_invocation_id);
69 case nir_intrinsic_load_work_group_id:
70 return emit_load_3vec(instr, m_workgroup_id);
71 case nir_intrinsic_load_num_work_groups:
72 return emit_load_num_work_groups(instr);
73 default:
74 return false;
75 }
76 }
77
78 bool ComputeShaderFromNir::emit_load_3vec(nir_intrinsic_instr* instr,
79 const std::array<PValue,3>& src)
80 {
81 AluInstruction *ir = nullptr;
82 for (int i = 0; i < 3; ++i) {
83 ir = new AluInstruction(op1_mov, from_nir(instr->dest, i), src[i], {alu_write});
84 emit_instruction(ir);
85 }
86 ir->set_flag(alu_last_instr);
87 return true;
88 }
89
90 bool ComputeShaderFromNir::emit_load_num_work_groups(nir_intrinsic_instr* instr)
91 {
92 int temp = allocate_temp_register();
93 PValue a_zero(new GPRValue(temp, 1));
94 emit_instruction(new AluInstruction(op1_mov, a_zero, Value::zero, EmitInstruction::last_write));
95 GPRVector dest;
96 for (int i = 0; i < 3; ++i)
97 dest.set_reg_i(i, from_nir(instr->dest, i));
98 dest.set_reg_i(3, from_nir(instr->dest, 7));
99
100 auto ir = new FetchInstruction(vc_fetch, no_index_offset,
101 fmt_32_32_32_32, vtx_nf_int, vtx_es_none, a_zero, dest, 16,
102 false, 16, R600_BUFFER_INFO_CONST_BUFFER, 0,
103 bim_none, false, false, 0, 0, 0, PValue(), {0,1,2,7});
104 ir->set_flag(vtx_srf_mode);
105 emit_instruction(ir);
106 return true;
107 }
108
109 bool ComputeShaderFromNir::do_process_inputs(UNUSED nir_variable *input)
110 {
111 return true;
112 }
113
114 bool ComputeShaderFromNir::do_process_outputs(UNUSED nir_variable *output)
115 {
116 return true;
117 }
118
119 bool ComputeShaderFromNir::do_emit_load_deref(UNUSED const nir_variable *in_var,
120 UNUSED nir_intrinsic_instr* instr)
121 {
122 return true;
123 }
124
125 bool ComputeShaderFromNir::do_emit_store_deref(UNUSED const nir_variable *out_var,
126 UNUSED nir_intrinsic_instr* instr)
127 {
128 return true;
129 }
130 void ComputeShaderFromNir::do_finalize()
131 {
132
133 }
134
135 }