pan/bi: Fix off-by-one in scoreboarding packing
[mesa.git] / src / panfrost / bifrost / bi_schedule.c
1 /*
2 * Copyright (C) 2020 Collabora Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is 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
18 * THE 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 * Authors (Collabora):
24 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
25 */
26
27 #include "compiler.h"
28
29 /* Finds the clause type required or return none */
30
31 static enum bifrost_clause_type
32 bi_clause_type_for_ins(bi_instruction *ins)
33 {
34 unsigned T = ins->type;
35
36 /* Only high latency ops impose clause types */
37 if (!(bi_class_props[T] & BI_SCHED_HI_LATENCY))
38 return BIFROST_CLAUSE_NONE;
39
40 switch (T) {
41 case BI_BRANCH:
42 case BI_DISCARD:
43 return BIFROST_CLAUSE_NONE;
44
45 case BI_LOAD_VAR:
46 return BIFROST_CLAUSE_LOAD_VARY;
47
48 case BI_LOAD_UNIFORM:
49 case BI_LOAD_ATTR:
50 case BI_LOAD_VAR_ADDRESS:
51 return BIFROST_CLAUSE_UBO;
52
53 case BI_TEX:
54 return BIFROST_CLAUSE_TEX;
55
56 case BI_LOAD:
57 return BIFROST_CLAUSE_SSBO_LOAD;
58
59 case BI_STORE:
60 case BI_STORE_VAR:
61 return BIFROST_CLAUSE_SSBO_STORE;
62
63 case BI_BLEND:
64 return BIFROST_CLAUSE_BLEND;
65
66 case BI_ATEST:
67 return BIFROST_CLAUSE_ATEST;
68
69 default:
70 unreachable("Invalid high-latency class");
71 }
72 }
73
74 /* Eventually, we'll need a proper scheduling, grouping instructions
75 * into clauses and ordering/assigning grouped instructions to the
76 * appropriate FMA/ADD slots. Right now we do the dumbest possible
77 * thing just to have the scheduler stubbed out so we can focus on
78 * codegen */
79
80 void
81 bi_schedule(bi_context *ctx)
82 {
83 unsigned ids = 0;
84 unsigned last_id = 0;
85 bool is_first = true;
86
87 bi_foreach_block(ctx, block) {
88 bi_block *bblock = (bi_block *) block;
89
90 list_inithead(&bblock->clauses);
91
92 bi_foreach_instr_in_block(bblock, ins) {
93 unsigned props = bi_class_props[ins->type];
94
95 bi_clause *u = rzalloc(ctx, bi_clause);
96 u->bundle_count = 1;
97
98 if (props & BI_SCHED_FMA)
99 u->bundles[0].fma = ins;
100 else
101 u->bundles[0].add = ins;
102
103 u->scoreboard_id = ids++;
104
105 if (is_first)
106 is_first = false;
107 else {
108 /* Rule: first instructions cannot have write barriers */
109 u->dependencies |= (1 << last_id);
110 u->data_register_write_barrier = true;
111 }
112
113 ids = ids & 1;
114 last_id = u->scoreboard_id;
115 u->back_to_back = true;
116
117 u->constant_count = 1;
118 u->constants[0] = ins->constant.u64;
119
120 u->clause_type = bi_clause_type_for_ins(ins);
121
122 list_addtail(&u->link, &bblock->clauses);
123 }
124
125 bblock->scheduled = true;
126 }
127 }