1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 * Unit tests for blend LLVM IR generation
33 * @author Jose Fonseca <jfonseca@vmware.com>
35 * Blend computation code derived from code written by
36 * @author Brian Paul <brian@vmware.com>
40 #include "gallivm/lp_bld_init.h"
41 #include "gallivm/lp_bld_type.h"
42 #include "gallivm/lp_bld_debug.h"
43 #include "lp_bld_blend.h"
54 typedef void (*blend_test_ptr_t
)(const void *src
, const void *dst
, const void *con
, void *res
);
57 static blend_test_ptr_t
58 voidptr_to_blend_test_ptr_t(void *p
)
71 write_tsv_header(FILE *fp
)
75 "cycles_per_channel\t"
86 "alpha_dst_factor\n");
93 write_tsv_row(FILE *fp
,
94 const struct pipe_blend_state
*blend
,
95 enum vector_mode mode
,
100 fprintf(fp
, "%s\t", success
? "pass" : "fail");
103 fprintf(fp
, "%.1f\t", cycles
/ type
.length
);
104 fprintf(fp
, "aos\t");
108 fprintf(fp
, "%.1f\t", cycles
/ (4 * type
.length
));
109 fprintf(fp
, "soa\t");
112 fprintf(fp
, "%s%u%sx%u\t",
113 type
.floating
? "f" : (type
.fixed
? "h" : (type
.sign
? "s" : "u")),
115 type
.norm
? "n" : "",
120 blend
->rt
[0].rgb_func
!= blend
->rt
[0].alpha_func
? "true" : "false",
121 blend
->rt
[0].rgb_src_factor
!= blend
->rt
[0].alpha_src_factor
? "true" : "false",
122 blend
->rt
[0].rgb_dst_factor
!= blend
->rt
[0].alpha_dst_factor
? "true" : "false");
125 "%s\t%s\t%s\t%s\t%s\t%s\n",
126 util_dump_blend_func(blend
->rt
[0].rgb_func
, TRUE
),
127 util_dump_blend_factor(blend
->rt
[0].rgb_src_factor
, TRUE
),
128 util_dump_blend_factor(blend
->rt
[0].rgb_dst_factor
, TRUE
),
129 util_dump_blend_func(blend
->rt
[0].alpha_func
, TRUE
),
130 util_dump_blend_factor(blend
->rt
[0].alpha_src_factor
, TRUE
),
131 util_dump_blend_factor(blend
->rt
[0].alpha_dst_factor
, TRUE
));
138 dump_blend_type(FILE *fp
,
139 const struct pipe_blend_state
*blend
,
140 enum vector_mode mode
,
143 fprintf(fp
, "%s", mode
? "soa" : "aos");
145 fprintf(fp
, " type=%s%u%sx%u",
146 type
.floating
? "f" : (type
.fixed
? "h" : (type
.sign
? "s" : "u")),
148 type
.norm
? "n" : "",
152 " %s=%s %s=%s %s=%s %s=%s %s=%s %s=%s",
153 "rgb_func", util_dump_blend_func(blend
->rt
[0].rgb_func
, TRUE
),
154 "rgb_src_factor", util_dump_blend_factor(blend
->rt
[0].rgb_src_factor
, TRUE
),
155 "rgb_dst_factor", util_dump_blend_factor(blend
->rt
[0].rgb_dst_factor
, TRUE
),
156 "alpha_func", util_dump_blend_func(blend
->rt
[0].alpha_func
, TRUE
),
157 "alpha_src_factor", util_dump_blend_factor(blend
->rt
[0].alpha_src_factor
, TRUE
),
158 "alpha_dst_factor", util_dump_blend_factor(blend
->rt
[0].alpha_dst_factor
, TRUE
));
160 fprintf(fp
, " ...\n");
166 add_blend_test(struct gallivm_state
*gallivm
,
167 const struct pipe_blend_state
*blend
,
168 enum vector_mode mode
,
171 LLVMModuleRef module
= gallivm
->module
;
172 LLVMContextRef context
= gallivm
->context
;
173 LLVMTypeRef vec_type
;
176 LLVMValueRef src_ptr
;
177 LLVMValueRef dst_ptr
;
178 LLVMValueRef const_ptr
;
179 LLVMValueRef res_ptr
;
180 LLVMBasicBlockRef block
;
181 LLVMBuilderRef builder
;
182 const unsigned rt
= 0;
184 vec_type
= lp_build_vec_type(gallivm
, type
);
186 args
[3] = args
[2] = args
[1] = args
[0] = LLVMPointerType(vec_type
, 0);
187 func
= LLVMAddFunction(module
, "test", LLVMFunctionType(LLVMVoidTypeInContext(context
), args
, 4, 0));
188 LLVMSetFunctionCallConv(func
, LLVMCCallConv
);
189 src_ptr
= LLVMGetParam(func
, 0);
190 dst_ptr
= LLVMGetParam(func
, 1);
191 const_ptr
= LLVMGetParam(func
, 2);
192 res_ptr
= LLVMGetParam(func
, 3);
194 block
= LLVMAppendBasicBlockInContext(context
, func
, "entry");
195 builder
= gallivm
->builder
;
196 LLVMPositionBuilderAtEnd(builder
, block
);
204 src
= LLVMBuildLoad(builder
, src_ptr
, "src");
205 dst
= LLVMBuildLoad(builder
, dst_ptr
, "dst");
206 con
= LLVMBuildLoad(builder
, const_ptr
, "const");
208 res
= lp_build_blend_aos(gallivm
, blend
, type
, rt
, src
, dst
, con
, 3);
210 lp_build_name(res
, "res");
212 LLVMBuildStore(builder
, res
, res_ptr
);
222 for(i
= 0; i
< 4; ++i
) {
223 LLVMValueRef index
= LLVMConstInt(LLVMInt32TypeInContext(context
), i
, 0);
224 src
[i
] = LLVMBuildLoad(builder
, LLVMBuildGEP(builder
, src_ptr
, &index
, 1, ""), "");
225 dst
[i
] = LLVMBuildLoad(builder
, LLVMBuildGEP(builder
, dst_ptr
, &index
, 1, ""), "");
226 con
[i
] = LLVMBuildLoad(builder
, LLVMBuildGEP(builder
, const_ptr
, &index
, 1, ""), "");
227 lp_build_name(src
[i
], "src.%c", "rgba"[i
]);
228 lp_build_name(con
[i
], "con.%c", "rgba"[i
]);
229 lp_build_name(dst
[i
], "dst.%c", "rgba"[i
]);
232 lp_build_blend_soa(gallivm
, blend
, type
, rt
, src
, dst
, con
, res
);
234 for(i
= 0; i
< 4; ++i
) {
235 LLVMValueRef index
= LLVMConstInt(LLVMInt32TypeInContext(context
), i
, 0);
236 lp_build_name(res
[i
], "res.%c", "rgba"[i
]);
237 LLVMBuildStore(builder
, res
[i
], LLVMBuildGEP(builder
, res_ptr
, &index
, 1, ""));
241 LLVMBuildRetVoid(builder
);;
248 compute_blend_ref_term(unsigned rgb_factor
,
249 unsigned alpha_factor
,
250 const double *factor
,
258 switch (rgb_factor
) {
259 case PIPE_BLENDFACTOR_ONE
:
260 term
[0] = factor
[0]; /* R */
261 term
[1] = factor
[1]; /* G */
262 term
[2] = factor
[2]; /* B */
264 case PIPE_BLENDFACTOR_SRC_COLOR
:
265 term
[0] = factor
[0] * src
[0]; /* R */
266 term
[1] = factor
[1] * src
[1]; /* G */
267 term
[2] = factor
[2] * src
[2]; /* B */
269 case PIPE_BLENDFACTOR_SRC_ALPHA
:
270 term
[0] = factor
[0] * src
[3]; /* R */
271 term
[1] = factor
[1] * src
[3]; /* G */
272 term
[2] = factor
[2] * src
[3]; /* B */
274 case PIPE_BLENDFACTOR_DST_COLOR
:
275 term
[0] = factor
[0] * dst
[0]; /* R */
276 term
[1] = factor
[1] * dst
[1]; /* G */
277 term
[2] = factor
[2] * dst
[2]; /* B */
279 case PIPE_BLENDFACTOR_DST_ALPHA
:
280 term
[0] = factor
[0] * dst
[3]; /* R */
281 term
[1] = factor
[1] * dst
[3]; /* G */
282 term
[2] = factor
[2] * dst
[3]; /* B */
284 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
285 temp
= MIN2(src
[3], 1.0f
- dst
[3]);
286 term
[0] = factor
[0] * temp
; /* R */
287 term
[1] = factor
[1] * temp
; /* G */
288 term
[2] = factor
[2] * temp
; /* B */
290 case PIPE_BLENDFACTOR_CONST_COLOR
:
291 term
[0] = factor
[0] * con
[0]; /* R */
292 term
[1] = factor
[1] * con
[1]; /* G */
293 term
[2] = factor
[2] * con
[2]; /* B */
295 case PIPE_BLENDFACTOR_CONST_ALPHA
:
296 term
[0] = factor
[0] * con
[3]; /* R */
297 term
[1] = factor
[1] * con
[3]; /* G */
298 term
[2] = factor
[2] * con
[3]; /* B */
300 case PIPE_BLENDFACTOR_SRC1_COLOR
:
301 assert(0); /* to do */
303 case PIPE_BLENDFACTOR_SRC1_ALPHA
:
304 assert(0); /* to do */
306 case PIPE_BLENDFACTOR_ZERO
:
307 term
[0] = 0.0f
; /* R */
308 term
[1] = 0.0f
; /* G */
309 term
[2] = 0.0f
; /* B */
311 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
312 term
[0] = factor
[0] * (1.0f
- src
[0]); /* R */
313 term
[1] = factor
[1] * (1.0f
- src
[1]); /* G */
314 term
[2] = factor
[2] * (1.0f
- src
[2]); /* B */
316 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
317 term
[0] = factor
[0] * (1.0f
- src
[3]); /* R */
318 term
[1] = factor
[1] * (1.0f
- src
[3]); /* G */
319 term
[2] = factor
[2] * (1.0f
- src
[3]); /* B */
321 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
322 term
[0] = factor
[0] * (1.0f
- dst
[3]); /* R */
323 term
[1] = factor
[1] * (1.0f
- dst
[3]); /* G */
324 term
[2] = factor
[2] * (1.0f
- dst
[3]); /* B */
326 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
327 term
[0] = factor
[0] * (1.0f
- dst
[0]); /* R */
328 term
[1] = factor
[1] * (1.0f
- dst
[1]); /* G */
329 term
[2] = factor
[2] * (1.0f
- dst
[2]); /* B */
331 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
332 term
[0] = factor
[0] * (1.0f
- con
[0]); /* R */
333 term
[1] = factor
[1] * (1.0f
- con
[1]); /* G */
334 term
[2] = factor
[2] * (1.0f
- con
[2]); /* B */
336 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
337 term
[0] = factor
[0] * (1.0f
- con
[3]); /* R */
338 term
[1] = factor
[1] * (1.0f
- con
[3]); /* G */
339 term
[2] = factor
[2] * (1.0f
- con
[3]); /* B */
341 case PIPE_BLENDFACTOR_INV_SRC1_COLOR
:
342 assert(0); /* to do */
344 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA
:
345 assert(0); /* to do */
352 * Compute src/first term A
354 switch (alpha_factor
) {
355 case PIPE_BLENDFACTOR_ONE
:
356 term
[3] = factor
[3]; /* A */
358 case PIPE_BLENDFACTOR_SRC_COLOR
:
359 case PIPE_BLENDFACTOR_SRC_ALPHA
:
360 term
[3] = factor
[3] * src
[3]; /* A */
362 case PIPE_BLENDFACTOR_DST_COLOR
:
363 case PIPE_BLENDFACTOR_DST_ALPHA
:
364 term
[3] = factor
[3] * dst
[3]; /* A */
366 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
367 term
[3] = src
[3]; /* A */
369 case PIPE_BLENDFACTOR_CONST_COLOR
:
370 case PIPE_BLENDFACTOR_CONST_ALPHA
:
371 term
[3] = factor
[3] * con
[3]; /* A */
373 case PIPE_BLENDFACTOR_ZERO
:
374 term
[3] = 0.0f
; /* A */
376 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
377 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
378 term
[3] = factor
[3] * (1.0f
- src
[3]); /* A */
380 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
381 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
382 term
[3] = factor
[3] * (1.0f
- dst
[3]); /* A */
384 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
385 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
386 term
[3] = factor
[3] * (1.0f
- con
[3]);
395 compute_blend_ref(const struct pipe_blend_state
*blend
,
404 compute_blend_ref_term(blend
->rt
[0].rgb_src_factor
, blend
->rt
[0].alpha_src_factor
,
405 src
, src
, dst
, con
, src_term
);
406 compute_blend_ref_term(blend
->rt
[0].rgb_dst_factor
, blend
->rt
[0].alpha_dst_factor
,
407 dst
, src
, dst
, con
, dst_term
);
412 switch (blend
->rt
[0].rgb_func
) {
414 res
[0] = src_term
[0] + dst_term
[0]; /* R */
415 res
[1] = src_term
[1] + dst_term
[1]; /* G */
416 res
[2] = src_term
[2] + dst_term
[2]; /* B */
418 case PIPE_BLEND_SUBTRACT
:
419 res
[0] = src_term
[0] - dst_term
[0]; /* R */
420 res
[1] = src_term
[1] - dst_term
[1]; /* G */
421 res
[2] = src_term
[2] - dst_term
[2]; /* B */
423 case PIPE_BLEND_REVERSE_SUBTRACT
:
424 res
[0] = dst_term
[0] - src_term
[0]; /* R */
425 res
[1] = dst_term
[1] - src_term
[1]; /* G */
426 res
[2] = dst_term
[2] - src_term
[2]; /* B */
429 res
[0] = MIN2(src_term
[0], dst_term
[0]); /* R */
430 res
[1] = MIN2(src_term
[1], dst_term
[1]); /* G */
431 res
[2] = MIN2(src_term
[2], dst_term
[2]); /* B */
434 res
[0] = MAX2(src_term
[0], dst_term
[0]); /* R */
435 res
[1] = MAX2(src_term
[1], dst_term
[1]); /* G */
436 res
[2] = MAX2(src_term
[2], dst_term
[2]); /* B */
445 switch (blend
->rt
[0].alpha_func
) {
447 res
[3] = src_term
[3] + dst_term
[3]; /* A */
449 case PIPE_BLEND_SUBTRACT
:
450 res
[3] = src_term
[3] - dst_term
[3]; /* A */
452 case PIPE_BLEND_REVERSE_SUBTRACT
:
453 res
[3] = dst_term
[3] - src_term
[3]; /* A */
456 res
[3] = MIN2(src_term
[3], dst_term
[3]); /* A */
459 res
[3] = MAX2(src_term
[3], dst_term
[3]); /* A */
469 test_one(struct gallivm_state
*gallivm
,
472 const struct pipe_blend_state
*blend
,
473 enum vector_mode mode
,
476 LLVMModuleRef module
= gallivm
->module
;
477 LLVMValueRef func
= NULL
;
478 LLVMExecutionEngineRef engine
= gallivm
->engine
;
480 blend_test_ptr_t blend_test_ptr
;
482 const unsigned n
= LP_TEST_NUM_SAMPLES
;
483 int64_t cycles
[LP_TEST_NUM_SAMPLES
];
484 double cycles_avg
= 0.0;
489 dump_blend_type(stdout
, blend
, mode
, type
);
491 func
= add_blend_test(gallivm
, blend
, mode
, type
);
493 if(LLVMVerifyModule(module
, LLVMPrintMessageAction
, &error
)) {
494 LLVMDumpModule(module
);
497 LLVMDisposeMessage(error
);
499 code
= LLVMGetPointerToGlobal(engine
, func
);
500 blend_test_ptr
= voidptr_to_blend_test_ptr_t(code
);
503 lp_disassemble(code
);
506 for(i
= 0; i
< n
&& success
; ++i
) {
508 PIPE_ALIGN_VAR(16) uint8_t src
[LP_NATIVE_VECTOR_WIDTH
/8];
509 PIPE_ALIGN_VAR(16) uint8_t dst
[LP_NATIVE_VECTOR_WIDTH
/8];
510 PIPE_ALIGN_VAR(16) uint8_t con
[LP_NATIVE_VECTOR_WIDTH
/8];
511 PIPE_ALIGN_VAR(16) uint8_t res
[LP_NATIVE_VECTOR_WIDTH
/8];
512 PIPE_ALIGN_VAR(16) uint8_t ref
[LP_NATIVE_VECTOR_WIDTH
/8];
513 int64_t start_counter
= 0;
514 int64_t end_counter
= 0;
516 random_vec(type
, src
);
517 random_vec(type
, dst
);
518 random_vec(type
, con
);
521 double fsrc
[LP_MAX_VECTOR_LENGTH
];
522 double fdst
[LP_MAX_VECTOR_LENGTH
];
523 double fcon
[LP_MAX_VECTOR_LENGTH
];
524 double fref
[LP_MAX_VECTOR_LENGTH
];
526 read_vec(type
, src
, fsrc
);
527 read_vec(type
, dst
, fdst
);
528 read_vec(type
, con
, fcon
);
530 for(j
= 0; j
< type
.length
; j
+= 4)
531 compute_blend_ref(blend
, fsrc
+ j
, fdst
+ j
, fcon
+ j
, fref
+ j
);
533 write_vec(type
, ref
, fref
);
536 start_counter
= rdtsc();
537 blend_test_ptr(src
, dst
, con
, res
);
538 end_counter
= rdtsc();
540 cycles
[i
] = end_counter
- start_counter
;
542 if(!compare_vec(type
, res
, ref
)) {
546 dump_blend_type(stderr
, blend
, mode
, type
);
547 fprintf(stderr
, "MISMATCH\n");
549 fprintf(stderr
, " Src: ");
550 dump_vec(stderr
, type
, src
);
551 fprintf(stderr
, "\n");
553 fprintf(stderr
, " Dst: ");
554 dump_vec(stderr
, type
, dst
);
555 fprintf(stderr
, "\n");
557 fprintf(stderr
, " Con: ");
558 dump_vec(stderr
, type
, con
);
559 fprintf(stderr
, "\n");
561 fprintf(stderr
, " Res: ");
562 dump_vec(stderr
, type
, res
);
563 fprintf(stderr
, "\n");
565 fprintf(stderr
, " Ref: ");
566 dump_vec(stderr
, type
, ref
);
567 fprintf(stderr
, "\n");
572 const unsigned stride
= type
.length
*type
.width
/8;
573 PIPE_ALIGN_VAR(16) uint8_t src
[4*LP_NATIVE_VECTOR_WIDTH
/8];
574 PIPE_ALIGN_VAR(16) uint8_t dst
[4*LP_NATIVE_VECTOR_WIDTH
/8];
575 PIPE_ALIGN_VAR(16) uint8_t con
[4*LP_NATIVE_VECTOR_WIDTH
/8];
576 PIPE_ALIGN_VAR(16) uint8_t res
[4*LP_NATIVE_VECTOR_WIDTH
/8];
577 PIPE_ALIGN_VAR(16) uint8_t ref
[4*LP_NATIVE_VECTOR_WIDTH
/8];
578 int64_t start_counter
= 0;
579 int64_t end_counter
= 0;
582 for(j
= 0; j
< 4; ++j
) {
583 random_vec(type
, src
+ j
*stride
);
584 random_vec(type
, dst
+ j
*stride
);
585 random_vec(type
, con
+ j
*stride
);
595 for(k
= 0; k
< type
.length
; ++k
) {
596 for(j
= 0; j
< 4; ++j
) {
597 fsrc
[j
] = read_elem(type
, src
+ j
*stride
, k
);
598 fdst
[j
] = read_elem(type
, dst
+ j
*stride
, k
);
599 fcon
[j
] = read_elem(type
, con
+ j
*stride
, k
);
602 compute_blend_ref(blend
, fsrc
, fdst
, fcon
, fref
);
604 for(j
= 0; j
< 4; ++j
)
605 write_elem(type
, ref
+ j
*stride
, k
, fref
[j
]);
609 start_counter
= rdtsc();
610 blend_test_ptr(src
, dst
, con
, res
);
611 end_counter
= rdtsc();
613 cycles
[i
] = end_counter
- start_counter
;
616 for (j
= 0; j
< 4; ++j
)
617 if(!compare_vec(type
, res
+ j
*stride
, ref
+ j
*stride
))
624 dump_blend_type(stderr
, blend
, mode
, type
);
625 fprintf(stderr
, "MISMATCH\n");
626 for(j
= 0; j
< 4; ++j
) {
627 char channel
= "RGBA"[j
];
628 fprintf(stderr
, " Src%c: ", channel
);
629 dump_vec(stderr
, type
, src
+ j
*stride
);
630 fprintf(stderr
, "\n");
632 fprintf(stderr
, " Dst%c: ", channel
);
633 dump_vec(stderr
, type
, dst
+ j
*stride
);
634 fprintf(stderr
, "\n");
636 fprintf(stderr
, " Con%c: ", channel
);
637 dump_vec(stderr
, type
, con
+ j
*stride
);
638 fprintf(stderr
, "\n");
640 fprintf(stderr
, " Res%c: ", channel
);
641 dump_vec(stderr
, type
, res
+ j
*stride
);
642 fprintf(stderr
, "\n");
644 fprintf(stderr
, " Ref%c: ", channel
);
645 dump_vec(stderr
, type
, ref
+ j
*stride
);
646 fprintf(stderr
, "\n");
648 fprintf(stderr
, "\n");
655 * Unfortunately the output of cycle counter is not very reliable as it comes
656 * -- sometimes we get outliers (due IRQs perhaps?) which are
657 * better removed to avoid random or biased data.
660 double sum
= 0.0, sum2
= 0.0;
664 for(i
= 0; i
< n
; ++i
) {
666 sum2
+= cycles
[i
]*cycles
[i
];
670 std
= sqrtf((sum2
- n
*avg
*avg
)/n
);
674 for(i
= 0; i
< n
; ++i
) {
675 if(fabs(cycles
[i
] - avg
) <= 4.0*std
) {
686 write_tsv_row(fp
, blend
, mode
, type
, cycles_avg
, success
);
690 LLVMDumpModule(module
);
691 LLVMWriteBitcodeToFile(module
, "blend.bc");
692 fprintf(stderr
, "blend.bc written\n");
693 fprintf(stderr
, "Invoke as \"llc -o - blend.bc\"\n");
697 LLVMFreeMachineCodeForFunction(engine
, func
);
705 PIPE_BLENDFACTOR_ZERO
,
706 PIPE_BLENDFACTOR_ONE
,
707 PIPE_BLENDFACTOR_SRC_COLOR
,
708 PIPE_BLENDFACTOR_SRC_ALPHA
,
709 PIPE_BLENDFACTOR_DST_COLOR
,
710 PIPE_BLENDFACTOR_DST_ALPHA
,
711 PIPE_BLENDFACTOR_CONST_COLOR
,
712 PIPE_BLENDFACTOR_CONST_ALPHA
,
714 PIPE_BLENDFACTOR_SRC1_COLOR
,
715 PIPE_BLENDFACTOR_SRC1_ALPHA
,
717 PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
,
718 PIPE_BLENDFACTOR_INV_SRC_COLOR
,
719 PIPE_BLENDFACTOR_INV_SRC_ALPHA
,
720 PIPE_BLENDFACTOR_INV_DST_COLOR
,
721 PIPE_BLENDFACTOR_INV_DST_ALPHA
,
722 PIPE_BLENDFACTOR_INV_CONST_COLOR
,
723 PIPE_BLENDFACTOR_INV_CONST_ALPHA
,
725 PIPE_BLENDFACTOR_INV_SRC1_COLOR
,
726 PIPE_BLENDFACTOR_INV_SRC1_ALPHA
,
735 PIPE_BLEND_REVERSE_SUBTRACT
,
741 const struct lp_type blend_types
[] = {
742 /* float, fixed, sign, norm, width, len */
743 { TRUE
, FALSE
, TRUE
, FALSE
, 32, 4 }, /* f32 x 4 */
744 { FALSE
, FALSE
, FALSE
, TRUE
, 8, 16 }, /* u8n x 16 */
748 const unsigned num_funcs
= sizeof(blend_funcs
)/sizeof(blend_funcs
[0]);
749 const unsigned num_factors
= sizeof(blend_factors
)/sizeof(blend_factors
[0]);
750 const unsigned num_types
= sizeof(blend_types
)/sizeof(blend_types
[0]);
754 test_all(struct gallivm_state
*gallivm
, unsigned verbose
, FILE *fp
)
756 const unsigned *rgb_func
;
757 const unsigned *rgb_src_factor
;
758 const unsigned *rgb_dst_factor
;
759 const unsigned *alpha_func
;
760 const unsigned *alpha_src_factor
;
761 const unsigned *alpha_dst_factor
;
762 struct pipe_blend_state blend
;
763 enum vector_mode mode
;
764 const struct lp_type
*type
;
765 boolean success
= TRUE
;
767 for(rgb_func
= blend_funcs
; rgb_func
< &blend_funcs
[num_funcs
]; ++rgb_func
) {
768 for(alpha_func
= blend_funcs
; alpha_func
< &blend_funcs
[num_funcs
]; ++alpha_func
) {
769 for(rgb_src_factor
= blend_factors
; rgb_src_factor
< &blend_factors
[num_factors
]; ++rgb_src_factor
) {
770 for(rgb_dst_factor
= blend_factors
; rgb_dst_factor
<= rgb_src_factor
; ++rgb_dst_factor
) {
771 for(alpha_src_factor
= blend_factors
; alpha_src_factor
< &blend_factors
[num_factors
]; ++alpha_src_factor
) {
772 for(alpha_dst_factor
= blend_factors
; alpha_dst_factor
<= alpha_src_factor
; ++alpha_dst_factor
) {
773 for(mode
= 0; mode
< 2; ++mode
) {
774 for(type
= blend_types
; type
< &blend_types
[num_types
]; ++type
) {
776 if(*rgb_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
||
777 *alpha_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
)
780 memset(&blend
, 0, sizeof blend
);
781 blend
.rt
[0].blend_enable
= 1;
782 blend
.rt
[0].rgb_func
= *rgb_func
;
783 blend
.rt
[0].rgb_src_factor
= *rgb_src_factor
;
784 blend
.rt
[0].rgb_dst_factor
= *rgb_dst_factor
;
785 blend
.rt
[0].alpha_func
= *alpha_func
;
786 blend
.rt
[0].alpha_src_factor
= *alpha_src_factor
;
787 blend
.rt
[0].alpha_dst_factor
= *alpha_dst_factor
;
788 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
790 if(!test_one(gallivm
, verbose
, fp
, &blend
, mode
, *type
))
807 test_some(struct gallivm_state
*gallivm
, unsigned verbose
, FILE *fp
,
810 const unsigned *rgb_func
;
811 const unsigned *rgb_src_factor
;
812 const unsigned *rgb_dst_factor
;
813 const unsigned *alpha_func
;
814 const unsigned *alpha_src_factor
;
815 const unsigned *alpha_dst_factor
;
816 struct pipe_blend_state blend
;
817 enum vector_mode mode
;
818 const struct lp_type
*type
;
820 boolean success
= TRUE
;
822 for(i
= 0; i
< n
; ++i
) {
823 rgb_func
= &blend_funcs
[rand() % num_funcs
];
824 alpha_func
= &blend_funcs
[rand() % num_funcs
];
825 rgb_src_factor
= &blend_factors
[rand() % num_factors
];
826 alpha_src_factor
= &blend_factors
[rand() % num_factors
];
829 rgb_dst_factor
= &blend_factors
[rand() % num_factors
];
830 } while(*rgb_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
);
833 alpha_dst_factor
= &blend_factors
[rand() % num_factors
];
834 } while(*alpha_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
);
838 type
= &blend_types
[rand() % num_types
];
840 memset(&blend
, 0, sizeof blend
);
841 blend
.rt
[0].blend_enable
= 1;
842 blend
.rt
[0].rgb_func
= *rgb_func
;
843 blend
.rt
[0].rgb_src_factor
= *rgb_src_factor
;
844 blend
.rt
[0].rgb_dst_factor
= *rgb_dst_factor
;
845 blend
.rt
[0].alpha_func
= *alpha_func
;
846 blend
.rt
[0].alpha_src_factor
= *alpha_src_factor
;
847 blend
.rt
[0].alpha_dst_factor
= *alpha_dst_factor
;
848 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
850 if(!test_one(gallivm
, verbose
, fp
, &blend
, mode
, *type
))
859 test_single(struct gallivm_state
*gallivm
, unsigned verbose
, FILE *fp
)
861 printf("no test_single()");