1af69d88dSmrg/* 2af69d88dSmrg * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org> 3af69d88dSmrg * 4af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a 5af69d88dSmrg * copy of this software and associated documentation files (the "Software"), 6af69d88dSmrg * to deal in the Software without restriction, including without limitation 7af69d88dSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8af69d88dSmrg * and/or sell copies of the Software, and to permit persons to whom the 9af69d88dSmrg * Software is furnished to do so, subject to the following conditions: 10af69d88dSmrg * 11af69d88dSmrg * The above copyright notice and this permission notice (including the next 12af69d88dSmrg * paragraph) shall be included in all copies or substantial portions of the 13af69d88dSmrg * Software. 14af69d88dSmrg * 15af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16af69d88dSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17af69d88dSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19af69d88dSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20af69d88dSmrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21af69d88dSmrg * SOFTWARE. 22af69d88dSmrg * 23af69d88dSmrg * Authors: 24af69d88dSmrg * Rob Clark <robclark@freedesktop.org> 25af69d88dSmrg */ 26af69d88dSmrg 27af69d88dSmrg#include "pipe/p_defines.h" 287ec681f3Smrg#include "util/format/u_format.h" 29af69d88dSmrg 30af69d88dSmrg#include "freedreno_util.h" 31af69d88dSmrg 327ec681f3Smrgint32_t marker_cnt; 33af69d88dSmrg 34af69d88dSmrgenum adreno_rb_depth_format 35af69d88dSmrgfd_pipe2depth(enum pipe_format format) 36af69d88dSmrg{ 377ec681f3Smrg switch (format) { 387ec681f3Smrg case PIPE_FORMAT_Z16_UNORM: 397ec681f3Smrg return DEPTHX_16; 407ec681f3Smrg case PIPE_FORMAT_Z24X8_UNORM: 417ec681f3Smrg case PIPE_FORMAT_Z24_UNORM_S8_UINT: 427ec681f3Smrg case PIPE_FORMAT_X8Z24_UNORM: 437ec681f3Smrg case PIPE_FORMAT_S8_UINT_Z24_UNORM: 447ec681f3Smrg return DEPTHX_24_8; 457ec681f3Smrg case PIPE_FORMAT_Z32_FLOAT: 467ec681f3Smrg case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: 477ec681f3Smrg return DEPTHX_32; 487ec681f3Smrg default: 497ec681f3Smrg return ~0; 507ec681f3Smrg } 51af69d88dSmrg} 52af69d88dSmrg 53af69d88dSmrgenum pc_di_index_size 54af69d88dSmrgfd_pipe2index(enum pipe_format format) 55af69d88dSmrg{ 567ec681f3Smrg switch (format) { 577ec681f3Smrg case PIPE_FORMAT_R8_UINT: 587ec681f3Smrg return INDEX_SIZE_8_BIT; 597ec681f3Smrg case PIPE_FORMAT_R16_UINT: 607ec681f3Smrg return INDEX_SIZE_16_BIT; 617ec681f3Smrg case PIPE_FORMAT_R32_UINT: 627ec681f3Smrg return INDEX_SIZE_32_BIT; 637ec681f3Smrg default: 647ec681f3Smrg return ~0; 657ec681f3Smrg } 66af69d88dSmrg} 67af69d88dSmrg 6801e04c3fSmrg/* we need to special case a bit the depth/stencil restore, because we are 6901e04c3fSmrg * using the texture sampler to blit into the depth/stencil buffer, *not* 7001e04c3fSmrg * into a color buffer. Otherwise fdN_tex_swiz() will do the wrong thing, 7101e04c3fSmrg * as it is assuming that you are sampling into normal render target.. 7201e04c3fSmrg */ 7301e04c3fSmrgenum pipe_format 7401e04c3fSmrgfd_gmem_restore_format(enum pipe_format format) 7501e04c3fSmrg{ 767ec681f3Smrg switch (format) { 777ec681f3Smrg case PIPE_FORMAT_Z24X8_UNORM: 787ec681f3Smrg case PIPE_FORMAT_Z24_UNORM_S8_UINT: 797ec681f3Smrg return PIPE_FORMAT_R8G8B8A8_UNORM; 807ec681f3Smrg case PIPE_FORMAT_Z16_UNORM: 817ec681f3Smrg return PIPE_FORMAT_R8G8_UNORM; 827ec681f3Smrg case PIPE_FORMAT_S8_UINT: 837ec681f3Smrg return PIPE_FORMAT_R8_UNORM; 847ec681f3Smrg default: 857ec681f3Smrg return format; 867ec681f3Smrg } 8701e04c3fSmrg} 88af69d88dSmrg 89af69d88dSmrgenum adreno_rb_blend_factor 90af69d88dSmrgfd_blend_factor(unsigned factor) 91af69d88dSmrg{ 927ec681f3Smrg switch (factor) { 937ec681f3Smrg case PIPE_BLENDFACTOR_ONE: 947ec681f3Smrg return FACTOR_ONE; 957ec681f3Smrg case PIPE_BLENDFACTOR_SRC_COLOR: 967ec681f3Smrg return FACTOR_SRC_COLOR; 977ec681f3Smrg case PIPE_BLENDFACTOR_SRC_ALPHA: 987ec681f3Smrg return FACTOR_SRC_ALPHA; 997ec681f3Smrg case PIPE_BLENDFACTOR_DST_ALPHA: 1007ec681f3Smrg return FACTOR_DST_ALPHA; 1017ec681f3Smrg case PIPE_BLENDFACTOR_DST_COLOR: 1027ec681f3Smrg return FACTOR_DST_COLOR; 1037ec681f3Smrg case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: 1047ec681f3Smrg return FACTOR_SRC_ALPHA_SATURATE; 1057ec681f3Smrg case PIPE_BLENDFACTOR_CONST_COLOR: 1067ec681f3Smrg return FACTOR_CONSTANT_COLOR; 1077ec681f3Smrg case PIPE_BLENDFACTOR_CONST_ALPHA: 1087ec681f3Smrg return FACTOR_CONSTANT_ALPHA; 1097ec681f3Smrg case PIPE_BLENDFACTOR_ZERO: 1107ec681f3Smrg case 0: 1117ec681f3Smrg return FACTOR_ZERO; 1127ec681f3Smrg case PIPE_BLENDFACTOR_INV_SRC_COLOR: 1137ec681f3Smrg return FACTOR_ONE_MINUS_SRC_COLOR; 1147ec681f3Smrg case PIPE_BLENDFACTOR_INV_SRC_ALPHA: 1157ec681f3Smrg return FACTOR_ONE_MINUS_SRC_ALPHA; 1167ec681f3Smrg case PIPE_BLENDFACTOR_INV_DST_ALPHA: 1177ec681f3Smrg return FACTOR_ONE_MINUS_DST_ALPHA; 1187ec681f3Smrg case PIPE_BLENDFACTOR_INV_DST_COLOR: 1197ec681f3Smrg return FACTOR_ONE_MINUS_DST_COLOR; 1207ec681f3Smrg case PIPE_BLENDFACTOR_INV_CONST_COLOR: 1217ec681f3Smrg return FACTOR_ONE_MINUS_CONSTANT_COLOR; 1227ec681f3Smrg case PIPE_BLENDFACTOR_INV_CONST_ALPHA: 1237ec681f3Smrg return FACTOR_ONE_MINUS_CONSTANT_ALPHA; 1247ec681f3Smrg case PIPE_BLENDFACTOR_INV_SRC1_COLOR: 1257ec681f3Smrg return FACTOR_ONE_MINUS_SRC1_COLOR; 1267ec681f3Smrg case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: 1277ec681f3Smrg return FACTOR_ONE_MINUS_SRC1_ALPHA; 1287ec681f3Smrg case PIPE_BLENDFACTOR_SRC1_COLOR: 1297ec681f3Smrg return FACTOR_SRC1_COLOR; 1307ec681f3Smrg case PIPE_BLENDFACTOR_SRC1_ALPHA: 1317ec681f3Smrg return FACTOR_SRC1_ALPHA; 1327ec681f3Smrg default: 1337ec681f3Smrg DBG("invalid blend factor: %x", factor); 1347ec681f3Smrg return 0; 1357ec681f3Smrg } 136af69d88dSmrg} 137af69d88dSmrg 138af69d88dSmrgenum adreno_pa_su_sc_draw 139af69d88dSmrgfd_polygon_mode(unsigned mode) 140af69d88dSmrg{ 1417ec681f3Smrg switch (mode) { 1427ec681f3Smrg case PIPE_POLYGON_MODE_POINT: 1437ec681f3Smrg return PC_DRAW_POINTS; 1447ec681f3Smrg case PIPE_POLYGON_MODE_LINE: 1457ec681f3Smrg return PC_DRAW_LINES; 1467ec681f3Smrg case PIPE_POLYGON_MODE_FILL: 1477ec681f3Smrg return PC_DRAW_TRIANGLES; 1487ec681f3Smrg default: 1497ec681f3Smrg DBG("invalid polygon mode: %u", mode); 1507ec681f3Smrg return 0; 1517ec681f3Smrg } 152af69d88dSmrg} 153af69d88dSmrg 154af69d88dSmrgenum adreno_stencil_op 155af69d88dSmrgfd_stencil_op(unsigned op) 156af69d88dSmrg{ 1577ec681f3Smrg switch (op) { 1587ec681f3Smrg case PIPE_STENCIL_OP_KEEP: 1597ec681f3Smrg return STENCIL_KEEP; 1607ec681f3Smrg case PIPE_STENCIL_OP_ZERO: 1617ec681f3Smrg return STENCIL_ZERO; 1627ec681f3Smrg case PIPE_STENCIL_OP_REPLACE: 1637ec681f3Smrg return STENCIL_REPLACE; 1647ec681f3Smrg case PIPE_STENCIL_OP_INCR: 1657ec681f3Smrg return STENCIL_INCR_CLAMP; 1667ec681f3Smrg case PIPE_STENCIL_OP_DECR: 1677ec681f3Smrg return STENCIL_DECR_CLAMP; 1687ec681f3Smrg case PIPE_STENCIL_OP_INCR_WRAP: 1697ec681f3Smrg return STENCIL_INCR_WRAP; 1707ec681f3Smrg case PIPE_STENCIL_OP_DECR_WRAP: 1717ec681f3Smrg return STENCIL_DECR_WRAP; 1727ec681f3Smrg case PIPE_STENCIL_OP_INVERT: 1737ec681f3Smrg return STENCIL_INVERT; 1747ec681f3Smrg default: 1757ec681f3Smrg DBG("invalid stencil op: %u", op); 1767ec681f3Smrg return 0; 1777ec681f3Smrg } 178af69d88dSmrg} 179