mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-24 07:05:39 +01:00
Refactor a bunch of things to renforce a bunch of style rules.
This commit is contained in:
parent
9282541160
commit
0304bd4187
@ -1,30 +1,39 @@
|
|||||||
/* FasTC
|
/* 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,
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
|
* documentation for educational, research, and non-profit purposes, without
|
||||||
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
|
* fee, and without a written agreement is hereby granted, provided that the
|
||||||
* in all copies.
|
* 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
|
* Permission to incorporate this software into commercial products may be
|
||||||
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
* 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.
|
* This software program and documentation are copyrighted by the University of
|
||||||
* The software program and documentation are supplied "as is," without any accompanying services from the
|
* North Carolina at Chapel Hill. The software program and documentation are
|
||||||
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
|
* supplied "as is," without any accompanying services from the University of
|
||||||
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
|
* North Carolina at Chapel Hill or the authors. The University of North
|
||||||
* end-user understands that the program was developed for research purposes and is advised not to rely
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
||||||
* exclusively on the program for any reason.
|
* 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
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
||||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
||||||
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
||||||
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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,
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
||||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
||||||
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* 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.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*
|
*
|
||||||
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
||||||
@ -46,83 +55,92 @@
|
|||||||
//
|
//
|
||||||
// This code has been modified significantly from the original.
|
// This code has been modified significantly from the original.
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright 2011 Intel Corporation
|
// Copyright 2011 Intel Corporation
|
||||||
// All Rights Reserved
|
// All Rights Reserved
|
||||||
//
|
//
|
||||||
// Permission is granted to use, copy, distribute and prepare derivative works of this
|
// Permission is granted to use, copy, distribute and prepare derivative works
|
||||||
// software for any purpose and without fee, provided, that the above copyright notice
|
// of this software for any purpose and without fee, provided, that the above
|
||||||
// and this statement appear in all copies. Intel makes no representations about the
|
// copyright notice and this statement appear in all copies. Intel makes no
|
||||||
// suitability of this software for any purpose. THIS SOFTWARE IS PROVIDED "AS IS."
|
// representations about the suitability of this software for any purpose. THIS
|
||||||
// INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY,
|
// SOFTWARE IS PROVIDED "AS IS." INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
||||||
// INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE,
|
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER
|
||||||
// INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE
|
// INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR
|
||||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not
|
// INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE WARRANTIES OF
|
||||||
// assume any responsibility for any errors which may appear in this software nor any
|
// 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.
|
// responsibility to update it.
|
||||||
//
|
//
|
||||||
//--------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef BPTCENCODER_INCLUDE_BC7COMPRESSOR_H_
|
||||||
|
#define BPTCENCODER_INCLUDE_BC7COMPRESSOR_H_
|
||||||
|
|
||||||
#include "BC7Config.h"
|
#include "BC7Config.h"
|
||||||
#include "CompressionJob.h"
|
#include "CompressionJob.h"
|
||||||
|
|
||||||
class BlockStatManager;
|
class BlockStatManager;
|
||||||
|
|
||||||
namespace BC7C
|
namespace BC7C {
|
||||||
{
|
|
||||||
// This is the error metric that is applied to our error measurement algorithm
|
// 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
|
// 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
|
// 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
|
// channel is treated equally. For a while, the widely accepted non-uniform
|
||||||
// has been to give red 30%, green 59% and blue 11% weight when computing the error
|
// metric has been to give red 30%, green 59% and blue 11% weight when
|
||||||
// between two pixels.
|
// computing the error between two pixels.
|
||||||
enum ErrorMetric
|
enum ErrorMetric {
|
||||||
{
|
eErrorMetric_Uniform, // Treats r, g, and b channels equally
|
||||||
eErrorMetric_Uniform, // Treats r, g, and b channels equally
|
eErrorMetric_Nonuniform, // { 0.3, 0.59, 0.11 }
|
||||||
eErrorMetric_Nonuniform, // { 0.3, 0.59, 0.11 }
|
|
||||||
|
|
||||||
kNumErrorMetrics
|
kNumErrorMetrics
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sets the error metric to be the one specified.
|
// Sets the error metric to be the one specified.
|
||||||
void SetErrorMetric(ErrorMetric e);
|
void SetErrorMetric(ErrorMetric e);
|
||||||
|
|
||||||
// Retreives a float4 pointer for the r, g, b, a weights for each color channel, in
|
// Retreives a float4 pointer for the r, g, b, a weights for each color
|
||||||
// that order, based on the current error metric.
|
// channel, in that order, based on the current error metric.
|
||||||
const float *GetErrorMetric();
|
const float *GetErrorMetric();
|
||||||
|
|
||||||
// Returns the enumeration for the current error metric.
|
// Returns the enumeration for the current error metric.
|
||||||
ErrorMetric GetErrorMetricEnum();
|
ErrorMetric GetErrorMetricEnum();
|
||||||
|
|
||||||
// Sets the number of steps that we use to perform simulated annealing. In general, a
|
// Sets the number of steps that we use to perform simulated annealing. In
|
||||||
// larger number produces better results. The default is set to 50. This metric works
|
// general, a larger number produces better results. The default is set to 50.
|
||||||
// on a logarithmic scale -- twice the value will double the compute time, but only
|
// This metric works on a logarithmic scale -- twice the value will double the
|
||||||
// decrease the error by two times a factor.
|
// compute time, but only decrease the error by two times a factor.
|
||||||
void SetQualityLevel(int q);
|
void SetQualityLevel(int q);
|
||||||
int GetQualityLevel();
|
int GetQualityLevel();
|
||||||
|
|
||||||
// Compress the image given as RGBA data to BC7 format. Width and Height are the dimensions of
|
// Compress the image given as RGBA data to BC7 format. Width and Height are
|
||||||
// the image in pixels.
|
// the dimensions of the image in pixels.
|
||||||
void Compress(const CompressionJob &);
|
void Compress(const CompressionJob &);
|
||||||
|
|
||||||
// Perform a compression while recording all of the choices the compressor made into a
|
// Perform a compression while recording all of the choices the compressor
|
||||||
// list of statistics. We can use this to see whether or not certain heuristics are working, such as
|
// made into a list of statistics. We can use this to see whether or not
|
||||||
// whether or not certain modes are being chosen more often than others, etc.
|
// 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);
|
void CompressWithStats(const CompressionJob &, BlockStatManager &statManager);
|
||||||
|
|
||||||
#ifdef HAS_SSE_41
|
#ifdef HAS_SSE_41
|
||||||
// Compress the image given as RGBA data to BC7 format using an algorithm optimized for SIMD
|
// Compress the image given as RGBA data to BC7 format using an algorithm
|
||||||
// enabled platforms. Width and Height are the dimensions of the image in pixels.
|
// optimized for SIMD enabled platforms. Width and Height are the dimensions
|
||||||
void CompressImageBC7SIMD(const unsigned char* inBuf, unsigned char* outBuf, unsigned int width, unsigned int height);
|
// of the image in pixels.
|
||||||
|
void CompressImageBC7SIMD(const unsigned char* inBuf, unsigned char* outBuf,
|
||||||
|
unsigned int width, unsigned int height);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_ATOMICS
|
#ifdef HAS_ATOMICS
|
||||||
// This is a threadsafe version of the compression function that is designed to compress a list of
|
// This is a threadsafe version of the compression function that is designed
|
||||||
// textures. If this function is called with the same argument from multiple threads, they will work
|
// to compress a list of textures. If this function is called with the same
|
||||||
// together to compress all of the images in the list.
|
// argument from multiple threads, they will work together to compress all of
|
||||||
|
// the images in the list.
|
||||||
void CompressAtomic(CompressionJobList &);
|
void CompressAtomic(CompressionJobList &);
|
||||||
#endif
|
#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 &);
|
void Decompress(const DecompressionJob &);
|
||||||
}
|
} // namespace BC7C
|
||||||
|
|
||||||
|
#endif // BPTCENCODER_INCLUDE_BC7COMPRESSOR_H_
|
||||||
|
@ -1,30 +1,39 @@
|
|||||||
/* FasTC
|
/* 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,
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
|
* documentation for educational, research, and non-profit purposes, without
|
||||||
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
|
* fee, and without a written agreement is hereby granted, provided that the
|
||||||
* in all copies.
|
* 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
|
* Permission to incorporate this software into commercial products may be
|
||||||
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
* 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.
|
* This software program and documentation are copyrighted by the University of
|
||||||
* The software program and documentation are supplied "as is," without any accompanying services from the
|
* North Carolina at Chapel Hill. The software program and documentation are
|
||||||
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
|
* supplied "as is," without any accompanying services from the University of
|
||||||
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
|
* North Carolina at Chapel Hill or the authors. The University of North
|
||||||
* end-user understands that the program was developed for research purposes and is advised not to rely
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
||||||
* exclusively on the program for any reason.
|
* 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
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
||||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
||||||
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
||||||
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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,
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
||||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
||||||
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* 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.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*
|
*
|
||||||
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
||||||
@ -46,25 +55,26 @@
|
|||||||
//
|
//
|
||||||
// This code has been modified significantly from the original.
|
// This code has been modified significantly from the original.
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright 2011 Intel Corporation
|
// Copyright 2011 Intel Corporation
|
||||||
// All Rights Reserved
|
// All Rights Reserved
|
||||||
//
|
//
|
||||||
// Permission is granted to use, copy, distribute and prepare derivative works of this
|
// Permission is granted to use, copy, distribute and prepare derivative works
|
||||||
// software for any purpose and without fee, provided, that the above copyright notice
|
// of this software for any purpose and without fee, provided, that the above
|
||||||
// and this statement appear in all copies. Intel makes no representations about the
|
// copyright notice and this statement appear in all copies. Intel makes no
|
||||||
// suitability of this software for any purpose. THIS SOFTWARE IS PROVIDED "AS IS."
|
// representations about the suitability of this software for any purpose. THIS
|
||||||
// INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY,
|
// SOFTWARE IS PROVIDED "AS IS." INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
||||||
// INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE,
|
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER
|
||||||
// INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE
|
// INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR
|
||||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not
|
// INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE WARRANTIES OF
|
||||||
// assume any responsibility for any errors which may appear in this software nor any
|
// 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.
|
// responsibility to update it.
|
||||||
//
|
//
|
||||||
//--------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef __BC7_COMPRESSIONMODE_SIMD_H__
|
#ifndef BPTCENCODER_SRC_BC7COMPRESSIONMODE_H_
|
||||||
#define __BC7_COMPRESSIONMODE_SIMD_H__
|
#define BPTCENCODER_SRC_BC7COMPRESSIONMODE_H_
|
||||||
|
|
||||||
#include "RGBAEndpoints.h"
|
#include "RGBAEndpoints.h"
|
||||||
|
|
||||||
@ -80,8 +90,6 @@ static const int kPBits[4][2] = {
|
|||||||
{ 1, 1 }
|
{ 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 {
|
class BC7CompressionMode {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -89,36 +97,40 @@ class BC7CompressionMode {
|
|||||||
static const uint32 kMaxNumSubsets = 3;
|
static const uint32 kMaxNumSubsets = 3;
|
||||||
static const uint32 kNumModes = 8;
|
static const uint32 kNumModes = 8;
|
||||||
|
|
||||||
// This initializes the compression variables used in order to compress a list of clusters.
|
// This initializes the compression variables used in order to compress a list
|
||||||
// We can increase the speed a tad by specifying whether or not the block is opaque or not.
|
// of clusters. We can increase the speed a tad by specifying whether or not
|
||||||
explicit BC7CompressionMode(int mode, bool opaque = true)
|
// the block is opaque or not.
|
||||||
|
explicit BC7CompressionMode(int mode, bool opaque = true)
|
||||||
: m_IsOpaque(opaque)
|
: m_IsOpaque(opaque)
|
||||||
, m_Attributes(&(kModeAttributes[mode]))
|
, m_Attributes(&(kModeAttributes[mode]))
|
||||||
, m_RotateMode(0)
|
, m_RotateMode(0)
|
||||||
, m_IndexMode(0)
|
, m_IndexMode(0)
|
||||||
{ }
|
{ }
|
||||||
~BC7CompressionMode() { }
|
~BC7CompressionMode() { }
|
||||||
|
|
||||||
// This function compresses a group of clusters into the passed bitstream. The size of the
|
// This function compresses a group of clusters into the passed bitstream. The
|
||||||
// clusters array is determined by the BC7 compression mode.
|
// size of the clusters array is determined by the BC7 compression mode.
|
||||||
double Compress(BitStream &stream, const int shapeIdx, const RGBACluster *clusters);
|
double Compress(BitStream &stream,
|
||||||
|
const int shapeIdx, const RGBACluster *clusters);
|
||||||
|
|
||||||
// This switch controls the quality of the simulated annealing optimizer. We will not make
|
// This switch controls the quality of the simulated annealing optimizer. We
|
||||||
// more than this many steps regardless of how bad the error is. Higher values will produce
|
// will not make more than this many steps regardless of how bad the error is.
|
||||||
// better quality results but will run slower. Default is 20.
|
// Higher values will produce better quality results but will run slower.
|
||||||
static int MaxAnnealingIterations; // This is a setting
|
// Default is 20.
|
||||||
static const int kMaxAnnealingIterations = 256; // This is a limit
|
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
|
// P-bits are low-order bits that are shared across color channels. This enum
|
||||||
// both endpoints share a p-bit or whether or not they even have a p-bit.
|
// says whether or not both endpoints share a p-bit or whether or not they
|
||||||
|
// even have a p-bit.
|
||||||
enum EPBitType {
|
enum EPBitType {
|
||||||
ePBitType_Shared,
|
ePBitType_Shared,
|
||||||
ePBitType_NotShared,
|
ePBitType_NotShared,
|
||||||
ePBitType_None
|
ePBitType_None
|
||||||
};
|
};
|
||||||
|
|
||||||
// These are all the per-mode attributes that can be set. They are specified in a table
|
// These are all the per-mode attributes that can be set. They are specified
|
||||||
// and we access them through the private m_Attributes variable.
|
// in a table and we access them through the private m_Attributes variable.
|
||||||
static struct Attributes {
|
static struct Attributes {
|
||||||
int modeNumber;
|
int modeNumber;
|
||||||
int numPartitionBits;
|
int numPartitionBits;
|
||||||
@ -139,7 +151,7 @@ class BC7CompressionMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const double m_IsOpaque;
|
const double m_IsOpaque;
|
||||||
const Attributes *const m_Attributes;
|
const Attributes *const m_Attributes;
|
||||||
|
|
||||||
@ -149,32 +161,36 @@ class BC7CompressionMode {
|
|||||||
void SetIndexMode(int mode) { m_IndexMode = mode; }
|
void SetIndexMode(int mode) { m_IndexMode = mode; }
|
||||||
void SetRotationMode(int mode) { m_RotateMode = 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 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 GetNumberOfSubsets() const { return m_Attributes->numSubsets; }
|
||||||
|
|
||||||
int GetNumberOfBitsPerIndex(int indexMode = -1) const {
|
int GetNumberOfBitsPerIndex(int indexMode = -1) const {
|
||||||
if(indexMode < 0) indexMode = m_IndexMode;
|
if(indexMode < 0) indexMode = m_IndexMode;
|
||||||
if(indexMode == 0)
|
if(indexMode == 0)
|
||||||
return m_Attributes->numBitsPerIndex;
|
return m_Attributes->numBitsPerIndex;
|
||||||
else
|
else
|
||||||
return m_Attributes->numBitsPerAlpha;
|
return m_Attributes->numBitsPerAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetNumberOfBitsPerAlpha(int indexMode = -1) const {
|
int GetNumberOfBitsPerAlpha(int indexMode = -1) const {
|
||||||
if(indexMode < 0) indexMode = m_IndexMode;
|
if(indexMode < 0) indexMode = m_IndexMode;
|
||||||
if(indexMode == 0)
|
if(indexMode == 0)
|
||||||
return m_Attributes->numBitsPerAlpha;
|
return m_Attributes->numBitsPerAlpha;
|
||||||
else
|
else
|
||||||
return m_Attributes->numBitsPerIndex;
|
return m_Attributes->numBitsPerIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we handle alpha separately, then we will consider the alpha channel
|
// If we handle alpha separately, then we will consider the alpha channel
|
||||||
// to be not used whenever we do any calculations...
|
// to be not used whenever we do any calculations...
|
||||||
int GetAlphaChannelPrecision() const {
|
int GetAlphaChannelPrecision() const {
|
||||||
return m_Attributes->alphaChannelPrecision;
|
return m_Attributes->alphaChannelPrecision;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This returns the proper error metric even if we have rotation bits set
|
// This returns the proper error metric even if we have rotation bits set
|
||||||
@ -192,24 +208,25 @@ class BC7CompressionMode {
|
|||||||
EPBitType GetPBitType() const { return m_Attributes->pbitType; }
|
EPBitType GetPBitType() const { return m_Attributes->pbitType; }
|
||||||
|
|
||||||
// This function creates an integer that represents the maximum values in each
|
// 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
|
// channel. We can use this to figure out the proper endpoint values for a
|
||||||
// mode.
|
// given mode.
|
||||||
unsigned int GetQuantizationMask() const {
|
unsigned int GetQuantizationMask() const {
|
||||||
const int maskSeed = 0x80000000;
|
const int maskSeed = 0x80000000;
|
||||||
const uint32 alphaPrec = GetAlphaChannelPrecision();
|
const uint32 alphaPrec = GetAlphaChannelPrecision();
|
||||||
|
const uint32 cbits = m_Attributes->colorChannelPrecision - 1;
|
||||||
|
const uint32 abits = GetAlphaChannelPrecision() - 1;
|
||||||
if(alphaPrec > 0) {
|
if(alphaPrec > 0) {
|
||||||
return (
|
return (
|
||||||
(maskSeed >> (24 + m_Attributes->colorChannelPrecision - 1) & 0xFF) |
|
(maskSeed >> (24 + cbits) & 0xFF) |
|
||||||
(maskSeed >> (16 + m_Attributes->colorChannelPrecision - 1) & 0xFF00) |
|
(maskSeed >> (16 + cbits) & 0xFF00) |
|
||||||
(maskSeed >> (8 + m_Attributes->colorChannelPrecision - 1) & 0xFF0000) |
|
(maskSeed >> (8 + cbits) & 0xFF0000) |
|
||||||
(maskSeed >> (GetAlphaChannelPrecision() - 1) & 0xFF000000)
|
(maskSeed >> abits & 0xFF000000)
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return (
|
return (
|
||||||
((maskSeed >> (24 + m_Attributes->colorChannelPrecision - 1) & 0xFF) |
|
((maskSeed >> (24 + cbits) & 0xFF) |
|
||||||
(maskSeed >> (16 + m_Attributes->colorChannelPrecision - 1) & 0xFF00) |
|
(maskSeed >> (16 + cbits) & 0xFF00) |
|
||||||
(maskSeed >> (8 + m_Attributes->colorChannelPrecision - 1) & 0xFF0000)) &
|
(maskSeed >> (8 + cbits) & 0xFF0000)) &
|
||||||
(0x00FFFFFF)
|
(0x00FFFFFF)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -234,7 +251,7 @@ class BC7CompressionMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This performs simulated annealing on the endpoints p1 and p2 based on the
|
// This performs simulated annealing on the endpoints p1 and p2 based on the
|
||||||
// current MaxAnnealingIterations. This is set by calling the function
|
// current MaxAnnealingIterations. This is set by calling the function
|
||||||
// SetQualityLevel
|
// SetQualityLevel
|
||||||
double OptimizeEndpointsForCluster(
|
double OptimizeEndpointsForCluster(
|
||||||
const RGBACluster &cluster,
|
const RGBACluster &cluster,
|
||||||
@ -247,40 +264,49 @@ class BC7CompressionMode {
|
|||||||
// endpoints to p1 and p2 based on the compression mode (index precision,
|
// endpoints to p1 and p2 based on the compression mode (index precision,
|
||||||
// endpoint precision etc)
|
// endpoint precision etc)
|
||||||
void PickBestNeighboringEndpoints(
|
void PickBestNeighboringEndpoints(
|
||||||
const RGBACluster &cluster,
|
const RGBACluster &cluster,
|
||||||
const RGBAVector &p1, const RGBAVector &p2,
|
const RGBAVector &p1, const RGBAVector &p2,
|
||||||
const int curPbitCombo,
|
const int curPbitCombo,
|
||||||
RGBAVector &np1, RGBAVector &np2,
|
RGBAVector &np1, RGBAVector &np2,
|
||||||
int &nPbitCombo,
|
int &nPbitCombo,
|
||||||
const VisitedState *visitedStates,
|
const VisitedState *visitedStates,
|
||||||
int nVisited,
|
int nVisited,
|
||||||
float stepSz = 1.0f
|
float stepSz = 1.0f
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
// This is used by simulated annealing to determine whether or not the newError
|
// This is used by simulated annealing to determine whether or not the
|
||||||
// (from the neighboring endpoints) is sufficient to continue the annealing process
|
// newError (from the neighboring endpoints) is sufficient to continue the
|
||||||
// from these new endpoints based on how good the oldError was, and how long we've
|
// annealing process from these new endpoints based on how good the oldError
|
||||||
// been annealing (temp)
|
// was, and how long we've been annealing (t)
|
||||||
bool AcceptNewEndpointError(double newError, double oldError, float temp) const;
|
bool AcceptNewEndpointError(double newError, double oldError, float t) const;
|
||||||
|
|
||||||
// This function figures out the best compression for the single color p, and places
|
// This function figures out the best compression for the single color p, and
|
||||||
// the endpoints in p1 and p2. If the compression mode supports p-bits, then we
|
// places the endpoints in p1 and p2. If the compression mode supports p-bits,
|
||||||
// choose the best p-bit combo and return it as well.
|
// 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;
|
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
|
// Compress the cluster using a generalized cluster fit. This figures out the
|
||||||
// assuming that we have no alpha.
|
// proper endpoints assuming that we have no alpha.
|
||||||
double CompressCluster(const RGBACluster &cluster, RGBAVector &p1, RGBAVector &p2, int *bestIndices, int &bestPbitCombo) const;
|
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
|
// Compress the non-opaque cluster using a generalized cluster fit, and place
|
||||||
// endpoints within p1 and p2. The color indices and alpha indices are computed as well.
|
// the endpoints within p1 and p2. The color indices and alpha indices are
|
||||||
double CompressCluster(const RGBACluster &cluster, RGBAVector &p1, RGBAVector &p2, int *bestIndices, int *alphaIndices) const;
|
// 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
|
// This function takes two endpoints in the continuous domain (as floats) and
|
||||||
// to the nearest grid points based on the compression mode (and possible pbit values)
|
// clamps them to the nearest grid points based on the compression mode (and
|
||||||
void ClampEndpointsToGrid(RGBAVector &p1, RGBAVector &p2, int &bestPBitCombo) const;
|
// possible pbit values)
|
||||||
|
void ClampEndpointsToGrid(RGBAVector &p1, RGBAVector &p2,
|
||||||
|
int &bestPBitCombo) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const uint32 kBC7InterpolationValues[4][16][2];
|
extern const uint32 kBC7InterpolationValues[4][16][2];
|
||||||
|
|
||||||
#endif // __BC7_COMPRESSIONMODE_SIMD_H__
|
#endif // BPTCENCODER_SRC_BC7COMPRESSIONMODE_H_
|
||||||
|
@ -1,30 +1,39 @@
|
|||||||
/* FasTC
|
/* 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,
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
* research, and non-profit purposes, without fee, and without a written agreement is hereby granted,
|
* documentation for educational, research, and non-profit purposes, without
|
||||||
* provided that the above copyright notice, this paragraph, and the following four paragraphs appear
|
* fee, and without a written agreement is hereby granted, provided that the
|
||||||
* in all copies.
|
* 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
|
* Permission to incorporate this software into commercial products may be
|
||||||
* authors or the Office of Technology Development at the University of North Carolina at Chapel Hill <otd@unc.edu>.
|
* 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.
|
* This software program and documentation are copyrighted by the University of
|
||||||
* The software program and documentation are supplied "as is," without any accompanying services from the
|
* North Carolina at Chapel Hill. The software program and documentation are
|
||||||
* University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill
|
* supplied "as is," without any accompanying services from the University of
|
||||||
* and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The
|
* North Carolina at Chapel Hill or the authors. The University of North
|
||||||
* end-user understands that the program was developed for research purposes and is advised not to rely
|
* Carolina at Chapel Hill and the authors do not warrant that the operation of
|
||||||
* exclusively on the program for any reason.
|
* 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
|
* IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
||||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE
|
* AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
||||||
* USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
|
* OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
|
||||||
* AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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,
|
* THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
|
||||||
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
* DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
* STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY
|
||||||
* OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
* 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.
|
* ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
*
|
*
|
||||||
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
* Please send all BUG REPORTS to <pavel@cs.unc.edu>.
|
||||||
@ -46,25 +55,26 @@
|
|||||||
//
|
//
|
||||||
// This code has been modified significantly from the original.
|
// This code has been modified significantly from the original.
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright 2011 Intel Corporation
|
// Copyright 2011 Intel Corporation
|
||||||
// All Rights Reserved
|
// All Rights Reserved
|
||||||
//
|
//
|
||||||
// Permission is granted to use, copy, distribute and prepare derivative works of this
|
// Permission is granted to use, copy, distribute and prepare derivative works
|
||||||
// software for any purpose and without fee, provided, that the above copyright notice
|
// of this software for any purpose and without fee, provided, that the above
|
||||||
// and this statement appear in all copies. Intel makes no representations about the
|
// copyright notice and this statement appear in all copies. Intel makes no
|
||||||
// suitability of this software for any purpose. THIS SOFTWARE IS PROVIDED "AS IS."
|
// representations about the suitability of this software for any purpose. THIS
|
||||||
// INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, AND ALL LIABILITY,
|
// SOFTWARE IS PROVIDED "AS IS." INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES,
|
||||||
// INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE,
|
// EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER
|
||||||
// INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE
|
// INDIRECT DAMAGES, FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR
|
||||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Intel does not
|
// INFRINGEMENT OF ANY PROPRIETARY RIGHTS, AND INCLUDING THE WARRANTIES OF
|
||||||
// assume any responsibility for any errors which may appear in this software nor any
|
// 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.
|
// responsibility to update it.
|
||||||
//
|
//
|
||||||
//--------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef __BC7_COMPRESSIONMODE_H__
|
#ifndef BPTCENCODER_SRC_BC7COMPRESSIONMODESIMD_H_
|
||||||
#define __BC7_COMPRESSIONMODE_H__
|
#define BPTCENCODER_SRC_BC7COMPRESSIONMODESIMD_H_
|
||||||
|
|
||||||
#include "TexCompTypes.h"
|
#include "TexCompTypes.h"
|
||||||
#include "RGBAEndpointsSIMD.h"
|
#include "RGBAEndpointsSIMD.h"
|
||||||
@ -73,129 +83,158 @@
|
|||||||
class BitStream;
|
class BitStream;
|
||||||
|
|
||||||
static const int kPBits[4][2] = {
|
static const int kPBits[4][2] = {
|
||||||
{ 0, 0 },
|
{ 0, 0 },
|
||||||
{ 0, 1 },
|
{ 0, 1 },
|
||||||
{ 1, 0 },
|
{ 1, 0 },
|
||||||
{ 1, 1 }
|
{ 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 {
|
class BC7CompressionModeSIMD {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static const int kMaxNumSubsets = 3;
|
static const int kMaxNumSubsets = 3;
|
||||||
static const int kNumModes = 8;
|
static const int kNumModes = 8;
|
||||||
|
|
||||||
enum EPBitType {
|
enum EPBitType {
|
||||||
ePBitType_Shared,
|
ePBitType_Shared,
|
||||||
ePBitType_NotShared,
|
ePBitType_NotShared,
|
||||||
ePBitType_None
|
ePBitType_None
|
||||||
};
|
};
|
||||||
|
|
||||||
BC7CompressionModeSIMD(int mode, double err) : m_EstimatedError(err), m_Attributes(&(kModeAttributes[mode])) { }
|
BC7CompressionModeSIMD(int mode, double err)
|
||||||
~BC7CompressionModeSIMD() { }
|
: m_EstimatedError(err)
|
||||||
|
, m_Attributes(&(kModeAttributes[mode]))
|
||||||
|
{ }
|
||||||
|
~BC7CompressionModeSIMD() { }
|
||||||
|
|
||||||
static int NumUses[8];
|
static int NumUses[8];
|
||||||
static void ResetNumUses() { memset(NumUses, 0, sizeof(NumUses)); }
|
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
|
// This switch controls the quality of the simulated annealing optimizer. We
|
||||||
// more than this many steps regardless of how bad the error is. Higher values will produce
|
// will not make more than this many steps regardless of how bad the error is.
|
||||||
// better quality results but will run slower. Default is 50.
|
// Higher values will produce better quality results but will run slower.
|
||||||
static int MaxAnnealingIterations; // This is a setting
|
// Default is 50.
|
||||||
|
static int MaxAnnealingIterations; // This is a setting
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static struct Attributes {
|
static struct Attributes {
|
||||||
int modeNumber;
|
int modeNumber;
|
||||||
int numPartitionBits;
|
int numPartitionBits;
|
||||||
int numSubsets;
|
int numSubsets;
|
||||||
int numBitsPerIndex;
|
int numBitsPerIndex;
|
||||||
int redChannelPrecision;
|
int redChannelPrecision;
|
||||||
int greenChannelPrecision;
|
int greenChannelPrecision;
|
||||||
int blueChannelPrecision;
|
int blueChannelPrecision;
|
||||||
int alphaChannelPrecision;
|
int alphaChannelPrecision;
|
||||||
EPBitType pbitType;
|
EPBitType pbitType;
|
||||||
} kModeAttributes[kNumModes];
|
} kModeAttributes[kNumModes];
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const Attributes *const m_Attributes;
|
const Attributes *const m_Attributes;
|
||||||
|
|
||||||
int GetModeNumber() const { return m_Attributes->modeNumber; }
|
int GetModeNumber() const { return m_Attributes->modeNumber; }
|
||||||
int GetNumberOfPartitionBits() const { return m_Attributes->numPartitionBits; }
|
int GetNumberOfPartitionBits() const {
|
||||||
int GetNumberOfSubsets() const { return m_Attributes->numSubsets; }
|
return m_Attributes->numPartitionBits;
|
||||||
int GetNumberOfBitsPerIndex() const { return m_Attributes->numBitsPerIndex; }
|
}
|
||||||
|
int GetNumberOfSubsets() const { return m_Attributes->numSubsets; }
|
||||||
|
int GetNumberOfBitsPerIndex() const { return m_Attributes->numBitsPerIndex; }
|
||||||
|
|
||||||
int GetRedChannelPrecision() const { return m_Attributes->redChannelPrecision; }
|
int GetRedChannelPrecision() const {
|
||||||
int GetGreenChannelPrecision() const { return m_Attributes->greenChannelPrecision; }
|
return m_Attributes->redChannelPrecision;
|
||||||
int GetBlueChannelPrecision() const { return m_Attributes->blueChannelPrecision; }
|
}
|
||||||
int GetAlphaChannelPrecision() const { return m_Attributes->alphaChannelPrecision; }
|
|
||||||
|
|
||||||
EPBitType GetPBitType() const { return m_Attributes->pbitType; }
|
int GetGreenChannelPrecision() const {
|
||||||
|
return m_Attributes->greenChannelPrecision;
|
||||||
|
}
|
||||||
|
|
||||||
// !SPEED! Add this to the attributes lookup table
|
int GetBlueChannelPrecision() const {
|
||||||
void GetQuantizationMask(__m128i &mask) const {
|
return m_Attributes->blueChannelPrecision;
|
||||||
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 GetNumPbitCombos() const {
|
int GetAlphaChannelPrecision() const {
|
||||||
switch(GetPBitType()) {
|
return m_Attributes->alphaChannelPrecision;
|
||||||
case ePBitType_Shared: return 2;
|
}
|
||||||
case ePBitType_NotShared: return 4;
|
|
||||||
default:
|
|
||||||
case ePBitType_None: return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const int *GetPBitCombo(int idx) const {
|
EPBitType GetPBitType() const { return m_Attributes->pbitType; }
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double OptimizeEndpointsForCluster(const RGBAClusterSIMD &cluster, RGBAVectorSIMD &p1, RGBAVectorSIMD &p2, __m128i *bestIndices, int &bestPbitCombo) const;
|
|
||||||
|
|
||||||
struct VisitedState {
|
// !SPEED! Add this to the attributes lookup table
|
||||||
RGBAVectorSIMD p1;
|
void GetQuantizationMask(__m128i &mask) const {
|
||||||
RGBAVectorSIMD p2;
|
const int maskSeed = 0x80000000;
|
||||||
int pBitCombo;
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void PickBestNeighboringEndpoints(
|
int GetNumPbitCombos() const {
|
||||||
const RGBAClusterSIMD &cluster,
|
switch(GetPBitType()) {
|
||||||
const RGBAVectorSIMD &p1, const RGBAVectorSIMD &p2,
|
case ePBitType_Shared: return 2;
|
||||||
const int curPbitCombo,
|
case ePBitType_NotShared: return 4;
|
||||||
RGBAVectorSIMD &np1, RGBAVectorSIMD &np2,
|
default:
|
||||||
int &nPbitCombo,
|
case ePBitType_None: return 1;
|
||||||
const __m128 &stepVec
|
}
|
||||||
) const;
|
}
|
||||||
|
|
||||||
bool AcceptNewEndpointError(float newError, float oldError, float temp) 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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double CompressSingleColor(const RGBAVectorSIMD &p, RGBAVectorSIMD &p1, RGBAVectorSIMD &p2, int &bestPbitCombo) const;
|
double OptimizeEndpointsForCluster(const RGBAClusterSIMD &cluster,
|
||||||
double CompressCluster(const RGBAClusterSIMD &cluster, RGBAVectorSIMD &p1, RGBAVectorSIMD &p2, __m128i *bestIndices, int &bestPbitCombo) const;
|
RGBAVectorSIMD &p1, RGBAVectorSIMD &p2,
|
||||||
|
__m128i *bestIndices,
|
||||||
|
int &bestPbitCombo) const;
|
||||||
|
|
||||||
void ClampEndpointsToGrid(RGBAVectorSIMD &p1, RGBAVectorSIMD &p2, int &bestPBitCombo) const;
|
struct VisitedState {
|
||||||
|
RGBAVectorSIMD p1;
|
||||||
|
RGBAVectorSIMD p2;
|
||||||
|
int pBitCombo;
|
||||||
|
};
|
||||||
|
|
||||||
int GetSubsetForIndex(int idx, const int shapeIdx) const;
|
void PickBestNeighboringEndpoints(
|
||||||
int GetAnchorIndexForSubset(int subset, const int shapeIdx) const;
|
const RGBAClusterSIMD &cluster,
|
||||||
|
const RGBAVectorSIMD &p1, const RGBAVectorSIMD &p2,
|
||||||
|
const int curPbitCombo,
|
||||||
|
RGBAVectorSIMD &np1, RGBAVectorSIMD &np2,
|
||||||
|
int &nPbitCombo,
|
||||||
|
const __m128 &stepVec
|
||||||
|
) const;
|
||||||
|
|
||||||
double GetEstimatedError() const { return m_EstimatedError; }
|
bool AcceptNewEndpointError(float newError, float oldError, float temp) const;
|
||||||
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 __m128i kBC7InterpolationValuesSIMD[4][16][2];
|
||||||
extern const uint32 kBC7InterpolationValuesScalar[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
Loading…
Reference in New Issue
Block a user