Refactor a bunch of things to renforce a bunch of style rules.

This commit is contained in:
Pavel Krajcevski 2013-08-26 16:11:39 -04:00
parent 9282541160
commit 0304bd4187
4 changed files with 1044 additions and 781 deletions

View File

@ -1,30 +1,39 @@
/* FasTC
* Copyright (c) 2012 University of North Carolina at Chapel Hill. All rights reserved.
* Copyright (c) 2012 University of North Carolina at Chapel Hill.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its documentation for educational,
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
* in all copies.
* Permission to use, copy, modify, and distribute this software and its
* documentation for educational, research, and non-profit purposes, without
* fee, and without a written agreement is hereby granted, provided that the
* above copyright notice, this paragraph, and the following four paragraphs
* appear in all copies.
*
* Permission to incorporate this software into commercial products may be obtained by contacting the
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
* Permission to incorporate this software into commercial products may be
* obtained by contacting the authors or the Office of Technology Development
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
*
* This software program and documentation are copyrighted by the University of North Carolina at Chapel Hill.
* The software program and documentation are supplied "as is," without any accompanying services from the
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
* end-user understands that the program was developed for research purposes and is advised not to rely
* exclusively on the program for any reason.
* This software program and documentation are copyrighted by the University of
* North Carolina at Chapel Hill. The software program and documentation are
* supplied "as is," without any accompanying services from the University of
* North Carolina at Chapel Hill or the authors. The University of North
* Carolina at Chapel Hill and the authors do not warrant that the operation of
* the program will be uninterrupted or error-free. The end-user understands
* that the program was developed for research purposes and is advised not to
* rely exclusively on the program for any reason.
*
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
*
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
@ -46,40 +55,42 @@
//
// This code has been modified significantly from the original.
//--------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Copyright 2011 Intel Corporation
// All Rights Reserved
//
// Permission is granted to use, copy, distribute and prepare derivative works of this
// software for any purpose and without fee, provided, that the above copyright notice
// and this statement appear in all copies. Intel makes no representations about the
// suitability of this software for any purpose. THIS SOFTWARE IS PROVIDED "AS IS."
// INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY,
// INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE,
// INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not
// assume any responsibility for any errors which may appear in this software nor any
// Permission is granted to use, copy, distribute and prepare derivative works
// of this software for any purpose and without fee, provided, that the above
// copyright notice and this statement appear in all copies. Intel makes no
// representations about the suitability of this software for any purpose. THIS
// SOFTWARE IS PROVIDED "AS IS." INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER
// INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR
// INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not assume
// any responsibility for any errors which may appear in this software nor any
// responsibility to update it.
//
//--------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef BPTCENCODER_INCLUDE_BC7COMPRESSOR_H_
#define BPTCENCODER_INCLUDE_BC7COMPRESSOR_H_
#include "BC7Config.h"
#include "CompressionJob.h"
class BlockStatManager;
namespace BC7C
{
namespace BC7C {
// This is the error metric that is applied to our error measurement algorithm
// in order to bias calculation towards results that are more in-line with
// how the Human Visual System works. Uniform error means that each color
// channel is treated equally. For a while, the widely accepted non-uniform metric
// has been to give red 30%, green 59% and blue 11% weight when computing the error
// between two pixels.
enum ErrorMetric
{
eErrorMetric_Uniform, // Treats r, g, and b channels equally
eErrorMetric_Nonuniform, // { 0.3, 0.59, 0.11 }
// channel is treated equally. For a while, the widely accepted non-uniform
// metric has been to give red 30%, green 59% and blue 11% weight when
// computing the error between two pixels.
enum ErrorMetric {
eErrorMetric_Uniform, // Treats r, g, and b channels equally
eErrorMetric_Nonuniform, // { 0.3, 0.59, 0.11 }
kNumErrorMetrics
};
@ -87,42 +98,49 @@ namespace BC7C
// Sets the error metric to be the one specified.
void SetErrorMetric(ErrorMetric e);
// Retreives a float4 pointer for the r, g, b, a weights for each color channel, in
// that order, based on the current error metric.
// Retreives a float4 pointer for the r, g, b, a weights for each color
// channel, in that order, based on the current error metric.
const float *GetErrorMetric();
// Returns the enumeration for the current error metric.
ErrorMetric GetErrorMetricEnum();
// Sets the number of steps that we use to perform simulated annealing. In general, a
// larger number produces better results. The default is set to 50. This metric works
// on a logarithmic scale -- twice the value will double the compute time, but only
// decrease the error by two times a factor.
// Sets the number of steps that we use to perform simulated annealing. In
// general, a larger number produces better results. The default is set to 50.
// This metric works on a logarithmic scale -- twice the value will double the
// compute time, but only decrease the error by two times a factor.
void SetQualityLevel(int q);
int GetQualityLevel();
// Compress the image given as RGBA data to BC7 format. Width and Height are the dimensions of
// the image in pixels.
// Compress the image given as RGBA data to BC7 format. Width and Height are
// the dimensions of the image in pixels.
void Compress(const CompressionJob &);
// Perform a compression while recording all of the choices the compressor made into a
// list of statistics. We can use this to see whether or not certain heuristics are working, such as
// whether or not certain modes are being chosen more often than others, etc.
// Perform a compression while recording all of the choices the compressor
// made into a list of statistics. We can use this to see whether or not
// certain heuristics are working, such as whether or not certain modes are
// being chosen more often than others, etc.
void CompressWithStats(const CompressionJob &, BlockStatManager &statManager);
#ifdef HAS_SSE_41
// Compress the image given as RGBA data to BC7 format using an algorithm optimized for SIMD
// enabled platforms. Width and Height are the dimensions of the image in pixels.
void CompressImageBC7SIMD(const unsigned char* inBuf, unsigned char* outBuf, unsigned int width, unsigned int height);
// Compress the image given as RGBA data to BC7 format using an algorithm
// optimized for SIMD enabled platforms. Width and Height are the dimensions
// of the image in pixels.
void CompressImageBC7SIMD(const unsigned char* inBuf, unsigned char* outBuf,
unsigned int width, unsigned int height);
#endif
#ifdef HAS_ATOMICS
// This is a threadsafe version of the compression function that is designed to compress a list of
// textures. If this function is called with the same argument from multiple threads, they will work
// together to compress all of the images in the list.
// This is a threadsafe version of the compression function that is designed
// to compress a list of textures. If this function is called with the same
// argument from multiple threads, they will work together to compress all of
// the images in the list.
void CompressAtomic(CompressionJobList &);
#endif
// Decompress the image given as BC7 data to R8G8B8A8 format. Width and Height are the dimensions of the image in pixels.
// Decompress the image given as BC7 data to R8G8B8A8 format. Width and Height
// are the dimensions of the image in pixels.
void Decompress(const DecompressionJob &);
}
} // namespace BC7C
#endif // BPTCENCODER_INCLUDE_BC7COMPRESSOR_H_

View File

@ -1,30 +1,39 @@
/* FasTC
* Copyright (c) 2012 University of North Carolina at Chapel Hill. All rights reserved.
* Copyright (c) 2012 University of North Carolina at Chapel Hill.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its documentation for educational,
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
* in all copies.
* Permission to use, copy, modify, and distribute this software and its
* documentation for educational, research, and non-profit purposes, without
* fee, and without a written agreement is hereby granted, provided that the
* above copyright notice, this paragraph, and the following four paragraphs
* appear in all copies.
*
* Permission to incorporate this software into commercial products may be obtained by contacting the
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
* Permission to incorporate this software into commercial products may be
* obtained by contacting the authors or the Office of Technology Development
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
*
* This software program and documentation are copyrighted by the University of North Carolina at Chapel Hill.
* The software program and documentation are supplied "as is," without any accompanying services from the
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
* end-user understands that the program was developed for research purposes and is advised not to rely
* exclusively on the program for any reason.
* This software program and documentation are copyrighted by the University of
* North Carolina at Chapel Hill. The software program and documentation are
* supplied "as is," without any accompanying services from the University of
* North Carolina at Chapel Hill or the authors. The University of North
* Carolina at Chapel Hill and the authors do not warrant that the operation of
* the program will be uninterrupted or error-free. The end-user understands
* that the program was developed for research purposes and is advised not to
* rely exclusively on the program for any reason.
*
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
*
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
@ -46,25 +55,26 @@
//
// This code has been modified significantly from the original.
//--------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Copyright 2011 Intel Corporation
// All Rights Reserved
//
// Permission is granted to use, copy, distribute and prepare derivative works of this
// software for any purpose and without fee, provided, that the above copyright notice
// and this statement appear in all copies. Intel makes no representations about the
// suitability of this software for any purpose. THIS SOFTWARE IS PROVIDED "AS IS."
// INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY,
// INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE,
// INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not
// assume any responsibility for any errors which may appear in this software nor any
// Permission is granted to use, copy, distribute and prepare derivative works
// of this software for any purpose and without fee, provided, that the above
// copyright notice and this statement appear in all copies. Intel makes no
// representations about the suitability of this software for any purpose. THIS
// SOFTWARE IS PROVIDED "AS IS." INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER
// INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR
// INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not assume
// any responsibility for any errors which may appear in this software nor any
// responsibility to update it.
//
//--------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef __BC7_COMPRESSIONMODE_SIMD_H__
#define __BC7_COMPRESSIONMODE_SIMD_H__
#ifndef BPTCENCODER_SRC_BC7COMPRESSIONMODE_H_
#define BPTCENCODER_SRC_BC7COMPRESSIONMODE_H_
#include "RGBAEndpoints.h"
@ -80,8 +90,6 @@ static const int kPBits[4][2] = {
{ 1, 1 }
};
// Abstract class that outlines all of the different settings for BC7 compression modes
// Note that at the moment, we only support modes 0-3, so we don't deal with alpha channels.
class BC7CompressionMode {
public:
@ -89,8 +97,9 @@ class BC7CompressionMode {
static const uint32 kMaxNumSubsets = 3;
static const uint32 kNumModes = 8;
// This initializes the compression variables used in order to compress a list of clusters.
// We can increase the speed a tad by specifying whether or not the block is opaque or not.
// This initializes the compression variables used in order to compress a list
// of clusters. We can increase the speed a tad by specifying whether or not
// the block is opaque or not.
explicit BC7CompressionMode(int mode, bool opaque = true)
: m_IsOpaque(opaque)
, m_Attributes(&(kModeAttributes[mode]))
@ -99,26 +108,29 @@ class BC7CompressionMode {
{ }
~BC7CompressionMode() { }
// This function compresses a group of clusters into the passed bitstream. The size of the
// clusters array is determined by the BC7 compression mode.
double Compress(BitStream &stream, const int shapeIdx, const RGBACluster *clusters);
// This function compresses a group of clusters into the passed bitstream. The
// size of the clusters array is determined by the BC7 compression mode.
double Compress(BitStream &stream,
const int shapeIdx, const RGBACluster *clusters);
// This switch controls the quality of the simulated annealing optimizer. We will not make
// more than this many steps regardless of how bad the error is. Higher values will produce
// better quality results but will run slower. Default is 20.
static int MaxAnnealingIterations; // This is a setting
static const int kMaxAnnealingIterations = 256; // This is a limit
// This switch controls the quality of the simulated annealing optimizer. We
// will not make more than this many steps regardless of how bad the error is.
// Higher values will produce better quality results but will run slower.
// Default is 20.
static int MaxAnnealingIterations; // This is a setting
static const int kMaxAnnealingIterations = 256; // This is a limit
// P-bits are low-order bits that are shared across color channels. This enum says whether or not
// both endpoints share a p-bit or whether or not they even have a p-bit.
// P-bits are low-order bits that are shared across color channels. This enum
// says whether or not both endpoints share a p-bit or whether or not they
// even have a p-bit.
enum EPBitType {
ePBitType_Shared,
ePBitType_NotShared,
ePBitType_None
};
// These are all the per-mode attributes that can be set. They are specified in a table
// and we access them through the private m_Attributes variable.
// These are all the per-mode attributes that can be set. They are specified
// in a table and we access them through the private m_Attributes variable.
static struct Attributes {
int modeNumber;
int numPartitionBits;
@ -149,10 +161,14 @@ class BC7CompressionMode {
void SetIndexMode(int mode) { m_IndexMode = mode; }
void SetRotationMode(int mode) { m_RotateMode = mode; }
int GetRotationMode() const { return m_Attributes->hasRotation? m_RotateMode : 0; }
int GetRotationMode() const {
return m_Attributes->hasRotation? m_RotateMode : 0;
}
int GetModeNumber() const { return m_Attributes->modeNumber; }
int GetNumberOfPartitionBits() const { return m_Attributes->numPartitionBits; }
int GetNumberOfPartitionBits() const {
return m_Attributes->numPartitionBits;
}
int GetNumberOfSubsets() const { return m_Attributes->numSubsets; }
int GetNumberOfBitsPerIndex(int indexMode = -1) const {
@ -192,24 +208,25 @@ class BC7CompressionMode {
EPBitType GetPBitType() const { return m_Attributes->pbitType; }
// This function creates an integer that represents the maximum values in each
// channel. We can use this to figure out the proper endpoint values for a given
// mode.
// channel. We can use this to figure out the proper endpoint values for a
// given mode.
unsigned int GetQuantizationMask() const {
const int maskSeed = 0x80000000;
const uint32 alphaPrec = GetAlphaChannelPrecision();
const uint32 cbits = m_Attributes->colorChannelPrecision - 1;
const uint32 abits = GetAlphaChannelPrecision() - 1;
if(alphaPrec > 0) {
return (
(maskSeed >> (24 + m_Attributes->colorChannelPrecision - 1) & 0xFF) |
(maskSeed >> (16 + m_Attributes->colorChannelPrecision - 1) & 0xFF00) |
(maskSeed >> (8 + m_Attributes->colorChannelPrecision - 1) & 0xFF0000) |
(maskSeed >> (GetAlphaChannelPrecision() - 1) & 0xFF000000)
(maskSeed >> (24 + cbits) & 0xFF) |
(maskSeed >> (16 + cbits) & 0xFF00) |
(maskSeed >> (8 + cbits) & 0xFF0000) |
(maskSeed >> abits & 0xFF000000)
);
}
else {
} else {
return (
((maskSeed >> (24 + m_Attributes->colorChannelPrecision - 1) & 0xFF) |
(maskSeed >> (16 + m_Attributes->colorChannelPrecision - 1) & 0xFF00) |
(maskSeed >> (8 + m_Attributes->colorChannelPrecision - 1) & 0xFF0000)) &
((maskSeed >> (24 + cbits) & 0xFF) |
(maskSeed >> (16 + cbits) & 0xFF00) |
(maskSeed >> (8 + cbits) & 0xFF0000)) &
(0x00FFFFFF)
);
}
@ -257,30 +274,39 @@ class BC7CompressionMode {
float stepSz = 1.0f
) const;
// This is used by simulated annealing to determine whether or not the newError
// (from the neighboring endpoints) is sufficient to continue the annealing process
// from these new endpoints based on how good the oldError was, and how long we've
// been annealing (temp)
bool AcceptNewEndpointError(double newError, double oldError, float temp) const;
// This is used by simulated annealing to determine whether or not the
// newError (from the neighboring endpoints) is sufficient to continue the
// annealing process from these new endpoints based on how good the oldError
// was, and how long we've been annealing (t)
bool AcceptNewEndpointError(double newError, double oldError, float t) const;
// This function figures out the best compression for the single color p, and places
// the endpoints in p1 and p2. If the compression mode supports p-bits, then we
// choose the best p-bit combo and return it as well.
double CompressSingleColor(const RGBAVector &p, RGBAVector &p1, RGBAVector &p2, int &bestPbitCombo) const;
// This function figures out the best compression for the single color p, and
// places the endpoints in p1 and p2. If the compression mode supports p-bits,
// then we choose the best p-bit combo and return it as well.
double CompressSingleColor(const RGBAVector &p,
RGBAVector &p1, RGBAVector &p2,
int &bestPbitCombo) const;
// Compress the cluster using a generalized cluster fit. This figures out the proper endpoints
// assuming that we have no alpha.
double CompressCluster(const RGBACluster &cluster, RGBAVector &p1, RGBAVector &p2, int *bestIndices, int &bestPbitCombo) const;
// Compress the cluster using a generalized cluster fit. This figures out the
// proper endpoints assuming that we have no alpha.
double CompressCluster(const RGBACluster &cluster,
RGBAVector &p1, RGBAVector &p2,
int *bestIndices, int &bestPbitCombo) const;
// Compress the non-opaque cluster using a generalized cluster fit, and place the
// endpoints within p1 and p2. The color indices and alpha indices are computed as well.
double CompressCluster(const RGBACluster &cluster, RGBAVector &p1, RGBAVector &p2, int *bestIndices, int *alphaIndices) const;
// Compress the non-opaque cluster using a generalized cluster fit, and place
// the endpoints within p1 and p2. The color indices and alpha indices are
// computed as well.
double CompressCluster(const RGBACluster &cluster,
RGBAVector &p1, RGBAVector &p2,
int *bestIndices, int *alphaIndices) const;
// This function takes two endpoints in the continuous domain (as floats) and clamps them
// to the nearest grid points based on the compression mode (and possible pbit values)
void ClampEndpointsToGrid(RGBAVector &p1, RGBAVector &p2, int &bestPBitCombo) const;
// This function takes two endpoints in the continuous domain (as floats) and
// clamps them to the nearest grid points based on the compression mode (and
// possible pbit values)
void ClampEndpointsToGrid(RGBAVector &p1, RGBAVector &p2,
int &bestPBitCombo) const;
};
extern const uint32 kBC7InterpolationValues[4][16][2];
#endif // __BC7_COMPRESSIONMODE_SIMD_H__
#endif // BPTCENCODER_SRC_BC7COMPRESSIONMODE_H_

View File

@ -1,30 +1,39 @@
/* FasTC
* Copyright (c) 2012 University of North Carolina at Chapel Hill. All rights reserved.
* Copyright (c) 2012 University of North Carolina at Chapel Hill.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its documentation for educational,
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
* in all copies.
* Permission to use, copy, modify, and distribute this software and its
* documentation for educational, research, and non-profit purposes, without
* fee, and without a written agreement is hereby granted, provided that the
* above copyright notice, this paragraph, and the following four paragraphs
* appear in all copies.
*
* Permission to incorporate this software into commercial products may be obtained by contacting the
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
* Permission to incorporate this software into commercial products may be
* obtained by contacting the authors or the Office of Technology Development
* at the University of North Carolina at Chapel Hill <otd@unc.edu>.
*
* This software program and documentation are copyrighted by the University of North Carolina at Chapel Hill.
* The software program and documentation are supplied "as is," without any accompanying services from the
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
* end-user understands that the program was developed for research purposes and is advised not to rely
* exclusively on the program for any reason.
* This software program and documentation are copyrighted by the University of
* North Carolina at Chapel Hill. The software program and documentation are
* supplied "as is," without any accompanying services from the University of
* North Carolina at Chapel Hill or the authors. The University of North
* Carolina at Chapel Hill and the authors do not warrant that the operation of
* the program will be uninterrupted or error-free. The end-user understands
* that the program was developed for research purposes and is advised not to
* rely exclusively on the program for any reason.
*
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
* THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA
* AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON
* AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND
* THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
*
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
@ -46,25 +55,26 @@
//
// This code has been modified significantly from the original.
//--------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Copyright 2011 Intel Corporation
// All Rights Reserved
//
// Permission is granted to use, copy, distribute and prepare derivative works of this
// software for any purpose and without fee, provided, that the above copyright notice
// and this statement appear in all copies. Intel makes no representations about the
// suitability of this software for any purpose. THIS SOFTWARE IS PROVIDED "AS IS."
// INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY,
// INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE,
// INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not
// assume any responsibility for any errors which may appear in this software nor any
// Permission is granted to use, copy, distribute and prepare derivative works
// of this software for any purpose and without fee, provided, that the above
// copyright notice and this statement appear in all copies. Intel makes no
// representations about the suitability of this software for any purpose. THIS
// SOFTWARE IS PROVIDED "AS IS." INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER
// INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR
// INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not assume
// any responsibility for any errors which may appear in this software nor any
// responsibility to update it.
//
//--------------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef __BC7_COMPRESSIONMODE_H__
#define __BC7_COMPRESSIONMODE_H__
#ifndef BPTCENCODER_SRC_BC7COMPRESSIONMODESIMD_H_
#define BPTCENCODER_SRC_BC7COMPRESSIONMODESIMD_H_
#include "TexCompTypes.h"
#include "RGBAEndpointsSIMD.h"
@ -73,129 +83,158 @@
class BitStream;
static const int kPBits[4][2] = {
{ 0, 0 },
{ 0, 1 },
{ 1, 0 },
{ 1, 1 }
{ 0, 0 },
{ 0, 1 },
{ 1, 0 },
{ 1, 1 }
};
// Abstract class that outlines all of the different settings for BC7 compression modes
// Note that at the moment, we only support modes 0-3, so we don't deal with alpha channels.
class BC7CompressionModeSIMD {
public:
public:
static const int kMaxNumSubsets = 3;
static const int kNumModes = 8;
static const int kMaxNumSubsets = 3;
static const int kNumModes = 8;
enum EPBitType {
ePBitType_Shared,
ePBitType_NotShared,
ePBitType_None
};
enum EPBitType {
ePBitType_Shared,
ePBitType_NotShared,
ePBitType_None
};
BC7CompressionModeSIMD(int mode, double err) : m_EstimatedError(err), m_Attributes(&(kModeAttributes[mode])) { }
~BC7CompressionModeSIMD() { }
BC7CompressionModeSIMD(int mode, double err)
: m_EstimatedError(err)
, m_Attributes(&(kModeAttributes[mode]))
{ }
~BC7CompressionModeSIMD() { }
static int NumUses[8];
static void ResetNumUses() { memset(NumUses, 0, sizeof(NumUses)); }
static int NumUses[8];
static void ResetNumUses() { memset(NumUses, 0, sizeof(NumUses)); }
double Compress(BitStream &stream, const int shapeIdx, const RGBAClusterSIMD *clusters) const;
double Compress(BitStream &stream, const int shapeIdx,
const RGBAClusterSIMD *clusters) const;
// This switch controls the quality of the simulated annealing optimizer. We will not make
// more than this many steps regardless of how bad the error is. Higher values will produce
// better quality results but will run slower. Default is 50.
static int MaxAnnealingIterations; // This is a setting
// This switch controls the quality of the simulated annealing optimizer. We
// will not make more than this many steps regardless of how bad the error is.
// Higher values will produce better quality results but will run slower.
// Default is 50.
static int MaxAnnealingIterations; // This is a setting
private:
private:
static struct Attributes {
int modeNumber;
int numPartitionBits;
int numSubsets;
int numBitsPerIndex;
int redChannelPrecision;
int greenChannelPrecision;
int blueChannelPrecision;
int alphaChannelPrecision;
EPBitType pbitType;
} kModeAttributes[kNumModes];
static struct Attributes {
int modeNumber;
int numPartitionBits;
int numSubsets;
int numBitsPerIndex;
int redChannelPrecision;
int greenChannelPrecision;
int blueChannelPrecision;
int alphaChannelPrecision;
EPBitType pbitType;
} kModeAttributes[kNumModes];
protected:
const Attributes *const m_Attributes;
protected:
const Attributes *const m_Attributes;
int GetModeNumber() const { return m_Attributes->modeNumber; }
int GetNumberOfPartitionBits() const { return m_Attributes->numPartitionBits; }
int GetNumberOfSubsets() const { return m_Attributes->numSubsets; }
int GetNumberOfBitsPerIndex() const { return m_Attributes->numBitsPerIndex; }
int GetModeNumber() const { return m_Attributes->modeNumber; }
int GetNumberOfPartitionBits() const {
return m_Attributes->numPartitionBits;
}
int GetNumberOfSubsets() const { return m_Attributes->numSubsets; }
int GetNumberOfBitsPerIndex() const { return m_Attributes->numBitsPerIndex; }
int GetRedChannelPrecision() const { return m_Attributes->redChannelPrecision; }
int GetGreenChannelPrecision() const { return m_Attributes->greenChannelPrecision; }
int GetBlueChannelPrecision() const { return m_Attributes->blueChannelPrecision; }
int GetAlphaChannelPrecision() const { return m_Attributes->alphaChannelPrecision; }
int GetRedChannelPrecision() const {
return m_Attributes->redChannelPrecision;
}
EPBitType GetPBitType() const { return m_Attributes->pbitType; }
int GetGreenChannelPrecision() const {
return m_Attributes->greenChannelPrecision;
}
// !SPEED! Add this to the attributes lookup table
void GetQuantizationMask(__m128i &mask) const {
const int maskSeed = 0x80000000;
mask = _mm_set_epi32(
(GetAlphaChannelPrecision() > 0)? (maskSeed >> (24 + GetAlphaChannelPrecision() - 1) & 0xFF) : 0xFF,
(maskSeed >> (24 + GetBlueChannelPrecision() - 1) & 0xFF),
(maskSeed >> (24 + GetGreenChannelPrecision() - 1) & 0xFF),
(maskSeed >> (24 + GetRedChannelPrecision() - 1) & 0xFF)
);
}
int GetBlueChannelPrecision() const {
return m_Attributes->blueChannelPrecision;
}
int GetNumPbitCombos() const {
switch(GetPBitType()) {
case ePBitType_Shared: return 2;
case ePBitType_NotShared: return 4;
default:
case ePBitType_None: return 1;
}
}
int GetAlphaChannelPrecision() const {
return m_Attributes->alphaChannelPrecision;
}
const int *GetPBitCombo(int idx) const {
switch(GetPBitType()) {
case ePBitType_Shared: return (idx)? kPBits[3] : kPBits[0];
case ePBitType_NotShared: return kPBits[idx % 4];
default:
case ePBitType_None: return kPBits[0];
}
}
EPBitType GetPBitType() const { return m_Attributes->pbitType; }
double OptimizeEndpointsForCluster(const RGBAClusterSIMD &cluster, RGBAVectorSIMD &p1, RGBAVectorSIMD &p2, __m128i *bestIndices, int &bestPbitCombo) const;
// !SPEED! Add this to the attributes lookup table
void GetQuantizationMask(__m128i &mask) const {
const int maskSeed = 0x80000000;
const uint32 abits = 24 + GetAlphaChannelPrecision() - 1;
const uint32 rbits = 24 + GetRedChannelPrecision() - 1;
const uint32 gbits = 24 + GetGreenChannelPrecision() - 1;
const uint32 bbits = 24 + GetBlueChannelPrecision() - 1;
mask = _mm_set_epi32(
(GetAlphaChannelPrecision() > 0)? (maskSeed >> abits & 0xFF) : 0xFF,
(maskSeed >> rbits & 0xFF),
(maskSeed >> gbits & 0xFF),
(maskSeed >> bbits & 0xFF)
);
}
struct VisitedState {
RGBAVectorSIMD p1;
RGBAVectorSIMD p2;
int pBitCombo;
};
int GetNumPbitCombos() const {
switch(GetPBitType()) {
case ePBitType_Shared: return 2;
case ePBitType_NotShared: return 4;
default:
case ePBitType_None: return 1;
}
}
void PickBestNeighboringEndpoints(
const RGBAClusterSIMD &cluster,
const RGBAVectorSIMD &p1, const RGBAVectorSIMD &p2,
const int curPbitCombo,
RGBAVectorSIMD &np1, RGBAVectorSIMD &np2,
int &nPbitCombo,
const __m128 &stepVec
) const;
const int *GetPBitCombo(int idx) const {
switch(GetPBitType()) {
case ePBitType_Shared: return (idx)? kPBits[3] : kPBits[0];
case ePBitType_NotShared: return kPBits[idx % 4];
default:
case ePBitType_None: return kPBits[0];
}
}
bool AcceptNewEndpointError(float newError, float oldError, float temp) const;
double OptimizeEndpointsForCluster(const RGBAClusterSIMD &cluster,
RGBAVectorSIMD &p1, RGBAVectorSIMD &p2,
__m128i *bestIndices,
int &bestPbitCombo) const;
double CompressSingleColor(const RGBAVectorSIMD &p, RGBAVectorSIMD &p1, RGBAVectorSIMD &p2, int &bestPbitCombo) const;
double CompressCluster(const RGBAClusterSIMD &cluster, RGBAVectorSIMD &p1, RGBAVectorSIMD &p2, __m128i *bestIndices, int &bestPbitCombo) const;
struct VisitedState {
RGBAVectorSIMD p1;
RGBAVectorSIMD p2;
int pBitCombo;
};
void ClampEndpointsToGrid(RGBAVectorSIMD &p1, RGBAVectorSIMD &p2, int &bestPBitCombo) const;
void PickBestNeighboringEndpoints(
const RGBAClusterSIMD &cluster,
const RGBAVectorSIMD &p1, const RGBAVectorSIMD &p2,
const int curPbitCombo,
RGBAVectorSIMD &np1, RGBAVectorSIMD &np2,
int &nPbitCombo,
const __m128 &stepVec
) const;
int GetSubsetForIndex(int idx, const int shapeIdx) const;
int GetAnchorIndexForSubset(int subset, const int shapeIdx) const;
bool AcceptNewEndpointError(float newError, float oldError, float temp) const;
double GetEstimatedError() const { return m_EstimatedError; }
const double m_EstimatedError;
double CompressSingleColor(const RGBAVectorSIMD &p,
RGBAVectorSIMD &p1, RGBAVectorSIMD &p2,
int &bestPbitCombo) const;
double CompressCluster(const RGBAClusterSIMD &cluster,
RGBAVectorSIMD &p1, RGBAVectorSIMD &p2,
__m128i *bestIndices,
int &bestPbitCombo) const;
void ClampEndpointsToGrid(RGBAVectorSIMD &p1, RGBAVectorSIMD &p2,
int &bestPBitCombo) const;
int GetSubsetForIndex(int idx, const int shapeIdx) const;
int GetAnchorIndexForSubset(int subset, const int shapeIdx) const;
double GetEstimatedError() const { return m_EstimatedError; }
const double m_EstimatedError;
};
extern const __m128i kBC7InterpolationValuesSIMD[4][16][2];
extern const uint32 kBC7InterpolationValuesScalar[4][16][2];
#endif // __BC7_COMPRESSIONMODE_H__
#endif // BPTCENCODER_SRC_BC7COMPRESSIONMODESIMD_H_

File diff suppressed because it is too large Load Diff