1 /**************************************************************************
3 * Copyright 2009 VMware, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
30 #include "tgsi/tgsi_ureg.h"
32 typedef void (* ureg_func
)( struct ureg_program
*ureg
,
35 struct ureg_src
*sampler
,
36 struct ureg_dst
*temp
,
37 struct ureg_src
*constant
);
40 solid_fill( struct ureg_program
*ureg
,
43 struct ureg_src
*sampler
,
44 struct ureg_dst
*temp
,
45 struct ureg_src
*constant
)
47 ureg_MOV(ureg
, *out
, constant
[0]);
51 linear_grad( struct ureg_program
*ureg
,
54 struct ureg_src
*sampler
,
55 struct ureg_dst
*temp
,
56 struct ureg_src
*constant
)
60 ureg_writemask(temp
[0], TGSI_WRITEMASK_XY
),
63 ureg_writemask(temp
[0], TGSI_WRITEMASK_Z
),
64 ureg_scalar(constant
[1], TGSI_SWIZZLE_Y
));
65 ureg_DP3(ureg
, temp
[1], constant
[2], ureg_src(temp
[0]));
66 ureg_DP3(ureg
, temp
[2], constant
[3], ureg_src(temp
[0]));
67 ureg_DP3(ureg
, temp
[3], constant
[4], ureg_src(temp
[0]));
68 ureg_RCP(ureg
, temp
[3], ureg_src(temp
[3]));
69 ureg_MUL(ureg
, temp
[1], ureg_src(temp
[1]), ureg_src(temp
[3]));
70 ureg_MUL(ureg
, temp
[2], ureg_src(temp
[2]), ureg_src(temp
[3]));
71 ureg_MOV(ureg
, ureg_writemask(temp
[4], TGSI_WRITEMASK_X
), ureg_src(temp
[1]));
72 ureg_MOV(ureg
, ureg_writemask(temp
[4], TGSI_WRITEMASK_Y
), ureg_src(temp
[2]));
73 ureg_MUL(ureg
, temp
[0],
74 ureg_scalar(constant
[0], TGSI_SWIZZLE_Y
),
75 ureg_scalar(ureg_src(temp
[4]), TGSI_SWIZZLE_Y
));
76 ureg_MAD(ureg
, temp
[1],
77 ureg_scalar(constant
[0], TGSI_SWIZZLE_X
),
78 ureg_scalar(ureg_src(temp
[4]), TGSI_SWIZZLE_X
),
80 ureg_MUL(ureg
, temp
[2], ureg_src(temp
[1]),
81 ureg_scalar(constant
[0], TGSI_SWIZZLE_Z
));
82 ureg_TEX(ureg
, *out
, TGSI_TEXTURE_1D
, ureg_src(temp
[2]), sampler
[0]);
86 radial_grad( struct ureg_program
*ureg
,
89 struct ureg_src
*sampler
,
90 struct ureg_dst
*temp
,
91 struct ureg_src
*constant
)
94 ureg_MOV(ureg
, ureg_writemask(temp
[0], TGSI_WRITEMASK_XY
), in
[0]);
96 ureg_writemask(temp
[0], TGSI_WRITEMASK_Z
),
97 ureg_scalar(constant
[1], TGSI_SWIZZLE_Y
));
98 ureg_DP3(ureg
, temp
[1], constant
[2], ureg_src(temp
[0]));
99 ureg_DP3(ureg
, temp
[2], constant
[3], ureg_src(temp
[0]));
100 ureg_DP3(ureg
, temp
[3], constant
[4], ureg_src(temp
[0]));
101 ureg_RCP(ureg
, temp
[3], ureg_src(temp
[3]));
102 ureg_MUL(ureg
, temp
[1], ureg_src(temp
[1]), ureg_src(temp
[3]));
103 ureg_MUL(ureg
, temp
[2], ureg_src(temp
[2]), ureg_src(temp
[3]));
104 ureg_MOV(ureg
, ureg_writemask(temp
[5], TGSI_WRITEMASK_X
), ureg_src(temp
[1]));
105 ureg_MOV(ureg
, ureg_writemask(temp
[5], TGSI_WRITEMASK_Y
), ureg_src(temp
[2]));
106 ureg_MUL(ureg
, temp
[0], ureg_scalar(constant
[0], TGSI_SWIZZLE_Y
),
107 ureg_scalar(ureg_src(temp
[5]), TGSI_SWIZZLE_Y
));
108 ureg_MAD(ureg
, temp
[1],
109 ureg_scalar(constant
[0], TGSI_SWIZZLE_X
),
110 ureg_scalar(ureg_src(temp
[5]), TGSI_SWIZZLE_X
), ureg_src(temp
[0]));
111 ureg_ADD(ureg
, temp
[1], ureg_src(temp
[1]), ureg_src(temp
[1]));
112 ureg_MUL(ureg
, temp
[3],
113 ureg_scalar(ureg_src(temp
[5]), TGSI_SWIZZLE_Y
),
114 ureg_scalar(ureg_src(temp
[5]), TGSI_SWIZZLE_Y
));
115 ureg_MAD(ureg
, temp
[4],
116 ureg_scalar(ureg_src(temp
[5]), TGSI_SWIZZLE_X
),
117 ureg_scalar(ureg_src(temp
[5]), TGSI_SWIZZLE_X
),
119 ureg_MOV(ureg
, temp
[4], ureg_negate(ureg_src(temp
[4])));
120 ureg_MUL(ureg
, temp
[2],
121 ureg_scalar(constant
[0], TGSI_SWIZZLE_Z
),
123 ureg_MUL(ureg
, temp
[0],
124 ureg_scalar(constant
[1], TGSI_SWIZZLE_W
),
126 ureg_MUL(ureg
, temp
[3], ureg_src(temp
[1]), ureg_src(temp
[1]));
128 ureg_SUB(ureg
, temp
[2], ureg_src(temp
[3]), ureg_src(temp
[0]));
129 ureg_RSQ(ureg
, temp
[2], ureg_abs(ureg_src(temp
[2])));
130 ureg_RCP(ureg
, temp
[2], ureg_src(temp
[2]));
131 ureg_SUB(ureg
, temp
[1], ureg_src(temp
[2]), ureg_src(temp
[1]));
132 ureg_ADD(ureg
, temp
[0],
133 ureg_scalar(constant
[0], TGSI_SWIZZLE_Z
),
134 ureg_scalar(constant
[0], TGSI_SWIZZLE_Z
));
135 ureg_RCP(ureg
, temp
[0], ureg_src(temp
[0]));
136 ureg_MUL(ureg
, temp
[2], ureg_src(temp
[1]), ureg_src(temp
[0]));
137 ureg_TEX(ureg
, *out
, TGSI_TEXTURE_1D
, ureg_src(temp
[2]), sampler
[0]);
143 pattern( struct ureg_program
*ureg
,
144 struct ureg_dst
*out
,
146 struct ureg_src
*sampler
,
147 struct ureg_dst
*temp
,
148 struct ureg_src
*constant
)
151 ureg_writemask(temp
[0], TGSI_WRITEMASK_XY
),
154 ureg_writemask(temp
[0], TGSI_WRITEMASK_Z
),
155 ureg_scalar(constant
[1], TGSI_SWIZZLE_Y
));
156 ureg_DP3(ureg
, temp
[1], constant
[2], ureg_src(temp
[0]));
157 ureg_DP3(ureg
, temp
[2], constant
[3], ureg_src(temp
[0]));
158 ureg_DP3(ureg
, temp
[3], constant
[4], ureg_src(temp
[0]));
159 ureg_RCP(ureg
, temp
[3], ureg_src(temp
[3]));
160 ureg_MUL(ureg
, temp
[1], ureg_src(temp
[1]), ureg_src(temp
[3]));
161 ureg_MUL(ureg
, temp
[2], ureg_src(temp
[2]), ureg_src(temp
[3]));
162 ureg_MOV(ureg
, ureg_writemask(temp
[4], TGSI_WRITEMASK_X
), ureg_src(temp
[1]));
163 ureg_MOV(ureg
, ureg_writemask(temp
[4], TGSI_WRITEMASK_Y
), ureg_src(temp
[2]));
164 ureg_RCP(ureg
, temp
[0],
165 ureg_swizzle(constant
[1],
170 ureg_MOV(ureg
, temp
[1], ureg_src(temp
[4]));
172 ureg_writemask(temp
[1], TGSI_WRITEMASK_X
),
176 ureg_writemask(temp
[1], TGSI_WRITEMASK_Y
),
179 ureg_TEX(ureg
, *out
, TGSI_TEXTURE_2D
, ureg_src(temp
[1]), sampler
[0]);
183 mask( struct ureg_program
*ureg
,
184 struct ureg_dst
*out
,
186 struct ureg_src
*sampler
,
187 struct ureg_dst
*temp
,
188 struct ureg_src
*constant
)
190 ureg_TEX(ureg
, temp
[1], TGSI_TEXTURE_2D
, in
[0], sampler
[1]);
191 ureg_MUL(ureg
, ureg_writemask(temp
[0], TGSI_WRITEMASK_W
),
192 ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_W
),
193 ureg_scalar(ureg_src(temp
[1]), TGSI_SWIZZLE_W
));
194 ureg_MOV(ureg
, *out
, ureg_src(temp
[0]));
198 image_normal( struct ureg_program
*ureg
,
199 struct ureg_dst
*out
,
201 struct ureg_src
*sampler
,
202 struct ureg_dst
*temp
,
203 struct ureg_src
*constant
)
205 ureg_TEX(ureg
, *out
, TGSI_TEXTURE_2D
, in
[1], sampler
[3]);
210 image_multiply( struct ureg_program
*ureg
,
211 struct ureg_dst
*out
,
213 struct ureg_src
*sampler
,
214 struct ureg_dst
*temp
,
215 struct ureg_src
*constant
)
217 ureg_TEX(ureg
, temp
[1], TGSI_TEXTURE_2D
, in
[1], sampler
[3]);
218 ureg_MUL(ureg
, *out
, ureg_src(temp
[0]), ureg_src(temp
[1]));
223 image_stencil( struct ureg_program
*ureg
,
224 struct ureg_dst
*out
,
226 struct ureg_src
*sampler
,
227 struct ureg_dst
*temp
,
228 struct ureg_src
*constant
)
230 ureg_TEX(ureg
, temp
[1], TGSI_TEXTURE_2D
, in
[1], sampler
[3]);
231 ureg_MUL(ureg
, *out
, ureg_src(temp
[0]), ureg_src(temp
[1]));
234 #define EXTENDED_BLENDER_OVER_FUNC \
235 ureg_SUB(ureg, temp[3], \
236 ureg_scalar(constant[1], TGSI_SWIZZLE_Y), \
237 ureg_scalar(ureg_src(temp[1]), TGSI_SWIZZLE_W)); \
238 ureg_SUB(ureg, temp[3], \
239 ureg_scalar(constant[1], TGSI_SWIZZLE_Y), \
240 ureg_scalar(ureg_src(temp[0]), TGSI_SWIZZLE_W)); \
241 ureg_MUL(ureg, temp[3], ureg_src(temp[0]), ureg_src(temp[3])); \
242 ureg_MUL(ureg, temp[4], ureg_src(temp[1]), ureg_src(temp[4])); \
243 ureg_ADD(ureg, temp[3], ureg_src(temp[3]), ureg_src(temp[4]));
247 blend_multiply( struct ureg_program
*ureg
,
248 struct ureg_dst
*out
,
250 struct ureg_src
*sampler
,
251 struct ureg_dst
*temp
,
252 struct ureg_src
*constant
)
254 ureg_TEX(ureg
, temp
[1], TGSI_TEXTURE_2D
, in
[0], sampler
[2]);
255 EXTENDED_BLENDER_OVER_FUNC
256 ureg_MUL(ureg
, temp
[4], ureg_src(temp
[0]), ureg_src(temp
[1]));
257 ureg_ADD(ureg
, temp
[1], ureg_src(temp
[4]), ureg_src(temp
[3]));
259 ureg_MUL(ureg
, temp
[2], ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_W
),
260 ureg_scalar(ureg_src(temp
[1]), TGSI_SWIZZLE_W
));
261 ureg_ADD(ureg
, temp
[3], ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_W
),
262 ureg_scalar(ureg_src(temp
[1]), TGSI_SWIZZLE_W
));
263 ureg_SUB(ureg
, ureg_writemask(temp
[1], TGSI_WRITEMASK_W
),
264 ureg_src(temp
[3]), ureg_src(temp
[2]));
266 ureg_MOV(ureg
, *out
, ureg_src(temp
[1]));
270 blend_screen( struct ureg_program
*ureg
,
271 struct ureg_dst
*out
,
273 struct ureg_src
*sampler
,
274 struct ureg_dst
*temp
,
275 struct ureg_src
*constant
)
277 ureg_TEX(ureg
, temp
[1], TGSI_TEXTURE_2D
, in
[0], sampler
[2]);
278 ureg_ADD(ureg
, temp
[3], ureg_src(temp
[0]), ureg_src(temp
[1]));
279 ureg_MUL(ureg
, temp
[2], ureg_src(temp
[0]), ureg_src(temp
[1]));
280 ureg_SUB(ureg
, *out
, ureg_src(temp
[3]), ureg_src(temp
[2]));
284 blend_darken( struct ureg_program
*ureg
,
285 struct ureg_dst
*out
,
287 struct ureg_src
*sampler
,
288 struct ureg_dst
*temp
,
289 struct ureg_src
*constant
)
291 ureg_TEX(ureg
, temp
[1], TGSI_TEXTURE_2D
, in
[0], sampler
[2]);
292 EXTENDED_BLENDER_OVER_FUNC
293 ureg_MUL(ureg
, temp
[4], ureg_src(temp
[0]),
294 ureg_scalar(ureg_src(temp
[1]), TGSI_SWIZZLE_W
));
295 ureg_MUL(ureg
, temp
[5], ureg_src(temp
[1]),
296 ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_W
));
297 ureg_MIN(ureg
, temp
[4], ureg_src(temp
[4]), ureg_src(temp
[5]));
298 ureg_ADD(ureg
, temp
[1], ureg_src(temp
[3]), ureg_src(temp
[4]));
300 ureg_MUL(ureg
, temp
[2], ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_W
),
301 ureg_scalar(ureg_src(temp
[1]), TGSI_SWIZZLE_W
));
302 ureg_ADD(ureg
, temp
[3], ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_W
),
303 ureg_scalar(ureg_src(temp
[1]), TGSI_SWIZZLE_W
));
304 ureg_SUB(ureg
, ureg_writemask(temp
[1], TGSI_WRITEMASK_W
),
305 ureg_src(temp
[3]), ureg_src(temp
[2]));
307 ureg_MOV(ureg
, *out
, ureg_src(temp
[1]));
311 blend_lighten( struct ureg_program
*ureg
,
312 struct ureg_dst
*out
,
314 struct ureg_src
*sampler
,
315 struct ureg_dst
*temp
,
316 struct ureg_src
*constant
)
318 ureg_TEX(ureg
, temp
[1], TGSI_TEXTURE_2D
, in
[0], sampler
[2]);
319 EXTENDED_BLENDER_OVER_FUNC
320 ureg_MUL(ureg
, temp
[4], ureg_src(temp
[0]),
321 ureg_scalar(ureg_src(temp
[1]), TGSI_SWIZZLE_W
));
322 ureg_MUL(ureg
, temp
[5], ureg_src(temp
[1]),
323 ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_W
));
324 ureg_MAX(ureg
, temp
[4], ureg_src(temp
[4]), ureg_src(temp
[5]));
325 ureg_ADD(ureg
, temp
[1], ureg_src(temp
[3]), ureg_src(temp
[4]));
327 ureg_MUL(ureg
, temp
[2], ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_W
),
328 ureg_scalar(ureg_src(temp
[1]), TGSI_SWIZZLE_W
));
329 ureg_ADD(ureg
, temp
[3], ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_W
),
330 ureg_scalar(ureg_src(temp
[1]), TGSI_SWIZZLE_W
));
331 ureg_SUB(ureg
, ureg_writemask(temp
[1], TGSI_WRITEMASK_W
),
332 ureg_src(temp
[3]), ureg_src(temp
[2]));
334 ureg_MOV(ureg
, *out
, ureg_src(temp
[1]));
338 premultiply( struct ureg_program
*ureg
,
339 struct ureg_dst
*out
,
341 struct ureg_src
*sampler
,
342 struct ureg_dst
*temp
,
343 struct ureg_src
*constant
)
346 ureg_writemask(temp
[0], TGSI_WRITEMASK_XYZ
),
348 ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_W
));
352 unpremultiply( struct ureg_program
*ureg
,
353 struct ureg_dst
*out
,
355 struct ureg_src
*sampler
,
356 struct ureg_dst
*temp
,
357 struct ureg_src
*constant
)
359 ureg_TEX(ureg
, temp
[0], TGSI_TEXTURE_2D
, in
[0], sampler
[1]);
364 color_bw( struct ureg_program
*ureg
,
365 struct ureg_dst
*out
,
367 struct ureg_src
*sampler
,
368 struct ureg_dst
*temp
,
369 struct ureg_src
*constant
)
371 ureg_ADD(ureg
, temp
[1],
372 ureg_scalar(constant
[1], TGSI_SWIZZLE_Y
),
373 ureg_scalar(constant
[1], TGSI_SWIZZLE_Y
));
374 ureg_RCP(ureg
, temp
[2], ureg_src(temp
[1]));
375 ureg_ADD(ureg
, temp
[1],
376 ureg_scalar(constant
[1], TGSI_SWIZZLE_Y
),
378 ureg_ADD(ureg
, ureg_writemask(temp
[2], TGSI_WRITEMASK_X
),
379 ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_X
),
380 ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_Y
));
381 ureg_ADD(ureg
, ureg_writemask(temp
[2], TGSI_WRITEMASK_X
),
382 ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_Z
),
383 ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_X
));
385 ureg_writemask(temp
[0], TGSI_WRITEMASK_XYZ
),
386 ureg_scalar(ureg_src(temp
[2]), TGSI_SWIZZLE_X
),
389 ureg_writemask(temp
[0], TGSI_WRITEMASK_W
),
390 ureg_scalar(ureg_src(temp
[0]), TGSI_SWIZZLE_W
),
391 ureg_scalar(ureg_src(temp
[2]), TGSI_SWIZZLE_Y
));
392 ureg_MOV(ureg
, *out
, ureg_src(temp
[0]));
396 struct shader_asm_info
{
400 VGboolean needs_position
;
413 static const struct shader_asm_info shaders_asm
[] = {
415 {VEGA_SOLID_FILL_SHADER
, solid_fill
,
416 VG_FALSE
, 0, 1, 0, 0, 0, 0},
417 {VEGA_LINEAR_GRADIENT_SHADER
, linear_grad
,
418 VG_TRUE
, 0, 5, 0, 1, 0, 5},
419 {VEGA_RADIAL_GRADIENT_SHADER
, radial_grad
,
420 VG_TRUE
, 0, 5, 0, 1, 0, 6},
421 {VEGA_PATTERN_SHADER
, pattern
,
422 VG_TRUE
, 1, 4, 0, 1, 0, 5},
424 /* image draw modes */
425 {VEGA_IMAGE_NORMAL_SHADER
, image_normal
,
426 VG_TRUE
, 0, 0, 3, 1, 0, 0},
427 {VEGA_IMAGE_MULTIPLY_SHADER
, image_multiply
,
428 VG_TRUE
, 0, 0, 3, 1, 0, 2},
429 {VEGA_IMAGE_STENCIL_SHADER
, image_stencil
,
430 VG_TRUE
, 0, 0, 3, 1, 0, 2},
432 {VEGA_MASK_SHADER
, mask
,
433 VG_TRUE
, 0, 0, 1, 1, 0, 2},
435 /* extra blend modes */
436 {VEGA_BLEND_MULTIPLY_SHADER
, blend_multiply
,
437 VG_TRUE
, 1, 1, 2, 1, 0, 5},
438 {VEGA_BLEND_SCREEN_SHADER
, blend_screen
,
439 VG_TRUE
, 0, 0, 2, 1, 0, 4},
440 {VEGA_BLEND_DARKEN_SHADER
, blend_darken
,
441 VG_TRUE
, 1, 1, 2, 1, 0, 6},
442 {VEGA_BLEND_LIGHTEN_SHADER
, blend_lighten
,
443 VG_TRUE
, 1, 1, 2, 1, 0, 6},
446 {VEGA_PREMULTIPLY_SHADER
, premultiply
,
447 VG_FALSE
, 0, 0, 0, 0, 0, 1},
448 {VEGA_UNPREMULTIPLY_SHADER
, unpremultiply
,
449 VG_FALSE
, 0, 0, 0, 0, 0, 1},
451 /* color transform to black and white */
452 {VEGA_BW_SHADER
, color_bw
,
453 VG_FALSE
, 1, 1, 0, 0, 0, 3},