2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include "r600_compiler.h"
29 struct r600_shader_operand
{
30 struct c_vector
*vector
;
37 struct r600_shader_vfetch
{
38 struct r600_shader_vfetch
*next
;
39 struct r600_shader_vfetch
*prev
;
41 struct r600_shader_operand src
[2];
42 struct r600_shader_operand dst
[4];
45 struct r600_shader_inst
{
49 struct r600_shader_operand src
[3];
50 struct r600_shader_operand dst
;
54 struct r600_shader_alu
{
55 struct r600_shader_alu
*next
;
56 struct r600_shader_alu
*prev
;
60 struct r600_shader_inst alu
[5];
64 struct r600_shader_node
{
65 struct r600_shader_node
*next
;
66 struct r600_shader_node
*prev
;
67 unsigned cf_id
; /**< cf index (in dw) in byte code */
68 unsigned cf_addr
; /**< instructions index (in dw) in byte code */
69 unsigned nslot
; /**< number of slot (2 dw) needed by this node */
71 struct c_node
*node
; /**< compiler node from which this node originate */
72 struct r600_shader_vfetch vfetch
; /**< list of vfetch instructions */
73 struct r600_shader_alu alu
; /**< list of alu instructions */
76 struct r600_shader_io
{
83 unsigned stack_size
; /**< stack size needed by this shader */
84 unsigned ngpr
; /**< number of GPR needed by this shader */
85 unsigned nconstant
; /**< number of constants used by this shader */
86 unsigned nresource
; /**< number of resources used by this shader */
90 unsigned ncf
; /**< total number of cf clauses */
91 unsigned nslot
; /**< total number of slots (2 dw) */
92 unsigned flat_shade
; /**< are we flat shading */
93 struct r600_shader_node nodes
; /**< list of node */
94 struct r600_shader_io input
[32];
95 struct r600_shader_io output
[32];
96 /* TODO replace GPR by some better register allocator */
97 struct c_vector
**gpr
;
98 unsigned ndw
; /**< bytes code size in dw */
99 u32
*bcode
; /**< bytes code */
100 enum pipe_format resource_format
[160]; /**< format of resource */
101 struct c_shader cshader
;
104 void r600_shader_cleanup(struct r600_shader
*rshader
);
105 int r600_shader_register(struct r600_shader
*rshader
);
106 int r600_shader_node(struct r600_shader
*shader
);
107 void r600_shader_node_place(struct r600_shader
*rshader
);
108 int r600_shader_find_gpr(struct r600_shader
*rshader
, struct c_vector
*v
, unsigned swizzle
,
109 struct r600_shader_operand
*operand
);
110 int r600_shader_vfetch_bytecode(struct r600_shader
*rshader
,
111 struct r600_shader_node
*rnode
,
112 struct r600_shader_vfetch
*vfetch
,
114 int r600_shader_update(struct r600_shader
*rshader
,
115 enum pipe_format
*resource_format
);
116 int r600_shader_legalize(struct r600_shader
*rshader
);
117 int r600_cshader_legalize(struct c_shader
*shader
);
119 int r700_shader_translate(struct r600_shader
*rshader
);
121 int c_shader_from_tgsi(struct c_shader
*shader
, unsigned type
,
122 const struct tgsi_token
*tokens
);
123 int r600_shader_register(struct r600_shader
*rshader
);
124 int r600_shader_translate_rec(struct r600_shader
*rshader
, struct c_node
*node
);
125 int r700_shader_translate(struct r600_shader
*rshader
);
126 int r600_shader_insert_fetch(struct c_shader
*shader
);
128 enum r600_instruction
{
141 INST_SETGT_DX10
= 12,
142 INST_SETGE_DX10
= 13,
143 INST_SETNE_DX10
= 14,
150 INST_MOVA_FLOOR
= 21,
154 INST_PRED_SETGT_UINT
= 25,
155 INST_PRED_SETGE_UINT
= 26,
157 INST_PRED_SETGT
= 28,
158 INST_PRED_SETGE
= 29,
159 INST_PRED_SETNE
= 30,
160 INST_PRED_SET_INV
= 31,
161 INST_PRED_SET_POP
= 32,
162 INST_PRED_SET_CLR
= 33,
163 INST_PRED_SET_RESTORE
= 34,
164 INST_PRED_SETE_PUSH
= 35,
165 INST_PRED_SETGT_PUSH
= 36,
166 INST_PRED_SETGE_PUSH
= 37,
167 INST_PRED_SETNE_PUSH
= 38,
186 INST_SETGT_UINT
= 57,
187 INST_SETGE_UINT
= 58,
188 INST_KILLGT_UINT
= 59,
189 INST_KILLGE_UINT
= 60,
190 INST_PRED_SETE_INT
= 61,
191 INST_PRED_SETGT_INT
= 62,
192 INST_PRED_SETGE_INT
= 63,
193 INST_PRED_SETNE_INT
= 64,
195 INST_KILLGT_INT
= 66,
196 INST_KILLGE_INT
= 67,
197 INST_KILLNE_INT
= 68,
198 INST_PRED_SETE_PUSH_INT
= 69,
199 INST_PRED_SETGT_PUSH_INT
= 70,
200 INST_PRED_SETGE_PUSH_INT
= 71,
201 INST_PRED_SETNE_PUSH_INT
= 72,
202 INST_PRED_SETLT_PUSH_INT
= 73,
203 INST_PRED_SETLE_PUSH_INT
= 74,
208 INST_MOVA_GPR_INT
= 79,
210 INST_LOG_CLAMPED
= 81,
212 INST_RECIP_CLAMPED
= 83,
214 INST_RECIP_IEEE
= 85,
215 INST_RECIPSQRT_CLAMPED
= 86,
216 INST_RECIPSQRT_FF
= 87,
217 INST_RECIPSQRT_IEEE
= 88,
219 INST_FLT_TO_INT
= 90,
220 INST_INT_TO_FLT
= 91,
221 INST_UINT_TO_FLT
= 92,
229 INST_MULLO_UINT
= 100,
230 INST_MULHI_UINT
= 101,
231 INST_RECIP_INT
= 102,
232 INST_RECIP_UINT
= 103,
233 INST_FLT_TO_UINT
= 104,
235 INST_MUL_LIT_M2
= 106,
236 INST_MUL_LIT_M4
= 107,
237 INST_MUL_LIT_D2
= 108,
239 INST_MULADD_M2
= 110,
240 INST_MULADD_M4
= 111,
241 INST_MULADD_D2
= 112,
242 INST_MULADD_IEEE
= 113,
243 INST_MULADD_IEEE_M2
= 114,
244 INST_MULADD_IEEE_M4
= 115,
245 INST_MULADD_IEEE_D2
= 116,
250 INST_CNDGT_INT
= 121,
251 INST_CNDGE_INT
= 122,
255 struct r600_instruction_info
{
256 enum r600_instruction instruction
;