1 /*
2 * Copyright (c) 2017 Lima Project
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, sub license,
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
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the 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 NON-INFRINGEMENT. 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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25 #include "util/ralloc.h"
26 #include "util/register_allocate.h"
27 #include "util/u_debug.h"
28
29 #include "ppir.h"
30 #include "lima_context.h"
31
32 #define PPIR_REG_COUNT (6 * 4)
33
34 enum ppir_ra_reg_class {
35 ppir_ra_reg_class_vec1,
36 ppir_ra_reg_class_vec2,
37 ppir_ra_reg_class_vec3,
38 ppir_ra_reg_class_vec4,
39
40 /* 4 reg class for load/store instr regs:
41 * load/store instr has no swizzle field, so the (virtual) register
42 * must be allocated at the beginning of a (physical) register,
43 */
44 ppir_ra_reg_class_head_vec1,
45 ppir_ra_reg_class_head_vec2,
46 ppir_ra_reg_class_head_vec3,
47 ppir_ra_reg_class_head_vec4,
48
49 ppir_ra_reg_class_num,
50 };
51
ppir_regalloc_init(void * mem_ctx)52 struct ra_regs *ppir_regalloc_init(void *mem_ctx)
53 {
54 struct ra_regs *ret = ra_alloc_reg_set(mem_ctx, PPIR_REG_COUNT, false);
55 if (!ret)
56 return NULL;
57
58 /* Classes for contiguous 1-4 channel groups anywhere within a register. */
59 struct ra_class *classes[ppir_ra_reg_class_num];
60 for (int i = 0; i < ppir_ra_reg_class_head_vec1; i++) {
61 classes[i] = ra_alloc_contig_reg_class(ret, i + 1);
62
63 for (int j = 0; j < PPIR_REG_COUNT; j += 4) {
64 for (int swiz = 0; swiz < (4 - i); swiz++)
65 ra_class_add_reg(classes[i], j + swiz);
66 }
67 }
68
69 /* Classes for contiguous 1-4 channels with a start channel of .x */
70 for (int i = ppir_ra_reg_class_head_vec1; i < ppir_ra_reg_class_num; i++) {
71 classes[i] = ra_alloc_contig_reg_class(ret, i - ppir_ra_reg_class_head_vec1 + 1);
72
73 for (int j = 0; j < PPIR_REG_COUNT; j += 4)
74 ra_class_add_reg(classes[i], j);
75 }
76
77 ra_set_finalize(ret, NULL);
78 return ret;
79 }
80
ppir_regalloc_update_reglist_ssa(ppir_compiler * comp)81 static void ppir_regalloc_update_reglist_ssa(ppir_compiler *comp)
82 {
83 list_for_each_entry(ppir_block, block, &comp->block_list, list) {
84 list_for_each_entry(ppir_node, node, &block->node_list, list) {
85 if (!node->instr || node->op == ppir_op_const)
86 continue;
87
88 ppir_dest *dest = ppir_node_get_dest(node);
89 if (dest) {
90 ppir_reg *reg = NULL;
91
92 if (dest->type == ppir_target_ssa) {
93 reg = &dest->ssa;
94 if (node->is_out)
95 reg->out_reg = true;
96 list_addtail(®->list, &comp->reg_list);
97 comp->reg_num++;
98 }
99 }
100 }
101 }
102 }
103
ppir_regalloc_print_result(ppir_compiler * comp)104 static void ppir_regalloc_print_result(ppir_compiler *comp)
105 {
106 printf("======ppir regalloc result======\n");
107 list_for_each_entry(ppir_block, block, &comp->block_list, list) {
108 list_for_each_entry(ppir_instr, instr, &block->instr_list, list) {
109 printf("%03d:", instr->index);
110 for (int i = 0; i < PPIR_INSTR_SLOT_NUM; i++) {
111 ppir_node *node = instr->slots[i];
112 if (!node)
113 continue;
114
115 printf(" (%d|", node->index);
116
117 ppir_dest *dest = ppir_node_get_dest(node);
118 if (dest)
119 printf("%d", ppir_target_get_dest_reg_index(dest));
120
121 printf("|");
122
123 for (int i = 0; i < ppir_node_get_src_num(node); i++) {
124 if (i)
125 printf(" ");
126 printf("%d", ppir_target_get_src_reg_index(ppir_node_get_src(node, i)));
127 }
128
129 printf(")");
130 }
131 printf("\n");
132 }
133 }
134 printf("--------------------------\n");
135
136 printf("======ppir output regs======\n");
137 for (int i = 0; i < ppir_output_num; i++) {
138 if (comp->out_type_to_reg[i] != -1)
139 printf("%s: $%d\n", ppir_output_type_to_str(i),
140 (int)comp->out_type_to_reg[i]);
141 }
142 printf("--------------------------\n");
143 }
144
create_new_instr_after(ppir_block * block,ppir_instr * ref,ppir_node * node)145 static bool create_new_instr_after(ppir_block *block, ppir_instr *ref,
146 ppir_node *node)
147 {
148 ppir_instr *newinstr = ppir_instr_create(block);
149 if (unlikely(!newinstr))
150 return false;
151
152 list_del(&newinstr->list);
153 list_add(&newinstr->list, &ref->list);
154
155 if (!ppir_instr_insert_node(newinstr, node))
156 return false;
157
158 list_for_each_entry_from(ppir_instr, instr, ref, &block->instr_list, list) {
159 instr->seq++;
160 }
161 newinstr->seq = ref->seq+1;
162 newinstr->scheduled = true;
163 return true;
164 }
165
create_new_instr_before(ppir_block * block,ppir_instr * ref,ppir_node * node)166 static bool create_new_instr_before(ppir_block *block, ppir_instr *ref,
167 ppir_node *node)
168 {
169 ppir_instr *newinstr = ppir_instr_create(block);
170 if (unlikely(!newinstr))
171 return false;
172
173 list_del(&newinstr->list);
174 list_addtail(&newinstr->list, &ref->list);
175
176 if (!ppir_instr_insert_node(newinstr, node))
177 return false;
178
179 list_for_each_entry_from(ppir_instr, instr, ref, &block->instr_list, list) {
180 instr->seq++;
181 }
182 newinstr->seq = ref->seq-1;
183 newinstr->scheduled = true;
184 return true;
185 }
186
ppir_update_spilled_src(ppir_compiler * comp,ppir_block * block,ppir_node * node,ppir_src * src,ppir_node ** fill_node)187 static bool ppir_update_spilled_src(ppir_compiler *comp, ppir_block *block,
188 ppir_node *node, ppir_src *src,
189 ppir_node **fill_node)
190 {
191 /* nodes might have multiple references to the same value.
192 * avoid creating unnecessary loads for the same fill by
193 * saving the node resulting from the temporary load */
194 if (*fill_node)
195 goto update_src;
196
197 int num_components = src->reg->num_components;
198
199 /* alloc new node to load value */
200 ppir_node *load_node = ppir_node_create(block, ppir_op_load_temp, -1, 0);
201 if (!load_node)
202 return false;
203 list_addtail(&load_node->list, &node->list);
204 comp->num_fills++;
205
206 ppir_load_node *load = ppir_node_to_load(load_node);
207
208 load->index = -comp->prog->state.stack_size; /* index sizes are negative */
209 load->num_components = num_components;
210
211 ppir_dest *ld_dest = &load->dest;
212 ld_dest->type = ppir_target_pipeline;
213 ld_dest->pipeline = ppir_pipeline_reg_uniform;
214 ld_dest->write_mask = u_bit_consecutive(0, num_components);
215
216 /* If the uniform slot is empty, we can insert the load_temp
217 * there and use it directly. Exceptionally, if the node is in the
218 * varying or texld slot, this doesn't work. */
219 if (!node->instr->slots[PPIR_INSTR_SLOT_UNIFORM] &&
220 node->instr_pos != PPIR_INSTR_SLOT_VARYING &&
221 node->instr_pos != PPIR_INSTR_SLOT_TEXLD) {
222 ppir_node_target_assign(src, load_node);
223 *fill_node = load_node;
224 return ppir_instr_insert_node(node->instr, load_node);
225 }
226
227 /* Uniform slot was taken, so fall back to a new instruction with a mov */
228 if (!create_new_instr_before(block, node->instr, load_node))
229 return false;
230
231 /* Create move node */
232 ppir_node *move_node = ppir_node_create(block, ppir_op_mov, -1 , 0);
233 if (unlikely(!move_node))
234 return false;
235 list_addtail(&move_node->list, &node->list);
236
237 ppir_alu_node *move_alu = ppir_node_to_alu(move_node);
238
239 move_alu->num_src = 1;
240 move_alu->src->type = ppir_target_pipeline;
241 move_alu->src->pipeline = ppir_pipeline_reg_uniform;
242 for (int i = 0; i < 4; i++)
243 move_alu->src->swizzle[i] = i;
244
245 ppir_dest *alu_dest = &move_alu->dest;
246 alu_dest->type = ppir_target_ssa;
247 alu_dest->ssa.num_components = num_components;
248 alu_dest->ssa.spilled = true;
249 alu_dest->write_mask = u_bit_consecutive(0, num_components);
250
251 list_addtail(&alu_dest->ssa.list, &comp->reg_list);
252 comp->reg_num++;
253
254 if (!ppir_instr_insert_node(load_node->instr, move_node))
255 return false;
256
257 /* insert the new node as predecessor */
258 ppir_node_foreach_pred_safe(node, dep) {
259 ppir_node *pred = dep->pred;
260 ppir_node_remove_dep(dep);
261 ppir_node_add_dep(load_node, pred, ppir_dep_src);
262 }
263 ppir_node_add_dep(node, move_node, ppir_dep_src);
264 ppir_node_add_dep(move_node, load_node, ppir_dep_src);
265
266 *fill_node = move_node;
267
268 update_src:
269 /* switch node src to use the fill node dest */
270 ppir_node_target_assign(src, *fill_node);
271
272 return true;
273 }
274
ppir_update_spilled_dest_load(ppir_compiler * comp,ppir_block * block,ppir_node * node)275 static bool ppir_update_spilled_dest_load(ppir_compiler *comp, ppir_block *block,
276 ppir_node *node)
277 {
278 ppir_dest *dest = ppir_node_get_dest(node);
279 assert(dest != NULL);
280 assert(dest->type == ppir_target_register);
281 ppir_reg *reg = dest->reg;
282 int num_components = reg->num_components;
283
284 /* alloc new node to load value */
285 ppir_node *load_node = ppir_node_create(block, ppir_op_load_temp, -1, 0);
286 if (!load_node)
287 return NULL;
288 list_addtail(&load_node->list, &node->list);
289 comp->num_fills++;
290
291 ppir_load_node *load = ppir_node_to_load(load_node);
292
293 load->index = -comp->prog->state.stack_size; /* index sizes are negative */
294 load->num_components = num_components;
295
296 load->dest.type = ppir_target_pipeline;
297 load->dest.pipeline = ppir_pipeline_reg_uniform;
298 load->dest.write_mask = u_bit_consecutive(0, num_components);
299
300 /* New instruction is needed since we're updating a dest register
301 * and we can't write to the uniform pipeline reg */
302 if (!create_new_instr_before(block, node->instr, load_node))
303 return false;
304
305 /* Create move node */
306 ppir_node *move_node = ppir_node_create(block, ppir_op_mov, -1 , 0);
307 if (unlikely(!move_node))
308 return false;
309 list_addtail(&move_node->list, &node->list);
310
311 ppir_alu_node *move_alu = ppir_node_to_alu(move_node);
312
313 move_alu->num_src = 1;
314 move_alu->src->type = ppir_target_pipeline;
315 move_alu->src->pipeline = ppir_pipeline_reg_uniform;
316 for (int i = 0; i < 4; i++)
317 move_alu->src->swizzle[i] = i;
318
319 move_alu->dest.type = ppir_target_register;
320 move_alu->dest.reg = reg;
321 move_alu->dest.write_mask = u_bit_consecutive(0, num_components);
322
323 if (!ppir_instr_insert_node(load_node->instr, move_node))
324 return false;
325
326 ppir_node_foreach_pred_safe(node, dep) {
327 ppir_node *pred = dep->pred;
328 ppir_node_remove_dep(dep);
329 ppir_node_add_dep(load_node, pred, ppir_dep_src);
330 }
331 ppir_node_add_dep(node, move_node, ppir_dep_src);
332 ppir_node_add_dep(move_node, load_node, ppir_dep_src);
333
334 return true;
335 }
336
ppir_update_spilled_dest(ppir_compiler * comp,ppir_block * block,ppir_node * node)337 static bool ppir_update_spilled_dest(ppir_compiler *comp, ppir_block *block,
338 ppir_node *node)
339 {
340 ppir_dest *dest = ppir_node_get_dest(node);
341 assert(dest != NULL);
342 ppir_reg *reg = ppir_dest_get_reg(dest);
343
344 /* alloc new node to store value */
345 ppir_node *store_node = ppir_node_create(block, ppir_op_store_temp, -1, 0);
346 if (!store_node)
347 return false;
348 list_addtail(&store_node->list, &node->list);
349 comp->num_spills++;
350
351 ppir_store_node *store = ppir_node_to_store(store_node);
352
353 store->index = -comp->prog->state.stack_size; /* index sizes are negative */
354
355 ppir_node_target_assign(&store->src, node);
356 store->num_components = reg->num_components;
357
358 /* insert the new node as successor */
359 ppir_node_foreach_succ_safe(node, dep) {
360 ppir_node *succ = dep->succ;
361 ppir_node_remove_dep(dep);
362 ppir_node_add_dep(succ, store_node, ppir_dep_src);
363 }
364 ppir_node_add_dep(store_node, node, ppir_dep_src);
365
366 /* If the store temp slot is empty, we can insert the store_temp
367 * there and use it directly. Exceptionally, if the node is in the
368 * combine slot, this doesn't work. */
369 if (!node->instr->slots[PPIR_INSTR_SLOT_STORE_TEMP] &&
370 node->instr_pos != PPIR_INSTR_SLOT_ALU_COMBINE)
371 return ppir_instr_insert_node(node->instr, store_node);
372
373 /* Not possible to merge store, so fall back to a new instruction */
374 return create_new_instr_after(block, node->instr, store_node);
375 }
376
ppir_regalloc_spill_reg(ppir_compiler * comp,ppir_reg * chosen)377 static bool ppir_regalloc_spill_reg(ppir_compiler *comp, ppir_reg *chosen)
378 {
379 list_for_each_entry(ppir_block, block, &comp->block_list, list) {
380 list_for_each_entry(ppir_node, node, &block->node_list, list) {
381
382 ppir_dest *dest = ppir_node_get_dest(node);
383 if (dest && ppir_dest_get_reg(dest) == chosen) {
384 /* If dest is a register, it might be updating only some its
385 * components, so need to load the existing value first */
386 if (dest->type == ppir_target_register) {
387 if (!ppir_update_spilled_dest_load(comp, block, node))
388 return false;
389 }
390 if (!ppir_update_spilled_dest(comp, block, node))
391 return false;
392 }
393
394 ppir_node *fill_node = NULL;
395 /* nodes might have multiple references to the same value.
396 * avoid creating unnecessary loads for the same fill by
397 * saving the node resulting from the temporary load */
398 for (int i = 0; i < ppir_node_get_src_num(node); i++) {
399 ppir_src *src = ppir_node_get_src(node, i);
400 ppir_reg *reg = ppir_src_get_reg(src);
401 if (reg == chosen) {
402 if (!ppir_update_spilled_src(comp, block, node, src, &fill_node))
403 return false;
404 }
405 }
406 }
407 }
408
409 return true;
410 }
411
ppir_regalloc_choose_spill_node(ppir_compiler * comp,struct ra_graph * g)412 static ppir_reg *ppir_regalloc_choose_spill_node(ppir_compiler *comp,
413 struct ra_graph *g)
414 {
415 float spill_costs[comp->reg_num];
416 /* experimentally determined, it seems to be worth scaling cost of
417 * regs in instructions that have used uniform/store_temp slots,
418 * but not too much as to offset the num_components base cost. */
419 const float slot_scale = 1.1f;
420
421 memset(spill_costs, 0, sizeof(spill_costs[0]) * comp->reg_num);
422 list_for_each_entry(ppir_reg, reg, &comp->reg_list, list) {
423 if (reg->spilled) {
424 /* not considered for spilling */
425 spill_costs[reg->regalloc_index] = 0.0f;
426 continue;
427 }
428
429 /* It is beneficial to spill registers with higher component number,
430 * so increase the cost of spilling registers with few components */
431 float spill_cost = 4.0f / (float)reg->num_components;
432 spill_costs[reg->regalloc_index] = spill_cost;
433 }
434
435 list_for_each_entry(ppir_block, block, &comp->block_list, list) {
436 list_for_each_entry(ppir_instr, instr, &block->instr_list, list) {
437 if (instr->slots[PPIR_INSTR_SLOT_UNIFORM]) {
438 for (int i = 0; i < PPIR_INSTR_SLOT_NUM; i++) {
439 ppir_node *node = instr->slots[i];
440 if (!node)
441 continue;
442 for (int j = 0; j < ppir_node_get_src_num(node); j++) {
443 ppir_src *src = ppir_node_get_src(node, j);
444 if (!src)
445 continue;
446 ppir_reg *reg = ppir_src_get_reg(src);
447 if (!reg)
448 continue;
449
450 spill_costs[reg->regalloc_index] *= slot_scale;
451 }
452 }
453 }
454 if (instr->slots[PPIR_INSTR_SLOT_STORE_TEMP]) {
455 for (int i = 0; i < PPIR_INSTR_SLOT_NUM; i++) {
456 ppir_node *node = instr->slots[i];
457 if (!node)
458 continue;
459 ppir_dest *dest = ppir_node_get_dest(node);
460 if (!dest)
461 continue;
462 ppir_reg *reg = ppir_dest_get_reg(dest);
463 if (!reg)
464 continue;
465
466 spill_costs[reg->regalloc_index] *= slot_scale;
467 }
468 }
469 }
470 }
471
472 for (int i = 0; i < comp->reg_num; i++)
473 ra_set_node_spill_cost(g, i, spill_costs[i]);
474
475 int r = ra_get_best_spill_node(g);
476 if (r == -1)
477 return NULL;
478
479 ppir_reg *chosen = NULL;
480 int i = 0;
481 list_for_each_entry(ppir_reg, reg, &comp->reg_list, list) {
482 if (i++ == r) {
483 chosen = reg;
484 break;
485 }
486 }
487 assert(chosen);
488 chosen->spilled = true;
489 chosen->is_head = true; /* store_temp unable to do swizzle */
490
491 return chosen;
492 }
493
ppir_regalloc_reset_liveness_info(ppir_compiler * comp)494 static void ppir_regalloc_reset_liveness_info(ppir_compiler *comp)
495 {
496 int idx = 0;
497
498 list_for_each_entry(ppir_reg, reg, &comp->reg_list, list) {
499 reg->regalloc_index = idx++;
500 }
501
502 list_for_each_entry(ppir_block, block, &comp->block_list, list) {
503 list_for_each_entry(ppir_instr, instr, &block->instr_list, list) {
504
505 if (instr->live_mask)
506 ralloc_free(instr->live_mask);
507 instr->live_mask = rzalloc_array(comp, uint8_t,
508 reg_mask_size(comp->reg_num));
509
510 if (instr->live_set)
511 ralloc_free(instr->live_set);
512 instr->live_set = rzalloc_array(comp, BITSET_WORD, comp->reg_num);
513
514 if (instr->live_internal)
515 ralloc_free(instr->live_internal);
516 instr->live_internal = rzalloc_array(comp, BITSET_WORD, comp->reg_num);
517 }
518 }
519 }
520
ppir_all_interference(ppir_compiler * comp,struct ra_graph * g,BITSET_WORD * liveness)521 static void ppir_all_interference(ppir_compiler *comp, struct ra_graph *g,
522 BITSET_WORD *liveness)
523 {
524 int i, j;
525 BITSET_FOREACH_SET(i, liveness, comp->reg_num) {
526 BITSET_FOREACH_SET(j, liveness, comp->reg_num) {
527 ra_add_node_interference(g, i, j);
528 }
529 BITSET_CLEAR(liveness, i);
530 }
531 }
532
533 int lima_ppir_force_spilling = 0;
534
ppir_regalloc_prog_try(ppir_compiler * comp,bool * spilled)535 static bool ppir_regalloc_prog_try(ppir_compiler *comp, bool *spilled)
536 {
537 ppir_regalloc_reset_liveness_info(comp);
538
539 struct ra_graph *g = ra_alloc_interference_graph(
540 comp->ra, comp->reg_num);
541
542 int n = 0;
543 list_for_each_entry(ppir_reg, reg, &comp->reg_list, list) {
544 int c = ppir_ra_reg_class_vec1 + (reg->num_components - 1);
545 if (reg->is_head)
546 c += 4;
547 ra_set_node_class(g, n++, ra_get_class_from_index(comp->ra, c));
548 }
549
550 ppir_liveness_analysis(comp);
551
552 list_for_each_entry(ppir_block, block, &comp->block_list, list) {
553 list_for_each_entry(ppir_instr, instr, &block->instr_list, list) {
554 int i;
555 BITSET_FOREACH_SET(i, instr->live_internal, comp->reg_num) {
556 BITSET_SET(instr->live_set, i);
557 }
558 ppir_all_interference(comp, g, instr->live_set);
559 }
560 }
561
562 *spilled = false;
563 bool ok = ra_allocate(g);
564 if (!ok || (comp->force_spilling-- > 0)) {
565 ppir_reg *chosen = ppir_regalloc_choose_spill_node(comp, g);
566 if (chosen) {
567 /* stack_size will be used to assemble the frame reg in lima_draw.
568 * It is also be used in the spilling code, as negative indices
569 * starting from -1, to create stack addresses. */
570 comp->prog->state.stack_size++;
571 if (!ppir_regalloc_spill_reg(comp, chosen))
572 goto err_out;
573 /* Ask the outer loop to call back in. */
574 *spilled = true;
575
576 ppir_debug("spilled register %d/%d, num_components: %d\n",
577 chosen->regalloc_index, comp->reg_num,
578 chosen->num_components);
579 goto err_out;
580 }
581
582 ppir_error("regalloc fail\n");
583 goto err_out;
584 }
585
586 n = 0;
587 list_for_each_entry(ppir_reg, reg, &comp->reg_list, list) {
588 reg->index = ra_get_node_reg(g, n++);
589 if (reg->out_reg) {
590 /* We need actual reg number, we don't have swizzle for output regs */
591 assert(!(reg->index & 0x3) && "ppir: output regs don't have swizzle");
592 comp->out_type_to_reg[reg->out_type] = reg->index / 4;
593 }
594 }
595
596 ralloc_free(g);
597
598 if (lima_debug & LIMA_DEBUG_PP)
599 ppir_regalloc_print_result(comp);
600
601 return true;
602
603 err_out:
604 ralloc_free(g);
605 return false;
606 }
607
ppir_regalloc_prog(ppir_compiler * comp)608 bool ppir_regalloc_prog(ppir_compiler *comp)
609 {
610 bool spilled = false;
611 comp->prog->state.stack_size = 0;
612
613 /* Set from an environment variable to force spilling
614 * for debugging purposes, see lima_screen.c */
615 comp->force_spilling = lima_ppir_force_spilling;
616
617 ppir_regalloc_update_reglist_ssa(comp);
618
619 /* No registers? Probably shader consists of discard instruction */
620 if (list_is_empty(&comp->reg_list)) {
621 comp->prog->state.frag_color0_reg = 0;
622 comp->prog->state.frag_color1_reg = -1;
623 comp->prog->state.frag_depth_reg = -1;
624 return true;
625 }
626
627 /* this will most likely succeed in the first
628 * try, except for very complicated shaders */
629 while (!ppir_regalloc_prog_try(comp, &spilled))
630 if (!spilled)
631 return false;
632
633 comp->prog->state.frag_color0_reg =
634 comp->out_type_to_reg[ppir_output_color0];
635 comp->prog->state.frag_color1_reg =
636 comp->out_type_to_reg[ppir_output_color1];
637 comp->prog->state.frag_depth_reg =
638 comp->out_type_to_reg[ppir_output_depth];
639
640 return true;
641 }
642