1 /*
2 * Copyright © 2022 Imagination Technologies Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #include "rogue.h"
25 #include "rogue_builder.h"
26 #include "util/macros.h"
27
28 #include <stdbool.h>
29
30 /**
31 * \file rogue_schedule_uvsw.c
32 *
33 * \brief Contains the rogue_schedule_uvsw pass.
34 */
35
36 /* TODO: See if maybe this can/should be done in rogue_lower_END instead? */
37
38 /* Schedules UVSW task control instructions. */
39 PUBLIC
rogue_schedule_uvsw(rogue_shader * shader,bool latency_hiding)40 bool rogue_schedule_uvsw(rogue_shader *shader, bool latency_hiding)
41 {
42 if (shader->is_grouped)
43 return false;
44
45 /* TODO: Support for other shader types that write to the unified vertex
46 * store. */
47 if (shader->stage != MESA_SHADER_VERTEX)
48 return false;
49
50 /* TODO: Add support for delayed scheduling (latency hiding). */
51 if (latency_hiding)
52 unreachable("Latency hiding is unimplemented.");
53
54 rogue_builder b;
55 rogue_builder_init(&b, shader);
56
57 /* Check whether there are uvsw.writes. */
58 bool uvsw_write_present = false;
59 rogue_foreach_instr_in_shader (instr, shader) {
60 if (instr->type != ROGUE_INSTR_TYPE_BACKEND)
61 continue;
62
63 rogue_backend_instr *backend = rogue_instr_as_backend(instr);
64 if (backend->op != ROGUE_BACKEND_OP_UVSW_WRITE)
65 continue;
66
67 uvsw_write_present = true;
68 break;
69 }
70
71 if (!uvsw_write_present)
72 return false;
73
74 /* Insert emit/end task before the final instruction (nop.end). */
75 rogue_block *final_block =
76 list_last_entry(&shader->blocks, rogue_block, link);
77 rogue_instr *final_instr =
78 list_last_entry(&final_block->instrs, rogue_instr, link);
79
80 if (!rogue_instr_is_nop_end(final_instr))
81 unreachable("UVSW emit/end task need to be the final instruction.");
82
83 b.cursor = rogue_cursor_before_instr(final_instr);
84
85 /* TODO: If instruction before nop.end is uvsw.write then
86 * UVSW_WRITETHENEMITTHENENDTASK. */
87
88 rogue_UVSW_EMIT(&b);
89 rogue_UVSW_ENDTASK(&b);
90
91 /* TODO: replace nop.end and add end flag to final uvsw instruction instead.
92 */
93
94 return true;
95 }
96