2 * Mesa 3-D graphics library
4 * Copyright (C) 2012-2013 LunarG, Inc.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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 NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Chia-I Wu <olv@lunarg.com>
31 #include "brw_defines.h"
33 #include "ilo_common.h"
38 ilo_init_format_functions(struct ilo_screen
*is
);
41 ilo_translate_color_format(enum pipe_format format
);
44 * Translate a pipe format to a hardware surface format suitable for
45 * the given purpose. Return -1 on errors.
47 * This is an inline function not only for performance reasons. There are
48 * caveats that the callers should that before calling this function.
51 ilo_translate_format(enum pipe_format format
, unsigned bind
)
54 case PIPE_BIND_RENDER_TARGET
:
56 * Some RGBX formats are not supported as render target formats. But we
57 * can use their RGBA counterparts and force the destination alpha to be
58 * one when blending is enabled.
61 case PIPE_FORMAT_B8G8R8X8_UNORM
:
62 return BRW_SURFACEFORMAT_B8G8R8A8_UNORM
;
64 return ilo_translate_color_format(format
);
67 case PIPE_BIND_SAMPLER_VIEW
:
69 * For depth formats, we want the depth values to be returned as R
70 * values. But we assume in many places that the depth values are
71 * returned as I values (util_make_fragment_tex_shader_writedepth() is
72 * one such example). We have to live with that at least for now.
75 case PIPE_FORMAT_Z16_UNORM
:
76 return BRW_SURFACEFORMAT_I16_UNORM
;
77 case PIPE_FORMAT_Z32_FLOAT
:
78 return BRW_SURFACEFORMAT_I32_FLOAT
;
79 case PIPE_FORMAT_Z24X8_UNORM
:
80 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
81 return BRW_SURFACEFORMAT_I24X8_UNORM
;
82 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
83 return BRW_SURFACEFORMAT_I32X32_FLOAT
;
85 return ilo_translate_color_format(format
);
88 case PIPE_BIND_VERTEX_BUFFER
:
90 * Some 3-component formats are not supported as vertex element formats.
91 * But since we move between vertices using vb->stride, we should be
92 * good to use their 4-component counterparts if we force the W
93 * component to be one. The only exception is that the vb boundary
94 * check for the last vertex may fail.
97 case PIPE_FORMAT_R16G16B16_FLOAT
:
98 return BRW_SURFACEFORMAT_R16G16B16A16_FLOAT
;
99 case PIPE_FORMAT_R16G16B16_UINT
:
100 return BRW_SURFACEFORMAT_R16G16B16A16_UINT
;
101 case PIPE_FORMAT_R16G16B16_SINT
:
102 return BRW_SURFACEFORMAT_R16G16B16A16_SINT
;
103 case PIPE_FORMAT_R8G8B8_UINT
:
104 return BRW_SURFACEFORMAT_R8G8B8A8_UINT
;
105 case PIPE_FORMAT_R8G8B8_SINT
:
106 return BRW_SURFACEFORMAT_R8G8B8A8_SINT
;
108 return ilo_translate_color_format(format
);
112 assert(!"cannot translate format");
120 ilo_translate_render_format(enum pipe_format format
)
122 return ilo_translate_format(format
, PIPE_BIND_RENDER_TARGET
);
126 ilo_translate_texture_format(enum pipe_format format
)
128 return ilo_translate_format(format
, PIPE_BIND_SAMPLER_VIEW
);
132 ilo_translate_vertex_format(enum pipe_format format
)
134 return ilo_translate_format(format
, PIPE_BIND_VERTEX_BUFFER
);
137 #endif /* ILO_FORMAT_H */