Path: blob/21.2-virgl/src/gallium/drivers/i915/i915_state_inlines.h
4570 views
/**************************************************************************1*2* Copyright 2003 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#ifndef I915_STATE_INLINES_H28#define I915_STATE_INLINES_H2930#include "pipe/p_compiler.h"31#include "pipe/p_defines.h"32#include "util/u_debug.h"33#include "i915_reg.h"3435static inline unsigned36i915_translate_compare_func(unsigned func)37{38switch (func) {39case PIPE_FUNC_NEVER:40return COMPAREFUNC_NEVER;41case PIPE_FUNC_LESS:42return COMPAREFUNC_LESS;43case PIPE_FUNC_LEQUAL:44return COMPAREFUNC_LEQUAL;45case PIPE_FUNC_GREATER:46return COMPAREFUNC_GREATER;47case PIPE_FUNC_GEQUAL:48return COMPAREFUNC_GEQUAL;49case PIPE_FUNC_NOTEQUAL:50return COMPAREFUNC_NOTEQUAL;51case PIPE_FUNC_EQUAL:52return COMPAREFUNC_EQUAL;53case PIPE_FUNC_ALWAYS:54return COMPAREFUNC_ALWAYS;55default:56return COMPAREFUNC_ALWAYS;57}58}5960static inline unsigned61i915_translate_shadow_compare_func(unsigned func)62{63switch (func) {64case PIPE_FUNC_NEVER:65return COMPAREFUNC_ALWAYS;66case PIPE_FUNC_LESS:67return COMPAREFUNC_LEQUAL;68case PIPE_FUNC_LEQUAL:69return COMPAREFUNC_LESS;70case PIPE_FUNC_GREATER:71return COMPAREFUNC_GEQUAL;72case PIPE_FUNC_GEQUAL:73return COMPAREFUNC_GREATER;74case PIPE_FUNC_NOTEQUAL:75return COMPAREFUNC_EQUAL;76case PIPE_FUNC_EQUAL:77return COMPAREFUNC_NOTEQUAL;78case PIPE_FUNC_ALWAYS:79return COMPAREFUNC_NEVER;80default:81return COMPAREFUNC_NEVER;82}83}8485static inline unsigned86i915_translate_stencil_op(unsigned op)87{88switch (op) {89case PIPE_STENCIL_OP_KEEP:90return STENCILOP_KEEP;91case PIPE_STENCIL_OP_ZERO:92return STENCILOP_ZERO;93case PIPE_STENCIL_OP_REPLACE:94return STENCILOP_REPLACE;95case PIPE_STENCIL_OP_INCR:96return STENCILOP_INCRSAT;97case PIPE_STENCIL_OP_DECR:98return STENCILOP_DECRSAT;99case PIPE_STENCIL_OP_INCR_WRAP:100return STENCILOP_INCR;101case PIPE_STENCIL_OP_DECR_WRAP:102return STENCILOP_DECR;103case PIPE_STENCIL_OP_INVERT:104return STENCILOP_INVERT;105default:106return STENCILOP_ZERO;107}108}109110static inline unsigned111i915_translate_blend_factor(unsigned factor)112{113switch (factor) {114case PIPE_BLENDFACTOR_ZERO:115return BLENDFACT_ZERO;116case PIPE_BLENDFACTOR_SRC_ALPHA:117return BLENDFACT_SRC_ALPHA;118case PIPE_BLENDFACTOR_ONE:119return BLENDFACT_ONE;120case PIPE_BLENDFACTOR_SRC_COLOR:121return BLENDFACT_SRC_COLR;122case PIPE_BLENDFACTOR_INV_SRC_COLOR:123return BLENDFACT_INV_SRC_COLR;124case PIPE_BLENDFACTOR_DST_COLOR:125return BLENDFACT_DST_COLR;126case PIPE_BLENDFACTOR_INV_DST_COLOR:127return BLENDFACT_INV_DST_COLR;128case PIPE_BLENDFACTOR_INV_SRC_ALPHA:129return BLENDFACT_INV_SRC_ALPHA;130case PIPE_BLENDFACTOR_DST_ALPHA:131return BLENDFACT_DST_ALPHA;132case PIPE_BLENDFACTOR_INV_DST_ALPHA:133return BLENDFACT_INV_DST_ALPHA;134case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:135return BLENDFACT_SRC_ALPHA_SATURATE;136case PIPE_BLENDFACTOR_CONST_COLOR:137return BLENDFACT_CONST_COLOR;138case PIPE_BLENDFACTOR_INV_CONST_COLOR:139return BLENDFACT_INV_CONST_COLOR;140case PIPE_BLENDFACTOR_CONST_ALPHA:141return BLENDFACT_CONST_ALPHA;142case PIPE_BLENDFACTOR_INV_CONST_ALPHA:143return BLENDFACT_INV_CONST_ALPHA;144default:145return BLENDFACT_ZERO;146}147}148149static inline unsigned150i915_translate_blend_func(unsigned mode)151{152switch (mode) {153case PIPE_BLEND_ADD:154return BLENDFUNC_ADD;155case PIPE_BLEND_MIN:156return BLENDFUNC_MIN;157case PIPE_BLEND_MAX:158return BLENDFUNC_MAX;159case PIPE_BLEND_SUBTRACT:160return BLENDFUNC_SUBTRACT;161case PIPE_BLEND_REVERSE_SUBTRACT:162return BLENDFUNC_REVERSE_SUBTRACT;163default:164return 0;165}166}167168static inline unsigned169i915_translate_logic_op(unsigned opcode)170{171switch (opcode) {172case PIPE_LOGICOP_CLEAR:173return LOGICOP_CLEAR;174case PIPE_LOGICOP_AND:175return LOGICOP_AND;176case PIPE_LOGICOP_AND_REVERSE:177return LOGICOP_AND_RVRSE;178case PIPE_LOGICOP_COPY:179return LOGICOP_COPY;180case PIPE_LOGICOP_COPY_INVERTED:181return LOGICOP_COPY_INV;182case PIPE_LOGICOP_AND_INVERTED:183return LOGICOP_AND_INV;184case PIPE_LOGICOP_NOOP:185return LOGICOP_NOOP;186case PIPE_LOGICOP_XOR:187return LOGICOP_XOR;188case PIPE_LOGICOP_OR:189return LOGICOP_OR;190case PIPE_LOGICOP_OR_INVERTED:191return LOGICOP_OR_INV;192case PIPE_LOGICOP_NOR:193return LOGICOP_NOR;194case PIPE_LOGICOP_EQUIV:195return LOGICOP_EQUIV;196case PIPE_LOGICOP_INVERT:197return LOGICOP_INV;198case PIPE_LOGICOP_OR_REVERSE:199return LOGICOP_OR_RVRSE;200case PIPE_LOGICOP_NAND:201return LOGICOP_NAND;202case PIPE_LOGICOP_SET:203return LOGICOP_SET;204default:205return LOGICOP_SET;206}207}208209static inline bool210i915_validate_vertices(unsigned hw_prim, unsigned nr)211{212bool ok;213214switch (hw_prim) {215case PRIM3D_POINTLIST:216ok = (nr >= 1);217assert(ok);218break;219case PRIM3D_LINELIST:220ok = (nr >= 2) && (nr % 2) == 0;221assert(ok);222break;223case PRIM3D_LINESTRIP:224ok = (nr >= 2);225assert(ok);226break;227case PRIM3D_TRILIST:228ok = (nr >= 3) && (nr % 3) == 0;229assert(ok);230break;231case PRIM3D_TRISTRIP:232ok = (nr >= 3);233assert(ok);234break;235case PRIM3D_TRIFAN:236ok = (nr >= 3);237assert(ok);238break;239case PRIM3D_POLY:240ok = (nr >= 3);241assert(ok);242break;243default:244assert(0);245ok = 0;246break;247}248249return ok;250}251252#endif253254255