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_type.h"
41 #include "gallivm/lp_bld_debug.h"
42 #include "lp_bld_blend.h"
53 typedef void (*blend_test_ptr_t
)(const void *src
, const void *dst
, const void *con
, void *res
);
57 write_tsv_header(FILE *fp
)
61 "cycles_per_channel\t"
72 "alpha_dst_factor\n");
79 write_tsv_row(FILE *fp
,
80 const struct pipe_blend_state
*blend
,
81 enum vector_mode mode
,
86 fprintf(fp
, "%s\t", success
? "pass" : "fail");
89 fprintf(fp
, "%.1f\t", cycles
/ type
.length
);
94 fprintf(fp
, "%.1f\t", cycles
/ (4 * type
.length
));
98 fprintf(fp
, "%s%u%sx%u\t",
99 type
.floating
? "f" : (type
.fixed
? "h" : (type
.sign
? "s" : "u")),
101 type
.norm
? "n" : "",
106 blend
->rt
[0].rgb_func
!= blend
->rt
[0].alpha_func
? "true" : "false",
107 blend
->rt
[0].rgb_src_factor
!= blend
->rt
[0].alpha_src_factor
? "true" : "false",
108 blend
->rt
[0].rgb_dst_factor
!= blend
->rt
[0].alpha_dst_factor
? "true" : "false");
111 "%s\t%s\t%s\t%s\t%s\t%s\n",
112 util_dump_blend_func(blend
->rt
[0].rgb_func
, TRUE
),
113 util_dump_blend_factor(blend
->rt
[0].rgb_src_factor
, TRUE
),
114 util_dump_blend_factor(blend
->rt
[0].rgb_dst_factor
, TRUE
),
115 util_dump_blend_func(blend
->rt
[0].alpha_func
, TRUE
),
116 util_dump_blend_factor(blend
->rt
[0].alpha_src_factor
, TRUE
),
117 util_dump_blend_factor(blend
->rt
[0].alpha_dst_factor
, TRUE
));
124 dump_blend_type(FILE *fp
,
125 const struct pipe_blend_state
*blend
,
126 enum vector_mode mode
,
129 fprintf(fp
, "%s", mode
? "soa" : "aos");
131 fprintf(fp
, " type=%s%u%sx%u",
132 type
.floating
? "f" : (type
.fixed
? "h" : (type
.sign
? "s" : "u")),
134 type
.norm
? "n" : "",
138 " %s=%s %s=%s %s=%s %s=%s %s=%s %s=%s",
139 "rgb_func", util_dump_blend_func(blend
->rt
[0].rgb_func
, TRUE
),
140 "rgb_src_factor", util_dump_blend_factor(blend
->rt
[0].rgb_src_factor
, TRUE
),
141 "rgb_dst_factor", util_dump_blend_factor(blend
->rt
[0].rgb_dst_factor
, TRUE
),
142 "alpha_func", util_dump_blend_func(blend
->rt
[0].alpha_func
, TRUE
),
143 "alpha_src_factor", util_dump_blend_factor(blend
->rt
[0].alpha_src_factor
, TRUE
),
144 "alpha_dst_factor", util_dump_blend_factor(blend
->rt
[0].alpha_dst_factor
, TRUE
));
146 fprintf(fp
, " ...\n");
152 add_blend_test(LLVMModuleRef module
,
153 const struct pipe_blend_state
*blend
,
154 enum vector_mode mode
,
157 LLVMTypeRef vec_type
;
160 LLVMValueRef src_ptr
;
161 LLVMValueRef dst_ptr
;
162 LLVMValueRef const_ptr
;
163 LLVMValueRef res_ptr
;
164 LLVMBasicBlockRef block
;
165 LLVMBuilderRef builder
;
166 const unsigned rt
= 0;
168 vec_type
= lp_build_vec_type(type
);
170 args
[3] = args
[2] = args
[1] = args
[0] = LLVMPointerType(vec_type
, 0);
171 func
= LLVMAddFunction(module
, "test", LLVMFunctionType(LLVMVoidType(), args
, 4, 0));
172 LLVMSetFunctionCallConv(func
, LLVMCCallConv
);
173 src_ptr
= LLVMGetParam(func
, 0);
174 dst_ptr
= LLVMGetParam(func
, 1);
175 const_ptr
= LLVMGetParam(func
, 2);
176 res_ptr
= LLVMGetParam(func
, 3);
178 block
= LLVMAppendBasicBlock(func
, "entry");
179 builder
= LLVMCreateBuilder();
180 LLVMPositionBuilderAtEnd(builder
, block
);
188 src
= LLVMBuildLoad(builder
, src_ptr
, "src");
189 dst
= LLVMBuildLoad(builder
, dst_ptr
, "dst");
190 con
= LLVMBuildLoad(builder
, const_ptr
, "const");
192 res
= lp_build_blend_aos(builder
, blend
, type
, rt
, src
, dst
, con
, 3);
194 lp_build_name(res
, "res");
196 LLVMBuildStore(builder
, res
, res_ptr
);
206 for(i
= 0; i
< 4; ++i
) {
207 LLVMValueRef index
= LLVMConstInt(LLVMInt32Type(), i
, 0);
208 src
[i
] = LLVMBuildLoad(builder
, LLVMBuildGEP(builder
, src_ptr
, &index
, 1, ""), "");
209 dst
[i
] = LLVMBuildLoad(builder
, LLVMBuildGEP(builder
, dst_ptr
, &index
, 1, ""), "");
210 con
[i
] = LLVMBuildLoad(builder
, LLVMBuildGEP(builder
, const_ptr
, &index
, 1, ""), "");
211 lp_build_name(src
[i
], "src.%c", "rgba"[i
]);
212 lp_build_name(con
[i
], "con.%c", "rgba"[i
]);
213 lp_build_name(dst
[i
], "dst.%c", "rgba"[i
]);
216 lp_build_blend_soa(builder
, blend
, type
, rt
, src
, dst
, con
, res
);
218 for(i
= 0; i
< 4; ++i
) {
219 LLVMValueRef index
= LLVMConstInt(LLVMInt32Type(), i
, 0);
220 lp_build_name(res
[i
], "res.%c", "rgba"[i
]);
221 LLVMBuildStore(builder
, res
[i
], LLVMBuildGEP(builder
, res_ptr
, &index
, 1, ""));
225 LLVMBuildRetVoid(builder
);;
227 LLVMDisposeBuilder(builder
);
232 /** Add and limit result to ceiling of 1.0 */
233 #define ADD_SAT(R, A, B) \
235 R = (A) + (B); if (R > 1.0f) R = 1.0f; \
238 /** Subtract and limit result to floor of 0.0 */
239 #define SUB_SAT(R, A, B) \
241 R = (A) - (B); if (R < 0.0f) R = 0.0f; \
246 compute_blend_ref_term(unsigned rgb_factor
,
247 unsigned alpha_factor
,
248 const double *factor
,
256 switch (rgb_factor
) {
257 case PIPE_BLENDFACTOR_ONE
:
258 term
[0] = factor
[0]; /* R */
259 term
[1] = factor
[1]; /* G */
260 term
[2] = factor
[2]; /* B */
262 case PIPE_BLENDFACTOR_SRC_COLOR
:
263 term
[0] = factor
[0] * src
[0]; /* R */
264 term
[1] = factor
[1] * src
[1]; /* G */
265 term
[2] = factor
[2] * src
[2]; /* B */
267 case PIPE_BLENDFACTOR_SRC_ALPHA
:
268 term
[0] = factor
[0] * src
[3]; /* R */
269 term
[1] = factor
[1] * src
[3]; /* G */
270 term
[2] = factor
[2] * src
[3]; /* B */
272 case PIPE_BLENDFACTOR_DST_COLOR
:
273 term
[0] = factor
[0] * dst
[0]; /* R */
274 term
[1] = factor
[1] * dst
[1]; /* G */
275 term
[2] = factor
[2] * dst
[2]; /* B */
277 case PIPE_BLENDFACTOR_DST_ALPHA
:
278 term
[0] = factor
[0] * dst
[3]; /* R */
279 term
[1] = factor
[1] * dst
[3]; /* G */
280 term
[2] = factor
[2] * dst
[3]; /* B */
282 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
283 temp
= MIN2(src
[3], 1.0f
- dst
[3]);
284 term
[0] = factor
[0] * temp
; /* R */
285 term
[1] = factor
[1] * temp
; /* G */
286 term
[2] = factor
[2] * temp
; /* B */
288 case PIPE_BLENDFACTOR_CONST_COLOR
:
289 term
[0] = factor
[0] * con
[0]; /* R */
290 term
[1] = factor
[1] * con
[1]; /* G */
291 term
[2] = factor
[2] * con
[2]; /* B */
293 case PIPE_BLENDFACTOR_CONST_ALPHA
:
294 term
[0] = factor
[0] * con
[3]; /* R */
295 term
[1] = factor
[1] * con
[3]; /* G */
296 term
[2] = factor
[2] * con
[3]; /* B */
298 case PIPE_BLENDFACTOR_SRC1_COLOR
:
299 assert(0); /* to do */
301 case PIPE_BLENDFACTOR_SRC1_ALPHA
:
302 assert(0); /* to do */
304 case PIPE_BLENDFACTOR_ZERO
:
305 term
[0] = 0.0f
; /* R */
306 term
[1] = 0.0f
; /* G */
307 term
[2] = 0.0f
; /* B */
309 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
310 term
[0] = factor
[0] * (1.0f
- src
[0]); /* R */
311 term
[1] = factor
[1] * (1.0f
- src
[1]); /* G */
312 term
[2] = factor
[2] * (1.0f
- src
[2]); /* B */
314 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
315 term
[0] = factor
[0] * (1.0f
- src
[3]); /* R */
316 term
[1] = factor
[1] * (1.0f
- src
[3]); /* G */
317 term
[2] = factor
[2] * (1.0f
- src
[3]); /* B */
319 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
320 term
[0] = factor
[0] * (1.0f
- dst
[3]); /* R */
321 term
[1] = factor
[1] * (1.0f
- dst
[3]); /* G */
322 term
[2] = factor
[2] * (1.0f
- dst
[3]); /* B */
324 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
325 term
[0] = factor
[0] * (1.0f
- dst
[0]); /* R */
326 term
[1] = factor
[1] * (1.0f
- dst
[1]); /* G */
327 term
[2] = factor
[2] * (1.0f
- dst
[2]); /* B */
329 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
330 term
[0] = factor
[0] * (1.0f
- con
[0]); /* R */
331 term
[1] = factor
[1] * (1.0f
- con
[1]); /* G */
332 term
[2] = factor
[2] * (1.0f
- con
[2]); /* B */
334 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
335 term
[0] = factor
[0] * (1.0f
- con
[3]); /* R */
336 term
[1] = factor
[1] * (1.0f
- con
[3]); /* G */
337 term
[2] = factor
[2] * (1.0f
- con
[3]); /* B */
339 case PIPE_BLENDFACTOR_INV_SRC1_COLOR
:
340 assert(0); /* to do */
342 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA
:
343 assert(0); /* to do */
350 * Compute src/first term A
352 switch (alpha_factor
) {
353 case PIPE_BLENDFACTOR_ONE
:
354 term
[3] = factor
[3]; /* A */
356 case PIPE_BLENDFACTOR_SRC_COLOR
:
357 case PIPE_BLENDFACTOR_SRC_ALPHA
:
358 term
[3] = factor
[3] * src
[3]; /* A */
360 case PIPE_BLENDFACTOR_DST_COLOR
:
361 case PIPE_BLENDFACTOR_DST_ALPHA
:
362 term
[3] = factor
[3] * dst
[3]; /* A */
364 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
365 term
[3] = src
[3]; /* A */
367 case PIPE_BLENDFACTOR_CONST_COLOR
:
368 case PIPE_BLENDFACTOR_CONST_ALPHA
:
369 term
[3] = factor
[3] * con
[3]; /* A */
371 case PIPE_BLENDFACTOR_ZERO
:
372 term
[3] = 0.0f
; /* A */
374 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
375 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
376 term
[3] = factor
[3] * (1.0f
- src
[3]); /* A */
378 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
379 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
380 term
[3] = factor
[3] * (1.0f
- dst
[3]); /* A */
382 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
383 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
384 term
[3] = factor
[3] * (1.0f
- con
[3]);
393 compute_blend_ref(const struct pipe_blend_state
*blend
,
402 compute_blend_ref_term(blend
->rt
[0].rgb_src_factor
, blend
->rt
[0].alpha_src_factor
,
403 src
, src
, dst
, con
, src_term
);
404 compute_blend_ref_term(blend
->rt
[0].rgb_dst_factor
, blend
->rt
[0].alpha_dst_factor
,
405 dst
, src
, dst
, con
, dst_term
);
410 switch (blend
->rt
[0].rgb_func
) {
412 ADD_SAT(res
[0], src_term
[0], dst_term
[0]); /* R */
413 ADD_SAT(res
[1], src_term
[1], dst_term
[1]); /* G */
414 ADD_SAT(res
[2], src_term
[2], dst_term
[2]); /* B */
416 case PIPE_BLEND_SUBTRACT
:
417 SUB_SAT(res
[0], src_term
[0], dst_term
[0]); /* R */
418 SUB_SAT(res
[1], src_term
[1], dst_term
[1]); /* G */
419 SUB_SAT(res
[2], src_term
[2], dst_term
[2]); /* B */
421 case PIPE_BLEND_REVERSE_SUBTRACT
:
422 SUB_SAT(res
[0], dst_term
[0], src_term
[0]); /* R */
423 SUB_SAT(res
[1], dst_term
[1], src_term
[1]); /* G */
424 SUB_SAT(res
[2], dst_term
[2], src_term
[2]); /* B */
427 res
[0] = MIN2(src_term
[0], dst_term
[0]); /* R */
428 res
[1] = MIN2(src_term
[1], dst_term
[1]); /* G */
429 res
[2] = MIN2(src_term
[2], dst_term
[2]); /* B */
432 res
[0] = MAX2(src_term
[0], dst_term
[0]); /* R */
433 res
[1] = MAX2(src_term
[1], dst_term
[1]); /* G */
434 res
[2] = MAX2(src_term
[2], dst_term
[2]); /* B */
443 switch (blend
->rt
[0].alpha_func
) {
445 ADD_SAT(res
[3], src_term
[3], dst_term
[3]); /* A */
447 case PIPE_BLEND_SUBTRACT
:
448 SUB_SAT(res
[3], src_term
[3], dst_term
[3]); /* A */
450 case PIPE_BLEND_REVERSE_SUBTRACT
:
451 SUB_SAT(res
[3], dst_term
[3], src_term
[3]); /* A */
454 res
[3] = MIN2(src_term
[3], dst_term
[3]); /* A */
457 res
[3] = MAX2(src_term
[3], dst_term
[3]); /* A */
467 test_one(unsigned verbose
,
469 const struct pipe_blend_state
*blend
,
470 enum vector_mode mode
,
473 LLVMModuleRef module
= NULL
;
474 LLVMValueRef func
= NULL
;
475 LLVMExecutionEngineRef engine
= NULL
;
476 LLVMModuleProviderRef provider
= NULL
;
477 LLVMPassManagerRef pass
= NULL
;
479 blend_test_ptr_t blend_test_ptr
;
481 const unsigned n
= LP_TEST_NUM_SAMPLES
;
482 int64_t cycles
[LP_TEST_NUM_SAMPLES
];
483 double cycles_avg
= 0.0;
487 dump_blend_type(stdout
, blend
, mode
, type
);
489 module
= LLVMModuleCreateWithName("test");
491 func
= add_blend_test(module
, blend
, mode
, type
);
493 if(LLVMVerifyModule(module
, LLVMPrintMessageAction
, &error
)) {
494 LLVMDumpModule(module
);
497 LLVMDisposeMessage(error
);
499 provider
= LLVMCreateModuleProviderForExistingModule(module
);
500 if (LLVMCreateJITCompiler(&engine
, provider
, 1, &error
)) {
502 dump_blend_type(stderr
, blend
, mode
, type
);
503 fprintf(stderr
, "%s\n", error
);
504 LLVMDisposeMessage(error
);
509 pass
= LLVMCreatePassManager();
510 LLVMAddTargetData(LLVMGetExecutionEngineTargetData(engine
), pass
);
511 /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
512 * but there are more on SVN. */
513 LLVMAddConstantPropagationPass(pass
);
514 LLVMAddInstructionCombiningPass(pass
);
515 LLVMAddPromoteMemoryToRegisterPass(pass
);
516 LLVMAddGVNPass(pass
);
517 LLVMAddCFGSimplificationPass(pass
);
518 LLVMRunPassManager(pass
, module
);
524 LLVMDumpModule(module
);
526 blend_test_ptr
= (blend_test_ptr_t
)LLVMGetPointerToGlobal(engine
, func
);
529 lp_disassemble(blend_test_ptr
);
532 for(i
= 0; i
< n
&& success
; ++i
) {
534 PIPE_ALIGN_VAR(16) uint8_t src
[LP_NATIVE_VECTOR_WIDTH
/8];
535 PIPE_ALIGN_VAR(16) uint8_t dst
[LP_NATIVE_VECTOR_WIDTH
/8];
536 PIPE_ALIGN_VAR(16) uint8_t con
[LP_NATIVE_VECTOR_WIDTH
/8];
537 PIPE_ALIGN_VAR(16) uint8_t res
[LP_NATIVE_VECTOR_WIDTH
/8];
538 PIPE_ALIGN_VAR(16) uint8_t ref
[LP_NATIVE_VECTOR_WIDTH
/8];
539 int64_t start_counter
= 0;
540 int64_t end_counter
= 0;
542 random_vec(type
, src
);
543 random_vec(type
, dst
);
544 random_vec(type
, con
);
547 double fsrc
[LP_MAX_VECTOR_LENGTH
];
548 double fdst
[LP_MAX_VECTOR_LENGTH
];
549 double fcon
[LP_MAX_VECTOR_LENGTH
];
550 double fref
[LP_MAX_VECTOR_LENGTH
];
552 read_vec(type
, src
, fsrc
);
553 read_vec(type
, dst
, fdst
);
554 read_vec(type
, con
, fcon
);
556 for(j
= 0; j
< type
.length
; j
+= 4)
557 compute_blend_ref(blend
, fsrc
+ j
, fdst
+ j
, fcon
+ j
, fref
+ j
);
559 write_vec(type
, ref
, fref
);
562 start_counter
= rdtsc();
563 blend_test_ptr(src
, dst
, con
, res
);
564 end_counter
= rdtsc();
566 cycles
[i
] = end_counter
- start_counter
;
568 if(!compare_vec(type
, res
, ref
)) {
572 dump_blend_type(stderr
, blend
, mode
, type
);
573 fprintf(stderr
, "MISMATCH\n");
575 fprintf(stderr
, " Src: ");
576 dump_vec(stderr
, type
, src
);
577 fprintf(stderr
, "\n");
579 fprintf(stderr
, " Dst: ");
580 dump_vec(stderr
, type
, dst
);
581 fprintf(stderr
, "\n");
583 fprintf(stderr
, " Con: ");
584 dump_vec(stderr
, type
, con
);
585 fprintf(stderr
, "\n");
587 fprintf(stderr
, " Res: ");
588 dump_vec(stderr
, type
, res
);
589 fprintf(stderr
, "\n");
591 fprintf(stderr
, " Ref: ");
592 dump_vec(stderr
, type
, ref
);
593 fprintf(stderr
, "\n");
598 const unsigned stride
= type
.length
*type
.width
/8;
599 PIPE_ALIGN_VAR(16) uint8_t src
[4*LP_NATIVE_VECTOR_WIDTH
/8];
600 PIPE_ALIGN_VAR(16) uint8_t dst
[4*LP_NATIVE_VECTOR_WIDTH
/8];
601 PIPE_ALIGN_VAR(16) uint8_t con
[4*LP_NATIVE_VECTOR_WIDTH
/8];
602 PIPE_ALIGN_VAR(16) uint8_t res
[4*LP_NATIVE_VECTOR_WIDTH
/8];
603 PIPE_ALIGN_VAR(16) uint8_t ref
[4*LP_NATIVE_VECTOR_WIDTH
/8];
604 int64_t start_counter
= 0;
605 int64_t end_counter
= 0;
608 for(j
= 0; j
< 4; ++j
) {
609 random_vec(type
, src
+ j
*stride
);
610 random_vec(type
, dst
+ j
*stride
);
611 random_vec(type
, con
+ j
*stride
);
621 for(k
= 0; k
< type
.length
; ++k
) {
622 for(j
= 0; j
< 4; ++j
) {
623 fsrc
[j
] = read_elem(type
, src
+ j
*stride
, k
);
624 fdst
[j
] = read_elem(type
, dst
+ j
*stride
, k
);
625 fcon
[j
] = read_elem(type
, con
+ j
*stride
, k
);
628 compute_blend_ref(blend
, fsrc
, fdst
, fcon
, fref
);
630 for(j
= 0; j
< 4; ++j
)
631 write_elem(type
, ref
+ j
*stride
, k
, fref
[j
]);
635 start_counter
= rdtsc();
636 blend_test_ptr(src
, dst
, con
, res
);
637 end_counter
= rdtsc();
639 cycles
[i
] = end_counter
- start_counter
;
642 for (j
= 0; j
< 4; ++j
)
643 if(!compare_vec(type
, res
+ j
*stride
, ref
+ j
*stride
))
650 dump_blend_type(stderr
, blend
, mode
, type
);
651 fprintf(stderr
, "MISMATCH\n");
652 for(j
= 0; j
< 4; ++j
) {
653 char channel
= "RGBA"[j
];
654 fprintf(stderr
, " Src%c: ", channel
);
655 dump_vec(stderr
, type
, src
+ j
*stride
);
656 fprintf(stderr
, "\n");
658 fprintf(stderr
, " Dst%c: ", channel
);
659 dump_vec(stderr
, type
, dst
+ j
*stride
);
660 fprintf(stderr
, "\n");
662 fprintf(stderr
, " Con%c: ", channel
);
663 dump_vec(stderr
, type
, con
+ j
*stride
);
664 fprintf(stderr
, "\n");
666 fprintf(stderr
, " Res%c: ", channel
);
667 dump_vec(stderr
, type
, res
+ j
*stride
);
668 fprintf(stderr
, "\n");
670 fprintf(stderr
, " Ref%c: ", channel
);
671 dump_vec(stderr
, type
, ref
+ j
*stride
);
672 fprintf(stderr
, "\n");
679 * Unfortunately the output of cycle counter is not very reliable as it comes
680 * -- sometimes we get outliers (due IRQs perhaps?) which are
681 * better removed to avoid random or biased data.
684 double sum
= 0.0, sum2
= 0.0;
688 for(i
= 0; i
< n
; ++i
) {
690 sum2
+= cycles
[i
]*cycles
[i
];
694 std
= sqrtf((sum2
- n
*avg
*avg
)/n
);
698 for(i
= 0; i
< n
; ++i
) {
699 if(fabs(cycles
[i
] - avg
) <= 4.0*std
) {
710 write_tsv_row(fp
, blend
, mode
, type
, cycles_avg
, success
);
714 LLVMDumpModule(module
);
715 LLVMWriteBitcodeToFile(module
, "blend.bc");
716 fprintf(stderr
, "blend.bc written\n");
717 fprintf(stderr
, "Invoke as \"llc -o - blend.bc\"\n");
721 LLVMFreeMachineCodeForFunction(engine
, func
);
723 LLVMDisposeExecutionEngine(engine
);
725 LLVMDisposePassManager(pass
);
733 PIPE_BLENDFACTOR_ZERO
,
734 PIPE_BLENDFACTOR_ONE
,
735 PIPE_BLENDFACTOR_SRC_COLOR
,
736 PIPE_BLENDFACTOR_SRC_ALPHA
,
737 PIPE_BLENDFACTOR_DST_COLOR
,
738 PIPE_BLENDFACTOR_DST_ALPHA
,
739 PIPE_BLENDFACTOR_CONST_COLOR
,
740 PIPE_BLENDFACTOR_CONST_ALPHA
,
742 PIPE_BLENDFACTOR_SRC1_COLOR
,
743 PIPE_BLENDFACTOR_SRC1_ALPHA
,
745 PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
,
746 PIPE_BLENDFACTOR_INV_SRC_COLOR
,
747 PIPE_BLENDFACTOR_INV_SRC_ALPHA
,
748 PIPE_BLENDFACTOR_INV_DST_COLOR
,
749 PIPE_BLENDFACTOR_INV_DST_ALPHA
,
750 PIPE_BLENDFACTOR_INV_CONST_COLOR
,
751 PIPE_BLENDFACTOR_INV_CONST_ALPHA
,
753 PIPE_BLENDFACTOR_INV_SRC1_COLOR
,
754 PIPE_BLENDFACTOR_INV_SRC1_ALPHA
,
763 PIPE_BLEND_REVERSE_SUBTRACT
,
769 const struct lp_type blend_types
[] = {
770 /* float, fixed, sign, norm, width, len */
771 { TRUE
, FALSE
, FALSE
, TRUE
, 32, 4 }, /* f32 x 4 */
772 { FALSE
, FALSE
, FALSE
, TRUE
, 8, 16 }, /* u8n x 16 */
776 const unsigned num_funcs
= sizeof(blend_funcs
)/sizeof(blend_funcs
[0]);
777 const unsigned num_factors
= sizeof(blend_factors
)/sizeof(blend_factors
[0]);
778 const unsigned num_types
= sizeof(blend_types
)/sizeof(blend_types
[0]);
782 test_all(unsigned verbose
, FILE *fp
)
784 const unsigned *rgb_func
;
785 const unsigned *rgb_src_factor
;
786 const unsigned *rgb_dst_factor
;
787 const unsigned *alpha_func
;
788 const unsigned *alpha_src_factor
;
789 const unsigned *alpha_dst_factor
;
790 struct pipe_blend_state blend
;
791 enum vector_mode mode
;
792 const struct lp_type
*type
;
795 for(rgb_func
= blend_funcs
; rgb_func
< &blend_funcs
[num_funcs
]; ++rgb_func
) {
796 for(alpha_func
= blend_funcs
; alpha_func
< &blend_funcs
[num_funcs
]; ++alpha_func
) {
797 for(rgb_src_factor
= blend_factors
; rgb_src_factor
< &blend_factors
[num_factors
]; ++rgb_src_factor
) {
798 for(rgb_dst_factor
= blend_factors
; rgb_dst_factor
<= rgb_src_factor
; ++rgb_dst_factor
) {
799 for(alpha_src_factor
= blend_factors
; alpha_src_factor
< &blend_factors
[num_factors
]; ++alpha_src_factor
) {
800 for(alpha_dst_factor
= blend_factors
; alpha_dst_factor
<= alpha_src_factor
; ++alpha_dst_factor
) {
801 for(mode
= 0; mode
< 2; ++mode
) {
802 for(type
= blend_types
; type
< &blend_types
[num_types
]; ++type
) {
804 if(*rgb_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
||
805 *alpha_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
)
808 memset(&blend
, 0, sizeof blend
);
809 blend
.rt
[0].blend_enable
= 1;
810 blend
.rt
[0].rgb_func
= *rgb_func
;
811 blend
.rt
[0].rgb_src_factor
= *rgb_src_factor
;
812 blend
.rt
[0].rgb_dst_factor
= *rgb_dst_factor
;
813 blend
.rt
[0].alpha_func
= *alpha_func
;
814 blend
.rt
[0].alpha_src_factor
= *alpha_src_factor
;
815 blend
.rt
[0].alpha_dst_factor
= *alpha_dst_factor
;
816 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
818 if(!test_one(verbose
, fp
, &blend
, mode
, *type
))
835 test_some(unsigned verbose
, FILE *fp
, unsigned long n
)
837 const unsigned *rgb_func
;
838 const unsigned *rgb_src_factor
;
839 const unsigned *rgb_dst_factor
;
840 const unsigned *alpha_func
;
841 const unsigned *alpha_src_factor
;
842 const unsigned *alpha_dst_factor
;
843 struct pipe_blend_state blend
;
844 enum vector_mode mode
;
845 const struct lp_type
*type
;
849 for(i
= 0; i
< n
; ++i
) {
850 rgb_func
= &blend_funcs
[rand() % num_funcs
];
851 alpha_func
= &blend_funcs
[rand() % num_funcs
];
852 rgb_src_factor
= &blend_factors
[rand() % num_factors
];
853 alpha_src_factor
= &blend_factors
[rand() % num_factors
];
856 rgb_dst_factor
= &blend_factors
[rand() % num_factors
];
857 } while(*rgb_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
);
860 alpha_dst_factor
= &blend_factors
[rand() % num_factors
];
861 } while(*alpha_dst_factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
);
865 type
= &blend_types
[rand() % num_types
];
867 memset(&blend
, 0, sizeof blend
);
868 blend
.rt
[0].blend_enable
= 1;
869 blend
.rt
[0].rgb_func
= *rgb_func
;
870 blend
.rt
[0].rgb_src_factor
= *rgb_src_factor
;
871 blend
.rt
[0].rgb_dst_factor
= *rgb_dst_factor
;
872 blend
.rt
[0].alpha_func
= *alpha_func
;
873 blend
.rt
[0].alpha_src_factor
= *alpha_src_factor
;
874 blend
.rt
[0].alpha_dst_factor
= *alpha_dst_factor
;
875 blend
.rt
[0].colormask
= PIPE_MASK_RGBA
;
877 if(!test_one(verbose
, fp
, &blend
, mode
, *type
))