1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2003 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#ifndef I915_STATE_INLINES_H 29bf215546Sopenharmony_ci#define I915_STATE_INLINES_H 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#include "pipe/p_compiler.h" 32bf215546Sopenharmony_ci#include "pipe/p_defines.h" 33bf215546Sopenharmony_ci#include "util/u_debug.h" 34bf215546Sopenharmony_ci#include "i915_reg.h" 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_cistatic inline unsigned 37bf215546Sopenharmony_cii915_translate_compare_func(unsigned func) 38bf215546Sopenharmony_ci{ 39bf215546Sopenharmony_ci switch (func) { 40bf215546Sopenharmony_ci case PIPE_FUNC_NEVER: 41bf215546Sopenharmony_ci return COMPAREFUNC_NEVER; 42bf215546Sopenharmony_ci case PIPE_FUNC_LESS: 43bf215546Sopenharmony_ci return COMPAREFUNC_LESS; 44bf215546Sopenharmony_ci case PIPE_FUNC_LEQUAL: 45bf215546Sopenharmony_ci return COMPAREFUNC_LEQUAL; 46bf215546Sopenharmony_ci case PIPE_FUNC_GREATER: 47bf215546Sopenharmony_ci return COMPAREFUNC_GREATER; 48bf215546Sopenharmony_ci case PIPE_FUNC_GEQUAL: 49bf215546Sopenharmony_ci return COMPAREFUNC_GEQUAL; 50bf215546Sopenharmony_ci case PIPE_FUNC_NOTEQUAL: 51bf215546Sopenharmony_ci return COMPAREFUNC_NOTEQUAL; 52bf215546Sopenharmony_ci case PIPE_FUNC_EQUAL: 53bf215546Sopenharmony_ci return COMPAREFUNC_EQUAL; 54bf215546Sopenharmony_ci case PIPE_FUNC_ALWAYS: 55bf215546Sopenharmony_ci return COMPAREFUNC_ALWAYS; 56bf215546Sopenharmony_ci default: 57bf215546Sopenharmony_ci return COMPAREFUNC_ALWAYS; 58bf215546Sopenharmony_ci } 59bf215546Sopenharmony_ci} 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_cistatic inline unsigned 62bf215546Sopenharmony_cii915_translate_shadow_compare_func(unsigned func) 63bf215546Sopenharmony_ci{ 64bf215546Sopenharmony_ci switch (func) { 65bf215546Sopenharmony_ci case PIPE_FUNC_NEVER: 66bf215546Sopenharmony_ci return COMPAREFUNC_ALWAYS; 67bf215546Sopenharmony_ci case PIPE_FUNC_LESS: 68bf215546Sopenharmony_ci return COMPAREFUNC_LEQUAL; 69bf215546Sopenharmony_ci case PIPE_FUNC_LEQUAL: 70bf215546Sopenharmony_ci return COMPAREFUNC_LESS; 71bf215546Sopenharmony_ci case PIPE_FUNC_GREATER: 72bf215546Sopenharmony_ci return COMPAREFUNC_GEQUAL; 73bf215546Sopenharmony_ci case PIPE_FUNC_GEQUAL: 74bf215546Sopenharmony_ci return COMPAREFUNC_GREATER; 75bf215546Sopenharmony_ci case PIPE_FUNC_NOTEQUAL: 76bf215546Sopenharmony_ci return COMPAREFUNC_EQUAL; 77bf215546Sopenharmony_ci case PIPE_FUNC_EQUAL: 78bf215546Sopenharmony_ci return COMPAREFUNC_NOTEQUAL; 79bf215546Sopenharmony_ci case PIPE_FUNC_ALWAYS: 80bf215546Sopenharmony_ci return COMPAREFUNC_NEVER; 81bf215546Sopenharmony_ci default: 82bf215546Sopenharmony_ci return COMPAREFUNC_NEVER; 83bf215546Sopenharmony_ci } 84bf215546Sopenharmony_ci} 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_cistatic inline unsigned 87bf215546Sopenharmony_cii915_translate_stencil_op(unsigned op) 88bf215546Sopenharmony_ci{ 89bf215546Sopenharmony_ci switch (op) { 90bf215546Sopenharmony_ci case PIPE_STENCIL_OP_KEEP: 91bf215546Sopenharmony_ci return STENCILOP_KEEP; 92bf215546Sopenharmony_ci case PIPE_STENCIL_OP_ZERO: 93bf215546Sopenharmony_ci return STENCILOP_ZERO; 94bf215546Sopenharmony_ci case PIPE_STENCIL_OP_REPLACE: 95bf215546Sopenharmony_ci return STENCILOP_REPLACE; 96bf215546Sopenharmony_ci case PIPE_STENCIL_OP_INCR: 97bf215546Sopenharmony_ci return STENCILOP_INCRSAT; 98bf215546Sopenharmony_ci case PIPE_STENCIL_OP_DECR: 99bf215546Sopenharmony_ci return STENCILOP_DECRSAT; 100bf215546Sopenharmony_ci case PIPE_STENCIL_OP_INCR_WRAP: 101bf215546Sopenharmony_ci return STENCILOP_INCR; 102bf215546Sopenharmony_ci case PIPE_STENCIL_OP_DECR_WRAP: 103bf215546Sopenharmony_ci return STENCILOP_DECR; 104bf215546Sopenharmony_ci case PIPE_STENCIL_OP_INVERT: 105bf215546Sopenharmony_ci return STENCILOP_INVERT; 106bf215546Sopenharmony_ci default: 107bf215546Sopenharmony_ci return STENCILOP_ZERO; 108bf215546Sopenharmony_ci } 109bf215546Sopenharmony_ci} 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_cistatic inline unsigned 112bf215546Sopenharmony_cii915_translate_blend_factor(unsigned factor) 113bf215546Sopenharmony_ci{ 114bf215546Sopenharmony_ci switch (factor) { 115bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_ZERO: 116bf215546Sopenharmony_ci return BLENDFACT_ZERO; 117bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_ALPHA: 118bf215546Sopenharmony_ci return BLENDFACT_SRC_ALPHA; 119bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_ONE: 120bf215546Sopenharmony_ci return BLENDFACT_ONE; 121bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_COLOR: 122bf215546Sopenharmony_ci return BLENDFACT_SRC_COLR; 123bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC_COLOR: 124bf215546Sopenharmony_ci return BLENDFACT_INV_SRC_COLR; 125bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_DST_COLOR: 126bf215546Sopenharmony_ci return BLENDFACT_DST_COLR; 127bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_DST_COLOR: 128bf215546Sopenharmony_ci return BLENDFACT_INV_DST_COLR; 129bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC_ALPHA: 130bf215546Sopenharmony_ci return BLENDFACT_INV_SRC_ALPHA; 131bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_DST_ALPHA: 132bf215546Sopenharmony_ci return BLENDFACT_DST_ALPHA; 133bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_DST_ALPHA: 134bf215546Sopenharmony_ci return BLENDFACT_INV_DST_ALPHA; 135bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: 136bf215546Sopenharmony_ci return BLENDFACT_SRC_ALPHA_SATURATE; 137bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_CONST_COLOR: 138bf215546Sopenharmony_ci return BLENDFACT_CONST_COLOR; 139bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_CONST_COLOR: 140bf215546Sopenharmony_ci return BLENDFACT_INV_CONST_COLOR; 141bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_CONST_ALPHA: 142bf215546Sopenharmony_ci return BLENDFACT_CONST_ALPHA; 143bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_CONST_ALPHA: 144bf215546Sopenharmony_ci return BLENDFACT_INV_CONST_ALPHA; 145bf215546Sopenharmony_ci default: 146bf215546Sopenharmony_ci return BLENDFACT_ZERO; 147bf215546Sopenharmony_ci } 148bf215546Sopenharmony_ci} 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_cistatic inline unsigned 151bf215546Sopenharmony_cii915_translate_blend_func(unsigned mode) 152bf215546Sopenharmony_ci{ 153bf215546Sopenharmony_ci switch (mode) { 154bf215546Sopenharmony_ci case PIPE_BLEND_ADD: 155bf215546Sopenharmony_ci return BLENDFUNC_ADD; 156bf215546Sopenharmony_ci case PIPE_BLEND_MIN: 157bf215546Sopenharmony_ci return BLENDFUNC_MIN; 158bf215546Sopenharmony_ci case PIPE_BLEND_MAX: 159bf215546Sopenharmony_ci return BLENDFUNC_MAX; 160bf215546Sopenharmony_ci case PIPE_BLEND_SUBTRACT: 161bf215546Sopenharmony_ci return BLENDFUNC_SUBTRACT; 162bf215546Sopenharmony_ci case PIPE_BLEND_REVERSE_SUBTRACT: 163bf215546Sopenharmony_ci return BLENDFUNC_REVERSE_SUBTRACT; 164bf215546Sopenharmony_ci default: 165bf215546Sopenharmony_ci return 0; 166bf215546Sopenharmony_ci } 167bf215546Sopenharmony_ci} 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_cistatic inline unsigned 170bf215546Sopenharmony_cii915_translate_logic_op(unsigned opcode) 171bf215546Sopenharmony_ci{ 172bf215546Sopenharmony_ci switch (opcode) { 173bf215546Sopenharmony_ci case PIPE_LOGICOP_CLEAR: 174bf215546Sopenharmony_ci return LOGICOP_CLEAR; 175bf215546Sopenharmony_ci case PIPE_LOGICOP_AND: 176bf215546Sopenharmony_ci return LOGICOP_AND; 177bf215546Sopenharmony_ci case PIPE_LOGICOP_AND_REVERSE: 178bf215546Sopenharmony_ci return LOGICOP_AND_RVRSE; 179bf215546Sopenharmony_ci case PIPE_LOGICOP_COPY: 180bf215546Sopenharmony_ci return LOGICOP_COPY; 181bf215546Sopenharmony_ci case PIPE_LOGICOP_COPY_INVERTED: 182bf215546Sopenharmony_ci return LOGICOP_COPY_INV; 183bf215546Sopenharmony_ci case PIPE_LOGICOP_AND_INVERTED: 184bf215546Sopenharmony_ci return LOGICOP_AND_INV; 185bf215546Sopenharmony_ci case PIPE_LOGICOP_NOOP: 186bf215546Sopenharmony_ci return LOGICOP_NOOP; 187bf215546Sopenharmony_ci case PIPE_LOGICOP_XOR: 188bf215546Sopenharmony_ci return LOGICOP_XOR; 189bf215546Sopenharmony_ci case PIPE_LOGICOP_OR: 190bf215546Sopenharmony_ci return LOGICOP_OR; 191bf215546Sopenharmony_ci case PIPE_LOGICOP_OR_INVERTED: 192bf215546Sopenharmony_ci return LOGICOP_OR_INV; 193bf215546Sopenharmony_ci case PIPE_LOGICOP_NOR: 194bf215546Sopenharmony_ci return LOGICOP_NOR; 195bf215546Sopenharmony_ci case PIPE_LOGICOP_EQUIV: 196bf215546Sopenharmony_ci return LOGICOP_EQUIV; 197bf215546Sopenharmony_ci case PIPE_LOGICOP_INVERT: 198bf215546Sopenharmony_ci return LOGICOP_INV; 199bf215546Sopenharmony_ci case PIPE_LOGICOP_OR_REVERSE: 200bf215546Sopenharmony_ci return LOGICOP_OR_RVRSE; 201bf215546Sopenharmony_ci case PIPE_LOGICOP_NAND: 202bf215546Sopenharmony_ci return LOGICOP_NAND; 203bf215546Sopenharmony_ci case PIPE_LOGICOP_SET: 204bf215546Sopenharmony_ci return LOGICOP_SET; 205bf215546Sopenharmony_ci default: 206bf215546Sopenharmony_ci return LOGICOP_SET; 207bf215546Sopenharmony_ci } 208bf215546Sopenharmony_ci} 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_cistatic inline bool 211bf215546Sopenharmony_cii915_validate_vertices(unsigned hw_prim, unsigned nr) 212bf215546Sopenharmony_ci{ 213bf215546Sopenharmony_ci bool ok; 214bf215546Sopenharmony_ci 215bf215546Sopenharmony_ci switch (hw_prim) { 216bf215546Sopenharmony_ci case PRIM3D_POINTLIST: 217bf215546Sopenharmony_ci ok = (nr >= 1); 218bf215546Sopenharmony_ci assert(ok); 219bf215546Sopenharmony_ci break; 220bf215546Sopenharmony_ci case PRIM3D_LINELIST: 221bf215546Sopenharmony_ci ok = (nr >= 2) && (nr % 2) == 0; 222bf215546Sopenharmony_ci assert(ok); 223bf215546Sopenharmony_ci break; 224bf215546Sopenharmony_ci case PRIM3D_LINESTRIP: 225bf215546Sopenharmony_ci ok = (nr >= 2); 226bf215546Sopenharmony_ci assert(ok); 227bf215546Sopenharmony_ci break; 228bf215546Sopenharmony_ci case PRIM3D_TRILIST: 229bf215546Sopenharmony_ci ok = (nr >= 3) && (nr % 3) == 0; 230bf215546Sopenharmony_ci assert(ok); 231bf215546Sopenharmony_ci break; 232bf215546Sopenharmony_ci case PRIM3D_TRISTRIP: 233bf215546Sopenharmony_ci ok = (nr >= 3); 234bf215546Sopenharmony_ci assert(ok); 235bf215546Sopenharmony_ci break; 236bf215546Sopenharmony_ci case PRIM3D_TRIFAN: 237bf215546Sopenharmony_ci ok = (nr >= 3); 238bf215546Sopenharmony_ci assert(ok); 239bf215546Sopenharmony_ci break; 240bf215546Sopenharmony_ci case PRIM3D_POLY: 241bf215546Sopenharmony_ci ok = (nr >= 3); 242bf215546Sopenharmony_ci assert(ok); 243bf215546Sopenharmony_ci break; 244bf215546Sopenharmony_ci default: 245bf215546Sopenharmony_ci assert(0); 246bf215546Sopenharmony_ci ok = 0; 247bf215546Sopenharmony_ci break; 248bf215546Sopenharmony_ci } 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_ci return ok; 251bf215546Sopenharmony_ci} 252bf215546Sopenharmony_ci 253bf215546Sopenharmony_ci#endif 254