mesa: add ASTC 2D LDR decoder
Tested-by: Mike Lothian <mike@fireburn.co.uk> Tested-By: Gert Wollny <gert.wollny@collabora.com> Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de>
This commit is contained in:
@@ -214,6 +214,8 @@ MAIN_FILES = \
|
|||||||
main/syncobj.c \
|
main/syncobj.c \
|
||||||
main/syncobj.h \
|
main/syncobj.h \
|
||||||
main/texcompress.c \
|
main/texcompress.c \
|
||||||
|
main/texcompress_astc.cpp \
|
||||||
|
main/texcompress_astc.h \
|
||||||
main/texcompress_bptc.c \
|
main/texcompress_bptc.c \
|
||||||
main/texcompress_bptc.h \
|
main/texcompress_bptc.h \
|
||||||
main/texcompress_bptc_tmp.h \
|
main/texcompress_bptc_tmp.h \
|
||||||
|
@@ -627,6 +627,48 @@ _mesa_is_format_etc2(mesa_format format)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return TRUE if format is an ASTC 2D compressed format.
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
_mesa_is_format_astc_2d(mesa_format format)
|
||||||
|
{
|
||||||
|
switch (format) {
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_4x4:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_5x4:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_5x5:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_6x5:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_6x6:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_8x5:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_8x6:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_8x8:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_10x5:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_10x6:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_10x8:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_10x10:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_12x10:
|
||||||
|
case MESA_FORMAT_RGBA_ASTC_12x12:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10:
|
||||||
|
case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the given format is a compressed format, return a corresponding
|
* If the given format is a compressed format, return a corresponding
|
||||||
* uncompressed format.
|
* uncompressed format.
|
||||||
|
@@ -721,6 +721,9 @@ _mesa_is_format_integer(mesa_format format);
|
|||||||
extern bool
|
extern bool
|
||||||
_mesa_is_format_etc2(mesa_format format);
|
_mesa_is_format_etc2(mesa_format format);
|
||||||
|
|
||||||
|
bool
|
||||||
|
_mesa_is_format_astc_2d(mesa_format format);
|
||||||
|
|
||||||
GLenum
|
GLenum
|
||||||
_mesa_is_format_color_format(mesa_format format);
|
_mesa_is_format_color_format(mesa_format format);
|
||||||
|
|
||||||
|
1871
src/mesa/main/texcompress_astc.cpp
Normal file
1871
src/mesa/main/texcompress_astc.cpp
Normal file
File diff suppressed because it is too large
Load Diff
47
src/mesa/main/texcompress_astc.h
Normal file
47
src/mesa/main/texcompress_astc.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Advanced Micro Devices, 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 (including the next
|
||||||
|
* paragraph) 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 TEXCOMPRESS_ASTC_H
|
||||||
|
#define TEXCOMPRESS_ASTC_H
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include "texcompress.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
_mesa_unpack_astc_2d_ldr(uint8_t *dst_row,
|
||||||
|
unsigned dst_stride,
|
||||||
|
const uint8_t *src_row,
|
||||||
|
unsigned src_stride,
|
||||||
|
unsigned src_width,
|
||||||
|
unsigned src_height,
|
||||||
|
mesa_format format);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@@ -254,6 +254,8 @@ files_libmesa_common = files(
|
|||||||
'main/syncobj.c',
|
'main/syncobj.c',
|
||||||
'main/syncobj.h',
|
'main/syncobj.h',
|
||||||
'main/texcompress.c',
|
'main/texcompress.c',
|
||||||
|
'main/texcompress_astc.cpp',
|
||||||
|
'main/texcompress_astc.h',
|
||||||
'main/texcompress_bptc.c',
|
'main/texcompress_bptc.c',
|
||||||
'main/texcompress_bptc.h',
|
'main/texcompress_bptc.h',
|
||||||
'main/texcompress_cpal.c',
|
'main/texcompress_cpal.c',
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
* Mesa 3-D graphics library
|
* Mesa 3-D graphics library
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
|
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
|
||||||
|
* Copyright 2015 Philip Taylor <philip@zaynar.co.uk>
|
||||||
|
* Copyright 2018 Advanced Micro Devices, Inc.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
* copy of this software and associated documentation files (the "Software"),
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -175,3 +177,60 @@ _mesa_half_to_float(uint16_t val)
|
|||||||
result = fi.f;
|
result = fi.f;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert 0.0 to 0x00, 1.0 to 0xff.
|
||||||
|
* Values outside the range [0.0, 1.0] will give undefined results.
|
||||||
|
*/
|
||||||
|
uint8_t _mesa_half_to_unorm8(uint16_t val)
|
||||||
|
{
|
||||||
|
const int m = val & 0x3ff;
|
||||||
|
const int e = (val >> 10) & 0x1f;
|
||||||
|
const int s = (val >> 15) & 0x1;
|
||||||
|
|
||||||
|
/* v = round_to_nearest(1.mmmmmmmmmm * 2^(e-15) * 255)
|
||||||
|
* = round_to_nearest((1.mmmmmmmmmm * 255) * 2^(e-15))
|
||||||
|
* = round_to_nearest((1mmmmmmmmmm * 255) * 2^(e-25))
|
||||||
|
* = round_to_zero((1mmmmmmmmmm * 255) * 2^(e-25) + 0.5)
|
||||||
|
* = round_to_zero(((1mmmmmmmmmm * 255) * 2^(e-24) + 1) / 2)
|
||||||
|
*
|
||||||
|
* This happens to give the correct answer for zero/subnormals too
|
||||||
|
*/
|
||||||
|
assert(s == 0 && val <= FP16_ONE); /* check 0 <= this <= 1 */
|
||||||
|
/* (implies e <= 15, which means the bit-shifts below are safe) */
|
||||||
|
|
||||||
|
uint32_t v = ((1 << 10) | m) * 255;
|
||||||
|
v = ((v >> (24 - e)) + 1) >> 1;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a uint16_t, divides by 65536, converts the infinite-precision
|
||||||
|
* result to fp16 with round-to-zero. Used by the ASTC decoder.
|
||||||
|
*/
|
||||||
|
uint16_t _mesa_uint16_div_64k_to_half(uint16_t v)
|
||||||
|
{
|
||||||
|
/* Zero or subnormal. Set the mantissa to (v << 8) and return. */
|
||||||
|
if (v < 4)
|
||||||
|
return v << 8;
|
||||||
|
|
||||||
|
/* Count the leading 0s in the uint16_t */
|
||||||
|
int n = __builtin_clz(v) - (sizeof(unsigned int) - sizeof(uint16_t)) * 8;
|
||||||
|
|
||||||
|
/* Shift the mantissa up so bit 16 is the hidden 1 bit,
|
||||||
|
* mask it off, then shift back down to 10 bits
|
||||||
|
*/
|
||||||
|
int m = ( ((uint32_t)v << (n + 1)) & 0xffff ) >> 6;
|
||||||
|
|
||||||
|
/* (0{n} 1 X{15-n}) * 2^-16
|
||||||
|
* = 1.X * 2^(15-n-16)
|
||||||
|
* = 1.X * 2^(14-n - 15)
|
||||||
|
* which is the FP16 form with e = 14 - n
|
||||||
|
*/
|
||||||
|
int e = 14 - n;
|
||||||
|
|
||||||
|
assert(e >= 1 && e <= 30);
|
||||||
|
assert(m >= 0 && m < 0x400);
|
||||||
|
|
||||||
|
return (e << 10) | m;
|
||||||
|
}
|
||||||
|
@@ -32,8 +32,13 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define FP16_ONE 0x3C00
|
||||||
|
#define FP16_ZERO 0
|
||||||
|
|
||||||
uint16_t _mesa_float_to_half(float val);
|
uint16_t _mesa_float_to_half(float val);
|
||||||
float _mesa_half_to_float(uint16_t val);
|
float _mesa_half_to_float(uint16_t val);
|
||||||
|
uint8_t _mesa_half_to_unorm8(uint16_t v);
|
||||||
|
uint16_t _mesa_uint16_div_64k_to_half(uint16_t v);
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
_mesa_half_is_negative(uint16_t h)
|
_mesa_half_is_negative(uint16_t h)
|
||||||
|
Reference in New Issue
Block a user