2 * Copyright (c) 2012 Rob Clark <robdclark@gmail.com>
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:
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
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
30 #include "instr-a2xx.h"
32 /* low level intermediate representation of an adreno a2xx shader program */
38 struct ir2_shader_info
{
40 int8_t max_reg
; /* highest GPR # used by shader */
44 int16_t write_idx
, write_idx2
, read_idx
, reg
;
45 /* bitmask of variables on which this one depends
46 * XXX: use bitmask util?
48 uint32_t regmask
[REG_MASK
/32+1];
51 struct ir2_src_register
{
62 struct ir2_dst_register
{
76 struct ir2_instruction
{
77 struct ir2_shader
*shader
;
86 unsigned src_reg_count
;
87 struct ir2_dst_register dst_reg
;
88 struct ir2_src_register src_reg
[3];
92 instr_fetch_opc_t opc
;
94 /* texture fetch specific: */
97 /* vertex fetch specific: */
98 unsigned const_idx_sel
;
99 enum a2xx_sq_surfaceformat fmt
;
101 bool is_normalized
: 1;
105 /* ALU-Vector specific: */
107 instr_vector_opc_t opc
;
110 /* ALU-Scalar specific: */
112 instr_scalar_opc_t opc
;
119 unsigned instr_count
;
121 struct ir2_register reg
[REG_MASK
+1];
123 struct ir2_instruction
*instr
[0x200];
124 uint32_t heap
[100 * 4096];
127 enum ir2_pred pred
; /* pred inherited by newly created instrs */
130 struct ir2_shader
* ir2_shader_create(void);
131 void ir2_shader_destroy(struct ir2_shader
*shader
);
132 void * ir2_shader_assemble(struct ir2_shader
*shader
,
133 struct ir2_shader_info
*info
);
135 struct ir2_instruction
* ir2_instr_create(struct ir2_shader
*shader
,
138 struct ir2_dst_register
* ir2_dst_create(struct ir2_instruction
*instr
,
139 int num
, const char *swizzle
, int flags
);
140 struct ir2_src_register
* ir2_reg_create(struct ir2_instruction
*instr
,
141 int num
, const char *swizzle
, int flags
);
143 /* some helper fxns: */
145 static inline struct ir2_instruction
*
146 ir2_instr_create_alu_v(struct ir2_shader
*shader
, instr_vector_opc_t vop
)
148 struct ir2_instruction
*instr
= ir2_instr_create(shader
, IR2_ALU_VECTOR
);
151 instr
->alu_vector
.opc
= vop
;
155 static inline struct ir2_instruction
*
156 ir2_instr_create_alu_s(struct ir2_shader
*shader
, instr_scalar_opc_t sop
)
158 struct ir2_instruction
*instr
= ir2_instr_create(shader
, IR2_ALU_SCALAR
);
161 instr
->alu_scalar
.opc
= sop
;
165 static inline struct ir2_instruction
*
166 ir2_instr_create_vtx_fetch(struct ir2_shader
*shader
, int ci
, int cis
,
167 enum a2xx_sq_surfaceformat fmt
, bool is_signed
, int stride
)
169 struct ir2_instruction
*instr
= ir2_instr_create(shader
, IR2_FETCH
);
170 instr
->fetch
.opc
= VTX_FETCH
;
171 instr
->fetch
.const_idx
= ci
;
172 instr
->fetch
.const_idx_sel
= cis
;
173 instr
->fetch
.fmt
= fmt
;
174 instr
->fetch
.is_signed
= is_signed
;
175 instr
->fetch
.stride
= stride
;
178 static inline struct ir2_instruction
*
179 ir2_instr_create_tex_fetch(struct ir2_shader
*shader
, int ci
)
181 struct ir2_instruction
*instr
= ir2_instr_create(shader
, IR2_FETCH
);
182 instr
->fetch
.opc
= TEX_FETCH
;
183 instr
->fetch
.const_idx
= ci
;