| 1 |
/* |
| 2 |
* Copyright © 2024 Imagination Technologies Ltd. |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
*/ |
| 6 |
|
| 7 |
/** |
| 8 |
* \file pco_end.c |
| 9 |
* |
| 10 |
* \brief PCO shader ending pass. |
| 11 |
*/ |
| 12 |
|
| 13 |
#include "pco.h" |
| 14 |
#include "pco_builder.h" |
| 15 |
#include "pco_internal.h" |
| 16 |
#include "util/macros.h" |
| 17 |
|
| 18 |
#include <stdbool.h> |
| 19 |
|
| 20 |
/** |
| 21 |
* \brief Processes end of shader instruction(s). |
| 22 |
* |
| 23 |
* \param[in,out] shader PCO shader. |
| 24 |
* \return True if the pass made progress. |
| 25 |
*/ |
| 26 |
bool pco_end(pco_shader *shader) |
| 27 |
{ |
| 28 |
/* TODO: Support for multiple end points. */ |
| 29 |
pco_func *entry = pco_entrypoint(shader); |
| 30 |
pco_block *last_block = pco_func_last_block(entry); |
| 31 |
pco_instr *last_instr = pco_last_instr(last_block); |
| 32 |
|
| 33 |
pco_builder b = |
| 34 |
pco_builder_create(entry, pco_cursor_after_block(last_block)); |
| 35 |
|
| 36 |
if (shader->stage == MESA_SHADER_VERTEX) { |
| 37 |
if (last_instr && last_instr->op == PCO_OP_UVSW_WRITE && |
| 38 |
pco_instr_has_default_exec(last_instr) && |
| 39 |
pco_instr_get_rpt(last_instr) == 1) { |
| 40 |
pco_instr *new_last_instr = |
| 41 |
pco_uvsw_write_emit_endtask(&b, |
| 42 |
last_instr->src[0], |
| 43 |
last_instr->src[1]); |
| 44 |
pco_instr_delete(last_instr); |
| 45 |
last_instr = new_last_instr; |
| 46 |
} else { |
| 47 |
last_instr = pco_uvsw_emit_endtask(&b); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
if (last_instr && pco_instr_has_end(last_instr)) { |
| 52 |
pco_instr_set_end(last_instr, true); |
| 53 |
return true; |
| 54 |
} |
| 55 |
|
| 56 |
pco_nop(&b, .end = true); |
| 57 |
|
| 58 |
return true; |
| 59 |
} |