Merge changes from The Witness.

This commit is contained in:
Ignacio
2015-10-28 23:53:08 -07:00
parent a382ea5b21
commit c0ad0f4d31
43 changed files with 890 additions and 136 deletions

View File

@ -17,7 +17,7 @@
using namespace nv;
static uint atomic_counter = 0;
//static uint atomic_counter = 0;
float nv::compress_dxt5_rgbm(const Vector4 input_colors[16], const float input_weights[16], float min_m, BlockDXT5 * output) {
@ -87,10 +87,15 @@ float nv::compress_dxt5_rgbm(const Vector4 input_colors[16], const float input_w
m = (m - min_m) / (1 - min_m);
#if 0
// IC: This does indeed happen. What does that mean? The best choice of m is above the available range. If this happened too often it would make sense to scale m in
// the pixel shader to allow for more accurate reconstruction. However, that scaling would reduce the precision over the [0-1] range. I haven't measured how much
// error is introduced by the clamping vs. how much the error would change with the increased range.
if (m > 1.0f) {
uint counter = atomicIncrement(&atomic_counter);
printf("It happens %u times!", counter);
}
#endif
M.alpha[i] = U8(ftoi_round(saturate(m) * 255.0f));
M.weights[i] = input_weights[i];

View File

@ -193,7 +193,7 @@ namespace
F.field.biasedexponent = 0xFF;
F.field.mantissa = M << (23 - 6);
return F.value;
#if 0
// X Channel (6-bit mantissa)
Mantissa = pSource->xm;
@ -228,9 +228,7 @@ namespace
Result[0] = ((Exponent + 112) << 23) | (Mantissa << 17);
}
}
#endif
}
// https://www.opengl.org/registry/specs/EXT/texture_shared_exponent.txt

View File

@ -52,12 +52,12 @@ using namespace nvtt;
namespace
{
// 1 -> 1, 2 -> 2, 3 -> 2, 4 -> 4, 5 -> 4, ...
static uint previousPowerOfTwo(const uint v)
static inline uint previousPowerOfTwo(uint v)
{
return nextPowerOfTwo(v + 1) / 2;
}
static uint nearestPowerOfTwo(const uint v)
static inline uint nearestPowerOfTwo(uint v)
{
const uint np2 = nextPowerOfTwo(v);
const uint pp2 = previousPowerOfTwo(v);
@ -72,6 +72,31 @@ namespace
}
}
static inline uint nextMultipleOfFour(uint v)
{
return (v + 3) & ~3;
}
static inline uint previousMultipleOfFour(uint v)
{
return v & ~3;
}
static inline uint nearestMultipleOfFour(uint v)
{
const uint nm4 = nextMultipleOfFour(v);
const uint pm4 = previousMultipleOfFour(v);
if (nm4 - v <= v - pm4)
{
return nm4;
}
else
{
return pm4;
}
}
static int blockSize(Format format)
{
if (format == Format_DXT1 || format == Format_DXT1a || format == Format_DXT1n) {
@ -225,6 +250,24 @@ void nv::getTargetExtent(int * width, int * height, int * depth, int maxExtent,
h = previousPowerOfTwo(h);
d = previousPowerOfTwo(d);
}
else if (roundMode == RoundMode_ToNextMultipleOfFour)
{
w = nextMultipleOfFour(w);
h = nextMultipleOfFour(h);
d = nextMultipleOfFour(d);
}
else if (roundMode == RoundMode_ToNextMultipleOfFour)
{
w = nearestMultipleOfFour(w);
h = nearestMultipleOfFour(h);
d = nearestMultipleOfFour(d);
}
else if (roundMode == RoundMode_ToPreviousMultipleOfFour)
{
w = previousMultipleOfFour(w);
h = previousMultipleOfFour(h);
d = previousMultipleOfFour(d);
}
*width = w;
*height = h;

View File

@ -240,6 +240,9 @@ namespace nvtt
RoundMode_ToNextPowerOfTwo,
RoundMode_ToNearestPowerOfTwo,
RoundMode_ToPreviousPowerOfTwo,
RoundMode_ToNextMultipleOfFour, // (New in NVTT 2.1)
RoundMode_ToNearestMultipleOfFour, // (New in NVTT 2.1)
RoundMode_ToPreviousMultipleOfFour, // (New in NVTT 2.1)
};
// Alpha mode.

View File

@ -641,8 +641,8 @@ int main(int argc, char *argv[])
//compressionOptions.setPixelFormat(10, 10, 10, 2);
// DXGI_FORMAT_R11G11B10_FLOAT
compressionOptions.setPixelType(nvtt::PixelType_Float);
compressionOptions.setPixelFormat(11, 11, 10, 0);
//compressionOptions.setPixelType(nvtt::PixelType_Float);
//compressionOptions.setPixelFormat(11, 11, 10, 0);
}
}
else if (format == nvtt::Format_BC6)