b0afe1868eb72b5068d310a8795c90a653fab04e
2 * Copyright (c) 2013 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-a3xx.h"
32 /* low level intermediate representation of an adreno shader program */
36 struct ir3_shader
* fd_asm_parse(const char *src
);
38 struct ir3_shader_info
{
40 /* NOTE: max_reg, etc, does not include registers not touched
41 * by the shader (ie. vertex fetched via VFD_DECODE but not
44 int8_t max_reg
; /* highest GPR # used by shader */
51 IR3_REG_CONST
= 0x001,
52 IR3_REG_IMMED
= 0x002,
54 IR3_REG_RELATIV
= 0x008,
56 IR3_REG_NEGATE
= 0x020,
59 IR3_REG_POS_INF
= 0x100,
60 /* (ei) flag, end-input? Set on last bary, presumably to signal
61 * that the shader needs no more input:
67 * the component is in the low two bits of the reg #, so
68 * rN.x becomes: (N << 2) | x
78 /* used for cat5 instructions, but also for internal/IR level
79 * tracking of what registers are read/written by an instruction.
80 * wrmask may be a bad name since it is used to represent both
81 * src and dst that touch multiple adjacent registers.
86 struct ir3_instruction
{
87 struct ir3_shader
*shader
;
91 /* (sy) flag is set on first instruction, and after sample
92 * instructions (probably just on RAW hazard).
95 /* (ss) flag is set on first instruction, and first instruction
96 * to depend on the result of "long" instructions (RAW hazard):
98 * rcp, rsq, log2, exp2, sin, cos, sqrt
100 * It seems to synchronize until all in-flight instructions are
101 * completed, for example:
104 * add.f hr2.z, (neg)hr2.z, hc0.y
105 * mul.f hr2.w, (neg)hr2.y, (neg)hr2.y
108 * mad.f16 hr2.w, hr2.z, hr2.z, hr2.w
110 * mad.f16 hr2.w, (neg)hr0.w, (neg)hr0.w, hr2.w
111 * (ss)(rpt2)mul.f hr1.x, (r)hr1.x, hr1.w
112 * (rpt2)mul.f hr0.x, (neg)(r)hr0.x, hr2.x
114 * The last mul.f does not have (ss) set, presumably because the
115 * (ss) on the previous instruction does the job.
117 * The blob driver also seems to set it on WAR hazards, although
118 * not really clear if this is needed or just blob compiler being
119 * sloppy. So far I haven't found a case where removing the (ss)
120 * causes problems for WAR hazard, but I could just be getting
124 * (ss)(rpt2)mad.f32 r3.y, (r)c9.x, r1.x, (r)r3.z
127 IR3_INSTR_SS
= 0x002,
128 /* (jp) flag is set on jump targets:
130 IR3_INSTR_JP
= 0x004,
131 IR3_INSTR_UL
= 0x008,
132 IR3_INSTR_3D
= 0x010,
137 IR3_INSTR_S2EN
= 0x200,
141 struct ir3_register
*regs
[4];
149 type_t src_type
, dst_type
;
173 #define MAX_INSTRS 1024
176 unsigned instrs_count
;
177 struct ir3_instruction
*instrs
[MAX_INSTRS
];
178 uint32_t heap
[128 * MAX_INSTRS
];
182 struct ir3_shader
* ir3_shader_create(void);
183 void ir3_shader_destroy(struct ir3_shader
*shader
);
184 void * ir3_shader_assemble(struct ir3_shader
*shader
,
185 struct ir3_shader_info
*info
);
187 struct ir3_instruction
* ir3_instr_create(struct ir3_shader
*shader
,
188 int category
, opc_t opc
);
189 struct ir3_instruction
* ir3_instr_clone(struct ir3_instruction
*instr
);
191 struct ir3_register
* ir3_reg_create(struct ir3_instruction
*instr
,