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"
31 /* Some maths. These should probably find their way to u_math, if needed. */
33 static INLINE
int pack_float_16_6x(float f
) {
34 return ((int)(f
* 6.0) & 0xffff);
39 static INLINE
uint32_t r300_translate_blend_function(int blend_func
)
43 return R300_COMB_FCN_ADD_CLAMP
;
44 case PIPE_BLEND_SUBTRACT
:
45 return R300_COMB_FCN_SUB_CLAMP
;
46 case PIPE_BLEND_REVERSE_SUBTRACT
:
47 return R300_COMB_FCN_RSUB_CLAMP
;
49 return R300_COMB_FCN_MIN
;
51 return R300_COMB_FCN_MAX
;
53 debug_printf("r300: Unknown blend function %d\n", blend_func
);
59 /* XXX we can also offer the D3D versions of some of these... */
60 static INLINE
uint32_t r300_translate_blend_factor(int blend_fact
)
63 case PIPE_BLENDFACTOR_ONE
:
64 return R300_BLEND_GL_ONE
;
65 case PIPE_BLENDFACTOR_SRC_COLOR
:
66 return R300_BLEND_GL_SRC_COLOR
;
67 case PIPE_BLENDFACTOR_SRC_ALPHA
:
68 return R300_BLEND_GL_SRC_ALPHA
;
69 case PIPE_BLENDFACTOR_DST_ALPHA
:
70 return R300_BLEND_GL_DST_ALPHA
;
71 case PIPE_BLENDFACTOR_DST_COLOR
:
72 return R300_BLEND_GL_DST_COLOR
;
73 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
74 return R300_BLEND_GL_SRC_ALPHA_SATURATE
;
75 case PIPE_BLENDFACTOR_CONST_COLOR
:
76 return R300_BLEND_GL_CONST_COLOR
;
77 case PIPE_BLENDFACTOR_CONST_ALPHA
:
78 return R300_BLEND_GL_CONST_ALPHA
;
80 case PIPE_BLENDFACTOR_SRC1_COLOR:
81 case PIPE_BLENDFACTOR_SRC1_ALPHA: */
82 case PIPE_BLENDFACTOR_ZERO
:
83 return R300_BLEND_GL_ZERO
;
84 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
85 return R300_BLEND_GL_ONE_MINUS_SRC_COLOR
;
86 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
87 return R300_BLEND_GL_ONE_MINUS_SRC_ALPHA
;
88 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
89 return R300_BLEND_GL_ONE_MINUS_DST_ALPHA
;
90 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
91 return R300_BLEND_GL_ONE_MINUS_DST_COLOR
;
92 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
93 return R300_BLEND_GL_ONE_MINUS_CONST_COLOR
;
94 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
95 return R300_BLEND_GL_ONE_MINUS_CONST_ALPHA
;
97 case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
98 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: */
100 debug_printf("r300: Unknown blend factor %d\n", blend_fact
);
108 static INLINE
uint32_t r300_translate_depth_stencil_function(int zs_func
)
111 case PIPE_FUNC_NEVER
:
112 return R300_ZS_NEVER
;
115 case PIPE_FUNC_EQUAL
:
116 return R300_ZS_EQUAL
;
117 case PIPE_FUNC_LEQUAL
:
118 return R300_ZS_LEQUAL
;
119 case PIPE_FUNC_GREATER
:
120 return R300_ZS_GREATER
;
121 case PIPE_FUNC_NOTEQUAL
:
122 return R300_ZS_NOTEQUAL
;
123 case PIPE_FUNC_GEQUAL
:
124 return R300_ZS_GEQUAL
;
125 case PIPE_FUNC_ALWAYS
:
126 return R300_ZS_ALWAYS
;
128 debug_printf("r300: Unknown depth/stencil function %d\n",
135 static INLINE
uint32_t r300_translate_stencil_op(int s_op
)
138 case PIPE_STENCIL_OP_KEEP
:
140 case PIPE_STENCIL_OP_ZERO
:
142 case PIPE_STENCIL_OP_REPLACE
:
143 return R300_ZS_REPLACE
;
144 case PIPE_STENCIL_OP_INCR
:
146 case PIPE_STENCIL_OP_DECR
:
148 case PIPE_STENCIL_OP_INCR_WRAP
:
149 return R300_ZS_INCR_WRAP
;
150 case PIPE_STENCIL_OP_DECR_WRAP
:
151 return R300_ZS_DECR_WRAP
;
152 case PIPE_STENCIL_OP_INVERT
:
153 return R300_ZS_INVERT
;
155 debug_printf("r300: Unknown stencil op %d", s_op
);
161 static INLINE
uint32_t r300_translate_alpha_function(int alpha_func
)
163 switch (alpha_func
) {
164 case PIPE_FUNC_NEVER
:
165 return R300_FG_ALPHA_FUNC_NEVER
;
167 return R300_FG_ALPHA_FUNC_LESS
;
168 case PIPE_FUNC_EQUAL
:
169 return R300_FG_ALPHA_FUNC_EQUAL
;
170 case PIPE_FUNC_LEQUAL
:
171 return R300_FG_ALPHA_FUNC_LE
;
172 case PIPE_FUNC_GREATER
:
173 return R300_FG_ALPHA_FUNC_GREATER
;
174 case PIPE_FUNC_NOTEQUAL
:
175 return R300_FG_ALPHA_FUNC_NOTEQUAL
;
176 case PIPE_FUNC_GEQUAL
:
177 return R300_FG_ALPHA_FUNC_GE
;
178 case PIPE_FUNC_ALWAYS
:
179 return R300_FG_ALPHA_FUNC_ALWAYS
;
181 debug_printf("r300: Unknown alpha function %d", alpha_func
);
187 /* Texture sampler state. */
189 static INLINE
uint32_t r300_translate_wrap(int wrap
)
192 case PIPE_TEX_WRAP_REPEAT
:
193 return R300_TX_REPEAT
;
194 case PIPE_TEX_WRAP_CLAMP
:
195 return R300_TX_CLAMP
;
196 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
197 return R300_TX_CLAMP_TO_EDGE
;
198 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
199 return R300_TX_CLAMP_TO_BORDER
;
200 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
201 return R300_TX_REPEAT
| R300_TX_MIRRORED
;
202 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
203 return R300_TX_CLAMP
| R300_TX_MIRRORED
;
204 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
205 return R300_TX_CLAMP_TO_EDGE
| R300_TX_MIRRORED
;
206 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
207 return R300_TX_CLAMP_TO_EDGE
| R300_TX_MIRRORED
;
209 debug_printf("r300: Unknown texture wrap %d", wrap
);
214 static INLINE
uint32_t r300_translate_tex_filters(int min
, int mag
, int mip
)
218 case PIPE_TEX_FILTER_NEAREST
:
219 retval
|= R300_TX_MIN_FILTER_NEAREST
;
220 case PIPE_TEX_FILTER_LINEAR
:
221 retval
|= R300_TX_MIN_FILTER_LINEAR
;
222 case PIPE_TEX_FILTER_ANISO
:
223 retval
|= R300_TX_MIN_FILTER_ANISO
;
225 debug_printf("r300: Unknown texture filter %d", min
);
229 case PIPE_TEX_FILTER_NEAREST
:
230 retval
|= R300_TX_MAG_FILTER_NEAREST
;
231 case PIPE_TEX_FILTER_LINEAR
:
232 retval
|= R300_TX_MAG_FILTER_LINEAR
;
233 case PIPE_TEX_FILTER_ANISO
:
234 retval
|= R300_TX_MAG_FILTER_ANISO
;
236 debug_printf("r300: Unknown texture filter %d", mag
);
240 case PIPE_TEX_MIPFILTER_NONE
:
241 retval
|= R300_TX_MIN_FILTER_MIP_NONE
;
242 case PIPE_TEX_MIPFILTER_NEAREST
:
243 retval
|= R300_TX_MIN_FILTER_MIP_NEAREST
;
244 case PIPE_TEX_MIPFILTER_LINEAR
:
245 retval
|= R300_TX_MIN_FILTER_MIP_LINEAR
;
247 debug_printf("r300: Unknown texture filter %d", mip
);
254 static INLINE
uint32_t r300_anisotropy(float max_aniso
)
256 if (max_aniso
>= 16.0f
) {
257 return R300_TX_MAX_ANISO_16_TO_1
;
258 } else if (max_aniso
>= 8.0f
) {
259 return R300_TX_MAX_ANISO_8_TO_1
;
260 } else if (max_aniso
>= 4.0f
) {
261 return R300_TX_MAX_ANISO_4_TO_1
;
262 } else if (max_aniso
>= 2.0f
) {
263 return R300_TX_MAX_ANISO_2_TO_1
;
265 return R300_TX_MAX_ANISO_1_TO_1
;
269 /* Buffer formats. */
271 static INLINE
uint32_t r300_translate_colorformat(enum pipe_format format
)
275 case PIPE_FORMAT_I8_UNORM
:
276 return R300_COLOR_FORMAT_I8
;
278 case PIPE_FORMAT_R5G6B5_UNORM
:
279 return R300_COLOR_FORMAT_RGB565
;
280 case PIPE_FORMAT_A1R5G5B5_UNORM
:
281 return R300_COLOR_FORMAT_ARGB1555
;
282 case PIPE_FORMAT_A4R4G4B4_UNORM
:
283 return R300_COLOR_FORMAT_ARGB4444
;
285 case PIPE_FORMAT_A8R8G8B8_UNORM
:
286 return R300_COLOR_FORMAT_ARGB8888
;
287 /* XXX Not in pipe_format
288 case PIPE_FORMAT_A32R32G32B32:
289 return R300_COLOR_FORMAT_ARGB32323232;
290 case PIPE_FORMAT_A16R16G16B16:
291 return R300_COLOR_FORMAT_ARGB16161616; */
292 /* XXX Not in pipe_format
293 case PIPE_FORMAT_A10R10G10B10_UNORM:
294 return R500_COLOR_FORMAT_ARGB10101010;
295 case PIPE_FORMAT_A2R10G10B10_UNORM:
296 return R500_COLOR_FORMAT_ARGB2101010;
297 case PIPE_FORMAT_I10_UNORM:
298 return R500_COLOR_FORMAT_I10; */
300 debug_printf("r300: Implementation error: " \
301 "Got unsupported color format %s in %s\n",
302 pf_name(format
), __FUNCTION__
);
308 static INLINE
uint32_t r300_translate_zsformat(enum pipe_format format
)
311 /* 16-bit depth, no stencil */
312 case PIPE_FORMAT_Z16_UNORM
:
313 return R300_DEPTHFORMAT_16BIT_INT_Z
;
314 /* 24-bit depth, 8-bit stencil */
315 case PIPE_FORMAT_Z24S8_UNORM
:
316 return R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL
;
318 debug_printf("r300: Implementation error: " \
319 "Got unsupported ZS format %s in %s\n",
320 pf_name(format
), __FUNCTION__
);
326 /* Non-CSO state. (For now.) */
328 static INLINE
uint32_t r300_translate_gb_pipes(int pipe_count
)
330 switch (pipe_count
) {
332 return R300_GB_TILE_PIPE_COUNT_RV300
;
335 return R300_GB_TILE_PIPE_COUNT_R300
;
338 return R300_GB_TILE_PIPE_COUNT_R420_3P
;
341 return R300_GB_TILE_PIPE_COUNT_R420
;
347 static INLINE
uint32_t translate_vertex_data_type(int type
) {
351 return R300_DATA_TYPE_FLOAT_1
;
354 return R300_DATA_TYPE_FLOAT_2
;
357 return R300_DATA_TYPE_FLOAT_3
;
360 return R300_DATA_TYPE_FLOAT_4
;
363 return R300_DATA_TYPE_BYTE
;
366 debug_printf("r300: Implementation error: "
367 "Bad vertex data type!\n");
375 #endif /* R300_STATE_INLINES_H */