mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-22 04:50:11 +01:00
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 <maraeo@gmail.com>
Signed-off-by: Denis Pauk <pauk.denis@gmail.com>
CC: Nicolai Hähnle <nicolai.haehnle@amd.com>
CC: Marek Olšák <maraeo@gmail.com>
CC: Gert Wollny <gw.fossdev@gmail.com>
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
This commit is contained in:
parent
bf4871f9e8
commit
f69bc797e1
6 changed files with 408 additions and 1 deletions
|
|
@ -256,6 +256,8 @@ C_SOURCES := \
|
|||
util/u_fifo.h \
|
||||
util/u_format.c \
|
||||
util/u_format.h \
|
||||
util/u_format_bptc.c \
|
||||
util/u_format_bptc.h \
|
||||
util/u_format_etc.c \
|
||||
util/u_format_etc.h \
|
||||
util/u_format_latc.c \
|
||||
|
|
|
|||
|
|
@ -276,6 +276,8 @@ files_libgallium = files(
|
|||
'util/u_fifo.h',
|
||||
'util/u_format.c',
|
||||
'util/u_format.h',
|
||||
'util/u_format_bptc.c',
|
||||
'util/u_format_bptc.h',
|
||||
'util/u_format_etc.c',
|
||||
'util/u_format_etc.h',
|
||||
'util/u_format_latc.c',
|
||||
|
|
|
|||
279
src/gallium/auxiliary/util/u_format_bptc.c
Normal file
279
src/gallium/auxiliary/util/u_format_bptc.c
Normal file
|
|
@ -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);
|
||||
}
|
||||
122
src/gallium/auxiliary/util/u_format_bptc.h
Normal file
122
src/gallium/auxiliary/util/u_format_bptc.h
Normal file
|
|
@ -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_ */
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue