~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/compiler/glsl/ir_builder.h

  • Committer: mmach
  • Date: 2022-09-22 19:58:36 UTC
  • Revision ID: netbit73@gmail.com-20220922195836-9nl9joew85y8d25o
2022-07-04 12:44:28

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2012 Intel Corporation
 
3
 *
 
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:
 
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
 
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
 
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
21
 * IN THE SOFTWARE.
 
22
 */
 
23
 
 
24
#ifndef IR_BUILDER_H
 
25
#define IR_BUILDER_H
 
26
 
 
27
#include "ir.h"
 
28
 
 
29
namespace ir_builder {
 
30
 
 
31
#ifndef WRITEMASK_X
 
32
enum writemask {
 
33
   WRITEMASK_X = 0x1,
 
34
   WRITEMASK_Y = 0x2,
 
35
   WRITEMASK_Z = 0x4,
 
36
   WRITEMASK_W = 0x8,
 
37
};
 
38
#endif
 
39
 
 
40
/**
 
41
 * This little class exists to let the helper expression generators
 
42
 * take either an ir_rvalue * or an ir_variable * to be automatically
 
43
 * dereferenced, while still providing compile-time type checking.
 
44
 *
 
45
 * You don't have to explicitly call the constructor -- C++ will see
 
46
 * that you passed an ir_variable, and silently call the
 
47
 * operand(ir_variable *var) constructor behind your back.
 
48
 */
 
49
class operand {
 
50
public:
 
51
   operand(ir_rvalue *val)
 
52
      : val(val)
 
53
   {
 
54
   }
 
55
 
 
56
   operand(ir_variable *var)
 
57
   {
 
58
      void *mem_ctx = ralloc_parent(var);
 
59
      val = new(mem_ctx) ir_dereference_variable(var);
 
60
   }
 
61
 
 
62
   ir_rvalue *val;
 
63
};
 
64
 
 
65
/** Automatic generator for ir_dereference_variable on assignment LHS.
 
66
 *
 
67
 * \sa operand
 
68
 */
 
69
class deref {
 
70
public:
 
71
   deref(ir_dereference *val)
 
72
      : val(val)
 
73
   {
 
74
   }
 
75
 
 
76
   deref(ir_variable *var)
 
77
   {
 
78
      void *mem_ctx = ralloc_parent(var);
 
79
      val = new(mem_ctx) ir_dereference_variable(var);
 
80
   }
 
81
 
 
82
 
 
83
   ir_dereference *val;
 
84
};
 
85
 
 
86
class ir_factory {
 
87
public:
 
88
   ir_factory(exec_list *instructions = NULL, void *mem_ctx = NULL)
 
89
      : instructions(instructions),
 
90
        mem_ctx(mem_ctx)
 
91
   {
 
92
      return;
 
93
   }
 
94
 
 
95
   void emit(ir_instruction *ir);
 
96
   ir_variable *make_temp(const glsl_type *type, const char *name);
 
97
 
 
98
   ir_constant*
 
99
   constant(float f)
 
100
   {
 
101
      return new(mem_ctx) ir_constant(f);
 
102
   }
 
103
 
 
104
   ir_constant*
 
105
   constant(int i)
 
106
   {
 
107
      return new(mem_ctx) ir_constant(i);
 
108
   }
 
109
 
 
110
   ir_constant*
 
111
   constant(unsigned u)
 
112
   {
 
113
      return new(mem_ctx) ir_constant(u);
 
114
   }
 
115
 
 
116
   ir_constant*
 
117
   constant(bool b)
 
118
   {
 
119
      return new(mem_ctx) ir_constant(b);
 
120
   }
 
121
 
 
122
   exec_list *instructions;
 
123
   void *mem_ctx;
 
124
};
 
125
 
 
126
ir_assignment *assign(deref lhs, operand rhs);
 
127
ir_assignment *assign(deref lhs, operand rhs, int writemask);
 
128
 
 
129
ir_return *ret(operand retval);
 
130
 
 
131
ir_expression *expr(ir_expression_operation op, operand a);
 
132
ir_expression *expr(ir_expression_operation op, operand a, operand b);
 
133
ir_expression *expr(ir_expression_operation op, operand a, operand b, operand c);
 
134
ir_expression *add(operand a, operand b);
 
135
ir_expression *sub(operand a, operand b);
 
136
ir_expression *mul(operand a, operand b);
 
137
ir_expression *imul_high(operand a, operand b);
 
138
ir_expression *div(operand a, operand b);
 
139
ir_expression *carry(operand a, operand b);
 
140
ir_expression *borrow(operand a, operand b);
 
141
ir_expression *trunc(operand a);
 
142
ir_expression *round_even(operand a);
 
143
ir_expression *fract(operand a);
 
144
ir_expression *dot(operand a, operand b);
 
145
ir_expression *clamp(operand a, operand b, operand c);
 
146
ir_expression *saturate(operand a);
 
147
ir_expression *abs(operand a);
 
148
ir_expression *neg(operand a);
 
149
ir_expression *sin(operand a);
 
150
ir_expression *cos(operand a);
 
151
ir_expression *exp(operand a);
 
152
ir_expression *rcp(operand a);
 
153
ir_expression *rsq(operand a);
 
154
ir_expression *sqrt(operand a);
 
155
ir_expression *log(operand a);
 
156
ir_expression *sign(operand a);
 
157
 
 
158
ir_expression *subr_to_int(operand a);
 
159
ir_expression *equal(operand a, operand b);
 
160
ir_expression *nequal(operand a, operand b);
 
161
ir_expression *less(operand a, operand b);
 
162
ir_expression *greater(operand a, operand b);
 
163
ir_expression *lequal(operand a, operand b);
 
164
ir_expression *gequal(operand a, operand b);
 
165
 
 
166
ir_expression *logic_not(operand a);
 
167
ir_expression *logic_and(operand a, operand b);
 
168
ir_expression *logic_or(operand a, operand b);
 
169
 
 
170
ir_expression *bit_not(operand a);
 
171
ir_expression *bit_or(operand a, operand b);
 
172
ir_expression *bit_and(operand a, operand b);
 
173
ir_expression *bit_xor(operand a, operand b);
 
174
ir_expression *lshift(operand a, operand b);
 
175
ir_expression *rshift(operand a, operand b);
 
176
 
 
177
ir_expression *f2i(operand a);
 
178
ir_expression *bitcast_f2i(operand a);
 
179
ir_expression *i2f(operand a);
 
180
ir_expression *bitcast_i2f(operand a);
 
181
ir_expression *f2u(operand a);
 
182
ir_expression *bitcast_f2u(operand a);
 
183
ir_expression *u2f(operand a);
 
184
ir_expression *bitcast_u2f(operand a);
 
185
ir_expression *i2u(operand a);
 
186
ir_expression *u2i(operand a);
 
187
ir_expression *b2i(operand a);
 
188
ir_expression *i2b(operand a);
 
189
ir_expression *f2b(operand a);
 
190
ir_expression *b2f(operand a);
 
191
 
 
192
ir_expression *f2d(operand a);
 
193
ir_expression *i2d(operand a);
 
194
ir_expression *u2d(operand a);
 
195
 
 
196
ir_expression *bitcast_d2i64(operand a);
 
197
ir_expression *bitcast_d2u64(operand a);
 
198
 
 
199
ir_expression *bitcast_i642d(operand a);
 
200
ir_expression *bitcast_u642d(operand a);
 
201
 
 
202
ir_expression *min2(operand a, operand b);
 
203
ir_expression *max2(operand a, operand b);
 
204
 
 
205
ir_expression *interpolate_at_centroid(operand a);
 
206
ir_expression *interpolate_at_offset(operand a, operand b);
 
207
ir_expression *interpolate_at_sample(operand a, operand b);
 
208
 
 
209
ir_expression *fma(operand a, operand b, operand c);
 
210
ir_expression *lrp(operand x, operand y, operand a);
 
211
ir_expression *csel(operand a, operand b, operand c);
 
212
ir_expression *bitfield_extract(operand a, operand b, operand c);
 
213
ir_expression *bitfield_insert(operand a, operand b, operand c, operand d);
 
214
 
 
215
ir_swizzle *swizzle(operand a, int swizzle, int components);
 
216
/**
 
217
 * Swizzle away later components, but preserve the ordering.
 
218
 */
 
219
ir_swizzle *swizzle_for_size(operand a, unsigned components);
 
220
 
 
221
ir_swizzle *swizzle_xxxx(operand a);
 
222
ir_swizzle *swizzle_yyyy(operand a);
 
223
ir_swizzle *swizzle_zzzz(operand a);
 
224
ir_swizzle *swizzle_wwww(operand a);
 
225
ir_swizzle *swizzle_x(operand a);
 
226
ir_swizzle *swizzle_y(operand a);
 
227
ir_swizzle *swizzle_z(operand a);
 
228
ir_swizzle *swizzle_w(operand a);
 
229
ir_swizzle *swizzle_xy(operand a);
 
230
ir_swizzle *swizzle_xyz(operand a);
 
231
ir_swizzle *swizzle_xyzw(operand a);
 
232
 
 
233
ir_if *if_tree(operand condition,
 
234
               ir_instruction *then_branch);
 
235
ir_if *if_tree(operand condition,
 
236
               ir_instruction *then_branch,
 
237
               ir_instruction *else_branch);
 
238
 
 
239
} /* namespace ir_builder */
 
240
 
 
241
#endif