summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/freedreno/freedreno_util.c
blob: bf1e05ba740ac0f4089b1cfa0d3b44539f56d699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Authors:
 *    Rob Clark <robclark@freedesktop.org>
 */

#include "pipe/p_defines.h"
#include "util/format/u_format.h"

#include "freedreno_util.h"

unsigned marker_cnt;

enum adreno_rb_depth_format
fd_pipe2depth(enum pipe_format format)
{
	switch (format) {
	case PIPE_FORMAT_Z16_UNORM:
		return DEPTHX_16;
	case PIPE_FORMAT_Z24X8_UNORM:
	case PIPE_FORMAT_Z24_UNORM_S8_UINT:
	case PIPE_FORMAT_X8Z24_UNORM:
	case PIPE_FORMAT_S8_UINT_Z24_UNORM:
		return DEPTHX_24_8;
	case PIPE_FORMAT_Z32_FLOAT:
	case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
		return DEPTHX_32;
	default:
		return ~0;
	}
}

enum pc_di_index_size
fd_pipe2index(enum pipe_format format)
{
	switch (format) {
	case PIPE_FORMAT_I8_UINT:
		return INDEX_SIZE_8_BIT;
	case PIPE_FORMAT_I16_UINT:
		return INDEX_SIZE_16_BIT;
	case PIPE_FORMAT_I32_UINT:
		return INDEX_SIZE_32_BIT;
	default:
		return ~0;
	}
}

/* we need to special case a bit the depth/stencil restore, because we are
 * using the texture sampler to blit into the depth/stencil buffer, *not*
 * into a color buffer.  Otherwise fdN_tex_swiz() will do the wrong thing,
 * as it is assuming that you are sampling into normal render target..
 */
enum pipe_format
fd_gmem_restore_format(enum pipe_format format)
{
	switch (format) {
	case PIPE_FORMAT_Z24X8_UNORM:
	case PIPE_FORMAT_Z24_UNORM_S8_UINT:
		return PIPE_FORMAT_R8G8B8A8_UNORM;
	case PIPE_FORMAT_Z16_UNORM:
		return PIPE_FORMAT_R8G8_UNORM;
	case PIPE_FORMAT_S8_UINT:
		return PIPE_FORMAT_R8_UNORM;
	default:
		return format;
	}
}

enum adreno_rb_blend_factor
fd_blend_factor(unsigned factor)
{
	switch (factor) {
	case PIPE_BLENDFACTOR_ONE:
		return FACTOR_ONE;
	case PIPE_BLENDFACTOR_SRC_COLOR:
		return FACTOR_SRC_COLOR;
	case PIPE_BLENDFACTOR_SRC_ALPHA:
		return FACTOR_SRC_ALPHA;
	case PIPE_BLENDFACTOR_DST_ALPHA:
		return FACTOR_DST_ALPHA;
	case PIPE_BLENDFACTOR_DST_COLOR:
		return FACTOR_DST_COLOR;
	case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
		return FACTOR_SRC_ALPHA_SATURATE;
	case PIPE_BLENDFACTOR_CONST_COLOR:
		return FACTOR_CONSTANT_COLOR;
	case PIPE_BLENDFACTOR_CONST_ALPHA:
		return FACTOR_CONSTANT_ALPHA;
	case PIPE_BLENDFACTOR_ZERO:
	case 0:
		return FACTOR_ZERO;
	case PIPE_BLENDFACTOR_INV_SRC_COLOR:
		return FACTOR_ONE_MINUS_SRC_COLOR;
	case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
		return FACTOR_ONE_MINUS_SRC_ALPHA;
	case PIPE_BLENDFACTOR_INV_DST_ALPHA:
		return FACTOR_ONE_MINUS_DST_ALPHA;
	case PIPE_BLENDFACTOR_INV_DST_COLOR:
		return FACTOR_ONE_MINUS_DST_COLOR;
	case PIPE_BLENDFACTOR_INV_CONST_COLOR:
		return FACTOR_ONE_MINUS_CONSTANT_COLOR;
	case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
		return FACTOR_ONE_MINUS_CONSTANT_ALPHA;
	case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
		return FACTOR_ONE_MINUS_SRC1_COLOR;
	case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
		return FACTOR_ONE_MINUS_SRC1_ALPHA;
	case PIPE_BLENDFACTOR_SRC1_COLOR:
		return FACTOR_SRC1_COLOR;
	case PIPE_BLENDFACTOR_SRC1_ALPHA:
		return FACTOR_SRC1_ALPHA;
	default:
		DBG("invalid blend factor: %x", factor);
		return 0;
	}
}

enum adreno_pa_su_sc_draw
fd_polygon_mode(unsigned mode)
{
	switch (mode) {
	case PIPE_POLYGON_MODE_POINT:
		return PC_DRAW_POINTS;
	case PIPE_POLYGON_MODE_LINE:
		return PC_DRAW_LINES;
	case PIPE_POLYGON_MODE_FILL:
		return PC_DRAW_TRIANGLES;
	default:
		DBG("invalid polygon mode: %u", mode);
		return 0;
	}
}

enum adreno_stencil_op
fd_stencil_op(unsigned op)
{
	switch (op) {
	case PIPE_STENCIL_OP_KEEP:
		return STENCIL_KEEP;
	case PIPE_STENCIL_OP_ZERO:
		return STENCIL_ZERO;
	case PIPE_STENCIL_OP_REPLACE:
		return STENCIL_REPLACE;
	case PIPE_STENCIL_OP_INCR:
		return STENCIL_INCR_CLAMP;
	case PIPE_STENCIL_OP_DECR:
		return STENCIL_DECR_CLAMP;
	case PIPE_STENCIL_OP_INCR_WRAP:
		return STENCIL_INCR_WRAP;
	case PIPE_STENCIL_OP_DECR_WRAP:
		return STENCIL_DECR_WRAP;
	case PIPE_STENCIL_OP_INVERT:
		return STENCIL_INVERT;
	default:
		DBG("invalid stencil op: %u", op);
		return 0;
	}
}