1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci/** 30bf215546Sopenharmony_ci * @file 31bf215546Sopenharmony_ci * Unit tests for blend LLVM IR generation 32bf215546Sopenharmony_ci * 33bf215546Sopenharmony_ci * @author Jose Fonseca <jfonseca@vmware.com> 34bf215546Sopenharmony_ci * 35bf215546Sopenharmony_ci * Blend computation code derived from code written by 36bf215546Sopenharmony_ci * @author Brian Paul <brian@vmware.com> 37bf215546Sopenharmony_ci */ 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci#include "util/u_memory.h" 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci#include "gallivm/lp_bld_init.h" 42bf215546Sopenharmony_ci#include "gallivm/lp_bld_type.h" 43bf215546Sopenharmony_ci#include "gallivm/lp_bld_debug.h" 44bf215546Sopenharmony_ci#include "lp_bld_blend.h" 45bf215546Sopenharmony_ci#include "lp_test.h" 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_citypedef void (*blend_test_ptr_t)(const void *src, const void *src1, 49bf215546Sopenharmony_ci const void *dst, const void *con, void *res); 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_civoid 53bf215546Sopenharmony_ciwrite_tsv_header(FILE *fp) 54bf215546Sopenharmony_ci{ 55bf215546Sopenharmony_ci fprintf(fp, 56bf215546Sopenharmony_ci "result\t" 57bf215546Sopenharmony_ci "cycles_per_channel\t" 58bf215546Sopenharmony_ci "type\t" 59bf215546Sopenharmony_ci "sep_func\t" 60bf215546Sopenharmony_ci "sep_src_factor\t" 61bf215546Sopenharmony_ci "sep_dst_factor\t" 62bf215546Sopenharmony_ci "rgb_func\t" 63bf215546Sopenharmony_ci "rgb_src_factor\t" 64bf215546Sopenharmony_ci "rgb_dst_factor\t" 65bf215546Sopenharmony_ci "alpha_func\t" 66bf215546Sopenharmony_ci "alpha_src_factor\t" 67bf215546Sopenharmony_ci "alpha_dst_factor\n"); 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci fflush(fp); 70bf215546Sopenharmony_ci} 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_cistatic void 74bf215546Sopenharmony_ciwrite_tsv_row(FILE *fp, 75bf215546Sopenharmony_ci const struct pipe_blend_state *blend, 76bf215546Sopenharmony_ci struct lp_type type, 77bf215546Sopenharmony_ci double cycles, 78bf215546Sopenharmony_ci boolean success) 79bf215546Sopenharmony_ci{ 80bf215546Sopenharmony_ci fprintf(fp, "%s\t", success ? "pass" : "fail"); 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_ci fprintf(fp, "%.1f\t", cycles / type.length); 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_ci fprintf(fp, "%s%u%sx%u\t", 85bf215546Sopenharmony_ci type.floating ? "f" : (type.fixed ? "h" : (type.sign ? "s" : "u")), 86bf215546Sopenharmony_ci type.width, 87bf215546Sopenharmony_ci type.norm ? "n" : "", 88bf215546Sopenharmony_ci type.length); 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_ci fprintf(fp, 91bf215546Sopenharmony_ci "%s\t%s\t%s\t", 92bf215546Sopenharmony_ci blend->rt[0].rgb_func != blend->rt[0].alpha_func ? "true" : "false", 93bf215546Sopenharmony_ci blend->rt[0].rgb_src_factor != blend->rt[0].alpha_src_factor ? "true" : "false", 94bf215546Sopenharmony_ci blend->rt[0].rgb_dst_factor != blend->rt[0].alpha_dst_factor ? "true" : "false"); 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci fprintf(fp, 97bf215546Sopenharmony_ci "%s\t%s\t%s\t%s\t%s\t%s\n", 98bf215546Sopenharmony_ci util_str_blend_func(blend->rt[0].rgb_func, TRUE), 99bf215546Sopenharmony_ci util_str_blend_factor(blend->rt[0].rgb_src_factor, TRUE), 100bf215546Sopenharmony_ci util_str_blend_factor(blend->rt[0].rgb_dst_factor, TRUE), 101bf215546Sopenharmony_ci util_str_blend_func(blend->rt[0].alpha_func, TRUE), 102bf215546Sopenharmony_ci util_str_blend_factor(blend->rt[0].alpha_src_factor, TRUE), 103bf215546Sopenharmony_ci util_str_blend_factor(blend->rt[0].alpha_dst_factor, TRUE)); 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci fflush(fp); 106bf215546Sopenharmony_ci} 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci 109bf215546Sopenharmony_cistatic void 110bf215546Sopenharmony_cidump_blend_type(FILE *fp, 111bf215546Sopenharmony_ci const struct pipe_blend_state *blend, 112bf215546Sopenharmony_ci struct lp_type type) 113bf215546Sopenharmony_ci{ 114bf215546Sopenharmony_ci fprintf(fp, " type=%s%u%sx%u", 115bf215546Sopenharmony_ci type.floating ? "f" : (type.fixed ? "h" : (type.sign ? "s" : "u")), 116bf215546Sopenharmony_ci type.width, 117bf215546Sopenharmony_ci type.norm ? "n" : "", 118bf215546Sopenharmony_ci type.length); 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_ci fprintf(fp, 121bf215546Sopenharmony_ci " %s=%s %s=%s %s=%s %s=%s %s=%s %s=%s", 122bf215546Sopenharmony_ci "rgb_func", util_str_blend_func(blend->rt[0].rgb_func, TRUE), 123bf215546Sopenharmony_ci "rgb_src_factor", util_str_blend_factor(blend->rt[0].rgb_src_factor, TRUE), 124bf215546Sopenharmony_ci "rgb_dst_factor", util_str_blend_factor(blend->rt[0].rgb_dst_factor, TRUE), 125bf215546Sopenharmony_ci "alpha_func", util_str_blend_func(blend->rt[0].alpha_func, TRUE), 126bf215546Sopenharmony_ci "alpha_src_factor", util_str_blend_factor(blend->rt[0].alpha_src_factor, TRUE), 127bf215546Sopenharmony_ci "alpha_dst_factor", util_str_blend_factor(blend->rt[0].alpha_dst_factor, TRUE)); 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_ci fprintf(fp, " ...\n"); 130bf215546Sopenharmony_ci fflush(fp); 131bf215546Sopenharmony_ci} 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ci 134bf215546Sopenharmony_cistatic LLVMValueRef 135bf215546Sopenharmony_ciadd_blend_test(struct gallivm_state *gallivm, 136bf215546Sopenharmony_ci const struct pipe_blend_state *blend, 137bf215546Sopenharmony_ci struct lp_type type) 138bf215546Sopenharmony_ci{ 139bf215546Sopenharmony_ci LLVMModuleRef module = gallivm->module; 140bf215546Sopenharmony_ci LLVMContextRef context = gallivm->context; 141bf215546Sopenharmony_ci LLVMTypeRef vec_type; 142bf215546Sopenharmony_ci LLVMTypeRef args[5]; 143bf215546Sopenharmony_ci LLVMValueRef func; 144bf215546Sopenharmony_ci LLVMValueRef src_ptr; 145bf215546Sopenharmony_ci LLVMValueRef src1_ptr; 146bf215546Sopenharmony_ci LLVMValueRef dst_ptr; 147bf215546Sopenharmony_ci LLVMValueRef const_ptr; 148bf215546Sopenharmony_ci LLVMValueRef res_ptr; 149bf215546Sopenharmony_ci LLVMBasicBlockRef block; 150bf215546Sopenharmony_ci LLVMBuilderRef builder; 151bf215546Sopenharmony_ci const enum pipe_format format = PIPE_FORMAT_R8G8B8A8_UNORM; 152bf215546Sopenharmony_ci const unsigned rt = 0; 153bf215546Sopenharmony_ci const unsigned char swizzle[4] = { 0, 1, 2, 3 }; 154bf215546Sopenharmony_ci LLVMValueRef src; 155bf215546Sopenharmony_ci LLVMValueRef src1; 156bf215546Sopenharmony_ci LLVMValueRef dst; 157bf215546Sopenharmony_ci LLVMValueRef con; 158bf215546Sopenharmony_ci LLVMValueRef res; 159bf215546Sopenharmony_ci 160bf215546Sopenharmony_ci vec_type = lp_build_vec_type(gallivm, type); 161bf215546Sopenharmony_ci 162bf215546Sopenharmony_ci args[4] = args[3] = args[2] = args[1] = args[0] = LLVMPointerType(vec_type, 0); 163bf215546Sopenharmony_ci func = LLVMAddFunction(module, "test", LLVMFunctionType(LLVMVoidTypeInContext(context), args, 5, 0)); 164bf215546Sopenharmony_ci LLVMSetFunctionCallConv(func, LLVMCCallConv); 165bf215546Sopenharmony_ci src_ptr = LLVMGetParam(func, 0); 166bf215546Sopenharmony_ci src1_ptr = LLVMGetParam(func, 1); 167bf215546Sopenharmony_ci dst_ptr = LLVMGetParam(func, 2); 168bf215546Sopenharmony_ci const_ptr = LLVMGetParam(func, 3); 169bf215546Sopenharmony_ci res_ptr = LLVMGetParam(func, 4); 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci block = LLVMAppendBasicBlockInContext(context, func, "entry"); 172bf215546Sopenharmony_ci builder = gallivm->builder; 173bf215546Sopenharmony_ci LLVMPositionBuilderAtEnd(builder, block); 174bf215546Sopenharmony_ci 175bf215546Sopenharmony_ci src = LLVMBuildLoad(builder, src_ptr, "src"); 176bf215546Sopenharmony_ci src1 = LLVMBuildLoad(builder, src1_ptr, "src1"); 177bf215546Sopenharmony_ci dst = LLVMBuildLoad(builder, dst_ptr, "dst"); 178bf215546Sopenharmony_ci con = LLVMBuildLoad(builder, const_ptr, "const"); 179bf215546Sopenharmony_ci 180bf215546Sopenharmony_ci res = lp_build_blend_aos(gallivm, blend, format, type, rt, src, NULL, 181bf215546Sopenharmony_ci src1, NULL, dst, NULL, con, NULL, swizzle, 4); 182bf215546Sopenharmony_ci 183bf215546Sopenharmony_ci lp_build_name(res, "res"); 184bf215546Sopenharmony_ci 185bf215546Sopenharmony_ci LLVMBuildStore(builder, res, res_ptr); 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci LLVMBuildRetVoid(builder); 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ci gallivm_verify_function(gallivm, func); 190bf215546Sopenharmony_ci 191bf215546Sopenharmony_ci return func; 192bf215546Sopenharmony_ci} 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_cistatic void 196bf215546Sopenharmony_cicompute_blend_ref_term(unsigned rgb_factor, 197bf215546Sopenharmony_ci unsigned alpha_factor, 198bf215546Sopenharmony_ci const double *factor, 199bf215546Sopenharmony_ci const double *src, 200bf215546Sopenharmony_ci const double *src1, 201bf215546Sopenharmony_ci const double *dst, 202bf215546Sopenharmony_ci const double *con, 203bf215546Sopenharmony_ci double *term) 204bf215546Sopenharmony_ci{ 205bf215546Sopenharmony_ci double temp; 206bf215546Sopenharmony_ci 207bf215546Sopenharmony_ci switch (rgb_factor) { 208bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_ONE: 209bf215546Sopenharmony_ci term[0] = factor[0]; /* R */ 210bf215546Sopenharmony_ci term[1] = factor[1]; /* G */ 211bf215546Sopenharmony_ci term[2] = factor[2]; /* B */ 212bf215546Sopenharmony_ci break; 213bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_COLOR: 214bf215546Sopenharmony_ci term[0] = factor[0] * src[0]; /* R */ 215bf215546Sopenharmony_ci term[1] = factor[1] * src[1]; /* G */ 216bf215546Sopenharmony_ci term[2] = factor[2] * src[2]; /* B */ 217bf215546Sopenharmony_ci break; 218bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_ALPHA: 219bf215546Sopenharmony_ci term[0] = factor[0] * src[3]; /* R */ 220bf215546Sopenharmony_ci term[1] = factor[1] * src[3]; /* G */ 221bf215546Sopenharmony_ci term[2] = factor[2] * src[3]; /* B */ 222bf215546Sopenharmony_ci break; 223bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_DST_COLOR: 224bf215546Sopenharmony_ci term[0] = factor[0] * dst[0]; /* R */ 225bf215546Sopenharmony_ci term[1] = factor[1] * dst[1]; /* G */ 226bf215546Sopenharmony_ci term[2] = factor[2] * dst[2]; /* B */ 227bf215546Sopenharmony_ci break; 228bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_DST_ALPHA: 229bf215546Sopenharmony_ci term[0] = factor[0] * dst[3]; /* R */ 230bf215546Sopenharmony_ci term[1] = factor[1] * dst[3]; /* G */ 231bf215546Sopenharmony_ci term[2] = factor[2] * dst[3]; /* B */ 232bf215546Sopenharmony_ci break; 233bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: 234bf215546Sopenharmony_ci temp = MIN2(src[3], 1.0f - dst[3]); 235bf215546Sopenharmony_ci term[0] = factor[0] * temp; /* R */ 236bf215546Sopenharmony_ci term[1] = factor[1] * temp; /* G */ 237bf215546Sopenharmony_ci term[2] = factor[2] * temp; /* B */ 238bf215546Sopenharmony_ci break; 239bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_CONST_COLOR: 240bf215546Sopenharmony_ci term[0] = factor[0] * con[0]; /* R */ 241bf215546Sopenharmony_ci term[1] = factor[1] * con[1]; /* G */ 242bf215546Sopenharmony_ci term[2] = factor[2] * con[2]; /* B */ 243bf215546Sopenharmony_ci break; 244bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_CONST_ALPHA: 245bf215546Sopenharmony_ci term[0] = factor[0] * con[3]; /* R */ 246bf215546Sopenharmony_ci term[1] = factor[1] * con[3]; /* G */ 247bf215546Sopenharmony_ci term[2] = factor[2] * con[3]; /* B */ 248bf215546Sopenharmony_ci break; 249bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC1_COLOR: 250bf215546Sopenharmony_ci term[0] = factor[0] * src1[0]; /* R */ 251bf215546Sopenharmony_ci term[1] = factor[1] * src1[1]; /* G */ 252bf215546Sopenharmony_ci term[2] = factor[2] * src1[2]; /* B */ 253bf215546Sopenharmony_ci break; 254bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC1_ALPHA: 255bf215546Sopenharmony_ci term[0] = factor[0] * src1[3]; /* R */ 256bf215546Sopenharmony_ci term[1] = factor[1] * src1[3]; /* G */ 257bf215546Sopenharmony_ci term[2] = factor[2] * src1[3]; /* B */ 258bf215546Sopenharmony_ci break; 259bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_ZERO: 260bf215546Sopenharmony_ci term[0] = 0.0f; /* R */ 261bf215546Sopenharmony_ci term[1] = 0.0f; /* G */ 262bf215546Sopenharmony_ci term[2] = 0.0f; /* B */ 263bf215546Sopenharmony_ci break; 264bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC_COLOR: 265bf215546Sopenharmony_ci term[0] = factor[0] * (1.0f - src[0]); /* R */ 266bf215546Sopenharmony_ci term[1] = factor[1] * (1.0f - src[1]); /* G */ 267bf215546Sopenharmony_ci term[2] = factor[2] * (1.0f - src[2]); /* B */ 268bf215546Sopenharmony_ci break; 269bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC_ALPHA: 270bf215546Sopenharmony_ci term[0] = factor[0] * (1.0f - src[3]); /* R */ 271bf215546Sopenharmony_ci term[1] = factor[1] * (1.0f - src[3]); /* G */ 272bf215546Sopenharmony_ci term[2] = factor[2] * (1.0f - src[3]); /* B */ 273bf215546Sopenharmony_ci break; 274bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_DST_ALPHA: 275bf215546Sopenharmony_ci term[0] = factor[0] * (1.0f - dst[3]); /* R */ 276bf215546Sopenharmony_ci term[1] = factor[1] * (1.0f - dst[3]); /* G */ 277bf215546Sopenharmony_ci term[2] = factor[2] * (1.0f - dst[3]); /* B */ 278bf215546Sopenharmony_ci break; 279bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_DST_COLOR: 280bf215546Sopenharmony_ci term[0] = factor[0] * (1.0f - dst[0]); /* R */ 281bf215546Sopenharmony_ci term[1] = factor[1] * (1.0f - dst[1]); /* G */ 282bf215546Sopenharmony_ci term[2] = factor[2] * (1.0f - dst[2]); /* B */ 283bf215546Sopenharmony_ci break; 284bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_CONST_COLOR: 285bf215546Sopenharmony_ci term[0] = factor[0] * (1.0f - con[0]); /* R */ 286bf215546Sopenharmony_ci term[1] = factor[1] * (1.0f - con[1]); /* G */ 287bf215546Sopenharmony_ci term[2] = factor[2] * (1.0f - con[2]); /* B */ 288bf215546Sopenharmony_ci break; 289bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_CONST_ALPHA: 290bf215546Sopenharmony_ci term[0] = factor[0] * (1.0f - con[3]); /* R */ 291bf215546Sopenharmony_ci term[1] = factor[1] * (1.0f - con[3]); /* G */ 292bf215546Sopenharmony_ci term[2] = factor[2] * (1.0f - con[3]); /* B */ 293bf215546Sopenharmony_ci break; 294bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC1_COLOR: 295bf215546Sopenharmony_ci term[0] = factor[0] * (1.0f - src1[0]); /* R */ 296bf215546Sopenharmony_ci term[1] = factor[1] * (1.0f - src1[1]); /* G */ 297bf215546Sopenharmony_ci term[2] = factor[2] * (1.0f - src1[2]); /* B */ 298bf215546Sopenharmony_ci break; 299bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: 300bf215546Sopenharmony_ci term[0] = factor[0] * (1.0f - src1[3]); /* R */ 301bf215546Sopenharmony_ci term[1] = factor[1] * (1.0f - src1[3]); /* G */ 302bf215546Sopenharmony_ci term[2] = factor[2] * (1.0f - src1[3]); /* B */ 303bf215546Sopenharmony_ci break; 304bf215546Sopenharmony_ci default: 305bf215546Sopenharmony_ci assert(0); 306bf215546Sopenharmony_ci } 307bf215546Sopenharmony_ci 308bf215546Sopenharmony_ci /* 309bf215546Sopenharmony_ci * Compute src/first term A 310bf215546Sopenharmony_ci */ 311bf215546Sopenharmony_ci switch (alpha_factor) { 312bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_ONE: 313bf215546Sopenharmony_ci term[3] = factor[3]; /* A */ 314bf215546Sopenharmony_ci break; 315bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_COLOR: 316bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_ALPHA: 317bf215546Sopenharmony_ci term[3] = factor[3] * src[3]; /* A */ 318bf215546Sopenharmony_ci break; 319bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_DST_COLOR: 320bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_DST_ALPHA: 321bf215546Sopenharmony_ci term[3] = factor[3] * dst[3]; /* A */ 322bf215546Sopenharmony_ci break; 323bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: 324bf215546Sopenharmony_ci term[3] = src[3]; /* A */ 325bf215546Sopenharmony_ci break; 326bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_CONST_COLOR: 327bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_CONST_ALPHA: 328bf215546Sopenharmony_ci term[3] = factor[3] * con[3]; /* A */ 329bf215546Sopenharmony_ci break; 330bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC1_COLOR: 331bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC1_ALPHA: 332bf215546Sopenharmony_ci term[3] = factor[3] * src1[3]; /* A */ 333bf215546Sopenharmony_ci break; 334bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_ZERO: 335bf215546Sopenharmony_ci term[3] = 0.0f; /* A */ 336bf215546Sopenharmony_ci break; 337bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC_COLOR: 338bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC_ALPHA: 339bf215546Sopenharmony_ci term[3] = factor[3] * (1.0f - src[3]); /* A */ 340bf215546Sopenharmony_ci break; 341bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_DST_COLOR: 342bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_DST_ALPHA: 343bf215546Sopenharmony_ci term[3] = factor[3] * (1.0f - dst[3]); /* A */ 344bf215546Sopenharmony_ci break; 345bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_CONST_COLOR: 346bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_CONST_ALPHA: 347bf215546Sopenharmony_ci term[3] = factor[3] * (1.0f - con[3]); 348bf215546Sopenharmony_ci break; 349bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC1_COLOR: 350bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: 351bf215546Sopenharmony_ci term[3] = factor[3] * (1.0f - src1[3]); /* A */ 352bf215546Sopenharmony_ci break; 353bf215546Sopenharmony_ci default: 354bf215546Sopenharmony_ci assert(0); 355bf215546Sopenharmony_ci } 356bf215546Sopenharmony_ci} 357bf215546Sopenharmony_ci 358bf215546Sopenharmony_ci 359bf215546Sopenharmony_cistatic void 360bf215546Sopenharmony_cicompute_blend_ref(const struct pipe_blend_state *blend, 361bf215546Sopenharmony_ci const double *src, 362bf215546Sopenharmony_ci const double *src1, 363bf215546Sopenharmony_ci const double *dst, 364bf215546Sopenharmony_ci const double *con, 365bf215546Sopenharmony_ci double *res) 366bf215546Sopenharmony_ci{ 367bf215546Sopenharmony_ci double src_term[4]; 368bf215546Sopenharmony_ci double dst_term[4]; 369bf215546Sopenharmony_ci 370bf215546Sopenharmony_ci compute_blend_ref_term(blend->rt[0].rgb_src_factor, blend->rt[0].alpha_src_factor, 371bf215546Sopenharmony_ci src, src, src1, dst, con, src_term); 372bf215546Sopenharmony_ci compute_blend_ref_term(blend->rt[0].rgb_dst_factor, blend->rt[0].alpha_dst_factor, 373bf215546Sopenharmony_ci dst, src, src1, dst, con, dst_term); 374bf215546Sopenharmony_ci 375bf215546Sopenharmony_ci /* 376bf215546Sopenharmony_ci * Combine RGB terms 377bf215546Sopenharmony_ci */ 378bf215546Sopenharmony_ci switch (blend->rt[0].rgb_func) { 379bf215546Sopenharmony_ci case PIPE_BLEND_ADD: 380bf215546Sopenharmony_ci res[0] = src_term[0] + dst_term[0]; /* R */ 381bf215546Sopenharmony_ci res[1] = src_term[1] + dst_term[1]; /* G */ 382bf215546Sopenharmony_ci res[2] = src_term[2] + dst_term[2]; /* B */ 383bf215546Sopenharmony_ci break; 384bf215546Sopenharmony_ci case PIPE_BLEND_SUBTRACT: 385bf215546Sopenharmony_ci res[0] = src_term[0] - dst_term[0]; /* R */ 386bf215546Sopenharmony_ci res[1] = src_term[1] - dst_term[1]; /* G */ 387bf215546Sopenharmony_ci res[2] = src_term[2] - dst_term[2]; /* B */ 388bf215546Sopenharmony_ci break; 389bf215546Sopenharmony_ci case PIPE_BLEND_REVERSE_SUBTRACT: 390bf215546Sopenharmony_ci res[0] = dst_term[0] - src_term[0]; /* R */ 391bf215546Sopenharmony_ci res[1] = dst_term[1] - src_term[1]; /* G */ 392bf215546Sopenharmony_ci res[2] = dst_term[2] - src_term[2]; /* B */ 393bf215546Sopenharmony_ci break; 394bf215546Sopenharmony_ci case PIPE_BLEND_MIN: 395bf215546Sopenharmony_ci res[0] = MIN2(src_term[0], dst_term[0]); /* R */ 396bf215546Sopenharmony_ci res[1] = MIN2(src_term[1], dst_term[1]); /* G */ 397bf215546Sopenharmony_ci res[2] = MIN2(src_term[2], dst_term[2]); /* B */ 398bf215546Sopenharmony_ci break; 399bf215546Sopenharmony_ci case PIPE_BLEND_MAX: 400bf215546Sopenharmony_ci res[0] = MAX2(src_term[0], dst_term[0]); /* R */ 401bf215546Sopenharmony_ci res[1] = MAX2(src_term[1], dst_term[1]); /* G */ 402bf215546Sopenharmony_ci res[2] = MAX2(src_term[2], dst_term[2]); /* B */ 403bf215546Sopenharmony_ci break; 404bf215546Sopenharmony_ci default: 405bf215546Sopenharmony_ci assert(0); 406bf215546Sopenharmony_ci } 407bf215546Sopenharmony_ci 408bf215546Sopenharmony_ci /* 409bf215546Sopenharmony_ci * Combine A terms 410bf215546Sopenharmony_ci */ 411bf215546Sopenharmony_ci switch (blend->rt[0].alpha_func) { 412bf215546Sopenharmony_ci case PIPE_BLEND_ADD: 413bf215546Sopenharmony_ci res[3] = src_term[3] + dst_term[3]; /* A */ 414bf215546Sopenharmony_ci break; 415bf215546Sopenharmony_ci case PIPE_BLEND_SUBTRACT: 416bf215546Sopenharmony_ci res[3] = src_term[3] - dst_term[3]; /* A */ 417bf215546Sopenharmony_ci break; 418bf215546Sopenharmony_ci case PIPE_BLEND_REVERSE_SUBTRACT: 419bf215546Sopenharmony_ci res[3] = dst_term[3] - src_term[3]; /* A */ 420bf215546Sopenharmony_ci break; 421bf215546Sopenharmony_ci case PIPE_BLEND_MIN: 422bf215546Sopenharmony_ci res[3] = MIN2(src_term[3], dst_term[3]); /* A */ 423bf215546Sopenharmony_ci break; 424bf215546Sopenharmony_ci case PIPE_BLEND_MAX: 425bf215546Sopenharmony_ci res[3] = MAX2(src_term[3], dst_term[3]); /* A */ 426bf215546Sopenharmony_ci break; 427bf215546Sopenharmony_ci default: 428bf215546Sopenharmony_ci assert(0); 429bf215546Sopenharmony_ci } 430bf215546Sopenharmony_ci} 431bf215546Sopenharmony_ci 432bf215546Sopenharmony_ci 433bf215546Sopenharmony_ciPIPE_ALIGN_STACK 434bf215546Sopenharmony_cistatic boolean 435bf215546Sopenharmony_citest_one(unsigned verbose, 436bf215546Sopenharmony_ci FILE *fp, 437bf215546Sopenharmony_ci const struct pipe_blend_state *blend, 438bf215546Sopenharmony_ci struct lp_type type) 439bf215546Sopenharmony_ci{ 440bf215546Sopenharmony_ci LLVMContextRef context; 441bf215546Sopenharmony_ci struct gallivm_state *gallivm; 442bf215546Sopenharmony_ci LLVMValueRef func = NULL; 443bf215546Sopenharmony_ci blend_test_ptr_t blend_test_ptr; 444bf215546Sopenharmony_ci boolean success; 445bf215546Sopenharmony_ci const unsigned n = LP_TEST_NUM_SAMPLES; 446bf215546Sopenharmony_ci int64_t cycles[LP_TEST_NUM_SAMPLES]; 447bf215546Sopenharmony_ci double cycles_avg = 0.0; 448bf215546Sopenharmony_ci unsigned i, j; 449bf215546Sopenharmony_ci const unsigned stride = lp_type_width(type)/8; 450bf215546Sopenharmony_ci 451bf215546Sopenharmony_ci if(verbose >= 1) 452bf215546Sopenharmony_ci dump_blend_type(stdout, blend, type); 453bf215546Sopenharmony_ci 454bf215546Sopenharmony_ci context = LLVMContextCreate(); 455bf215546Sopenharmony_ci#if LLVM_VERSION_MAJOR >= 15 456bf215546Sopenharmony_ci LLVMContextSetOpaquePointers(context, false); 457bf215546Sopenharmony_ci#endif 458bf215546Sopenharmony_ci gallivm = gallivm_create("test_module", context, NULL); 459bf215546Sopenharmony_ci 460bf215546Sopenharmony_ci func = add_blend_test(gallivm, blend, type); 461bf215546Sopenharmony_ci 462bf215546Sopenharmony_ci gallivm_compile_module(gallivm); 463bf215546Sopenharmony_ci 464bf215546Sopenharmony_ci blend_test_ptr = (blend_test_ptr_t)gallivm_jit_function(gallivm, func); 465bf215546Sopenharmony_ci 466bf215546Sopenharmony_ci gallivm_free_ir(gallivm); 467bf215546Sopenharmony_ci 468bf215546Sopenharmony_ci success = TRUE; 469bf215546Sopenharmony_ci 470bf215546Sopenharmony_ci { 471bf215546Sopenharmony_ci uint8_t *src, *src1, *dst, *con, *res, *ref; 472bf215546Sopenharmony_ci src = align_malloc(stride, stride); 473bf215546Sopenharmony_ci src1 = align_malloc(stride, stride); 474bf215546Sopenharmony_ci dst = align_malloc(stride, stride); 475bf215546Sopenharmony_ci con = align_malloc(stride, stride); 476bf215546Sopenharmony_ci res = align_malloc(stride, stride); 477bf215546Sopenharmony_ci ref = align_malloc(stride, stride); 478bf215546Sopenharmony_ci 479bf215546Sopenharmony_ci for(i = 0; i < n && success; ++i) { 480bf215546Sopenharmony_ci int64_t start_counter = 0; 481bf215546Sopenharmony_ci int64_t end_counter = 0; 482bf215546Sopenharmony_ci 483bf215546Sopenharmony_ci random_vec(type, src); 484bf215546Sopenharmony_ci random_vec(type, src1); 485bf215546Sopenharmony_ci random_vec(type, dst); 486bf215546Sopenharmony_ci random_vec(type, con); 487bf215546Sopenharmony_ci 488bf215546Sopenharmony_ci { 489bf215546Sopenharmony_ci double fsrc[LP_MAX_VECTOR_LENGTH]; 490bf215546Sopenharmony_ci double fsrc1[LP_MAX_VECTOR_LENGTH]; 491bf215546Sopenharmony_ci double fdst[LP_MAX_VECTOR_LENGTH]; 492bf215546Sopenharmony_ci double fcon[LP_MAX_VECTOR_LENGTH]; 493bf215546Sopenharmony_ci double fref[LP_MAX_VECTOR_LENGTH]; 494bf215546Sopenharmony_ci 495bf215546Sopenharmony_ci read_vec(type, src, fsrc); 496bf215546Sopenharmony_ci read_vec(type, src1, fsrc1); 497bf215546Sopenharmony_ci read_vec(type, dst, fdst); 498bf215546Sopenharmony_ci read_vec(type, con, fcon); 499bf215546Sopenharmony_ci 500bf215546Sopenharmony_ci for(j = 0; j < type.length; j += 4) 501bf215546Sopenharmony_ci compute_blend_ref(blend, fsrc + j, fsrc1 + j, fdst + j, fcon + j, fref + j); 502bf215546Sopenharmony_ci 503bf215546Sopenharmony_ci write_vec(type, ref, fref); 504bf215546Sopenharmony_ci } 505bf215546Sopenharmony_ci 506bf215546Sopenharmony_ci start_counter = rdtsc(); 507bf215546Sopenharmony_ci blend_test_ptr(src, src1, dst, con, res); 508bf215546Sopenharmony_ci end_counter = rdtsc(); 509bf215546Sopenharmony_ci 510bf215546Sopenharmony_ci cycles[i] = end_counter - start_counter; 511bf215546Sopenharmony_ci 512bf215546Sopenharmony_ci if(!compare_vec(type, res, ref)) { 513bf215546Sopenharmony_ci success = FALSE; 514bf215546Sopenharmony_ci 515bf215546Sopenharmony_ci if(verbose < 1) 516bf215546Sopenharmony_ci dump_blend_type(stderr, blend, type); 517bf215546Sopenharmony_ci fprintf(stderr, "MISMATCH\n"); 518bf215546Sopenharmony_ci 519bf215546Sopenharmony_ci fprintf(stderr, " Src: "); 520bf215546Sopenharmony_ci dump_vec(stderr, type, src); 521bf215546Sopenharmony_ci fprintf(stderr, "\n"); 522bf215546Sopenharmony_ci 523bf215546Sopenharmony_ci fprintf(stderr, " Src1: "); 524bf215546Sopenharmony_ci dump_vec(stderr, type, src1); 525bf215546Sopenharmony_ci fprintf(stderr, "\n"); 526bf215546Sopenharmony_ci 527bf215546Sopenharmony_ci fprintf(stderr, " Dst: "); 528bf215546Sopenharmony_ci dump_vec(stderr, type, dst); 529bf215546Sopenharmony_ci fprintf(stderr, "\n"); 530bf215546Sopenharmony_ci 531bf215546Sopenharmony_ci fprintf(stderr, " Con: "); 532bf215546Sopenharmony_ci dump_vec(stderr, type, con); 533bf215546Sopenharmony_ci fprintf(stderr, "\n"); 534bf215546Sopenharmony_ci 535bf215546Sopenharmony_ci fprintf(stderr, " Res: "); 536bf215546Sopenharmony_ci dump_vec(stderr, type, res); 537bf215546Sopenharmony_ci fprintf(stderr, "\n"); 538bf215546Sopenharmony_ci 539bf215546Sopenharmony_ci fprintf(stderr, " Ref: "); 540bf215546Sopenharmony_ci dump_vec(stderr, type, ref); 541bf215546Sopenharmony_ci fprintf(stderr, "\n"); 542bf215546Sopenharmony_ci } 543bf215546Sopenharmony_ci } 544bf215546Sopenharmony_ci align_free(src); 545bf215546Sopenharmony_ci align_free(src1); 546bf215546Sopenharmony_ci align_free(dst); 547bf215546Sopenharmony_ci align_free(con); 548bf215546Sopenharmony_ci align_free(res); 549bf215546Sopenharmony_ci align_free(ref); 550bf215546Sopenharmony_ci } 551bf215546Sopenharmony_ci 552bf215546Sopenharmony_ci /* 553bf215546Sopenharmony_ci * Unfortunately the output of cycle counter is not very reliable as it comes 554bf215546Sopenharmony_ci * -- sometimes we get outliers (due IRQs perhaps?) which are 555bf215546Sopenharmony_ci * better removed to avoid random or biased data. 556bf215546Sopenharmony_ci */ 557bf215546Sopenharmony_ci { 558bf215546Sopenharmony_ci double sum = 0.0, sum2 = 0.0; 559bf215546Sopenharmony_ci double avg, std; 560bf215546Sopenharmony_ci unsigned m; 561bf215546Sopenharmony_ci 562bf215546Sopenharmony_ci for(i = 0; i < n; ++i) { 563bf215546Sopenharmony_ci sum += cycles[i]; 564bf215546Sopenharmony_ci sum2 += cycles[i]*cycles[i]; 565bf215546Sopenharmony_ci } 566bf215546Sopenharmony_ci 567bf215546Sopenharmony_ci avg = sum/n; 568bf215546Sopenharmony_ci std = sqrtf((sum2 - n*avg*avg)/n); 569bf215546Sopenharmony_ci 570bf215546Sopenharmony_ci m = 0; 571bf215546Sopenharmony_ci sum = 0.0; 572bf215546Sopenharmony_ci for(i = 0; i < n; ++i) { 573bf215546Sopenharmony_ci if(fabs(cycles[i] - avg) <= 4.0*std) { 574bf215546Sopenharmony_ci sum += cycles[i]; 575bf215546Sopenharmony_ci ++m; 576bf215546Sopenharmony_ci } 577bf215546Sopenharmony_ci } 578bf215546Sopenharmony_ci 579bf215546Sopenharmony_ci cycles_avg = sum/m; 580bf215546Sopenharmony_ci 581bf215546Sopenharmony_ci } 582bf215546Sopenharmony_ci 583bf215546Sopenharmony_ci if(fp) 584bf215546Sopenharmony_ci write_tsv_row(fp, blend, type, cycles_avg, success); 585bf215546Sopenharmony_ci 586bf215546Sopenharmony_ci gallivm_destroy(gallivm); 587bf215546Sopenharmony_ci LLVMContextDispose(context); 588bf215546Sopenharmony_ci 589bf215546Sopenharmony_ci return success; 590bf215546Sopenharmony_ci} 591bf215546Sopenharmony_ci 592bf215546Sopenharmony_ci 593bf215546Sopenharmony_ciconst unsigned 594bf215546Sopenharmony_ciblend_factors[] = { 595bf215546Sopenharmony_ci PIPE_BLENDFACTOR_ZERO, 596bf215546Sopenharmony_ci PIPE_BLENDFACTOR_ONE, 597bf215546Sopenharmony_ci PIPE_BLENDFACTOR_SRC_COLOR, 598bf215546Sopenharmony_ci PIPE_BLENDFACTOR_SRC_ALPHA, 599bf215546Sopenharmony_ci PIPE_BLENDFACTOR_DST_COLOR, 600bf215546Sopenharmony_ci PIPE_BLENDFACTOR_DST_ALPHA, 601bf215546Sopenharmony_ci PIPE_BLENDFACTOR_CONST_COLOR, 602bf215546Sopenharmony_ci PIPE_BLENDFACTOR_CONST_ALPHA, 603bf215546Sopenharmony_ci PIPE_BLENDFACTOR_SRC1_COLOR, 604bf215546Sopenharmony_ci PIPE_BLENDFACTOR_SRC1_ALPHA, 605bf215546Sopenharmony_ci PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE, 606bf215546Sopenharmony_ci PIPE_BLENDFACTOR_INV_SRC_COLOR, 607bf215546Sopenharmony_ci PIPE_BLENDFACTOR_INV_SRC_ALPHA, 608bf215546Sopenharmony_ci PIPE_BLENDFACTOR_INV_DST_COLOR, 609bf215546Sopenharmony_ci PIPE_BLENDFACTOR_INV_DST_ALPHA, 610bf215546Sopenharmony_ci PIPE_BLENDFACTOR_INV_CONST_COLOR, 611bf215546Sopenharmony_ci PIPE_BLENDFACTOR_INV_CONST_ALPHA, 612bf215546Sopenharmony_ci PIPE_BLENDFACTOR_INV_SRC1_COLOR, 613bf215546Sopenharmony_ci PIPE_BLENDFACTOR_INV_SRC1_ALPHA, 614bf215546Sopenharmony_ci}; 615bf215546Sopenharmony_ci 616bf215546Sopenharmony_ci 617bf215546Sopenharmony_ciconst unsigned 618bf215546Sopenharmony_ciblend_funcs[] = { 619bf215546Sopenharmony_ci PIPE_BLEND_ADD, 620bf215546Sopenharmony_ci PIPE_BLEND_SUBTRACT, 621bf215546Sopenharmony_ci PIPE_BLEND_REVERSE_SUBTRACT, 622bf215546Sopenharmony_ci PIPE_BLEND_MIN, 623bf215546Sopenharmony_ci PIPE_BLEND_MAX 624bf215546Sopenharmony_ci}; 625bf215546Sopenharmony_ci 626bf215546Sopenharmony_ci 627bf215546Sopenharmony_ciconst struct lp_type blend_types[] = { 628bf215546Sopenharmony_ci /* float, fixed, sign, norm, width, len */ 629bf215546Sopenharmony_ci { TRUE, FALSE, TRUE, FALSE, 32, 4 }, /* f32 x 4 */ 630bf215546Sopenharmony_ci { FALSE, FALSE, FALSE, TRUE, 8, 16 }, /* u8n x 16 */ 631bf215546Sopenharmony_ci}; 632bf215546Sopenharmony_ci 633bf215546Sopenharmony_ci 634bf215546Sopenharmony_ciconst unsigned num_funcs = ARRAY_SIZE(blend_funcs); 635bf215546Sopenharmony_ciconst unsigned num_factors = ARRAY_SIZE(blend_factors); 636bf215546Sopenharmony_ciconst unsigned num_types = ARRAY_SIZE(blend_types); 637bf215546Sopenharmony_ci 638bf215546Sopenharmony_ci 639bf215546Sopenharmony_ciboolean 640bf215546Sopenharmony_citest_all(unsigned verbose, FILE *fp) 641bf215546Sopenharmony_ci{ 642bf215546Sopenharmony_ci const unsigned *rgb_func; 643bf215546Sopenharmony_ci const unsigned *rgb_src_factor; 644bf215546Sopenharmony_ci const unsigned *rgb_dst_factor; 645bf215546Sopenharmony_ci const unsigned *alpha_func; 646bf215546Sopenharmony_ci const unsigned *alpha_src_factor; 647bf215546Sopenharmony_ci const unsigned *alpha_dst_factor; 648bf215546Sopenharmony_ci struct pipe_blend_state blend; 649bf215546Sopenharmony_ci const struct lp_type *type; 650bf215546Sopenharmony_ci boolean success = TRUE; 651bf215546Sopenharmony_ci 652bf215546Sopenharmony_ci for(rgb_func = blend_funcs; rgb_func < &blend_funcs[num_funcs]; ++rgb_func) { 653bf215546Sopenharmony_ci for(alpha_func = blend_funcs; alpha_func < &blend_funcs[num_funcs]; ++alpha_func) { 654bf215546Sopenharmony_ci for(rgb_src_factor = blend_factors; rgb_src_factor < &blend_factors[num_factors]; ++rgb_src_factor) { 655bf215546Sopenharmony_ci for(rgb_dst_factor = blend_factors; rgb_dst_factor <= rgb_src_factor; ++rgb_dst_factor) { 656bf215546Sopenharmony_ci for(alpha_src_factor = blend_factors; alpha_src_factor < &blend_factors[num_factors]; ++alpha_src_factor) { 657bf215546Sopenharmony_ci for(alpha_dst_factor = blend_factors; alpha_dst_factor <= alpha_src_factor; ++alpha_dst_factor) { 658bf215546Sopenharmony_ci for(type = blend_types; type < &blend_types[num_types]; ++type) { 659bf215546Sopenharmony_ci 660bf215546Sopenharmony_ci if(*rgb_dst_factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE || 661bf215546Sopenharmony_ci *alpha_dst_factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE) 662bf215546Sopenharmony_ci continue; 663bf215546Sopenharmony_ci 664bf215546Sopenharmony_ci memset(&blend, 0, sizeof blend); 665bf215546Sopenharmony_ci blend.rt[0].blend_enable = 1; 666bf215546Sopenharmony_ci blend.rt[0].rgb_func = *rgb_func; 667bf215546Sopenharmony_ci blend.rt[0].rgb_src_factor = *rgb_src_factor; 668bf215546Sopenharmony_ci blend.rt[0].rgb_dst_factor = *rgb_dst_factor; 669bf215546Sopenharmony_ci blend.rt[0].alpha_func = *alpha_func; 670bf215546Sopenharmony_ci blend.rt[0].alpha_src_factor = *alpha_src_factor; 671bf215546Sopenharmony_ci blend.rt[0].alpha_dst_factor = *alpha_dst_factor; 672bf215546Sopenharmony_ci blend.rt[0].colormask = PIPE_MASK_RGBA; 673bf215546Sopenharmony_ci 674bf215546Sopenharmony_ci if(!test_one(verbose, fp, &blend, *type)) 675bf215546Sopenharmony_ci success = FALSE; 676bf215546Sopenharmony_ci 677bf215546Sopenharmony_ci } 678bf215546Sopenharmony_ci } 679bf215546Sopenharmony_ci } 680bf215546Sopenharmony_ci } 681bf215546Sopenharmony_ci } 682bf215546Sopenharmony_ci } 683bf215546Sopenharmony_ci } 684bf215546Sopenharmony_ci 685bf215546Sopenharmony_ci return success; 686bf215546Sopenharmony_ci} 687bf215546Sopenharmony_ci 688bf215546Sopenharmony_ci 689bf215546Sopenharmony_ciboolean 690bf215546Sopenharmony_citest_some(unsigned verbose, FILE *fp, 691bf215546Sopenharmony_ci unsigned long n) 692bf215546Sopenharmony_ci{ 693bf215546Sopenharmony_ci const unsigned *rgb_func; 694bf215546Sopenharmony_ci const unsigned *rgb_src_factor; 695bf215546Sopenharmony_ci const unsigned *rgb_dst_factor; 696bf215546Sopenharmony_ci const unsigned *alpha_func; 697bf215546Sopenharmony_ci const unsigned *alpha_src_factor; 698bf215546Sopenharmony_ci const unsigned *alpha_dst_factor; 699bf215546Sopenharmony_ci struct pipe_blend_state blend; 700bf215546Sopenharmony_ci const struct lp_type *type; 701bf215546Sopenharmony_ci unsigned long i; 702bf215546Sopenharmony_ci boolean success = TRUE; 703bf215546Sopenharmony_ci 704bf215546Sopenharmony_ci for(i = 0; i < n; ++i) { 705bf215546Sopenharmony_ci rgb_func = &blend_funcs[rand() % num_funcs]; 706bf215546Sopenharmony_ci alpha_func = &blend_funcs[rand() % num_funcs]; 707bf215546Sopenharmony_ci rgb_src_factor = &blend_factors[rand() % num_factors]; 708bf215546Sopenharmony_ci alpha_src_factor = &blend_factors[rand() % num_factors]; 709bf215546Sopenharmony_ci 710bf215546Sopenharmony_ci do { 711bf215546Sopenharmony_ci rgb_dst_factor = &blend_factors[rand() % num_factors]; 712bf215546Sopenharmony_ci } while(*rgb_dst_factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE); 713bf215546Sopenharmony_ci 714bf215546Sopenharmony_ci do { 715bf215546Sopenharmony_ci alpha_dst_factor = &blend_factors[rand() % num_factors]; 716bf215546Sopenharmony_ci } while(*alpha_dst_factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE); 717bf215546Sopenharmony_ci 718bf215546Sopenharmony_ci type = &blend_types[rand() % num_types]; 719bf215546Sopenharmony_ci 720bf215546Sopenharmony_ci memset(&blend, 0, sizeof blend); 721bf215546Sopenharmony_ci blend.rt[0].blend_enable = 1; 722bf215546Sopenharmony_ci blend.rt[0].rgb_func = *rgb_func; 723bf215546Sopenharmony_ci blend.rt[0].rgb_src_factor = *rgb_src_factor; 724bf215546Sopenharmony_ci blend.rt[0].rgb_dst_factor = *rgb_dst_factor; 725bf215546Sopenharmony_ci blend.rt[0].alpha_func = *alpha_func; 726bf215546Sopenharmony_ci blend.rt[0].alpha_src_factor = *alpha_src_factor; 727bf215546Sopenharmony_ci blend.rt[0].alpha_dst_factor = *alpha_dst_factor; 728bf215546Sopenharmony_ci blend.rt[0].colormask = PIPE_MASK_RGBA; 729bf215546Sopenharmony_ci 730bf215546Sopenharmony_ci if(!test_one(verbose, fp, &blend, *type)) 731bf215546Sopenharmony_ci success = FALSE; 732bf215546Sopenharmony_ci } 733bf215546Sopenharmony_ci 734bf215546Sopenharmony_ci return success; 735bf215546Sopenharmony_ci} 736bf215546Sopenharmony_ci 737bf215546Sopenharmony_ci 738bf215546Sopenharmony_ciboolean 739bf215546Sopenharmony_citest_single(unsigned verbose, FILE *fp) 740bf215546Sopenharmony_ci{ 741bf215546Sopenharmony_ci printf("no test_single()"); 742bf215546Sopenharmony_ci return TRUE; 743bf215546Sopenharmony_ci} 744