diff --git a/src/nvtt/CompressorDX11.cpp b/src/nvtt/CompressorDX11.cpp index 1659080..ba388c8 100644 --- a/src/nvtt/CompressorDX11.cpp +++ b/src/nvtt/CompressorDX11.cpp @@ -24,10 +24,31 @@ #include "CompressorDX11.h" #include "nvtt.h" +#include "CompressionOptions.h" + +#include "bc6h/zoh.h" +#include "bc6h/utils.h" using namespace nv; using namespace nvtt; +void CompressorBC6::compressBlock(Tile & tile, AlphaMode alphaMode, const CompressionOptions::Private & compressionOptions, void * output) +{ + NV_UNUSED(alphaMode); // ZOH does not support alpha. + + if (compressionOptions.pixelType == PixelType_UnsignedFloat || + compressionOptions.pixelType == PixelType_UnsignedNorm || + compressionOptions.pixelType == PixelType_UnsignedInt) + { + Utils::FORMAT = UNSIGNED_F16; // @@ Do not use globals. + } + else + { + Utils::FORMAT = SIGNED_F16; + } + + ZOH::compress(tile, (char *)output); +} diff --git a/src/nvtt/CompressorDX11.h b/src/nvtt/CompressorDX11.h index 61b29d0..3b97415 100644 --- a/src/nvtt/CompressorDX11.h +++ b/src/nvtt/CompressorDX11.h @@ -28,15 +28,15 @@ namespace nv { - struct CompressorBC6 : public FixedBlockCompressor + struct CompressorBC6 : public TileCompressor { - virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); + virtual void compressBlock(Tile & tile, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); virtual uint blockSize() const { return 16; } }; - struct CompressorBC7 : public FixedBlockCompressor + struct CompressorBC7 : public TileCompressor { - virtual void compressBlock(ColorBlock & rgba, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); + virtual void compressBlock(Tile & tile, nvtt::AlphaMode alphaMode, const nvtt::CompressionOptions::Private & compressionOptions, void * output); virtual uint blockSize() const { return 16; } }; diff --git a/src/nvtt/CompressorDXT.cpp b/src/nvtt/CompressorDXT.cpp index 0dea7b1..0ad2998 100644 --- a/src/nvtt/CompressorDXT.cpp +++ b/src/nvtt/CompressorDXT.cpp @@ -49,7 +49,6 @@ void FixedBlockCompressor::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMo const uint bs = blockSize(); const uint bw = (w + 3) / 4; const uint bh = (h + 3) / 4; - const uint size = bs * bw * bh; #if defined(HAVE_OPENMP) bool singleThreaded = false; @@ -61,9 +60,9 @@ void FixedBlockCompressor::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMo if (bw * bh < 16) singleThreaded = true; if (singleThreaded) - { - nvDebugCheck(bs <= 16); - uint8 mem[16]; + { + nvDebugCheck(bs <= 16); + uint8 mem[16]; // @@ Output one row at a time! for (int y = 0; y < int(h); y += 4) { for (uint x = 0; x < w; x += 4) { @@ -88,7 +87,8 @@ void FixedBlockCompressor::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMo #if defined(HAVE_OPENMP) else { - uint8 * mem = new uint8[size]; + const uint size = bs * bw * bh; + uint8 * mem = new uint8[size]; #pragma omp parallel { @@ -121,3 +121,40 @@ void FixedBlockCompressor::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMo #endif } + +#include "bc6h/tile.h" + +void TileCompressor::compress(InputFormat inputFormat, AlphaMode alphaMode, uint w, uint h, const void * data, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) +{ + const uint bs = blockSize(); + const uint bw = (w + 3) / 4; + const uint bh = (h + 3) / 4; + + bool singleThreaded = true; + + if (singleThreaded) + { + nvDebugCheck(bs <= 16); + uint8 mem[16]; // @@ Output one row at a time! + + for (uint y = 0; y < h; y += 4) { + for (uint x = 0; x < w; x += 4) { + + Tile tile; + if (inputFormat == nvtt::InputFormat_BGRA_8UB) { + //tile.init((const uint *)data, w, h, x, y); + } + else { + nvDebugCheck(inputFormat == nvtt::InputFormat_RGBA_32F); + //tile.init((const float *)data, w, h, x, y); + } + + compressBlock(tile, alphaMode, compressionOptions, mem); + + if (outputOptions.outputHandler != NULL) { + outputOptions.outputHandler->writeData(mem, bs); + } + } + } + } +} diff --git a/src/nvtt/CompressorDXT.h b/src/nvtt/CompressorDXT.h index 9ce4822..6e181aa 100644 --- a/src/nvtt/CompressorDXT.h +++ b/src/nvtt/CompressorDXT.h @@ -26,10 +26,11 @@ #include "Compressor.h" +struct Tile; + namespace nv { struct ColorBlock; - struct Tile; struct FixedBlockCompressor : public CompressorInterface { diff --git a/src/nvtt/bc6h/tile.h b/src/nvtt/bc6h/tile.h index cf3e88a..28e597c 100644 --- a/src/nvtt/bc6h/tile.h +++ b/src/nvtt/bc6h/tile.h @@ -75,7 +75,7 @@ public: static const int TILE_H = 4; static const int TILE_W = 4; static const int TILE_TOTAL = TILE_H * TILE_W; - Vector3 data[TILE_H][TILE_W]; + nv::Vector3 data[TILE_H][TILE_W]; float importance_map[TILE_H][TILE_W]; int size_x, size_y; // actual size of tile }; diff --git a/src/nvtt/bc6h/utils.h b/src/nvtt/bc6h/utils.h index 9d276c9..f4c0d5a 100644 --- a/src/nvtt/bc6h/utils.h +++ b/src/nvtt/bc6h/utils.h @@ -17,7 +17,6 @@ See the License for the specific language governing permissions and limitations #include "nvmath/Vector.h" -using namespace nv; // @@ Move everything to nv namespace instead. #define PALETTE_LERP(a, b, i, denom) Utils::lerp(a, b, i, denom) @@ -45,18 +44,18 @@ enum Format { UNSIGNED_F16, SIGNED_F16 }; class Utils { public: - static Format FORMAT; // this is a global -- we're either handling unsigned or unsigned half values + static ::Format FORMAT; // this is a global -- we're either handling unsigned or unsigned half values // error metrics - static double norm(const Vector3 &a, const Vector3 &b); - static double mpsnr_norm(const Vector3 &a, int exposure, const Vector3 &b); + static double norm(const nv::Vector3 &a, const nv::Vector3 &b); + static double mpsnr_norm(const nv::Vector3 &a, int exposure, const nv::Vector3 &b); // conversion & clamp static int ushort_to_format(unsigned short input); static unsigned short format_to_ushort(int input); // clamp to format - static void clamp(Vector3 &v); + static void clamp(nv::Vector3 &v); // quantization and unquantization static int finish_unquantize(int q, int prec); @@ -67,7 +66,7 @@ public: // lerping static int lerp(int a, int b, int i, int denom); - static Vector3 lerp(const Vector3 & a, const Vector3 & b, int i, int denom); + static nv::Vector3 lerp(const nv::Vector3 & a, const nv::Vector3 & b, int i, int denom); }; #endif // _UTILS_H diff --git a/src/nvtt/bc6h/zoh.h b/src/nvtt/bc6h/zoh.h index 0220706..64adcc3 100644 --- a/src/nvtt/bc6h/zoh.h +++ b/src/nvtt/bc6h/zoh.h @@ -29,8 +29,8 @@ See the License for the specific language governing permissions and limitations struct FltEndpts { - Vector3 A; - Vector3 B; + nv::Vector3 A; + nv::Vector3 B; }; struct IntEndpts diff --git a/src/nvtt/tools/CMakeLists.txt b/src/nvtt/tools/CMakeLists.txt index fe91761..f6e13d8 100644 --- a/src/nvtt/tools/CMakeLists.txt +++ b/src/nvtt/tools/CMakeLists.txt @@ -19,12 +19,12 @@ TARGET_LINK_LIBRARIES(nvzoom nvcore nvmath nvimage) SET(TOOLS nvcompress nvdecompress nvddsinfo nvassemble nvzoom) -IF(GLEW_FOUND AND GLUT_FOUND) - INCLUDE_DIRECTORIES(${GLEW_INCLUDE_PATH} ${GLUT_INCLUDE_DIR}) - ADD_EXECUTABLE(nvddsview ddsview.cpp cmdline.h) - TARGET_LINK_LIBRARIES(nvddsview nvcore nvmath nvimage ${GLEW_LIBRARY} ${GLUT_LIBRARY}) - SET(TOOLS ${TOOLS} nvddsview) -ENDIF(GLEW_FOUND AND GLUT_FOUND) +#IF(GLEW_FOUND AND GLUT_FOUND) +# INCLUDE_DIRECTORIES(${GLEW_INCLUDE_PATH} ${GLUT_INCLUDE_DIR}) +# ADD_EXECUTABLE(nvddsview ddsview.cpp cmdline.h) +# TARGET_LINK_LIBRARIES(nvddsview nvcore nvmath nvimage ${GLEW_LIBRARY} ${GLUT_LIBRARY}) +# SET(TOOLS ${TOOLS} nvddsview) +#ENDIF(GLEW_FOUND AND GLUT_FOUND) ADD_EXECUTABLE(nv-gnome-thumbnailer thumbnailer.cpp cmdline.h)