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 */
36 struct ir2_shader_info
{
38 int8_t max_reg
; /* highest GPR # used by shader */
39 uint8_t max_input_reg
;
40 uint64_t regs_written
;
60 struct ir2_instruction
{
61 struct ir2_shader
*shader
;
69 struct ir2_register
*regs
[5];
73 instr_fetch_opc_t opc
;
75 /* texture fetch specific: */
77 /* vertex fetch specific: */
78 unsigned const_idx_sel
;
79 enum a2xx_sq_surfaceformat fmt
;
81 bool is_normalized
: 1;
87 instr_vector_opc_t vector_opc
;
88 instr_scalar_opc_t scalar_opc
;
89 bool vector_clamp
: 1;
90 bool scalar_clamp
: 1;
96 struct ir2_shader
*shader
;
97 instr_cf_opc_t cf_type
;
100 /* EXEC/EXEC_END specific: */
102 unsigned instrs_count
;
103 struct ir2_instruction
*instrs
[6];
104 uint32_t addr
, cnt
, sequence
;
106 /* ALLOC specific: */
108 instr_alloc_type_t type
; /* SQ_POSITION or SQ_PARAMETER_PIXEL */
116 struct ir2_cf
*cfs
[0x56];
117 uint32_t heap
[100 * 4096];
120 enum ir2_pred pred
; /* pred inherited by newly created instrs */
123 struct ir2_shader
* ir2_shader_create(void);
124 void ir2_shader_destroy(struct ir2_shader
*shader
);
125 void * ir2_shader_assemble(struct ir2_shader
*shader
,
126 struct ir2_shader_info
*info
);
128 struct ir2_cf
* ir2_cf_create(struct ir2_shader
*shader
, instr_cf_opc_t cf_type
);
130 struct ir2_instruction
* ir2_instr_create(struct ir2_cf
*cf
, int instr_type
);
132 struct ir2_register
* ir2_reg_create(struct ir2_instruction
*instr
,
133 int num
, const char *swizzle
, int flags
);
135 /* some helper fxns: */
137 static inline struct ir2_cf
*
138 ir2_cf_create_alloc(struct ir2_shader
*shader
, instr_alloc_type_t type
, int size
)
140 struct ir2_cf
*cf
= ir2_cf_create(shader
, ALLOC
);
143 cf
->alloc
.type
= type
;
144 cf
->alloc
.size
= size
;
147 static inline struct ir2_instruction
*
148 ir2_instr_create_alu(struct ir2_cf
*cf
, instr_vector_opc_t vop
, instr_scalar_opc_t sop
)
150 struct ir2_instruction
*instr
= ir2_instr_create(cf
, IR2_ALU
);
153 instr
->alu
.vector_opc
= vop
;
154 instr
->alu
.scalar_opc
= sop
;
157 static inline struct ir2_instruction
*
158 ir2_instr_create_vtx_fetch(struct ir2_cf
*cf
, int ci
, int cis
,
159 enum a2xx_sq_surfaceformat fmt
, bool is_signed
, int stride
)
161 struct ir2_instruction
*instr
= instr
= ir2_instr_create(cf
, IR2_FETCH
);
162 instr
->fetch
.opc
= VTX_FETCH
;
163 instr
->fetch
.const_idx
= ci
;
164 instr
->fetch
.const_idx_sel
= cis
;
165 instr
->fetch
.fmt
= fmt
;
166 instr
->fetch
.is_signed
= is_signed
;
167 instr
->fetch
.stride
= stride
;
170 static inline struct ir2_instruction
*
171 ir2_instr_create_tex_fetch(struct ir2_cf
*cf
, int ci
)
173 struct ir2_instruction
*instr
= instr
= ir2_instr_create(cf
, IR2_FETCH
);
174 instr
->fetch
.opc
= TEX_FETCH
;
175 instr
->fetch
.const_idx
= ci
;