Merge branch 'master' of ../mesa into vulkan
[mesa.git] / src / gallium / drivers / freedreno / freedreno_util.c
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
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
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
71 enum adreno_rb_blend_factor
72 fd_blend_factor(unsigned factor)
73 {
74 switch (factor) {
75 case PIPE_BLENDFACTOR_ONE:
76 return FACTOR_ONE;
77 case PIPE_BLENDFACTOR_SRC_COLOR:
78 return FACTOR_SRC_COLOR;
79 case PIPE_BLENDFACTOR_SRC_ALPHA:
80 return FACTOR_SRC_ALPHA;
81 case PIPE_BLENDFACTOR_DST_ALPHA:
82 return FACTOR_DST_ALPHA;
83 case PIPE_BLENDFACTOR_DST_COLOR:
84 return FACTOR_DST_COLOR;
85 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
86 return FACTOR_SRC_ALPHA_SATURATE;
87 case PIPE_BLENDFACTOR_CONST_COLOR:
88 return FACTOR_CONSTANT_COLOR;
89 case PIPE_BLENDFACTOR_CONST_ALPHA:
90 return FACTOR_CONSTANT_ALPHA;
91 case PIPE_BLENDFACTOR_ZERO:
92 case 0:
93 return FACTOR_ZERO;
94 case PIPE_BLENDFACTOR_INV_SRC_COLOR:
95 return FACTOR_ONE_MINUS_SRC_COLOR;
96 case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
97 return FACTOR_ONE_MINUS_SRC_ALPHA;
98 case PIPE_BLENDFACTOR_INV_DST_ALPHA:
99 return FACTOR_ONE_MINUS_DST_ALPHA;
100 case PIPE_BLENDFACTOR_INV_DST_COLOR:
101 return FACTOR_ONE_MINUS_DST_COLOR;
102 case PIPE_BLENDFACTOR_INV_CONST_COLOR:
103 return FACTOR_ONE_MINUS_CONSTANT_COLOR;
104 case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
105 return FACTOR_ONE_MINUS_CONSTANT_ALPHA;
106 case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
107 return FACTOR_ONE_MINUS_SRC1_COLOR;
108 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
109 return FACTOR_ONE_MINUS_SRC1_ALPHA;
110 case PIPE_BLENDFACTOR_SRC1_COLOR:
111 return FACTOR_SRC1_COLOR;
112 case PIPE_BLENDFACTOR_SRC1_ALPHA:
113 return FACTOR_SRC1_ALPHA;
114 default:
115 DBG("invalid blend factor: %x", factor);
116 return 0;
117 }
118 }
119
120 enum adreno_pa_su_sc_draw
121 fd_polygon_mode(unsigned mode)
122 {
123 switch (mode) {
124 case PIPE_POLYGON_MODE_POINT:
125 return PC_DRAW_POINTS;
126 case PIPE_POLYGON_MODE_LINE:
127 return PC_DRAW_LINES;
128 case PIPE_POLYGON_MODE_FILL:
129 return PC_DRAW_TRIANGLES;
130 default:
131 DBG("invalid polygon mode: %u", mode);
132 return 0;
133 }
134 }
135
136 enum adreno_stencil_op
137 fd_stencil_op(unsigned op)
138 {
139 switch (op) {
140 case PIPE_STENCIL_OP_KEEP:
141 return STENCIL_KEEP;
142 case PIPE_STENCIL_OP_ZERO:
143 return STENCIL_ZERO;
144 case PIPE_STENCIL_OP_REPLACE:
145 return STENCIL_REPLACE;
146 case PIPE_STENCIL_OP_INCR:
147 return STENCIL_INCR_CLAMP;
148 case PIPE_STENCIL_OP_DECR:
149 return STENCIL_DECR_CLAMP;
150 case PIPE_STENCIL_OP_INCR_WRAP:
151 return STENCIL_INCR_WRAP;
152 case PIPE_STENCIL_OP_DECR_WRAP:
153 return STENCIL_DECR_WRAP;
154 case PIPE_STENCIL_OP_INVERT:
155 return STENCIL_INVERT;
156 default:
157 DBG("invalid stencil op: %u", op);
158 return 0;
159 }
160 }