1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org> 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Rob Clark <robclark@freedesktop.org> 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "pipe/p_defines.h" 28bf215546Sopenharmony_ci#include "util/format/u_format.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "freedreno_util.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ciint32_t marker_cnt; 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cienum adreno_rb_depth_format 35bf215546Sopenharmony_cifd_pipe2depth(enum pipe_format format) 36bf215546Sopenharmony_ci{ 37bf215546Sopenharmony_ci switch (format) { 38bf215546Sopenharmony_ci case PIPE_FORMAT_Z16_UNORM: 39bf215546Sopenharmony_ci return DEPTHX_16; 40bf215546Sopenharmony_ci case PIPE_FORMAT_Z24X8_UNORM: 41bf215546Sopenharmony_ci case PIPE_FORMAT_Z24_UNORM_S8_UINT: 42bf215546Sopenharmony_ci case PIPE_FORMAT_X8Z24_UNORM: 43bf215546Sopenharmony_ci case PIPE_FORMAT_S8_UINT_Z24_UNORM: 44bf215546Sopenharmony_ci return DEPTHX_24_8; 45bf215546Sopenharmony_ci case PIPE_FORMAT_Z32_FLOAT: 46bf215546Sopenharmony_ci case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: 47bf215546Sopenharmony_ci return DEPTHX_32; 48bf215546Sopenharmony_ci default: 49bf215546Sopenharmony_ci return ~0; 50bf215546Sopenharmony_ci } 51bf215546Sopenharmony_ci} 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_cienum pc_di_index_size 54bf215546Sopenharmony_cifd_pipe2index(enum pipe_format format) 55bf215546Sopenharmony_ci{ 56bf215546Sopenharmony_ci switch (format) { 57bf215546Sopenharmony_ci case PIPE_FORMAT_R8_UINT: 58bf215546Sopenharmony_ci return INDEX_SIZE_8_BIT; 59bf215546Sopenharmony_ci case PIPE_FORMAT_R16_UINT: 60bf215546Sopenharmony_ci return INDEX_SIZE_16_BIT; 61bf215546Sopenharmony_ci case PIPE_FORMAT_R32_UINT: 62bf215546Sopenharmony_ci return INDEX_SIZE_32_BIT; 63bf215546Sopenharmony_ci default: 64bf215546Sopenharmony_ci return ~0; 65bf215546Sopenharmony_ci } 66bf215546Sopenharmony_ci} 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_ci/* we need to special case a bit the depth/stencil restore, because we are 69bf215546Sopenharmony_ci * using the texture sampler to blit into the depth/stencil buffer, *not* 70bf215546Sopenharmony_ci * into a color buffer. Otherwise fdN_tex_swiz() will do the wrong thing, 71bf215546Sopenharmony_ci * as it is assuming that you are sampling into normal render target.. 72bf215546Sopenharmony_ci */ 73bf215546Sopenharmony_cienum pipe_format 74bf215546Sopenharmony_cifd_gmem_restore_format(enum pipe_format format) 75bf215546Sopenharmony_ci{ 76bf215546Sopenharmony_ci switch (format) { 77bf215546Sopenharmony_ci case PIPE_FORMAT_Z24X8_UNORM: 78bf215546Sopenharmony_ci case PIPE_FORMAT_Z24_UNORM_S8_UINT: 79bf215546Sopenharmony_ci return PIPE_FORMAT_R8G8B8A8_UNORM; 80bf215546Sopenharmony_ci case PIPE_FORMAT_Z16_UNORM: 81bf215546Sopenharmony_ci return PIPE_FORMAT_R8G8_UNORM; 82bf215546Sopenharmony_ci case PIPE_FORMAT_S8_UINT: 83bf215546Sopenharmony_ci return PIPE_FORMAT_R8_UNORM; 84bf215546Sopenharmony_ci default: 85bf215546Sopenharmony_ci return format; 86bf215546Sopenharmony_ci } 87bf215546Sopenharmony_ci} 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_cienum adreno_rb_blend_factor 90bf215546Sopenharmony_cifd_blend_factor(unsigned factor) 91bf215546Sopenharmony_ci{ 92bf215546Sopenharmony_ci switch (factor) { 93bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_ONE: 94bf215546Sopenharmony_ci return FACTOR_ONE; 95bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_COLOR: 96bf215546Sopenharmony_ci return FACTOR_SRC_COLOR; 97bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_ALPHA: 98bf215546Sopenharmony_ci return FACTOR_SRC_ALPHA; 99bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_DST_ALPHA: 100bf215546Sopenharmony_ci return FACTOR_DST_ALPHA; 101bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_DST_COLOR: 102bf215546Sopenharmony_ci return FACTOR_DST_COLOR; 103bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: 104bf215546Sopenharmony_ci return FACTOR_SRC_ALPHA_SATURATE; 105bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_CONST_COLOR: 106bf215546Sopenharmony_ci return FACTOR_CONSTANT_COLOR; 107bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_CONST_ALPHA: 108bf215546Sopenharmony_ci return FACTOR_CONSTANT_ALPHA; 109bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_ZERO: 110bf215546Sopenharmony_ci case 0: 111bf215546Sopenharmony_ci return FACTOR_ZERO; 112bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC_COLOR: 113bf215546Sopenharmony_ci return FACTOR_ONE_MINUS_SRC_COLOR; 114bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC_ALPHA: 115bf215546Sopenharmony_ci return FACTOR_ONE_MINUS_SRC_ALPHA; 116bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_DST_ALPHA: 117bf215546Sopenharmony_ci return FACTOR_ONE_MINUS_DST_ALPHA; 118bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_DST_COLOR: 119bf215546Sopenharmony_ci return FACTOR_ONE_MINUS_DST_COLOR; 120bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_CONST_COLOR: 121bf215546Sopenharmony_ci return FACTOR_ONE_MINUS_CONSTANT_COLOR; 122bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_CONST_ALPHA: 123bf215546Sopenharmony_ci return FACTOR_ONE_MINUS_CONSTANT_ALPHA; 124bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC1_COLOR: 125bf215546Sopenharmony_ci return FACTOR_ONE_MINUS_SRC1_COLOR; 126bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: 127bf215546Sopenharmony_ci return FACTOR_ONE_MINUS_SRC1_ALPHA; 128bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC1_COLOR: 129bf215546Sopenharmony_ci return FACTOR_SRC1_COLOR; 130bf215546Sopenharmony_ci case PIPE_BLENDFACTOR_SRC1_ALPHA: 131bf215546Sopenharmony_ci return FACTOR_SRC1_ALPHA; 132bf215546Sopenharmony_ci default: 133bf215546Sopenharmony_ci DBG("invalid blend factor: %x", factor); 134bf215546Sopenharmony_ci return 0; 135bf215546Sopenharmony_ci } 136bf215546Sopenharmony_ci} 137bf215546Sopenharmony_ci 138bf215546Sopenharmony_cienum adreno_pa_su_sc_draw 139bf215546Sopenharmony_cifd_polygon_mode(unsigned mode) 140bf215546Sopenharmony_ci{ 141bf215546Sopenharmony_ci switch (mode) { 142bf215546Sopenharmony_ci case PIPE_POLYGON_MODE_POINT: 143bf215546Sopenharmony_ci return PC_DRAW_POINTS; 144bf215546Sopenharmony_ci case PIPE_POLYGON_MODE_LINE: 145bf215546Sopenharmony_ci return PC_DRAW_LINES; 146bf215546Sopenharmony_ci case PIPE_POLYGON_MODE_FILL: 147bf215546Sopenharmony_ci return PC_DRAW_TRIANGLES; 148bf215546Sopenharmony_ci default: 149bf215546Sopenharmony_ci DBG("invalid polygon mode: %u", mode); 150bf215546Sopenharmony_ci return 0; 151bf215546Sopenharmony_ci } 152bf215546Sopenharmony_ci} 153bf215546Sopenharmony_ci 154bf215546Sopenharmony_cienum adreno_stencil_op 155bf215546Sopenharmony_cifd_stencil_op(unsigned op) 156bf215546Sopenharmony_ci{ 157bf215546Sopenharmony_ci switch (op) { 158bf215546Sopenharmony_ci case PIPE_STENCIL_OP_KEEP: 159bf215546Sopenharmony_ci return STENCIL_KEEP; 160bf215546Sopenharmony_ci case PIPE_STENCIL_OP_ZERO: 161bf215546Sopenharmony_ci return STENCIL_ZERO; 162bf215546Sopenharmony_ci case PIPE_STENCIL_OP_REPLACE: 163bf215546Sopenharmony_ci return STENCIL_REPLACE; 164bf215546Sopenharmony_ci case PIPE_STENCIL_OP_INCR: 165bf215546Sopenharmony_ci return STENCIL_INCR_CLAMP; 166bf215546Sopenharmony_ci case PIPE_STENCIL_OP_DECR: 167bf215546Sopenharmony_ci return STENCIL_DECR_CLAMP; 168bf215546Sopenharmony_ci case PIPE_STENCIL_OP_INCR_WRAP: 169bf215546Sopenharmony_ci return STENCIL_INCR_WRAP; 170bf215546Sopenharmony_ci case PIPE_STENCIL_OP_DECR_WRAP: 171bf215546Sopenharmony_ci return STENCIL_DECR_WRAP; 172bf215546Sopenharmony_ci case PIPE_STENCIL_OP_INVERT: 173bf215546Sopenharmony_ci return STENCIL_INVERT; 174bf215546Sopenharmony_ci default: 175bf215546Sopenharmony_ci DBG("invalid stencil op: %u", op); 176bf215546Sopenharmony_ci return 0; 177bf215546Sopenharmony_ci } 178bf215546Sopenharmony_ci} 179