Add squish external compressor.

Rename our squish version to nvsquish.
This commit is contained in:
castano
2008-11-23 08:59:56 +00:00
parent 4a85f8e48d
commit 4bbf5e96f4
20 changed files with 126 additions and 77 deletions

View File

@ -28,7 +28,7 @@
#include "colourblock.h"
#include <cfloat>
namespace squish {
namespace nvsquish {
ClusterFit::ClusterFit()
{

View File

@ -23,15 +23,15 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_CLUSTERFIT_H
#define SQUISH_CLUSTERFIT_H
#ifndef NV_SQUISH_CLUSTERFIT_H
#define NV_SQUISH_CLUSTERFIT_H
#include "squish.h"
#include "maths.h"
#include "simd.h"
#include "colourfit.h"
namespace squish {
namespace nvsquish {
class ClusterFit : public ColourFit
{

View File

@ -25,7 +25,7 @@
#include "colourblock.h"
namespace squish {
namespace nvsquish {
static int FloatToInt( float a, int limit )
{

View File

@ -23,13 +23,13 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_COLOURBLOCK_H
#define SQUISH_COLOURBLOCK_H
#ifndef NV_SQUISH_COLOURBLOCK_H
#define NV_SQUISH_COLOURBLOCK_H
#include "squish.h"
#include "maths.h"
namespace squish {
namespace nvsquish {
void WriteColourBlock3( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* block );
void WriteColourBlock4( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* block );

View File

@ -26,7 +26,7 @@
#include "colourfit.h"
#include "colourset.h"
namespace squish {
namespace nvsquish {
ColourFit::ColourFit()
{

View File

@ -23,13 +23,13 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_COLOURFIT_H
#define SQUISH_COLOURFIT_H
#ifndef NV_SQUISH_COLOURFIT_H
#define NV_SQUISH_COLOURFIT_H
#include "squish.h"
#include "maths.h"
namespace squish {
namespace nvsquish {
class ColourSet;

View File

@ -25,7 +25,7 @@
#include "colourset.h"
namespace squish {
namespace nvsquish {
// @@ Add flags:
// - MatchTransparent

View File

@ -23,14 +23,14 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_COLOURSET_H
#define SQUISH_COLOURSET_H
#ifndef NV_SQUISH_COLOURSET_H
#define NV_SQUISH_COLOURSET_H
#include "squish.h"
#include "maths.h"
#include "simd.h"
namespace squish {
namespace nvsquish {
/*! @brief Represents a set of block colours
*/

View File

@ -31,7 +31,7 @@
#include "fastclusterlookup.inl"
namespace squish {
namespace nvsquish {
FastClusterFit::FastClusterFit()
{

View File

@ -24,15 +24,15 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_FASTCLUSTERFIT_H
#define SQUISH_FASTCLUSTERFIT_H
#ifndef NV_SQUISH_FASTCLUSTERFIT_H
#define NV_SQUISH_FASTCLUSTERFIT_H
#include "squish.h"
#include "maths.h"
#include "simd.h"
#include "colourfit.h"
namespace squish {
namespace nvsquish {
class FastClusterFit : public ColourFit
{

View File

@ -26,7 +26,7 @@
#include "maths.h"
#include <cfloat>
namespace squish {
namespace nvsquish {
Sym3x3 ComputeWeightedCovariance( int n, Vec3 const* points, float const* weights, Vec3::Arg metric )
{

View File

@ -23,14 +23,14 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_MATHS_H
#define SQUISH_MATHS_H
#ifndef NV_SQUISH_MATHS_H
#define NV_SQUISH_MATHS_H
#include <cmath>
#include <algorithm>
#include "config.h"
namespace squish {
namespace nvsquish {
class Vec3
{

View File

@ -23,8 +23,8 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_SIMD_H
#define SQUISH_SIMD_H
#ifndef NV_SQUISH_SIMD_H
#define NV_SQUISH_SIMD_H
#include "maths.h"

View File

@ -23,8 +23,8 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_SIMD_SSE_H
#define SQUISH_SIMD_SSE_H
#ifndef NV_SQUISH_SIMD_SSE_H
#define NV_SQUISH_SIMD_SSE_H
#include <xmmintrin.h>
#if ( SQUISH_USE_SSE > 1 )
@ -35,7 +35,7 @@
#define SQUISH_SSE_SPLAT( a ) \
( ( a ) | ( ( a ) << 2 ) | ( ( a ) << 4 ) | ( ( a ) << 6 ) )
namespace squish {
namespace nvsquish {
#define VEC4_CONST( X ) Vec4( _mm_set1_ps( X ) )

View File

@ -23,11 +23,11 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_H
#define SQUISH_H
#ifndef NV_SQUISH_H
#define NV_SQUISH_H
//! All squish API functions live in this namespace.
namespace squish {
namespace nvsquish {
// -----------------------------------------------------------------------------

View File

@ -30,7 +30,7 @@
#include <cfloat>
namespace squish {
namespace nvsquish {
WeightedClusterFit::WeightedClusterFit()
{
@ -131,6 +131,7 @@ float WeightedClusterFit::GetBestError() const
void WeightedClusterFit::Compress3( void* block )
{
int const count = m_colours->GetCount();
Vec4 const one = VEC4_CONST(1.0f);
Vec4 const zero = VEC4_CONST(0.0f);
Vec4 const half(0.5f, 0.5f, 0.5f, 0.25f);
@ -148,11 +149,11 @@ void WeightedClusterFit::Compress3( void* block )
int b0 = 0, b1 = 0;
// check all possible clusters for this total order
for( int c0 = 0; c0 <= 16; c0++)
for( int c0 = 0; c0 <= count; c0++)
{
Vec4 x1 = zero;
for( int c1 = 0; c1 <= 16-c0; c1++)
for( int c1 = 0; c1 <= count-c0; c1++)
{
Vec4 const x2 = m_xsum - x1 - x0;
@ -220,17 +221,17 @@ void WeightedClusterFit::Compress3( void* block )
for(; i < b0+b1; i++) {
bestindices[i] = 2;
}
for(; i < 16; i++) {
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < 16; ++i )
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices ); // Set alpha indices.
m_colours->RemapIndices( ordered, bestindices );
// save the block
@ -243,6 +244,7 @@ void WeightedClusterFit::Compress3( void* block )
void WeightedClusterFit::Compress4( void* block )
{
int const count = m_colours->GetCount();
Vec4 const one = VEC4_CONST(1.0f);
Vec4 const zero = VEC4_CONST(0.0f);
Vec4 const half = VEC4_CONST(0.5f);
@ -262,15 +264,15 @@ void WeightedClusterFit::Compress4( void* block )
int b0 = 0, b1 = 0, b2 = 0;
// check all possible clusters for this total order
for( int c0 = 0; c0 <= 16; c0++)
for( int c0 = 0; c0 <= count; c0++)
{
Vec4 x1 = zero;
for( int c1 = 0; c1 <= 16-c0; c1++)
for( int c1 = 0; c1 <= count-c0; c1++)
{
Vec4 x2 = zero;
for( int c2 = 0; c2 <= 16-c0-c1; c2++)
for( int c2 = 0; c2 <= count-c0-c1; c2++)
{
Vec4 const x3 = m_xsum - x2 - x1 - x0;
@ -345,18 +347,20 @@ void WeightedClusterFit::Compress4( void* block )
for(; i < b0+b1+b2; i++) {
bestindices[i] = 3;
}
for(; i < 16; i++) {
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < 16; ++i )
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices );
// save the block
WriteColourBlock4( beststart.GetVec3(), bestend.GetVec3(), ordered, block );
WriteColourBlock4( beststart.GetVec3(), bestend.GetVec3(), bestindices, block );
// save the error
m_besterror = besterror;
@ -367,6 +371,7 @@ void WeightedClusterFit::Compress4( void* block )
void WeightedClusterFit::Compress3( void* block )
{
int const count = m_colours->GetCount();
Vec3 const one( 1.0f );
Vec3 const zero( 0.0f );
Vec3 const half( 0.5f );
@ -384,12 +389,12 @@ void WeightedClusterFit::Compress3( void* block )
int b0 = 0, b1 = 0;
// check all possible clusters for this total order
for( int c0 = 0; c0 <= 16; c0++)
for( int c0 = 0; c0 <= count; c0++)
{
Vec3 x1(0.0f);
float w1 = 0.0f;
for( int c1 = 0; c1 <= 16-c0; c1++)
for( int c1 = 0; c1 <= count-c0; c1++)
{
float w2 = m_wsum - w0 - w1;
@ -448,18 +453,20 @@ void WeightedClusterFit::Compress3( void* block )
for(; i < b0+b1; i++) {
bestindices[i] = 2;
}
for(; i < 16; i++) {
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < 16; ++i )
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices );
// save the block
WriteColourBlock3( beststart, bestend, ordered, block );
WriteColourBlock3( beststart, bestend, bestindices, block );
// save the error
m_besterror = besterror;
@ -468,6 +475,7 @@ void WeightedClusterFit::Compress3( void* block )
void WeightedClusterFit::Compress4( void* block )
{
int const count = m_colours->GetCount();
Vec3 const one( 1.0f );
Vec3 const zero( 0.0f );
Vec3 const half( 0.5f );
@ -484,17 +492,17 @@ void WeightedClusterFit::Compress4( void* block )
int b0 = 0, b1 = 0, b2 = 0;
// check all possible clusters for this total order
for( int c0 = 0; c0 <= 16; c0++)
for( int c0 = 0; c0 <= count; c0++)
{
Vec3 x1(0.0f);
float w1 = 0.0f;
for( int c1 = 0; c1 <= 16-c0; c1++)
for( int c1 = 0; c1 <= count-c0; c1++)
{
Vec3 x2(0.0f);
float w2 = 0.0f;
for( int c2 = 0; c2 <= 16-c0-c1; c2++)
for( int c2 = 0; c2 <= count-c0-c1; c2++)
{
float w3 = m_wsum - w0 - w1 - w2;
@ -560,18 +568,20 @@ void WeightedClusterFit::Compress4( void* block )
for(; i < b0+b1+b2; i++) {
bestindices[i] = 3;
}
for(; i < 16; i++) {
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < 16; ++i )
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices );
// save the block
WriteColourBlock4( beststart, bestend, ordered, block );
WriteColourBlock4( beststart, bestend, bestindices, block );
// save the error
m_besterror = besterror;

View File

@ -24,15 +24,15 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_WEIGHTEDCLUSTERFIT_H
#define SQUISH_WEIGHTEDCLUSTERFIT_H
#ifndef NV_SQUISH_WEIGHTEDCLUSTERFIT_H
#define NV_SQUISH_WEIGHTEDCLUSTERFIT_H
#include "squish.h"
#include "maths.h"
#include "simd.h"
#include "colourfit.h"
namespace squish {
namespace nvsquish {
class WeightedClusterFit : public ColourFit
{