xref: /aosp_15_r20/external/mesa3d/src/imagination/vulkan/usc/pvr_uscgen.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2023 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 "pvr_job_transfer.h"
25 #include "pvr_uscgen.h"
26 #include "rogue/rogue.h"
27 #include "rogue/rogue_builder.h"
28 #include "util/u_dynarray.h"
29 
30 #include <stdbool.h>
31 
32 /* Expects emit_count ROGUE_NUM_PBESTATE_STATE_WORDS entries */
pvr_uscgen_eot(const char * name,uint32_t emit_count,const uint32_t * emit_state,unsigned * temps_used,struct util_dynarray * binary)33 void pvr_uscgen_eot(const char *name,
34                     uint32_t emit_count,
35                     const uint32_t *emit_state,
36                     unsigned *temps_used,
37                     struct util_dynarray *binary)
38 {
39    rogue_builder b;
40    rogue_shader *shader = rogue_shader_create(NULL, MESA_SHADER_NONE);
41    rogue_reg *state_word_0 = rogue_temp_reg(shader, 0);
42    rogue_reg *state_word_1 = rogue_temp_reg(shader, 1);
43    rogue_backend_instr *emitpix = NULL;
44 
45    rogue_set_shader_name(shader, name);
46    rogue_builder_init(&b, shader);
47    rogue_push_block(&b);
48 
49    for (unsigned u = 0; u < emit_count; u++) {
50       if (u > 0)
51          rogue_WOP(&b);
52 
53       rogue_MOV(&b, rogue_ref_reg(state_word_0), rogue_ref_imm(emit_state[0]));
54       rogue_MOV(&b, rogue_ref_reg(state_word_1), rogue_ref_imm(emit_state[1]));
55 
56       emitpix = rogue_EMITPIX(&b,
57                               rogue_ref_reg(state_word_0),
58                               rogue_ref_reg(state_word_1));
59 
60       emit_state += 2;
61    }
62 
63    assert(emitpix);
64 
65    rogue_set_backend_op_mod(emitpix, ROGUE_BACKEND_OP_MOD_FREEP);
66    emitpix->instr.end = true;
67 
68    rogue_shader_passes(shader);
69    rogue_encode_shader(NULL, shader, binary);
70 
71    *temps_used = rogue_count_used_regs(shader, ROGUE_REG_CLASS_TEMP);
72 
73    ralloc_free(shader);
74 }
75 
pvr_uscgen_nop(struct util_dynarray * binary)76 void pvr_uscgen_nop(struct util_dynarray *binary)
77 {
78    rogue_builder b;
79    rogue_shader *shader = rogue_shader_create(NULL, MESA_SHADER_NONE);
80    rogue_set_shader_name(shader, "NOP");
81    rogue_builder_init(&b, shader);
82    rogue_push_block(&b);
83 
84    rogue_END(&b);
85 
86    rogue_shader_passes(shader);
87    rogue_encode_shader(NULL, shader, binary);
88 
89    ralloc_free(shader);
90 }
91