2 * Copyright 2009 Joakim Sindholt <opensource@zhasha.com>
3 * Corbin Simpson <MostAwesomeDude@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
24 #ifndef R300_STATE_INLINES_H
25 #define R300_STATE_INLINES_H
27 #include "pipe/p_format.h"
33 static INLINE
uint32_t r300_translate_blend_function(int blend_func
)
37 return R300_COMB_FCN_ADD_CLAMP
;
38 case PIPE_BLEND_SUBTRACT
:
39 return R300_COMB_FCN_SUB_CLAMP
;
40 case PIPE_BLEND_REVERSE_SUBTRACT
:
41 return R300_COMB_FCN_RSUB_CLAMP
;
43 return R300_COMB_FCN_MIN
;
45 return R300_COMB_FCN_MAX
;
47 debug_printf("r300: Unknown blend function %d\n", blend_func
);
53 /* XXX we can also offer the D3D versions of some of these... */
54 static INLINE
uint32_t r300_translate_blend_factor(int blend_fact
)
57 case PIPE_BLENDFACTOR_ONE
:
58 return R300_BLEND_GL_ONE
;
59 case PIPE_BLENDFACTOR_SRC_COLOR
:
60 return R300_BLEND_GL_SRC_COLOR
;
61 case PIPE_BLENDFACTOR_SRC_ALPHA
:
62 return R300_BLEND_GL_SRC_ALPHA
;
63 case PIPE_BLENDFACTOR_DST_ALPHA
:
64 return R300_BLEND_GL_DST_ALPHA
;
65 case PIPE_BLENDFACTOR_DST_COLOR
:
66 return R300_BLEND_GL_DST_COLOR
;
67 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
68 return R300_BLEND_GL_SRC_ALPHA_SATURATE
;
69 case PIPE_BLENDFACTOR_CONST_COLOR
:
70 return R300_BLEND_GL_CONST_COLOR
;
71 case PIPE_BLENDFACTOR_CONST_ALPHA
:
72 return R300_BLEND_GL_CONST_ALPHA
;
74 case PIPE_BLENDFACTOR_SRC1_COLOR:
75 case PIPE_BLENDFACTOR_SRC1_ALPHA: */
76 case PIPE_BLENDFACTOR_ZERO
:
77 return R300_BLEND_GL_ZERO
;
78 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
79 return R300_BLEND_GL_ONE_MINUS_SRC_COLOR
;
80 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
81 return R300_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
82 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
83 return R300_BLEND_GL_ONE_MINUS_DST_ALPHA
;
84 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
85 return R300_BLEND_GL_ONE_MINUS_DST_COLOR
;
86 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
87 return R300_BLEND_GL_ONE_MINUS_CONST_COLOR
;
88 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
89 return R300_BLEND_GL_ONE_MINUS_CONST_ALPHA
;
91 case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
92 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: */
94 debug_printf("r300: Unknown blend factor %d\n", blend_fact
);
102 static INLINE
uint32_t r300_translate_depth_stencil_function(int zs_func
)
105 case PIPE_FUNC_NEVER
:
106 return R300_ZS_NEVER
;
109 case PIPE_FUNC_EQUAL
:
110 return R300_ZS_EQUAL
;
111 case PIPE_FUNC_LEQUAL
:
112 return R300_ZS_LEQUAL
;
113 case PIPE_FUNC_GREATER
:
114 return R300_ZS_GREATER
;
115 case PIPE_FUNC_NOTEQUAL
:
116 return R300_ZS_NOTEQUAL
;
117 case PIPE_FUNC_GEQUAL
:
118 return R300_ZS_GEQUAL
;
119 case PIPE_FUNC_ALWAYS
:
120 return R300_ZS_ALWAYS
;
122 debug_printf("r300: Unknown depth/stencil function %d\n",
129 static INLINE
uint32_t r300_translate_stencil_op(int s_op
)
132 case PIPE_STENCIL_OP_KEEP
:
134 case PIPE_STENCIL_OP_ZERO
:
136 case PIPE_STENCIL_OP_REPLACE
:
137 return R300_ZS_REPLACE
;
138 case PIPE_STENCIL_OP_INCR
:
140 case PIPE_STENCIL_OP_DECR
:
142 case PIPE_STENCIL_OP_INCR_WRAP
:
143 return R300_ZS_INCR_WRAP
;
144 case PIPE_STENCIL_OP_DECR_WRAP
:
145 return R300_ZS_DECR_WRAP
;
146 case PIPE_STENCIL_OP_INVERT
:
147 return R300_ZS_INVERT
;
149 debug_printf("r300: Unknown stencil op %d", s_op
);
155 static INLINE
uint32_t r300_translate_alpha_function(int alpha_func
)
157 switch (alpha_func
) {
158 case PIPE_FUNC_NEVER
:
159 return R300_FG_ALPHA_FUNC_NEVER
;
161 return R300_FG_ALPHA_FUNC_LESS
;
162 case PIPE_FUNC_EQUAL
:
163 return R300_FG_ALPHA_FUNC_EQUAL
;
164 case PIPE_FUNC_LEQUAL
:
165 return R300_FG_ALPHA_FUNC_LE
;
166 case PIPE_FUNC_GREATER
:
167 return R300_FG_ALPHA_FUNC_GREATER
;
168 case PIPE_FUNC_NOTEQUAL
:
169 return R300_FG_ALPHA_FUNC_NOTEQUAL
;
170 case PIPE_FUNC_GEQUAL
:
171 return R300_FG_ALPHA_FUNC_GE
;
172 case PIPE_FUNC_ALWAYS
:
173 return R300_FG_ALPHA_FUNC_ALWAYS
;
175 debug_printf("r300: Unknown alpha function %d", alpha_func
);
181 /* Texture sampler state. */
183 static INLINE
uint32_t r300_translate_wrap(int wrap
)
186 case PIPE_TEX_WRAP_REPEAT
:
187 return R300_TX_REPEAT
;
188 case PIPE_TEX_WRAP_CLAMP
:
189 return R300_TX_CLAMP
;
190 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
191 return R300_TX_CLAMP_TO_EDGE
;
192 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
193 return R300_TX_CLAMP_TO_BORDER
;
194 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
195 return R300_TX_REPEAT
| R300_TX_MIRRORED
;
196 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
197 return R300_TX_CLAMP
| R300_TX_MIRRORED
;
198 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
199 return R300_TX_CLAMP_TO_EDGE
| R300_TX_MIRRORED
;
200 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
201 return R300_TX_CLAMP_TO_EDGE
| R300_TX_MIRRORED
;
203 debug_printf("r300: Unknown texture wrap %d", wrap
);
208 static INLINE
uint32_t r300_translate_tex_filters(int min
, int mag
, int mip
)
212 case PIPE_TEX_FILTER_NEAREST
:
213 retval
|= R300_TX_MIN_FILTER_NEAREST
;
214 case PIPE_TEX_FILTER_LINEAR
:
215 retval
|= R300_TX_MIN_FILTER_LINEAR
;
216 case PIPE_TEX_FILTER_ANISO
:
217 retval
|= R300_TX_MIN_FILTER_ANISO
;
219 debug_printf("r300: Unknown texture filter %d", min
);
223 case PIPE_TEX_FILTER_NEAREST
:
224 retval
|= R300_TX_MAG_FILTER_NEAREST
;
225 case PIPE_TEX_FILTER_LINEAR
:
226 retval
|= R300_TX_MAG_FILTER_LINEAR
;
227 case PIPE_TEX_FILTER_ANISO
:
228 retval
|= R300_TX_MAG_FILTER_ANISO
;
230 debug_printf("r300: Unknown texture filter %d", mag
);
234 case PIPE_TEX_MIPFILTER_NONE
:
235 retval
|= R300_TX_MIN_FILTER_MIP_NONE
;
236 case PIPE_TEX_MIPFILTER_NEAREST
:
237 retval
|= R300_TX_MIN_FILTER_MIP_NEAREST
;
238 case PIPE_TEX_MIPFILTER_LINEAR
:
239 retval
|= R300_TX_MIN_FILTER_MIP_LINEAR
;
241 debug_printf("r300: Unknown texture filter %d", mip
);
248 static INLINE
uint32_t r300_anisotropy(float max_aniso
)
250 if (max_aniso
>= 16.0f
) {
251 return R300_TX_MAX_ANISO_16_TO_1
;
252 } else if (max_aniso
>= 8.0f
) {
253 return R300_TX_MAX_ANISO_8_TO_1
;
254 } else if (max_aniso
>= 4.0f
) {
255 return R300_TX_MAX_ANISO_4_TO_1
;
256 } else if (max_aniso
>= 2.0f
) {
257 return R300_TX_MAX_ANISO_2_TO_1
;
259 return R300_TX_MAX_ANISO_1_TO_1
;
263 /* Buffer formats. */
265 static INLINE
uint32_t r300_translate_colorformat(enum pipe_format format
)
269 case PIPE_FORMAT_I8_UNORM
:
270 return R300_COLOR_FORMAT_I8
;
272 case PIPE_FORMAT_R5G6B5_UNORM
:
273 return R300_COLOR_FORMAT_RGB565
;
274 case PIPE_FORMAT_A1R5G5B5_UNORM
:
275 return R300_COLOR_FORMAT_ARGB1555
;
276 case PIPE_FORMAT_A4R4G4B4_UNORM
:
277 return R300_COLOR_FORMAT_ARGB4444
;
279 case PIPE_FORMAT_A8R8G8B8_UNORM
:
280 return R300_COLOR_FORMAT_ARGB8888
;
281 /* XXX Not in pipe_format
282 case PIPE_FORMAT_A32R32G32B32:
283 return R300_COLOR_FORMAT_ARGB32323232;
284 case PIPE_FORMAT_A16R16G16B16:
285 return R300_COLOR_FORMAT_ARGB16161616; */
286 /* XXX Not in pipe_format
287 case PIPE_FORMAT_A10R10G10B10_UNORM:
288 return R500_COLOR_FORMAT_ARGB10101010;
289 case PIPE_FORMAT_A2R10G10B10_UNORM:
290 return R500_COLOR_FORMAT_ARGB2101010;
291 case PIPE_FORMAT_I10_UNORM:
292 return R500_COLOR_FORMAT_I10; */
294 debug_printf("r300: Implementation error: " \
295 "Got unsupported color format %s in %s\n",
296 pf_name(format
), __FUNCTION__
);
302 static INLINE
uint32_t r300_translate_zsformat(enum pipe_format format
)
305 /* 16-bit depth, no stencil */
306 case PIPE_FORMAT_Z16_UNORM
:
307 return R300_DEPTHFORMAT_16BIT_INT_Z
;
308 /* 24-bit depth, 8-bit stencil */
309 case PIPE_FORMAT_Z24S8_UNORM
:
310 return R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL
;
312 debug_printf("r300: Implementation error: " \
313 "Got unsupported ZS format %s in %s\n",
314 pf_name(format
), __FUNCTION__
);
320 #endif /* R300_STATE_INLINES_H */