Upgrade NVTT to version 2.1.1, fixes #4549.

Windows binaries built with toolset v140_xp.
Tested under Windows, Linux and macOS.
Includes a patch for building on musl Linux, contributed by voroskoi,
containing code by leper.
Use the opportunity to set native line endings in the NVTT bundle.

The NVTT DLL was the last one built with VS 2010, refs #5379, #5527.

Differential Revision: https://code.wildfiregames.com/D2475
This was SVN commit r23305.
This commit is contained in:
Nicolas Auvray 2019-12-29 11:21:33 +00:00
parent fcac07213f
commit cc7071c691
5 changed files with 14 additions and 35 deletions

View File

@ -242,6 +242,7 @@
{"nick": "usey11"},
{"nick": "vincent_c", "name": "Vincent Cheng"},
{"nick": "vladislavbelov", "name": "Vladislav Belov"},
{"nick": "voroskoi"},
{"nick": "vts", "name": "Jeroen DR"},
{"nick": "wacko", "name": "Andrew Spiering"},
{"nick": "WhiteTreePaladin", "name": "Brian Ashley"},

View File

@ -463,7 +463,7 @@ extern_lib_defs = {
add_default_links({
win_names = { "nvtt" },
unix_names = { "nvcore", "nvmath", "nvimage", "nvtt" },
osx_names = { "nvcore", "nvmath", "nvimage", "nvtt", "squish" },
osx_names = { "bc6h", "bc7", "nvcore", "nvimage", "nvmath", "nvthread", "nvtt", "squish" },
dbg_suffix = "", -- for performance we always use the release-mode version
})
end,

View File

@ -1002,7 +1002,7 @@ then
# Could use CMAKE_OSX_DEPLOYMENT_TARGET and CMAKE_OSX_SYSROOT
# but they're not as flexible for cross-compiling
# Disable optional libs that we don't need (avoids some conflicts with MacPorts)
# Disable png support (avoids some conflicts with MacPorts)
(cmake .. \
-DCMAKE_LINK_FLAGS="$LDFLAGS" \
-DCMAKE_C_FLAGS="$CFLAGS" \
@ -1010,19 +1010,13 @@ then
-DCMAKE_BUILD_TYPE=Release \
-DBINDIR=bin \
-DLIBDIR=lib \
-DGLUT=0 \
-DGLEW=0 \
-DCG=0 \
-DCUDA=0 \
-DOPENEXR=0 \
-DJPEG=0 \
-DPNG=0 \
-DTIFF=0 \
-G "Unix Makefiles" \
&& make clean && make nvtt ${JOBS}) || die "NVTT build failed"
popd
mkdir -p ../lib
cp build/src/bc*/libbc*.a ../lib/
cp build/src/nv*/libnv*.a ../lib/
cp build/src/nvtt/squish/libsquish.a ../lib/
popd

View File

@ -52,6 +52,10 @@ struct BufferOutputHandler : public nvtt::OutputHandler
memcpy(&buffer[off], data, size);
return true;
}
virtual void endImage()
{
}
};
/**
@ -64,8 +68,6 @@ struct CTextureConverter::ConversionRequest
nvtt::InputOptions inputOptions;
nvtt::CompressionOptions compressionOptions;
nvtt::OutputOptions outputOptions;
bool isDXT1a; // see comment in RunThread
bool is8bpp;
};
/**
@ -383,9 +385,6 @@ bool CTextureConverter::ConvertTexture(const CTexturePtr& texture, const VfsPath
else
request->inputOptions.setAlphaMode(nvtt::AlphaMode_None);
request->isDXT1a = false;
request->is8bpp = false;
if (settings.format == FMT_RGBA)
{
request->compressionOptions.setFormat(nvtt::Format_RGBA);
@ -396,7 +395,6 @@ bool CTextureConverter::ConvertTexture(const CTexturePtr& texture, const VfsPath
{
request->compressionOptions.setFormat(nvtt::Format_RGBA);
request->compressionOptions.setPixelFormat(8, 0x00, 0x00, 0x00, 0xFF);
request->is8bpp = true;
}
else if (!hasAlpha)
{
@ -406,7 +404,6 @@ bool CTextureConverter::ConvertTexture(const CTexturePtr& texture, const VfsPath
else if (settings.format == FMT_DXT1)
{
request->compressionOptions.setFormat(nvtt::Format_DXT1a);
request->isDXT1a = true;
}
else if (settings.format == FMT_DXT3)
{
@ -578,19 +575,6 @@ void CTextureConverter::RunThread(CTextureConverter* textureConverter)
result->ret = compressor.process(request->inputOptions, request->compressionOptions, request->outputOptions);
}
// Ugly hack: NVTT 2.0 doesn't set DDPF_ALPHAPIXELS for DXT1a, so we can't
// distinguish it from DXT1. (It's fixed in trunk by
// http://code.google.com/p/nvidia-texture-tools/source/detail?r=924&path=/trunk).
// Rather than using a trunk NVTT (unstable, makes packaging harder)
// or patching our copy (makes packaging harder), we'll just manually
// set the flag here.
if (request->isDXT1a && result->ret && result->output.buffer.size() > 80)
result->output.buffer[80] |= 1; // DDPF_ALPHAPIXELS in DDS_PIXELFORMAT.dwFlags
// Ugly hack: NVTT always sets DDPF_RGB, even if we're trying to output 8-bit
// alpha-only DDS with no RGB components. Unset that flag.
if (request->is8bpp)
result->output.buffer[80] &= ~0x40; // DDPF_RGB in DDS_PIXELFORMAT.dwFlags
// Push the result onto the queue
std::lock_guard<std::mutex> wait_lock(textureConverter->m_WorkerMutex);
textureConverter->m_ResultQueue.push_back(result);

View File

@ -310,10 +310,10 @@ static Status s3tc_decompress(Tex* t)
// DDS_PIXELFORMAT.dwFlags
// we've seen some DXT3 files that don't have this set (which is nonsense;
// any image lacking alpha should be stored as DXT1). it's authoritative
// if fourcc is DXT1 (there's no other way to tell DXT1 and DXT1a apart)
// and ignored otherwise.
// any image lacking alpha should be stored as DXT1).
#define DDPF_ALPHAPIXELS 0x00000001
// DDPF_ALPHA is used instead of DDPF_ALPHAPIXELS for DXT1a.
#define DDPF_ALPHA 0x00000002
#define DDPF_FOURCC 0x00000004
#define DDPF_RGB 0x00000040
@ -326,7 +326,7 @@ struct DDS_PIXELFORMAT
u32 dwRBitMask;
u32 dwGBitMask;
u32 dwBBitMask;
u32 dwABitMask; // (DDPF_ALPHAPIXELS)
u32 dwABitMask; // (DDPF_ALPHA or DDPF_ALPHAPIXELS)
};
@ -435,7 +435,7 @@ static Status decode_pf(const DDS_PIXELFORMAT* pf, size_t& bpp, size_t& flags)
RETURN_STATUS_IF_ERR(tex_validate_plain_format(bpp, (int)flags));
}
// .. uncompressed 8bpp greyscale
else if(pf_flags & DDPF_ALPHAPIXELS)
else if(pf_flags & DDPF_ALPHA)
{
const size_t pf_bpp = (size_t)read_le32(&pf->dwRGBBitCount);
const size_t pf_a_mask = (size_t)read_le32(&pf->dwABitMask);
@ -460,7 +460,7 @@ static Status decode_pf(const DDS_PIXELFORMAT* pf, size_t& bpp, size_t& flags)
{
case FOURCC('D','X','T','1'):
bpp = 4;
if(pf_flags & DDPF_ALPHAPIXELS)
if(pf_flags & DDPF_ALPHA)
flags |= DXT1A | TEX_ALPHA;
else
flags |= 1;