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