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.
74 * For ETC1 format, the texture data will be decompressed before being
75 * written to the bo. See tex_staging_sys_convert_write().
78 case PIPE_FORMAT_Z16_UNORM
:
79 return BRW_SURFACEFORMAT_I16_UNORM
;
80 case PIPE_FORMAT_Z32_FLOAT
:
81 return BRW_SURFACEFORMAT_I32_FLOAT
;
82 case PIPE_FORMAT_Z24X8_UNORM
:
83 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
84 return BRW_SURFACEFORMAT_I24X8_UNORM
;
85 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
86 return BRW_SURFACEFORMAT_I32X32_FLOAT
;
87 case PIPE_FORMAT_ETC1_RGB8
:
88 return BRW_SURFACEFORMAT_R8G8B8X8_UNORM
;
90 return ilo_translate_color_format(format
);
93 case PIPE_BIND_VERTEX_BUFFER
:
95 * Some 3-component formats are not supported as vertex element formats.
96 * But since we move between vertices using vb->stride, we should be
97 * good to use their 4-component counterparts if we force the W
98 * component to be one. The only exception is that the vb boundary
99 * check for the last vertex may fail.
102 case PIPE_FORMAT_R16G16B16_FLOAT
:
103 return BRW_SURFACEFORMAT_R16G16B16A16_FLOAT
;
104 case PIPE_FORMAT_R16G16B16_UINT
:
105 return BRW_SURFACEFORMAT_R16G16B16A16_UINT
;
106 case PIPE_FORMAT_R16G16B16_SINT
:
107 return BRW_SURFACEFORMAT_R16G16B16A16_SINT
;
108 case PIPE_FORMAT_R8G8B8_UINT
:
109 return BRW_SURFACEFORMAT_R8G8B8A8_UINT
;
110 case PIPE_FORMAT_R8G8B8_SINT
:
111 return BRW_SURFACEFORMAT_R8G8B8A8_SINT
;
113 return ilo_translate_color_format(format
);
117 assert(!"cannot translate format");
125 ilo_translate_render_format(enum pipe_format format
)
127 return ilo_translate_format(format
, PIPE_BIND_RENDER_TARGET
);
131 ilo_translate_texture_format(enum pipe_format format
)
133 return ilo_translate_format(format
, PIPE_BIND_SAMPLER_VIEW
);
137 ilo_translate_vertex_format(enum pipe_format format
)
139 return ilo_translate_format(format
, PIPE_BIND_VERTEX_BUFFER
);
142 #endif /* ILO_FORMAT_H */