//===================================================================== // Copyright (c) 2007-2016 Advanced Micro Devices, Inc. All rights reserved. // Copyright (c) 2004-2006 ATI Technologies Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files(the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions : // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // /// \file Compressonator.h // //===================================================================== #ifndef COMPRESSONATOR_H #define COMPRESSONATOR_H #include #include #include #include "../UseDefinitions.h" #ifndef ASPM_GPU namespace CMP { // Basic types. typedef uint8_t BYTE; typedef uint16_t WORD; typedef uint32_t DWORD; typedef int32_t LONG; typedef bool BOOL; #ifdef _LINUX typedef int32_t* DWORD_PTR; #else typedef size_t DWORD_PTR; #endif typedef unsigned int UINT; } // namespace CMP typedef CMP::DWORD CMP_DWORD; ///< A 32-bit unsigned integer format. typedef CMP::WORD CMP_WORD; ///< A 16-bit unsigned integer format. typedef CMP::BOOL CMP_BOOL; ///< A 32-bit integer boolean format. typedef CMP::DWORD_PTR CMP_DWORD_PTR; typedef CMP::BYTE CMP_BYTE; ///< An 8-bit unsigned integer format. typedef char CMP_CHAR; ///< An 8-bit signed char format. typedef float CMP_FLOAT; ///< A 32-bit signed float format. typedef short CMP_HALFSHORT; ///< A 16-bit short Half format. This should be unsigned!! typedef long CMP_LONG; typedef int CMP_INT; typedef unsigned int CMP_UINT; typedef double CMP_DOUBLE; typedef void CMP_VOID; typedef std::vector CMP_VEC8; #define AMD_COMPRESS_VERSION_MAJOR 3 ///< The major version number of this release. #define AMD_COMPRESS_VERSION_MINOR 2 ///< The minor version number of this release. #if defined(WIN32) || defined(_WIN64) #define CMP_API __cdecl #else #define CMP_API #endif // Texture format. typedef enum { CMP_FORMAT_Unknown = 0, // Undefined texture format. // Channel Component formats -------------------------------------------------------------------------------- CMP_FORMAT_ARGB_8888 , // ARGB format with 8-bit fixed channels. CMP_FORMAT_ABGR_8888 , // ABGR format with 8-bit fixed channels. CMP_FORMAT_RGBA_8888 , // RGBA format with 8-bit fixed channels. CMP_FORMAT_BGRA_8888 , // BGRA format with 8-bit fixed channels. CMP_FORMAT_RGB_888 , // RGB format with 8-bit fixed channels. CMP_FORMAT_BGR_888 , // BGR format with 8-bit fixed channels. CMP_FORMAT_RG_8 , // Two component format with 8-bit fixed channels. CMP_FORMAT_R_8 , // Single component format with 8-bit fixed channels. CMP_FORMAT_ARGB_2101010 , // ARGB format with 10-bit fixed channels for color & a 2-bit fixed channel for alpha. CMP_FORMAT_ARGB_16 , // ARGB format with 16-bit fixed channels. CMP_FORMAT_ABGR_16 , // ABGR format with 16-bit fixed channels. CMP_FORMAT_RGBA_16 , // RGBA format with 16-bit fixed channels. CMP_FORMAT_BGRA_16 , // BGRA format with 16-bit fixed channels. CMP_FORMAT_RG_16 , // Two component format with 16-bit fixed channels. CMP_FORMAT_R_16 , // Single component format with 16-bit fixed channels. CMP_FORMAT_RGBE_32F , // RGB format with 9-bit floating point each channel and shared 5 bit exponent CMP_FORMAT_ARGB_16F , // ARGB format with 16-bit floating-point channels. CMP_FORMAT_ABGR_16F , // ABGR format with 16-bit floating-point channels. CMP_FORMAT_RGBA_16F , // RGBA format with 16-bit floating-point channels. CMP_FORMAT_BGRA_16F , // BGRA format with 16-bit floating-point channels. CMP_FORMAT_RG_16F , // Two component format with 16-bit floating-point channels. CMP_FORMAT_R_16F , // Single component with 16-bit floating-point channels. CMP_FORMAT_ARGB_32F , // ARGB format with 32-bit floating-point channels. CMP_FORMAT_ABGR_32F , // ABGR format with 32-bit floating-point channels. CMP_FORMAT_RGBA_32F , // RGBA format with 32-bit floating-point channels. CMP_FORMAT_BGRA_32F , // BGRA format with 32-bit floating-point channels. CMP_FORMAT_RGB_32F , // RGB format with 32-bit floating-point channels. CMP_FORMAT_BGR_32F , // BGR format with 32-bit floating-point channels. CMP_FORMAT_RG_32F , // Two component format with 32-bit floating-point channels. CMP_FORMAT_R_32F , // Single component with 32-bit floating-point channels. // Compression formats ----------------------------------------------------------------------------------- CMP_FORMAT_ASTC , // ASTC (Adaptive Scalable Texture Compression) open texture compression standard CMP_FORMAT_ATI1N , // Single component compression format using the same technique as DXT5 alpha. Four bits per pixel. CMP_FORMAT_ATI2N , // Two component compression format using the same technique as DXT5 alpha. Designed for compression of tangent space normal maps. Eight bits per pixel. CMP_FORMAT_ATI2N_XY , // Two component compression format using the same technique as DXT5 alpha. The same as ATI2N but with the channels swizzled. Eight bits per pixel. CMP_FORMAT_ATI2N_DXT5 , // ATI2N like format using DXT5. Intended for use on GPUs that do not natively support ATI2N. Eight bits per pixel. CMP_FORMAT_ATC_RGB , // CMP - a compressed RGB format. CMP_FORMAT_ATC_RGBA_Explicit , // CMP - a compressed ARGB format with explicit alpha. CMP_FORMAT_ATC_RGBA_Interpolated, // CMP - a compressed ARGB format with interpolated alpha. CMP_FORMAT_BC1 , // A four component opaque (or 1-bit alpha) compressed texture format for Microsoft DirectX10. Identical to DXT1. Four bits per pixel. CMP_FORMAT_BC2 , // A four component compressed texture format with explicit alpha for Microsoft DirectX10. Identical to DXT3. Eight bits per pixel. CMP_FORMAT_BC3 , // A four component compressed texture format with interpolated alpha for Microsoft DirectX10. Identical to DXT5. Eight bits per pixel. CMP_FORMAT_BC4 , // A single component compressed texture format for Microsoft DirectX10. Identical to ATI1N. Four bits per pixel. CMP_FORMAT_BC5 , // A two component compressed texture format for Microsoft DirectX10. Identical to ATI2N_XY. Eight bits per pixel. CMP_FORMAT_BC6H , // BC6H compressed texture format (UF) CMP_FORMAT_BC6H_SF , // BC6H compressed texture format (SF) CMP_FORMAT_BC7 , // BC7 compressed texture format CMP_FORMAT_DXT1 , // An DXTC compressed texture matopaque (or 1-bit alpha). Four bits per pixel. CMP_FORMAT_DXT3 , // DXTC compressed texture format with explicit alpha. Eight bits per pixel. CMP_FORMAT_DXT5 , // DXTC compressed texture format with interpolated alpha. Eight bits per pixel. CMP_FORMAT_DXT5_xGBR , // DXT5 with the red component swizzled into the alpha channel. Eight bits per pixel. CMP_FORMAT_DXT5_RxBG , // swizzled DXT5 format with the green component swizzled into the alpha channel. Eight bits per pixel. CMP_FORMAT_DXT5_RBxG , // swizzled DXT5 format with the green component swizzled into the alpha channel & the blue component swizzled into the green channel. Eight bits per pixel. CMP_FORMAT_DXT5_xRBG , // swizzled DXT5 format with the green component swizzled into the alpha channel & the red component swizzled into the green channel. Eight bits per pixel. CMP_FORMAT_DXT5_RGxB , // swizzled DXT5 format with the blue component swizzled into the alpha channel. Eight bits per pixel. CMP_FORMAT_DXT5_xGxR , // two-component swizzled DXT5 format with the red component swizzled into the alpha channel & the green component in the green channel. Eight bits per pixel. CMP_FORMAT_ETC_RGB , // ETC GL_COMPRESSED_RGB8_ETC2 backward compatible CMP_FORMAT_ETC2_RGB , // ETC2 GL_COMPRESSED_RGB8_ETC2 CMP_FORMAT_ETC2_SRGB , // ETC2 GL_COMPRESSED_SRGB8_ETC2 CMP_FORMAT_ETC2_RGBA , // ETC2 GL_COMPRESSED_RGBA8_ETC2_EAC CMP_FORMAT_ETC2_RGBA1 , // ETC2 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 CMP_FORMAT_ETC2_SRGBA , // ETC2 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC CMP_FORMAT_ETC2_SRGBA1 , // ETC2 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 CMP_FORMAT_PVRTC , // Transcoder formats - ------------------------------------------------------------ CMP_FORMAT_GTC , ///< GTC Fast Gradient Texture Compressor CMP_FORMAT_BASIS , ///< BASIS compression // End of list CMP_FORMAT_MAX = CMP_FORMAT_BASIS } CMP_FORMAT; /// Compress error codes typedef enum { CMP_OK = 0, // Ok. CMP_ABORTED, // The conversion was aborted. CMP_ERR_INVALID_SOURCE_TEXTURE, // The source texture is invalid. CMP_ERR_INVALID_DEST_TEXTURE, // The destination texture is invalid. CMP_ERR_UNSUPPORTED_SOURCE_FORMAT, // The source format is not a supported format. CMP_ERR_UNSUPPORTED_DEST_FORMAT, // The destination format is not a supported format. CMP_ERR_UNSUPPORTED_GPU_ASTC_DECODE, // The gpu hardware is not supported. CMP_ERR_UNSUPPORTED_GPU_BASIS_DECODE, // The gpu hardware is not supported. CMP_ERR_SIZE_MISMATCH, // The source and destination texture sizes do not match. CMP_ERR_UNABLE_TO_INIT_CODEC, // Compressonator was unable to initialize the codec needed for conversion. CMP_ERR_UNABLE_TO_INIT_DECOMPRESSLIB, // GPU_Decode Lib was unable to initialize the codec needed for decompression . CMP_ERR_UNABLE_TO_INIT_COMPUTELIB, // Compute Lib was unable to initialize the codec needed for compression. CMP_ERR_CMP_DESTINATION, // Error in compressing destination texture CMP_ERR_MEM_ALLOC_FOR_MIPSET, // Memory Error: allocating MIPSet compression level data buffer CMP_ERR_UNKNOWN_DESTINATION_FORMAT, // The destination Codec Type is unknown! In SDK refer to GetCodecType() CMP_ERR_FAILED_HOST_SETUP, // Failed to setup Host for processing CMP_ERR_PLUGIN_FILE_NOT_FOUND, // The required plugin library was not found CMP_ERR_UNABLE_TO_LOAD_FILE, // The requested file was not loaded CMP_ERR_UNABLE_TO_CREATE_ENCODER, // Request to create an encoder failed CMP_ERR_UNABLE_TO_LOAD_ENCODER, // Unable to load an encode library CMP_ERR_NOSHADER_CODE_DEFINED, // No shader code is available for the requested framework CMP_ERR_GPU_DOESNOT_SUPPORT_COMPUTE, // The GPU device selected does not support compute CMP_ERR_NOPERFSTATS, // No Performance Stats are available CMP_ERR_GENERIC // An unknown error occurred. } CMP_ERROR; //======================================== Interfaces used in v3.2 and higher (Host Libs) ======================================== /// An enum selecting the different GPU driver types. typedef enum { CMP_UNKNOWN = 0, CMP_CPU = 1, //Use CPU Only, encoders defined CMP_CPUEncode or Compressonator lib will be used CMP_HPC = 2, //Use CPU High Performance Compute Encoders with SPMD support defined in CMP_CPUEncode) //#ifdef USE_GPUEncoders CMP_GPU = 3, //Use GPU Kernel Encoders to compress textures using Default GPU Framework auto set by the codecs been used CMP_GPU_OCL = 4, //Use GPU Kernel Encoders to compress textures using OpenCL Framework CMP_GPU_DXC = 5, //Use GPU Kernel Encoders to compress textures using DirectX Compute Framework CMP_GPU_VLK = 6 //Use GPU Kernel Encoders to compress textures using Vulkan Compute Framework //#endif } CMP_Compute_type; struct ComputeOptions { //public: data settings bool force_rebuild; ///255. // Pixel data in the block should be arranged in row-major order // For three-component input images the 4th component (BC7_COMP_ALPHA) should be set to 255 for // all pixels to ensure optimal encoding // // For BC6H: // Input is expected to be a single 16 element block containing 4 components in Half-Float format (16bit). // Pixel data in the block should be arranged in row-major order. // the 4th component should be set to 0, since Alpha is not supported in BC6H // BC_ERROR CMP_API CMP_EncodeBC7Block(BC7BlockEncoder* encoder, double in[BC_BLOCK_PIXELS][BC_COMPONENT_COUNT], CMP_BYTE* out); BC_ERROR CMP_API CMP_EncodeBC6HBlock(BC6HBlockEncoder* encoder, CMP_FLOAT in[BC_BLOCK_PIXELS][BC_COMPONENT_COUNT], CMP_BYTE* out); // // CMP_DecodeBC6HBlock() - Decode a BC6H block to an uncompressed output // CMP_DecodeBC7Block() - Decode a BC7 block to an uncompressed output // // This function takes a pointer to an encoded BC block as input, decodes it and writes out the result // // BC_ERROR CMP_API CMP_DecodeBC6HBlock(CMP_BYTE* in, CMP_FLOAT out[BC_BLOCK_PIXELS][BC_COMPONENT_COUNT]); BC_ERROR CMP_API CMP_DecodeBC7Block(CMP_BYTE* in, double out[BC_BLOCK_PIXELS][BC_COMPONENT_COUNT]); // // CMP_DestroyBC6HEncoder() - Deletes a previously allocated encoder object // CMP_DestroyBC7Encoder() - Deletes a previously allocated encoder object // // BC_ERROR CMP_API CMP_DestroyBC6HEncoder(BC6HBlockEncoder* encoder); BC_ERROR CMP_API CMP_DestroyBC7Encoder(BC7BlockEncoder* encoder); //================================================================================= // CMP_Feedback_Proc // Feedback function for conversion. // \param[in] fProgress The percentage progress of the texture compression. // \param[in] mipProgress The current MIP level been processed, value of fProgress = mipProgress // \return non-NULL(true) value to abort conversion typedef bool(CMP_API* CMP_Feedback_Proc)(CMP_FLOAT fProgress, CMP_DWORD_PTR pUser1, CMP_DWORD_PTR pUser2); /// Calculates the required buffer size for the specified texture /// \param[in] pTexture A pointer to the texture. /// \return The size of the buffer required to hold the texture data. CMP_DWORD CMP_API CMP_CalculateBufferSize(const CMP_Texture* pTexture); /// Converts the source texture to the destination texture /// This can be compression, decompression or converting between two uncompressed formats. /// \param[in] pSourceTexture A pointer to the source texture. /// \param[in] pDestTexture A pointer to the destination texture. /// \param[in] pOptions A pointer to the compression options - can be NULL. /// \param[in] pFeedbackProc A pointer to the feedback function - can be NULL. /// \return CMP_OK if successful, otherwise the error code. CMP_ERROR CMP_API CMP_ConvertTexture(CMP_Texture* pSourceTexture, CMP_Texture* pDestTexture, const CMP_CompressOptions* pOptions, CMP_Feedback_Proc pFeedbackProc); #ifdef __cplusplus }; #endif //================================================== // API Definitions for Compressonator v3.2 and higher //=================================================== typedef struct { CMP_FLOAT mipProgress; // The percentage progress of the current MIP level texture compression CMP_INT mipLevel; // returns the current MIP level been processed 0..max available for the image CMP_INT cubeFace; // returns the current Cube Face been processed 1..6 } CMP_MIPPROGRESSPARAM; // The structure describing block encoder level settings. typedef struct { unsigned int width; // Width of the encoded texture. unsigned int height; // Height of the encoded texture. unsigned int pitch; // Distance to start of next line.. float quality; // Set the quality used for encoders 0.05 is the lowest and 1.0 for highest. unsigned int format; // Format of the encoder to use: this is a enum set see compressonator.h CMP_FORMAT } CMP_EncoderSetting; #ifdef __cplusplus extern "C" { #endif /// MIP MAP Interfaces CMP_INT CMP_API CMP_CalcMinMipSize(CMP_INT nHeight, CMP_INT nWidth, CMP_INT MipsLevel); CMP_INT CMP_API CMP_GenerateMIPLevels(CMP_MipSet *pMipSet, CMP_INT nMinSize); CMP_ERROR CMP_API CMP_CreateCompressMipSet(CMP_MipSet* pMipSetCMP, CMP_MipSet* pMipSetSRC); /// CMP_MIPFeedback_Proc /// Feedback function for conversion. /// \param[in] fProgress The percentage progress of the texture compression. /// \param[in] mipProgress The current MIP level been processed, value of fProgress = mipProgress /// \return non-NULL(true) value to abort conversion typedef bool(CMP_API* CMP_MIPFeedback_Proc)(CMP_MIPPROGRESSPARAM mipProgress); /// Converts the source texture to the destination texture using MipSets with MIP MAP Levels CMP_ERROR CMP_API CMP_ConvertMipTexture(CMP_MipSet* p_MipSetIn, CMP_MipSet* p_MipSetOut, const CMP_CompressOptions* pOptions, CMP_Feedback_Proc pFeedbackProc); //-------------------------------------------- // CMP_Compute Lib: Texture Encoder Interfaces //-------------------------------------------- CMP_ERROR CMP_API CMP_LoadTexture(const char *sourceFile, CMP_MipSet *pMipSet); CMP_ERROR CMP_API CMP_SaveTexture(const char *destFile, CMP_MipSet *pMipSet); CMP_ERROR CMP_API CMP_ProcessTexture(CMP_MipSet* srcMipSet, CMP_MipSet* dstMipSet, KernelOptions kernelOptions, CMP_Feedback_Proc pFeedbackProc); CMP_ERROR CMP_API CMP_CompressTexture(KernelOptions *options,CMP_MipSet srcMipSet,CMP_MipSet dstMipSet,CMP_Feedback_Proc pFeedback); CMP_VOID CMP_API CMP_Format2FourCC(CMP_FORMAT format, CMP_MipSet *pMipSet); CMP_FORMAT CMP_API CMP_ParseFormat(char* pFormat); CMP_INT CMP_API CMP_NumberOfProcessors(); CMP_VOID CMP_API CMP_FreeMipSet(CMP_MipSet *MipSetIn); CMP_VOID CMP_API CMP_GetMipLevel(CMP_MipLevel **data, const CMP_MipSet* pMipSet, CMP_INT nMipLevel, CMP_INT nFaceOrSlice); CMP_ERROR CMP_API CMP_GetPerformanceStats(KernelPerformanceStats* pPerfStats); CMP_ERROR CMP_API CMP_GetDeviceInfo(KernelDeviceInfo* pDeviceInfo); //-------------------------------------------- // CMP_Compute Lib: Host level interface //-------------------------------------------- CMP_ERROR CMP_API CMP_CreateComputeLibrary(CMP_MipSet *srcTexture, KernelOptions *kernelOptions, void *Reserved); CMP_ERROR CMP_API CMP_DestroyComputeLibrary(CMP_BOOL forceClose); CMP_ERROR CMP_API CMP_SetComputeOptions(ComputeOptions *options); //--------------------------------------------------------- // Generic API to access the core using CMP_EncoderSetting //---------------------------------------------------------- CMP_ERROR CMP_API CMP_CreateBlockEncoder(void **blockEncoder, CMP_EncoderSetting encodeSettings); CMP_ERROR CMP_API CMP_CompressBlock( void **block_encoder,void *SourceTexture, unsigned int sourceStride, void *DestTexture, unsigned int DestStride); CMP_ERROR CMP_API CMP_CompressBlockXY(void **blockEncoder,unsigned int blockx, unsigned int blocky, void *imgSrc, unsigned int sourceStride, void *cmpDst, unsigned int dstStride); void CMP_API CMP_DestroyBlockEncoder(void **blockEncoder); #ifdef __cplusplus }; #endif #endif // ASPM_GPU typedef bool (CMP_API * Codec_Feedback_Proc)(float fProgress, CMP_DWORD_PTR pUser1, CMP_DWORD_PTR pUser2); #endif // COMPRESSONATOR_H