1848b8605Smrg/*
2848b8605Smrg * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
3848b8605Smrg *
4848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5848b8605Smrg * copy of this software and associated documentation files (the "Software"),
6848b8605Smrg * to deal in the Software without restriction, including without limitation
7848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
9848b8605Smrg * Software is furnished to do so, subject to the following conditions:
10848b8605Smrg *
11848b8605Smrg * The above copyright notice and this permission notice (including the next
12848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the
13848b8605Smrg * Software.
14848b8605Smrg *
15848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19848b8605Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20848b8605Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21848b8605Smrg * SOFTWARE.
22848b8605Smrg *
23848b8605Smrg * Authors:
24848b8605Smrg *    Rob Clark <robclark@freedesktop.org>
25848b8605Smrg */
26848b8605Smrg
27848b8605Smrg#include "pipe/p_defines.h"
28848b8605Smrg#include "util/u_format.h"
29848b8605Smrg
30848b8605Smrg#include "freedreno_util.h"
31848b8605Smrg
32848b8605Smrgunsigned marker_cnt;
33848b8605Smrg
34848b8605Smrgenum adreno_rb_depth_format
35848b8605Smrgfd_pipe2depth(enum pipe_format format)
36848b8605Smrg{
37848b8605Smrg	switch (format) {
38848b8605Smrg	case PIPE_FORMAT_Z16_UNORM:
39848b8605Smrg		return DEPTHX_16;
40848b8605Smrg	case PIPE_FORMAT_Z24X8_UNORM:
41848b8605Smrg	case PIPE_FORMAT_Z24_UNORM_S8_UINT:
42848b8605Smrg	case PIPE_FORMAT_X8Z24_UNORM:
43848b8605Smrg	case PIPE_FORMAT_S8_UINT_Z24_UNORM:
44848b8605Smrg		return DEPTHX_24_8;
45b8e80941Smrg	case PIPE_FORMAT_Z32_FLOAT:
46b8e80941Smrg	case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
47b8e80941Smrg		return DEPTHX_32;
48848b8605Smrg	default:
49848b8605Smrg		return ~0;
50848b8605Smrg	}
51848b8605Smrg}
52848b8605Smrg
53848b8605Smrgenum pc_di_index_size
54848b8605Smrgfd_pipe2index(enum pipe_format format)
55848b8605Smrg{
56848b8605Smrg	switch (format) {
57848b8605Smrg	case PIPE_FORMAT_I8_UINT:
58848b8605Smrg		return INDEX_SIZE_8_BIT;
59848b8605Smrg	case PIPE_FORMAT_I16_UINT:
60848b8605Smrg		return INDEX_SIZE_16_BIT;
61848b8605Smrg	case PIPE_FORMAT_I32_UINT:
62848b8605Smrg		return INDEX_SIZE_32_BIT;
63848b8605Smrg	default:
64848b8605Smrg		return ~0;
65848b8605Smrg	}
66848b8605Smrg}
67848b8605Smrg
68b8e80941Smrg/* we need to special case a bit the depth/stencil restore, because we are
69b8e80941Smrg * using the texture sampler to blit into the depth/stencil buffer, *not*
70b8e80941Smrg * into a color buffer.  Otherwise fdN_tex_swiz() will do the wrong thing,
71b8e80941Smrg * as it is assuming that you are sampling into normal render target..
72b8e80941Smrg */
73b8e80941Smrgenum pipe_format
74b8e80941Smrgfd_gmem_restore_format(enum pipe_format format)
75b8e80941Smrg{
76b8e80941Smrg	switch (format) {
77b8e80941Smrg	case PIPE_FORMAT_Z24X8_UNORM:
78b8e80941Smrg	case PIPE_FORMAT_Z24_UNORM_S8_UINT:
79b8e80941Smrg		return PIPE_FORMAT_R8G8B8A8_UNORM;
80b8e80941Smrg	case PIPE_FORMAT_Z16_UNORM:
81b8e80941Smrg		return PIPE_FORMAT_R8G8_UNORM;
82b8e80941Smrg	case PIPE_FORMAT_S8_UINT:
83b8e80941Smrg		return PIPE_FORMAT_R8_UNORM;
84b8e80941Smrg	default:
85b8e80941Smrg		return format;
86b8e80941Smrg	}
87b8e80941Smrg}
88848b8605Smrg
89848b8605Smrgenum adreno_rb_blend_factor
90848b8605Smrgfd_blend_factor(unsigned factor)
91848b8605Smrg{
92848b8605Smrg	switch (factor) {
93848b8605Smrg	case PIPE_BLENDFACTOR_ONE:
94848b8605Smrg		return FACTOR_ONE;
95848b8605Smrg	case PIPE_BLENDFACTOR_SRC_COLOR:
96848b8605Smrg		return FACTOR_SRC_COLOR;
97848b8605Smrg	case PIPE_BLENDFACTOR_SRC_ALPHA:
98848b8605Smrg		return FACTOR_SRC_ALPHA;
99848b8605Smrg	case PIPE_BLENDFACTOR_DST_ALPHA:
100848b8605Smrg		return FACTOR_DST_ALPHA;
101848b8605Smrg	case PIPE_BLENDFACTOR_DST_COLOR:
102848b8605Smrg		return FACTOR_DST_COLOR;
103848b8605Smrg	case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
104848b8605Smrg		return FACTOR_SRC_ALPHA_SATURATE;
105848b8605Smrg	case PIPE_BLENDFACTOR_CONST_COLOR:
106848b8605Smrg		return FACTOR_CONSTANT_COLOR;
107848b8605Smrg	case PIPE_BLENDFACTOR_CONST_ALPHA:
108848b8605Smrg		return FACTOR_CONSTANT_ALPHA;
109848b8605Smrg	case PIPE_BLENDFACTOR_ZERO:
110848b8605Smrg	case 0:
111848b8605Smrg		return FACTOR_ZERO;
112848b8605Smrg	case PIPE_BLENDFACTOR_INV_SRC_COLOR:
113848b8605Smrg		return FACTOR_ONE_MINUS_SRC_COLOR;
114848b8605Smrg	case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
115848b8605Smrg		return FACTOR_ONE_MINUS_SRC_ALPHA;
116848b8605Smrg	case PIPE_BLENDFACTOR_INV_DST_ALPHA:
117848b8605Smrg		return FACTOR_ONE_MINUS_DST_ALPHA;
118848b8605Smrg	case PIPE_BLENDFACTOR_INV_DST_COLOR:
119848b8605Smrg		return FACTOR_ONE_MINUS_DST_COLOR;
120848b8605Smrg	case PIPE_BLENDFACTOR_INV_CONST_COLOR:
121848b8605Smrg		return FACTOR_ONE_MINUS_CONSTANT_COLOR;
122848b8605Smrg	case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
123848b8605Smrg		return FACTOR_ONE_MINUS_CONSTANT_ALPHA;
124848b8605Smrg	case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
125b8e80941Smrg		return FACTOR_ONE_MINUS_SRC1_COLOR;
126848b8605Smrg	case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
127b8e80941Smrg		return FACTOR_ONE_MINUS_SRC1_ALPHA;
128848b8605Smrg	case PIPE_BLENDFACTOR_SRC1_COLOR:
129b8e80941Smrg		return FACTOR_SRC1_COLOR;
130848b8605Smrg	case PIPE_BLENDFACTOR_SRC1_ALPHA:
131b8e80941Smrg		return FACTOR_SRC1_ALPHA;
132848b8605Smrg	default:
133848b8605Smrg		DBG("invalid blend factor: %x", factor);
134848b8605Smrg		return 0;
135848b8605Smrg	}
136848b8605Smrg}
137848b8605Smrg
138848b8605Smrgenum adreno_pa_su_sc_draw
139848b8605Smrgfd_polygon_mode(unsigned mode)
140848b8605Smrg{
141848b8605Smrg	switch (mode) {
142848b8605Smrg	case PIPE_POLYGON_MODE_POINT:
143848b8605Smrg		return PC_DRAW_POINTS;
144848b8605Smrg	case PIPE_POLYGON_MODE_LINE:
145848b8605Smrg		return PC_DRAW_LINES;
146848b8605Smrg	case PIPE_POLYGON_MODE_FILL:
147848b8605Smrg		return PC_DRAW_TRIANGLES;
148848b8605Smrg	default:
149848b8605Smrg		DBG("invalid polygon mode: %u", mode);
150848b8605Smrg		return 0;
151848b8605Smrg	}
152848b8605Smrg}
153848b8605Smrg
154848b8605Smrgenum adreno_stencil_op
155848b8605Smrgfd_stencil_op(unsigned op)
156848b8605Smrg{
157848b8605Smrg	switch (op) {
158848b8605Smrg	case PIPE_STENCIL_OP_KEEP:
159848b8605Smrg		return STENCIL_KEEP;
160848b8605Smrg	case PIPE_STENCIL_OP_ZERO:
161848b8605Smrg		return STENCIL_ZERO;
162848b8605Smrg	case PIPE_STENCIL_OP_REPLACE:
163848b8605Smrg		return STENCIL_REPLACE;
164848b8605Smrg	case PIPE_STENCIL_OP_INCR:
165848b8605Smrg		return STENCIL_INCR_CLAMP;
166848b8605Smrg	case PIPE_STENCIL_OP_DECR:
167848b8605Smrg		return STENCIL_DECR_CLAMP;
168848b8605Smrg	case PIPE_STENCIL_OP_INCR_WRAP:
169848b8605Smrg		return STENCIL_INCR_WRAP;
170848b8605Smrg	case PIPE_STENCIL_OP_DECR_WRAP:
171848b8605Smrg		return STENCIL_DECR_WRAP;
172848b8605Smrg	case PIPE_STENCIL_OP_INVERT:
173848b8605Smrg		return STENCIL_INVERT;
174848b8605Smrg	default:
175848b8605Smrg		DBG("invalid stencil op: %u", op);
176848b8605Smrg		return 0;
177848b8605Smrg	}
178848b8605Smrg}
179