|
|
|
@ -60,6 +60,7 @@ __device__ void sortColors(const float * values, int * cmp)
|
|
|
|
|
{
|
|
|
|
|
int tid = threadIdx.x;
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
cmp[tid] = (values[0] < values[tid]);
|
|
|
|
|
cmp[tid] += (values[1] < values[tid]);
|
|
|
|
|
cmp[tid] += (values[2] < values[tid]);
|
|
|
|
@ -93,6 +94,23 @@ __device__ void sortColors(const float * values, int * cmp)
|
|
|
|
|
if (tid > 12 && cmp[tid] == cmp[12]) ++cmp[tid];
|
|
|
|
|
if (tid > 13 && cmp[tid] == cmp[13]) ++cmp[tid];
|
|
|
|
|
if (tid > 14 && cmp[tid] == cmp[14]) ++cmp[tid];
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
cmp[tid] = 0;
|
|
|
|
|
|
|
|
|
|
#pragma unroll
|
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
cmp[tid] += (values[i] < values[tid]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resolve elements with the same index.
|
|
|
|
|
#pragma unroll
|
|
|
|
|
for (int i = 0; i < 15; i++)
|
|
|
|
|
{
|
|
|
|
|
if (tid > 0 && cmp[tid] == cmp[i]) ++cmp[tid];
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -183,11 +201,48 @@ __device__ void loadColorBlock(const uint * image, float3 colors[16], float3 sum
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__device__ void loadColorBlock(const uint * image, float2 colors[16], float2 sums[16], int xrefs[16])
|
|
|
|
|
{
|
|
|
|
|
const int bid = blockIdx.x;
|
|
|
|
|
const int idx = threadIdx.x;
|
|
|
|
|
|
|
|
|
|
__shared__ float dps[16];
|
|
|
|
|
|
|
|
|
|
if (idx < 16)
|
|
|
|
|
{
|
|
|
|
|
// Read color and copy to shared mem.
|
|
|
|
|
uint c = image[(bid) * 16 + idx];
|
|
|
|
|
|
|
|
|
|
colors[idx].y = ((c >> 8) & 0xFF) * (1.0f / 255.0f);
|
|
|
|
|
colors[idx].x = ((c >> 16) & 0xFF) * (1.0f / 255.0f);
|
|
|
|
|
|
|
|
|
|
// No need to synchronize, 16 < warp size.
|
|
|
|
|
#if __DEVICE_EMULATION__
|
|
|
|
|
} __debugsync(); if (idx < 16) {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Sort colors along the best fit line.
|
|
|
|
|
colorSums(colors, sums);
|
|
|
|
|
float2 axis = bestFitLine(colors, sums[0]);
|
|
|
|
|
|
|
|
|
|
dps[idx] = dot(colors[idx], axis);
|
|
|
|
|
|
|
|
|
|
#if __DEVICE_EMULATION__
|
|
|
|
|
} __debugsync(); if (idx < 16) {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
sortColors(dps, xrefs);
|
|
|
|
|
|
|
|
|
|
float2 tmp = colors[idx];
|
|
|
|
|
colors[xrefs[idx]] = tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Round color to RGB565 and expand
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
inline __device__ float3 roundAndExpand(float3 v, ushort * w)
|
|
|
|
|
inline __device__ float3 roundAndExpand565(float3 v, ushort * w)
|
|
|
|
|
{
|
|
|
|
|
v.x = rintf(__saturatef(v.x) * 31.0f);
|
|
|
|
|
v.y = rintf(__saturatef(v.y) * 63.0f);
|
|
|
|
@ -199,6 +254,26 @@ inline __device__ float3 roundAndExpand(float3 v, ushort * w)
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline __device__ float2 roundAndExpand56(float2 v, ushort * w)
|
|
|
|
|
{
|
|
|
|
|
v.x = rintf(__saturatef(v.x) * 31.0f);
|
|
|
|
|
v.y = rintf(__saturatef(v.y) * 63.0f);
|
|
|
|
|
*w = ((ushort)v.x << 11) | ((ushort)v.y << 5);
|
|
|
|
|
v.x *= 0.03227752766457f; // approximate integer bit expansion.
|
|
|
|
|
v.y *= 0.01583151765563f;
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline __device__ float2 roundAndExpand88(float2 v, ushort * w)
|
|
|
|
|
{
|
|
|
|
|
v.x = rintf(__saturatef(v.x) * 255.0f);
|
|
|
|
|
v.y = rintf(__saturatef(v.y) * 255.0f);
|
|
|
|
|
*w = ((ushort)v.x << 8) | ((ushort)v.y);
|
|
|
|
|
v.x *= 1.0f / 255.0f;
|
|
|
|
|
v.y *= 1.0f / 255.0f;
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Evaluate permutations
|
|
|
|
@ -234,8 +309,8 @@ __device__ float evalPermutation4(const float3 * colors, uint permutation, ushor
|
|
|
|
|
float3 b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor;
|
|
|
|
|
|
|
|
|
|
// Round a, b to the closest 5-6-5 color and expand...
|
|
|
|
|
a = roundAndExpand(a, start);
|
|
|
|
|
b = roundAndExpand(b, end);
|
|
|
|
|
a = roundAndExpand565(a, start);
|
|
|
|
|
b = roundAndExpand565(b, end);
|
|
|
|
|
|
|
|
|
|
// compute the error
|
|
|
|
|
float3 e = a * a * alpha2_sum + b * b * beta2_sum + 2.0f * (a * b * alphabeta_sum - a * alphax_sum - b * betax_sum);
|
|
|
|
@ -274,8 +349,8 @@ __device__ float evalPermutation3(const float3 * colors, uint permutation, ushor
|
|
|
|
|
float3 b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor;
|
|
|
|
|
|
|
|
|
|
// Round a, b to the closest 5-6-5 color and expand...
|
|
|
|
|
a = roundAndExpand(a, start);
|
|
|
|
|
b = roundAndExpand(b, end);
|
|
|
|
|
a = roundAndExpand565(a, start);
|
|
|
|
|
b = roundAndExpand565(b, end);
|
|
|
|
|
|
|
|
|
|
// compute the error
|
|
|
|
|
float3 e = a * a * alpha2_sum + b * b * beta2_sum + 2.0f * (a * b * alphabeta_sum - a * alphax_sum - b * betax_sum);
|
|
|
|
@ -315,8 +390,8 @@ __device__ float evalPermutation4(const float3 * colors, float3 color_sum, uint
|
|
|
|
|
float3 b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor;
|
|
|
|
|
|
|
|
|
|
// Round a, b to the closest 5-6-5 color and expand...
|
|
|
|
|
a = roundAndExpand(a, start);
|
|
|
|
|
b = roundAndExpand(b, end);
|
|
|
|
|
a = roundAndExpand565(a, start);
|
|
|
|
|
b = roundAndExpand565(b, end);
|
|
|
|
|
|
|
|
|
|
// compute the error
|
|
|
|
|
float3 e = a * a * alpha2_sum + b * b * beta2_sum + 2.0f * (a * b * alphabeta_sum - a * alphax_sum - b * betax_sum);
|
|
|
|
@ -351,8 +426,8 @@ __device__ float evalPermutation3(const float3 * colors, float3 color_sum, uint
|
|
|
|
|
float3 b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor;
|
|
|
|
|
|
|
|
|
|
// Round a, b to the closest 5-6-5 color and expand...
|
|
|
|
|
a = roundAndExpand(a, start);
|
|
|
|
|
b = roundAndExpand(b, end);
|
|
|
|
|
a = roundAndExpand565(a, start);
|
|
|
|
|
b = roundAndExpand565(b, end);
|
|
|
|
|
|
|
|
|
|
// compute the error
|
|
|
|
|
float3 e = a * a * alpha2_sum + b * b * beta2_sum + 2.0f * (a * b * alphabeta_sum - a * alphax_sum - b * betax_sum);
|
|
|
|
@ -391,8 +466,8 @@ __device__ float evalPermutation4(const float3 * colors, const float * weights,
|
|
|
|
|
float3 b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor;
|
|
|
|
|
|
|
|
|
|
// Round a, b to the closest 5-6-5 color and expand...
|
|
|
|
|
a = roundAndExpand(a, start);
|
|
|
|
|
b = roundAndExpand(b, end);
|
|
|
|
|
a = roundAndExpand565(a, start);
|
|
|
|
|
b = roundAndExpand565(b, end);
|
|
|
|
|
|
|
|
|
|
// compute the error
|
|
|
|
|
float3 e = a * a * alpha2_sum + b * b * beta2_sum + 2.0f * (a * b * alphabeta_sum - a * alphax_sum - b * betax_sum);
|
|
|
|
@ -432,8 +507,8 @@ __device__ float evalPermutation3(const float3 * colors, const float * weights,
|
|
|
|
|
float3 b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor;
|
|
|
|
|
|
|
|
|
|
// Round a, b to the closest 5-6-5 color and expand...
|
|
|
|
|
a = roundAndExpand(a, start);
|
|
|
|
|
b = roundAndExpand(b, end);
|
|
|
|
|
a = roundAndExpand565(a, start);
|
|
|
|
|
b = roundAndExpand565(b, end);
|
|
|
|
|
|
|
|
|
|
// compute the error
|
|
|
|
|
float3 e = a * a * alpha2_sum + b * b * beta2_sum + 2.0f * (a * b * alphabeta_sum - a * alphax_sum - b * betax_sum);
|
|
|
|
@ -442,6 +517,114 @@ __device__ float evalPermutation3(const float3 * colors, const float * weights,
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
__device__ float evalPermutation4(const float2 * colors, float2 color_sum, uint permutation, ushort * start, ushort * end)
|
|
|
|
|
{
|
|
|
|
|
// Compute endpoints using least squares.
|
|
|
|
|
float2 alphax_sum = make_float2(0.0f, 0.0f);
|
|
|
|
|
uint akku = 0;
|
|
|
|
|
|
|
|
|
|
// Compute alpha & beta for this permutation.
|
|
|
|
|
#pragma unroll
|
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
const uint bits = permutation >> (2*i);
|
|
|
|
|
|
|
|
|
|
alphax_sum += alphaTable4[bits & 3] * colors[i];
|
|
|
|
|
akku += prods4[bits & 3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float alpha2_sum = float(akku >> 16);
|
|
|
|
|
float beta2_sum = float((akku >> 8) & 0xff);
|
|
|
|
|
float alphabeta_sum = float(akku & 0xff);
|
|
|
|
|
float2 betax_sum = 9.0f * color_sum - alphax_sum;
|
|
|
|
|
|
|
|
|
|
const float factor = 1.0f / (alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum);
|
|
|
|
|
|
|
|
|
|
float2 a = (alphax_sum * beta2_sum - betax_sum * alphabeta_sum) * factor;
|
|
|
|
|
float2 b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor;
|
|
|
|
|
|
|
|
|
|
// Round a, b to the closest 5-6 color and expand...
|
|
|
|
|
a = roundAndExpand56(a, start);
|
|
|
|
|
b = roundAndExpand56(b, end);
|
|
|
|
|
|
|
|
|
|
// compute the error
|
|
|
|
|
float2 e = a * a * alpha2_sum + b * b * beta2_sum + 2.0f * (a * b * alphabeta_sum - a * alphax_sum - b * betax_sum);
|
|
|
|
|
|
|
|
|
|
return (1.0f / 9.0f) * (e.x + e.y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__device__ float evalPermutation3(const float2 * colors, float2 color_sum, uint permutation, ushort * start, ushort * end)
|
|
|
|
|
{
|
|
|
|
|
// Compute endpoints using least squares.
|
|
|
|
|
float2 alphax_sum = make_float2(0.0f, 0.0f);
|
|
|
|
|
uint akku = 0;
|
|
|
|
|
|
|
|
|
|
// Compute alpha & beta for this permutation.
|
|
|
|
|
#pragma unroll
|
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
const uint bits = permutation >> (2*i);
|
|
|
|
|
|
|
|
|
|
alphax_sum += alphaTable3[bits & 3] * colors[i];
|
|
|
|
|
akku += prods3[bits & 3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float alpha2_sum = float(akku >> 16);
|
|
|
|
|
float beta2_sum = float((akku >> 8) & 0xff);
|
|
|
|
|
float alphabeta_sum = float(akku & 0xff);
|
|
|
|
|
float2 betax_sum = 4.0f * color_sum - alphax_sum;
|
|
|
|
|
|
|
|
|
|
const float factor = 1.0f / (alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum);
|
|
|
|
|
|
|
|
|
|
float2 a = (alphax_sum * beta2_sum - betax_sum * alphabeta_sum) * factor;
|
|
|
|
|
float2 b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor;
|
|
|
|
|
|
|
|
|
|
// Round a, b to the closest 5-6 color and expand...
|
|
|
|
|
a = roundAndExpand56(a, start);
|
|
|
|
|
b = roundAndExpand56(b, end);
|
|
|
|
|
|
|
|
|
|
// compute the error
|
|
|
|
|
float2 e = a * a * alpha2_sum + b * b * beta2_sum + 2.0f * (a * b * alphabeta_sum - a * alphax_sum - b * betax_sum);
|
|
|
|
|
|
|
|
|
|
return (1.0f / 4.0f) * (e.x + e.y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__device__ float evalPermutationCTX(const float2 * colors, float2 color_sum, uint permutation, ushort * start, ushort * end)
|
|
|
|
|
{
|
|
|
|
|
// Compute endpoints using least squares.
|
|
|
|
|
float2 alphax_sum = make_float2(0.0f, 0.0f);
|
|
|
|
|
uint akku = 0;
|
|
|
|
|
|
|
|
|
|
// Compute alpha & beta for this permutation.
|
|
|
|
|
#pragma unroll
|
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
const uint bits = permutation >> (2*i);
|
|
|
|
|
|
|
|
|
|
alphax_sum += alphaTable4[bits & 3] * colors[i];
|
|
|
|
|
akku += prods4[bits & 3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float alpha2_sum = float(akku >> 16);
|
|
|
|
|
float beta2_sum = float((akku >> 8) & 0xff);
|
|
|
|
|
float alphabeta_sum = float(akku & 0xff);
|
|
|
|
|
float2 betax_sum = 9.0f * color_sum - alphax_sum;
|
|
|
|
|
|
|
|
|
|
const float factor = 1.0f / (alpha2_sum * beta2_sum - alphabeta_sum * alphabeta_sum);
|
|
|
|
|
|
|
|
|
|
float2 a = (alphax_sum * beta2_sum - betax_sum * alphabeta_sum) * factor;
|
|
|
|
|
float2 b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor;
|
|
|
|
|
|
|
|
|
|
// Round a, b to the closest 8-8 color and expand...
|
|
|
|
|
a = roundAndExpand88(a, start);
|
|
|
|
|
b = roundAndExpand88(b, end);
|
|
|
|
|
|
|
|
|
|
// compute the error
|
|
|
|
|
float2 e = a * a * alpha2_sum + b * b * beta2_sum + 2.0f * (a * b * alphabeta_sum - a * alphax_sum - b * betax_sum);
|
|
|
|
|
|
|
|
|
|
return (1.0f / 9.0f) * (e.x + e.y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Evaluate all permutations
|
|
|
|
@ -570,6 +753,67 @@ __device__ void evalAllPermutations(const float3 * colors, const float * weights
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
__device__ void evalAllPermutations(const float2 * colors, float2 colorSum, const uint * permutations, ushort & bestStart, ushort & bestEnd, uint & bestPermutation, float * errors)
|
|
|
|
|
{
|
|
|
|
|
const int idx = threadIdx.x;
|
|
|
|
|
|
|
|
|
|
float bestError = FLT_MAX;
|
|
|
|
|
|
|
|
|
|
__shared__ uint s_permutations[160];
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
int pidx = idx + NUM_THREADS * i;
|
|
|
|
|
if (pidx >= 992) break;
|
|
|
|
|
|
|
|
|
|
ushort start, end;
|
|
|
|
|
uint permutation = permutations[pidx];
|
|
|
|
|
if (pidx < 160) s_permutations[pidx] = permutation;
|
|
|
|
|
|
|
|
|
|
float error = evalPermutation4(colors, colorSum, permutation, &start, &end);
|
|
|
|
|
|
|
|
|
|
if (error < bestError)
|
|
|
|
|
{
|
|
|
|
|
bestError = error;
|
|
|
|
|
bestPermutation = permutation;
|
|
|
|
|
bestStart = start;
|
|
|
|
|
bestEnd = end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bestStart < bestEnd)
|
|
|
|
|
{
|
|
|
|
|
swap(bestEnd, bestStart);
|
|
|
|
|
bestPermutation ^= 0x55555555; // Flip indices.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 3; i++)
|
|
|
|
|
{
|
|
|
|
|
int pidx = idx + NUM_THREADS * i;
|
|
|
|
|
if (pidx >= 160) break;
|
|
|
|
|
|
|
|
|
|
ushort start, end;
|
|
|
|
|
uint permutation = s_permutations[pidx];
|
|
|
|
|
float error = evalPermutation3(colors, colorSum, permutation, &start, &end);
|
|
|
|
|
|
|
|
|
|
if (error < bestError)
|
|
|
|
|
{
|
|
|
|
|
bestError = error;
|
|
|
|
|
bestPermutation = permutation;
|
|
|
|
|
bestStart = start;
|
|
|
|
|
bestEnd = end;
|
|
|
|
|
|
|
|
|
|
if (bestStart > bestEnd)
|
|
|
|
|
{
|
|
|
|
|
swap(bestEnd, bestStart);
|
|
|
|
|
bestPermutation ^= (~bestPermutation >> 1) & 0x55555555; // Flip indices.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errors[idx] = bestError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__device__ void evalLevel4Permutations(const float3 * colors, const float * weights, float3 colorSum, const uint * permutations, ushort & bestStart, ushort & bestEnd, uint & bestPermutation, float * errors)
|
|
|
|
|
{
|
|
|
|
|
const int idx = threadIdx.x;
|
|
|
|
@ -604,6 +848,39 @@ __device__ void evalLevel4Permutations(const float3 * colors, const float * weig
|
|
|
|
|
errors[idx] = bestError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__device__ void evalAllPermutationsCTX(const float2 * colors, float2 colorSum, const uint * permutations, ushort & bestStart, ushort & bestEnd, uint & bestPermutation, float * errors)
|
|
|
|
|
{
|
|
|
|
|
const int idx = threadIdx.x;
|
|
|
|
|
|
|
|
|
|
float bestError = FLT_MAX;
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 16; i++)
|
|
|
|
|
{
|
|
|
|
|
int pidx = idx + NUM_THREADS * i;
|
|
|
|
|
if (pidx >= 992) break;
|
|
|
|
|
|
|
|
|
|
ushort start, end;
|
|
|
|
|
uint permutation = permutations[pidx];
|
|
|
|
|
|
|
|
|
|
float error = evalPermutationCTX(colors, colorSum, permutation, &start, &end);
|
|
|
|
|
|
|
|
|
|
if (error < bestError)
|
|
|
|
|
{
|
|
|
|
|
bestError = error;
|
|
|
|
|
bestPermutation = permutation;
|
|
|
|
|
bestStart = start;
|
|
|
|
|
bestEnd = end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bestStart < bestEnd)
|
|
|
|
|
{
|
|
|
|
|
swap(bestEnd, bestStart);
|
|
|
|
|
bestPermutation ^= 0x55555555; // Flip indices.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errors[idx] = bestError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
@ -715,13 +992,17 @@ __device__ void saveBlockDXT1(ushort start, ushort end, uint permutation, int xr
|
|
|
|
|
result[bid].y = indices;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__device__ void saveBlockCTX1(ushort start, ushort end, uint permutation, int xrefs[16], uint2 * result)
|
|
|
|
|
{
|
|
|
|
|
saveBlockDXT1(start, end, permutation, xrefs, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Compress color block
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
__global__ void compress(const uint * permutations, const uint * image, uint2 * result)
|
|
|
|
|
__global__ void compressDXT1(const uint * permutations, const uint * image, uint2 * result)
|
|
|
|
|
{
|
|
|
|
|
__shared__ float3 colors[16];
|
|
|
|
|
__shared__ float3 sums[16];
|
|
|
|
@ -749,7 +1030,7 @@ __global__ void compress(const uint * permutations, const uint * image, uint2 *
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__global__ void compressWeighted(const uint * permutations, const uint * image, uint2 * result)
|
|
|
|
|
__global__ void compressWeightedDXT1(const uint * permutations, const uint * image, uint2 * result)
|
|
|
|
|
{
|
|
|
|
|
__shared__ float3 colors[16];
|
|
|
|
|
__shared__ float3 sums[16];
|
|
|
|
@ -778,6 +1059,61 @@ __global__ void compressWeighted(const uint * permutations, const uint * image,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__global__ void compressNormalDXT1(const uint * permutations, const uint * image, uint2 * result)
|
|
|
|
|
{
|
|
|
|
|
__shared__ float2 colors[16];
|
|
|
|
|
__shared__ float2 sums[16];
|
|
|
|
|
__shared__ int xrefs[16];
|
|
|
|
|
|
|
|
|
|
loadColorBlock(image, colors, sums, xrefs);
|
|
|
|
|
|
|
|
|
|
__syncthreads();
|
|
|
|
|
|
|
|
|
|
ushort bestStart, bestEnd;
|
|
|
|
|
uint bestPermutation;
|
|
|
|
|
|
|
|
|
|
__shared__ float errors[NUM_THREADS];
|
|
|
|
|
|
|
|
|
|
evalAllPermutations(colors, sums[0], permutations, bestStart, bestEnd, bestPermutation, errors);
|
|
|
|
|
|
|
|
|
|
// Use a parallel reduction to find minimum error.
|
|
|
|
|
const int minIdx = findMinError(errors);
|
|
|
|
|
|
|
|
|
|
// Only write the result of the winner thread.
|
|
|
|
|
if (threadIdx.x == minIdx)
|
|
|
|
|
{
|
|
|
|
|
saveBlockDXT1(bestStart, bestEnd, bestPermutation, xrefs, result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__global__ void compressCTX1(const uint * permutations, const uint * image, uint2 * result)
|
|
|
|
|
{
|
|
|
|
|
__shared__ float2 colors[16];
|
|
|
|
|
__shared__ float2 sums[16];
|
|
|
|
|
__shared__ int xrefs[16];
|
|
|
|
|
|
|
|
|
|
loadColorBlock(image, colors, sums, xrefs);
|
|
|
|
|
|
|
|
|
|
__syncthreads();
|
|
|
|
|
|
|
|
|
|
ushort bestStart, bestEnd;
|
|
|
|
|
uint bestPermutation;
|
|
|
|
|
|
|
|
|
|
__shared__ float errors[NUM_THREADS];
|
|
|
|
|
|
|
|
|
|
evalAllPermutationsCTX(colors, sums[0], permutations, bestStart, bestEnd, bestPermutation, errors);
|
|
|
|
|
|
|
|
|
|
// Use a parallel reduction to find minimum error.
|
|
|
|
|
const int minIdx = findMinError(errors);
|
|
|
|
|
|
|
|
|
|
// Only write the result of the winner thread.
|
|
|
|
|
if (threadIdx.x == minIdx)
|
|
|
|
|
{
|
|
|
|
|
saveBlockCTX1(bestStart, bestEnd, bestPermutation, xrefs, result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
__device__ float computeError(const float weights[16], uchar a0, uchar a1)
|
|
|
|
|
{
|
|
|
|
@ -845,8 +1181,8 @@ __device__ void optimizeAlpha8(const float alphas[16], uchar & a0, uchar & a1)
|
|
|
|
|
float a = (alphax_sum * beta2_sum - betax_sum * alphabeta_sum) * factor;
|
|
|
|
|
float b = (betax_sum * alpha2_sum - alphax_sum * alphabeta_sum) * factor;
|
|
|
|
|
|
|
|
|
|
a0 = roundAndExpand(a);
|
|
|
|
|
a1 = roundAndExpand(b);
|
|
|
|
|
a0 = roundAndExpand8(a);
|
|
|
|
|
a1 = roundAndExpand8(b);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
@ -978,12 +1314,22 @@ extern "C" void setupCompressKernel(const float weights[3])
|
|
|
|
|
// Launch kernel
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
extern "C" void compressKernel(uint blockNum, uint * d_data, uint * d_result, uint * d_bitmaps)
|
|
|
|
|
extern "C" void compressKernelDXT1(uint blockNum, uint * d_data, uint * d_result, uint * d_bitmaps)
|
|
|
|
|
{
|
|
|
|
|
compressDXT1<<<blockNum, NUM_THREADS>>>(d_bitmaps, d_data, (uint2 *)d_result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" void compressWeightedKernelDXT1(uint blockNum, uint * d_data, uint * d_result, uint * d_bitmaps)
|
|
|
|
|
{
|
|
|
|
|
compressWeightedDXT1<<<blockNum, NUM_THREADS>>>(d_bitmaps, d_data, (uint2 *)d_result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" void compressNormalKernelDXT1(uint blockNum, uint * d_data, uint * d_result, uint * d_bitmaps)
|
|
|
|
|
{
|
|
|
|
|
compress<<<blockNum, NUM_THREADS>>>(d_bitmaps, d_data, (uint2 *)d_result);
|
|
|
|
|
compressNormalDXT1<<<blockNum, NUM_THREADS>>>(d_bitmaps, d_data, (uint2 *)d_result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" void compressWeightedKernel(uint blockNum, uint * d_data, uint * d_result, uint * d_bitmaps)
|
|
|
|
|
extern "C" void compressKernelCTX1(uint blockNum, uint * d_data, uint * d_result, uint * d_bitmaps)
|
|
|
|
|
{
|
|
|
|
|
compressWeighted<<<blockNum, NUM_THREADS>>>(d_bitmaps, d_data, (uint2 *)d_result);
|
|
|
|
|
compressCTX1<<<blockNum, NUM_THREADS>>>(d_bitmaps, d_data, (uint2 *)d_result);
|
|
|
|
|
}
|
|
|
|
|