Merge changes from the witness.
This commit is contained in:
@ -37,7 +37,7 @@ using namespace nv;
|
||||
using namespace nvtt;
|
||||
|
||||
|
||||
void CompressorBC6::compressBlock(Tile & tile, AlphaMode alphaMode, const CompressionOptions::Private & compressionOptions, void * output)
|
||||
void CompressorBC6::compressBlock(ColorSet & tile, AlphaMode alphaMode, const CompressionOptions::Private & compressionOptions, void * output)
|
||||
{
|
||||
NV_UNUSED(alphaMode); // ZOH does not support alpha.
|
||||
|
||||
@ -56,7 +56,7 @@ void CompressorBC6::compressBlock(Tile & tile, AlphaMode alphaMode, const Compre
|
||||
}
|
||||
|
||||
|
||||
void CompressorBC7::compressBlock(Tile & tile, AlphaMode alphaMode, const CompressionOptions::Private & compressionOptions, void * output)
|
||||
void CompressorBC7::compressBlock(ColorSet & tile, AlphaMode alphaMode, const CompressionOptions::Private & compressionOptions, void * output)
|
||||
{
|
||||
// @@ TODO
|
||||
}
|
||||
|
@ -481,10 +481,10 @@ void D3DXCompressorDXT1::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode
|
||||
|
||||
err = surface->LockRect(&rect, NULL, D3DLOCK_READONLY);
|
||||
|
||||
if (outputOptions.outputHandler != NULL) {
|
||||
int size = rect.Pitch * ((h + 3) / 4);
|
||||
outputOptions.outputHandler->writeData(rect.pBits, size);
|
||||
}
|
||||
if (outputOptions.outputHandler != NULL) {
|
||||
int size = rect.Pitch * ((h + 3) / 4);
|
||||
outputOptions.outputHandler->writeData(rect.pBits, size);
|
||||
}
|
||||
|
||||
err = surface->UnlockRect();
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ namespace
|
||||
{
|
||||
nvDebugCheck(alignment >= 1);
|
||||
flush();
|
||||
int remainder = (size_t)ptr % alignment;
|
||||
int remainder = (int)((uintptr_t)ptr % alignment);
|
||||
if (remainder != 0) {
|
||||
putBits(0, (alignment - remainder) * 8);
|
||||
}
|
||||
|
@ -349,6 +349,8 @@ bool Compressor::Private::compress(AlphaMode alphaMode, int w, int h, int d, int
|
||||
compressor->compress(alphaMode, w, h, d, rgba, dispatcher, compressionOptions, outputOptions);
|
||||
}
|
||||
|
||||
outputOptions.endImage();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -135,6 +135,11 @@ bool OutputOptions::Private::writeData(const void * data, int size) const
|
||||
return outputHandler == NULL || outputHandler->writeData(data, size);
|
||||
}
|
||||
|
||||
void OutputOptions::Private::endImage() const
|
||||
{
|
||||
if (outputHandler != NULL) outputHandler->endImage();
|
||||
}
|
||||
|
||||
void OutputOptions::Private::error(Error e) const
|
||||
{
|
||||
if (errorHandler != NULL) errorHandler->error(e);
|
||||
|
@ -52,6 +52,11 @@ namespace nvtt
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void endImage()
|
||||
{
|
||||
// ignore.
|
||||
}
|
||||
|
||||
nv::StdOutputStream stream;
|
||||
};
|
||||
|
||||
@ -72,6 +77,7 @@ namespace nvtt
|
||||
|
||||
void beginImage(int size, int width, int height, int depth, int face, int miplevel) const;
|
||||
bool writeData(const void * data, int size) const;
|
||||
void endImage() const;
|
||||
void error(Error e) const;
|
||||
};
|
||||
|
||||
|
@ -18,8 +18,8 @@
|
||||
// http://msdn.microsoft.com/en-us/library/dd504870.aspx
|
||||
#if NV_OS_WIN32 && _MSC_VER >= 1600
|
||||
#define HAVE_PPL 1
|
||||
//#include <array>
|
||||
#include <ppl.h>
|
||||
#include <array>
|
||||
//#include <ppl.h>
|
||||
#endif
|
||||
|
||||
// Intel Thread Building Blocks (TBB).
|
||||
@ -28,6 +28,8 @@
|
||||
#include <tbb/parallel_for.h>
|
||||
#endif
|
||||
|
||||
#include "nvthread/ParallelFor.h"
|
||||
|
||||
|
||||
namespace nvtt {
|
||||
|
||||
@ -40,6 +42,15 @@ namespace nvtt {
|
||||
}
|
||||
};
|
||||
|
||||
struct ParallelTaskDispatcher : public TaskDispatcher
|
||||
{
|
||||
virtual void dispatch(Task * task, void * context, int count) {
|
||||
nv::ParallelFor parallelFor(task, context);
|
||||
parallelFor.run(count); // @@ Add support for custom grain.
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#if defined(HAVE_OPENMP)
|
||||
|
||||
struct OpenMPTaskDispatcher : public TaskDispatcher
|
||||
@ -81,9 +92,24 @@ namespace nvtt {
|
||||
|
||||
#if defined(HAVE_PPL)
|
||||
|
||||
class CountingIterator
|
||||
{
|
||||
public:
|
||||
CountingIterator() : i(0) {}
|
||||
CountingIterator(const CountingIterator & rhs) : i(0) {}
|
||||
explicit CountingIterator(int x) : i(x) {}
|
||||
|
||||
const int & operator*() const { return i; }
|
||||
CountingIterator & operator++() { i++; return *this; }
|
||||
CountingIterator & operator--() { i--; return *this; }
|
||||
|
||||
private:
|
||||
int i;
|
||||
};
|
||||
|
||||
struct TaskFunctor {
|
||||
TaskFunctor(Task * task, void * context) : task(task), context(context) {}
|
||||
void operator()(int n) const {
|
||||
void operator()(int & n) const {
|
||||
task(context, n);
|
||||
}
|
||||
Task * task;
|
||||
@ -95,12 +121,16 @@ namespace nvtt {
|
||||
{
|
||||
virtual void dispatch(Task * task, void * context, int count)
|
||||
{
|
||||
CountingIterator begin(0);
|
||||
CountingIterator end((int)count);
|
||||
TaskFunctor func(task, context);
|
||||
Concurrency::parallel_for(0, count, func);
|
||||
|
||||
std::for_each(begin, end, func);
|
||||
//parallel_for_each(begin, end, func);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // HAVE_PPL
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_TBB)
|
||||
|
||||
@ -132,7 +162,8 @@ namespace nvtt {
|
||||
#elif defined(HAVE_GCD)
|
||||
typedef AppleTaskDispatcher ConcurrentTaskDispatcher;
|
||||
#else
|
||||
typedef SequentialTaskDispatcher ConcurrentTaskDispatcher;
|
||||
//typedef SequentialTaskDispatcher ConcurrentTaskDispatcher;
|
||||
typedef ParallelTaskDispatcher ConcurrentTaskDispatcher;
|
||||
#endif
|
||||
|
||||
} // namespace nvtt
|
||||
|
@ -615,7 +615,7 @@ bool TexImage::setImage2D(Format format, Decoder decoder, int w, int h, const vo
|
||||
block->decodeBlock(&colors, false);
|
||||
}
|
||||
else if (decoder == Decoder_NV5x) {
|
||||
block->decodeBlockNV5x(&colors);
|
||||
block->decodeBlockNV5x(&colors);
|
||||
}
|
||||
}
|
||||
else if (format == nvtt::Format_BC3)
|
||||
@ -629,19 +629,19 @@ bool TexImage::setImage2D(Format format, Decoder decoder, int w, int h, const vo
|
||||
block->decodeBlock(&colors, false);
|
||||
}
|
||||
else if (decoder == Decoder_NV5x) {
|
||||
block->decodeBlockNV5x(&colors);
|
||||
block->decodeBlockNV5x(&colors);
|
||||
}
|
||||
}
|
||||
else if (format == nvtt::Format_BC4)
|
||||
{
|
||||
const BlockATI1 * block = (const BlockATI1 *)ptr;
|
||||
block->decodeBlock(&colors, decoder == Decoder_D3D9);
|
||||
}
|
||||
else if (format == nvtt::Format_BC5)
|
||||
{
|
||||
const BlockATI2 * block = (const BlockATI2 *)ptr;
|
||||
block->decodeBlock(&colors, decoder == Decoder_D3D9);
|
||||
}
|
||||
const BlockATI1 * block = (const BlockATI1 *)ptr;
|
||||
block->decodeBlock(&colors, decoder == Decoder_D3D9);
|
||||
}
|
||||
else if (format == nvtt::Format_BC5)
|
||||
{
|
||||
const BlockATI2 * block = (const BlockATI2 *)ptr;
|
||||
block->decodeBlock(&colors, decoder == Decoder_D3D9);
|
||||
}
|
||||
|
||||
for (int yy = 0; yy < 4; yy++)
|
||||
{
|
||||
@ -864,6 +864,42 @@ bool TexImage::buildNextMipmap(MipmapFilter filter, float filterWidth, const flo
|
||||
return true;
|
||||
}
|
||||
|
||||
void TexImage::canvasSize(int w, int h, int d)
|
||||
{
|
||||
nvDebugCheck(w > 0 && h > 0 && d > 0);
|
||||
|
||||
FloatImage * img = m->image;
|
||||
if (img == NULL || (w == img->width() && h == img->height() && d == img->depth())) {
|
||||
return;
|
||||
}
|
||||
|
||||
detach();
|
||||
|
||||
FloatImage * new_img = new FloatImage;
|
||||
new_img->allocate(4, w, h, d);
|
||||
new_img->clear();
|
||||
|
||||
w = min(uint(w), img->width());
|
||||
h = min(uint(h), img->height());
|
||||
d = min(uint(d), img->depth());
|
||||
|
||||
for (int z = 0; z < d; z++) {
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
new_img->pixel(0, x, y, z) = img->pixel(0, x, y, z);
|
||||
new_img->pixel(1, x, y, z) = img->pixel(1, x, y, z);
|
||||
new_img->pixel(2, x, y, z) = img->pixel(2, x, y, z);
|
||||
new_img->pixel(3, x, y, z) = img->pixel(3, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete m->image;
|
||||
m->image = new_img;
|
||||
m->type = (d == 1) ? TextureType_2D : TextureType_3D;
|
||||
}
|
||||
|
||||
|
||||
// Color transforms.
|
||||
void TexImage::toLinear(float gamma)
|
||||
{
|
||||
@ -885,6 +921,66 @@ void TexImage::toGamma(float gamma)
|
||||
m->image->toGamma(0, 3, gamma);
|
||||
}
|
||||
|
||||
|
||||
static float toSrgb(float f) {
|
||||
if (f <= 0.0) f = 0.0f;
|
||||
else if (f <= 0.0031308f) f = 12.92f * f;
|
||||
else if (f <= 1.0f) f = (powf(f, 0.41666f) * 1.055f) - 0.055f;
|
||||
else f = 1.0f;
|
||||
return f;
|
||||
}
|
||||
|
||||
void TexImage::toSrgb()
|
||||
{
|
||||
FloatImage * img = m->image;
|
||||
if (img == NULL) return;
|
||||
|
||||
detach();
|
||||
|
||||
const uint count = img->pixelCount();
|
||||
for (uint j = 0; j < count; j++)
|
||||
{
|
||||
float & r = img->pixel(0, j);
|
||||
float & g = img->pixel(1, j);
|
||||
float & b = img->pixel(2, j);
|
||||
|
||||
r = ::toSrgb(r);
|
||||
g = ::toSrgb(g);
|
||||
b = ::toSrgb(b);
|
||||
}
|
||||
}
|
||||
|
||||
static float toXenonSrgb(float f) {
|
||||
if (f < 0) f = 0;
|
||||
else if (f < (1.0f/16.0f)) f = 4.0f * f;
|
||||
else if (f < (1.0f/8.0f)) f = 0.25f + 2.0f * (f - 0.0625f);
|
||||
else if (f < 0.5f) f = 0.375f + 1.0f * (f - 0.125f);
|
||||
else if (f < 1.0f) f = 0.75f + 0.5f * (f - 0.50f);
|
||||
else f = 1.0f;
|
||||
return f;
|
||||
}
|
||||
|
||||
void TexImage::toXenonSrgb()
|
||||
{
|
||||
FloatImage * img = m->image;
|
||||
if (img == NULL) return;
|
||||
|
||||
detach();
|
||||
|
||||
const uint count = img->pixelCount();
|
||||
for (uint j = 0; j < count; j++)
|
||||
{
|
||||
float & r = img->pixel(0, j);
|
||||
float & g = img->pixel(1, j);
|
||||
float & b = img->pixel(2, j);
|
||||
|
||||
r = ::toXenonSrgb(r);
|
||||
g = ::toXenonSrgb(g);
|
||||
b = ::toXenonSrgb(b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TexImage::transform(const float w0[4], const float w1[4], const float w2[4], const float w3[4], const float offset[4])
|
||||
{
|
||||
if (m->image == NULL) return;
|
||||
@ -1140,9 +1236,9 @@ void TexImage::toRGBM(float range/*= 1*/, float threshold/*= 0.25*/)
|
||||
|
||||
const uint count = img->pixelCount();
|
||||
for (uint i = 0; i < count; i++) {
|
||||
float R = nv::clamp(r[i] * irange, 0.0f, 1.0f);
|
||||
float G = nv::clamp(g[i] * irange, 0.0f, 1.0f);
|
||||
float B = nv::clamp(b[i] * irange, 0.0f, 1.0f);
|
||||
float R = nv::clamp(r[i], 0.0f, 1.0f);
|
||||
float G = nv::clamp(g[i], 0.0f, 1.0f);
|
||||
float B = nv::clamp(b[i], 0.0f, 1.0f);
|
||||
#if 1
|
||||
float M = max(max(R, G), max(B, threshold));
|
||||
|
||||
|
@ -294,6 +294,9 @@ namespace nvtt
|
||||
|
||||
/// Output data. Compressed data is output as soon as it's generated to minimize memory allocations.
|
||||
virtual bool writeData(const void * data, int size) = 0;
|
||||
|
||||
/// Indicate the end of a the compressed image.
|
||||
virtual void endImage() = 0;
|
||||
};
|
||||
|
||||
/// Error codes.
|
||||
@ -440,10 +443,13 @@ namespace nvtt
|
||||
NVTT_API void resize(int maxExtent, RoundMode mode, ResizeFilter filter, float filterWidth, const float * params = 0);
|
||||
NVTT_API bool buildNextMipmap(MipmapFilter filter);
|
||||
NVTT_API bool buildNextMipmap(MipmapFilter filter, float filterWidth, const float * params = 0);
|
||||
NVTT_API void canvasSize(int w, int h, int d);
|
||||
|
||||
// Color transforms.
|
||||
NVTT_API void toLinear(float gamma);
|
||||
NVTT_API void toGamma(float gamma);
|
||||
NVTT_API void toSrgb();
|
||||
NVTT_API void toXenonSrgb();
|
||||
NVTT_API void transform(const float w0[4], const float w1[4], const float w2[4], const float w3[4], const float offset[4]);
|
||||
NVTT_API void swizzle(int r, int g, int b, int a);
|
||||
NVTT_API void scaleBias(int channel, float scale, float bias);
|
||||
|
@ -56,6 +56,11 @@ struct MyOutputHandler : public nvtt::OutputHandler
|
||||
// ignore.
|
||||
}
|
||||
|
||||
virtual void endImage()
|
||||
{
|
||||
// Ignore.
|
||||
}
|
||||
|
||||
// Output data.
|
||||
virtual bool writeData(const void * data, int size)
|
||||
{
|
||||
|
Reference in New Issue
Block a user