From bd74a9ffc6cfcfec34a5c59b224df5933ae9eff7 Mon Sep 17 00:00:00 2001 From: castano Date: Thu, 21 Oct 2010 18:44:10 +0000 Subject: [PATCH] Merge changes from the-witness. --- src/nvcore/Array.h | 64 ++++++++++----------- src/nvcore/Debug.cpp | 57 ++++++++++++++++-- src/nvcore/DefsVcWin32.h | 2 +- src/nvcore/FileSystem.cpp | 11 +++- src/nvcore/Library.cpp | 8 ++- src/nvcore/Memory.h | 2 +- src/nvcore/StrLib.cpp | 6 +- src/nvcore/nvcore.h | 18 ++++-- src/nvimage/BlockDXT.cpp | 28 ++++----- src/nvimage/DirectDrawSurface.cpp | 4 +- src/nvimage/FloatImage.cpp | 2 +- src/nvimage/Image.cpp | 2 +- src/nvimage/ImageIO.cpp | 2 +- src/nvimage/NormalMap.cpp | 4 +- src/nvimage/nvimage.h | 58 +++++++++---------- src/nvmath/Fitting.cpp | 2 +- src/nvmath/Half.cpp | 11 +++- src/nvmath/Vector.h | 4 ++ src/nvmath/nvmath.h | 6 +- src/nvtt/Context.cpp | 6 +- src/nvtt/TexImage.cpp | 12 ++-- src/nvtt/cuda/CudaCompressorDXT.cpp | 13 ++++- src/nvtt/experimental/nvtt_experimental.cpp | 3 - src/nvtt/squish/alpha.h | 2 +- src/nvtt/squish/squish.cpp | 2 +- src/nvtt/tests/testsuite.cpp | 4 +- src/nvtt/tools/thumbnailer.cpp | 10 ++-- 27 files changed, 217 insertions(+), 126 deletions(-) diff --git a/src/nvcore/Array.h b/src/nvcore/Array.h index f8fe814..f7fa5ce 100644 --- a/src/nvcore/Array.h +++ b/src/nvcore/Array.h @@ -120,46 +120,46 @@ namespace nv /// Const element access. - const T & operator[]( uint index ) const + NV_FORCEINLINE const T & operator[]( uint index ) const { nvDebugCheck(index < m_size); return m_buffer[index]; } - const T & at( uint index ) const + NV_FORCEINLINE const T & at( uint index ) const { nvDebugCheck(index < m_size); return m_buffer[index]; } /// Element access. - T & operator[] ( uint index ) + NV_FORCEINLINE T & operator[] ( uint index ) { nvDebugCheck(index < m_size); return m_buffer[index]; } - T & at( uint index ) + NV_FORCEINLINE T & at( uint index ) { nvDebugCheck(index < m_size); return m_buffer[index]; } /// Get vector size. - uint size() const { return m_size; } + NV_FORCEINLINE uint size() const { return m_size; } /// Get vector size. - uint count() const { return m_size; } + NV_FORCEINLINE uint count() const { return m_size; } /// Get const vector pointer. - const T * buffer() const { return m_buffer; } + NV_FORCEINLINE const T * buffer() const { return m_buffer; } /// Get vector pointer. - T * mutableBuffer() { return m_buffer; } + NV_FORCEINLINE T * mutableBuffer() { return m_buffer; } /// Is vector empty. - bool isEmpty() const { return m_size == 0; } + NV_FORCEINLINE bool isEmpty() const { return m_size == 0; } /// Is a null vector. - bool isNull() const { return m_buffer == NULL; } + NV_FORCEINLINE bool isNull() const { return m_buffer == NULL; } /// Push an element at the end of the vector. @@ -179,17 +179,17 @@ namespace nv new(m_buffer+new_size-1) T(val); } } - void pushBack( const T & val ) + NV_FORCEINLINE void pushBack( const T & val ) { push_back(val); } - void append( const T & val ) + NV_FORCEINLINE void append( const T & val ) { push_back(val); } /// Qt like push operator. - Array & operator<< ( T & t ) + NV_FORCEINLINE Array & operator<< ( T & t ) { push_back(t); return *this; @@ -201,41 +201,41 @@ namespace nv nvDebugCheck( m_size > 0 ); resize( m_size - 1 ); } - void popBack() + NV_FORCEINLINE void popBack() { pop_back(); } /// Get back element. - const T & back() const + NV_FORCEINLINE const T & back() const { nvDebugCheck( m_size > 0 ); return m_buffer[m_size-1]; } /// Get back element. - T & back() + NV_FORCEINLINE T & back() { nvDebugCheck( m_size > 0 ); return m_buffer[m_size-1]; } /// Get front element. - const T & front() const + NV_FORCEINLINE const T & front() const { nvDebugCheck( m_size > 0 ); return m_buffer[0]; } /// Get front element. - T & front() + NV_FORCEINLINE T & front() { nvDebugCheck( m_size > 0 ); return m_buffer[0]; } /// Return true if element found. - bool find(const T & element, uint * index) const + NV_FORCEINLINE bool find(const T & element, uint * index) const { return find(element, 0, m_size, index); } @@ -253,7 +253,7 @@ namespace nv } /// Check if the given element is contained in the array. - bool contains(const T & e) const + NV_FORCEINLINE bool contains(const T & e) const { return find(e, NULL); } @@ -301,7 +301,7 @@ namespace nv } /// Append the given data to our vector. - void append(const Array & other) + NV_FORCEINLINE void append(const Array & other) { append(other.m_buffer, other.m_size); } @@ -324,7 +324,7 @@ namespace nv void replaceWithLast(uint index) { nvDebugCheck( index < m_size ); - swap(m_buffer[index], back()); + nv::swap(m_buffer[index], back()); //m_buffer[index] = back(); (m_buffer+m_size-1)->~T(); m_size--; @@ -409,13 +409,13 @@ namespace nv } /// Clear the buffer. - void clear() + NV_FORCEINLINE void clear() { resize(0); } /// Shrink the allocated vector. - void shrink() + NV_FORCEINLINE void shrink() { if (m_size < m_buffer_size) { allocate(m_size); @@ -423,7 +423,7 @@ namespace nv } /// Preallocate space. - void reserve(uint desired_size) + NV_FORCEINLINE void reserve(uint desired_size) { if (desired_size > m_buffer_size) { allocate( desired_size ); @@ -440,7 +440,7 @@ namespace nv } /// Assignment operator. - Array & operator=( const Array & a ) + NV_FORCEINLINE Array & operator=( const Array & a ) { copy(a.m_buffer, a.m_size); return *this; @@ -470,15 +470,15 @@ namespace nv // Array enumerator. typedef uint PseudoIndex; - PseudoIndex start() const { return 0; } - bool isDone(const PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); return i == this->m_size; }; - void advance(PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); i++; } + NV_FORCEINLINE PseudoIndex start() const { return 0; } + NV_FORCEINLINE bool isDone(const PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); return i == this->m_size; }; + NV_FORCEINLINE void advance(PseudoIndex & i) const { nvDebugCheck(i <= this->m_size); i++; } #if NV_CC_MSVC - T & operator[]( const PseudoIndexWrapper & i ) { + NV_FORCEINLINE T & operator[]( const PseudoIndexWrapper & i ) { return m_buffer[i(this)]; } - const T & operator[]( const PseudoIndexWrapper & i ) const { + NV_FORCEINLINE const T & operator[]( const PseudoIndexWrapper & i ) const { return m_buffer[i(this)]; } #endif @@ -510,7 +510,7 @@ namespace nv // realloc the buffer else { - m_buffer = (T *) realloc( m_buffer, sizeof(T) * m_buffer_size ); + m_buffer = realloc(m_buffer, m_buffer_size); } } diff --git a/src/nvcore/Debug.cpp b/src/nvcore/Debug.cpp index 3f971dc..b348292 100644 --- a/src/nvcore/Debug.cpp +++ b/src/nvcore/Debug.cpp @@ -24,6 +24,13 @@ # pragma comment(lib,"dbghelp.lib") #endif +#if NV_OS_XBOX +# include +# ifdef _DEBUG +# include +# endif //_DEBUG +#endif //NV_OS_XBOX + #if !NV_OS_WIN32 && defined(HAVE_SIGNAL_H) # include #endif @@ -419,7 +426,7 @@ namespace #if NV_OS_WIN32 //&& NV_CC_MSVC - /** Win32 asset handler. */ + /** Win32 assert handler. */ struct Win32AssertHandler : public AssertHandler { // Code from Daniel Vogel. @@ -491,10 +498,50 @@ namespace return ret; } }; +#elif NV_OS_XBOX + + /** Xbox360 assert handler. */ + struct Xbox360AssertHandler : public AssertHandler + { + static bool isDebuggerPresent() + { +#ifdef _DEBUG + return DmIsDebuggerPresent() == TRUE; +#else + return false; +#endif + } + + // Assert handler method. + virtual int assertion( const char * exp, const char * file, int line, const char * func/*=NULL*/ ) + { + int ret = NV_ABORT_EXIT; + + StringBuilder error_string; + if( func != NULL ) { + error_string.format( "*** Assertion failed: %s\n On file: %s\n On function: %s\n On line: %d\n ", exp, file, func, line ); + nvDebug( error_string.str() ); + } + else { + error_string.format( "*** Assertion failed: %s\n On file: %s\n On line: %d\n ", exp, file, line ); + nvDebug( error_string.str() ); + } + + if (isDebuggerPresent()) { + return NV_ABORT_DEBUG; + } + if( ret == NV_ABORT_EXIT ) { + // Exit cleanly. + throw "Assertion failed"; + } + + return ret; + } + }; #else - /** Unix asset handler. */ + /** Unix assert handler. */ struct UnixAssertHandler : public AssertHandler { bool isDebuggerPresent() @@ -552,11 +599,13 @@ namespace } // namespace -/// Handle assertion through the asset handler. +/// Handle assertion through the assert handler. int nvAbort(const char * exp, const char * file, int line, const char * func/*=NULL*/) { #if NV_OS_WIN32 //&& NV_CC_MSVC static Win32AssertHandler s_default_assert_handler; +#elif NV_OS_XBOX + static Xbox360AssertHandler s_default_assert_handler; #else static UnixAssertHandler s_default_assert_handler; #endif @@ -585,7 +634,7 @@ void NV_CDECL nvDebugPrint(const char *msg, ...) /// Dump debug info. void debug::dumpInfo() { -#if NV_OS_WIN32 || (defined(HAVE_SIGNAL_H) && defined(HAVE_EXECINFO_H)) +#if (NV_OS_WIN32 && NV_CC_MSVC) || (defined(HAVE_SIGNAL_H) && defined(HAVE_EXECINFO_H)) if (hasStackTrace()) { void * trace[64]; diff --git a/src/nvcore/DefsVcWin32.h b/src/nvcore/DefsVcWin32.h index 785922d..e92d67c 100644 --- a/src/nvcore/DefsVcWin32.h +++ b/src/nvcore/DefsVcWin32.h @@ -13,7 +13,6 @@ #define NV_CDECL __cdecl #define NV_STDCALL __stdcall #define NV_FASTCALL __fastcall -#define NV_FORCEINLINE __forceinline #define NV_DEPRECATED #define NV_PURE @@ -43,6 +42,7 @@ #endif #define NV_NOINLINE __declspec(noinline) +#define NV_FORCEINLINE __forceinline /* // Type definitions diff --git a/src/nvcore/FileSystem.cpp b/src/nvcore/FileSystem.cpp index 16bb48c..0c7ec01 100644 --- a/src/nvcore/FileSystem.cpp +++ b/src/nvcore/FileSystem.cpp @@ -7,6 +7,8 @@ //#include // PathFileExists #include // GetFileAttributes #include // _mkdir +#elif NV_OS_XBOX +#include #else #include #include @@ -23,7 +25,7 @@ bool FileSystem::exists(const char * path) return access(path, F_OK|R_OK) == 0; //struct stat buf; //return stat(path, &buf) == 0; -#elif NV_OS_WIN32 +#elif NV_OS_WIN32 || NV_OS_XBOX // PathFileExists requires linking to shlwapi.lib //return PathFileExists(path) != 0; return GetFileAttributesA(path) != 0xFFFFFFFF; @@ -39,8 +41,8 @@ bool FileSystem::exists(const char * path) bool FileSystem::createDirectory(const char * path) { -#if NV_OS_WIN32 - return _mkdir(path) != -1; +#if NV_OS_WIN32 || NV_OS_XBOX + return CreateDirectory(path, NULL) != 0; #else return mkdir(path, 0777) != -1; #endif @@ -50,6 +52,9 @@ bool FileSystem::changeDirectory(const char * path) { #if NV_OS_WIN32 return _chdir(path) != -1; +#elif NV_OS_XBOX + // Xbox doesn't support Current Working Directory! + return false; #else return chdir(path) != -1; #endif diff --git a/src/nvcore/Library.cpp b/src/nvcore/Library.cpp index 4da6695..d757e8f 100644 --- a/src/nvcore/Library.cpp +++ b/src/nvcore/Library.cpp @@ -6,6 +6,8 @@ #define WIN32_LEAN_AND_MEAN #define VC_EXTRALEAN #include +#elif NV_OS_XBOX +#include #else #include #endif @@ -16,6 +18,8 @@ void * nvLoadLibrary(const char * name) { #if NV_OS_WIN32 return (void *)LoadLibraryExA( name, NULL, 0 ); +#elif NV_OS_XBOX + return (void *)LoadLibraryA( name ); #else return dlopen(name, RTLD_LAZY); #endif @@ -24,7 +28,7 @@ void * nvLoadLibrary(const char * name) void nvUnloadLibrary(void * handle) { nvDebugCheck(handle != NULL); -#if NV_OS_WIN32 +#if NV_OS_WIN32 || NV_OS_XBOX FreeLibrary((HMODULE)handle); #else dlclose(handle); @@ -33,7 +37,7 @@ void nvUnloadLibrary(void * handle) void * nvBindSymbol(void * handle, const char * symbol) { -#if NV_OS_WIN32 +#if NV_OS_WIN32 || NV_OS_XBOX return (void *)GetProcAddress((HMODULE)handle, symbol); #else return (void *)dlsym(handle, symbol); diff --git a/src/nvcore/Memory.h b/src/nvcore/Memory.h index 8ad3238..67d37c7 100644 --- a/src/nvcore/Memory.h +++ b/src/nvcore/Memory.h @@ -44,7 +44,7 @@ namespace nv { } template void free(const T * ptr) { - ::free((T *)ptr); + ::free((void *)ptr); } } // nv namespace diff --git a/src/nvcore/StrLib.cpp b/src/nvcore/StrLib.cpp index bb57527..3fee676 100644 --- a/src/nvcore/StrLib.cpp +++ b/src/nvcore/StrLib.cpp @@ -15,17 +15,17 @@ namespace { static char * strAlloc(uint size) { - return static_cast(malloc(size)); + return malloc(size); } static char * strReAlloc(char * str, uint size) { - return static_cast(realloc(str, size)); + return realloc(str, size); } static void strFree(const char * str) { - return free(const_cast(str)); + return free(str); } /*static char * strDup( const char * str ) diff --git a/src/nvcore/nvcore.h b/src/nvcore/nvcore.h index ebbf815..327d866 100644 --- a/src/nvcore/nvcore.h +++ b/src/nvcore/nvcore.h @@ -33,6 +33,7 @@ // NV_OS_LINUX // NV_OS_UNIX // NV_OS_DARWIN +// NV_OS_XBOX #define NV_OS_STRING POSH_OS_STRING @@ -56,6 +57,8 @@ # define NV_OS_WIN32 1 #elif defined POSH_OS_WIN64 # define NV_OS_WIN64 1 +#elif defined POSH_OS_XBOX +# define NV_OS_XBOX 1 #else # error "Unsupported OS" #endif @@ -148,12 +151,17 @@ typedef uint32 uint; #define NV_DO_STRING_JOIN3(arg1, arg2, arg3) arg1 ## arg2 ## arg3 #define NV_STRING2(x) #x #define NV_STRING(x) NV_STRING2(x) -#if NV_CC_GNUC -//#define NV_FILE_LINE __FILE__ ":" NV_STRING(__LINE__) ": " -#define NV_FILE_LINE + +#if 1 +#if NV_CC_MSVC +#define NV_MESSAGE(x) message(__FILE__ "(" NV_STRING(__LINE__) ") : " x) #else -#define NV_FILE_LINE __FILE__ "(" NV_STRING(__LINE__) ") : " +#define NV_MESSAGE(x) message(x) #endif +#else +#define NV_MESSAGE(x) +#endif + // Startup initialization macro. #define NV_AT_STARTUP(some_code) \ @@ -180,6 +188,8 @@ typedef uint32 uint; #if NV_CC_MSVC # if NV_OS_WIN32 # include "DefsVcWin32.h" +# elif NV_OS_XBOX +# include "DefsVcXBox.h" # else # error "MSVC: Platform not supported" # endif diff --git a/src/nvimage/BlockDXT.cpp b/src/nvimage/BlockDXT.cpp index 455a735..0831751 100644 --- a/src/nvimage/BlockDXT.cpp +++ b/src/nvimage/BlockDXT.cpp @@ -96,35 +96,37 @@ uint BlockDXT1::evaluatePalette(Color32 color_array[4]) const uint BlockDXT1::evaluatePaletteNV5x(Color32 color_array[4]) const { // Does bit expansion before interpolation. - color_array[0].b = col0.b * 22 / 8; + color_array[0].b = (3 * col0.b * 22) / 8; color_array[0].g = (col0.g << 2) | (col0.g >> 4); - color_array[0].r = col0.r * 22 / 8; + color_array[0].r = (3 * col0.r * 22) / 8; color_array[0].a = 0xFF; - color_array[1].r = col1.r * 22 / 8; + color_array[1].r = (3 * col1.r * 22) / 8; color_array[1].g = (col1.g << 2) | (col1.g >> 4); - color_array[1].b = col1.b * 22 / 8; + color_array[1].b = (3 * col1.b * 22) / 8; color_array[1].a = 0xFF; + int gdiff = color_array[1].g - color_array[0].g; + if( col0.u > col1.u ) { // Four-color block: derive the other two colors. - color_array[2].r = (2 * col0.r + col1.r) * 22 / 8; - color_array[2].g = (256 * color_array[0].g + (color_array[1].g - color_array[0].g)/4 + 128 + (color_array[1].g - color_array[0].g) * 80) / 256; - color_array[2].b = (2 * col0.b + col1.b) * 22 / 8; + color_array[2].r = ((2 * col0.r + col1.r) * 22) / 8; + color_array[2].g = (256 * color_array[0].g + gdiff / 4 + 128 + gdiff * 80) / 256; + color_array[2].b = ((2 * col0.b + col1.b) * 22) / 8; color_array[2].a = 0xFF; - color_array[3].r = (2 * col1.r + col0.r) * 22 / 8; - color_array[3].g = (256 * color_array[1].g + (color_array[0].g - color_array[1].g)/4 + 128 + (color_array[0].g - color_array[1].g) * 80) / 256; - color_array[3].b = (2 * col1.b + col0.b) * 22 / 8; + color_array[3].r = ((2 * col1.r + col0.r) * 22) / 8; + color_array[3].g = (256 * color_array[1].g - gdiff / 4 + 128 - gdiff * 80) / 256; + color_array[3].b = ((2 * col1.b + col0.b) * 22) / 8; color_array[3].a = 0xFF; return 4; } else { // Three-color block: derive the other color. - color_array[2].r = (col0.r + col1.r) * 33 / 8; - color_array[2].g = (256 * color_array[0].g + (color_array[1].g - color_array[0].g)/4 + 128 + (color_array[1].g - color_array[0].g) * 128) / 256; - color_array[2].b = (col0.b + col1.b) * 33 / 8; + color_array[2].r = ((col0.r + col1.r) * 33) / 8; + color_array[2].g = (256 * color_array[0].g + gdiff / 4 + 128 + gdiff * 128) / 256; + color_array[2].b = ((col0.b + col1.b) * 33) / 8; color_array[2].a = 0xFF; // Set all components to 0 to match DXT specs. diff --git a/src/nvimage/DirectDrawSurface.cpp b/src/nvimage/DirectDrawSurface.cpp index 5eb8a7b..5f229b3 100644 --- a/src/nvimage/DirectDrawSurface.cpp +++ b/src/nvimage/DirectDrawSurface.cpp @@ -977,7 +977,7 @@ bool DirectDrawSurface::hasAlpha() const { if (header.hasDX10Header()) { -#pragma message(NV_FILE_LINE "TODO: Update hasAlpha to handle all DX10 formats.") +#pragma NV_MESSAGE("TODO: Update hasAlpha to handle all DX10 formats.") return header.header10.dxgiFormat == DXGI_FORMAT_BC1_UNORM || header.header10.dxgiFormat == DXGI_FORMAT_BC2_UNORM || @@ -1187,7 +1187,7 @@ void DirectDrawSurface::readLinearImage(Image * img) uint byteCount = (header.pf.bitcount + 7) / 8; -#pragma message(NV_FILE_LINE "TODO: Support floating point linear images and other FOURCC codes.") +#pragma NV_MESSAGE("TODO: Support floating point linear images and other FOURCC codes.") // Read linear RGB images. for (uint y = 0; y < h; y++) diff --git a/src/nvimage/FloatImage.cpp b/src/nvimage/FloatImage.cpp index f9707b2..ac08717 100644 --- a/src/nvimage/FloatImage.cpp +++ b/src/nvimage/FloatImage.cpp @@ -152,7 +152,7 @@ void FloatImage::resizeChannelCount(uint c) { if (m_componentNum != c) { uint count = m_width * m_height * c; - realloc(m_mem, count * sizeof(float)); + realloc(m_mem, count); if (c > m_componentNum) { memset(m_mem + m_count, 0, (count - m_count) * sizeof(float)); diff --git a/src/nvimage/Image.cpp b/src/nvimage/Image.cpp index 443febc..2b4bfbe 100644 --- a/src/nvimage/Image.cpp +++ b/src/nvimage/Image.cpp @@ -42,7 +42,7 @@ void Image::allocate(uint w, uint h) free(); m_width = w; m_height = h; - m_data = (Color32 *)realloc(m_data, w * h * sizeof(Color32)); + m_data = realloc(m_data, w * h); } bool Image::load(const char * name) diff --git a/src/nvimage/ImageIO.cpp b/src/nvimage/ImageIO.cpp index 8593ae8..53b1da2 100644 --- a/src/nvimage/ImageIO.cpp +++ b/src/nvimage/ImageIO.cpp @@ -224,7 +224,7 @@ FloatImage * nv::ImageIO::loadFloat(const char * fileName, Stream & s) } } #else // defined(HAVE_FREEIMAGE) -#pragma message(NV_FILE_LINE "TODO: Load TIFF and EXR files from stream.") +#pragma NV_MESSAGE("TODO: Load TIFF and EXR files from stream.") #if defined(HAVE_TIFF) if (strCaseCmp(extension, ".tif") == 0 || strCaseCmp(extension, ".tiff") == 0) { return loadFloatTIFF(fileName, s); diff --git a/src/nvimage/NormalMap.cpp b/src/nvimage/NormalMap.cpp index 51967d8..c4981c0 100644 --- a/src/nvimage/NormalMap.cpp +++ b/src/nvimage/NormalMap.cpp @@ -82,7 +82,7 @@ static FloatImage * createNormalMap(const FloatImage * img, FloatImage::WrapMode nvDebugCheck(kdv != NULL); nvDebugCheck(img != NULL); -#pragma message(NV_FILE_LINE "FIXME: Height scale parameter should go away. It should be a sensible value that produces good results when the heightmap is in the [0, 1] range.") +#pragma NV_MESSAGE("FIXME: Height scale parameter should go away. It should be a sensible value that produces good results when the heightmap is in the [0, 1] range.") const float heightScale = 1.0f / 16.0f; const uint w = img->width(); @@ -198,7 +198,7 @@ void nv::normalizeNormalMap(FloatImage * img) { nvDebugCheck(img != NULL); -#pragma message(NV_FILE_LINE "TODO: Pack and expand normals explicitly?") +#pragma NV_MESSAGE("TODO: Pack and expand normals explicitly?") img->expandNormals(0); img->normalize(0); diff --git a/src/nvimage/nvimage.h b/src/nvimage/nvimage.h index 03f9c2e..4eff444 100644 --- a/src/nvimage/nvimage.h +++ b/src/nvimage/nvimage.h @@ -1,33 +1,33 @@ -// This code is in the public domain -- castanyo@yahoo.es - -#pragma once -#ifndef NV_IMAGE_H -#define NV_IMAGE_H - -#include - -// Function linkage -#if NVIMAGE_SHARED -#ifdef NVIMAGE_EXPORTS -#define NVIMAGE_API DLL_EXPORT -#define NVIMAGE_CLASS DLL_EXPORT_CLASS -#else -#define NVIMAGE_API DLL_IMPORT -#define NVIMAGE_CLASS DLL_IMPORT -#endif -#else -#define NVIMAGE_API -#define NVIMAGE_CLASS -#endif - - -// Some utility functions: - +// This code is in the public domain -- castanyo@yahoo.es + +#pragma once +#ifndef NV_IMAGE_H +#define NV_IMAGE_H + +#include + +// Function linkage +#if NVIMAGE_SHARED +#ifdef NVIMAGE_EXPORTS +#define NVIMAGE_API DLL_EXPORT +#define NVIMAGE_CLASS DLL_EXPORT_CLASS +#else +#define NVIMAGE_API DLL_IMPORT +#define NVIMAGE_CLASS DLL_IMPORT +#endif +#else +#define NVIMAGE_API +#define NVIMAGE_CLASS +#endif + + +// Some utility functions: + inline uint computePitch(uint w, uint bitsize, uint alignment) { return ((w * bitsize + 8 * alignment - 1) / (8 * alignment)) * alignment; } - - - -#endif // NV_IMAGE_H + + + +#endif // NV_IMAGE_H diff --git a/src/nvmath/Fitting.cpp b/src/nvmath/Fitting.cpp index 1e86557..00adcb0 100644 --- a/src/nvmath/Fitting.cpp +++ b/src/nvmath/Fitting.cpp @@ -162,7 +162,7 @@ Plane nv::Fit::bestPlane(int n, const Vector3 *__restrict points) return Plane(Vector3(0, 0, 1), centroid); } -#pragma message(NV_FILE_LINE "TODO: need to write an eigensolver!") +#pragma NV_MESSAGE("TODO: need to write an eigensolver!") // - Numerical Recipes in C is a good reference. Householder transforms followed by QL decomposition seems to be the best approach. // - The one from magic-tools is now LGPL. For the 3D case it uses a cubic root solver, which is not very accurate. diff --git a/src/nvmath/Half.cpp b/src/nvmath/Half.cpp index 6cafc96..057bbaf 100644 --- a/src/nvmath/Half.cpp +++ b/src/nvmath/Half.cpp @@ -275,7 +275,10 @@ static inline uint16 _uint16_sels( uint16 test, uint16 a, uint16 b ) return (result); } -#if NV_CC_MSVC +#if NV_OS_XBOX +#include +#elif NV_CC_MSVC + #include #pragma intrinsic(_BitScanReverse) @@ -297,6 +300,9 @@ static inline uint32 _uint32_cntlz( uint32 x ) uint32 nlz = __builtin_clz( x ); uint32 result = _uint32_sels( is_x_nez_msb, nlz, 0x00000020 ); return (result); +#elif NV_OS_XBOX + // Xbox PPC has this as an intrinsic. + return _CountLeadingZeros(x); #elif NV_CC_MSVC uint32 is_x_nez_msb = _uint32_neg( x ); uint32 nlz = _uint32_nlz( x ); @@ -342,6 +348,9 @@ static inline uint16 _uint16_cntlz( uint16 x ) uint16 nlz32 = (uint16)_uint32_cntlz( (uint32)x ); uint32 nlz = _uint32_sub( nlz32, 16 ); return (nlz); +#elif _NV_OS_XBOX_ + uint16 nlz32 = (uint16)_CountLeadingZeros( (uint32)x ); + return _uint32_sub( nlz32, 16); #else const uint16 x0 = _uint16_srl( x, 1 ); const uint16 x1 = _uint16_or( x, x0 ); diff --git a/src/nvmath/Vector.h b/src/nvmath/Vector.h index 866c042..9a3f093 100644 --- a/src/nvmath/Vector.h +++ b/src/nvmath/Vector.h @@ -88,6 +88,10 @@ namespace nv }; }; + // Helpers to convert vector types. Assume T has x,y,z members and 3 argument constructor. + template Vector3 from(const T & v) { return Vector3(v.x, v.y, v.z); } + template T to(Vector3::Arg v) { return T(v.x, v.y, v.z); } + class NVMATH_CLASS Vector4 { diff --git a/src/nvmath/nvmath.h b/src/nvmath/nvmath.h index b565033..f516c2c 100644 --- a/src/nvmath/nvmath.h +++ b/src/nvmath/nvmath.h @@ -10,7 +10,7 @@ #include #include // INT_MAX -#if NV_OS_WIN32 +#if NV_OS_WIN32 || NV_OS_XBOX #include #endif @@ -116,7 +116,7 @@ namespace nv inline bool isFinite(const float f) { -#if NV_OS_WIN32 +#if NV_OS_WIN32 || NV_OS_XBOX return _finite(f) != 0; #elif NV_OS_DARWIN || NV_OS_FREEBSD return isfinite(f); @@ -131,7 +131,7 @@ namespace nv inline bool isNan(const float f) { -#if NV_OS_WIN32 +#if NV_OS_WIN32 || NV_OS_XBOX return _isnan(f) != 0; #elif NV_OS_DARWIN || NV_OS_FREEBSD return isnan(f); diff --git a/src/nvtt/Context.cpp b/src/nvtt/Context.cpp index dcdf374..8fc6174 100644 --- a/src/nvtt/Context.cpp +++ b/src/nvtt/Context.cpp @@ -224,7 +224,7 @@ Compressor::Compressor() : m(*new Compressor::Private()) if (m.cudaEnabled) { -#pragma message(NV_FILE_LINE "FIXME: This code is duplicated below.") +#pragma NV_MESSAGE("FIXME: This code is duplicated below.") // Select fastest CUDA device. int device = cuda::getFastestDevice(); if (!cuda::setDevice(device)) @@ -944,7 +944,7 @@ bool Compressor::Private::compressMipmaps(uint f, const InputOptions::Private & premultiplyAlphaMipmap(mipmap, inputOptions); } -#pragma message(NV_FILE_LINE "TODO: All color transforms should be done here!") +#pragma NV_MESSAGE("TODO: All color transforms should be done here!") // Apply gamma space color transforms: if (inputOptions.colorTransform == ColorTransform_YCoCg) @@ -1231,7 +1231,7 @@ void Compressor::Private::processInputImage(Mipmap & mipmap, const InputOptions: mipmap.toFloatImage(inputOptions); } -#pragma message(NV_FILE_LINE "FIXME: Do not perform color transforms here!") +#pragma NV_MESSAGE("FIXME: Do not perform color transforms here!") /*// Apply linear transforms in linear space. if (inputOptions.colorTransform == ColorTransform_Linear) diff --git a/src/nvtt/TexImage.cpp b/src/nvtt/TexImage.cpp index 4c1f8dd..c4f8fa7 100644 --- a/src/nvtt/TexImage.cpp +++ b/src/nvtt/TexImage.cpp @@ -61,7 +61,7 @@ namespace } } -#pragma message(NV_FILE_LINE "TODO: Move these functions to a common location.") +#pragma NV_MESSAGE("TODO: Move these functions to a common location.") static int blockSize(Format format) { @@ -288,7 +288,7 @@ bool TexImage::load(const char * fileName) bool TexImage::save(const char * fileName) const { -#pragma message(NV_FILE_LINE "TODO: Add support for DDS textures in TexImage::save") +#pragma NV_MESSAGE("TODO: Add support for DDS textures in TexImage::save") if (m->imageArray.count() == 0) { @@ -433,7 +433,7 @@ bool TexImage::setImage2D(Format format, Decoder decoder, int w, int h, int idx, return false; } -#pragma message(NV_FILE_LINE "TODO: Add support for all compressed formats in TexImage::setImage2D.") +#pragma NV_MESSAGE("TODO: Add support for all compressed formats in TexImage::setImage2D.") if (format != nvtt::Format_BC1 && format != nvtt::Format_BC2 && format != nvtt::Format_BC3) { @@ -526,7 +526,7 @@ bool TexImage::setImage2D(Format format, Decoder decoder, int w, int h, int idx, } -#pragma message(NV_FILE_LINE "TODO: provide a TexImage::resize that can override filter width and parameters.") +#pragma NV_MESSAGE("TODO: provide a TexImage::resize that can override filter width and parameters.") void TexImage::resize(int w, int h, ResizeFilter filter) { @@ -537,7 +537,7 @@ void TexImage::resize(int w, int h, ResizeFilter filter) if (m->type == TextureType_Cube) { -#pragma message(NV_FILE_LINE "TODO: Output error when image is cubemap and w != h.") +#pragma NV_MESSAGE("TODO: Output error when image is cubemap and w != h.") h = w; } @@ -1014,7 +1014,7 @@ void TexImage::toNormalMap(float sm, float medium, float big, float large) const FloatImage * img = m->imageArray[i]; m->imageArray[i] = nv::createNormalMap(img, (FloatImage::WrapMode)m->wrapMode, filterWeights); -#pragma message(NV_FILE_LINE "TODO: Pack and expand normals explicitly?") +#pragma NV_MESSAGE("TODO: Pack and expand normals explicitly?") m->imageArray[i]->packNormals(0); delete img; diff --git a/src/nvtt/cuda/CudaCompressorDXT.cpp b/src/nvtt/cuda/CudaCompressorDXT.cpp index 4180d8a..0795bc1 100644 --- a/src/nvtt/cuda/CudaCompressorDXT.cpp +++ b/src/nvtt/cuda/CudaCompressorDXT.cpp @@ -37,7 +37,6 @@ #include #include - #if defined HAVE_CUDA #include @@ -129,6 +128,8 @@ void CudaCompressor::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alp { nvDebugCheck(cuda::isHardwarePresent()); +#if defined HAVE_CUDA + // Allocate image as a cuda array. cudaArray * d_image; if (inputFormat == nvtt::InputFormat_BGRA_8UB) @@ -141,7 +142,7 @@ void CudaCompressor::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alp } else { -#pragma message(NV_FILE_LINE "FIXME: Floating point textures not really supported by CUDA compressors.") // @@ What's missing??? +#pragma NV_MESSAGE("FIXME: Floating point textures not really supported by CUDA compressors.") // @@ What's missing??? cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 32, 32, 32, cudaChannelFormatKindFloat); cudaMallocArray(&d_image, &channelDesc, w, h); @@ -189,8 +190,14 @@ void CudaCompressor::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alp free(h_result); cudaFreeArray(d_image); + +#else + outputOptions.error(Error_CudaError); +#endif + } +#if defined HAVE_CUDA void CudaCompressorDXT1::setup(cudaArray * image, const nvtt::CompressionOptions::Private & compressionOptions) { @@ -589,3 +596,5 @@ void CudaCompressor::compressDXT5n(const nvtt::CompressionOptions::Private & com } #endif // 0 + +#endif // defined HAVE_CUDA diff --git a/src/nvtt/experimental/nvtt_experimental.cpp b/src/nvtt/experimental/nvtt_experimental.cpp index 7d612aa..1d2c429 100644 --- a/src/nvtt/experimental/nvtt_experimental.cpp +++ b/src/nvtt/experimental/nvtt_experimental.cpp @@ -55,6 +55,3 @@ void nvttCompressImage(NvttImage * img, NvttFormat format) // @@ Invoke appropriate compressor. } - - -#endif // NVTT_EXPERIMENTAL_H diff --git a/src/nvtt/squish/alpha.h b/src/nvtt/squish/alpha.h index d09ba0e..2fb3baf 100644 --- a/src/nvtt/squish/alpha.h +++ b/src/nvtt/squish/alpha.h @@ -26,7 +26,7 @@ #ifndef SQUISH_ALPHA_H #define SQUISH_ALPHA_H -#include +#include "squish.h" namespace squish { diff --git a/src/nvtt/squish/squish.cpp b/src/nvtt/squish/squish.cpp index 6d9270e..393ebf4 100644 --- a/src/nvtt/squish/squish.cpp +++ b/src/nvtt/squish/squish.cpp @@ -23,7 +23,7 @@ -------------------------------------------------------------------------- */ -#include +#include "squish.h" #include "colourset.h" #include "maths.h" #include "rangefit.h" diff --git a/src/nvtt/tests/testsuite.cpp b/src/nvtt/tests/testsuite.cpp index 09475bb..8f77fa9 100644 --- a/src/nvtt/tests/testsuite.cpp +++ b/src/nvtt/tests/testsuite.cpp @@ -373,6 +373,8 @@ int main(int argc, char *argv[]) printf(" 1: \tWaterloo.\n"); printf(" 2: \tEpic.\n"); printf(" 3: \tFarbrausch.\n"); + printf(" 4: \Lugaru.\n"); + printf(" 5: \Quake 3.\n"); printf(" -dec x \tDecompressor.\n"); printf(" 0: \tReference.\n"); printf(" 1: \tNVIDIA.\n"); @@ -422,7 +424,7 @@ int main(int argc, char *argv[]) FileSystem::createDirectory(outPath); Path csvFileName; - csvFileName.format("%s/result.csv", outPath); + csvFileName.format("%s/result-%d.csv", outPath, set); StdOutputStream csvStream(csvFileName.str()); TextWriter csvWriter(&csvStream); diff --git a/src/nvtt/tools/thumbnailer.cpp b/src/nvtt/tools/thumbnailer.cpp index 48a511f..6270b5b 100644 --- a/src/nvtt/tools/thumbnailer.cpp +++ b/src/nvtt/tools/thumbnailer.cpp @@ -116,7 +116,7 @@ int main(int argc, char *argv[]) } nv::Image image; - if (!loadImage(image, input.str())) return 1; + if (!loadImage(image, input.str())) return 1; nv::ImageIO::ImageMetaData metaData; metaData.tagMap.add("Thumb::Image::Width", nv::StringBuilder().number (image.width())); @@ -143,13 +143,13 @@ int main(int argc, char *argv[]) nv::AutoPtr result(fresult->createImageGammaCorrect(gamma)); result->setFormat(nv::Image::Format_ARGB); - nv::StdOutputStream stream(output.str()); - nv::ImageIO::save(output.str(), stream, result.ptr(), &metaData); + nv::StdOutputStream stream(output.str()); + nv::ImageIO::save(output.str(), stream, result.ptr(), &metaData); } else { - nv::StdOutputStream stream(output.str()); - nv::ImageIO::save(output.str(), stream, &image, &metaData); + nv::StdOutputStream stream(output.str()); + nv::ImageIO::save(output.str(), stream, &image, &metaData); } return 0;