diff options
author | Denis Pauk <[email protected]> | 2018-06-26 23:30:50 +0300 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2018-07-01 15:42:37 -0400 |
commit | f69bc797e15fe6beb9e439009fab55f7fae0b7f9 (patch) | |
tree | ee695da5940eee8db43a5faf818960463cae76fa /src/gallium/auxiliary/util | |
parent | bf4871f9e83def8a38bbecd0b1fe0b909075523d (diff) |
gallium/auxiliary: Add helper support for bptc format compress/decompress
Reuse code shared with mesa/main/texcompress_bptc.
v2: Use block decompress function
v3: Include static bptc code from texcompress_bptc_tmp.h
Suggested-by: Marek Olšák <[email protected]>
Signed-off-by: Denis Pauk <[email protected]>
CC: Nicolai Hähnle <[email protected]>
CC: Marek Olšák <[email protected]>
CC: Gert Wollny <[email protected]>
Signed-off-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r-- | src/gallium/auxiliary/util/u_format_bptc.c | 279 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_format_bptc.h | 122 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_format_table.py | 3 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_tile.c | 1 |
4 files changed, 404 insertions, 1 deletions
diff --git a/src/gallium/auxiliary/util/u_format_bptc.c b/src/gallium/auxiliary/util/u_format_bptc.c new file mode 100644 index 00000000000..87ec4139e09 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_bptc.c @@ -0,0 +1,279 @@ +/************************************************************************** + * + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * Copyright (c) 2008 VMware, 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. + * + **************************************************************************/ + +#include "u_math.h" +#include "u_format.h" +#include "u_format_bptc.h" +#include "util/format_srgb.h" + +#define BPTC_BLOCK_DECODE +#include "../../../mesa/main/texcompress_bptc_tmp.h" + +void +util_format_bptc_rgba_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + decompress_rgba_unorm(width, height, + src_row, src_stride, + dst_row, dst_stride); +} + +void +util_format_bptc_rgba_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + compress_rgba_unorm(width, height, + src_row, src_stride, + dst_row, dst_stride); +} + +void +util_format_bptc_rgba_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + uint8_t *temp_block; + temp_block = malloc(width * height * 4 * sizeof(uint8_t)); + decompress_rgba_unorm(width, height, + src_row, src_stride, + temp_block, width * 4 * sizeof(uint8_t)); + util_format_read_4f(PIPE_FORMAT_R8G8B8A8_UNORM, + dst_row, dst_stride, + temp_block, width * 4 * sizeof(uint8_t), + 0, 0, width, height); + free((void *) temp_block); +} + +void +util_format_bptc_rgba_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + uint8_t *temp_block; + temp_block = malloc(width * height * 4 * sizeof(uint8_t)); + util_format_read_4ub(PIPE_FORMAT_R32G32B32A32_FLOAT, + temp_block, width * 4 * sizeof(uint8_t), + src_row, src_stride, + 0, 0, width, height); + compress_rgba_unorm(width, height, + temp_block, width * 4 * sizeof(uint8_t), + dst_row, dst_stride); + free((void *) temp_block); +} + +void +util_format_bptc_rgba_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned width, unsigned height) +{ + uint8_t temp_block[4]; + + fetch_rgba_unorm_from_block(src + ((width * sizeof(uint8_t)) * (height / 4) + (width / 4)) * 16, + temp_block, (width % 4) + (height % 4) * 4); + + util_format_read_4f(PIPE_FORMAT_R8G8B8A8_UNORM, + dst, 4 * sizeof(float), + temp_block, 4 * sizeof(uint8_t), + 0, 0, 1, 1); +} + +void +util_format_bptc_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + decompress_rgba_unorm(width, height, + src_row, src_stride, + dst_row, dst_stride); +} + +void +util_format_bptc_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + compress_rgba_unorm(width, height, + src_row, src_stride, + dst_row, dst_stride); +} + +void +util_format_bptc_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + uint8_t *temp_block; + temp_block = malloc(width * height * 4 * sizeof(uint8_t)); + decompress_rgba_unorm(width, height, + src_row, src_stride, + temp_block, width * 4 * sizeof(uint8_t)); + util_format_read_4f(PIPE_FORMAT_R8G8B8A8_SRGB, + dst_row, dst_stride, + temp_block, width * 4 * sizeof(uint8_t), + 0, 0, width, height); + free((void *) temp_block); +} + +void +util_format_bptc_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + compress_rgb_float(width, height, + src_row, src_stride, + dst_row, dst_stride, + true); +} + +void +util_format_bptc_srgba_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned width, unsigned height) +{ + uint8_t temp_block[4]; + + fetch_rgba_unorm_from_block(src + ((width * sizeof(uint8_t)) * (height / 4) + (width / 4)) * 16, + temp_block, (width % 4) + (height % 4) * 4); + util_format_read_4f(PIPE_FORMAT_R8G8B8A8_SRGB, + dst, 4 * sizeof(float), + temp_block, width * 4 * sizeof(uint8_t), + 0, 0, 1, 1); +} + +void +util_format_bptc_rgb_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + float *temp_block; + temp_block = malloc(width * height * 4 * sizeof(float)); + decompress_rgb_float(width, height, + src_row, src_stride, + temp_block, width * 4 * sizeof(float), + true); + util_format_read_4ub(PIPE_FORMAT_R32G32B32A32_FLOAT, + dst_row, dst_stride, + temp_block, width * 4 * sizeof(float), + 0, 0, width, height); + free((void *) temp_block); +} + +void +util_format_bptc_rgb_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + compress_rgba_unorm(width, height, + src_row, src_stride, + dst_row, dst_stride); +} + +void +util_format_bptc_rgb_float_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + decompress_rgb_float(width, height, + src_row, src_stride, + dst_row, dst_stride, + true); +} + +void +util_format_bptc_rgb_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + compress_rgb_float(width, height, + src_row, src_stride, + dst_row, dst_stride, + true); +} + +void +util_format_bptc_rgb_float_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned width, unsigned height) +{ + fetch_rgb_float_from_block(src + ((width * sizeof(uint8_t)) * (height / 4) + (width / 4)) * 16, + dst, (width % 4) + (height % 4) * 4, true); +} + +void +util_format_bptc_rgb_ufloat_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + float *temp_block; + temp_block = malloc(width * height * 4 * sizeof(float)); + decompress_rgb_float(width, height, + src_row, src_stride, + temp_block, width * 4 * sizeof(float), + false); + util_format_read_4ub(PIPE_FORMAT_R32G32B32A32_FLOAT, + dst_row, dst_stride, + temp_block, width * 4 * sizeof(float), + 0, 0, width, height); + free((void *) temp_block); +} + +void +util_format_bptc_rgb_ufloat_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + compress_rgba_unorm(width, height, + src_row, src_stride, + dst_row, dst_stride); +} + +void +util_format_bptc_rgb_ufloat_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + decompress_rgb_float(width, height, + src_row, src_stride, + dst_row, dst_stride, + false); +} + +void +util_format_bptc_rgb_ufloat_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height) +{ + compress_rgb_float(width, height, + src_row, src_stride, + dst_row, dst_stride, + false); +} + +void +util_format_bptc_rgb_ufloat_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned width, unsigned height) +{ + fetch_rgb_float_from_block(src + ((width * sizeof(uint8_t)) * (height / 4) + (width / 4)) * 16, + dst, (width % 4) + (height % 4) * 4, false); +} diff --git a/src/gallium/auxiliary/util/u_format_bptc.h b/src/gallium/auxiliary/util/u_format_bptc.h new file mode 100644 index 00000000000..eaf3ec396ab --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_bptc.h @@ -0,0 +1,122 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +#ifndef U_FORMAT_BPTC_H_ +#define U_FORMAT_BPTC_H_ + + +#include "pipe/p_compiler.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void +util_format_bptc_rgba_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgba_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgba_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgba_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgba_unorm_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned width, unsigned height); + +void +util_format_bptc_srgba_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_srgba_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_srgba_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_srgba_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_srgba_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned width, unsigned height); + +void +util_format_bptc_rgb_float_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgb_float_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgb_float_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgb_float_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgb_float_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned width, unsigned height); + +void +util_format_bptc_rgb_ufloat_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgb_ufloat_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgb_ufloat_unpack_rgba_float(float *dst_row, unsigned dst_stride, + const uint8_t *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgb_ufloat_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, + const float *src_row, unsigned src_stride, + unsigned width, unsigned height); +void +util_format_bptc_rgb_ufloat_fetch_rgba_float(float *dst, const uint8_t *src, + unsigned width, unsigned height); +#ifdef __cplusplus +} +#endif + +#endif /* U_FORMAT_BPTC_H_ */ diff --git a/src/gallium/auxiliary/util/u_format_table.py b/src/gallium/auxiliary/util/u_format_table.py index a09ae53cbc8..1f8e15fa971 100644 --- a/src/gallium/auxiliary/util/u_format_table.py +++ b/src/gallium/auxiliary/util/u_format_table.py @@ -85,6 +85,7 @@ def write_format_table(formats): print CopyRight.strip() print print '#include "u_format.h"' + print '#include "u_format_bptc.h"' print '#include "u_format_s3tc.h"' print '#include "u_format_rgtc.h"' print '#include "u_format_latc.h"' @@ -138,7 +139,7 @@ def write_format_table(formats): u_format_pack.print_channels(format, do_swizzle_array) print " %s," % (colorspace_map(format.colorspace),) access = True - if format.layout in ('bptc', 'astc'): + if format.layout in ('astc'): access = False if format.layout == 'etc' and format.short_name() != 'etc1_rgb8': access = False diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c index b91bb413a8c..0239b870482 100644 --- a/src/gallium/auxiliary/util/u_tile.c +++ b/src/gallium/auxiliary/util/u_tile.c @@ -35,6 +35,7 @@ #include "util/u_inlines.h" #include "util/u_format.h" +#include "util/u_format_bptc.h" #include "util/u_math.h" #include "util/u_memory.h" #include "util/u_surface.h" |