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