From 4b08c20b0e0b5ad1a4faf1a92fb1090461a2d4fa Mon Sep 17 00:00:00 2001 From: castano Date: Mon, 31 May 2010 08:13:23 +0000 Subject: [PATCH] More cleanup. --- src/nvtt/CMakeLists.txt | 6 +++ src/nvtt/Compressor.h | 8 ++-- src/nvtt/CompressorDX10.cpp | 78 +++++++++++++++++++++++++++++++++++++ src/nvtt/CompressorDX10.h | 63 ++++++++++++++++++++++++++++++ src/nvtt/CompressorDX11.cpp | 33 ++++++++++++++++ src/nvtt/CompressorDX11.h | 46 ++++++++++++++++++++++ src/nvtt/CompressorDXT.cpp | 41 +------------------ src/nvtt/CompressorDXT.h | 34 ++-------------- src/nvtt/CompressorRGB.h | 7 ++-- src/nvtt/CompressorRGBE.h | 7 ++-- src/nvtt/Context.cpp | 2 + src/nvtt/InputOptions.h | 6 +-- src/nvtt/TexImage.h | 6 +-- src/nvtt/nvtt.h | 6 +-- src/nvtt/squish/maths.h | 2 +- 15 files changed, 252 insertions(+), 93 deletions(-) create mode 100644 src/nvtt/CompressorDX10.cpp create mode 100644 src/nvtt/CompressorDX10.h create mode 100644 src/nvtt/CompressorDX11.cpp create mode 100644 src/nvtt/CompressorDX11.h diff --git a/src/nvtt/CMakeLists.txt b/src/nvtt/CMakeLists.txt index a20bbfc..8020f94 100644 --- a/src/nvtt/CMakeLists.txt +++ b/src/nvtt/CMakeLists.txt @@ -1,6 +1,8 @@ PROJECT(nvtt) ADD_SUBDIRECTORY(squish) +ADD_SUBDIRECTORY(bc6h) +#ADD_SUBDIRECTORY(bc7) SET(NVTT_SRCS nvtt.h @@ -12,6 +14,10 @@ SET(NVTT_SRCS Compressor.h CompressorDXT.h CompressorDXT.cpp + CompressorDX10.h + CompressorDX10.cpp + CompressorDX11.h + CompressorDX11.cpp CompressorRGB.h CompressorRGB.cpp CompressorRGBE.h diff --git a/src/nvtt/Compressor.h b/src/nvtt/Compressor.h index 1e87cda..bbe8319 100644 --- a/src/nvtt/Compressor.h +++ b/src/nvtt/Compressor.h @@ -21,11 +21,11 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#ifndef NV_TT_COMPRESSOR_H -#define NV_TT_COMPRESSOR_H +#ifndef NVTT_COMPRESSOR_H +#define NVTT_COMPRESSOR_H -#include // uint #include "nvtt.h" +#include "nvcore/nvcore.h" // uint namespace nv { @@ -37,4 +37,4 @@ namespace nv } // nv namespace -#endif // NV_TT_COMPRESSOR_H \ No newline at end of file +#endif // NVTT_COMPRESSOR_H diff --git a/src/nvtt/CompressorDX10.cpp b/src/nvtt/CompressorDX10.cpp new file mode 100644 index 0000000..5345f75 --- /dev/null +++ b/src/nvtt/CompressorDX10.cpp @@ -0,0 +1,78 @@ +// Copyright NVIDIA Corporation 2007 -- Ignacio Castano +// +// 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 "CompressorDX10.h" +#include "QuickCompressDXT.h" +#include "OptimalCompressDXT.h" + +#include "nvtt.h" + +#include "nvimage/ColorBlock.h" +#include "nvimage/BlockDXT.h" + +#include // placement new + +using namespace nv; +using namespace nvtt; + + +void FastCompressorBC4::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output) +{ + BlockATI1 * block = new(output) BlockATI1; + + rgba.swizzle(0, 1, 2, 0); // Copy red to alpha + QuickCompress::compressDXT5A(rgba, &block->alpha); +} + +void FastCompressorBC5::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output) +{ + BlockATI2 * block = new(output) BlockATI2; + + rgba.swizzle(0, 1, 2, 0); // Copy red to alpha + QuickCompress::compressDXT5A(rgba, &block->x); + + rgba.swizzle(0, 1, 2, 1); // Copy green to alpha + QuickCompress::compressDXT5A(rgba, &block->y); +} + + +void ProductionCompressorBC4::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output) +{ + BlockATI1 * block = new(output) BlockATI1; + + rgba.swizzle(0, 1, 2, 0); // Copy red to alpha + OptimalCompress::compressDXT5A(rgba, &block->alpha); +} + +void ProductionCompressorBC5::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output) +{ + BlockATI2 * block = new(output) BlockATI2; + + rgba.swizzle(0, 1, 2, 0); // Copy red to alpha + OptimalCompress::compressDXT5A(rgba, &block->x); + + rgba.swizzle(0, 1, 2, 1); // Copy green to alpha + OptimalCompress::compressDXT5A(rgba, &block->y); +} + + diff --git a/src/nvtt/CompressorDX10.h b/src/nvtt/CompressorDX10.h new file mode 100644 index 0000000..382190b --- /dev/null +++ b/src/nvtt/CompressorDX10.h @@ -0,0 +1,63 @@ +// Copyright NVIDIA Corporation 2007 -- Ignacio Castano +// +// 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. + +#ifndef NVTT_COMPRESSORDX10_H +#define NVTT_COMPRESSORDX10_H + +#include "CompressorDXT.h" + +namespace nv +{ + struct ColorBlock; + + // Fast CPU compressors. + struct FastCompressorBC4 : public FixedBlockCompressor + { + virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); + virtual uint blockSize() const { return 8; } + }; + + struct FastCompressorBC5 : public FixedBlockCompressor + { + virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); + virtual uint blockSize() const { return 16; } + }; + + + // Production CPU compressors. + struct ProductionCompressorBC4 : public FixedBlockCompressor + { + virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); + virtual uint blockSize() const { return 8; } + }; + + struct ProductionCompressorBC5 : public FixedBlockCompressor + { + virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); + virtual uint blockSize() const { return 16; } + }; + +} // nv namespace + + +#endif // NVTT_COMPRESSORDX10_H diff --git a/src/nvtt/CompressorDX11.cpp b/src/nvtt/CompressorDX11.cpp new file mode 100644 index 0000000..1659080 --- /dev/null +++ b/src/nvtt/CompressorDX11.cpp @@ -0,0 +1,33 @@ +// Copyright NVIDIA Corporation 2007 -- Ignacio Castano +// +// 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 "CompressorDX11.h" + +#include "nvtt.h" + +using namespace nv; +using namespace nvtt; + + + + diff --git a/src/nvtt/CompressorDX11.h b/src/nvtt/CompressorDX11.h new file mode 100644 index 0000000..61b29d0 --- /dev/null +++ b/src/nvtt/CompressorDX11.h @@ -0,0 +1,46 @@ +// Copyright NVIDIA Corporation 2007 -- Ignacio Castano +// +// 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. + +#ifndef NVTT_COMPRESSORDX11_H +#define NVTT_COMPRESSORDX11_H + +#include "CompressorDXT.h" + +namespace nv +{ + struct CompressorBC6 : public FixedBlockCompressor + { + virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); + virtual uint blockSize() const { return 16; } + }; + + struct CompressorBC7 : public FixedBlockCompressor + { + virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); + virtual uint blockSize() const { return 16; } + }; + +} // nv namespace + + +#endif // NVTT_COMPRESSORDX11_H diff --git a/src/nvtt/CompressorDXT.cpp b/src/nvtt/CompressorDXT.cpp index 917e776..b8d1ecf 100644 --- a/src/nvtt/CompressorDXT.cpp +++ b/src/nvtt/CompressorDXT.cpp @@ -40,6 +40,7 @@ #include "nvimage/ColorBlock.h" #include "nvimage/BlockDXT.h" +#include // placement new // s3_quant #if defined(HAVE_S3QUANT) @@ -190,25 +191,6 @@ void FastCompressorDXT5n::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alpha QuickCompress::compressDXT5(rgba, block); } -void FastCompressorBC4::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output) -{ - BlockATI1 * block = new(output) BlockATI1; - - rgba.swizzle(0, 1, 2, 0); // Copy red to alpha - QuickCompress::compressDXT5A(rgba, &block->alpha); -} - -void FastCompressorBC5::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output) -{ - BlockATI2 * block = new(output) BlockATI2; - - rgba.swizzle(0, 1, 2, 0); // Copy red to alpha - QuickCompress::compressDXT5A(rgba, &block->x); - - rgba.swizzle(0, 1, 2, 1); // Copy green to alpha - QuickCompress::compressDXT5A(rgba, &block->y); -} - void NormalCompressorDXT1::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output) { @@ -367,27 +349,6 @@ void NormalCompressorDXT5n::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alp } -void ProductionCompressorBC4::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output) -{ - BlockATI1 * block = new(output) BlockATI1; - - rgba.swizzle(0, 1, 2, 0); // Copy red to alpha - OptimalCompress::compressDXT5A(rgba, &block->alpha); -} - -void ProductionCompressorBC5::compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output) -{ - BlockATI2 * block = new(output) BlockATI2; - - rgba.swizzle(0, 1, 2, 0); // Copy red to alpha - OptimalCompress::compressDXT5A(rgba, &block->x); - - rgba.swizzle(0, 1, 2, 1); // Copy green to alpha - OptimalCompress::compressDXT5A(rgba, &block->y); -} - - - #if defined(HAVE_S3QUANT) void S3CompressorDXT1::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alphaMode, uint w, uint h, void * data, const nvtt::CompressionOptions::Private & compressionOptions, const nvtt::OutputOptions::Private & outputOptions) diff --git a/src/nvtt/CompressorDXT.h b/src/nvtt/CompressorDXT.h index a4ec26e..d1673c7 100644 --- a/src/nvtt/CompressorDXT.h +++ b/src/nvtt/CompressorDXT.h @@ -21,11 +21,9 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#ifndef NV_TT_COMPRESSORDXT_H -#define NV_TT_COMPRESSORDXT_H +#ifndef NVTT_COMPRESSORDXT_H +#define NVTT_COMPRESSORDXT_H -#include -#include "nvtt.h" #include "Compressor.h" namespace nv @@ -72,18 +70,6 @@ namespace nv virtual uint blockSize() const { return 16; } }; - struct FastCompressorBC4 : public FixedBlockCompressor - { - virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); - virtual uint blockSize() const { return 8; } - }; - - struct FastCompressorBC5 : public FixedBlockCompressor - { - virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); - virtual uint blockSize() const { return 16; } - }; - // Normal CPU compressors. struct NormalCompressorDXT1 : public FixedBlockCompressor @@ -117,20 +103,6 @@ namespace nv }; - // Production CPU compressors. - struct ProductionCompressorBC4 : public FixedBlockCompressor - { - virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); - virtual uint blockSize() const { return 8; } - }; - - struct ProductionCompressorBC5 : public FixedBlockCompressor - { - virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); - virtual uint blockSize() const { return 16; } - }; - - // External compressors. #if defined(HAVE_S3QUANT) struct S3CompressorDXT1 : public CompressorInterface @@ -176,4 +148,4 @@ namespace nv } // nv namespace -#endif // NV_TT_COMPRESSORDXT_H +#endif // NVTT_COMPRESSORDXT_H diff --git a/src/nvtt/CompressorRGB.h b/src/nvtt/CompressorRGB.h index 1010f4d..26e7966 100644 --- a/src/nvtt/CompressorRGB.h +++ b/src/nvtt/CompressorRGB.h @@ -21,10 +21,9 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#ifndef NV_TT_COMPRESSORRGB_H -#define NV_TT_COMPRESSORRGB_H +#ifndef NVTT_COMPRESSORRGB_H +#define NVTT_COMPRESSORRGB_H -#include "nvtt.h" #include "Compressor.h" namespace nv @@ -37,4 +36,4 @@ namespace nv } // nv namespace -#endif // NV_TT_COMPRESSORRGB_H +#endif // NVTT_COMPRESSORRGB_H diff --git a/src/nvtt/CompressorRGBE.h b/src/nvtt/CompressorRGBE.h index 97fd3eb..5be9bfa 100644 --- a/src/nvtt/CompressorRGBE.h +++ b/src/nvtt/CompressorRGBE.h @@ -21,10 +21,9 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#ifndef NV_TT_COMPRESSORRGBE_H -#define NV_TT_COMPRESSORRGBE_H +#ifndef NVTT_COMPRESSORRGBE_H +#define NVTT_COMPRESSORRGBE_H -#include "nvtt.h" #include "Compressor.h" namespace nv @@ -37,4 +36,4 @@ namespace nv } // nv namespace -#endif // NV_TT_COMPRESSORRGBE_H +#endif // NVTT_COMPRESSORRGBE_H diff --git a/src/nvtt/Context.cpp b/src/nvtt/Context.cpp index 6d2e230..879791a 100644 --- a/src/nvtt/Context.cpp +++ b/src/nvtt/Context.cpp @@ -45,6 +45,8 @@ #include "TexImage.h" #include "CompressorDXT.h" +#include "CompressorDX10.h" +#include "CompressorDX11.h" #include "CompressorRGB.h" #include "CompressorRGBE.h" #include "cuda/CudaUtils.h" diff --git a/src/nvtt/InputOptions.h b/src/nvtt/InputOptions.h index 444a7ca..91e0752 100644 --- a/src/nvtt/InputOptions.h +++ b/src/nvtt/InputOptions.h @@ -21,8 +21,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#ifndef NV_TT_INPUTOPTIONS_H -#define NV_TT_INPUTOPTIONS_H +#ifndef NVTT_INPUTOPTIONS_H +#define NVTT_INPUTOPTIONS_H #include #include @@ -120,4 +120,4 @@ namespace nvtt } // nvtt namespace -#endif // NV_TT_INPUTOPTIONS_H +#endif // NVTT_INPUTOPTIONS_H diff --git a/src/nvtt/TexImage.h b/src/nvtt/TexImage.h index b78c9a3..9a34f24 100644 --- a/src/nvtt/TexImage.h +++ b/src/nvtt/TexImage.h @@ -21,8 +21,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#ifndef NV_TT_TEXIMAGE_H -#define NV_TT_TEXIMAGE_H +#ifndef NVTT_TEXIMAGE_H +#define NVTT_TEXIMAGE_H #include "nvtt.h" @@ -78,4 +78,4 @@ namespace nvtt } // nvtt namespace -#endif // NV_TT_TEXIMAGE_H +#endif // NVTT_TEXIMAGE_H diff --git a/src/nvtt/nvtt.h b/src/nvtt/nvtt.h index 880004c..25189ff 100644 --- a/src/nvtt/nvtt.h +++ b/src/nvtt/nvtt.h @@ -22,8 +22,8 @@ // OTHER DEALINGS IN THE SOFTWARE. #pragma once -#ifndef NV_TT_H -#define NV_TT_H +#ifndef NVTT_H +#define NVTT_H // Function linkage #if NVTT_SHARED @@ -474,4 +474,4 @@ namespace nvtt } // nvtt namespace -#endif // NV_TT_H +#endif // NVTT_H diff --git a/src/nvtt/squish/maths.h b/src/nvtt/squish/maths.h index 19f1d9d..9b892a6 100644 --- a/src/nvtt/squish/maths.h +++ b/src/nvtt/squish/maths.h @@ -234,6 +234,6 @@ private: Sym3x3 ComputeWeightedCovariance( int n, Vec3 const* points, float const* weights, Vec3::Arg metric ); Vec3 ComputePrincipleComponent( Sym3x3 const& matrix ); -} // namespace squish +} // namespace nvsquish #endif // ndef SQUISH_MATHS_H