diff options
| author | Chia-I Wu <olvaffe@gmail.com> | 2014-08-16 12:46:32 +0800 |
|---|---|---|
| committer | Chia-I Wu <olvaffe@gmail.com> | 2014-08-16 13:10:49 +0800 |
| commit | d338c71aa37a28b8994f96016b9dd28490757b8d (patch) | |
| tree | 9b2ca4eec30cdbd288d92a155f175f6f47c0772b | |
| parent | 16ba34e8d9f971c20ae69d4acf63ceedb5eafdca (diff) | |
| download | usermoji-d338c71aa37a28b8994f96016b9dd28490757b8d.tar.xz | |
icd: add common format functions
| -rw-r--r-- | icd/common/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | icd/common/icd-format.c | 69 | ||||
| -rw-r--r-- | icd/common/icd-format.h | 93 |
3 files changed, 163 insertions, 1 deletions
diff --git a/icd/common/CMakeLists.txt b/icd/common/CMakeLists.txt index 45d2ad8f..7c8e8352 100644 --- a/icd/common/CMakeLists.txt +++ b/icd/common/CMakeLists.txt @@ -9,5 +9,5 @@ add_custom_command(OUTPUT icd-dispatch-entrypoints.c DEPENDS ${PROJECT_SOURCE_DIR}/xgl-generate.py ${PROJECT_SOURCE_DIR}/xgl.py) -add_library(icd OBJECT icd.c icd-dispatch-entrypoints.c icd-dispatch-table.h) +add_library(icd OBJECT icd.c icd-dispatch-entrypoints.c icd-dispatch-table.h icd-format.c) set_target_properties(icd PROPERTIES POSITION_INDEPENDENT_CODE ON) diff --git a/icd/common/icd-format.c b/icd/common/icd-format.c new file mode 100644 index 00000000..dc17476a --- /dev/null +++ b/icd/common/icd-format.c @@ -0,0 +1,69 @@ +/* + * Mesa 3-D graphics library + * + * Copyright (C) 2014 LunarG, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu <olv@lunarg.com> + */ + +#include "icd-format.h" + +static const struct icd_format_info { + XGL_SIZE size; +} icd_format_table[XGL_MAX_CH_FMT + 1] = { + [XGL_CH_FMT_UNDEFINED] = { 0 }, + [XGL_CH_FMT_R4G4] = { 1 }, + [XGL_CH_FMT_R4G4B4A4] = { 2 }, + [XGL_CH_FMT_R5G6B5] = { 2 }, + [XGL_CH_FMT_B5G6R5] = { 2 }, + [XGL_CH_FMT_R5G5B5A1] = { 2 }, + [XGL_CH_FMT_R8] = { 1 }, + [XGL_CH_FMT_R8G8] = { 2 }, + [XGL_CH_FMT_R8G8B8A8] = { 4 }, + [XGL_CH_FMT_B8G8R8A8] = { 4 }, + [XGL_CH_FMT_R10G11B11] = { 4 }, + [XGL_CH_FMT_R11G11B10] = { 4 }, + [XGL_CH_FMT_R10G10B10A2] = { 4 }, + [XGL_CH_FMT_R16] = { 2 }, + [XGL_CH_FMT_R16G16] = { 4 }, + [XGL_CH_FMT_R16G16B16A16] = { 8 }, + [XGL_CH_FMT_R32] = { 4 }, + [XGL_CH_FMT_R32G32] = { 8 }, + [XGL_CH_FMT_R32G32B32] = { 12 }, + [XGL_CH_FMT_R32G32B32A32] = { 16 }, + [XGL_CH_FMT_R16G8] = { 3 }, + [XGL_CH_FMT_R32G8] = { 5 }, + [XGL_CH_FMT_R9G9B9E5] = { 4 }, + [XGL_CH_FMT_BC1] = { 8 }, + [XGL_CH_FMT_BC2] = { 16 }, + [XGL_CH_FMT_BC3] = { 16 }, + [XGL_CH_FMT_BC4] = { 8 }, + [XGL_CH_FMT_BC5] = { 16 }, + [XGL_CH_FMT_BC6U] = { 16 }, + [XGL_CH_FMT_BC6S] = { 16 }, + [XGL_CH_FMT_BC7] = { 16 }, +}; + +unsigned int icd_format_get_size(XGL_FORMAT format) +{ + return icd_format_table[format.channelFormat].size; +} diff --git a/icd/common/icd-format.h b/icd/common/icd-format.h new file mode 100644 index 00000000..8c11680d --- /dev/null +++ b/icd/common/icd-format.h @@ -0,0 +1,93 @@ +/* + * XGL + * + * Copyright (C) 2014 LunarG, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef ICD_FORMAT_H +#define ICD_FORMAT_H + +#include <stdbool.h> +#include "icd.h" + +static inline bool icd_format_is_undef(XGL_FORMAT format) +{ + return (format.numericFormat == XGL_NUM_FMT_UNDEFINED); +} + +static inline bool icd_format_is_ds(XGL_FORMAT format) +{ + return (format.numericFormat == XGL_NUM_FMT_DS); +} + +static inline bool icd_format_is_color(XGL_FORMAT format) +{ + return !(icd_format_is_undef(format) || icd_format_is_ds(format)); +} + +static inline bool icd_format_is_norm(XGL_FORMAT format) +{ + return (format.numericFormat == XGL_NUM_FMT_UNORM || + format.numericFormat == XGL_NUM_FMT_SNORM); +}; + +static inline bool icd_format_is_int(XGL_FORMAT format) +{ + return (format.numericFormat == XGL_NUM_FMT_UINT || + format.numericFormat == XGL_NUM_FMT_SINT); +} + +static inline bool icd_format_is_float(XGL_FORMAT format) +{ + return (format.numericFormat == XGL_NUM_FMT_FLOAT); +} + +static inline bool icd_format_is_srgb(XGL_FORMAT format) +{ + return (format.numericFormat == XGL_NUM_FMT_SRGB); +} + +static inline bool icd_format_is_compressed(XGL_FORMAT format) +{ + switch (format.channelFormat) { + case XGL_CH_FMT_BC1: + case XGL_CH_FMT_BC2: + case XGL_CH_FMT_BC3: + case XGL_CH_FMT_BC4: + case XGL_CH_FMT_BC5: + case XGL_CH_FMT_BC6U: + case XGL_CH_FMT_BC6S: + case XGL_CH_FMT_BC7: + return true; + default: + return false; + } +} + +static inline bool icd_format_get_block_width(XGL_FORMAT format) +{ + /* all compressed formats use 4x4 blocks */ + return (icd_format_is_compressed(format)) ? 4 : 1; +} + +unsigned int icd_format_get_size(XGL_FORMAT format); + +#endif /* ICD_FORMAT_H */ |
