• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ROGUE_INSTR_H
25 #define ROGUE_INSTR_H
26 
27 #include <stdbool.h>
28 #include <stddef.h>
29 #include <stdint.h>
30 
31 #include "rogue_operand.h"
32 #include "util/list.h"
33 
34 /**
35  * \brief Instruction opcodes.
36  */
37 enum rogue_opcode {
38    ROGUE_OP_NOP = 0, /** No-operation. */
39    ROGUE_OP_END_FRAG, /** Fragment shader end. */
40    ROGUE_OP_END_VERT, /** Vertex shader end. */
41    ROGUE_OP_WDF, /** Write data fence. */
42 
43    ROGUE_OP_PIX_ITER_W, /** Pixel iteration with coefficients. */
44 
45    ROGUE_OP_MAX, /** Returns the largest out of two floats. */
46    ROGUE_OP_MIN, /** Returns the smallest out of two floats. */
47 
48    ROGUE_OP_PACK_U8888, /** Scales the four input floats:
49                          * [0.0f, 0.1f] -> [0, 255] and packs them
50                          * into a 32-bit unsigned integer.
51                          */
52 
53    ROGUE_OP_MOV, /** Register move instruction. */
54    ROGUE_OP_MOV_IMM, /** Move immediate instruction. */
55 
56    ROGUE_OP_FMA, /** Fused-multiply-add (float). */
57    ROGUE_OP_MUL, /** Multiply (float). */
58 
59    ROGUE_OP_VTXOUT, /** Writes the input register
60                      * to the given vertex output index.
61                      */
62 
63    ROGUE_OP_COUNT,
64 };
65 
66 /**
67  * \brief Instruction flags.
68  */
69 enum rogue_instr_flag {
70    ROGUE_INSTR_FLAG_SAT = 0, /** Saturate values to 0.0 ... 1.0. */
71    ROGUE_INSTR_FLAG_LP, /** Low-precision modifier. */
72    ROGUE_INSTR_FLAG_OLCHK, /** Overlap check (pixel write). */
73 
74    ROGUE_INSTR_FLAG_COUNT,
75 };
76 
77 /**
78  * \brief Instruction description.
79  */
80 struct rogue_instr {
81    enum rogue_opcode opcode;
82 
83    size_t num_operands;
84    struct rogue_operand *operands;
85 
86    uint64_t flags; /** A mask of #rogue_instr_flag values. */
87 
88    struct list_head node; /** Linked list node. */
89 };
90 
91 struct rogue_instr *rogue_instr_create(void *mem_ctx, enum rogue_opcode opcode);
92 
93 bool rogue_instr_set_flag(struct rogue_instr *instr,
94                           enum rogue_instr_flag flag);
95 
96 bool rogue_instr_set_operand_imm(struct rogue_instr *instr,
97                                  size_t index,
98                                  uint64_t value);
99 bool rogue_instr_set_operand_drc(struct rogue_instr *instr,
100                                  size_t index,
101                                  size_t number);
102 bool rogue_instr_set_operand_reg(struct rogue_instr *instr,
103                                  size_t index,
104                                  enum rogue_operand_type type,
105                                  size_t number);
106 bool rogue_instr_set_operand_vreg(struct rogue_instr *instr,
107                                   size_t index,
108                                   size_t number);
109 bool rogue_instr_set_operand_vreg_vec(struct rogue_instr *instr,
110                                       size_t index,
111                                       size_t component,
112                                       size_t number);
113 #endif /* ROGUE_INSTR_H */
114