Commit d96e87c3 authored by Jose Fonseca's avatar Jose Fonseca
Browse files

util: Use stubs for the dynamically loaded S3TC functions.

Loosely based on Luca Barbieri's commit
52e9b990.
parent a46ca645
......@@ -35,58 +35,121 @@
#endif
static void
util_format_dxt1_rgb_fetch_stub(int src_stride,
const uint8_t *src,
int col, int row,
uint8_t *dst)
{
assert(0);
}
static void
util_format_dxt1_rgba_fetch_stub(int src_stride,
const uint8_t *src,
int col, int row,
uint8_t *dst )
{
assert(0);
}
static void
util_format_dxt3_rgba_fetch_stub(int src_stride,
const uint8_t *src,
int col, int row,
uint8_t *dst )
{
assert(0);
}
static void
util_format_dxt5_rgba_fetch_stub(int src_stride,
const uint8_t *src,
int col, int row,
uint8_t *dst )
{
assert(0);
}
static void
util_format_dxtn_pack_stub(int src_comps,
int width, int height,
const uint8_t *src,
enum util_format_dxtn dst_format,
uint8_t *dst,
int dst_stride)
{
assert(0);
}
boolean util_format_s3tc_enabled = FALSE;
util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = NULL;
util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = NULL;
util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = NULL;
util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = NULL;
util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = util_format_dxt1_rgb_fetch_stub;
util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = util_format_dxt1_rgba_fetch_stub;
util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = util_format_dxt3_rgba_fetch_stub;
util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = util_format_dxt5_rgba_fetch_stub;
util_format_dxtn_pack_t util_format_dxtn_pack = NULL;
util_format_dxtn_pack_t util_format_dxtn_pack = util_format_dxtn_pack_stub;
void
util_format_s3tc_init(void)
{
static struct util_dl_library *
library = NULL;
static boolean first_time = TRUE;
struct util_dl_library *library = NULL;
util_dl_proc fetch_2d_texel_rgb_dxt1;
util_dl_proc fetch_2d_texel_rgba_dxt1;
util_dl_proc fetch_2d_texel_rgba_dxt3;
util_dl_proc fetch_2d_texel_rgba_dxt5;
util_dl_proc tx_compress_dxtn;
if (!first_time)
return;
first_time = FALSE;
if (util_format_s3tc_enabled)
return;
if (!library) {
library = util_dl_open(DXTN_LIBNAME);
if (!library) {
debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn "
"compression/decompression unavailable");
return;
}
else {
util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t)
fetch_2d_texel_rgb_dxt1 =
util_dl_get_proc_address(library, "fetch_2d_texel_rgb_dxt1");
util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t)
fetch_2d_texel_rgba_dxt1 =
util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt1");
util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t)
fetch_2d_texel_rgba_dxt3 =
util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt3");
util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t)
fetch_2d_texel_rgba_dxt5 =
util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt5");
util_format_dxtn_pack = (util_format_dxtn_pack_t)
tx_compress_dxtn =
util_dl_get_proc_address(library, "tx_compress_dxtn");
if (util_format_dxt1_rgb_fetch ||
util_format_dxt1_rgba_fetch ||
util_format_dxt3_rgba_fetch ||
util_format_dxt5_rgba_fetch ||
util_format_dxtn_pack) {
util_format_s3tc_enabled = TRUE;
debug_printf("software DXTn compression/decompression available");
} else {
debug_printf("couldn't reference all symbols in "
DXTN_LIBNAME ", software DXTn compression/decompression "
if (!util_format_dxt1_rgb_fetch ||
!util_format_dxt1_rgba_fetch ||
!util_format_dxt3_rgba_fetch ||
!util_format_dxt5_rgba_fetch ||
!util_format_dxtn_pack) {
debug_printf("couldn't reference all symbols in " DXTN_LIBNAME
", software DXTn compression/decompression "
"unavailable");
return;
}
}
}
util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgb_dxt1;
util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt1;
util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt3;
util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt5;
util_format_dxtn_pack = (util_format_dxtn_pack_t)tx_compress_dxtn;
util_format_s3tc_enabled = TRUE;
}
......@@ -97,85 +160,69 @@ util_format_s3tc_init(void)
void
util_format_dxt1_rgb_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
{
if (util_format_dxt1_rgb_fetch) {
util_format_dxt1_rgb_fetch(0, src, i, j, dst);
}
}
void
util_format_dxt1_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
{
if (util_format_dxt1_rgba_fetch) {
util_format_dxt1_rgba_fetch(0, src, i, j, dst);
}
}
void
util_format_dxt3_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
{
if (util_format_dxt3_rgba_fetch) {
util_format_dxt3_rgba_fetch(0, src, i, j, dst);
}
}
void
util_format_dxt5_rgba_fetch_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
{
if (util_format_dxt5_rgba_fetch) {
util_format_dxt5_rgba_fetch(0, src, i, j, dst);
}
}
void
util_format_dxt1_rgb_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
if (util_format_dxt1_rgb_fetch) {
uint8_t tmp[4];
util_format_dxt1_rgb_fetch(0, src, i, j, tmp);
dst[0] = ubyte_to_float(tmp[0]);
dst[1] = ubyte_to_float(tmp[1]);
dst[2] = ubyte_to_float(tmp[2]);
dst[3] = 1.0;
}
}
void
util_format_dxt1_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
if (util_format_dxt1_rgba_fetch) {
uint8_t tmp[4];
util_format_dxt1_rgba_fetch(0, src, i, j, tmp);
dst[0] = ubyte_to_float(tmp[0]);
dst[1] = ubyte_to_float(tmp[1]);
dst[2] = ubyte_to_float(tmp[2]);
dst[3] = ubyte_to_float(tmp[3]);
}
}
void
util_format_dxt3_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
if (util_format_dxt3_rgba_fetch) {
uint8_t tmp[4];
util_format_dxt3_rgba_fetch(0, src, i, j, tmp);
dst[0] = ubyte_to_float(tmp[0]);
dst[1] = ubyte_to_float(tmp[1]);
dst[2] = ubyte_to_float(tmp[2]);
dst[3] = ubyte_to_float(tmp[3]);
}
}
void
util_format_dxt5_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
{
if (util_format_dxt5_rgba_fetch) {
uint8_t tmp[4];
util_format_dxt5_rgba_fetch(0, src, i, j, tmp);
dst[0] = ubyte_to_float(tmp[0]);
dst[1] = ubyte_to_float(tmp[1]);
dst[2] = ubyte_to_float(tmp[2]);
dst[3] = ubyte_to_float(tmp[3]);
}
}
......@@ -186,7 +233,6 @@ util_format_dxt5_rgba_fetch_float(float *dst, const uint8_t *src, unsigned i, un
void
util_format_dxt1_rgb_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxt1_rgb_fetch) {
unsigned x, y, i, j;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -201,13 +247,11 @@ util_format_dxt1_rgb_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const
}
src_row += src_stride;
}
}
}
void
util_format_dxt1_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxt1_rgba_fetch) {
unsigned x, y, i, j;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -222,13 +266,11 @@ util_format_dxt1_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const
}
src_row += src_stride;
}
}
}
void
util_format_dxt3_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxt3_rgba_fetch) {
unsigned x, y, i, j;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -243,13 +285,11 @@ util_format_dxt3_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const
}
src_row += src_stride;
}
}
}
void
util_format_dxt5_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxt5_rgba_fetch) {
unsigned x, y, i, j;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -264,13 +304,11 @@ util_format_dxt5_rgba_unpack_8unorm(uint8_t *dst_row, unsigned dst_stride, const
}
src_row += src_stride;
}
}
}
void
util_format_dxt1_rgb_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxt1_rgb_fetch) {
unsigned x, y, i, j;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -290,13 +328,11 @@ util_format_dxt1_rgb_unpack_float(float *dst_row, unsigned dst_stride, const uin
}
src_row += src_stride;
}
}
}
void
util_format_dxt1_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxt1_rgba_fetch) {
unsigned x, y, i, j;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -316,13 +352,11 @@ util_format_dxt1_rgba_unpack_float(float *dst_row, unsigned dst_stride, const ui
}
src_row += src_stride;
}
}
}
void
util_format_dxt3_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxt3_rgba_fetch) {
unsigned x, y, i, j;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -342,13 +376,11 @@ util_format_dxt3_rgba_unpack_float(float *dst_row, unsigned dst_stride, const ui
}
src_row += src_stride;
}
}
}
void
util_format_dxt5_rgba_unpack_float(float *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxt5_rgba_fetch) {
unsigned x, y, i, j;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -368,7 +400,6 @@ util_format_dxt5_rgba_unpack_float(float *dst_row, unsigned dst_stride, const ui
}
src_row += src_stride;
}
}
}
......@@ -379,7 +410,6 @@ util_format_dxt5_rgba_unpack_float(float *dst_row, unsigned dst_stride, const ui
void
util_format_dxt1_rgb_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxtn_pack) {
unsigned x, y, i, j, k;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -400,13 +430,11 @@ util_format_dxt1_rgb_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const ui
src_row += src_stride;
dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
}
void
util_format_dxt1_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxtn_pack) {
unsigned x, y, i, j, k;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -427,13 +455,11 @@ util_format_dxt1_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const u
src_row += src_stride;
dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
}
void
util_format_dxt3_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxtn_pack) {
unsigned x, y, i, j, k;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -454,13 +480,11 @@ util_format_dxt3_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const u
src_row += src_stride;
dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
}
void
util_format_dxt5_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxtn_pack) {
unsigned x, y, i, j, k;
for(y = 0; y < height; y += 4) {
const uint8_t *src = src_row;
......@@ -481,13 +505,11 @@ util_format_dxt5_rgba_pack_8unorm(uint8_t *dst_row, unsigned dst_stride, const u
src_row += src_stride;
dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
}
void
util_format_dxt1_rgb_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxtn_pack) {
unsigned x, y, i, j, k;
for(y = 0; y < height; y += 4) {
const float *src = src_row;
......@@ -508,13 +530,11 @@ util_format_dxt1_rgb_pack_float(uint8_t *dst_row, unsigned dst_stride, const flo
src_row += src_stride;
dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
}
void
util_format_dxt1_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxtn_pack) {
unsigned x, y, i, j, k;
for(y = 0; y < height; y += 4) {
const float *src = src_row;
......@@ -535,13 +555,11 @@ util_format_dxt1_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const fl
src_row += src_stride;
dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
}
void
util_format_dxt3_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxtn_pack) {
unsigned x, y, i, j, k;
for(y = 0; y < height; y += 4) {
const float *src = src_row;
......@@ -562,13 +580,11 @@ util_format_dxt3_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const fl
src_row += src_stride;
dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
}
void
util_format_dxt5_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const float *src_row, unsigned src_stride, unsigned width, unsigned height)
{
if (util_format_dxtn_pack) {
unsigned x, y, i, j, k;
for(y = 0; y < height; y += 4) {
const float *src = src_row;
......@@ -589,7 +605,6 @@ util_format_dxt5_rgba_pack_float(uint8_t *dst_row, unsigned dst_stride, const fl
src_row += src_stride;
dst_row += 4*dst_stride/sizeof(*dst_row);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment