diff options
author | Chia-I Wu <[email protected]> | 2012-12-13 04:43:01 +0800 |
---|---|---|
committer | Chia-I Wu <[email protected]> | 2013-04-26 16:16:42 +0800 |
commit | b50e68cb67534bd9e648b5cb687949d9327ee011 (patch) | |
tree | 8a214545cca80ecd93ec01574624894daa1bfcde /src/gallium/drivers/ilo/ilo_format.h | |
parent | babb2b5c50a5ea6b9410b1175fd36257190b269d (diff) |
ilo: hook up pipe screen format functions
Diffstat (limited to 'src/gallium/drivers/ilo/ilo_format.h')
-rw-r--r-- | src/gallium/drivers/ilo/ilo_format.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/gallium/drivers/ilo/ilo_format.h b/src/gallium/drivers/ilo/ilo_format.h index a1f76382290..556b21887c3 100644 --- a/src/gallium/drivers/ilo/ilo_format.h +++ b/src/gallium/drivers/ilo/ilo_format.h @@ -28,6 +28,8 @@ #ifndef ILO_FORMAT_H #define ILO_FORMAT_H +#include "brw_defines.h" + #include "ilo_common.h" struct ilo_screen; @@ -35,4 +37,101 @@ struct ilo_screen; void ilo_init_format_functions(struct ilo_screen *is); +int +ilo_translate_color_format(enum pipe_format format); + +/** + * Translate a pipe format to a hardware surface format suitable for + * the given purpose. Return -1 on errors. + * + * This is an inline function not only for performance reasons. There are + * caveats that the callers should that before calling this function. + */ +static inline int +ilo_translate_format(enum pipe_format format, unsigned bind) +{ + switch (bind) { + case PIPE_BIND_RENDER_TARGET: + /* + * Some RGBX formats are not supported as render target formats. But we + * can use their RGBA counterparts and force the destination alpha to be + * one when blending is enabled. + */ + switch (format) { + case PIPE_FORMAT_B8G8R8X8_UNORM: + return BRW_SURFACEFORMAT_B8G8R8A8_UNORM; + default: + return ilo_translate_color_format(format); + } + break; + case PIPE_BIND_SAMPLER_VIEW: + /* + * For depth formats, we want the depth values to be returned as R + * values. But we assume in many places that the depth values are + * returned as I values (util_make_fragment_tex_shader_writedepth() is + * one such example). We have to live with that at least for now. + */ + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + return BRW_SURFACEFORMAT_I16_UNORM; + case PIPE_FORMAT_Z32_FLOAT: + return BRW_SURFACEFORMAT_I32_FLOAT; + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24_UNORM_S8_UINT: + return BRW_SURFACEFORMAT_I24X8_UNORM; + case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: + return BRW_SURFACEFORMAT_I32X32_FLOAT; + default: + return ilo_translate_color_format(format); + } + break; + case PIPE_BIND_VERTEX_BUFFER: + /* + * Some 3-component formats are not supported as vertex element formats. + * But since we move between vertices using vb->stride, we should be + * good to use their 4-component counterparts if we force the W + * component to be one. The only exception is that the vb boundary + * check for the last vertex may fail. + */ + switch (format) { + case PIPE_FORMAT_R16G16B16_FLOAT: + return BRW_SURFACEFORMAT_R16G16B16A16_FLOAT; + case PIPE_FORMAT_R16G16B16_UINT: + return BRW_SURFACEFORMAT_R16G16B16A16_UINT; + case PIPE_FORMAT_R16G16B16_SINT: + return BRW_SURFACEFORMAT_R16G16B16A16_SINT; + case PIPE_FORMAT_R8G8B8_UINT: + return BRW_SURFACEFORMAT_R8G8B8A8_UINT; + case PIPE_FORMAT_R8G8B8_SINT: + return BRW_SURFACEFORMAT_R8G8B8A8_SINT; + default: + return ilo_translate_color_format(format); + } + break; + default: + assert(!"cannot translate format"); + break; + } + + return -1; +} + +static inline int +ilo_translate_render_format(enum pipe_format format) +{ + return ilo_translate_format(format, PIPE_BIND_RENDER_TARGET); +} + +static inline int +ilo_translate_texture_format(enum pipe_format format) +{ + return ilo_translate_format(format, PIPE_BIND_SAMPLER_VIEW); +} + +static inline int +ilo_translate_vertex_format(enum pipe_format format) +{ + return ilo_translate_format(format, PIPE_BIND_VERTEX_BUFFER); +} + #endif /* ILO_FORMAT_H */ |