├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── README.md ├── ShaderCompile ├── LZMA.hpp ├── ShaderCompile.cpp ├── basetypes.h ├── cfgprocessor.cpp ├── cfgprocessor.h ├── cmdsink.h ├── d3dxfxc.cpp ├── d3dxfxc.h ├── include │ ├── C │ │ ├── 7z.h │ │ ├── 7zAlloc.c │ │ ├── 7zAlloc.h │ │ ├── 7zArcIn.c │ │ ├── 7zBuf.c │ │ ├── 7zBuf.h │ │ ├── 7zBuf2.c │ │ ├── 7zCrc.c │ │ ├── 7zCrc.h │ │ ├── 7zCrcOpt.c │ │ ├── 7zDec.c │ │ ├── 7zFile.c │ │ ├── 7zFile.h │ │ ├── 7zStream.c │ │ ├── 7zTypes.h │ │ ├── 7zVersion.h │ │ ├── 7zVersion.rc │ │ ├── Aes.c │ │ ├── Aes.h │ │ ├── AesOpt.c │ │ ├── Alloc.c │ │ ├── Alloc.h │ │ ├── Bcj2.c │ │ ├── Bcj2.h │ │ ├── Bra.c │ │ ├── Bra.h │ │ ├── Bra86.c │ │ ├── BraIA64.c │ │ ├── Compiler.h │ │ ├── CpuArch.c │ │ ├── CpuArch.h │ │ ├── Delta.c │ │ ├── Delta.h │ │ ├── LzFind.c │ │ ├── LzFind.h │ │ ├── LzFindMt.c │ │ ├── LzFindMt.h │ │ ├── LzHash.h │ │ ├── Lzma2Dec.c │ │ ├── Lzma2Dec.h │ │ ├── Lzma2Enc.c │ │ ├── Lzma2Enc.h │ │ ├── Lzma86.h │ │ ├── Lzma86Dec.c │ │ ├── Lzma86Enc.c │ │ ├── LzmaDec.c │ │ ├── LzmaDec.h │ │ ├── LzmaEnc.c │ │ ├── LzmaEnc.h │ │ ├── LzmaLib.c │ │ ├── LzmaLib.h │ │ ├── MtCoder.c │ │ ├── MtCoder.h │ │ ├── Ppmd.h │ │ ├── Ppmd7.c │ │ ├── Ppmd7.h │ │ ├── Ppmd7Dec.c │ │ ├── Ppmd7Enc.c │ │ ├── Precomp.h │ │ ├── RotateDefs.h │ │ ├── Sha256.c │ │ ├── Sha256.h │ │ ├── Sort.c │ │ ├── Sort.h │ │ ├── Threads.c │ │ ├── Threads.h │ │ ├── Xz.c │ │ ├── Xz.h │ │ ├── XzCrc64.c │ │ ├── XzCrc64.h │ │ ├── XzCrc64Opt.c │ │ ├── XzDec.c │ │ ├── XzEnc.c │ │ ├── XzEnc.h │ │ └── XzIn.c │ ├── CRC32.hpp │ ├── ezOptionParser.hpp │ ├── robin_hood.h │ └── termcolor │ │ ├── style.hpp │ │ └── termcolor.hpp ├── movingaverage.hpp ├── shader_vcs_version.h ├── shaderparser.cpp ├── shaderparser.h ├── strmanip.hpp ├── termcolors.hpp ├── utlbuffer.cpp ├── utlbuffer.h ├── utlintrusivelist.h ├── utlmemory.h └── utlnodehash.h ├── azure-pipelines.yml └── scripts ├── bin └── process_shaders.ps1 ├── headers ├── VS2013 │ └── cshader.h └── cshader.h └── stdshaders └── buildshaders.bat /.gitignore: -------------------------------------------------------------------------------- 1 | *.user 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "shared/gsl"] 2 | path = shared/gsl 3 | url = https://github.com/microsoft/GSL.git 4 | [submodule "shared/re2"] 5 | path = shared/re2 6 | url = https://github.com/google/re2.git 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.7...3.19) 2 | 3 | if(${CMAKE_VERSION} VERSION_LESS 3.12) 4 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 5 | endif() 6 | 7 | project(ShaderCompile CXX) 8 | 9 | option(RE2_BUILD_TESTING "" OFF) 10 | 11 | add_subdirectory(shared/re2) 12 | add_subdirectory(shared/gsl) 13 | 14 | set(CMAKE_CXX_STANDARD 20) 15 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 16 | set(CMAKE_CXX_EXTENSIONS OFF) 17 | 18 | set(SRC 19 | ShaderCompile/cfgprocessor.cpp 20 | ShaderCompile/d3dxfxc.cpp 21 | ShaderCompile/ShaderCompile.cpp 22 | ShaderCompile/shaderparser.cpp 23 | ShaderCompile/utlbuffer.cpp 24 | ) 25 | 26 | add_executable(ShaderCompile ${SRC}) 27 | target_link_libraries(ShaderCompile PRIVATE re2::re2 Microsoft.GSL::GSL) 28 | include_directories(ShaderCompile/include shared/re2) 29 | 30 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus") 31 | set_property(TARGET ShaderCompile PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") 32 | set_property(TARGET re2 PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") 33 | target_compile_definitions(ShaderCompile PRIVATE _ITERATOR_DEBUG_LEVEL=0) 34 | target_compile_definitions(re2 PRIVATE _ITERATOR_DEBUG_LEVEL=0) 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ShaderCompile 2 | Standalone shadercompile, that doesn't depend on valve libraries and supports x64. Also removes dependencies 3 | on external tools (no perl or DxSdk) 4 | ## Usage 5 | ``` 6 | ShaderCompile.exe [OPTIONS] -ver n -shaderdir src_dir shader.fxc 7 | ``` 8 | ## Options 9 | ``` 10 | -ver ARG Sets shader version, required 11 | -shaderpath ARG Base path for shaders, required 12 | -crc Calculate crc for shader 13 | -dynamic Generate only header 14 | -force Skip crc check during compilation 15 | -threads ARG Number of threads used, defaults to core count 16 | 17 | -h, -help Shows help 18 | -verbose Verbose file cache and final shader info 19 | -verbose2 Verbose compile commands 20 | -verbose_preprocessor Enables preprocessor debug printing 21 | 22 | -disable-optimization, /Od Disables shader optimization 23 | -disable-preshader, /Op Disables preshader generation 24 | -no-flow-control, /Gfa Directs the compiler to not use flow-control constructs where possible 25 | -prefer-flow-control, /Gfp Directs the compiler to use flow-control constructs where possible 26 | -partial-precision, /Gpp Compiles shader with partial precission 27 | -no-validation, /Vd Skips shader validation 28 | ``` 29 | ## Shader model version support 30 | All shader models starting from PS2.b/VS2.0 31 | 32 | 33 | Valid options for `-ver` 34 | ``` 35 | 20 ps2b/vs20 36 | 30 ps30/vs30 37 | ``` 38 | ## Getting started 39 | This assumes you have "clean" Source SDK2013 project. 40 | 1. In `game_shader_dx9_base.vpc` replace `$AdditionalIncludeDirectories "$BASE;fxctmp9;vshtmp9;"` 41 | with `$AdditionalIncludeDirectories "$BASE;include"` , shader headers will be now located in more sensible place 42 | 2. Replace `cshader.h` in public/shaderlib with one from this repo, if you are using VS2013 compiler use the one from 43 | VS2013 folder 44 | 3. Place `ShaderCompile.exe` and `process_shaders.ps1` to devtools/bin folder where `vpc.exe` is located 45 | 4. Replace `buildshaders.bat` with one from this repo 46 | 5. In `buildsdkshaders.bat`, remove from all commands `-dx9_30` so 47 | ```batch 48 | %BUILD_SHADER% stdshader_dx9_30 -game %GAMEDIR% -source %SOURCEDIR% -dx9_30 -force30 49 | ``` 50 | looks like 51 | ```batch 52 | %BUILD_SHADER% stdshader_dx9_30 -game %GAMEDIR% -source %SOURCEDIR% -force30 53 | ``` 54 | 6. Optionally remove all perl scripts for compiling shaders from devtools/bin, as they will be never used again 55 | ``` 56 | buildshaderlist.pl 57 | checkshaderchecksums.pl 58 | copyshaderincfiles.pl 59 | copyshaders.pl 60 | fxc_prep.pl 61 | psh_prep.pl 62 | shaderinfo.pl 63 | uniqifylist.pl 64 | updateshaders.pl 65 | valve_perl_helpers.pl 66 | vsh_prep.pl 67 | ``` -------------------------------------------------------------------------------- /ShaderCompile/LZMA.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace LZMA 4 | { 5 | static constexpr int LZMA_ID = ( 'A' << 24 ) + ( 'M' << 16 ) + ( 'Z' << 8 ) + 'L'; 6 | #pragma pack( 1 ) 7 | struct lzma_header_t 8 | { 9 | uint32_t id; 10 | uint32_t actualSize; // always little endian 11 | uint32_t lzmaSize; // always little endian 12 | uint8_t properties[5]; 13 | }; 14 | #pragma pack() 15 | static_assert( sizeof( lzma_header_t ) == 17 ); 16 | 17 | static inline void* SzAlloc( void*, size_t size ) 18 | { 19 | return malloc( size ); 20 | } 21 | static inline void SzFree( void*, void* address ) 22 | { 23 | free( address ); 24 | } 25 | static ISzAlloc g_Alloc = { SzAlloc, SzFree }; 26 | 27 | static inline SRes LzmaEncode( const Byte* inBuffer, size_t inSize, Byte* outBuffer, size_t outSize, size_t* outSizeProcessed ) 28 | { 29 | class CInStreamRam : public ISeqInStream 30 | { 31 | const Byte* Data; 32 | size_t Size; 33 | size_t Pos; 34 | 35 | SRes DoRead( void* buf, size_t* size ) 36 | { 37 | size_t inSize = *size; 38 | size_t remain = Size - Pos; 39 | if ( inSize > remain ) 40 | inSize = remain; 41 | 42 | for ( size_t i = 0; i < inSize; ++i ) 43 | reinterpret_cast( buf )[i] = Data[Pos + i]; 44 | 45 | Pos += inSize; 46 | *size = inSize; 47 | return SZ_OK; 48 | } 49 | 50 | static SRes StaticRead( void* p, void* buf, size_t* size ) 51 | { 52 | return reinterpret_cast( p )->DoRead( buf, size ); 53 | } 54 | 55 | public: 56 | CInStreamRam( const Byte* data, size_t size ) 57 | { 58 | Data = data; 59 | Size = size; 60 | Pos = 0; 61 | Read = StaticRead; 62 | } 63 | }; 64 | 65 | class COutStreamRam : public ISeqOutStream 66 | { 67 | size_t Size; 68 | 69 | static size_t StaticWrite( void* p, const void* buf, size_t size ) 70 | { 71 | return reinterpret_cast( p )->DoWrite( buf, size ); 72 | } 73 | 74 | public: 75 | Byte* Data; 76 | size_t Pos; 77 | bool Overflow; 78 | 79 | COutStreamRam( Byte* data, size_t size ) 80 | { 81 | Data = data; 82 | Size = size; 83 | Pos = 0; 84 | Overflow = false; 85 | Write = StaticWrite; 86 | } 87 | 88 | size_t DoWrite( const void* buf, size_t size ) 89 | { 90 | size_t i; 91 | for ( i = 0; i < size && Pos < Size; ++i ) 92 | Data[Pos++] = reinterpret_cast( buf )[i]; 93 | if ( i != size ) 94 | Overflow = true; 95 | return i; 96 | } 97 | }; 98 | 99 | // Based on Encode helper in SDK/LzmaUtil 100 | *outSizeProcessed = 0; 101 | 102 | const size_t kMinDestSize = 13; 103 | if ( outSize < kMinDestSize ) 104 | return SZ_ERROR_FAIL; 105 | 106 | CLzmaEncHandle enc; 107 | SRes res; 108 | CLzmaEncProps props; 109 | 110 | enc = LzmaEnc_Create( &g_Alloc ); 111 | if ( !enc ) 112 | return SZ_ERROR_FAIL; 113 | 114 | LzmaEncProps_Init( &props ); 115 | res = LzmaEnc_SetProps( enc, &props ); 116 | 117 | if ( res != SZ_OK ) 118 | return res; 119 | 120 | COutStreamRam outStream( outBuffer, outSize ); 121 | 122 | Byte header[LZMA_PROPS_SIZE + 8]; 123 | size_t headerSize = LZMA_PROPS_SIZE; 124 | 125 | res = LzmaEnc_WriteProperties( enc, header, &headerSize ); 126 | if ( res != SZ_OK ) 127 | return res; 128 | 129 | // Uncompressed size after properties in header 130 | for ( int i = 0; i < 8; i++ ) 131 | header[headerSize++] = static_cast( inSize >> ( 8 * i ) ); 132 | 133 | if ( outStream.DoWrite( header, headerSize ) != headerSize ) 134 | res = SZ_ERROR_WRITE; 135 | else if ( res == SZ_OK ) 136 | { 137 | CInStreamRam inStream( inBuffer, inSize ); 138 | res = LzmaEnc_Encode( enc, &outStream, &inStream, nullptr, &g_Alloc, &g_Alloc ); 139 | 140 | if ( outStream.Overflow ) 141 | res = SZ_ERROR_FAIL; 142 | else 143 | *outSizeProcessed = outStream.Pos; 144 | } 145 | 146 | LzmaEnc_Destroy( enc, &g_Alloc, &g_Alloc ); 147 | 148 | return res; 149 | } 150 | 151 | static inline uint8_t* Compress( uint8_t* pInput, size_t inputSize, size_t* pOutputSize ) 152 | { 153 | *pOutputSize = 0; 154 | 155 | // using same work buffer calcs as the SDK 105% + 64K 156 | size_t outSize = inputSize / 20 * 21 + ( 1 << 16 ); 157 | uint8_t* pOutputBuffer = new uint8_t[outSize]; 158 | if ( !pOutputBuffer ) 159 | return nullptr; 160 | 161 | // compress, skipping past our header 162 | size_t compressedSize; 163 | int result = LzmaEncode( pInput, inputSize, pOutputBuffer + sizeof( lzma_header_t ), outSize - sizeof( lzma_header_t ), &compressedSize ); 164 | if ( result != SZ_OK ) 165 | { 166 | Assert( result == SZ_OK ); 167 | delete[] pOutputBuffer; 168 | return nullptr; 169 | } 170 | 171 | // construct our header, strip theirs 172 | lzma_header_t* pHeader = reinterpret_cast( pOutputBuffer ); 173 | pHeader->id = LZMA_ID; 174 | pHeader->actualSize = gsl::narrow( inputSize ); 175 | pHeader->lzmaSize = gsl::narrow( compressedSize - 13 ); 176 | memcpy( pHeader->properties, pOutputBuffer + sizeof( lzma_header_t ), LZMA_PROPS_SIZE ); 177 | 178 | // shift the compressed data into place 179 | memmove( pOutputBuffer + sizeof( lzma_header_t ), pOutputBuffer + sizeof( lzma_header_t ) + 13, compressedSize - 13 ); 180 | 181 | // final output size is our header plus compressed bits 182 | *pOutputSize = sizeof( lzma_header_t ) + compressedSize - 13; 183 | 184 | return pOutputBuffer; 185 | } 186 | 187 | static inline uint8_t* OpportunisticCompress( uint8_t* pInput, size_t inputSize, size_t* pOutputSize ) 188 | { 189 | uint8_t* pRet = Compress( pInput, inputSize, pOutputSize ); 190 | if ( *pOutputSize >= inputSize ) 191 | { 192 | // compression got worse or stayed the same 193 | delete[] pRet; 194 | return nullptr; 195 | } 196 | 197 | return pRet; 198 | } 199 | } // namespace LZMA -------------------------------------------------------------------------------- /ShaderCompile/ShaderCompile.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SCell555/ShaderCompile/7ea74828baa22df9db5efad67b48abb7c5b3dbed/ShaderCompile/ShaderCompile.cpp -------------------------------------------------------------------------------- /ShaderCompile/basetypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #ifdef _DEBUG 5 | #include 6 | #endif 7 | 8 | #ifdef _DEBUG 9 | #define Assert assert 10 | #else 11 | #define Assert(e) 12 | #endif 13 | 14 | #ifndef WIN32 15 | #ifndef strcpy_s 16 | #define strcpy_s(dst, n, src) strncpy(dst, src, n) 17 | #endif 18 | #ifndef sprintf_s 19 | #define sprintf_s snprintf 20 | #endif 21 | #define _strupr_s strupr 22 | #define _strdup strdup 23 | #endif -------------------------------------------------------------------------------- /ShaderCompile/cfgprocessor.h: -------------------------------------------------------------------------------- 1 | //====== Copyright c 1996-2007, Valve Corporation, All rights reserved. =======// 2 | // 3 | // Purpose: 4 | // 5 | // $NoKeywords: $ 6 | // 7 | //=============================================================================// 8 | 9 | #pragma once 10 | 11 | #include "basetypes.h" 12 | #include "gsl/span" 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace Parser 20 | { 21 | struct Combo; 22 | } 23 | 24 | /* 25 | 26 | Layout of the internal structures is as follows: 27 | 28 | |-------- shader1.fxc ---------||--- shader2.fxc ---||--------- shader3.fxc -----||-... 29 | | 0 s s 3 s s s s 8 s 10 s s s || s s 2 3 4 s s s 8 || 0 s s s 4 s s s 8 9 s s s ||-... 30 | | 0 1 2 3 4 5 6 7 8 9 10 * * * 14 * * * * *20 * * 23 * * *27 * * * * * * *35 * * * 31 | 32 | GetSection( 10 ) -> shader1.fxc 33 | GetSection( 27 ) -> shader3.fxc 34 | 35 | GetNextCombo( 3, 3, 14 ) -> shader1.fxc : ( riCommandNumber = 8, rhCombo = "8" ) 36 | GetNextCombo( 10, 10, 14 ) -> NULL : ( riCommandNumber = 14, rhCombo = NULL ) 37 | GetNextCombo( 22, 8, 36 ) -> shader3.fxc : ( riCommandNumber = 23, rhCombo = "0" ) 38 | GetNextCombo( 29, -1, 36 ) -> shader3.fxc : ( riCommandNumber = 31, rhCombo = "8" ) 39 | 40 | */ 41 | 42 | namespace CfgProcessor 43 | { 44 | struct ShaderConfig 45 | { 46 | std::string name; 47 | std::string main; 48 | std::string_view version; 49 | std::string_view target; 50 | uint32_t centroid_mask; 51 | uint32_t crc32; 52 | std::vector static_c; 53 | std::vector dynamic_c; 54 | std::vector skip; 55 | std::vector includes; 56 | }; 57 | 58 | void SetupConfiguration( const std::vector& configs, const std::filesystem::path& root, bool bVerbose ); 59 | 60 | struct CfgEntryInfo 61 | { 62 | std::string_view m_szName; // Name of the shader, e.g. "shader_ps20b" 63 | std::string_view m_szShaderFileName; // Name of the src file, e.g. "shader_psxx.fxc" 64 | std::string_view m_szShaderVersion; // Version of shader 65 | std::string_view m_szEntryPoint; // Name of main function 66 | uint64_t m_numCombos; // Total possible num of combos, e.g. 1024 67 | uint64_t m_numDynamicCombos; // Num of dynamic combos, e.g. 4 68 | uint64_t m_numStaticCombos; // Num of static combos, e.g. 256 69 | uint64_t m_iCommandStart; // Start command, e.g. 0 70 | uint64_t m_iCommandEnd; // End command, e.g. 1024 71 | int m_nCentroidMask; // Mask of centroid samplers 72 | uint32_t m_nCrc32; 73 | }; 74 | 75 | std::unique_ptr DescribeConfiguration( bool bPrintExpressions ); 76 | 77 | // Working with combos 78 | struct __ComboHandle 79 | { 80 | int unused; 81 | }; 82 | using ComboHandle = __ComboHandle*; 83 | 84 | ComboHandle Combo_GetCombo( uint64_t iCommandNumber ); 85 | void Combo_GetNext( uint64_t& riCommandNumber, ComboHandle& rhCombo, uint64_t iCommandEnd ); 86 | void Combo_FormatCommandHumanReadable( ComboHandle hCombo, gsl::span pchBuffer ); 87 | uint64_t Combo_GetCommandNum( ComboHandle hCombo ) noexcept; 88 | uint64_t Combo_GetComboNum( ComboHandle hCombo ) noexcept; 89 | const CfgEntryInfo* Combo_GetEntryInfo( ComboHandle hCombo ) noexcept; 90 | 91 | struct ComboBuildCommand 92 | { 93 | std::string_view entryPoint; 94 | std::string_view fileName; 95 | std::string_view shaderModel; 96 | std::vector> defines; 97 | }; 98 | ComboBuildCommand Combo_BuildCommand( ComboHandle hCombo ); 99 | 100 | ComboHandle Combo_Alloc( ComboHandle hComboCopyFrom ) noexcept; 101 | void Combo_Assign( ComboHandle hComboDst, ComboHandle hComboSrc ); 102 | void Combo_Free( ComboHandle& rhComboFree ) noexcept; 103 | }; // namespace CfgProcessor -------------------------------------------------------------------------------- /ShaderCompile/cmdsink.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SCell555/ShaderCompile/7ea74828baa22df9db5efad67b48abb7c5b3dbed/ShaderCompile/cmdsink.h -------------------------------------------------------------------------------- /ShaderCompile/d3dxfxc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SCell555/ShaderCompile/7ea74828baa22df9db5efad67b48abb7c5b3dbed/ShaderCompile/d3dxfxc.cpp -------------------------------------------------------------------------------- /ShaderCompile/d3dxfxc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SCell555/ShaderCompile/7ea74828baa22df9db5efad67b48abb7c5b3dbed/ShaderCompile/d3dxfxc.h -------------------------------------------------------------------------------- /ShaderCompile/include/C/7z.h: -------------------------------------------------------------------------------- 1 | /* 7z.h -- 7z interface 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_H 5 | #define __7Z_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define k7zStartHeaderSize 0x20 12 | #define k7zSignatureSize 6 13 | 14 | extern Byte k7zSignature[k7zSignatureSize]; 15 | 16 | typedef struct 17 | { 18 | const Byte *Data; 19 | size_t Size; 20 | } CSzData; 21 | 22 | /* CSzCoderInfo & CSzFolder support only default methods */ 23 | 24 | typedef struct 25 | { 26 | size_t PropsOffset; 27 | UInt32 MethodID; 28 | Byte NumInStreams; 29 | Byte NumOutStreams; 30 | Byte PropsSize; 31 | } CSzCoderInfo; 32 | 33 | typedef struct 34 | { 35 | UInt32 InIndex; 36 | UInt32 OutIndex; 37 | } CSzBindPair; 38 | 39 | #define SZ_NUM_CODERS_IN_FOLDER_MAX 4 40 | #define SZ_NUM_BINDS_IN_FOLDER_MAX 3 41 | #define SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX 4 42 | #define SZ_NUM_CODERS_OUT_STREAMS_IN_FOLDER_MAX 4 43 | 44 | typedef struct 45 | { 46 | UInt32 NumCoders; 47 | UInt32 NumBindPairs; 48 | UInt32 NumPackStreams; 49 | UInt32 MainOutStream; 50 | UInt32 PackStreams[SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX]; 51 | CSzBindPair BindPairs[SZ_NUM_BINDS_IN_FOLDER_MAX]; 52 | CSzCoderInfo Coders[SZ_NUM_CODERS_IN_FOLDER_MAX]; 53 | UInt64 CodersUnpackSizes[SZ_NUM_CODERS_OUT_STREAMS_IN_FOLDER_MAX]; 54 | } CSzFolder; 55 | 56 | /* 57 | typedef struct 58 | { 59 | size_t CodersDataOffset; 60 | size_t UnpackSizeDataOffset; 61 | // UInt32 StartCoderUnpackSizesIndex; 62 | UInt32 StartPackStreamIndex; 63 | // UInt32 IndexOfMainOutStream; 64 | } CSzFolder2; 65 | */ 66 | 67 | SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd, CSzData *sdSizes); 68 | 69 | typedef struct 70 | { 71 | UInt32 Low; 72 | UInt32 High; 73 | } CNtfsFileTime; 74 | 75 | typedef struct 76 | { 77 | Byte *Defs; /* MSB 0 bit numbering */ 78 | UInt32 *Vals; 79 | } CSzBitUi32s; 80 | 81 | typedef struct 82 | { 83 | Byte *Defs; /* MSB 0 bit numbering */ 84 | // UInt64 *Vals; 85 | CNtfsFileTime *Vals; 86 | } CSzBitUi64s; 87 | 88 | #define SzBitArray_Check(p, i) (((p)[(i) >> 3] & (0x80 >> ((i) & 7))) != 0) 89 | 90 | #define SzBitWithVals_Check(p, i) ((p)->Defs && ((p)->Defs[(i) >> 3] & (0x80 >> ((i) & 7))) != 0) 91 | 92 | typedef struct 93 | { 94 | UInt32 NumPackStreams; 95 | UInt32 NumFolders; 96 | 97 | UInt64 *PackPositions; // NumPackStreams + 1 98 | CSzBitUi32s FolderCRCs; 99 | 100 | size_t *FoCodersOffsets; 101 | size_t *FoSizesOffsets; 102 | // UInt32 StartCoderUnpackSizesIndex; 103 | UInt32 *FoStartPackStreamIndex; 104 | 105 | // CSzFolder2 *Folders; // +1 item for sum values 106 | Byte *CodersData; 107 | Byte *UnpackSizesData; 108 | size_t UnpackSizesDataSize; 109 | // UInt64 *CoderUnpackSizes; 110 | } CSzAr; 111 | 112 | 113 | SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex, 114 | ILookInStream *stream, UInt64 startPos, 115 | Byte *outBuffer, size_t outSize, 116 | ISzAlloc *allocMain); 117 | 118 | /* 119 | SzExtract extracts file from archive 120 | 121 | *outBuffer must be 0 before first call for each new archive. 122 | 123 | Extracting cache: 124 | If you need to decompress more than one file, you can send 125 | these values from previous call: 126 | *blockIndex, 127 | *outBuffer, 128 | *outBufferSize 129 | You can consider "*outBuffer" as cache of solid block. If your archive is solid, 130 | it will increase decompression speed. 131 | 132 | If you use external function, you can declare these 3 cache variables 133 | (blockIndex, outBuffer, outBufferSize) as static in that external function. 134 | 135 | Free *outBuffer and set *outBuffer to 0, if you want to flush cache. 136 | */ 137 | 138 | typedef struct 139 | { 140 | CSzAr db; 141 | 142 | UInt64 startPosAfterHeader; 143 | UInt64 dataPos; 144 | 145 | UInt32 NumFiles; 146 | 147 | UInt64 *UnpackPositions; 148 | // Byte *IsEmptyFiles; 149 | Byte *IsDirs; 150 | CSzBitUi32s CRCs; 151 | 152 | CSzBitUi32s Attribs; 153 | // CSzBitUi32s Parents; 154 | CSzBitUi64s MTime; 155 | CSzBitUi64s CTime; 156 | 157 | // UInt32 *FolderStartPackStreamIndex; 158 | UInt32 *FolderStartFileIndex; // + 1 159 | UInt32 *FileIndexToFolderIndexMap; 160 | 161 | size_t *FileNameOffsets; /* in 2-byte steps */ 162 | Byte *FileNames; /* UTF-16-LE */ 163 | } CSzArEx; 164 | 165 | #define SzArEx_IsDir(p, i) (SzBitArray_Check((p)->IsDirs, i)) 166 | 167 | #define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i]) 168 | 169 | void SzArEx_Init(CSzArEx *p); 170 | void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc); 171 | UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder); 172 | int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize); 173 | 174 | /* 175 | if dest == nullptr, the return value specifies the required size of the buffer, 176 | in 16-bit characters, including the null-terminating character. 177 | if dest != nullptr, the return value specifies the number of 16-bit characters that 178 | are written to the dest, including the null-terminating character. */ 179 | 180 | size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest); 181 | 182 | /* 183 | size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex); 184 | UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest); 185 | */ 186 | 187 | SRes SzArEx_Extract( 188 | const CSzArEx *db, 189 | ILookInStream *inStream, 190 | UInt32 fileIndex, /* index of file */ 191 | UInt32 *blockIndex, /* index of solid block */ 192 | Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */ 193 | size_t *outBufferSize, /* buffer size for output buffer */ 194 | size_t *offset, /* offset of stream for required file in *outBuffer */ 195 | size_t *outSizeProcessed, /* size of file in *outBuffer */ 196 | ISzAlloc *allocMain, 197 | ISzAlloc *allocTemp); 198 | 199 | 200 | /* 201 | SzArEx_Open Errors: 202 | SZ_ERROR_NO_ARCHIVE 203 | SZ_ERROR_ARCHIVE 204 | SZ_ERROR_UNSUPPORTED 205 | SZ_ERROR_MEM 206 | SZ_ERROR_CRC 207 | SZ_ERROR_INPUT_EOF 208 | SZ_ERROR_FAIL 209 | */ 210 | 211 | SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, 212 | ISzAlloc *allocMain, ISzAlloc *allocTemp); 213 | 214 | EXTERN_C_END 215 | 216 | #endif 217 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zAlloc.c: -------------------------------------------------------------------------------- 1 | /* 7zAlloc.c -- Allocation functions 2 | 2010-10-29 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "7zAlloc.h" 7 | 8 | /* #define _SZ_ALLOC_DEBUG */ 9 | /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ 10 | 11 | #ifdef _SZ_ALLOC_DEBUG 12 | 13 | #ifdef _WIN32 14 | #include 15 | #endif 16 | 17 | #include 18 | int g_allocCount = 0; 19 | int g_allocCountTemp = 0; 20 | 21 | #endif 22 | 23 | void *SzAlloc(void *p, size_t size) 24 | { 25 | p = p; 26 | if (size == 0) 27 | return 0; 28 | #ifdef _SZ_ALLOC_DEBUG 29 | fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount); 30 | g_allocCount++; 31 | #endif 32 | return malloc(size); 33 | } 34 | 35 | void SzFree(void *p, void *address) 36 | { 37 | p = p; 38 | #ifdef _SZ_ALLOC_DEBUG 39 | if (address != 0) 40 | { 41 | g_allocCount--; 42 | fprintf(stderr, "\nFree; count = %10d", g_allocCount); 43 | } 44 | #endif 45 | free(address); 46 | } 47 | 48 | void *SzAllocTemp(void *p, size_t size) 49 | { 50 | p = p; 51 | if (size == 0) 52 | return 0; 53 | #ifdef _SZ_ALLOC_DEBUG 54 | fprintf(stderr, "\nAlloc_temp %10d bytes; count = %10d", size, g_allocCountTemp); 55 | g_allocCountTemp++; 56 | #ifdef _WIN32 57 | return HeapAlloc(GetProcessHeap(), 0, size); 58 | #endif 59 | #endif 60 | return malloc(size); 61 | } 62 | 63 | void SzFreeTemp(void *p, void *address) 64 | { 65 | p = p; 66 | #ifdef _SZ_ALLOC_DEBUG 67 | if (address != 0) 68 | { 69 | g_allocCountTemp--; 70 | fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp); 71 | } 72 | #ifdef _WIN32 73 | HeapFree(GetProcessHeap(), 0, address); 74 | return; 75 | #endif 76 | #endif 77 | free(address); 78 | } 79 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zAlloc.h: -------------------------------------------------------------------------------- 1 | /* 7zAlloc.h -- Allocation functions 2 | 2010-10-29 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_ALLOC_H 5 | #define __7Z_ALLOC_H 6 | 7 | #include 8 | 9 | void *SzAlloc(void *p, size_t size); 10 | void SzFree(void *p, void *address); 11 | 12 | void *SzAllocTemp(void *p, size_t size); 13 | void SzFreeTemp(void *p, void *address); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zBuf.c: -------------------------------------------------------------------------------- 1 | /* 7zBuf.c -- Byte Buffer 2 | 2013-01-21 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "7zBuf.h" 7 | 8 | void Buf_Init(CBuf *p) 9 | { 10 | p->data = 0; 11 | p->size = 0; 12 | } 13 | 14 | int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc) 15 | { 16 | p->size = 0; 17 | if (size == 0) 18 | { 19 | p->data = 0; 20 | return 1; 21 | } 22 | p->data = (Byte *)alloc->Alloc(alloc, size); 23 | if (p->data != 0) 24 | { 25 | p->size = size; 26 | return 1; 27 | } 28 | return 0; 29 | } 30 | 31 | void Buf_Free(CBuf *p, ISzAlloc *alloc) 32 | { 33 | alloc->Free(alloc, p->data); 34 | p->data = 0; 35 | p->size = 0; 36 | } 37 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zBuf.h: -------------------------------------------------------------------------------- 1 | /* 7zBuf.h -- Byte Buffer 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_BUF_H 5 | #define __7Z_BUF_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | typedef struct 12 | { 13 | Byte *data; 14 | size_t size; 15 | } CBuf; 16 | 17 | void Buf_Init(CBuf *p); 18 | int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc); 19 | void Buf_Free(CBuf *p, ISzAlloc *alloc); 20 | 21 | typedef struct 22 | { 23 | Byte *data; 24 | size_t size; 25 | size_t pos; 26 | } CDynBuf; 27 | 28 | void DynBuf_Construct(CDynBuf *p); 29 | void DynBuf_SeekToBeg(CDynBuf *p); 30 | int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc); 31 | void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc); 32 | 33 | EXTERN_C_END 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zBuf2.c: -------------------------------------------------------------------------------- 1 | /* 7zBuf2.c -- Byte Buffer 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include 7 | 8 | #include "7zBuf.h" 9 | 10 | void DynBuf_Construct(CDynBuf *p) 11 | { 12 | p->data = 0; 13 | p->size = 0; 14 | p->pos = 0; 15 | } 16 | 17 | void DynBuf_SeekToBeg(CDynBuf *p) 18 | { 19 | p->pos = 0; 20 | } 21 | 22 | int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc) 23 | { 24 | if (size > p->size - p->pos) 25 | { 26 | size_t newSize = p->pos + size; 27 | Byte *data; 28 | newSize += newSize / 4; 29 | data = (Byte *)alloc->Alloc(alloc, newSize); 30 | if (data == 0) 31 | return 0; 32 | p->size = newSize; 33 | memcpy(data, p->data, p->pos); 34 | alloc->Free(alloc, p->data); 35 | p->data = data; 36 | } 37 | memcpy(p->data + p->pos, buf, size); 38 | p->pos += size; 39 | return 1; 40 | } 41 | 42 | void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc) 43 | { 44 | alloc->Free(alloc, p->data); 45 | p->data = 0; 46 | p->size = 0; 47 | p->pos = 0; 48 | } 49 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zCrc.c: -------------------------------------------------------------------------------- 1 | /* 7zCrc.c -- CRC32 init 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "7zCrc.h" 7 | #include "CpuArch.h" 8 | 9 | #define kCrcPoly 0xEDB88320 10 | 11 | #ifdef MY_CPU_X86_OR_AMD64 12 | #define CRC_NUM_TABLES 8 13 | UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table); 14 | #elif defined(MY_CPU_LE) 15 | #define CRC_NUM_TABLES 4 16 | #else 17 | #define CRC_NUM_TABLES 5 18 | #define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24)) 19 | UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table); 20 | #endif 21 | 22 | #ifndef MY_CPU_BE 23 | UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table); 24 | #endif 25 | 26 | typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size, const UInt32 *table); 27 | 28 | CRC_FUNC g_CrcUpdate; 29 | UInt32 g_CrcTable[256 * CRC_NUM_TABLES]; 30 | 31 | UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size) 32 | { 33 | return g_CrcUpdate(v, data, size, g_CrcTable); 34 | } 35 | 36 | UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size) 37 | { 38 | return g_CrcUpdate(CRC_INIT_VAL, data, size, g_CrcTable) ^ CRC_INIT_VAL; 39 | } 40 | 41 | void MY_FAST_CALL CrcGenerateTable() 42 | { 43 | UInt32 i; 44 | for (i = 0; i < 256; i++) 45 | { 46 | UInt32 r = i; 47 | unsigned j; 48 | for (j = 0; j < 8; j++) 49 | r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); 50 | g_CrcTable[i] = r; 51 | } 52 | for (; i < 256 * CRC_NUM_TABLES; i++) 53 | { 54 | UInt32 r = g_CrcTable[i - 256]; 55 | g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8); 56 | } 57 | 58 | #ifdef MY_CPU_LE 59 | 60 | g_CrcUpdate = CrcUpdateT4; 61 | 62 | #if CRC_NUM_TABLES == 8 63 | if (!CPU_Is_InOrder()) 64 | g_CrcUpdate = CrcUpdateT8; 65 | #endif 66 | 67 | #else 68 | { 69 | #ifndef MY_CPU_BE 70 | UInt32 k = 1; 71 | if (*(const Byte *)&k == 1) 72 | g_CrcUpdate = CrcUpdateT4; 73 | else 74 | #endif 75 | { 76 | for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--) 77 | { 78 | UInt32 x = g_CrcTable[i - 256]; 79 | g_CrcTable[i] = CRC_UINT32_SWAP(x); 80 | } 81 | g_CrcUpdate = CrcUpdateT1_BeT4; 82 | } 83 | } 84 | #endif 85 | } 86 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zCrc.h: -------------------------------------------------------------------------------- 1 | /* 7zCrc.h -- CRC32 calculation 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_CRC_H 5 | #define __7Z_CRC_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | extern UInt32 g_CrcTable[]; 12 | 13 | /* Call CrcGenerateTable one time before other CRC functions */ 14 | void MY_FAST_CALL CrcGenerateTable(void); 15 | 16 | #define CRC_INIT_VAL 0xFFFFFFFF 17 | #define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL) 18 | #define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 19 | 20 | UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size); 21 | UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size); 22 | 23 | EXTERN_C_END 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zCrcOpt.c: -------------------------------------------------------------------------------- 1 | /* 7zCrcOpt.c -- CRC32 calculation 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "CpuArch.h" 7 | 8 | #define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 9 | 10 | #ifndef MY_CPU_BE 11 | 12 | UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table) 13 | { 14 | const Byte *p = (const Byte *)data; 15 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 16 | v = CRC_UPDATE_BYTE_2(v, *p); 17 | for (; size >= 4; size -= 4, p += 4) 18 | { 19 | v ^= *(const UInt32 *)p; 20 | v = 21 | table[0x300 + (v & 0xFF)] ^ 22 | table[0x200 + ((v >> 8) & 0xFF)] ^ 23 | table[0x100 + ((v >> 16) & 0xFF)] ^ 24 | table[0x000 + ((v >> 24))]; 25 | } 26 | for (; size > 0; size--, p++) 27 | v = CRC_UPDATE_BYTE_2(v, *p); 28 | return v; 29 | } 30 | 31 | UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table) 32 | { 33 | return CrcUpdateT4(v, data, size, table); 34 | } 35 | 36 | #endif 37 | 38 | 39 | #ifndef MY_CPU_LE 40 | 41 | #define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24)) 42 | 43 | UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table) 44 | { 45 | const Byte *p = (const Byte *)data; 46 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 47 | v = CRC_UPDATE_BYTE_2(v, *p); 48 | v = CRC_UINT32_SWAP(v); 49 | table += 0x100; 50 | for (; size >= 4; size -= 4, p += 4) 51 | { 52 | v ^= *(const UInt32 *)p; 53 | v = 54 | table[0x000 + (v & 0xFF)] ^ 55 | table[0x100 + ((v >> 8) & 0xFF)] ^ 56 | table[0x200 + ((v >> 16) & 0xFF)] ^ 57 | table[0x300 + ((v >> 24))]; 58 | } 59 | table -= 0x100; 60 | v = CRC_UINT32_SWAP(v); 61 | for (; size > 0; size--, p++) 62 | v = CRC_UPDATE_BYTE_2(v, *p); 63 | return v; 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zFile.c: -------------------------------------------------------------------------------- 1 | /* 7zFile.c -- File IO 2 | 2009-11-24 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "7zFile.h" 7 | 8 | #ifndef USE_WINDOWS_FILE 9 | 10 | #ifndef UNDER_CE 11 | #include 12 | #endif 13 | 14 | #else 15 | 16 | /* 17 | ReadFile and WriteFile functions in Windows have BUG: 18 | If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1) 19 | from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES 20 | (Insufficient system resources exist to complete the requested service). 21 | Probably in some version of Windows there are problems with other sizes: 22 | for 32 MB (maybe also for 16 MB). 23 | And message can be "Network connection was lost" 24 | */ 25 | 26 | #define kChunkSizeMax (1 << 22) 27 | 28 | #endif 29 | 30 | void File_Construct(CSzFile *p) 31 | { 32 | #ifdef USE_WINDOWS_FILE 33 | p->handle = INVALID_HANDLE_VALUE; 34 | #else 35 | p->file = NULL; 36 | #endif 37 | } 38 | 39 | #if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE) 40 | static WRes File_Open(CSzFile *p, const char *name, int writeMode) 41 | { 42 | #ifdef USE_WINDOWS_FILE 43 | p->handle = CreateFileA(name, 44 | writeMode ? GENERIC_WRITE : GENERIC_READ, 45 | FILE_SHARE_READ, NULL, 46 | writeMode ? CREATE_ALWAYS : OPEN_EXISTING, 47 | FILE_ATTRIBUTE_NORMAL, NULL); 48 | return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError(); 49 | #else 50 | p->file = fopen(name, writeMode ? "wb+" : "rb"); 51 | return (p->file != 0) ? 0 : 52 | #ifdef UNDER_CE 53 | 2; /* ENOENT */ 54 | #else 55 | errno; 56 | #endif 57 | #endif 58 | } 59 | 60 | WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); } 61 | WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); } 62 | #endif 63 | 64 | #ifdef USE_WINDOWS_FILE 65 | static WRes File_OpenW(CSzFile *p, const WCHAR *name, int writeMode) 66 | { 67 | p->handle = CreateFileW(name, 68 | writeMode ? GENERIC_WRITE : GENERIC_READ, 69 | FILE_SHARE_READ, NULL, 70 | writeMode ? CREATE_ALWAYS : OPEN_EXISTING, 71 | FILE_ATTRIBUTE_NORMAL, NULL); 72 | return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError(); 73 | } 74 | WRes InFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 0); } 75 | WRes OutFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 1); } 76 | #endif 77 | 78 | WRes File_Close(CSzFile *p) 79 | { 80 | #ifdef USE_WINDOWS_FILE 81 | if (p->handle != INVALID_HANDLE_VALUE) 82 | { 83 | if (!CloseHandle(p->handle)) 84 | return GetLastError(); 85 | p->handle = INVALID_HANDLE_VALUE; 86 | } 87 | #else 88 | if (p->file != NULL) 89 | { 90 | int res = fclose(p->file); 91 | if (res != 0) 92 | return res; 93 | p->file = NULL; 94 | } 95 | #endif 96 | return 0; 97 | } 98 | 99 | WRes File_Read(CSzFile *p, void *data, size_t *size) 100 | { 101 | size_t originalSize = *size; 102 | if (originalSize == 0) 103 | return 0; 104 | 105 | #ifdef USE_WINDOWS_FILE 106 | 107 | *size = 0; 108 | do 109 | { 110 | DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize; 111 | DWORD processed = 0; 112 | BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL); 113 | data = (void *)((Byte *)data + processed); 114 | originalSize -= processed; 115 | *size += processed; 116 | if (!res) 117 | return GetLastError(); 118 | if (processed == 0) 119 | break; 120 | } 121 | while (originalSize > 0); 122 | return 0; 123 | 124 | #else 125 | 126 | *size = fread(data, 1, originalSize, p->file); 127 | if (*size == originalSize) 128 | return 0; 129 | return ferror(p->file); 130 | 131 | #endif 132 | } 133 | 134 | WRes File_Write(CSzFile *p, const void *data, size_t *size) 135 | { 136 | size_t originalSize = *size; 137 | if (originalSize == 0) 138 | return 0; 139 | 140 | #ifdef USE_WINDOWS_FILE 141 | 142 | *size = 0; 143 | do 144 | { 145 | DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize; 146 | DWORD processed = 0; 147 | BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL); 148 | data = (void *)((Byte *)data + processed); 149 | originalSize -= processed; 150 | *size += processed; 151 | if (!res) 152 | return GetLastError(); 153 | if (processed == 0) 154 | break; 155 | } 156 | while (originalSize > 0); 157 | return 0; 158 | 159 | #else 160 | 161 | *size = fwrite(data, 1, originalSize, p->file); 162 | if (*size == originalSize) 163 | return 0; 164 | return ferror(p->file); 165 | 166 | #endif 167 | } 168 | 169 | WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin) 170 | { 171 | #ifdef USE_WINDOWS_FILE 172 | 173 | LARGE_INTEGER value; 174 | DWORD moveMethod; 175 | value.LowPart = (DWORD)*pos; 176 | value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */ 177 | switch (origin) 178 | { 179 | case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break; 180 | case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break; 181 | case SZ_SEEK_END: moveMethod = FILE_END; break; 182 | default: return ERROR_INVALID_PARAMETER; 183 | } 184 | value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod); 185 | if (value.LowPart == 0xFFFFFFFF) 186 | { 187 | WRes res = GetLastError(); 188 | if (res != NO_ERROR) 189 | return res; 190 | } 191 | *pos = ((Int64)value.HighPart << 32) | value.LowPart; 192 | return 0; 193 | 194 | #else 195 | 196 | int moveMethod; 197 | int res; 198 | switch (origin) 199 | { 200 | case SZ_SEEK_SET: moveMethod = SEEK_SET; break; 201 | case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break; 202 | case SZ_SEEK_END: moveMethod = SEEK_END; break; 203 | default: return 1; 204 | } 205 | res = fseek(p->file, (long)*pos, moveMethod); 206 | *pos = ftell(p->file); 207 | return res; 208 | 209 | #endif 210 | } 211 | 212 | WRes File_GetLength(CSzFile *p, UInt64 *length) 213 | { 214 | #ifdef USE_WINDOWS_FILE 215 | 216 | DWORD sizeHigh; 217 | DWORD sizeLow = GetFileSize(p->handle, &sizeHigh); 218 | if (sizeLow == 0xFFFFFFFF) 219 | { 220 | DWORD res = GetLastError(); 221 | if (res != NO_ERROR) 222 | return res; 223 | } 224 | *length = (((UInt64)sizeHigh) << 32) + sizeLow; 225 | return 0; 226 | 227 | #else 228 | 229 | long pos = ftell(p->file); 230 | int res = fseek(p->file, 0, SEEK_END); 231 | *length = ftell(p->file); 232 | fseek(p->file, pos, SEEK_SET); 233 | return res; 234 | 235 | #endif 236 | } 237 | 238 | 239 | /* ---------- FileSeqInStream ---------- */ 240 | 241 | static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size) 242 | { 243 | CFileSeqInStream *p = (CFileSeqInStream *)pp; 244 | return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ; 245 | } 246 | 247 | void FileSeqInStream_CreateVTable(CFileSeqInStream *p) 248 | { 249 | p->s.Read = FileSeqInStream_Read; 250 | } 251 | 252 | 253 | /* ---------- FileInStream ---------- */ 254 | 255 | static SRes FileInStream_Read(void *pp, void *buf, size_t *size) 256 | { 257 | CFileInStream *p = (CFileInStream *)pp; 258 | return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ; 259 | } 260 | 261 | static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin) 262 | { 263 | CFileInStream *p = (CFileInStream *)pp; 264 | return File_Seek(&p->file, pos, origin); 265 | } 266 | 267 | void FileInStream_CreateVTable(CFileInStream *p) 268 | { 269 | p->s.Read = FileInStream_Read; 270 | p->s.Seek = FileInStream_Seek; 271 | } 272 | 273 | 274 | /* ---------- FileOutStream ---------- */ 275 | 276 | static size_t FileOutStream_Write(void *pp, const void *data, size_t size) 277 | { 278 | CFileOutStream *p = (CFileOutStream *)pp; 279 | File_Write(&p->file, data, &size); 280 | return size; 281 | } 282 | 283 | void FileOutStream_CreateVTable(CFileOutStream *p) 284 | { 285 | p->s.Write = FileOutStream_Write; 286 | } 287 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zFile.h: -------------------------------------------------------------------------------- 1 | /* 7zFile.h -- File IO 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_FILE_H 5 | #define __7Z_FILE_H 6 | 7 | #ifdef _WIN32 8 | #define USE_WINDOWS_FILE 9 | #endif 10 | 11 | #ifdef USE_WINDOWS_FILE 12 | #include 13 | #else 14 | #include 15 | #endif 16 | 17 | #include "7zTypes.h" 18 | 19 | EXTERN_C_BEGIN 20 | 21 | /* ---------- File ---------- */ 22 | 23 | typedef struct 24 | { 25 | #ifdef USE_WINDOWS_FILE 26 | HANDLE handle; 27 | #else 28 | FILE *file; 29 | #endif 30 | } CSzFile; 31 | 32 | void File_Construct(CSzFile *p); 33 | #if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE) 34 | WRes InFile_Open(CSzFile *p, const char *name); 35 | WRes OutFile_Open(CSzFile *p, const char *name); 36 | #endif 37 | #ifdef USE_WINDOWS_FILE 38 | WRes InFile_OpenW(CSzFile *p, const WCHAR *name); 39 | WRes OutFile_OpenW(CSzFile *p, const WCHAR *name); 40 | #endif 41 | WRes File_Close(CSzFile *p); 42 | 43 | /* reads max(*size, remain file's size) bytes */ 44 | WRes File_Read(CSzFile *p, void *data, size_t *size); 45 | 46 | /* writes *size bytes */ 47 | WRes File_Write(CSzFile *p, const void *data, size_t *size); 48 | 49 | WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin); 50 | WRes File_GetLength(CSzFile *p, UInt64 *length); 51 | 52 | 53 | /* ---------- FileInStream ---------- */ 54 | 55 | typedef struct 56 | { 57 | ISeqInStream s; 58 | CSzFile file; 59 | } CFileSeqInStream; 60 | 61 | void FileSeqInStream_CreateVTable(CFileSeqInStream *p); 62 | 63 | 64 | typedef struct 65 | { 66 | ISeekInStream s; 67 | CSzFile file; 68 | } CFileInStream; 69 | 70 | void FileInStream_CreateVTable(CFileInStream *p); 71 | 72 | 73 | typedef struct 74 | { 75 | ISeqOutStream s; 76 | CSzFile file; 77 | } CFileOutStream; 78 | 79 | void FileOutStream_CreateVTable(CFileOutStream *p); 80 | 81 | EXTERN_C_END 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zStream.c: -------------------------------------------------------------------------------- 1 | /* 7zStream.c -- 7z Stream functions 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include 7 | 8 | #include "7zTypes.h" 9 | 10 | SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType) 11 | { 12 | while (size != 0) 13 | { 14 | size_t processed = size; 15 | RINOK(stream->Read(stream, buf, &processed)); 16 | if (processed == 0) 17 | return errorType; 18 | buf = (void *)((Byte *)buf + processed); 19 | size -= processed; 20 | } 21 | return SZ_OK; 22 | } 23 | 24 | SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size) 25 | { 26 | return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); 27 | } 28 | 29 | SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf) 30 | { 31 | size_t processed = 1; 32 | RINOK(stream->Read(stream, buf, &processed)); 33 | return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF; 34 | } 35 | 36 | SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset) 37 | { 38 | Int64 t = offset; 39 | return stream->Seek(stream, &t, SZ_SEEK_SET); 40 | } 41 | 42 | SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size) 43 | { 44 | const void *lookBuf; 45 | if (*size == 0) 46 | return SZ_OK; 47 | RINOK(stream->Look(stream, &lookBuf, size)); 48 | memcpy(buf, lookBuf, *size); 49 | return stream->Skip(stream, *size); 50 | } 51 | 52 | SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType) 53 | { 54 | while (size != 0) 55 | { 56 | size_t processed = size; 57 | RINOK(stream->Read(stream, buf, &processed)); 58 | if (processed == 0) 59 | return errorType; 60 | buf = (void *)((Byte *)buf + processed); 61 | size -= processed; 62 | } 63 | return SZ_OK; 64 | } 65 | 66 | SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size) 67 | { 68 | return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); 69 | } 70 | 71 | static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size) 72 | { 73 | SRes res = SZ_OK; 74 | CLookToRead *p = (CLookToRead *)pp; 75 | size_t size2 = p->size - p->pos; 76 | if (size2 == 0 && *size > 0) 77 | { 78 | p->pos = 0; 79 | size2 = LookToRead_BUF_SIZE; 80 | res = p->realStream->Read(p->realStream, p->buf, &size2); 81 | p->size = size2; 82 | } 83 | if (size2 < *size) 84 | *size = size2; 85 | *buf = p->buf + p->pos; 86 | return res; 87 | } 88 | 89 | static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size) 90 | { 91 | SRes res = SZ_OK; 92 | CLookToRead *p = (CLookToRead *)pp; 93 | size_t size2 = p->size - p->pos; 94 | if (size2 == 0 && *size > 0) 95 | { 96 | p->pos = 0; 97 | if (*size > LookToRead_BUF_SIZE) 98 | *size = LookToRead_BUF_SIZE; 99 | res = p->realStream->Read(p->realStream, p->buf, size); 100 | size2 = p->size = *size; 101 | } 102 | if (size2 < *size) 103 | *size = size2; 104 | *buf = p->buf + p->pos; 105 | return res; 106 | } 107 | 108 | static SRes LookToRead_Skip(void *pp, size_t offset) 109 | { 110 | CLookToRead *p = (CLookToRead *)pp; 111 | p->pos += offset; 112 | return SZ_OK; 113 | } 114 | 115 | static SRes LookToRead_Read(void *pp, void *buf, size_t *size) 116 | { 117 | CLookToRead *p = (CLookToRead *)pp; 118 | size_t rem = p->size - p->pos; 119 | if (rem == 0) 120 | return p->realStream->Read(p->realStream, buf, size); 121 | if (rem > *size) 122 | rem = *size; 123 | memcpy(buf, p->buf + p->pos, rem); 124 | p->pos += rem; 125 | *size = rem; 126 | return SZ_OK; 127 | } 128 | 129 | static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin) 130 | { 131 | CLookToRead *p = (CLookToRead *)pp; 132 | p->pos = p->size = 0; 133 | return p->realStream->Seek(p->realStream, pos, origin); 134 | } 135 | 136 | void LookToRead_CreateVTable(CLookToRead *p, int lookahead) 137 | { 138 | p->s.Look = lookahead ? 139 | LookToRead_Look_Lookahead : 140 | LookToRead_Look_Exact; 141 | p->s.Skip = LookToRead_Skip; 142 | p->s.Read = LookToRead_Read; 143 | p->s.Seek = LookToRead_Seek; 144 | } 145 | 146 | void LookToRead_Init(CLookToRead *p) 147 | { 148 | p->pos = p->size = 0; 149 | } 150 | 151 | static SRes SecToLook_Read(void *pp, void *buf, size_t *size) 152 | { 153 | CSecToLook *p = (CSecToLook *)pp; 154 | return LookInStream_LookRead(p->realStream, buf, size); 155 | } 156 | 157 | void SecToLook_CreateVTable(CSecToLook *p) 158 | { 159 | p->s.Read = SecToLook_Read; 160 | } 161 | 162 | static SRes SecToRead_Read(void *pp, void *buf, size_t *size) 163 | { 164 | CSecToRead *p = (CSecToRead *)pp; 165 | return p->realStream->Read(p->realStream, buf, size); 166 | } 167 | 168 | void SecToRead_CreateVTable(CSecToRead *p) 169 | { 170 | p->s.Read = SecToRead_Read; 171 | } 172 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zTypes.h: -------------------------------------------------------------------------------- 1 | /* 7zTypes.h -- Basic types 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_TYPES_H 5 | #define __7Z_TYPES_H 6 | 7 | #ifdef _WIN32 8 | /* #include */ 9 | #endif 10 | 11 | #include 12 | 13 | #ifndef EXTERN_C_BEGIN 14 | #ifdef __cplusplus 15 | #define EXTERN_C_BEGIN extern "C" { 16 | #define EXTERN_C_END } 17 | #else 18 | #define EXTERN_C_BEGIN 19 | #define EXTERN_C_END 20 | #endif 21 | #endif 22 | 23 | EXTERN_C_BEGIN 24 | 25 | #define SZ_OK 0 26 | 27 | #define SZ_ERROR_DATA 1 28 | #define SZ_ERROR_MEM 2 29 | #define SZ_ERROR_CRC 3 30 | #define SZ_ERROR_UNSUPPORTED 4 31 | #define SZ_ERROR_PARAM 5 32 | #define SZ_ERROR_INPUT_EOF 6 33 | #define SZ_ERROR_OUTPUT_EOF 7 34 | #define SZ_ERROR_READ 8 35 | #define SZ_ERROR_WRITE 9 36 | #define SZ_ERROR_PROGRESS 10 37 | #define SZ_ERROR_FAIL 11 38 | #define SZ_ERROR_THREAD 12 39 | 40 | #define SZ_ERROR_ARCHIVE 16 41 | #define SZ_ERROR_NO_ARCHIVE 17 42 | 43 | typedef int SRes; 44 | 45 | #ifdef _WIN32 46 | /* typedef DWORD WRes; */ 47 | typedef unsigned WRes; 48 | #else 49 | typedef int WRes; 50 | #endif 51 | 52 | #ifndef RINOK 53 | #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } 54 | #endif 55 | 56 | typedef unsigned char Byte; 57 | typedef short Int16; 58 | typedef unsigned short UInt16; 59 | 60 | #ifdef _LZMA_UINT32_IS_ULONG 61 | typedef long Int32; 62 | typedef unsigned long UInt32; 63 | #else 64 | typedef int Int32; 65 | typedef unsigned int UInt32; 66 | #endif 67 | 68 | #ifdef _SZ_NO_INT_64 69 | 70 | /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers. 71 | NOTES: Some code will work incorrectly in that case! */ 72 | 73 | typedef long Int64; 74 | typedef unsigned long UInt64; 75 | 76 | #else 77 | 78 | #if defined(_MSC_VER) || defined(__BORLANDC__) 79 | typedef __int64 Int64; 80 | typedef unsigned __int64 UInt64; 81 | #define UINT64_CONST(n) n 82 | #else 83 | typedef long long int Int64; 84 | typedef unsigned long long int UInt64; 85 | #define UINT64_CONST(n) n ## ULL 86 | #endif 87 | 88 | #endif 89 | 90 | #ifdef _LZMA_NO_SYSTEM_SIZE_T 91 | typedef UInt32 SizeT; 92 | #else 93 | typedef size_t SizeT; 94 | #endif 95 | 96 | typedef int Bool; 97 | #define True 1 98 | #define False 0 99 | 100 | 101 | #ifdef _WIN32 102 | #define MY_STD_CALL __stdcall 103 | #else 104 | #define MY_STD_CALL 105 | #endif 106 | 107 | #ifdef _MSC_VER 108 | 109 | #if _MSC_VER >= 1300 110 | #define MY_NO_INLINE __declspec(noinline) 111 | #else 112 | #define MY_NO_INLINE 113 | #endif 114 | 115 | #define MY_CDECL __cdecl 116 | #define MY_FAST_CALL __fastcall 117 | 118 | #else 119 | 120 | #define MY_NO_INLINE 121 | #define MY_CDECL 122 | #define MY_FAST_CALL 123 | 124 | #endif 125 | 126 | 127 | /* The following interfaces use first parameter as pointer to structure */ 128 | 129 | typedef struct 130 | { 131 | Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */ 132 | } IByteIn; 133 | 134 | typedef struct 135 | { 136 | void (*Write)(void *p, Byte b); 137 | } IByteOut; 138 | 139 | typedef struct 140 | { 141 | SRes (*Read)(void *p, void *buf, size_t *size); 142 | /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. 143 | (output(*size) < input(*size)) is allowed */ 144 | } ISeqInStream; 145 | 146 | /* it can return SZ_ERROR_INPUT_EOF */ 147 | SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size); 148 | SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType); 149 | SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf); 150 | 151 | typedef struct 152 | { 153 | size_t (*Write)(void *p, const void *buf, size_t size); 154 | /* Returns: result - the number of actually written bytes. 155 | (result < size) means error */ 156 | } ISeqOutStream; 157 | 158 | typedef enum 159 | { 160 | SZ_SEEK_SET = 0, 161 | SZ_SEEK_CUR = 1, 162 | SZ_SEEK_END = 2 163 | } ESzSeek; 164 | 165 | typedef struct 166 | { 167 | SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ 168 | SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); 169 | } ISeekInStream; 170 | 171 | typedef struct 172 | { 173 | SRes (*Look)(void *p, const void **buf, size_t *size); 174 | /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. 175 | (output(*size) > input(*size)) is not allowed 176 | (output(*size) < input(*size)) is allowed */ 177 | SRes (*Skip)(void *p, size_t offset); 178 | /* offset must be <= output(*size) of Look */ 179 | 180 | SRes (*Read)(void *p, void *buf, size_t *size); 181 | /* reads directly (without buffer). It's same as ISeqInStream::Read */ 182 | SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); 183 | } ILookInStream; 184 | 185 | SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size); 186 | SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset); 187 | 188 | /* reads via ILookInStream::Read */ 189 | SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType); 190 | SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size); 191 | 192 | #define LookToRead_BUF_SIZE (1 << 14) 193 | 194 | typedef struct 195 | { 196 | ILookInStream s; 197 | ISeekInStream *realStream; 198 | size_t pos; 199 | size_t size; 200 | Byte buf[LookToRead_BUF_SIZE]; 201 | } CLookToRead; 202 | 203 | void LookToRead_CreateVTable(CLookToRead *p, int lookahead); 204 | void LookToRead_Init(CLookToRead *p); 205 | 206 | typedef struct 207 | { 208 | ISeqInStream s; 209 | ILookInStream *realStream; 210 | } CSecToLook; 211 | 212 | void SecToLook_CreateVTable(CSecToLook *p); 213 | 214 | typedef struct 215 | { 216 | ISeqInStream s; 217 | ILookInStream *realStream; 218 | } CSecToRead; 219 | 220 | void SecToRead_CreateVTable(CSecToRead *p); 221 | 222 | typedef struct 223 | { 224 | SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize); 225 | /* Returns: result. (result != SZ_OK) means break. 226 | Value (UInt64)(Int64)-1 for size means unknown value. */ 227 | } ICompressProgress; 228 | 229 | typedef struct 230 | { 231 | void *(*Alloc)(void *p, size_t size); 232 | void (*Free)(void *p, void *address); /* address can be 0 */ 233 | } ISzAlloc; 234 | 235 | #define IAlloc_Alloc(p, size) (p)->Alloc((p), size) 236 | #define IAlloc_Free(p, a) (p)->Free((p), a) 237 | 238 | #ifdef _WIN32 239 | 240 | #define CHAR_PATH_SEPARATOR '\\' 241 | #define WCHAR_PATH_SEPARATOR L'\\' 242 | #define STRING_PATH_SEPARATOR "\\" 243 | #define WSTRING_PATH_SEPARATOR L"\\" 244 | 245 | #else 246 | 247 | #define CHAR_PATH_SEPARATOR '/' 248 | #define WCHAR_PATH_SEPARATOR L'/' 249 | #define STRING_PATH_SEPARATOR "/" 250 | #define WSTRING_PATH_SEPARATOR L"/" 251 | 252 | #endif 253 | 254 | EXTERN_C_END 255 | 256 | #endif 257 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zVersion.h: -------------------------------------------------------------------------------- 1 | #define MY_VER_MAJOR 9 2 | #define MY_VER_MINOR 38 3 | #define MY_VER_BUILD 00 4 | #define MY_VERSION "9.38 beta" 5 | // #define MY_7ZIP_VERSION "9.38" 6 | #define MY_DATE "2015-01-03" 7 | #undef MY_COPYRIGHT 8 | #undef MY_VERSION_COPYRIGHT_DATE 9 | #define MY_COPYRIGHT ": Igor Pavlov : Public domain" 10 | #define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE 11 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/7zVersion.rc: -------------------------------------------------------------------------------- 1 | #define MY_VS_FFI_FILEFLAGSMASK 0x0000003FL 2 | #define MY_VOS_NT_WINDOWS32 0x00040004L 3 | #define MY_VOS_CE_WINDOWS32 0x00050004L 4 | 5 | #define MY_VFT_APP 0x00000001L 6 | #define MY_VFT_DLL 0x00000002L 7 | 8 | // #include 9 | 10 | #ifndef MY_VERSION 11 | #include "7zVersion.h" 12 | #endif 13 | 14 | #define MY_VER MY_VER_MAJOR,MY_VER_MINOR,MY_VER_BUILD,0 15 | 16 | #ifdef DEBUG 17 | #define DBG_FL VS_FF_DEBUG 18 | #else 19 | #define DBG_FL 0 20 | #endif 21 | 22 | #define MY_VERSION_INFO(fileType, descr, intName, origName) \ 23 | LANGUAGE 9, 1 \ 24 | 1 VERSIONINFO \ 25 | FILEVERSION MY_VER \ 26 | PRODUCTVERSION MY_VER \ 27 | FILEFLAGSMASK MY_VS_FFI_FILEFLAGSMASK \ 28 | FILEFLAGS DBG_FL \ 29 | FILEOS MY_VOS_NT_WINDOWS32 \ 30 | FILETYPE fileType \ 31 | FILESUBTYPE 0x0L \ 32 | BEGIN \ 33 | BLOCK "StringFileInfo" \ 34 | BEGIN \ 35 | BLOCK "040904b0" \ 36 | BEGIN \ 37 | VALUE "CompanyName", "Igor Pavlov" \ 38 | VALUE "FileDescription", descr \ 39 | VALUE "FileVersion", MY_VERSION \ 40 | VALUE "InternalName", intName \ 41 | VALUE "LegalCopyright", MY_COPYRIGHT \ 42 | VALUE "OriginalFilename", origName \ 43 | VALUE "ProductName", "7-Zip" \ 44 | VALUE "ProductVersion", MY_VERSION \ 45 | END \ 46 | END \ 47 | BLOCK "VarFileInfo" \ 48 | BEGIN \ 49 | VALUE "Translation", 0x409, 1200 \ 50 | END \ 51 | END 52 | 53 | #define MY_VERSION_INFO_APP(descr, intName) MY_VERSION_INFO(MY_VFT_APP, descr, intName, intName ".exe") 54 | 55 | #define MY_VERSION_INFO_DLL(descr, intName) MY_VERSION_INFO(MY_VFT_DLL, descr, intName, intName ".dll") 56 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Aes.h: -------------------------------------------------------------------------------- 1 | /* Aes.h -- AES encryption / decryption 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __AES_H 5 | #define __AES_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define AES_BLOCK_SIZE 16 12 | 13 | /* Call AesGenTables one time before other AES functions */ 14 | void AesGenTables(void); 15 | 16 | /* UInt32 pointers must be 16-byte aligned */ 17 | 18 | /* 16-byte (4 * 32-bit words) blocks: 1 (IV) + 1 (keyMode) + 15 (AES-256 roundKeys) */ 19 | #define AES_NUM_IVMRK_WORDS ((1 + 1 + 15) * 4) 20 | 21 | /* aes - 16-byte aligned pointer to keyMode+roundKeys sequence */ 22 | /* keySize = 16 or 24 or 32 (bytes) */ 23 | typedef void (MY_FAST_CALL *AES_SET_KEY_FUNC)(UInt32 *aes, const Byte *key, unsigned keySize); 24 | void MY_FAST_CALL Aes_SetKey_Enc(UInt32 *aes, const Byte *key, unsigned keySize); 25 | void MY_FAST_CALL Aes_SetKey_Dec(UInt32 *aes, const Byte *key, unsigned keySize); 26 | 27 | /* ivAes - 16-byte aligned pointer to iv+keyMode+roundKeys sequence: UInt32[AES_NUM_IVMRK_WORDS] */ 28 | void AesCbc_Init(UInt32 *ivAes, const Byte *iv); /* iv size is AES_BLOCK_SIZE */ 29 | /* data - 16-byte aligned pointer to data */ 30 | /* numBlocks - the number of 16-byte blocks in data array */ 31 | typedef void (MY_FAST_CALL *AES_CODE_FUNC)(UInt32 *ivAes, Byte *data, size_t numBlocks); 32 | extern AES_CODE_FUNC g_AesCbc_Encode; 33 | extern AES_CODE_FUNC g_AesCbc_Decode; 34 | extern AES_CODE_FUNC g_AesCtr_Code; 35 | 36 | EXTERN_C_END 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/AesOpt.c: -------------------------------------------------------------------------------- 1 | /* AesOpt.c -- Intel's AES 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "CpuArch.h" 7 | 8 | #ifdef MY_CPU_X86_OR_AMD64 9 | #if _MSC_VER >= 1500 10 | #define USE_INTEL_AES 11 | #endif 12 | #endif 13 | 14 | #ifdef USE_INTEL_AES 15 | 16 | #include 17 | 18 | void MY_FAST_CALL AesCbc_Encode_Intel(__m128i *p, __m128i *data, size_t numBlocks) 19 | { 20 | __m128i m = *p; 21 | for (; numBlocks != 0; numBlocks--, data++) 22 | { 23 | UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1; 24 | const __m128i *w = p + 3; 25 | m = _mm_xor_si128(m, *data); 26 | m = _mm_xor_si128(m, p[2]); 27 | do 28 | { 29 | m = _mm_aesenc_si128(m, w[0]); 30 | m = _mm_aesenc_si128(m, w[1]); 31 | w += 2; 32 | } 33 | while (--numRounds2 != 0); 34 | m = _mm_aesenc_si128(m, w[0]); 35 | m = _mm_aesenclast_si128(m, w[1]); 36 | *data = m; 37 | } 38 | *p = m; 39 | } 40 | 41 | #define NUM_WAYS 3 42 | 43 | #define AES_OP_W(op, n) { \ 44 | const __m128i t = w[n]; \ 45 | m0 = op(m0, t); \ 46 | m1 = op(m1, t); \ 47 | m2 = op(m2, t); \ 48 | } 49 | 50 | #define AES_DEC(n) AES_OP_W(_mm_aesdec_si128, n) 51 | #define AES_DEC_LAST(n) AES_OP_W(_mm_aesdeclast_si128, n) 52 | #define AES_ENC(n) AES_OP_W(_mm_aesenc_si128, n) 53 | #define AES_ENC_LAST(n) AES_OP_W(_mm_aesenclast_si128, n) 54 | 55 | void MY_FAST_CALL AesCbc_Decode_Intel(__m128i *p, __m128i *data, size_t numBlocks) 56 | { 57 | __m128i iv = *p; 58 | for (; numBlocks >= NUM_WAYS; numBlocks -= NUM_WAYS, data += NUM_WAYS) 59 | { 60 | UInt32 numRounds2 = *(const UInt32 *)(p + 1); 61 | const __m128i *w = p + numRounds2 * 2; 62 | __m128i m0, m1, m2; 63 | { 64 | const __m128i t = w[2]; 65 | m0 = _mm_xor_si128(t, data[0]); 66 | m1 = _mm_xor_si128(t, data[1]); 67 | m2 = _mm_xor_si128(t, data[2]); 68 | } 69 | numRounds2--; 70 | do 71 | { 72 | AES_DEC(1) 73 | AES_DEC(0) 74 | w -= 2; 75 | } 76 | while (--numRounds2 != 0); 77 | AES_DEC(1) 78 | AES_DEC_LAST(0) 79 | 80 | { 81 | __m128i t; 82 | t = _mm_xor_si128(m0, iv); iv = data[0]; data[0] = t; 83 | t = _mm_xor_si128(m1, iv); iv = data[1]; data[1] = t; 84 | t = _mm_xor_si128(m2, iv); iv = data[2]; data[2] = t; 85 | } 86 | } 87 | for (; numBlocks != 0; numBlocks--, data++) 88 | { 89 | UInt32 numRounds2 = *(const UInt32 *)(p + 1); 90 | const __m128i *w = p + numRounds2 * 2; 91 | __m128i m = _mm_xor_si128(w[2], *data); 92 | numRounds2--; 93 | do 94 | { 95 | m = _mm_aesdec_si128(m, w[1]); 96 | m = _mm_aesdec_si128(m, w[0]); 97 | w -= 2; 98 | } 99 | while (--numRounds2 != 0); 100 | m = _mm_aesdec_si128(m, w[1]); 101 | m = _mm_aesdeclast_si128(m, w[0]); 102 | 103 | m = _mm_xor_si128(m, iv); 104 | iv = *data; 105 | *data = m; 106 | } 107 | *p = iv; 108 | } 109 | 110 | void MY_FAST_CALL AesCtr_Code_Intel(__m128i *p, __m128i *data, size_t numBlocks) 111 | { 112 | __m128i ctr = *p; 113 | __m128i one; 114 | one.m128i_u64[0] = 1; 115 | one.m128i_u64[1] = 0; 116 | for (; numBlocks >= NUM_WAYS; numBlocks -= NUM_WAYS, data += NUM_WAYS) 117 | { 118 | UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1; 119 | const __m128i *w = p; 120 | __m128i m0, m1, m2; 121 | { 122 | const __m128i t = w[2]; 123 | ctr = _mm_add_epi64(ctr, one); m0 = _mm_xor_si128(ctr, t); 124 | ctr = _mm_add_epi64(ctr, one); m1 = _mm_xor_si128(ctr, t); 125 | ctr = _mm_add_epi64(ctr, one); m2 = _mm_xor_si128(ctr, t); 126 | } 127 | w += 3; 128 | do 129 | { 130 | AES_ENC(0) 131 | AES_ENC(1) 132 | w += 2; 133 | } 134 | while (--numRounds2 != 0); 135 | AES_ENC(0) 136 | AES_ENC_LAST(1) 137 | data[0] = _mm_xor_si128(data[0], m0); 138 | data[1] = _mm_xor_si128(data[1], m1); 139 | data[2] = _mm_xor_si128(data[2], m2); 140 | } 141 | for (; numBlocks != 0; numBlocks--, data++) 142 | { 143 | UInt32 numRounds2 = *(const UInt32 *)(p + 1) - 1; 144 | const __m128i *w = p; 145 | __m128i m; 146 | ctr = _mm_add_epi64(ctr, one); 147 | m = _mm_xor_si128(ctr, p[2]); 148 | w += 3; 149 | do 150 | { 151 | m = _mm_aesenc_si128(m, w[0]); 152 | m = _mm_aesenc_si128(m, w[1]); 153 | w += 2; 154 | } 155 | while (--numRounds2 != 0); 156 | m = _mm_aesenc_si128(m, w[0]); 157 | m = _mm_aesenclast_si128(m, w[1]); 158 | *data = _mm_xor_si128(*data, m); 159 | } 160 | *p = ctr; 161 | } 162 | 163 | #else 164 | 165 | void MY_FAST_CALL AesCbc_Encode(UInt32 *ivAes, Byte *data, size_t numBlocks); 166 | void MY_FAST_CALL AesCbc_Decode(UInt32 *ivAes, Byte *data, size_t numBlocks); 167 | void MY_FAST_CALL AesCtr_Code(UInt32 *ivAes, Byte *data, size_t numBlocks); 168 | 169 | void MY_FAST_CALL AesCbc_Encode_Intel(UInt32 *p, Byte *data, size_t numBlocks) 170 | { 171 | AesCbc_Encode(p, data, numBlocks); 172 | } 173 | 174 | void MY_FAST_CALL AesCbc_Decode_Intel(UInt32 *p, Byte *data, size_t numBlocks) 175 | { 176 | AesCbc_Decode(p, data, numBlocks); 177 | } 178 | 179 | void MY_FAST_CALL AesCtr_Code_Intel(UInt32 *p, Byte *data, size_t numBlocks) 180 | { 181 | AesCtr_Code(p, data, numBlocks); 182 | } 183 | 184 | #endif 185 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Alloc.c: -------------------------------------------------------------------------------- 1 | /* Alloc.c -- Memory allocation functions 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #ifdef _WIN32 7 | #include 8 | #endif 9 | #include 10 | 11 | #include "Alloc.h" 12 | 13 | /* #define _SZ_ALLOC_DEBUG */ 14 | 15 | /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ 16 | #ifdef _SZ_ALLOC_DEBUG 17 | #include 18 | int g_allocCount = 0; 19 | int g_allocCountMid = 0; 20 | int g_allocCountBig = 0; 21 | #endif 22 | 23 | void *MyAlloc(size_t size) 24 | { 25 | if (size == 0) 26 | return 0; 27 | #ifdef _SZ_ALLOC_DEBUG 28 | { 29 | void *p = malloc(size); 30 | fprintf(stderr, "\nAlloc %10d bytes, count = %10d, addr = %8X", size, g_allocCount++, (unsigned)p); 31 | return p; 32 | } 33 | #else 34 | return malloc(size); 35 | #endif 36 | } 37 | 38 | void MyFree(void *address) 39 | { 40 | #ifdef _SZ_ALLOC_DEBUG 41 | if (address != 0) 42 | fprintf(stderr, "\nFree; count = %10d, addr = %8X", --g_allocCount, (unsigned)address); 43 | #endif 44 | free(address); 45 | } 46 | 47 | #ifdef _WIN32 48 | 49 | void *MidAlloc(size_t size) 50 | { 51 | if (size == 0) 52 | return 0; 53 | #ifdef _SZ_ALLOC_DEBUG 54 | fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++); 55 | #endif 56 | return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE); 57 | } 58 | 59 | void MidFree(void *address) 60 | { 61 | #ifdef _SZ_ALLOC_DEBUG 62 | if (address != 0) 63 | fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid); 64 | #endif 65 | if (address == 0) 66 | return; 67 | VirtualFree(address, 0, MEM_RELEASE); 68 | } 69 | 70 | #ifndef MEM_LARGE_PAGES 71 | #undef _7ZIP_LARGE_PAGES 72 | #endif 73 | 74 | #ifdef _7ZIP_LARGE_PAGES 75 | SIZE_T g_LargePageSize = 0; 76 | typedef SIZE_T (WINAPI *GetLargePageMinimumP)(); 77 | #endif 78 | 79 | void SetLargePageSize() 80 | { 81 | #ifdef _7ZIP_LARGE_PAGES 82 | SIZE_T size = 0; 83 | GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP) 84 | GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum"); 85 | if (largePageMinimum == 0) 86 | return; 87 | size = largePageMinimum(); 88 | if (size == 0 || (size & (size - 1)) != 0) 89 | return; 90 | g_LargePageSize = size; 91 | #endif 92 | } 93 | 94 | 95 | void *BigAlloc(size_t size) 96 | { 97 | if (size == 0) 98 | return 0; 99 | #ifdef _SZ_ALLOC_DEBUG 100 | fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++); 101 | #endif 102 | 103 | #ifdef _7ZIP_LARGE_PAGES 104 | if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18)) 105 | { 106 | void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)), 107 | MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE); 108 | if (res != 0) 109 | return res; 110 | } 111 | #endif 112 | return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE); 113 | } 114 | 115 | void BigFree(void *address) 116 | { 117 | #ifdef _SZ_ALLOC_DEBUG 118 | if (address != 0) 119 | fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig); 120 | #endif 121 | 122 | if (address == 0) 123 | return; 124 | VirtualFree(address, 0, MEM_RELEASE); 125 | } 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Alloc.h: -------------------------------------------------------------------------------- 1 | /* Alloc.h -- Memory allocation functions 2 | 2009-02-07 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __COMMON_ALLOC_H 5 | #define __COMMON_ALLOC_H 6 | 7 | #include 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | void *MyAlloc(size_t size); 14 | void MyFree(void *address); 15 | 16 | #ifdef _WIN32 17 | 18 | void SetLargePageSize(); 19 | 20 | void *MidAlloc(size_t size); 21 | void MidFree(void *address); 22 | void *BigAlloc(size_t size); 23 | void BigFree(void *address); 24 | 25 | #else 26 | 27 | #define MidAlloc(size) MyAlloc(size) 28 | #define MidFree(address) MyFree(address) 29 | #define BigAlloc(size) MyAlloc(size) 30 | #define BigFree(address) MyFree(address) 31 | 32 | #endif 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Bcj2.c: -------------------------------------------------------------------------------- 1 | /* Bcj2.c -- Converter for x86 code (BCJ2) 2 | 2008-10-04 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Bcj2.h" 7 | 8 | #ifdef _LZMA_PROB32 9 | #define CProb UInt32 10 | #else 11 | #define CProb UInt16 12 | #endif 13 | 14 | #define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80) 15 | #define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)) 16 | 17 | #define kNumTopBits 24 18 | #define kTopValue ((UInt32)1 << kNumTopBits) 19 | 20 | #define kNumBitModelTotalBits 11 21 | #define kBitModelTotal (1 << kNumBitModelTotalBits) 22 | #define kNumMoveBits 5 23 | 24 | #define RC_READ_BYTE (*buffer++) 25 | #define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; } 26 | #define RC_INIT2 code = 0; range = 0xFFFFFFFF; \ 27 | { int i; for (i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }} 28 | 29 | #define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; } 30 | 31 | #define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound) 32 | #define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE; 33 | #define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE; 34 | 35 | int Bcj2_Decode( 36 | const Byte *buf0, SizeT size0, 37 | const Byte *buf1, SizeT size1, 38 | const Byte *buf2, SizeT size2, 39 | const Byte *buf3, SizeT size3, 40 | Byte *outBuf, SizeT outSize) 41 | { 42 | CProb p[256 + 2]; 43 | SizeT inPos = 0, outPos = 0; 44 | 45 | const Byte *buffer, *bufferLim; 46 | UInt32 range, code; 47 | Byte prevByte = 0; 48 | 49 | unsigned int i; 50 | for (i = 0; i < sizeof(p) / sizeof(p[0]); i++) 51 | p[i] = kBitModelTotal >> 1; 52 | 53 | buffer = buf3; 54 | bufferLim = buffer + size3; 55 | RC_INIT2 56 | 57 | if (outSize == 0) 58 | return SZ_OK; 59 | 60 | for (;;) 61 | { 62 | Byte b; 63 | CProb *prob; 64 | UInt32 bound; 65 | UInt32 ttt; 66 | 67 | SizeT limit = size0 - inPos; 68 | if (outSize - outPos < limit) 69 | limit = outSize - outPos; 70 | while (limit != 0) 71 | { 72 | Byte b = buf0[inPos]; 73 | outBuf[outPos++] = b; 74 | if (IsJ(prevByte, b)) 75 | break; 76 | inPos++; 77 | prevByte = b; 78 | limit--; 79 | } 80 | 81 | if (limit == 0 || outPos == outSize) 82 | break; 83 | 84 | b = buf0[inPos++]; 85 | 86 | if (b == 0xE8) 87 | prob = p + prevByte; 88 | else if (b == 0xE9) 89 | prob = p + 256; 90 | else 91 | prob = p + 257; 92 | 93 | IF_BIT_0(prob) 94 | { 95 | UPDATE_0(prob) 96 | prevByte = b; 97 | } 98 | else 99 | { 100 | UInt32 dest; 101 | const Byte *v; 102 | UPDATE_1(prob) 103 | if (b == 0xE8) 104 | { 105 | v = buf1; 106 | if (size1 < 4) 107 | return SZ_ERROR_DATA; 108 | buf1 += 4; 109 | size1 -= 4; 110 | } 111 | else 112 | { 113 | v = buf2; 114 | if (size2 < 4) 115 | return SZ_ERROR_DATA; 116 | buf2 += 4; 117 | size2 -= 4; 118 | } 119 | dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) | 120 | ((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4); 121 | outBuf[outPos++] = (Byte)dest; 122 | if (outPos == outSize) 123 | break; 124 | outBuf[outPos++] = (Byte)(dest >> 8); 125 | if (outPos == outSize) 126 | break; 127 | outBuf[outPos++] = (Byte)(dest >> 16); 128 | if (outPos == outSize) 129 | break; 130 | outBuf[outPos++] = prevByte = (Byte)(dest >> 24); 131 | } 132 | } 133 | return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA; 134 | } 135 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Bcj2.h: -------------------------------------------------------------------------------- 1 | /* Bcj2.h -- Converter for x86 code (BCJ2) 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __BCJ2_H 5 | #define __BCJ2_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | /* 12 | Conditions: 13 | outSize <= FullOutputSize, 14 | where FullOutputSize is full size of output stream of x86_2 filter. 15 | 16 | If buf0 overlaps outBuf, there are two required conditions: 17 | 1) (buf0 >= outBuf) 18 | 2) (buf0 + size0 >= outBuf + FullOutputSize). 19 | 20 | Returns: 21 | SZ_OK 22 | SZ_ERROR_DATA - Data error 23 | */ 24 | 25 | int Bcj2_Decode( 26 | const Byte *buf0, SizeT size0, 27 | const Byte *buf1, SizeT size1, 28 | const Byte *buf2, SizeT size2, 29 | const Byte *buf3, SizeT size3, 30 | Byte *outBuf, SizeT outSize); 31 | 32 | EXTERN_C_END 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Bra.c: -------------------------------------------------------------------------------- 1 | /* Bra.c -- Converters for RISC code 2 | 2010-04-16 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Bra.h" 7 | 8 | SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 9 | { 10 | SizeT i; 11 | if (size < 4) 12 | return 0; 13 | size -= 4; 14 | ip += 8; 15 | for (i = 0; i <= size; i += 4) 16 | { 17 | if (data[i + 3] == 0xEB) 18 | { 19 | UInt32 dest; 20 | UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]); 21 | src <<= 2; 22 | if (encoding) 23 | dest = ip + (UInt32)i + src; 24 | else 25 | dest = src - (ip + (UInt32)i); 26 | dest >>= 2; 27 | data[i + 2] = (Byte)(dest >> 16); 28 | data[i + 1] = (Byte)(dest >> 8); 29 | data[i + 0] = (Byte)dest; 30 | } 31 | } 32 | return i; 33 | } 34 | 35 | SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 36 | { 37 | SizeT i; 38 | if (size < 4) 39 | return 0; 40 | size -= 4; 41 | ip += 4; 42 | for (i = 0; i <= size; i += 2) 43 | { 44 | if ((data[i + 1] & 0xF8) == 0xF0 && 45 | (data[i + 3] & 0xF8) == 0xF8) 46 | { 47 | UInt32 dest; 48 | UInt32 src = 49 | (((UInt32)data[i + 1] & 0x7) << 19) | 50 | ((UInt32)data[i + 0] << 11) | 51 | (((UInt32)data[i + 3] & 0x7) << 8) | 52 | (data[i + 2]); 53 | 54 | src <<= 1; 55 | if (encoding) 56 | dest = ip + (UInt32)i + src; 57 | else 58 | dest = src - (ip + (UInt32)i); 59 | dest >>= 1; 60 | 61 | data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7)); 62 | data[i + 0] = (Byte)(dest >> 11); 63 | data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7)); 64 | data[i + 2] = (Byte)dest; 65 | i += 2; 66 | } 67 | } 68 | return i; 69 | } 70 | 71 | SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 72 | { 73 | SizeT i; 74 | if (size < 4) 75 | return 0; 76 | size -= 4; 77 | for (i = 0; i <= size; i += 4) 78 | { 79 | if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1) 80 | { 81 | UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) | 82 | ((UInt32)data[i + 1] << 16) | 83 | ((UInt32)data[i + 2] << 8) | 84 | ((UInt32)data[i + 3] & (~3)); 85 | 86 | UInt32 dest; 87 | if (encoding) 88 | dest = ip + (UInt32)i + src; 89 | else 90 | dest = src - (ip + (UInt32)i); 91 | data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3)); 92 | data[i + 1] = (Byte)(dest >> 16); 93 | data[i + 2] = (Byte)(dest >> 8); 94 | data[i + 3] &= 0x3; 95 | data[i + 3] |= dest; 96 | } 97 | } 98 | return i; 99 | } 100 | 101 | SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 102 | { 103 | UInt32 i; 104 | if (size < 4) 105 | return 0; 106 | size -= 4; 107 | for (i = 0; i <= size; i += 4) 108 | { 109 | if ((data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00) || 110 | (data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)) 111 | { 112 | UInt32 src = 113 | ((UInt32)data[i + 0] << 24) | 114 | ((UInt32)data[i + 1] << 16) | 115 | ((UInt32)data[i + 2] << 8) | 116 | ((UInt32)data[i + 3]); 117 | UInt32 dest; 118 | 119 | src <<= 2; 120 | if (encoding) 121 | dest = ip + i + src; 122 | else 123 | dest = src - (ip + i); 124 | dest >>= 2; 125 | 126 | dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000; 127 | 128 | data[i + 0] = (Byte)(dest >> 24); 129 | data[i + 1] = (Byte)(dest >> 16); 130 | data[i + 2] = (Byte)(dest >> 8); 131 | data[i + 3] = (Byte)dest; 132 | } 133 | } 134 | return i; 135 | } 136 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Bra.h: -------------------------------------------------------------------------------- 1 | /* Bra.h -- Branch converters for executables 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __BRA_H 5 | #define __BRA_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | /* 12 | These functions convert relative addresses to absolute addresses 13 | in CALL instructions to increase the compression ratio. 14 | 15 | In: 16 | data - data buffer 17 | size - size of data 18 | ip - current virtual Instruction Pinter (IP) value 19 | state - state variable for x86 converter 20 | encoding - 0 (for decoding), 1 (for encoding) 21 | 22 | Out: 23 | state - state variable for x86 converter 24 | 25 | Returns: 26 | The number of processed bytes. If you call these functions with multiple calls, 27 | you must start next call with first byte after block of processed bytes. 28 | 29 | Type Endian Alignment LookAhead 30 | 31 | x86 little 1 4 32 | ARMT little 2 2 33 | ARM little 4 0 34 | PPC big 4 0 35 | SPARC big 4 0 36 | IA64 little 16 0 37 | 38 | size must be >= Alignment + LookAhead, if it's not last block. 39 | If (size < Alignment + LookAhead), converter returns 0. 40 | 41 | Example: 42 | 43 | UInt32 ip = 0; 44 | for () 45 | { 46 | ; size must be >= Alignment + LookAhead, if it's not last block 47 | SizeT processed = Convert(data, size, ip, 1); 48 | data += processed; 49 | size -= processed; 50 | ip += processed; 51 | } 52 | */ 53 | 54 | #define x86_Convert_Init(state) { state = 0; } 55 | SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding); 56 | SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 57 | SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 58 | SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 59 | SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 60 | SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); 61 | 62 | EXTERN_C_END 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Bra86.c: -------------------------------------------------------------------------------- 1 | /* Bra86.c -- Converter for x86 code (BCJ) 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Bra.h" 7 | 8 | #define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0) 9 | 10 | SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding) 11 | { 12 | SizeT pos = 0; 13 | UInt32 mask = *state & 7; 14 | if (size < 5) 15 | return 0; 16 | size -= 4; 17 | ip += 5; 18 | 19 | for (;;) 20 | { 21 | Byte *p = data + pos; 22 | const Byte *limit = data + size; 23 | for (; p < limit; p++) 24 | if ((*p & 0xFE) == 0xE8) 25 | break; 26 | 27 | { 28 | SizeT d = (SizeT)(p - data - pos); 29 | pos = (SizeT)(p - data); 30 | if (p >= limit) 31 | { 32 | *state = (d > 2 ? 0 : mask >> (unsigned)d); 33 | return pos; 34 | } 35 | if (d > 2) 36 | mask = 0; 37 | else 38 | { 39 | mask >>= (unsigned)d; 40 | if (mask != 0 && (mask > 4 || mask == 3 || Test86MSByte(p[(mask >> 1) + 1]))) 41 | { 42 | mask = (mask >> 1) | 4; 43 | pos++; 44 | continue; 45 | } 46 | } 47 | } 48 | 49 | if (Test86MSByte(p[4])) 50 | { 51 | UInt32 v = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]); 52 | UInt32 cur = ip + (UInt32)pos; 53 | pos += 5; 54 | if (encoding) 55 | v += cur; 56 | else 57 | v -= cur; 58 | if (mask != 0) 59 | { 60 | unsigned sh = (mask & 6) << 2; 61 | if (Test86MSByte((Byte)(v >> sh))) 62 | { 63 | v ^= (((UInt32)0x100 << sh) - 1); 64 | if (encoding) 65 | v += cur; 66 | else 67 | v -= cur; 68 | } 69 | mask = 0; 70 | } 71 | p[1] = (Byte)v; 72 | p[2] = (Byte)(v >> 8); 73 | p[3] = (Byte)(v >> 16); 74 | p[4] = (Byte)(0 - ((v >> 24) & 1)); 75 | } 76 | else 77 | { 78 | mask = (mask >> 1) | 4; 79 | pos++; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/BraIA64.c: -------------------------------------------------------------------------------- 1 | /* BraIA64.c -- Converter for IA-64 code 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Bra.h" 7 | 8 | static const Byte kBranchTable[32] = 9 | { 10 | 0, 0, 0, 0, 0, 0, 0, 0, 11 | 0, 0, 0, 0, 0, 0, 0, 0, 12 | 4, 4, 6, 6, 0, 0, 7, 7, 13 | 4, 4, 0, 0, 4, 4, 0, 0 14 | }; 15 | 16 | SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 17 | { 18 | SizeT i; 19 | if (size < 16) 20 | return 0; 21 | size -= 16; 22 | for (i = 0; i <= size; i += 16) 23 | { 24 | UInt32 instrTemplate = data[i] & 0x1F; 25 | UInt32 mask = kBranchTable[instrTemplate]; 26 | UInt32 bitPos = 5; 27 | int slot; 28 | for (slot = 0; slot < 3; slot++, bitPos += 41) 29 | { 30 | UInt32 bytePos, bitRes; 31 | UInt64 instruction, instNorm; 32 | int j; 33 | if (((mask >> slot) & 1) == 0) 34 | continue; 35 | bytePos = (bitPos >> 3); 36 | bitRes = bitPos & 0x7; 37 | instruction = 0; 38 | for (j = 0; j < 6; j++) 39 | instruction += (UInt64)data[i + j + bytePos] << (8 * j); 40 | 41 | instNorm = instruction >> bitRes; 42 | if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0) 43 | { 44 | UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF); 45 | UInt32 dest; 46 | src |= ((UInt32)(instNorm >> 36) & 1) << 20; 47 | 48 | src <<= 4; 49 | 50 | if (encoding) 51 | dest = ip + (UInt32)i + src; 52 | else 53 | dest = src - (ip + (UInt32)i); 54 | 55 | dest >>= 4; 56 | 57 | instNorm &= ~((UInt64)(0x8FFFFF) << 13); 58 | instNorm |= ((UInt64)(dest & 0xFFFFF) << 13); 59 | instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20)); 60 | 61 | instruction &= (1 << bitRes) - 1; 62 | instruction |= (instNorm << bitRes); 63 | for (j = 0; j < 6; j++) 64 | data[i + j + bytePos] = (Byte)(instruction >> (8 * j)); 65 | } 66 | } 67 | } 68 | return i; 69 | } 70 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Compiler.h: -------------------------------------------------------------------------------- 1 | /* Compiler.h -- Compiler ypes 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_COMPILER_H 5 | #define __7Z_COMPILER_H 6 | 7 | #ifdef _MSC_VER 8 | 9 | #ifdef UNDER_CE 10 | #define RPC_NO_WINDOWS_H 11 | /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */ 12 | #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union 13 | #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int 14 | #endif 15 | 16 | #if _MSC_VER >= 1300 17 | #pragma warning(disable : 4996) // This function or variable may be unsafe 18 | #else 19 | #pragma warning(disable : 4511) // copy constructor could not be generated 20 | #pragma warning(disable : 4512) // assignment operator could not be generated 21 | #pragma warning(disable : 4702) // unreachable code 22 | #pragma warning(disable : 4710) // not inlined 23 | #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information 24 | #endif 25 | 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/CpuArch.c: -------------------------------------------------------------------------------- 1 | /* CpuArch.c -- CPU specific code 2 | 2012-05-29: Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "CpuArch.h" 7 | 8 | #ifdef MY_CPU_X86_OR_AMD64 9 | 10 | #if (defined(_MSC_VER) && !defined(MY_CPU_AMD64)) || defined(__GNUC__) 11 | #define USE_ASM 12 | #endif 13 | 14 | #if !defined(USE_ASM) && _MSC_VER >= 1500 15 | #include 16 | #endif 17 | 18 | #if defined(USE_ASM) && !defined(MY_CPU_AMD64) 19 | static UInt32 CheckFlag(UInt32 flag) 20 | { 21 | #ifdef _MSC_VER 22 | __asm pushfd; 23 | __asm pop EAX; 24 | __asm mov EDX, EAX; 25 | __asm xor EAX, flag; 26 | __asm push EAX; 27 | __asm popfd; 28 | __asm pushfd; 29 | __asm pop EAX; 30 | __asm xor EAX, EDX; 31 | __asm push EDX; 32 | __asm popfd; 33 | __asm and flag, EAX; 34 | #else 35 | __asm__ __volatile__ ( 36 | "pushf\n\t" 37 | "pop %%EAX\n\t" 38 | "movl %%EAX,%%EDX\n\t" 39 | "xorl %0,%%EAX\n\t" 40 | "push %%EAX\n\t" 41 | "popf\n\t" 42 | "pushf\n\t" 43 | "pop %%EAX\n\t" 44 | "xorl %%EDX,%%EAX\n\t" 45 | "push %%EDX\n\t" 46 | "popf\n\t" 47 | "andl %%EAX, %0\n\t": 48 | "=c" (flag) : "c" (flag)); 49 | #endif 50 | return flag; 51 | } 52 | #define CHECK_CPUID_IS_SUPPORTED if (CheckFlag(1 << 18) == 0 || CheckFlag(1 << 21) == 0) return False; 53 | #else 54 | #define CHECK_CPUID_IS_SUPPORTED 55 | #endif 56 | 57 | static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d) 58 | { 59 | #ifdef USE_ASM 60 | 61 | #ifdef _MSC_VER 62 | 63 | UInt32 a2, b2, c2, d2; 64 | __asm xor EBX, EBX; 65 | __asm xor ECX, ECX; 66 | __asm xor EDX, EDX; 67 | __asm mov EAX, function; 68 | __asm cpuid; 69 | __asm mov a2, EAX; 70 | __asm mov b2, EBX; 71 | __asm mov c2, ECX; 72 | __asm mov d2, EDX; 73 | 74 | *a = a2; 75 | *b = b2; 76 | *c = c2; 77 | *d = d2; 78 | 79 | #else 80 | 81 | __asm__ __volatile__ ( 82 | #if defined(MY_CPU_X86) && defined(__PIC__) 83 | "mov %%ebx, %%edi;" 84 | "cpuid;" 85 | "xchgl %%ebx, %%edi;" 86 | : "=a" (*a) , 87 | "=D" (*b) , 88 | #else 89 | "cpuid" 90 | : "=a" (*a) , 91 | "=b" (*b) , 92 | #endif 93 | "=c" (*c) , 94 | "=d" (*d) 95 | : "0" (function)) ; 96 | 97 | #endif 98 | 99 | #else 100 | 101 | int CPUInfo[4]; 102 | __cpuid(CPUInfo, function); 103 | *a = CPUInfo[0]; 104 | *b = CPUInfo[1]; 105 | *c = CPUInfo[2]; 106 | *d = CPUInfo[3]; 107 | 108 | #endif 109 | } 110 | 111 | Bool x86cpuid_CheckAndRead(Cx86cpuid *p) 112 | { 113 | CHECK_CPUID_IS_SUPPORTED 114 | MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]); 115 | MyCPUID(1, &p->ver, &p->b, &p->c, &p->d); 116 | return True; 117 | } 118 | 119 | static UInt32 kVendors[][3] = 120 | { 121 | { 0x756E6547, 0x49656E69, 0x6C65746E}, 122 | { 0x68747541, 0x69746E65, 0x444D4163}, 123 | { 0x746E6543, 0x48727561, 0x736C7561} 124 | }; 125 | 126 | int x86cpuid_GetFirm(const Cx86cpuid *p) 127 | { 128 | unsigned i; 129 | for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[i]); i++) 130 | { 131 | const UInt32 *v = kVendors[i]; 132 | if (v[0] == p->vendor[0] && 133 | v[1] == p->vendor[1] && 134 | v[2] == p->vendor[2]) 135 | return (int)i; 136 | } 137 | return -1; 138 | } 139 | 140 | Bool CPU_Is_InOrder() 141 | { 142 | Cx86cpuid p; 143 | int firm; 144 | UInt32 family, model; 145 | if (!x86cpuid_CheckAndRead(&p)) 146 | return True; 147 | family = x86cpuid_GetFamily(&p); 148 | model = x86cpuid_GetModel(&p); 149 | firm = x86cpuid_GetFirm(&p); 150 | switch (firm) 151 | { 152 | case CPU_FIRM_INTEL: return (family < 6 || (family == 6 && ( 153 | /* Atom CPU */ 154 | model == 0x100C /* 45 nm, N4xx, D4xx, N5xx, D5xx, 230, 330 */ 155 | || model == 0x2006 /* 45 nm, Z6xx */ 156 | || model == 0x2007 /* 32 nm, Z2460 */ 157 | || model == 0x3005 /* 32 nm, Z2760 */ 158 | || model == 0x3006 /* 32 nm, N2xxx, D2xxx */ 159 | ))); 160 | case CPU_FIRM_AMD: return (family < 5 || (family == 5 && (model < 6 || model == 0xA))); 161 | case CPU_FIRM_VIA: return (family < 6 || (family == 6 && model < 0xF)); 162 | } 163 | return True; 164 | } 165 | 166 | #if !defined(MY_CPU_AMD64) && defined(_WIN32) 167 | #include 168 | static Bool CPU_Sys_Is_SSE_Supported() 169 | { 170 | OSVERSIONINFO vi; 171 | vi.dwOSVersionInfoSize = sizeof(vi); 172 | if (!GetVersionEx(&vi)) 173 | return False; 174 | return (vi.dwMajorVersion >= 5); 175 | } 176 | #define CHECK_SYS_SSE_SUPPORT if (!CPU_Sys_Is_SSE_Supported()) return False; 177 | #else 178 | #define CHECK_SYS_SSE_SUPPORT 179 | #endif 180 | 181 | Bool CPU_Is_Aes_Supported() 182 | { 183 | Cx86cpuid p; 184 | CHECK_SYS_SSE_SUPPORT 185 | if (!x86cpuid_CheckAndRead(&p)) 186 | return False; 187 | return (p.c >> 25) & 1; 188 | } 189 | 190 | #endif 191 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/CpuArch.h: -------------------------------------------------------------------------------- 1 | /* CpuArch.h -- CPU specific code 2 | 2013-11-12: Igor Pavlov : Public domain */ 3 | 4 | #ifndef __CPU_ARCH_H 5 | #define __CPU_ARCH_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | /* 12 | MY_CPU_LE means that CPU is LITTLE ENDIAN. 13 | If MY_CPU_LE is not defined, we don't know about that property of platform (it can be LITTLE ENDIAN). 14 | 15 | MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses. 16 | If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of platform. 17 | */ 18 | 19 | #if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) 20 | #define MY_CPU_AMD64 21 | #endif 22 | 23 | #if defined(MY_CPU_AMD64) || defined(_M_IA64) 24 | #define MY_CPU_64BIT 25 | #endif 26 | 27 | #if defined(_M_IX86) || defined(__i386__) 28 | #define MY_CPU_X86 29 | #endif 30 | 31 | #if defined(MY_CPU_X86) || defined(MY_CPU_AMD64) 32 | #define MY_CPU_X86_OR_AMD64 33 | #endif 34 | 35 | #if defined(MY_CPU_X86) || defined(_M_ARM) 36 | #define MY_CPU_32BIT 37 | #endif 38 | 39 | #if defined(_WIN32) && defined(_M_ARM) 40 | #define MY_CPU_ARM_LE 41 | #endif 42 | 43 | #if defined(_WIN32) && defined(_M_IA64) 44 | #define MY_CPU_IA64_LE 45 | #endif 46 | 47 | #if defined(MY_CPU_X86_OR_AMD64) 48 | #define MY_CPU_LE_UNALIGN 49 | #endif 50 | 51 | #if defined(MY_CPU_X86_OR_AMD64) || defined(MY_CPU_ARM_LE) || defined(MY_CPU_IA64_LE) || defined(__ARMEL__) || defined(__MIPSEL__) || defined(__LITTLE_ENDIAN__) 52 | #define MY_CPU_LE 53 | #endif 54 | 55 | #if defined(__BIG_ENDIAN__) || defined(__m68k__) || defined(__ARMEB__) || defined(__MIPSEB__) 56 | #define MY_CPU_BE 57 | #endif 58 | 59 | #if defined(MY_CPU_LE) && defined(MY_CPU_BE) 60 | Stop_Compiling_Bad_Endian 61 | #endif 62 | 63 | #ifdef MY_CPU_LE_UNALIGN 64 | 65 | #define GetUi16(p) (*(const UInt16 *)(const void *)(p)) 66 | #define GetUi32(p) (*(const UInt32 *)(const void *)(p)) 67 | #define GetUi64(p) (*(const UInt64 *)(const void *)(p)) 68 | #define SetUi16(p, d) *(UInt16 *)(p) = (d); 69 | #define SetUi32(p, d) *(UInt32 *)(p) = (d); 70 | #define SetUi64(p, d) *(UInt64 *)(p) = (d); 71 | 72 | #else 73 | 74 | #define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8)) 75 | 76 | #define GetUi32(p) ( \ 77 | ((const Byte *)(p))[0] | \ 78 | ((UInt32)((const Byte *)(p))[1] << 8) | \ 79 | ((UInt32)((const Byte *)(p))[2] << 16) | \ 80 | ((UInt32)((const Byte *)(p))[3] << 24)) 81 | 82 | #define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32)) 83 | 84 | #define SetUi16(p, d) { UInt32 _x_ = (d); \ 85 | ((Byte *)(p))[0] = (Byte)_x_; \ 86 | ((Byte *)(p))[1] = (Byte)(_x_ >> 8); } 87 | 88 | #define SetUi32(p, d) { UInt32 _x_ = (d); \ 89 | ((Byte *)(p))[0] = (Byte)_x_; \ 90 | ((Byte *)(p))[1] = (Byte)(_x_ >> 8); \ 91 | ((Byte *)(p))[2] = (Byte)(_x_ >> 16); \ 92 | ((Byte *)(p))[3] = (Byte)(_x_ >> 24); } 93 | 94 | #define SetUi64(p, d) { UInt64 _x64_ = (d); \ 95 | SetUi32(p, (UInt32)_x64_); \ 96 | SetUi32(((Byte *)(p)) + 4, (UInt32)(_x64_ >> 32)); } 97 | 98 | #endif 99 | 100 | #if defined(MY_CPU_LE_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300) 101 | 102 | #include 103 | 104 | #pragma intrinsic(_byteswap_ulong) 105 | #pragma intrinsic(_byteswap_uint64) 106 | #define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p)) 107 | #define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p)) 108 | 109 | #else 110 | 111 | #define GetBe32(p) ( \ 112 | ((UInt32)((const Byte *)(p))[0] << 24) | \ 113 | ((UInt32)((const Byte *)(p))[1] << 16) | \ 114 | ((UInt32)((const Byte *)(p))[2] << 8) | \ 115 | ((const Byte *)(p))[3] ) 116 | 117 | #define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4)) 118 | 119 | #endif 120 | 121 | #define GetBe16(p) ((UInt16)(((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])) 122 | 123 | 124 | #ifdef MY_CPU_X86_OR_AMD64 125 | 126 | typedef struct 127 | { 128 | UInt32 maxFunc; 129 | UInt32 vendor[3]; 130 | UInt32 ver; 131 | UInt32 b; 132 | UInt32 c; 133 | UInt32 d; 134 | } Cx86cpuid; 135 | 136 | enum 137 | { 138 | CPU_FIRM_INTEL, 139 | CPU_FIRM_AMD, 140 | CPU_FIRM_VIA 141 | }; 142 | 143 | Bool x86cpuid_CheckAndRead(Cx86cpuid *p); 144 | int x86cpuid_GetFirm(const Cx86cpuid *p); 145 | 146 | #define x86cpuid_GetFamily(p) (((p)->ver >> 8) & 0xFF00F) 147 | #define x86cpuid_GetModel(p) (((p)->ver >> 4) & 0xF00F) 148 | #define x86cpuid_GetStepping(p) ((p)->ver & 0xF) 149 | 150 | Bool CPU_Is_InOrder(); 151 | Bool CPU_Is_Aes_Supported(); 152 | 153 | #endif 154 | 155 | EXTERN_C_END 156 | 157 | #endif 158 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Delta.c: -------------------------------------------------------------------------------- 1 | /* Delta.c -- Delta converter 2 | 2009-05-26 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Delta.h" 7 | 8 | void Delta_Init(Byte *state) 9 | { 10 | unsigned i; 11 | for (i = 0; i < DELTA_STATE_SIZE; i++) 12 | state[i] = 0; 13 | } 14 | 15 | static void MyMemCpy(Byte *dest, const Byte *src, unsigned size) 16 | { 17 | unsigned i; 18 | for (i = 0; i < size; i++) 19 | dest[i] = src[i]; 20 | } 21 | 22 | void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size) 23 | { 24 | Byte buf[DELTA_STATE_SIZE]; 25 | unsigned j = 0; 26 | MyMemCpy(buf, state, delta); 27 | { 28 | SizeT i; 29 | for (i = 0; i < size;) 30 | { 31 | for (j = 0; j < delta && i < size; i++, j++) 32 | { 33 | Byte b = data[i]; 34 | data[i] = (Byte)(b - buf[j]); 35 | buf[j] = b; 36 | } 37 | } 38 | } 39 | if (j == delta) 40 | j = 0; 41 | MyMemCpy(state, buf + j, delta - j); 42 | MyMemCpy(state + delta - j, buf, j); 43 | } 44 | 45 | void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size) 46 | { 47 | Byte buf[DELTA_STATE_SIZE]; 48 | unsigned j = 0; 49 | MyMemCpy(buf, state, delta); 50 | { 51 | SizeT i; 52 | for (i = 0; i < size;) 53 | { 54 | for (j = 0; j < delta && i < size; i++, j++) 55 | { 56 | buf[j] = data[i] = (Byte)(buf[j] + data[i]); 57 | } 58 | } 59 | } 60 | if (j == delta) 61 | j = 0; 62 | MyMemCpy(state, buf + j, delta - j); 63 | MyMemCpy(state + delta - j, buf, j); 64 | } 65 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Delta.h: -------------------------------------------------------------------------------- 1 | /* Delta.h -- Delta converter 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __DELTA_H 5 | #define __DELTA_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define DELTA_STATE_SIZE 256 12 | 13 | void Delta_Init(Byte *state); 14 | void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size); 15 | void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size); 16 | 17 | EXTERN_C_END 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/LzFind.h: -------------------------------------------------------------------------------- 1 | /* LzFind.h -- Match finder for LZ algorithms 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZ_FIND_H 5 | #define __LZ_FIND_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | typedef UInt32 CLzRef; 12 | 13 | typedef struct _CMatchFinder 14 | { 15 | Byte *buffer; 16 | UInt32 pos; 17 | UInt32 posLimit; 18 | UInt32 streamPos; 19 | UInt32 lenLimit; 20 | 21 | UInt32 cyclicBufferPos; 22 | UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ 23 | 24 | UInt32 matchMaxLen; 25 | CLzRef *hash; 26 | CLzRef *son; 27 | UInt32 hashMask; 28 | UInt32 cutValue; 29 | 30 | Byte *bufferBase; 31 | ISeqInStream *stream; 32 | int streamEndWasReached; 33 | 34 | UInt32 blockSize; 35 | UInt32 keepSizeBefore; 36 | UInt32 keepSizeAfter; 37 | 38 | UInt32 numHashBytes; 39 | int directInput; 40 | size_t directInputRem; 41 | int btMode; 42 | int bigHash; 43 | UInt32 historySize; 44 | UInt32 fixedHashSize; 45 | UInt32 hashSizeSum; 46 | UInt32 numSons; 47 | SRes result; 48 | UInt32 crc[256]; 49 | } CMatchFinder; 50 | 51 | #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer) 52 | #define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)]) 53 | 54 | #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos) 55 | 56 | int MatchFinder_NeedMove(CMatchFinder *p); 57 | Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); 58 | void MatchFinder_MoveBlock(CMatchFinder *p); 59 | void MatchFinder_ReadIfRequired(CMatchFinder *p); 60 | 61 | void MatchFinder_Construct(CMatchFinder *p); 62 | 63 | /* Conditions: 64 | historySize <= 3 GB 65 | keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB 66 | */ 67 | int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, 68 | UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, 69 | ISzAlloc *alloc); 70 | void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc); 71 | void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems); 72 | void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); 73 | 74 | UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, 75 | UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, 76 | UInt32 *distances, UInt32 maxLen); 77 | 78 | /* 79 | Conditions: 80 | Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func. 81 | Mf_GetPointerToCurrentPos_Func's result must be used only before any other function 82 | */ 83 | 84 | typedef void (*Mf_Init_Func)(void *object); 85 | typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index); 86 | typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); 87 | typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); 88 | typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances); 89 | typedef void (*Mf_Skip_Func)(void *object, UInt32); 90 | 91 | typedef struct _IMatchFinder 92 | { 93 | Mf_Init_Func Init; 94 | Mf_GetIndexByte_Func GetIndexByte; 95 | Mf_GetNumAvailableBytes_Func GetNumAvailableBytes; 96 | Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos; 97 | Mf_GetMatches_Func GetMatches; 98 | Mf_Skip_Func Skip; 99 | } IMatchFinder; 100 | 101 | void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable); 102 | 103 | void MatchFinder_Init(CMatchFinder *p); 104 | UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); 105 | UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); 106 | void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); 107 | void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); 108 | 109 | EXTERN_C_END 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/LzFindMt.h: -------------------------------------------------------------------------------- 1 | /* LzFindMt.h -- multithreaded Match finder for LZ algorithms 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZ_FIND_MT_H 5 | #define __LZ_FIND_MT_H 6 | 7 | #include "LzFind.h" 8 | #include "Threads.h" 9 | 10 | EXTERN_C_BEGIN 11 | 12 | #define kMtHashBlockSize (1 << 13) 13 | #define kMtHashNumBlocks (1 << 3) 14 | #define kMtHashNumBlocksMask (kMtHashNumBlocks - 1) 15 | 16 | #define kMtBtBlockSize (1 << 14) 17 | #define kMtBtNumBlocks (1 << 6) 18 | #define kMtBtNumBlocksMask (kMtBtNumBlocks - 1) 19 | 20 | typedef struct _CMtSync 21 | { 22 | Bool wasCreated; 23 | Bool needStart; 24 | Bool exit; 25 | Bool stopWriting; 26 | 27 | CThread thread; 28 | CAutoResetEvent canStart; 29 | CAutoResetEvent wasStarted; 30 | CAutoResetEvent wasStopped; 31 | CSemaphore freeSemaphore; 32 | CSemaphore filledSemaphore; 33 | Bool csWasInitialized; 34 | Bool csWasEntered; 35 | CCriticalSection cs; 36 | UInt32 numProcessedBlocks; 37 | } CMtSync; 38 | 39 | typedef UInt32 * (*Mf_Mix_Matches)(void *p, UInt32 matchMinPos, UInt32 *distances); 40 | 41 | /* kMtCacheLineDummy must be >= size_of_CPU_cache_line */ 42 | #define kMtCacheLineDummy 128 43 | 44 | typedef void (*Mf_GetHeads)(const Byte *buffer, UInt32 pos, 45 | UInt32 *hash, UInt32 hashMask, UInt32 *heads, UInt32 numHeads, const UInt32 *crc); 46 | 47 | typedef struct _CMatchFinderMt 48 | { 49 | /* LZ */ 50 | const Byte *pointerToCurPos; 51 | UInt32 *btBuf; 52 | UInt32 btBufPos; 53 | UInt32 btBufPosLimit; 54 | UInt32 lzPos; 55 | UInt32 btNumAvailBytes; 56 | 57 | UInt32 *hash; 58 | UInt32 fixedHashSize; 59 | UInt32 historySize; 60 | const UInt32 *crc; 61 | 62 | Mf_Mix_Matches MixMatchesFunc; 63 | 64 | /* LZ + BT */ 65 | CMtSync btSync; 66 | Byte btDummy[kMtCacheLineDummy]; 67 | 68 | /* BT */ 69 | UInt32 *hashBuf; 70 | UInt32 hashBufPos; 71 | UInt32 hashBufPosLimit; 72 | UInt32 hashNumAvail; 73 | 74 | CLzRef *son; 75 | UInt32 matchMaxLen; 76 | UInt32 numHashBytes; 77 | UInt32 pos; 78 | Byte *buffer; 79 | UInt32 cyclicBufferPos; 80 | UInt32 cyclicBufferSize; /* it must be historySize + 1 */ 81 | UInt32 cutValue; 82 | 83 | /* BT + Hash */ 84 | CMtSync hashSync; 85 | /* Byte hashDummy[kMtCacheLineDummy]; */ 86 | 87 | /* Hash */ 88 | Mf_GetHeads GetHeadsFunc; 89 | CMatchFinder *MatchFinder; 90 | } CMatchFinderMt; 91 | 92 | void MatchFinderMt_Construct(CMatchFinderMt *p); 93 | void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc); 94 | SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore, 95 | UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc); 96 | void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable); 97 | void MatchFinderMt_ReleaseStream(CMatchFinderMt *p); 98 | 99 | EXTERN_C_END 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/LzHash.h: -------------------------------------------------------------------------------- 1 | /* LzHash.h -- HASH functions for LZ algorithms 2 | 2009-02-07 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZ_HASH_H 5 | #define __LZ_HASH_H 6 | 7 | #define kHash2Size (1 << 10) 8 | #define kHash3Size (1 << 16) 9 | #define kHash4Size (1 << 20) 10 | 11 | #define kFix3HashSize (kHash2Size) 12 | #define kFix4HashSize (kHash2Size + kHash3Size) 13 | #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) 14 | 15 | #define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8); 16 | 17 | #define HASH3_CALC { \ 18 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 19 | hash2Value = temp & (kHash2Size - 1); \ 20 | hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; } 21 | 22 | #define HASH4_CALC { \ 23 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 24 | hash2Value = temp & (kHash2Size - 1); \ 25 | hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ 26 | hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; } 27 | 28 | #define HASH5_CALC { \ 29 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 30 | hash2Value = temp & (kHash2Size - 1); \ 31 | hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ 32 | hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \ 33 | hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \ 34 | hash4Value &= (kHash4Size - 1); } 35 | 36 | /* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */ 37 | #define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF; 38 | 39 | 40 | #define MT_HASH2_CALC \ 41 | hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1); 42 | 43 | #define MT_HASH3_CALC { \ 44 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 45 | hash2Value = temp & (kHash2Size - 1); \ 46 | hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); } 47 | 48 | #define MT_HASH4_CALC { \ 49 | UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ 50 | hash2Value = temp & (kHash2Size - 1); \ 51 | hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ 52 | hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Lzma2Dec.h: -------------------------------------------------------------------------------- 1 | /* Lzma2Dec.h -- LZMA2 Decoder 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA2_DEC_H 5 | #define __LZMA2_DEC_H 6 | 7 | #include "LzmaDec.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | /* ---------- State Interface ---------- */ 12 | 13 | typedef struct 14 | { 15 | CLzmaDec decoder; 16 | UInt32 packSize; 17 | UInt32 unpackSize; 18 | int state; 19 | Byte control; 20 | Bool needInitDic; 21 | Bool needInitState; 22 | Bool needInitProp; 23 | } CLzma2Dec; 24 | 25 | #define Lzma2Dec_Construct(p) LzmaDec_Construct(&(p)->decoder) 26 | #define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc); 27 | #define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc); 28 | 29 | SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc); 30 | SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc); 31 | void Lzma2Dec_Init(CLzma2Dec *p); 32 | 33 | 34 | /* 35 | finishMode: 36 | It has meaning only if the decoding reaches output limit (*destLen or dicLimit). 37 | LZMA_FINISH_ANY - use smallest number of input bytes 38 | LZMA_FINISH_END - read EndOfStream marker after decoding 39 | 40 | Returns: 41 | SZ_OK 42 | status: 43 | LZMA_STATUS_FINISHED_WITH_MARK 44 | LZMA_STATUS_NOT_FINISHED 45 | LZMA_STATUS_NEEDS_MORE_INPUT 46 | SZ_ERROR_DATA - Data error 47 | */ 48 | 49 | SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, 50 | const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); 51 | 52 | SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, 53 | const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); 54 | 55 | 56 | /* ---------- One Call Interface ---------- */ 57 | 58 | /* 59 | finishMode: 60 | It has meaning only if the decoding reaches output limit (*destLen). 61 | LZMA_FINISH_ANY - use smallest number of input bytes 62 | LZMA_FINISH_END - read EndOfStream marker after decoding 63 | 64 | Returns: 65 | SZ_OK 66 | status: 67 | LZMA_STATUS_FINISHED_WITH_MARK 68 | LZMA_STATUS_NOT_FINISHED 69 | SZ_ERROR_DATA - Data error 70 | SZ_ERROR_MEM - Memory allocation error 71 | SZ_ERROR_UNSUPPORTED - Unsupported properties 72 | SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). 73 | */ 74 | 75 | SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, 76 | Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc); 77 | 78 | EXTERN_C_END 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Lzma2Enc.h: -------------------------------------------------------------------------------- 1 | /* Lzma2Enc.h -- LZMA2 Encoder 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA2_ENC_H 5 | #define __LZMA2_ENC_H 6 | 7 | #include "LzmaEnc.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | typedef struct 12 | { 13 | CLzmaEncProps lzmaProps; 14 | size_t blockSize; 15 | int numBlockThreads; 16 | int numTotalThreads; 17 | } CLzma2EncProps; 18 | 19 | void Lzma2EncProps_Init(CLzma2EncProps *p); 20 | void Lzma2EncProps_Normalize(CLzma2EncProps *p); 21 | 22 | /* ---------- CLzmaEnc2Handle Interface ---------- */ 23 | 24 | /* Lzma2Enc_* functions can return the following exit codes: 25 | Returns: 26 | SZ_OK - OK 27 | SZ_ERROR_MEM - Memory allocation error 28 | SZ_ERROR_PARAM - Incorrect paramater in props 29 | SZ_ERROR_WRITE - Write callback error 30 | SZ_ERROR_PROGRESS - some break from progress callback 31 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 32 | */ 33 | 34 | typedef void * CLzma2EncHandle; 35 | 36 | CLzma2EncHandle Lzma2Enc_Create(ISzAlloc *alloc, ISzAlloc *allocBig); 37 | void Lzma2Enc_Destroy(CLzma2EncHandle p); 38 | SRes Lzma2Enc_SetProps(CLzma2EncHandle p, const CLzma2EncProps *props); 39 | Byte Lzma2Enc_WriteProperties(CLzma2EncHandle p); 40 | SRes Lzma2Enc_Encode(CLzma2EncHandle p, 41 | ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress); 42 | 43 | /* ---------- One Call Interface ---------- */ 44 | 45 | /* Lzma2Encode 46 | Return code: 47 | SZ_OK - OK 48 | SZ_ERROR_MEM - Memory allocation error 49 | SZ_ERROR_PARAM - Incorrect paramater 50 | SZ_ERROR_OUTPUT_EOF - output buffer overflow 51 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 52 | */ 53 | 54 | /* 55 | SRes Lzma2Encode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, 56 | const CLzmaEncProps *props, Byte *propsEncoded, int writeEndMark, 57 | ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); 58 | */ 59 | 60 | EXTERN_C_END 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Lzma86.h: -------------------------------------------------------------------------------- 1 | /* Lzma86.h -- LZMA + x86 (BCJ) Filter 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA86_H 5 | #define __LZMA86_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define LZMA86_SIZE_OFFSET (1 + 5) 12 | #define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8) 13 | 14 | /* 15 | It's an example for LZMA + x86 Filter use. 16 | You can use .lzma86 extension, if you write that stream to file. 17 | .lzma86 header adds one additional byte to standard .lzma header. 18 | .lzma86 header (14 bytes): 19 | Offset Size Description 20 | 0 1 = 0 - no filter, pure LZMA 21 | = 1 - x86 filter + LZMA 22 | 1 1 lc, lp and pb in encoded form 23 | 2 4 dictSize (little endian) 24 | 6 8 uncompressed size (little endian) 25 | 26 | 27 | Lzma86_Encode 28 | ------------- 29 | level - compression level: 0 <= level <= 9, the default value for "level" is 5. 30 | 31 | dictSize - The dictionary size in bytes. The maximum value is 32 | 128 MB = (1 << 27) bytes for 32-bit version 33 | 1 GB = (1 << 30) bytes for 64-bit version 34 | The default value is 16 MB = (1 << 24) bytes, for level = 5. 35 | It's recommended to use the dictionary that is larger than 4 KB and 36 | that can be calculated as (1 << N) or (3 << N) sizes. 37 | For better compression ratio dictSize must be >= inSize. 38 | 39 | filterMode: 40 | SZ_FILTER_NO - no Filter 41 | SZ_FILTER_YES - x86 Filter 42 | SZ_FILTER_AUTO - it tries both alternatives to select best. 43 | Encoder will use 2 or 3 passes: 44 | 2 passes when FILTER_NO provides better compression. 45 | 3 passes when FILTER_YES provides better compression. 46 | 47 | Lzma86Encode allocates Data with MyAlloc functions. 48 | RAM Requirements for compressing: 49 | RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize 50 | filterMode FilterBlockSize 51 | SZ_FILTER_NO 0 52 | SZ_FILTER_YES inSize 53 | SZ_FILTER_AUTO inSize 54 | 55 | 56 | Return code: 57 | SZ_OK - OK 58 | SZ_ERROR_MEM - Memory allocation error 59 | SZ_ERROR_PARAM - Incorrect paramater 60 | SZ_ERROR_OUTPUT_EOF - output buffer overflow 61 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 62 | */ 63 | 64 | enum ESzFilterMode 65 | { 66 | SZ_FILTER_NO, 67 | SZ_FILTER_YES, 68 | SZ_FILTER_AUTO 69 | }; 70 | 71 | SRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, 72 | int level, UInt32 dictSize, int filterMode); 73 | 74 | 75 | /* 76 | Lzma86_GetUnpackSize: 77 | In: 78 | src - input data 79 | srcLen - input data size 80 | Out: 81 | unpackSize - size of uncompressed stream 82 | Return code: 83 | SZ_OK - OK 84 | SZ_ERROR_INPUT_EOF - Error in headers 85 | */ 86 | 87 | SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize); 88 | 89 | /* 90 | Lzma86_Decode: 91 | In: 92 | dest - output data 93 | destLen - output data size 94 | src - input data 95 | srcLen - input data size 96 | Out: 97 | destLen - processed output size 98 | srcLen - processed input size 99 | Return code: 100 | SZ_OK - OK 101 | SZ_ERROR_DATA - Data error 102 | SZ_ERROR_MEM - Memory allocation error 103 | SZ_ERROR_UNSUPPORTED - unsupported file 104 | SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer 105 | */ 106 | 107 | SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen); 108 | 109 | EXTERN_C_END 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Lzma86Dec.c: -------------------------------------------------------------------------------- 1 | /* Lzma86Dec.c -- LZMA + x86 (BCJ) Filter Decoder 2 | 2009-08-14 : Igor Pavlov : Public domain */ 3 | 4 | #include "Lzma86.h" 5 | 6 | #include "Alloc.h" 7 | #include "Bra.h" 8 | #include "LzmaDec.h" 9 | 10 | static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } 11 | static void SzFree(void *p, void *address) { p = p; MyFree(address); } 12 | 13 | SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize) 14 | { 15 | unsigned i; 16 | if (srcLen < LZMA86_HEADER_SIZE) 17 | return SZ_ERROR_INPUT_EOF; 18 | *unpackSize = 0; 19 | for (i = 0; i < sizeof(UInt64); i++) 20 | *unpackSize += ((UInt64)src[LZMA86_SIZE_OFFSET + i]) << (8 * i); 21 | return SZ_OK; 22 | } 23 | 24 | SRes Lzma86_Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen) 25 | { 26 | ISzAlloc g_Alloc = { SzAlloc, SzFree }; 27 | SRes res; 28 | int useFilter; 29 | SizeT inSizePure; 30 | ELzmaStatus status; 31 | 32 | if (*srcLen < LZMA86_HEADER_SIZE) 33 | return SZ_ERROR_INPUT_EOF; 34 | 35 | useFilter = src[0]; 36 | 37 | if (useFilter > 1) 38 | { 39 | *destLen = 0; 40 | return SZ_ERROR_UNSUPPORTED; 41 | } 42 | 43 | inSizePure = *srcLen - LZMA86_HEADER_SIZE; 44 | res = LzmaDecode(dest, destLen, src + LZMA86_HEADER_SIZE, &inSizePure, 45 | src + 1, LZMA_PROPS_SIZE, LZMA_FINISH_ANY, &status, &g_Alloc); 46 | *srcLen = inSizePure + LZMA86_HEADER_SIZE; 47 | if (res != SZ_OK) 48 | return res; 49 | if (useFilter == 1) 50 | { 51 | UInt32 x86State; 52 | x86_Convert_Init(x86State); 53 | x86_Convert(dest, *destLen, 0, &x86State, 0); 54 | } 55 | return SZ_OK; 56 | } 57 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Lzma86Enc.c: -------------------------------------------------------------------------------- 1 | /* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder 2 | 2009-08-14 : Igor Pavlov : Public domain */ 3 | 4 | #include 5 | 6 | #include "Lzma86.h" 7 | 8 | #include "Alloc.h" 9 | #include "Bra.h" 10 | #include "LzmaEnc.h" 11 | 12 | #define SZE_OUT_OVERFLOW SZE_DATA_ERROR 13 | 14 | static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } 15 | static void SzFree(void *p, void *address) { p = p; MyFree(address); } 16 | 17 | int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen, 18 | int level, UInt32 dictSize, int filterMode) 19 | { 20 | ISzAlloc g_Alloc = { SzAlloc, SzFree }; 21 | size_t outSize2 = *destLen; 22 | Byte *filteredStream; 23 | Bool useFilter; 24 | int mainResult = SZ_ERROR_OUTPUT_EOF; 25 | CLzmaEncProps props; 26 | LzmaEncProps_Init(&props); 27 | props.level = level; 28 | props.dictSize = dictSize; 29 | 30 | *destLen = 0; 31 | if (outSize2 < LZMA86_HEADER_SIZE) 32 | return SZ_ERROR_OUTPUT_EOF; 33 | 34 | { 35 | int i; 36 | UInt64 t = srcLen; 37 | for (i = 0; i < 8; i++, t >>= 8) 38 | dest[LZMA86_SIZE_OFFSET + i] = (Byte)t; 39 | } 40 | 41 | filteredStream = 0; 42 | useFilter = (filterMode != SZ_FILTER_NO); 43 | if (useFilter) 44 | { 45 | if (srcLen != 0) 46 | { 47 | filteredStream = (Byte *)MyAlloc(srcLen); 48 | if (filteredStream == 0) 49 | return SZ_ERROR_MEM; 50 | memcpy(filteredStream, src, srcLen); 51 | } 52 | { 53 | UInt32 x86State; 54 | x86_Convert_Init(x86State); 55 | x86_Convert(filteredStream, srcLen, 0, &x86State, 1); 56 | } 57 | } 58 | 59 | { 60 | size_t minSize = 0; 61 | Bool bestIsFiltered = False; 62 | 63 | /* passes for SZ_FILTER_AUTO: 64 | 0 - BCJ + LZMA 65 | 1 - LZMA 66 | 2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better. 67 | */ 68 | int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1; 69 | 70 | int i; 71 | for (i = 0; i < numPasses; i++) 72 | { 73 | size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE; 74 | size_t outPropsSize = 5; 75 | SRes curRes; 76 | Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1); 77 | if (curModeIsFiltered && !bestIsFiltered) 78 | break; 79 | if (useFilter && i == 0) 80 | curModeIsFiltered = True; 81 | 82 | curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed, 83 | curModeIsFiltered ? filteredStream : src, srcLen, 84 | &props, dest + 1, &outPropsSize, 0, 85 | NULL, &g_Alloc, &g_Alloc); 86 | 87 | if (curRes != SZ_ERROR_OUTPUT_EOF) 88 | { 89 | if (curRes != SZ_OK) 90 | { 91 | mainResult = curRes; 92 | break; 93 | } 94 | if (outSizeProcessed <= minSize || mainResult != SZ_OK) 95 | { 96 | minSize = outSizeProcessed; 97 | bestIsFiltered = curModeIsFiltered; 98 | mainResult = SZ_OK; 99 | } 100 | } 101 | } 102 | dest[0] = (Byte)(bestIsFiltered ? 1 : 0); 103 | *destLen = LZMA86_HEADER_SIZE + minSize; 104 | } 105 | if (useFilter) 106 | MyFree(filteredStream); 107 | return mainResult; 108 | } 109 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/LzmaDec.h: -------------------------------------------------------------------------------- 1 | /* LzmaDec.h -- LZMA Decoder 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA_DEC_H 5 | #define __LZMA_DEC_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | /* #define _LZMA_PROB32 */ 12 | /* _LZMA_PROB32 can increase the speed on some CPUs, 13 | but memory usage for CLzmaDec::probs will be doubled in that case */ 14 | 15 | #ifdef _LZMA_PROB32 16 | #define CLzmaProb UInt32 17 | #else 18 | #define CLzmaProb UInt16 19 | #endif 20 | 21 | 22 | /* ---------- LZMA Properties ---------- */ 23 | 24 | #define LZMA_PROPS_SIZE 5 25 | 26 | typedef struct _CLzmaProps 27 | { 28 | unsigned lc, lp, pb; 29 | UInt32 dicSize; 30 | } CLzmaProps; 31 | 32 | /* LzmaProps_Decode - decodes properties 33 | Returns: 34 | SZ_OK 35 | SZ_ERROR_UNSUPPORTED - Unsupported properties 36 | */ 37 | 38 | SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size); 39 | 40 | 41 | /* ---------- LZMA Decoder state ---------- */ 42 | 43 | /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case. 44 | Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */ 45 | 46 | #define LZMA_REQUIRED_INPUT_MAX 20 47 | 48 | typedef struct 49 | { 50 | CLzmaProps prop; 51 | CLzmaProb *probs; 52 | Byte *dic; 53 | const Byte *buf; 54 | UInt32 range, code; 55 | SizeT dicPos; 56 | SizeT dicBufSize; 57 | UInt32 processedPos; 58 | UInt32 checkDicSize; 59 | unsigned state; 60 | UInt32 reps[4]; 61 | unsigned remainLen; 62 | int needFlush; 63 | int needInitState; 64 | UInt32 numProbs; 65 | unsigned tempBufSize; 66 | Byte tempBuf[LZMA_REQUIRED_INPUT_MAX]; 67 | } CLzmaDec; 68 | 69 | #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; } 70 | 71 | void LzmaDec_Init(CLzmaDec *p); 72 | 73 | /* There are two types of LZMA streams: 74 | 0) Stream with end mark. That end mark adds about 6 bytes to compressed size. 75 | 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */ 76 | 77 | typedef enum 78 | { 79 | LZMA_FINISH_ANY, /* finish at any point */ 80 | LZMA_FINISH_END /* block must be finished at the end */ 81 | } ELzmaFinishMode; 82 | 83 | /* ELzmaFinishMode has meaning only if the decoding reaches output limit !!! 84 | 85 | You must use LZMA_FINISH_END, when you know that current output buffer 86 | covers last bytes of block. In other cases you must use LZMA_FINISH_ANY. 87 | 88 | If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK, 89 | and output value of destLen will be less than output buffer size limit. 90 | You can check status result also. 91 | 92 | You can use multiple checks to test data integrity after full decompression: 93 | 1) Check Result and "status" variable. 94 | 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize. 95 | 3) Check that output(srcLen) = compressedSize, if you know real compressedSize. 96 | You must use correct finish mode in that case. */ 97 | 98 | typedef enum 99 | { 100 | LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */ 101 | LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */ 102 | LZMA_STATUS_NOT_FINISHED, /* stream was not finished */ 103 | LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */ 104 | LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */ 105 | } ELzmaStatus; 106 | 107 | /* ELzmaStatus is used only as output value for function call */ 108 | 109 | 110 | /* ---------- Interfaces ---------- */ 111 | 112 | /* There are 3 levels of interfaces: 113 | 1) Dictionary Interface 114 | 2) Buffer Interface 115 | 3) One Call Interface 116 | You can select any of these interfaces, but don't mix functions from different 117 | groups for same object. */ 118 | 119 | 120 | /* There are two variants to allocate state for Dictionary Interface: 121 | 1) LzmaDec_Allocate / LzmaDec_Free 122 | 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs 123 | You can use variant 2, if you set dictionary buffer manually. 124 | For Buffer Interface you must always use variant 1. 125 | 126 | LzmaDec_Allocate* can return: 127 | SZ_OK 128 | SZ_ERROR_MEM - Memory allocation error 129 | SZ_ERROR_UNSUPPORTED - Unsupported properties 130 | */ 131 | 132 | SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc); 133 | void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc); 134 | 135 | SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc); 136 | void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc); 137 | 138 | /* ---------- Dictionary Interface ---------- */ 139 | 140 | /* You can use it, if you want to eliminate the overhead for data copying from 141 | dictionary to some other external buffer. 142 | You must work with CLzmaDec variables directly in this interface. 143 | 144 | STEPS: 145 | LzmaDec_Constr() 146 | LzmaDec_Allocate() 147 | for (each new stream) 148 | { 149 | LzmaDec_Init() 150 | while (it needs more decompression) 151 | { 152 | LzmaDec_DecodeToDic() 153 | use data from CLzmaDec::dic and update CLzmaDec::dicPos 154 | } 155 | } 156 | LzmaDec_Free() 157 | */ 158 | 159 | /* LzmaDec_DecodeToDic 160 | 161 | The decoding to internal dictionary buffer (CLzmaDec::dic). 162 | You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!! 163 | 164 | finishMode: 165 | It has meaning only if the decoding reaches output limit (dicLimit). 166 | LZMA_FINISH_ANY - Decode just dicLimit bytes. 167 | LZMA_FINISH_END - Stream must be finished after dicLimit. 168 | 169 | Returns: 170 | SZ_OK 171 | status: 172 | LZMA_STATUS_FINISHED_WITH_MARK 173 | LZMA_STATUS_NOT_FINISHED 174 | LZMA_STATUS_NEEDS_MORE_INPUT 175 | LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK 176 | SZ_ERROR_DATA - Data error 177 | */ 178 | 179 | SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, 180 | const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); 181 | 182 | 183 | /* ---------- Buffer Interface ---------- */ 184 | 185 | /* It's zlib-like interface. 186 | See LzmaDec_DecodeToDic description for information about STEPS and return results, 187 | but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need 188 | to work with CLzmaDec variables manually. 189 | 190 | finishMode: 191 | It has meaning only if the decoding reaches output limit (*destLen). 192 | LZMA_FINISH_ANY - Decode just destLen bytes. 193 | LZMA_FINISH_END - Stream must be finished after (*destLen). 194 | */ 195 | 196 | SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, 197 | const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); 198 | 199 | 200 | /* ---------- One Call Interface ---------- */ 201 | 202 | /* LzmaDecode 203 | 204 | finishMode: 205 | It has meaning only if the decoding reaches output limit (*destLen). 206 | LZMA_FINISH_ANY - Decode just destLen bytes. 207 | LZMA_FINISH_END - Stream must be finished after (*destLen). 208 | 209 | Returns: 210 | SZ_OK 211 | status: 212 | LZMA_STATUS_FINISHED_WITH_MARK 213 | LZMA_STATUS_NOT_FINISHED 214 | LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK 215 | SZ_ERROR_DATA - Data error 216 | SZ_ERROR_MEM - Memory allocation error 217 | SZ_ERROR_UNSUPPORTED - Unsupported properties 218 | SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). 219 | */ 220 | 221 | SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, 222 | const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, 223 | ELzmaStatus *status, ISzAlloc *alloc); 224 | 225 | EXTERN_C_END 226 | 227 | #endif 228 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/LzmaEnc.h: -------------------------------------------------------------------------------- 1 | /* LzmaEnc.h -- LZMA Encoder 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA_ENC_H 5 | #define __LZMA_ENC_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define LZMA_PROPS_SIZE 5 12 | 13 | typedef struct _CLzmaEncProps 14 | { 15 | int level; /* 0 <= level <= 9 */ 16 | UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version 17 | (1 << 12) <= dictSize <= (1 << 30) for 64-bit version 18 | default = (1 << 24) */ 19 | UInt64 reduceSize; /* estimated size of data that will be compressed. default = 0xFFFFFFFF. 20 | Encoder uses this value to reduce dictionary size */ 21 | int lc; /* 0 <= lc <= 8, default = 3 */ 22 | int lp; /* 0 <= lp <= 4, default = 0 */ 23 | int pb; /* 0 <= pb <= 4, default = 2 */ 24 | int algo; /* 0 - fast, 1 - normal, default = 1 */ 25 | int fb; /* 5 <= fb <= 273, default = 32 */ 26 | int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */ 27 | int numHashBytes; /* 2, 3 or 4, default = 4 */ 28 | UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */ 29 | unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */ 30 | int numThreads; /* 1 or 2, default = 2 */ 31 | } CLzmaEncProps; 32 | 33 | void LzmaEncProps_Init(CLzmaEncProps *p); 34 | void LzmaEncProps_Normalize(CLzmaEncProps *p); 35 | UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2); 36 | 37 | 38 | /* ---------- CLzmaEncHandle Interface ---------- */ 39 | 40 | /* LzmaEnc_* functions can return the following exit codes: 41 | Returns: 42 | SZ_OK - OK 43 | SZ_ERROR_MEM - Memory allocation error 44 | SZ_ERROR_PARAM - Incorrect paramater in props 45 | SZ_ERROR_WRITE - Write callback error. 46 | SZ_ERROR_PROGRESS - some break from progress callback 47 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 48 | */ 49 | 50 | typedef void * CLzmaEncHandle; 51 | 52 | CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc); 53 | void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig); 54 | SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props); 55 | SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size); 56 | SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream, 57 | ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); 58 | SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, 59 | int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); 60 | 61 | /* ---------- One Call Interface ---------- */ 62 | 63 | /* LzmaEncode 64 | Return code: 65 | SZ_OK - OK 66 | SZ_ERROR_MEM - Memory allocation error 67 | SZ_ERROR_PARAM - Incorrect paramater 68 | SZ_ERROR_OUTPUT_EOF - output buffer overflow 69 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 70 | */ 71 | 72 | SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, 73 | const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, 74 | ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); 75 | 76 | EXTERN_C_END 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/LzmaLib.c: -------------------------------------------------------------------------------- 1 | /* LzmaLib.c -- LZMA library wrapper 2 | 2008-08-05 3 | Igor Pavlov 4 | Public domain */ 5 | 6 | #include "LzmaEnc.h" 7 | #include "LzmaDec.h" 8 | #include "Alloc.h" 9 | #include "LzmaLib.h" 10 | 11 | static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } 12 | static void SzFree(void *p, void *address) { p = p; MyFree(address); } 13 | static ISzAlloc g_Alloc = { SzAlloc, SzFree }; 14 | 15 | MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, 16 | unsigned char *outProps, size_t *outPropsSize, 17 | int level, /* 0 <= level <= 9, default = 5 */ 18 | unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */ 19 | int lc, /* 0 <= lc <= 8, default = 3 */ 20 | int lp, /* 0 <= lp <= 4, default = 0 */ 21 | int pb, /* 0 <= pb <= 4, default = 2 */ 22 | int fb, /* 5 <= fb <= 273, default = 32 */ 23 | int numThreads /* 1 or 2, default = 2 */ 24 | ) 25 | { 26 | CLzmaEncProps props; 27 | LzmaEncProps_Init(&props); 28 | props.level = level; 29 | props.dictSize = dictSize; 30 | props.lc = lc; 31 | props.lp = lp; 32 | props.pb = pb; 33 | props.fb = fb; 34 | props.numThreads = numThreads; 35 | 36 | return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0, 37 | NULL, &g_Alloc, &g_Alloc); 38 | } 39 | 40 | 41 | MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen, 42 | const unsigned char *props, size_t propsSize) 43 | { 44 | ELzmaStatus status; 45 | return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc); 46 | } 47 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/LzmaLib.h: -------------------------------------------------------------------------------- 1 | /* LzmaLib.h -- LZMA library interface 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __LZMA_LIB_H 5 | #define __LZMA_LIB_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define MY_STDAPI int MY_STD_CALL 12 | 13 | #define LZMA_PROPS_SIZE 5 14 | 15 | /* 16 | RAM requirements for LZMA: 17 | for compression: (dictSize * 11.5 + 6 MB) + state_size 18 | for decompression: dictSize + state_size 19 | state_size = (4 + (1.5 << (lc + lp))) KB 20 | by default (lc=3, lp=0), state_size = 16 KB. 21 | 22 | LZMA properties (5 bytes) format 23 | Offset Size Description 24 | 0 1 lc, lp and pb in encoded form. 25 | 1 4 dictSize (little endian). 26 | */ 27 | 28 | /* 29 | LzmaCompress 30 | ------------ 31 | 32 | outPropsSize - 33 | In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5. 34 | Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5. 35 | 36 | LZMA Encoder will use defult values for any parameter, if it is 37 | -1 for any from: level, loc, lp, pb, fb, numThreads 38 | 0 for dictSize 39 | 40 | level - compression level: 0 <= level <= 9; 41 | 42 | level dictSize algo fb 43 | 0: 16 KB 0 32 44 | 1: 64 KB 0 32 45 | 2: 256 KB 0 32 46 | 3: 1 MB 0 32 47 | 4: 4 MB 0 32 48 | 5: 16 MB 1 32 49 | 6: 32 MB 1 32 50 | 7+: 64 MB 1 64 51 | 52 | The default value for "level" is 5. 53 | 54 | algo = 0 means fast method 55 | algo = 1 means normal method 56 | 57 | dictSize - The dictionary size in bytes. The maximum value is 58 | 128 MB = (1 << 27) bytes for 32-bit version 59 | 1 GB = (1 << 30) bytes for 64-bit version 60 | The default value is 16 MB = (1 << 24) bytes. 61 | It's recommended to use the dictionary that is larger than 4 KB and 62 | that can be calculated as (1 << N) or (3 << N) sizes. 63 | 64 | lc - The number of literal context bits (high bits of previous literal). 65 | It can be in the range from 0 to 8. The default value is 3. 66 | Sometimes lc=4 gives the gain for big files. 67 | 68 | lp - The number of literal pos bits (low bits of current position for literals). 69 | It can be in the range from 0 to 4. The default value is 0. 70 | The lp switch is intended for periodical data when the period is equal to 2^lp. 71 | For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's 72 | better to set lc=0, if you change lp switch. 73 | 74 | pb - The number of pos bits (low bits of current position). 75 | It can be in the range from 0 to 4. The default value is 2. 76 | The pb switch is intended for periodical data when the period is equal 2^pb. 77 | 78 | fb - Word size (the number of fast bytes). 79 | It can be in the range from 5 to 273. The default value is 32. 80 | Usually, a big number gives a little bit better compression ratio and 81 | slower compression process. 82 | 83 | numThreads - The number of thereads. 1 or 2. The default value is 2. 84 | Fast mode (algo = 0) can use only 1 thread. 85 | 86 | Out: 87 | destLen - processed output size 88 | Returns: 89 | SZ_OK - OK 90 | SZ_ERROR_MEM - Memory allocation error 91 | SZ_ERROR_PARAM - Incorrect paramater 92 | SZ_ERROR_OUTPUT_EOF - output buffer overflow 93 | SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) 94 | */ 95 | 96 | MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, 97 | unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */ 98 | int level, /* 0 <= level <= 9, default = 5 */ 99 | unsigned dictSize, /* default = (1 << 24) */ 100 | int lc, /* 0 <= lc <= 8, default = 3 */ 101 | int lp, /* 0 <= lp <= 4, default = 0 */ 102 | int pb, /* 0 <= pb <= 4, default = 2 */ 103 | int fb, /* 5 <= fb <= 273, default = 32 */ 104 | int numThreads /* 1 or 2, default = 2 */ 105 | ); 106 | 107 | /* 108 | LzmaUncompress 109 | -------------- 110 | In: 111 | dest - output data 112 | destLen - output data size 113 | src - input data 114 | srcLen - input data size 115 | Out: 116 | destLen - processed output size 117 | srcLen - processed input size 118 | Returns: 119 | SZ_OK - OK 120 | SZ_ERROR_DATA - Data error 121 | SZ_ERROR_MEM - Memory allocation arror 122 | SZ_ERROR_UNSUPPORTED - Unsupported properties 123 | SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src) 124 | */ 125 | 126 | MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen, 127 | const unsigned char *props, size_t propsSize); 128 | 129 | EXTERN_C_END 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/MtCoder.c: -------------------------------------------------------------------------------- 1 | /* MtCoder.c -- Multi-thread Coder 2 | 2010-09-24 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include 7 | 8 | #include "MtCoder.h" 9 | 10 | void LoopThread_Construct(CLoopThread *p) 11 | { 12 | Thread_Construct(&p->thread); 13 | Event_Construct(&p->startEvent); 14 | Event_Construct(&p->finishedEvent); 15 | } 16 | 17 | void LoopThread_Close(CLoopThread *p) 18 | { 19 | Thread_Close(&p->thread); 20 | Event_Close(&p->startEvent); 21 | Event_Close(&p->finishedEvent); 22 | } 23 | 24 | static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE LoopThreadFunc(void *pp) 25 | { 26 | CLoopThread *p = (CLoopThread *)pp; 27 | for (;;) 28 | { 29 | if (Event_Wait(&p->startEvent) != 0) 30 | return SZ_ERROR_THREAD; 31 | if (p->stop) 32 | return 0; 33 | p->res = p->func(p->param); 34 | if (Event_Set(&p->finishedEvent) != 0) 35 | return SZ_ERROR_THREAD; 36 | } 37 | } 38 | 39 | WRes LoopThread_Create(CLoopThread *p) 40 | { 41 | p->stop = 0; 42 | RINOK(AutoResetEvent_CreateNotSignaled(&p->startEvent)); 43 | RINOK(AutoResetEvent_CreateNotSignaled(&p->finishedEvent)); 44 | return Thread_Create(&p->thread, LoopThreadFunc, p); 45 | } 46 | 47 | WRes LoopThread_StopAndWait(CLoopThread *p) 48 | { 49 | p->stop = 1; 50 | if (Event_Set(&p->startEvent) != 0) 51 | return SZ_ERROR_THREAD; 52 | return Thread_Wait(&p->thread); 53 | } 54 | 55 | WRes LoopThread_StartSubThread(CLoopThread *p) { return Event_Set(&p->startEvent); } 56 | WRes LoopThread_WaitSubThread(CLoopThread *p) { return Event_Wait(&p->finishedEvent); } 57 | 58 | static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize) 59 | { 60 | return (p && p->Progress(p, inSize, outSize) != SZ_OK) ? SZ_ERROR_PROGRESS : SZ_OK; 61 | } 62 | 63 | static void MtProgress_Init(CMtProgress *p, ICompressProgress *progress) 64 | { 65 | unsigned i; 66 | for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++) 67 | p->inSizes[i] = p->outSizes[i] = 0; 68 | p->totalInSize = p->totalOutSize = 0; 69 | p->progress = progress; 70 | p->res = SZ_OK; 71 | } 72 | 73 | static void MtProgress_Reinit(CMtProgress *p, unsigned index) 74 | { 75 | p->inSizes[index] = 0; 76 | p->outSizes[index] = 0; 77 | } 78 | 79 | #define UPDATE_PROGRESS(size, prev, total) \ 80 | if (size != (UInt64)(Int64)-1) { total += size - prev; prev = size; } 81 | 82 | SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize) 83 | { 84 | SRes res; 85 | CriticalSection_Enter(&p->cs); 86 | UPDATE_PROGRESS(inSize, p->inSizes[index], p->totalInSize) 87 | UPDATE_PROGRESS(outSize, p->outSizes[index], p->totalOutSize) 88 | if (p->res == SZ_OK) 89 | p->res = Progress(p->progress, p->totalInSize, p->totalOutSize); 90 | res = p->res; 91 | CriticalSection_Leave(&p->cs); 92 | return res; 93 | } 94 | 95 | static void MtProgress_SetError(CMtProgress *p, SRes res) 96 | { 97 | CriticalSection_Enter(&p->cs); 98 | if (p->res == SZ_OK) 99 | p->res = res; 100 | CriticalSection_Leave(&p->cs); 101 | } 102 | 103 | static void MtCoder_SetError(CMtCoder* p, SRes res) 104 | { 105 | CriticalSection_Enter(&p->cs); 106 | if (p->res == SZ_OK) 107 | p->res = res; 108 | CriticalSection_Leave(&p->cs); 109 | } 110 | 111 | /* ---------- MtThread ---------- */ 112 | 113 | void CMtThread_Construct(CMtThread *p, CMtCoder *mtCoder) 114 | { 115 | p->mtCoder = mtCoder; 116 | p->outBuf = 0; 117 | p->inBuf = 0; 118 | Event_Construct(&p->canRead); 119 | Event_Construct(&p->canWrite); 120 | LoopThread_Construct(&p->thread); 121 | } 122 | 123 | #define RINOK_THREAD(x) { if((x) != 0) return SZ_ERROR_THREAD; } 124 | 125 | static void CMtThread_CloseEvents(CMtThread *p) 126 | { 127 | Event_Close(&p->canRead); 128 | Event_Close(&p->canWrite); 129 | } 130 | 131 | static void CMtThread_Destruct(CMtThread *p) 132 | { 133 | CMtThread_CloseEvents(p); 134 | 135 | if (Thread_WasCreated(&p->thread.thread)) 136 | { 137 | LoopThread_StopAndWait(&p->thread); 138 | LoopThread_Close(&p->thread); 139 | } 140 | 141 | if (p->mtCoder->alloc) 142 | IAlloc_Free(p->mtCoder->alloc, p->outBuf); 143 | p->outBuf = 0; 144 | 145 | if (p->mtCoder->alloc) 146 | IAlloc_Free(p->mtCoder->alloc, p->inBuf); 147 | p->inBuf = 0; 148 | } 149 | 150 | #define MY_BUF_ALLOC(buf, size, newSize) \ 151 | if (buf == 0 || size != newSize) \ 152 | { IAlloc_Free(p->mtCoder->alloc, buf); \ 153 | size = newSize; buf = (Byte *)IAlloc_Alloc(p->mtCoder->alloc, size); \ 154 | if (buf == 0) return SZ_ERROR_MEM; } 155 | 156 | static SRes CMtThread_Prepare(CMtThread *p) 157 | { 158 | MY_BUF_ALLOC(p->inBuf, p->inBufSize, p->mtCoder->blockSize) 159 | MY_BUF_ALLOC(p->outBuf, p->outBufSize, p->mtCoder->destBlockSize) 160 | 161 | p->stopReading = False; 162 | p->stopWriting = False; 163 | RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canRead)); 164 | RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canWrite)); 165 | 166 | return SZ_OK; 167 | } 168 | 169 | static SRes FullRead(ISeqInStream *stream, Byte *data, size_t *processedSize) 170 | { 171 | size_t size = *processedSize; 172 | *processedSize = 0; 173 | while (size != 0) 174 | { 175 | size_t curSize = size; 176 | SRes res = stream->Read(stream, data, &curSize); 177 | *processedSize += curSize; 178 | data += curSize; 179 | size -= curSize; 180 | RINOK(res); 181 | if (curSize == 0) 182 | return SZ_OK; 183 | } 184 | return SZ_OK; 185 | } 186 | 187 | #define GET_NEXT_THREAD(p) &p->mtCoder->threads[p->index == p->mtCoder->numThreads - 1 ? 0 : p->index + 1] 188 | 189 | static SRes MtThread_Process(CMtThread *p, Bool *stop) 190 | { 191 | CMtThread *next; 192 | *stop = True; 193 | if (Event_Wait(&p->canRead) != 0) 194 | return SZ_ERROR_THREAD; 195 | 196 | next = GET_NEXT_THREAD(p); 197 | 198 | if (p->stopReading) 199 | { 200 | next->stopReading = True; 201 | return Event_Set(&next->canRead) == 0 ? SZ_OK : SZ_ERROR_THREAD; 202 | } 203 | 204 | { 205 | size_t size = p->mtCoder->blockSize; 206 | size_t destSize = p->outBufSize; 207 | 208 | RINOK(FullRead(p->mtCoder->inStream, p->inBuf, &size)); 209 | next->stopReading = *stop = (size != p->mtCoder->blockSize); 210 | if (Event_Set(&next->canRead) != 0) 211 | return SZ_ERROR_THREAD; 212 | 213 | RINOK(p->mtCoder->mtCallback->Code(p->mtCoder->mtCallback, p->index, 214 | p->outBuf, &destSize, p->inBuf, size, *stop)); 215 | 216 | MtProgress_Reinit(&p->mtCoder->mtProgress, p->index); 217 | 218 | if (Event_Wait(&p->canWrite) != 0) 219 | return SZ_ERROR_THREAD; 220 | if (p->stopWriting) 221 | return SZ_ERROR_FAIL; 222 | if (p->mtCoder->outStream->Write(p->mtCoder->outStream, p->outBuf, destSize) != destSize) 223 | return SZ_ERROR_WRITE; 224 | return Event_Set(&next->canWrite) == 0 ? SZ_OK : SZ_ERROR_THREAD; 225 | } 226 | } 227 | 228 | static THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE ThreadFunc(void *pp) 229 | { 230 | CMtThread *p = (CMtThread *)pp; 231 | for (;;) 232 | { 233 | Bool stop; 234 | CMtThread *next = GET_NEXT_THREAD(p); 235 | SRes res = MtThread_Process(p, &stop); 236 | if (res != SZ_OK) 237 | { 238 | MtCoder_SetError(p->mtCoder, res); 239 | MtProgress_SetError(&p->mtCoder->mtProgress, res); 240 | next->stopReading = True; 241 | next->stopWriting = True; 242 | Event_Set(&next->canRead); 243 | Event_Set(&next->canWrite); 244 | return res; 245 | } 246 | if (stop) 247 | return 0; 248 | } 249 | } 250 | 251 | void MtCoder_Construct(CMtCoder* p) 252 | { 253 | unsigned i; 254 | p->alloc = 0; 255 | for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++) 256 | { 257 | CMtThread *t = &p->threads[i]; 258 | t->index = i; 259 | CMtThread_Construct(t, p); 260 | } 261 | CriticalSection_Init(&p->cs); 262 | CriticalSection_Init(&p->mtProgress.cs); 263 | } 264 | 265 | void MtCoder_Destruct(CMtCoder* p) 266 | { 267 | unsigned i; 268 | for (i = 0; i < NUM_MT_CODER_THREADS_MAX; i++) 269 | CMtThread_Destruct(&p->threads[i]); 270 | CriticalSection_Delete(&p->cs); 271 | CriticalSection_Delete(&p->mtProgress.cs); 272 | } 273 | 274 | SRes MtCoder_Code(CMtCoder *p) 275 | { 276 | unsigned i, numThreads = p->numThreads; 277 | SRes res = SZ_OK; 278 | p->res = SZ_OK; 279 | 280 | MtProgress_Init(&p->mtProgress, p->progress); 281 | 282 | for (i = 0; i < numThreads; i++) 283 | { 284 | RINOK(CMtThread_Prepare(&p->threads[i])); 285 | } 286 | 287 | for (i = 0; i < numThreads; i++) 288 | { 289 | CMtThread *t = &p->threads[i]; 290 | CLoopThread *lt = &t->thread; 291 | 292 | if (!Thread_WasCreated(<->thread)) 293 | { 294 | lt->func = ThreadFunc; 295 | lt->param = t; 296 | 297 | if (LoopThread_Create(lt) != SZ_OK) 298 | { 299 | res = SZ_ERROR_THREAD; 300 | break; 301 | } 302 | } 303 | } 304 | 305 | if (res == SZ_OK) 306 | { 307 | unsigned j; 308 | for (i = 0; i < numThreads; i++) 309 | { 310 | CMtThread *t = &p->threads[i]; 311 | if (LoopThread_StartSubThread(&t->thread) != SZ_OK) 312 | { 313 | res = SZ_ERROR_THREAD; 314 | p->threads[0].stopReading = True; 315 | break; 316 | } 317 | } 318 | 319 | Event_Set(&p->threads[0].canWrite); 320 | Event_Set(&p->threads[0].canRead); 321 | 322 | for (j = 0; j < i; j++) 323 | LoopThread_WaitSubThread(&p->threads[j].thread); 324 | } 325 | 326 | for (i = 0; i < numThreads; i++) 327 | CMtThread_CloseEvents(&p->threads[i]); 328 | return (res == SZ_OK) ? p->res : res; 329 | } 330 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/MtCoder.h: -------------------------------------------------------------------------------- 1 | /* MtCoder.h -- Multi-thread Coder 2 | 2009-11-19 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __MT_CODER_H 5 | #define __MT_CODER_H 6 | 7 | #include "Threads.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | typedef struct 12 | { 13 | CThread thread; 14 | CAutoResetEvent startEvent; 15 | CAutoResetEvent finishedEvent; 16 | int stop; 17 | 18 | THREAD_FUNC_TYPE func; 19 | LPVOID param; 20 | THREAD_FUNC_RET_TYPE res; 21 | } CLoopThread; 22 | 23 | void LoopThread_Construct(CLoopThread *p); 24 | void LoopThread_Close(CLoopThread *p); 25 | WRes LoopThread_Create(CLoopThread *p); 26 | WRes LoopThread_StopAndWait(CLoopThread *p); 27 | WRes LoopThread_StartSubThread(CLoopThread *p); 28 | WRes LoopThread_WaitSubThread(CLoopThread *p); 29 | 30 | #ifndef _7ZIP_ST 31 | #define NUM_MT_CODER_THREADS_MAX 32 32 | #else 33 | #define NUM_MT_CODER_THREADS_MAX 1 34 | #endif 35 | 36 | typedef struct 37 | { 38 | UInt64 totalInSize; 39 | UInt64 totalOutSize; 40 | ICompressProgress *progress; 41 | SRes res; 42 | CCriticalSection cs; 43 | UInt64 inSizes[NUM_MT_CODER_THREADS_MAX]; 44 | UInt64 outSizes[NUM_MT_CODER_THREADS_MAX]; 45 | } CMtProgress; 46 | 47 | SRes MtProgress_Set(CMtProgress *p, unsigned index, UInt64 inSize, UInt64 outSize); 48 | 49 | struct _CMtCoder; 50 | 51 | typedef struct 52 | { 53 | struct _CMtCoder *mtCoder; 54 | Byte *outBuf; 55 | size_t outBufSize; 56 | Byte *inBuf; 57 | size_t inBufSize; 58 | unsigned index; 59 | CLoopThread thread; 60 | 61 | Bool stopReading; 62 | Bool stopWriting; 63 | CAutoResetEvent canRead; 64 | CAutoResetEvent canWrite; 65 | } CMtThread; 66 | 67 | typedef struct 68 | { 69 | SRes (*Code)(void *p, unsigned index, Byte *dest, size_t *destSize, 70 | const Byte *src, size_t srcSize, int finished); 71 | } IMtCoderCallback; 72 | 73 | typedef struct _CMtCoder 74 | { 75 | size_t blockSize; 76 | size_t destBlockSize; 77 | unsigned numThreads; 78 | 79 | ISeqInStream *inStream; 80 | ISeqOutStream *outStream; 81 | ICompressProgress *progress; 82 | ISzAlloc *alloc; 83 | 84 | IMtCoderCallback *mtCallback; 85 | CCriticalSection cs; 86 | SRes res; 87 | 88 | CMtProgress mtProgress; 89 | CMtThread threads[NUM_MT_CODER_THREADS_MAX]; 90 | } CMtCoder; 91 | 92 | void MtCoder_Construct(CMtCoder* p); 93 | void MtCoder_Destruct(CMtCoder* p); 94 | SRes MtCoder_Code(CMtCoder *p); 95 | 96 | EXTERN_C_END 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Ppmd.h: -------------------------------------------------------------------------------- 1 | /* Ppmd.h -- PPMD codec common code 2 | 2013-01-18 : Igor Pavlov : Public domain 3 | This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 4 | 5 | #ifndef __PPMD_H 6 | #define __PPMD_H 7 | 8 | #include "CpuArch.h" 9 | 10 | EXTERN_C_BEGIN 11 | 12 | #ifdef MY_CPU_32BIT 13 | #define PPMD_32BIT 14 | #endif 15 | 16 | #define PPMD_INT_BITS 7 17 | #define PPMD_PERIOD_BITS 7 18 | #define PPMD_BIN_SCALE (1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS)) 19 | 20 | #define PPMD_GET_MEAN_SPEC(summ, shift, round) (((summ) + (1 << ((shift) - (round)))) >> (shift)) 21 | #define PPMD_GET_MEAN(summ) PPMD_GET_MEAN_SPEC((summ), PPMD_PERIOD_BITS, 2) 22 | #define PPMD_UPDATE_PROB_0(prob) ((prob) + (1 << PPMD_INT_BITS) - PPMD_GET_MEAN(prob)) 23 | #define PPMD_UPDATE_PROB_1(prob) ((prob) - PPMD_GET_MEAN(prob)) 24 | 25 | #define PPMD_N1 4 26 | #define PPMD_N2 4 27 | #define PPMD_N3 4 28 | #define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4) 29 | #define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4) 30 | 31 | #pragma pack(push, 1) 32 | /* Most compilers works OK here even without #pragma pack(push, 1), but some GCC compilers need it. */ 33 | 34 | /* SEE-contexts for PPM-contexts with masked symbols */ 35 | typedef struct 36 | { 37 | UInt16 Summ; /* Freq */ 38 | Byte Shift; /* Speed of Freq change; low Shift is for fast change */ 39 | Byte Count; /* Count to next change of Shift */ 40 | } CPpmd_See; 41 | 42 | #define Ppmd_See_Update(p) if ((p)->Shift < PPMD_PERIOD_BITS && --(p)->Count == 0) \ 43 | { (p)->Summ <<= 1; (p)->Count = (Byte)(3 << (p)->Shift++); } 44 | 45 | typedef struct 46 | { 47 | Byte Symbol; 48 | Byte Freq; 49 | UInt16 SuccessorLow; 50 | UInt16 SuccessorHigh; 51 | } CPpmd_State; 52 | 53 | #pragma pack(pop) 54 | 55 | typedef 56 | #ifdef PPMD_32BIT 57 | CPpmd_State * 58 | #else 59 | UInt32 60 | #endif 61 | CPpmd_State_Ref; 62 | 63 | typedef 64 | #ifdef PPMD_32BIT 65 | void * 66 | #else 67 | UInt32 68 | #endif 69 | CPpmd_Void_Ref; 70 | 71 | typedef 72 | #ifdef PPMD_32BIT 73 | Byte * 74 | #else 75 | UInt32 76 | #endif 77 | CPpmd_Byte_Ref; 78 | 79 | #define PPMD_SetAllBitsIn256Bytes(p) \ 80 | { unsigned i; for (i = 0; i < 256 / sizeof(p[0]); i += 8) { \ 81 | p[i+7] = p[i+6] = p[i+5] = p[i+4] = p[i+3] = p[i+2] = p[i+1] = p[i+0] = ~(size_t)0; }} 82 | 83 | EXTERN_C_END 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Ppmd7.h: -------------------------------------------------------------------------------- 1 | /* Ppmd7.h -- PPMdH compression codec 2 | 2010-03-12 : Igor Pavlov : Public domain 3 | This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 4 | 5 | /* This code supports virtual RangeDecoder and includes the implementation 6 | of RangeCoder from 7z, instead of RangeCoder from original PPMd var.H. 7 | If you need the compatibility with original PPMd var.H, you can use external RangeDecoder */ 8 | 9 | #ifndef __PPMD7_H 10 | #define __PPMD7_H 11 | 12 | #include "Ppmd.h" 13 | 14 | EXTERN_C_BEGIN 15 | 16 | #define PPMD7_MIN_ORDER 2 17 | #define PPMD7_MAX_ORDER 64 18 | 19 | #define PPMD7_MIN_MEM_SIZE (1 << 11) 20 | #define PPMD7_MAX_MEM_SIZE (0xFFFFFFFF - 12 * 3) 21 | 22 | struct CPpmd7_Context_; 23 | 24 | typedef 25 | #ifdef PPMD_32BIT 26 | struct CPpmd7_Context_ * 27 | #else 28 | UInt32 29 | #endif 30 | CPpmd7_Context_Ref; 31 | 32 | typedef struct CPpmd7_Context_ 33 | { 34 | UInt16 NumStats; 35 | UInt16 SummFreq; 36 | CPpmd_State_Ref Stats; 37 | CPpmd7_Context_Ref Suffix; 38 | } CPpmd7_Context; 39 | 40 | #define Ppmd7Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq) 41 | 42 | typedef struct 43 | { 44 | CPpmd7_Context *MinContext, *MaxContext; 45 | CPpmd_State *FoundState; 46 | unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag; 47 | Int32 RunLength, InitRL; /* must be 32-bit at least */ 48 | 49 | UInt32 Size; 50 | UInt32 GlueCount; 51 | Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart; 52 | UInt32 AlignOffset; 53 | 54 | Byte Indx2Units[PPMD_NUM_INDEXES]; 55 | Byte Units2Indx[128]; 56 | CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES]; 57 | Byte NS2Indx[256], NS2BSIndx[256], HB2Flag[256]; 58 | CPpmd_See DummySee, See[25][16]; 59 | UInt16 BinSumm[128][64]; 60 | } CPpmd7; 61 | 62 | void Ppmd7_Construct(CPpmd7 *p); 63 | Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc); 64 | void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc); 65 | void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder); 66 | #define Ppmd7_WasAllocated(p) ((p)->Base != nullptr) 67 | 68 | 69 | /* ---------- Internal Functions ---------- */ 70 | 71 | extern const Byte PPMD7_kExpEscape[16]; 72 | 73 | #ifdef PPMD_32BIT 74 | #define Ppmd7_GetPtr(p, ptr) (ptr) 75 | #define Ppmd7_GetContext(p, ptr) (ptr) 76 | #define Ppmd7_GetStats(p, ctx) ((ctx)->Stats) 77 | #else 78 | #define Ppmd7_GetPtr(p, offs) ((void *)((p)->Base + (offs))) 79 | #define Ppmd7_GetContext(p, offs) ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs))) 80 | #define Ppmd7_GetStats(p, ctx) ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats))) 81 | #endif 82 | 83 | void Ppmd7_Update1(CPpmd7 *p); 84 | void Ppmd7_Update1_0(CPpmd7 *p); 85 | void Ppmd7_Update2(CPpmd7 *p); 86 | void Ppmd7_UpdateBin(CPpmd7 *p); 87 | 88 | #define Ppmd7_GetBinSumm(p) \ 89 | &p->BinSumm[Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \ 90 | p->NS2BSIndx[Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \ 91 | (p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \ 92 | 2 * p->HB2Flag[Ppmd7Context_OneState(p->MinContext)->Symbol] + \ 93 | ((p->RunLength >> 26) & 0x20)] 94 | 95 | CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *scale); 96 | 97 | 98 | /* ---------- Decode ---------- */ 99 | 100 | typedef struct 101 | { 102 | UInt32 (*GetThreshold)(void *p, UInt32 total); 103 | void (*Decode)(void *p, UInt32 start, UInt32 size); 104 | UInt32 (*DecodeBit)(void *p, UInt32 size0); 105 | } IPpmd7_RangeDec; 106 | 107 | typedef struct 108 | { 109 | IPpmd7_RangeDec p; 110 | UInt32 Range; 111 | UInt32 Code; 112 | IByteIn *Stream; 113 | } CPpmd7z_RangeDec; 114 | 115 | void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p); 116 | Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p); 117 | #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0) 118 | 119 | int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc); 120 | 121 | 122 | /* ---------- Encode ---------- */ 123 | 124 | typedef struct 125 | { 126 | UInt64 Low; 127 | UInt32 Range; 128 | Byte Cache; 129 | UInt64 CacheSize; 130 | IByteOut *Stream; 131 | } CPpmd7z_RangeEnc; 132 | 133 | void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p); 134 | void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p); 135 | 136 | void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol); 137 | 138 | EXTERN_C_END 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Ppmd7Dec.c: -------------------------------------------------------------------------------- 1 | /* Ppmd7Dec.c -- PPMdH Decoder 2 | 2010-03-12 : Igor Pavlov : Public domain 3 | This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 4 | 5 | #include "Precomp.h" 6 | 7 | #include "Ppmd7.h" 8 | 9 | #define kTopValue (1 << 24) 10 | 11 | Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p) 12 | { 13 | unsigned i; 14 | p->Code = 0; 15 | p->Range = 0xFFFFFFFF; 16 | if (p->Stream->Read((void *)p->Stream) != 0) 17 | return False; 18 | for (i = 0; i < 4; i++) 19 | p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); 20 | return (p->Code < 0xFFFFFFFF); 21 | } 22 | 23 | static UInt32 Range_GetThreshold(void *pp, UInt32 total) 24 | { 25 | CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; 26 | return (p->Code) / (p->Range /= total); 27 | } 28 | 29 | static void Range_Normalize(CPpmd7z_RangeDec *p) 30 | { 31 | if (p->Range < kTopValue) 32 | { 33 | p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); 34 | p->Range <<= 8; 35 | if (p->Range < kTopValue) 36 | { 37 | p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); 38 | p->Range <<= 8; 39 | } 40 | } 41 | } 42 | 43 | static void Range_Decode(void *pp, UInt32 start, UInt32 size) 44 | { 45 | CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; 46 | p->Code -= start * p->Range; 47 | p->Range *= size; 48 | Range_Normalize(p); 49 | } 50 | 51 | static UInt32 Range_DecodeBit(void *pp, UInt32 size0) 52 | { 53 | CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; 54 | UInt32 newBound = (p->Range >> 14) * size0; 55 | UInt32 symbol; 56 | if (p->Code < newBound) 57 | { 58 | symbol = 0; 59 | p->Range = newBound; 60 | } 61 | else 62 | { 63 | symbol = 1; 64 | p->Code -= newBound; 65 | p->Range -= newBound; 66 | } 67 | Range_Normalize(p); 68 | return symbol; 69 | } 70 | 71 | void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p) 72 | { 73 | p->p.GetThreshold = Range_GetThreshold; 74 | p->p.Decode = Range_Decode; 75 | p->p.DecodeBit = Range_DecodeBit; 76 | } 77 | 78 | 79 | #define MASK(sym) ((signed char *)charMask)[sym] 80 | 81 | int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc) 82 | { 83 | size_t charMask[256 / sizeof(size_t)]; 84 | if (p->MinContext->NumStats != 1) 85 | { 86 | CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext); 87 | unsigned i; 88 | UInt32 count, hiCnt; 89 | if ((count = rc->GetThreshold(rc, p->MinContext->SummFreq)) < (hiCnt = s->Freq)) 90 | { 91 | Byte symbol; 92 | rc->Decode(rc, 0, s->Freq); 93 | p->FoundState = s; 94 | symbol = s->Symbol; 95 | Ppmd7_Update1_0(p); 96 | return symbol; 97 | } 98 | p->PrevSuccess = 0; 99 | i = p->MinContext->NumStats - 1; 100 | do 101 | { 102 | if ((hiCnt += (++s)->Freq) > count) 103 | { 104 | Byte symbol; 105 | rc->Decode(rc, hiCnt - s->Freq, s->Freq); 106 | p->FoundState = s; 107 | symbol = s->Symbol; 108 | Ppmd7_Update1(p); 109 | return symbol; 110 | } 111 | } 112 | while (--i); 113 | if (count >= p->MinContext->SummFreq) 114 | return -2; 115 | p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]; 116 | rc->Decode(rc, hiCnt, p->MinContext->SummFreq - hiCnt); 117 | PPMD_SetAllBitsIn256Bytes(charMask); 118 | MASK(s->Symbol) = 0; 119 | i = p->MinContext->NumStats - 1; 120 | do { MASK((--s)->Symbol) = 0; } while (--i); 121 | } 122 | else 123 | { 124 | UInt16 *prob = Ppmd7_GetBinSumm(p); 125 | if (rc->DecodeBit(rc, *prob) == 0) 126 | { 127 | Byte symbol; 128 | *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob); 129 | symbol = (p->FoundState = Ppmd7Context_OneState(p->MinContext))->Symbol; 130 | Ppmd7_UpdateBin(p); 131 | return symbol; 132 | } 133 | *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob); 134 | p->InitEsc = PPMD7_kExpEscape[*prob >> 10]; 135 | PPMD_SetAllBitsIn256Bytes(charMask); 136 | MASK(Ppmd7Context_OneState(p->MinContext)->Symbol) = 0; 137 | p->PrevSuccess = 0; 138 | } 139 | for (;;) 140 | { 141 | CPpmd_State *ps[256], *s; 142 | UInt32 freqSum, count, hiCnt; 143 | CPpmd_See *see; 144 | unsigned i, num, numMasked = p->MinContext->NumStats; 145 | do 146 | { 147 | p->OrderFall++; 148 | if (!p->MinContext->Suffix) 149 | return -1; 150 | p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix); 151 | } 152 | while (p->MinContext->NumStats == numMasked); 153 | hiCnt = 0; 154 | s = Ppmd7_GetStats(p, p->MinContext); 155 | i = 0; 156 | num = p->MinContext->NumStats - numMasked; 157 | do 158 | { 159 | int k = (int)(MASK(s->Symbol)); 160 | hiCnt += (s->Freq & k); 161 | ps[i] = s++; 162 | i -= k; 163 | } 164 | while (i != num); 165 | 166 | see = Ppmd7_MakeEscFreq(p, numMasked, &freqSum); 167 | freqSum += hiCnt; 168 | count = rc->GetThreshold(rc, freqSum); 169 | 170 | if (count < hiCnt) 171 | { 172 | Byte symbol; 173 | CPpmd_State **pps = ps; 174 | for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++); 175 | s = *pps; 176 | rc->Decode(rc, hiCnt - s->Freq, s->Freq); 177 | Ppmd_See_Update(see); 178 | p->FoundState = s; 179 | symbol = s->Symbol; 180 | Ppmd7_Update2(p); 181 | return symbol; 182 | } 183 | if (count >= freqSum) 184 | return -2; 185 | rc->Decode(rc, hiCnt, freqSum - hiCnt); 186 | see->Summ = (UInt16)(see->Summ + freqSum); 187 | do { MASK(ps[--i]->Symbol) = 0; } while (i != 0); 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Ppmd7Enc.c: -------------------------------------------------------------------------------- 1 | /* Ppmd7Enc.c -- PPMdH Encoder 2 | 2010-03-12 : Igor Pavlov : Public domain 3 | This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ 4 | 5 | #include "Precomp.h" 6 | 7 | #include "Ppmd7.h" 8 | 9 | #define kTopValue (1 << 24) 10 | 11 | void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p) 12 | { 13 | p->Low = 0; 14 | p->Range = 0xFFFFFFFF; 15 | p->Cache = 0; 16 | p->CacheSize = 1; 17 | } 18 | 19 | static void RangeEnc_ShiftLow(CPpmd7z_RangeEnc *p) 20 | { 21 | if ((UInt32)p->Low < (UInt32)0xFF000000 || (unsigned)(p->Low >> 32) != 0) 22 | { 23 | Byte temp = p->Cache; 24 | do 25 | { 26 | p->Stream->Write(p->Stream, (Byte)(temp + (Byte)(p->Low >> 32))); 27 | temp = 0xFF; 28 | } 29 | while(--p->CacheSize != 0); 30 | p->Cache = (Byte)((UInt32)p->Low >> 24); 31 | } 32 | p->CacheSize++; 33 | p->Low = (UInt32)p->Low << 8; 34 | } 35 | 36 | static void RangeEnc_Encode(CPpmd7z_RangeEnc *p, UInt32 start, UInt32 size, UInt32 total) 37 | { 38 | p->Low += start * (p->Range /= total); 39 | p->Range *= size; 40 | while (p->Range < kTopValue) 41 | { 42 | p->Range <<= 8; 43 | RangeEnc_ShiftLow(p); 44 | } 45 | } 46 | 47 | static void RangeEnc_EncodeBit_0(CPpmd7z_RangeEnc *p, UInt32 size0) 48 | { 49 | p->Range = (p->Range >> 14) * size0; 50 | while (p->Range < kTopValue) 51 | { 52 | p->Range <<= 8; 53 | RangeEnc_ShiftLow(p); 54 | } 55 | } 56 | 57 | static void RangeEnc_EncodeBit_1(CPpmd7z_RangeEnc *p, UInt32 size0) 58 | { 59 | UInt32 newBound = (p->Range >> 14) * size0; 60 | p->Low += newBound; 61 | p->Range -= newBound; 62 | while (p->Range < kTopValue) 63 | { 64 | p->Range <<= 8; 65 | RangeEnc_ShiftLow(p); 66 | } 67 | } 68 | 69 | void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p) 70 | { 71 | unsigned i; 72 | for (i = 0; i < 5; i++) 73 | RangeEnc_ShiftLow(p); 74 | } 75 | 76 | 77 | #define MASK(sym) ((signed char *)charMask)[sym] 78 | 79 | void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol) 80 | { 81 | size_t charMask[256 / sizeof(size_t)]; 82 | if (p->MinContext->NumStats != 1) 83 | { 84 | CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext); 85 | UInt32 sum; 86 | unsigned i; 87 | if (s->Symbol == symbol) 88 | { 89 | RangeEnc_Encode(rc, 0, s->Freq, p->MinContext->SummFreq); 90 | p->FoundState = s; 91 | Ppmd7_Update1_0(p); 92 | return; 93 | } 94 | p->PrevSuccess = 0; 95 | sum = s->Freq; 96 | i = p->MinContext->NumStats - 1; 97 | do 98 | { 99 | if ((++s)->Symbol == symbol) 100 | { 101 | RangeEnc_Encode(rc, sum, s->Freq, p->MinContext->SummFreq); 102 | p->FoundState = s; 103 | Ppmd7_Update1(p); 104 | return; 105 | } 106 | sum += s->Freq; 107 | } 108 | while (--i); 109 | 110 | p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]; 111 | PPMD_SetAllBitsIn256Bytes(charMask); 112 | MASK(s->Symbol) = 0; 113 | i = p->MinContext->NumStats - 1; 114 | do { MASK((--s)->Symbol) = 0; } while (--i); 115 | RangeEnc_Encode(rc, sum, p->MinContext->SummFreq - sum, p->MinContext->SummFreq); 116 | } 117 | else 118 | { 119 | UInt16 *prob = Ppmd7_GetBinSumm(p); 120 | CPpmd_State *s = Ppmd7Context_OneState(p->MinContext); 121 | if (s->Symbol == symbol) 122 | { 123 | RangeEnc_EncodeBit_0(rc, *prob); 124 | *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob); 125 | p->FoundState = s; 126 | Ppmd7_UpdateBin(p); 127 | return; 128 | } 129 | else 130 | { 131 | RangeEnc_EncodeBit_1(rc, *prob); 132 | *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob); 133 | p->InitEsc = PPMD7_kExpEscape[*prob >> 10]; 134 | PPMD_SetAllBitsIn256Bytes(charMask); 135 | MASK(s->Symbol) = 0; 136 | p->PrevSuccess = 0; 137 | } 138 | } 139 | for (;;) 140 | { 141 | UInt32 escFreq; 142 | CPpmd_See *see; 143 | CPpmd_State *s; 144 | UInt32 sum; 145 | unsigned i, numMasked = p->MinContext->NumStats; 146 | do 147 | { 148 | p->OrderFall++; 149 | if (!p->MinContext->Suffix) 150 | return; /* EndMarker (symbol = -1) */ 151 | p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix); 152 | } 153 | while (p->MinContext->NumStats == numMasked); 154 | 155 | see = Ppmd7_MakeEscFreq(p, numMasked, &escFreq); 156 | s = Ppmd7_GetStats(p, p->MinContext); 157 | sum = 0; 158 | i = p->MinContext->NumStats; 159 | do 160 | { 161 | int cur = s->Symbol; 162 | if (cur == symbol) 163 | { 164 | UInt32 low = sum; 165 | CPpmd_State *s1 = s; 166 | do 167 | { 168 | sum += (s->Freq & (int)(MASK(s->Symbol))); 169 | s++; 170 | } 171 | while (--i); 172 | RangeEnc_Encode(rc, low, s1->Freq, sum + escFreq); 173 | Ppmd_See_Update(see); 174 | p->FoundState = s1; 175 | Ppmd7_Update2(p); 176 | return; 177 | } 178 | sum += (s->Freq & (int)(MASK(cur))); 179 | MASK(cur) = 0; 180 | s++; 181 | } 182 | while (--i); 183 | 184 | RangeEnc_Encode(rc, sum, escFreq, sum + escFreq); 185 | see->Summ = (UInt16)(see->Summ + sum + escFreq); 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Precomp.h: -------------------------------------------------------------------------------- 1 | /* Precomp.h -- StdAfx 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_PRECOMP_H 5 | #define __7Z_PRECOMP_H 6 | 7 | #include "Compiler.h" 8 | /* #include "7zTypes.h" */ 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/RotateDefs.h: -------------------------------------------------------------------------------- 1 | /* RotateDefs.h -- Rotate functions 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __ROTATE_DEFS_H 5 | #define __ROTATE_DEFS_H 6 | 7 | #ifdef _MSC_VER 8 | 9 | #include 10 | 11 | // #if (_MSC_VER >= 1200) 12 | #pragma intrinsic(_rotl) 13 | #pragma intrinsic(_rotr) 14 | // #endif 15 | 16 | #define rotlFixed(x, n) _rotl((x), (n)) 17 | #define rotrFixed(x, n) _rotr((x), (n)) 18 | 19 | #else 20 | 21 | #define rotlFixed(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) 22 | #define rotrFixed(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) 23 | 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Sha256.c: -------------------------------------------------------------------------------- 1 | /* Crypto/Sha256.c -- SHA-256 Hash 2 | 2010-06-11 : Igor Pavlov : Public domain 3 | This code is based on public domain code from Wei Dai's Crypto++ library. */ 4 | 5 | #include "Precomp.h" 6 | 7 | #include "RotateDefs.h" 8 | #include "Sha256.h" 9 | 10 | /* define it for speed optimization */ 11 | /* #define _SHA256_UNROLL */ 12 | /* #define _SHA256_UNROLL2 */ 13 | 14 | void Sha256_Init(CSha256 *p) 15 | { 16 | p->state[0] = 0x6a09e667; 17 | p->state[1] = 0xbb67ae85; 18 | p->state[2] = 0x3c6ef372; 19 | p->state[3] = 0xa54ff53a; 20 | p->state[4] = 0x510e527f; 21 | p->state[5] = 0x9b05688c; 22 | p->state[6] = 0x1f83d9ab; 23 | p->state[7] = 0x5be0cd19; 24 | p->count = 0; 25 | } 26 | 27 | #define S0(x) (rotrFixed(x, 2) ^ rotrFixed(x,13) ^ rotrFixed(x, 22)) 28 | #define S1(x) (rotrFixed(x, 6) ^ rotrFixed(x,11) ^ rotrFixed(x, 25)) 29 | #define s0(x) (rotrFixed(x, 7) ^ rotrFixed(x,18) ^ (x >> 3)) 30 | #define s1(x) (rotrFixed(x,17) ^ rotrFixed(x,19) ^ (x >> 10)) 31 | 32 | #define blk0(i) (W[i] = data[i]) 33 | #define blk2(i) (W[i&15] += s1(W[(i-2)&15]) + W[(i-7)&15] + s0(W[(i-15)&15])) 34 | 35 | #define Ch(x,y,z) (z^(x&(y^z))) 36 | #define Maj(x,y,z) ((x&y)|(z&(x|y))) 37 | 38 | #define a(i) T[(0-(i))&7] 39 | #define b(i) T[(1-(i))&7] 40 | #define c(i) T[(2-(i))&7] 41 | #define d(i) T[(3-(i))&7] 42 | #define e(i) T[(4-(i))&7] 43 | #define f(i) T[(5-(i))&7] 44 | #define g(i) T[(6-(i))&7] 45 | #define h(i) T[(7-(i))&7] 46 | 47 | 48 | #ifdef _SHA256_UNROLL2 49 | 50 | #define R(a,b,c,d,e,f,g,h, i) h += S1(e) + Ch(e,f,g) + K[i+j] + (j?blk2(i):blk0(i));\ 51 | d += h; h += S0(a) + Maj(a, b, c) 52 | 53 | #define RX_8(i) \ 54 | R(a,b,c,d,e,f,g,h, i); \ 55 | R(h,a,b,c,d,e,f,g, i+1); \ 56 | R(g,h,a,b,c,d,e,f, i+2); \ 57 | R(f,g,h,a,b,c,d,e, i+3); \ 58 | R(e,f,g,h,a,b,c,d, i+4); \ 59 | R(d,e,f,g,h,a,b,c, i+5); \ 60 | R(c,d,e,f,g,h,a,b, i+6); \ 61 | R(b,c,d,e,f,g,h,a, i+7) 62 | 63 | #else 64 | 65 | #define R(i) h(i) += S1(e(i)) + Ch(e(i),f(i),g(i)) + K[i+j] + (j?blk2(i):blk0(i));\ 66 | d(i) += h(i); h(i) += S0(a(i)) + Maj(a(i), b(i), c(i)) 67 | 68 | #ifdef _SHA256_UNROLL 69 | 70 | #define RX_8(i) R(i+0); R(i+1); R(i+2); R(i+3); R(i+4); R(i+5); R(i+6); R(i+7); 71 | 72 | #endif 73 | 74 | #endif 75 | 76 | static const UInt32 K[64] = { 77 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 78 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 79 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 80 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 81 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 82 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 83 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 84 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 85 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 86 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 87 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 88 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 89 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 90 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 91 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 92 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 93 | }; 94 | 95 | static void Sha256_Transform(UInt32 *state, const UInt32 *data) 96 | { 97 | UInt32 W[16]; 98 | unsigned j; 99 | #ifdef _SHA256_UNROLL2 100 | UInt32 a,b,c,d,e,f,g,h; 101 | a = state[0]; 102 | b = state[1]; 103 | c = state[2]; 104 | d = state[3]; 105 | e = state[4]; 106 | f = state[5]; 107 | g = state[6]; 108 | h = state[7]; 109 | #else 110 | UInt32 T[8]; 111 | for (j = 0; j < 8; j++) 112 | T[j] = state[j]; 113 | #endif 114 | 115 | for (j = 0; j < 64; j += 16) 116 | { 117 | #if defined(_SHA256_UNROLL) || defined(_SHA256_UNROLL2) 118 | RX_8(0); RX_8(8); 119 | #else 120 | unsigned i; 121 | for (i = 0; i < 16; i++) { R(i); } 122 | #endif 123 | } 124 | 125 | #ifdef _SHA256_UNROLL2 126 | state[0] += a; 127 | state[1] += b; 128 | state[2] += c; 129 | state[3] += d; 130 | state[4] += e; 131 | state[5] += f; 132 | state[6] += g; 133 | state[7] += h; 134 | #else 135 | for (j = 0; j < 8; j++) 136 | state[j] += T[j]; 137 | #endif 138 | 139 | /* Wipe variables */ 140 | /* memset(W, 0, sizeof(W)); */ 141 | /* memset(T, 0, sizeof(T)); */ 142 | } 143 | 144 | #undef S0 145 | #undef S1 146 | #undef s0 147 | #undef s1 148 | 149 | static void Sha256_WriteByteBlock(CSha256 *p) 150 | { 151 | UInt32 data32[16]; 152 | unsigned i; 153 | for (i = 0; i < 16; i++) 154 | data32[i] = 155 | ((UInt32)(p->buffer[i * 4 ]) << 24) + 156 | ((UInt32)(p->buffer[i * 4 + 1]) << 16) + 157 | ((UInt32)(p->buffer[i * 4 + 2]) << 8) + 158 | ((UInt32)(p->buffer[i * 4 + 3])); 159 | Sha256_Transform(p->state, data32); 160 | } 161 | 162 | void Sha256_Update(CSha256 *p, const Byte *data, size_t size) 163 | { 164 | UInt32 curBufferPos = (UInt32)p->count & 0x3F; 165 | while (size > 0) 166 | { 167 | p->buffer[curBufferPos++] = *data++; 168 | p->count++; 169 | size--; 170 | if (curBufferPos == 64) 171 | { 172 | curBufferPos = 0; 173 | Sha256_WriteByteBlock(p); 174 | } 175 | } 176 | } 177 | 178 | void Sha256_Final(CSha256 *p, Byte *digest) 179 | { 180 | UInt64 lenInBits = (p->count << 3); 181 | UInt32 curBufferPos = (UInt32)p->count & 0x3F; 182 | unsigned i; 183 | p->buffer[curBufferPos++] = 0x80; 184 | while (curBufferPos != (64 - 8)) 185 | { 186 | curBufferPos &= 0x3F; 187 | if (curBufferPos == 0) 188 | Sha256_WriteByteBlock(p); 189 | p->buffer[curBufferPos++] = 0; 190 | } 191 | for (i = 0; i < 8; i++) 192 | { 193 | p->buffer[curBufferPos++] = (Byte)(lenInBits >> 56); 194 | lenInBits <<= 8; 195 | } 196 | Sha256_WriteByteBlock(p); 197 | 198 | for (i = 0; i < 8; i++) 199 | { 200 | *digest++ = (Byte)(p->state[i] >> 24); 201 | *digest++ = (Byte)(p->state[i] >> 16); 202 | *digest++ = (Byte)(p->state[i] >> 8); 203 | *digest++ = (Byte)(p->state[i]); 204 | } 205 | Sha256_Init(p); 206 | } 207 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Sha256.h: -------------------------------------------------------------------------------- 1 | /* Sha256.h -- SHA-256 Hash 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __CRYPTO_SHA256_H 5 | #define __CRYPTO_SHA256_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define SHA256_DIGEST_SIZE 32 12 | 13 | typedef struct 14 | { 15 | UInt32 state[8]; 16 | UInt64 count; 17 | Byte buffer[64]; 18 | } CSha256; 19 | 20 | void Sha256_Init(CSha256 *p); 21 | void Sha256_Update(CSha256 *p, const Byte *data, size_t size); 22 | void Sha256_Final(CSha256 *p, Byte *digest); 23 | 24 | EXTERN_C_END 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Sort.c: -------------------------------------------------------------------------------- 1 | /* Sort.c -- Sort functions 2 | 2014-04-05 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "Sort.h" 7 | 8 | #define HeapSortDown(p, k, size, temp) \ 9 | { for (;;) { \ 10 | size_t s = (k << 1); \ 11 | if (s > size) break; \ 12 | if (s < size && p[s + 1] > p[s]) s++; \ 13 | if (temp >= p[s]) break; \ 14 | p[k] = p[s]; k = s; \ 15 | } p[k] = temp; } 16 | 17 | void HeapSort(UInt32 *p, size_t size) 18 | { 19 | if (size <= 1) 20 | return; 21 | p--; 22 | { 23 | size_t i = size / 2; 24 | do 25 | { 26 | UInt32 temp = p[i]; 27 | size_t k = i; 28 | HeapSortDown(p, k, size, temp) 29 | } 30 | while (--i != 0); 31 | } 32 | /* 33 | do 34 | { 35 | size_t k = 1; 36 | UInt32 temp = p[size]; 37 | p[size--] = p[1]; 38 | HeapSortDown(p, k, size, temp) 39 | } 40 | while (size > 1); 41 | */ 42 | while (size > 3) 43 | { 44 | UInt32 temp = p[size]; 45 | size_t k = (p[3] > p[2]) ? 3 : 2; 46 | p[size--] = p[1]; 47 | p[1] = p[k]; 48 | HeapSortDown(p, k, size, temp) 49 | } 50 | { 51 | UInt32 temp = p[size]; 52 | p[size] = p[1]; 53 | if (size > 2 && p[2] < temp) 54 | { 55 | p[1] = p[2]; 56 | p[2] = temp; 57 | } 58 | else 59 | p[1] = temp; 60 | } 61 | } 62 | 63 | void HeapSort64(UInt64 *p, size_t size) 64 | { 65 | if (size <= 1) 66 | return; 67 | p--; 68 | { 69 | size_t i = size / 2; 70 | do 71 | { 72 | UInt64 temp = p[i]; 73 | size_t k = i; 74 | HeapSortDown(p, k, size, temp) 75 | } 76 | while (--i != 0); 77 | } 78 | /* 79 | do 80 | { 81 | size_t k = 1; 82 | UInt64 temp = p[size]; 83 | p[size--] = p[1]; 84 | HeapSortDown(p, k, size, temp) 85 | } 86 | while (size > 1); 87 | */ 88 | while (size > 3) 89 | { 90 | UInt64 temp = p[size]; 91 | size_t k = (p[3] > p[2]) ? 3 : 2; 92 | p[size--] = p[1]; 93 | p[1] = p[k]; 94 | HeapSortDown(p, k, size, temp) 95 | } 96 | { 97 | UInt64 temp = p[size]; 98 | p[size] = p[1]; 99 | if (size > 2 && p[2] < temp) 100 | { 101 | p[1] = p[2]; 102 | p[2] = temp; 103 | } 104 | else 105 | p[1] = temp; 106 | } 107 | } 108 | 109 | /* 110 | #define HeapSortRefDown(p, vals, n, size, temp) \ 111 | { size_t k = n; UInt32 val = vals[temp]; for (;;) { \ 112 | size_t s = (k << 1); \ 113 | if (s > size) break; \ 114 | if (s < size && vals[p[s + 1]] > vals[p[s]]) s++; \ 115 | if (val >= vals[p[s]]) break; \ 116 | p[k] = p[s]; k = s; \ 117 | } p[k] = temp; } 118 | 119 | void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size) 120 | { 121 | if (size <= 1) 122 | return; 123 | p--; 124 | { 125 | size_t i = size / 2; 126 | do 127 | { 128 | UInt32 temp = p[i]; 129 | HeapSortRefDown(p, vals, i, size, temp); 130 | } 131 | while (--i != 0); 132 | } 133 | do 134 | { 135 | UInt32 temp = p[size]; 136 | p[size--] = p[1]; 137 | HeapSortRefDown(p, vals, 1, size, temp); 138 | } 139 | while (size > 1); 140 | } 141 | */ 142 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Sort.h: -------------------------------------------------------------------------------- 1 | /* Sort.h -- Sort functions 2 | 2014-04-05 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_SORT_H 5 | #define __7Z_SORT_H 6 | 7 | #include "7zTypes.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | void HeapSort(UInt32 *p, size_t size); 12 | void HeapSort64(UInt64 *p, size_t size); 13 | 14 | /* void HeapSortRef(UInt32 *p, UInt32 *vals, size_t size); */ 15 | 16 | EXTERN_C_END 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Threads.c: -------------------------------------------------------------------------------- 1 | /* Threads.c -- multithreading library 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #ifndef _WIN32_WCE 7 | #include 8 | #endif 9 | 10 | #include "Threads.h" 11 | 12 | static WRes GetError() 13 | { 14 | DWORD res = GetLastError(); 15 | return (res) ? (WRes)(res) : 1; 16 | } 17 | 18 | WRes HandleToWRes(HANDLE h) { return (h != 0) ? 0 : GetError(); } 19 | WRes BOOLToWRes(BOOL v) { return v ? 0 : GetError(); } 20 | 21 | WRes HandlePtr_Close(HANDLE *p) 22 | { 23 | if (*p != NULL) 24 | if (!CloseHandle(*p)) 25 | return GetError(); 26 | *p = NULL; 27 | return 0; 28 | } 29 | 30 | WRes Handle_WaitObject(HANDLE h) { return (WRes)WaitForSingleObject(h, INFINITE); } 31 | 32 | WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param) 33 | { 34 | /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */ 35 | 36 | #ifdef UNDER_CE 37 | 38 | DWORD threadId; 39 | *p = CreateThread(0, 0, func, param, 0, &threadId); 40 | 41 | #else 42 | 43 | unsigned threadId; 44 | *p = (HANDLE)_beginthreadex(NULL, 0, func, param, 0, &threadId); 45 | 46 | #endif 47 | 48 | /* maybe we must use errno here, but probably GetLastError() is also OK. */ 49 | return HandleToWRes(*p); 50 | } 51 | 52 | WRes Event_Create(CEvent *p, BOOL manualReset, int signaled) 53 | { 54 | *p = CreateEvent(NULL, manualReset, (signaled ? TRUE : FALSE), NULL); 55 | return HandleToWRes(*p); 56 | } 57 | 58 | WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(*p)); } 59 | WRes Event_Reset(CEvent *p) { return BOOLToWRes(ResetEvent(*p)); } 60 | 61 | WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled) { return Event_Create(p, TRUE, signaled); } 62 | WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled) { return Event_Create(p, FALSE, signaled); } 63 | WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p) { return ManualResetEvent_Create(p, 0); } 64 | WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) { return AutoResetEvent_Create(p, 0); } 65 | 66 | 67 | WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount) 68 | { 69 | *p = CreateSemaphore(NULL, (LONG)initCount, (LONG)maxCount, NULL); 70 | return HandleToWRes(*p); 71 | } 72 | 73 | static WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount) 74 | { return BOOLToWRes(ReleaseSemaphore(*p, releaseCount, previousCount)); } 75 | WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num) 76 | { return Semaphore_Release(p, (LONG)num, NULL); } 77 | WRes Semaphore_Release1(CSemaphore *p) { return Semaphore_ReleaseN(p, 1); } 78 | 79 | WRes CriticalSection_Init(CCriticalSection *p) 80 | { 81 | /* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */ 82 | #ifdef _MSC_VER 83 | __try 84 | #endif 85 | { 86 | InitializeCriticalSection(p); 87 | /* InitializeCriticalSectionAndSpinCount(p, 0); */ 88 | } 89 | #ifdef _MSC_VER 90 | __except (EXCEPTION_EXECUTE_HANDLER) { return 1; } 91 | #endif 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Threads.h: -------------------------------------------------------------------------------- 1 | /* Threads.h -- multithreading library 2 | 2013-11-12 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __7Z_THREADS_H 5 | #define __7Z_THREADS_H 6 | 7 | #ifdef _WIN32 8 | #include 9 | #endif 10 | 11 | #include "7zTypes.h" 12 | 13 | EXTERN_C_BEGIN 14 | 15 | WRes HandlePtr_Close(HANDLE *h); 16 | WRes Handle_WaitObject(HANDLE h); 17 | 18 | typedef HANDLE CThread; 19 | #define Thread_Construct(p) *(p) = nullptr 20 | #define Thread_WasCreated(p) (*(p) != nullptr) 21 | #define Thread_Close(p) HandlePtr_Close(p) 22 | #define Thread_Wait(p) Handle_WaitObject(*(p)) 23 | 24 | typedef 25 | #ifdef UNDER_CE 26 | DWORD 27 | #else 28 | unsigned 29 | #endif 30 | THREAD_FUNC_RET_TYPE; 31 | 32 | #define THREAD_FUNC_CALL_TYPE MY_STD_CALL 33 | #define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE 34 | typedef THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE * THREAD_FUNC_TYPE)(void *); 35 | WRes Thread_Create(CThread *p, THREAD_FUNC_TYPE func, LPVOID param); 36 | 37 | typedef HANDLE CEvent; 38 | typedef CEvent CAutoResetEvent; 39 | typedef CEvent CManualResetEvent; 40 | #define Event_Construct(p) *(p) = nullptr 41 | #define Event_IsCreated(p) (*(p) != nullptr) 42 | #define Event_Close(p) HandlePtr_Close(p) 43 | #define Event_Wait(p) Handle_WaitObject(*(p)) 44 | WRes Event_Set(CEvent *p); 45 | WRes Event_Reset(CEvent *p); 46 | WRes ManualResetEvent_Create(CManualResetEvent *p, int signaled); 47 | WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p); 48 | WRes AutoResetEvent_Create(CAutoResetEvent *p, int signaled); 49 | WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p); 50 | 51 | typedef HANDLE CSemaphore; 52 | #define Semaphore_Construct(p) (*p) = nullptr 53 | #define Semaphore_Close(p) HandlePtr_Close(p) 54 | #define Semaphore_Wait(p) Handle_WaitObject(*(p)) 55 | WRes Semaphore_Create(CSemaphore *p, UInt32 initCount, UInt32 maxCount); 56 | WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num); 57 | WRes Semaphore_Release1(CSemaphore *p); 58 | 59 | typedef CRITICAL_SECTION CCriticalSection; 60 | WRes CriticalSection_Init(CCriticalSection *p); 61 | #define CriticalSection_Delete(p) DeleteCriticalSection(p) 62 | #define CriticalSection_Enter(p) EnterCriticalSection(p) 63 | #define CriticalSection_Leave(p) LeaveCriticalSection(p) 64 | 65 | EXTERN_C_END 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Xz.c: -------------------------------------------------------------------------------- 1 | /* Xz.c - Xz 2 | 2009-04-15 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "7zCrc.h" 7 | #include "CpuArch.h" 8 | #include "Xz.h" 9 | #include "XzCrc64.h" 10 | 11 | Byte XZ_SIG[XZ_SIG_SIZE] = { 0xFD, '7', 'z', 'X', 'Z', 0 }; 12 | Byte XZ_FOOTER_SIG[XZ_FOOTER_SIG_SIZE] = { 'Y', 'Z' }; 13 | 14 | unsigned Xz_WriteVarInt(Byte *buf, UInt64 v) 15 | { 16 | unsigned i = 0; 17 | do 18 | { 19 | buf[i++] = (Byte)((v & 0x7F) | 0x80); 20 | v >>= 7; 21 | } 22 | while (v != 0); 23 | buf[i - 1] &= 0x7F; 24 | return i; 25 | } 26 | 27 | void Xz_Construct(CXzStream *p) 28 | { 29 | p->numBlocks = p->numBlocksAllocated = 0; 30 | p->blocks = 0; 31 | p->flags = 0; 32 | } 33 | 34 | void Xz_Free(CXzStream *p, ISzAlloc *alloc) 35 | { 36 | alloc->Free(alloc, p->blocks); 37 | p->numBlocks = p->numBlocksAllocated = 0; 38 | p->blocks = 0; 39 | } 40 | 41 | unsigned XzFlags_GetCheckSize(CXzStreamFlags f) 42 | { 43 | int t = XzFlags_GetCheckType(f); 44 | return (t == 0) ? 0 : (4 << ((t - 1) / 3)); 45 | } 46 | 47 | void XzCheck_Init(CXzCheck *p, int mode) 48 | { 49 | p->mode = mode; 50 | switch (mode) 51 | { 52 | case XZ_CHECK_CRC32: p->crc = CRC_INIT_VAL; break; 53 | case XZ_CHECK_CRC64: p->crc64 = CRC64_INIT_VAL; break; 54 | case XZ_CHECK_SHA256: Sha256_Init(&p->sha); break; 55 | } 56 | } 57 | 58 | void XzCheck_Update(CXzCheck *p, const void *data, size_t size) 59 | { 60 | switch (p->mode) 61 | { 62 | case XZ_CHECK_CRC32: p->crc = CrcUpdate(p->crc, data, size); break; 63 | case XZ_CHECK_CRC64: p->crc64 = Crc64Update(p->crc64, data, size); break; 64 | case XZ_CHECK_SHA256: Sha256_Update(&p->sha, (const Byte *)data, size); break; 65 | } 66 | } 67 | 68 | int XzCheck_Final(CXzCheck *p, Byte *digest) 69 | { 70 | switch (p->mode) 71 | { 72 | case XZ_CHECK_CRC32: 73 | SetUi32(digest, CRC_GET_DIGEST(p->crc)); 74 | break; 75 | case XZ_CHECK_CRC64: 76 | { 77 | int i; 78 | UInt64 v = CRC64_GET_DIGEST(p->crc64); 79 | for (i = 0; i < 8; i++, v >>= 8) 80 | digest[i] = (Byte)(v & 0xFF); 81 | break; 82 | } 83 | case XZ_CHECK_SHA256: 84 | Sha256_Final(&p->sha, digest); 85 | break; 86 | default: 87 | return 0; 88 | } 89 | return 1; 90 | } 91 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/Xz.h: -------------------------------------------------------------------------------- 1 | /* Xz.h - Xz interface 2 | 2014-12-30 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __XZ_H 5 | #define __XZ_H 6 | 7 | #include "Sha256.h" 8 | 9 | EXTERN_C_BEGIN 10 | 11 | #define XZ_ID_Subblock 1 12 | #define XZ_ID_Delta 3 13 | #define XZ_ID_X86 4 14 | #define XZ_ID_PPC 5 15 | #define XZ_ID_IA64 6 16 | #define XZ_ID_ARM 7 17 | #define XZ_ID_ARMT 8 18 | #define XZ_ID_SPARC 9 19 | #define XZ_ID_LZMA2 0x21 20 | 21 | unsigned Xz_ReadVarInt(const Byte *p, size_t maxSize, UInt64 *value); 22 | unsigned Xz_WriteVarInt(Byte *buf, UInt64 v); 23 | 24 | /* ---------- xz block ---------- */ 25 | 26 | #define XZ_BLOCK_HEADER_SIZE_MAX 1024 27 | 28 | #define XZ_NUM_FILTERS_MAX 4 29 | #define XZ_BF_NUM_FILTERS_MASK 3 30 | #define XZ_BF_PACK_SIZE (1 << 6) 31 | #define XZ_BF_UNPACK_SIZE (1 << 7) 32 | 33 | #define XZ_FILTER_PROPS_SIZE_MAX 20 34 | 35 | typedef struct 36 | { 37 | UInt64 id; 38 | UInt32 propsSize; 39 | Byte props[XZ_FILTER_PROPS_SIZE_MAX]; 40 | } CXzFilter; 41 | 42 | typedef struct 43 | { 44 | UInt64 packSize; 45 | UInt64 unpackSize; 46 | Byte flags; 47 | CXzFilter filters[XZ_NUM_FILTERS_MAX]; 48 | } CXzBlock; 49 | 50 | #define XzBlock_GetNumFilters(p) (((p)->flags & XZ_BF_NUM_FILTERS_MASK) + 1) 51 | #define XzBlock_HasPackSize(p) (((p)->flags & XZ_BF_PACK_SIZE) != 0) 52 | #define XzBlock_HasUnpackSize(p) (((p)->flags & XZ_BF_UNPACK_SIZE) != 0) 53 | 54 | SRes XzBlock_Parse(CXzBlock *p, const Byte *header); 55 | SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, Bool *isIndex, UInt32 *headerSizeRes); 56 | 57 | /* ---------- xz stream ---------- */ 58 | 59 | #define XZ_SIG_SIZE 6 60 | #define XZ_FOOTER_SIG_SIZE 2 61 | 62 | extern Byte XZ_SIG[XZ_SIG_SIZE]; 63 | extern Byte XZ_FOOTER_SIG[XZ_FOOTER_SIG_SIZE]; 64 | 65 | #define XZ_STREAM_FLAGS_SIZE 2 66 | #define XZ_STREAM_CRC_SIZE 4 67 | 68 | #define XZ_STREAM_HEADER_SIZE (XZ_SIG_SIZE + XZ_STREAM_FLAGS_SIZE + XZ_STREAM_CRC_SIZE) 69 | #define XZ_STREAM_FOOTER_SIZE (XZ_FOOTER_SIG_SIZE + XZ_STREAM_FLAGS_SIZE + XZ_STREAM_CRC_SIZE + 4) 70 | 71 | #define XZ_CHECK_MASK 0xF 72 | #define XZ_CHECK_NO 0 73 | #define XZ_CHECK_CRC32 1 74 | #define XZ_CHECK_CRC64 4 75 | #define XZ_CHECK_SHA256 10 76 | 77 | typedef struct 78 | { 79 | int mode; 80 | UInt32 crc; 81 | UInt64 crc64; 82 | CSha256 sha; 83 | } CXzCheck; 84 | 85 | void XzCheck_Init(CXzCheck *p, int mode); 86 | void XzCheck_Update(CXzCheck *p, const void *data, size_t size); 87 | int XzCheck_Final(CXzCheck *p, Byte *digest); 88 | 89 | typedef UInt16 CXzStreamFlags; 90 | 91 | #define XzFlags_IsSupported(f) ((f) <= XZ_CHECK_MASK) 92 | #define XzFlags_GetCheckType(f) ((f) & XZ_CHECK_MASK) 93 | #define XzFlags_HasDataCrc32(f) (Xz_GetCheckType(f) == XZ_CHECK_CRC32) 94 | unsigned XzFlags_GetCheckSize(CXzStreamFlags f); 95 | 96 | SRes Xz_ParseHeader(CXzStreamFlags *p, const Byte *buf); 97 | SRes Xz_ReadHeader(CXzStreamFlags *p, ISeqInStream *inStream); 98 | 99 | typedef struct 100 | { 101 | UInt64 unpackSize; 102 | UInt64 totalSize; 103 | } CXzBlockSizes; 104 | 105 | typedef struct 106 | { 107 | CXzStreamFlags flags; 108 | size_t numBlocks; 109 | size_t numBlocksAllocated; 110 | CXzBlockSizes *blocks; 111 | UInt64 startOffset; 112 | } CXzStream; 113 | 114 | void Xz_Construct(CXzStream *p); 115 | void Xz_Free(CXzStream *p, ISzAlloc *alloc); 116 | 117 | #define XZ_SIZE_OVERFLOW ((UInt64)(Int64)-1) 118 | 119 | UInt64 Xz_GetUnpackSize(const CXzStream *p); 120 | UInt64 Xz_GetPackSize(const CXzStream *p); 121 | 122 | typedef struct 123 | { 124 | size_t num; 125 | size_t numAllocated; 126 | CXzStream *streams; 127 | } CXzs; 128 | 129 | void Xzs_Construct(CXzs *p); 130 | void Xzs_Free(CXzs *p, ISzAlloc *alloc); 131 | SRes Xzs_ReadBackward(CXzs *p, ILookInStream *inStream, Int64 *startOffset, ICompressProgress *progress, ISzAlloc *alloc); 132 | 133 | UInt64 Xzs_GetNumBlocks(const CXzs *p); 134 | UInt64 Xzs_GetUnpackSize(const CXzs *p); 135 | 136 | typedef enum 137 | { 138 | CODER_STATUS_NOT_SPECIFIED, /* use main error code instead */ 139 | CODER_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */ 140 | CODER_STATUS_NOT_FINISHED, /* stream was not finished */ 141 | CODER_STATUS_NEEDS_MORE_INPUT /* you must provide more input bytes */ 142 | } ECoderStatus; 143 | 144 | typedef enum 145 | { 146 | CODER_FINISH_ANY, /* finish at any point */ 147 | CODER_FINISH_END /* block must be finished at the end */ 148 | } ECoderFinishMode; 149 | 150 | typedef struct _IStateCoder 151 | { 152 | void *p; 153 | void (*Free)(void *p, ISzAlloc *alloc); 154 | SRes (*SetProps)(void *p, const Byte *props, size_t propSize, ISzAlloc *alloc); 155 | void (*Init)(void *p); 156 | SRes (*Code)(void *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, 157 | int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished); 158 | } IStateCoder; 159 | 160 | #define MIXCODER_NUM_FILTERS_MAX 4 161 | 162 | typedef struct 163 | { 164 | ISzAlloc *alloc; 165 | Byte *buf; 166 | int numCoders; 167 | int finished[MIXCODER_NUM_FILTERS_MAX - 1]; 168 | size_t pos[MIXCODER_NUM_FILTERS_MAX - 1]; 169 | size_t size[MIXCODER_NUM_FILTERS_MAX - 1]; 170 | UInt64 ids[MIXCODER_NUM_FILTERS_MAX]; 171 | IStateCoder coders[MIXCODER_NUM_FILTERS_MAX]; 172 | } CMixCoder; 173 | 174 | void MixCoder_Construct(CMixCoder *p, ISzAlloc *alloc); 175 | void MixCoder_Free(CMixCoder *p); 176 | void MixCoder_Init(CMixCoder *p); 177 | SRes MixCoder_SetFromMethod(CMixCoder *p, int coderIndex, UInt64 methodId); 178 | SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen, 179 | const Byte *src, SizeT *srcLen, int srcWasFinished, 180 | ECoderFinishMode finishMode, ECoderStatus *status); 181 | 182 | typedef enum 183 | { 184 | XZ_STATE_STREAM_HEADER, 185 | XZ_STATE_STREAM_INDEX, 186 | XZ_STATE_STREAM_INDEX_CRC, 187 | XZ_STATE_STREAM_FOOTER, 188 | XZ_STATE_STREAM_PADDING, 189 | XZ_STATE_BLOCK_HEADER, 190 | XZ_STATE_BLOCK, 191 | XZ_STATE_BLOCK_FOOTER 192 | } EXzState; 193 | 194 | typedef struct 195 | { 196 | EXzState state; 197 | UInt32 pos; 198 | unsigned alignPos; 199 | unsigned indexPreSize; 200 | 201 | CXzStreamFlags streamFlags; 202 | 203 | UInt32 blockHeaderSize; 204 | UInt64 packSize; 205 | UInt64 unpackSize; 206 | 207 | UInt64 numBlocks; 208 | UInt64 indexSize; 209 | UInt64 indexPos; 210 | UInt64 padSize; 211 | 212 | UInt64 numStartedStreams; 213 | UInt64 numFinishedStreams; 214 | UInt64 numTotalBlocks; 215 | 216 | UInt32 crc; 217 | CMixCoder decoder; 218 | CXzBlock block; 219 | CXzCheck check; 220 | CSha256 sha; 221 | Byte shaDigest[SHA256_DIGEST_SIZE]; 222 | Byte buf[XZ_BLOCK_HEADER_SIZE_MAX]; 223 | } CXzUnpacker; 224 | 225 | void XzUnpacker_Construct(CXzUnpacker *p, ISzAlloc *alloc); 226 | void XzUnpacker_Init(CXzUnpacker *p); 227 | void XzUnpacker_Free(CXzUnpacker *p); 228 | 229 | /* 230 | finishMode: 231 | It has meaning only if the decoding reaches output limit (*destLen). 232 | CODER_FINISH_ANY - use smallest number of input bytes 233 | CODER_FINISH_END - read EndOfStream marker after decoding 234 | 235 | Returns: 236 | SZ_OK 237 | status: 238 | CODER_STATUS_NOT_FINISHED, 239 | CODER_STATUS_NEEDS_MORE_INPUT - maybe there are more xz streams, 240 | call XzUnpacker_IsStreamWasFinished to check that current stream was finished 241 | SZ_ERROR_MEM - Memory allocation error 242 | SZ_ERROR_DATA - Data error 243 | SZ_ERROR_UNSUPPORTED - Unsupported method or method properties 244 | SZ_ERROR_CRC - CRC error 245 | // SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). 246 | 247 | SZ_ERROR_NO_ARCHIVE - the error with xz Stream Header with one of the following reasons: 248 | - xz Stream Signature failure 249 | - CRC32 of xz Stream Header is failed 250 | - The size of Stream padding is not multiple of four bytes. 251 | It's possible to get that error, if xz stream was finished and the stream 252 | contains some another data. In that case you can call XzUnpacker_GetExtraSize() 253 | function to get real size of xz stream. 254 | */ 255 | 256 | 257 | SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen, 258 | const Byte *src, SizeT *srcLen, ECoderFinishMode finishMode, 259 | ECoderStatus *status); 260 | 261 | Bool XzUnpacker_IsStreamWasFinished(CXzUnpacker *p); 262 | 263 | /* 264 | Call XzUnpacker_GetExtraSize after XzUnpacker_Code function to detect real size of 265 | xz stream in two cases: 266 | XzUnpacker_Code() returns: 267 | res == SZ_OK && status == CODER_STATUS_NEEDS_MORE_INPUT 268 | res == SZ_ERROR_NO_ARCHIVE 269 | */ 270 | 271 | UInt64 XzUnpacker_GetExtraSize(CXzUnpacker *p); 272 | 273 | EXTERN_C_END 274 | 275 | #endif 276 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/XzCrc64.c: -------------------------------------------------------------------------------- 1 | /* XzCrc64.c -- CRC64 calculation 2 | 2011-06-28 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "XzCrc64.h" 7 | #include "CpuArch.h" 8 | 9 | #define kCrc64Poly UINT64_CONST(0xC96C5795D7870F42) 10 | 11 | #ifdef MY_CPU_LE 12 | #define CRC_NUM_TABLES 4 13 | #else 14 | #define CRC_NUM_TABLES 5 15 | #define CRC_UINT64_SWAP(v) \ 16 | ((v >> 56) | \ 17 | ((v >> 40) & ((UInt64)0xFF << 8)) | \ 18 | ((v >> 24) & ((UInt64)0xFF << 16)) | \ 19 | ((v >> 8) & ((UInt64)0xFF << 24)) | \ 20 | ((v << 8) & ((UInt64)0xFF << 32)) | \ 21 | ((v << 24) & ((UInt64)0xFF << 40)) | \ 22 | ((v << 40) & ((UInt64)0xFF << 48)) | \ 23 | (v << 56)) 24 | UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table); 25 | #endif 26 | 27 | #ifndef MY_CPU_BE 28 | UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table); 29 | #endif 30 | 31 | typedef UInt64 (MY_FAST_CALL *CRC_FUNC)(UInt64 v, const void *data, size_t size, const UInt64 *table); 32 | 33 | static CRC_FUNC g_Crc64Update; 34 | UInt64 g_Crc64Table[256 * CRC_NUM_TABLES]; 35 | 36 | UInt64 MY_FAST_CALL Crc64Update(UInt64 v, const void *data, size_t size) 37 | { 38 | return g_Crc64Update(v, data, size, g_Crc64Table); 39 | } 40 | 41 | UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size) 42 | { 43 | return g_Crc64Update(CRC64_INIT_VAL, data, size, g_Crc64Table) ^ CRC64_INIT_VAL; 44 | } 45 | 46 | void MY_FAST_CALL Crc64GenerateTable() 47 | { 48 | UInt32 i; 49 | for (i = 0; i < 256; i++) 50 | { 51 | UInt64 r = i; 52 | unsigned j; 53 | for (j = 0; j < 8; j++) 54 | r = (r >> 1) ^ (kCrc64Poly & ~((r & 1) - 1)); 55 | g_Crc64Table[i] = r; 56 | } 57 | for (; i < 256 * CRC_NUM_TABLES; i++) 58 | { 59 | UInt64 r = g_Crc64Table[i - 256]; 60 | g_Crc64Table[i] = g_Crc64Table[r & 0xFF] ^ (r >> 8); 61 | } 62 | 63 | #ifdef MY_CPU_LE 64 | 65 | g_Crc64Update = XzCrc64UpdateT4; 66 | 67 | 68 | 69 | 70 | 71 | 72 | #else 73 | { 74 | #ifndef MY_CPU_BE 75 | UInt32 k = 1; 76 | if (*(const Byte *)&k == 1) 77 | g_Crc64Update = XzCrc64UpdateT4; 78 | else 79 | #endif 80 | { 81 | for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--) 82 | { 83 | UInt64 x = g_Crc64Table[i - 256]; 84 | g_Crc64Table[i] = CRC_UINT64_SWAP(x); 85 | } 86 | g_Crc64Update = XzCrc64UpdateT1_BeT4; 87 | } 88 | } 89 | #endif 90 | } 91 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/XzCrc64.h: -------------------------------------------------------------------------------- 1 | /* XzCrc64.h -- CRC64 calculation 2 | 2013-01-18 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __XZ_CRC64_H 5 | #define __XZ_CRC64_H 6 | 7 | #include 8 | 9 | #include "7zTypes.h" 10 | 11 | EXTERN_C_BEGIN 12 | 13 | extern UInt64 g_Crc64Table[]; 14 | 15 | void MY_FAST_CALL Crc64GenerateTable(void); 16 | 17 | #define CRC64_INIT_VAL UINT64_CONST(0xFFFFFFFFFFFFFFFF) 18 | #define CRC64_GET_DIGEST(crc) ((crc) ^ CRC64_INIT_VAL) 19 | #define CRC64_UPDATE_BYTE(crc, b) (g_Crc64Table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 20 | 21 | UInt64 MY_FAST_CALL Crc64Update(UInt64 crc, const void *data, size_t size); 22 | UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size); 23 | 24 | EXTERN_C_END 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/XzCrc64Opt.c: -------------------------------------------------------------------------------- 1 | /* XzCrc64Opt.c -- CRC64 calculation 2 | 2011-06-28 : Igor Pavlov : Public domain */ 3 | 4 | #include "Precomp.h" 5 | 6 | #include "CpuArch.h" 7 | 8 | #define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) 9 | 10 | #ifndef MY_CPU_BE 11 | 12 | UInt64 MY_FAST_CALL XzCrc64UpdateT4(UInt64 v, const void *data, size_t size, const UInt64 *table) 13 | { 14 | const Byte *p = (const Byte *)data; 15 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 16 | v = CRC_UPDATE_BYTE_2(v, *p); 17 | for (; size >= 4; size -= 4, p += 4) 18 | { 19 | UInt32 d = (UInt32)v ^ *(const UInt32 *)p; 20 | v = (v >> 32) ^ 21 | table[0x300 + ((d ) & 0xFF)] ^ 22 | table[0x200 + ((d >> 8) & 0xFF)] ^ 23 | table[0x100 + ((d >> 16) & 0xFF)] ^ 24 | table[0x000 + ((d >> 24))]; 25 | } 26 | for (; size > 0; size--, p++) 27 | v = CRC_UPDATE_BYTE_2(v, *p); 28 | return v; 29 | } 30 | 31 | #endif 32 | 33 | 34 | #ifndef MY_CPU_LE 35 | 36 | #define CRC_UINT64_SWAP(v) \ 37 | ((v >> 56) | \ 38 | ((v >> 40) & ((UInt64)0xFF << 8)) | \ 39 | ((v >> 24) & ((UInt64)0xFF << 16)) | \ 40 | ((v >> 8) & ((UInt64)0xFF << 24)) | \ 41 | ((v << 8) & ((UInt64)0xFF << 32)) | \ 42 | ((v << 24) & ((UInt64)0xFF << 40)) | \ 43 | ((v << 40) & ((UInt64)0xFF << 48)) | \ 44 | (v << 56)) 45 | 46 | UInt64 MY_FAST_CALL XzCrc64UpdateT1_BeT4(UInt64 v, const void *data, size_t size, const UInt64 *table) 47 | { 48 | const Byte *p = (const Byte *)data; 49 | for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) 50 | v = CRC_UPDATE_BYTE_2(v, *p); 51 | v = CRC_UINT64_SWAP(v); 52 | table += 0x100; 53 | for (; size >= 4; size -= 4, p += 4) 54 | { 55 | UInt32 d = (UInt32)(v >> 32) ^ *(const UInt32 *)p; 56 | v = (v << 32) ^ 57 | table[0x000 + ((d ) & 0xFF)] ^ 58 | table[0x100 + ((d >> 8) & 0xFF)] ^ 59 | table[0x200 + ((d >> 16) & 0xFF)] ^ 60 | table[0x300 + ((d >> 24))]; 61 | } 62 | table -= 0x100; 63 | v = CRC_UINT64_SWAP(v); 64 | for (; size > 0; size--, p++) 65 | v = CRC_UPDATE_BYTE_2(v, *p); 66 | return v; 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /ShaderCompile/include/C/XzEnc.h: -------------------------------------------------------------------------------- 1 | /* XzEnc.h -- Xz Encode 2 | 2011-02-07 : Igor Pavlov : Public domain */ 3 | 4 | #ifndef __XZ_ENC_H 5 | #define __XZ_ENC_H 6 | 7 | #include "Lzma2Enc.h" 8 | 9 | #include "Xz.h" 10 | 11 | EXTERN_C_BEGIN 12 | 13 | typedef struct 14 | { 15 | UInt32 id; 16 | UInt32 delta; 17 | UInt32 ip; 18 | int ipDefined; 19 | } CXzFilterProps; 20 | 21 | void XzFilterProps_Init(CXzFilterProps *p); 22 | 23 | typedef struct 24 | { 25 | const CLzma2EncProps *lzma2Props; 26 | const CXzFilterProps *filterProps; 27 | unsigned checkId; 28 | } CXzProps; 29 | 30 | void XzProps_Init(CXzProps *p); 31 | 32 | SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream, 33 | const CXzProps *props, ICompressProgress *progress); 34 | 35 | SRes Xz_EncodeEmpty(ISeqOutStream *outStream); 36 | 37 | EXTERN_C_END 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /ShaderCompile/include/CRC32.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace CRC32 4 | { 5 | static constexpr auto CRC32_INIT_VALUE = 0xFFFFFFFFUL; 6 | static constexpr auto CRC32_XOR_VALUE = 0xFFFFFFFFUL; 7 | 8 | typedef unsigned int CRC32_t; 9 | 10 | static constexpr auto NUM_BYTES = 256; 11 | static constexpr const CRC32_t pulCRCTable[NUM_BYTES] = { 12 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 13 | 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 14 | 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 15 | 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 16 | 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 17 | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 18 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 19 | 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 20 | 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 21 | 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 22 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 23 | 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 24 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 25 | 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 26 | 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 27 | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 28 | 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 29 | 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 30 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 31 | 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 32 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 33 | 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 34 | 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 35 | 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 36 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 37 | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 38 | 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 39 | 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 40 | 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 41 | 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 42 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 43 | 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 44 | 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 45 | 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 46 | 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 47 | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 48 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 49 | 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 50 | 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 51 | 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 52 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 53 | 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 54 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 55 | 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 56 | 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 57 | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 58 | 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 59 | 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 60 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 61 | 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 62 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 63 | 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 64 | 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 65 | 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 66 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 67 | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 68 | 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 69 | 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 70 | 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 71 | 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 72 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 73 | 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 74 | 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 75 | 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d 76 | }; 77 | 78 | static void Init( CRC32_t& pulCRC ) 79 | { 80 | pulCRC = CRC32_INIT_VALUE; 81 | } 82 | 83 | static void ProcessBuffer( CRC32_t& pulCRC, const void* pBuffer, size_t nBuffer ) 84 | { 85 | CRC32_t ulCrc = pulCRC; 86 | const auto* pb = static_cast( pBuffer ); 87 | 88 | JustAfew: 89 | switch ( nBuffer ) 90 | { 91 | case 7: 92 | ulCrc = pulCRCTable[*pb++ ^ static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 93 | [[fallthrough]]; 94 | 95 | case 6: 96 | ulCrc = pulCRCTable[*pb++ ^ static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 97 | [[fallthrough]]; 98 | 99 | case 5: 100 | ulCrc = pulCRCTable[*pb++ ^ static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 101 | [[fallthrough]]; 102 | 103 | case 4: 104 | ulCrc ^= *reinterpret_cast( pb ); 105 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 106 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 107 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 108 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 109 | pulCRC = ulCrc; 110 | return; 111 | 112 | case 3: 113 | ulCrc = pulCRCTable[*pb++ ^ static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 114 | [[fallthrough]]; 115 | 116 | case 2: 117 | ulCrc = pulCRCTable[*pb++ ^ static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 118 | [[fallthrough]]; 119 | 120 | case 1: 121 | ulCrc = pulCRCTable[*pb++ ^ static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 122 | [[fallthrough]]; 123 | 124 | case 0: 125 | pulCRC = ulCrc; 126 | return; 127 | } 128 | 129 | // We may need to do some alignment work up front, and at the end, so that 130 | // the main loop is aligned and only has to worry about 8 byte at a time. 131 | // 132 | // The low-order two bits of pb and nBuffer in total control the 133 | // upfront work. 134 | // 135 | const int nFront = gsl::narrow( reinterpret_cast( pb ) & 3 ); 136 | nBuffer -= nFront; 137 | switch ( nFront ) 138 | { 139 | case 3: 140 | ulCrc = pulCRCTable[*pb++ ^ static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 141 | [[fallthrough]]; 142 | case 2: 143 | ulCrc = pulCRCTable[*pb++ ^ static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 144 | [[fallthrough]]; 145 | case 1: 146 | ulCrc = pulCRCTable[*pb++ ^ static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 147 | } 148 | 149 | size_t nMain = nBuffer >> 3; 150 | while ( nMain-- ) 151 | { 152 | ulCrc ^= ( *reinterpret_cast( pb ) ); 153 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 154 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 155 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 156 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 157 | ulCrc ^= *reinterpret_cast( pb + 4 ); 158 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 159 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 160 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 161 | ulCrc = pulCRCTable[static_cast( ulCrc )] ^ ( ulCrc >> 8 ); 162 | pb += 8; 163 | } 164 | 165 | nBuffer &= 7; 166 | goto JustAfew; 167 | } 168 | 169 | static void Final( CRC32_t& pulCRC ) 170 | { 171 | pulCRC ^= CRC32_XOR_VALUE; 172 | } 173 | 174 | static CRC32_t ProcessSingleBuffer( const void* p, size_t len ) 175 | { 176 | CRC32_t crc; 177 | 178 | Init( crc ); 179 | ProcessBuffer( crc, p, len ); 180 | Final( crc ); 181 | 182 | return crc; 183 | } 184 | } // namespace CRC32 -------------------------------------------------------------------------------- /ShaderCompile/movingaverage.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | class CUtlMovingAverage 5 | { 6 | public: 7 | CUtlMovingAverage() 8 | : m_buffer{ 0 } 9 | , m_nValuesPushed( 0 ) 10 | , m_nIndex( 0 ) 11 | , m_total( 0 ) 12 | { 13 | } 14 | 15 | void Reset() 16 | { 17 | m_nValuesPushed = 0; 18 | m_nIndex = 0; 19 | m_total = 0; 20 | memset( m_buffer, 0, sizeof( m_buffer ) ); 21 | } 22 | 23 | [[nodiscard]] StorageType GetAverage() const 24 | { 25 | const uint32_t n = std::min( TBufferSize, m_nIndex ); 26 | return gsl::narrow_cast( n ? ( m_total / static_cast( n ) ) : 0 ); 27 | } 28 | 29 | void PushValue( StorageType v ) 30 | { 31 | uint32_t nIndex = m_nValuesPushed % TBufferSize; 32 | m_nValuesPushed = nIndex + 1; 33 | m_nIndex = std::max( m_nIndex, m_nValuesPushed ); 34 | 35 | m_total -= m_buffer[nIndex]; 36 | m_total += v; 37 | 38 | m_buffer[nIndex] = v; 39 | } 40 | 41 | private: 42 | StorageType m_buffer[TBufferSize]; 43 | uint32_t m_nValuesPushed; 44 | uint32_t m_nIndex; 45 | 46 | StorageType m_total; 47 | }; -------------------------------------------------------------------------------- /ShaderCompile/shader_vcs_version.h: -------------------------------------------------------------------------------- 1 | //========= Copyright Valve Corporation, All rights reserved. ============// 2 | // 3 | // Purpose: 4 | // 5 | //=============================================================================// 6 | 7 | #pragma once 8 | 9 | #include "basetypes.h" 10 | 11 | // 1 = hl2 shipped 12 | // 2 = compressed with diffs version (lostcoast) 13 | // 3 = compressed with bzip 14 | // 4 = v2 + crc32 15 | // 5 = v3 + crc32 16 | // 6 = v5 + duplicate static combo records 17 | static inline constexpr int SHADER_VCS_VERSION_NUMBER = 6; 18 | 19 | static inline constexpr int MAX_SHADER_UNPACKED_BLOCK_SIZE = ( 1 << 17 ); 20 | static inline constexpr int MAX_SHADER_PACKED_SIZE = ( 1 + MAX_SHADER_UNPACKED_BLOCK_SIZE ); 21 | 22 | #pragma pack( 1 ) 23 | struct ShaderHeader_t 24 | { 25 | int32_t m_nVersion; 26 | int32_t m_nTotalCombos; 27 | int32_t m_nDynamicCombos; 28 | uint32_t m_nFlags; 29 | uint32_t m_nCentroidMask; 30 | uint32_t m_nNumStaticCombos; // includes sentinal key 31 | uint32_t m_nSourceCRC32; // NOTE: If you move this, update copyshaders.pl, *_prep.pl, updateshaders.pl 32 | }; 33 | #pragma pack() 34 | static_assert( sizeof( ShaderHeader_t ) == 7 * 4 ); 35 | 36 | #pragma pack( 1 ) 37 | struct ShaderHeader_t_v4 // still used for assembly shaders 38 | { 39 | int32_t m_nVersion; 40 | int32_t m_nTotalCombos; 41 | int32_t m_nDynamicCombos; 42 | uint32_t m_nFlags; 43 | uint32_t m_nCentroidMask; 44 | uint32_t m_nDiffReferenceSize; 45 | uint32_t m_nSourceCRC32; // NOTE: If you move this, update copyshaders.pl, *_prep.pl, updateshaders.pl 46 | }; 47 | #pragma pack() 48 | static_assert( sizeof( ShaderHeader_t_v4 ) == 7 * 4 ); 49 | 50 | // for old format files 51 | struct ShaderDictionaryEntry_t 52 | { 53 | int m_Offset; 54 | int m_Size; 55 | }; 56 | static_assert( sizeof( ShaderDictionaryEntry_t ) == 2 * 4 ); 57 | 58 | // record for one static combo 59 | struct StaticComboRecord_t 60 | { 61 | uint32_t m_nStaticComboID; 62 | uint32_t m_nFileOffset; 63 | }; 64 | static_assert( sizeof( StaticComboRecord_t ) == 2 * 4 ); 65 | 66 | struct StaticComboAliasRecord_t // for duplicate static combos 67 | { 68 | uint32_t m_nStaticComboID; // this combo 69 | uint32_t m_nSourceStaticCombo; // the combo it is the same as 70 | }; 71 | static_assert( sizeof( StaticComboAliasRecord_t ) == 2 * 4 ); -------------------------------------------------------------------------------- /ShaderCompile/shaderparser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace CfgProcessor 9 | { 10 | struct ShaderConfig; 11 | } 12 | 13 | namespace Parser 14 | { 15 | struct Combo 16 | { 17 | std::string name; 18 | int32_t minVal; 19 | int32_t maxVal; 20 | std::string initVal; 21 | 22 | Combo( const std::string& name, int32_t min, int32_t max, const std::string& init_val ); 23 | }; 24 | 25 | std::string ConstructName( const std::string& baseName, const std::string_view& target, const std::string_view& ver ); 26 | std::string_view GetTarget( const std::string& baseName ); 27 | bool ParseFile( const std::filesystem::path& name, const std::string& root, const std::string_view& target, const std::string_view& version, CfgProcessor::ShaderConfig& conf ); 28 | void WriteInclude( const std::filesystem::path& fileName, const std::string& name, const std::string_view& target, const std::vector& static_c, 29 | const std::vector& dynamic_c, const std::vector& skip, bool writeSCI ); 30 | bool CheckCrc( const std::filesystem::path& sourceFile, const std::string& root, const std::string& name, uint32_t& crc32 ); 31 | } -------------------------------------------------------------------------------- /ShaderCompile/strmanip.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | template 7 | struct _Smanip2 8 | { 9 | friend std::ostream& operator<<(std::ostream& _Ostr, const _Smanip2& _Manip) 10 | { 11 | (*_Manip._Pfun)(_Ostr, _Manip._Manarg); 12 | return _Ostr; 13 | } 14 | 15 | void(__cdecl* _Pfun)(std::ostream&, _Arg); 16 | _Arg _Manarg; 17 | }; 18 | 19 | static inline void __PrettyPrintNumber( std::ostream& s, uint64_t k ) 20 | { 21 | char chCompileString[50] = { 0 }; 22 | char* pchPrint = chCompileString + sizeof( chCompileString ) - 3; 23 | for ( uint64_t j = 0; k > 0; k /= 10, ++j ) 24 | { 25 | ( j && !( j % 3 ) ) ? ( *pchPrint-- = ',' ) : 0; 26 | *pchPrint-- = '0' + char( k % 10 ); 27 | } 28 | *++pchPrint ? 0 : *pchPrint = 0; 29 | s << pchPrint; 30 | } 31 | 32 | static inline _Smanip2 PrettyPrint( uint64_t i ) 33 | { 34 | return { __PrettyPrintNumber, i }; 35 | } 36 | 37 | static inline void __FormatTime( std::ostream& s, int64_t nInputSeconds ) 38 | { 39 | int64_t nMinutes = nInputSeconds / 60; 40 | const int64_t nSeconds = nInputSeconds - nMinutes * 60; 41 | const int64_t nHours = nMinutes / 60; 42 | nMinutes -= nHours * 60; 43 | 44 | static constexpr const std::string_view extra[2] = { "", "s" }; 45 | 46 | s << std::setfill( '0' ); 47 | if ( nHours > 0 ) 48 | s << clr::green << nHours << clr::reset << " hour" << extra[nHours != 1] << ", " << clr::green << std::setw( 2 ) << nMinutes << clr::reset << " minute" << extra[nMinutes != 1] << ", " << clr::green << std::setw( 2 ) << nSeconds << clr::reset << " second" << extra[nSeconds != 1]; 49 | else if ( nMinutes > 0 ) 50 | s << clr::green << nMinutes << clr::reset << " minute" << extra[nMinutes != 1] << ", " << clr::green << std::setw( 2 ) << nSeconds << clr::reset << " second" << extra[nSeconds != 1]; 51 | else 52 | s << clr::green << nSeconds << clr::reset << " second" << extra[nSeconds != 1]; 53 | s << std::setfill( ' ' ); 54 | } 55 | 56 | static inline void __FormatTime2( std::ostream& s, int64_t nInputSeconds ) 57 | { 58 | int64_t nMinutes = nInputSeconds / 60; 59 | const int64_t nSeconds = nInputSeconds - nMinutes * 60; 60 | const int64_t nHours = nMinutes / 60; 61 | nMinutes -= nHours * 60; 62 | 63 | static constexpr const std::string_view extra[2] = { "", "s" }; 64 | 65 | s << std::setfill( '0' ); 66 | if ( nHours > 0 ) 67 | s << clr::green << nHours << clr::reset << ":" << clr::green << std::setw( 2 ) << nMinutes << clr::reset << ":" << clr::green << std::setw( 2 ) << nSeconds << clr::reset; 68 | else if ( nMinutes > 0 ) 69 | s << clr::green << nMinutes << clr::reset << ":" << clr::green << std::setw( 2 ) << nSeconds << clr::reset; 70 | else 71 | s << clr::green << nSeconds << clr::reset << " second" << extra[nSeconds != 1]; 72 | s << std::setfill( ' ' ); 73 | } 74 | 75 | static inline _Smanip2 FormatTime( int64_t i ) 76 | { 77 | return { __FormatTime, i }; 78 | } 79 | 80 | static inline _Smanip2 FormatTimeShort( int64_t i ) 81 | { 82 | return { __FormatTime2, i }; 83 | } 84 | 85 | static inline bool V_IsAbsolutePath( const char* pStr ) 86 | { 87 | return ( pStr[0] && pStr[1] == ':' ) || pStr[0] == '/' || pStr[0] == '\\'; 88 | } -------------------------------------------------------------------------------- /ShaderCompile/termcolors.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TERMCOLORS_HPP 2 | #define TERMCOLORS_HPP 3 | 4 | namespace clr 5 | { 6 | using namespace termcolor; 7 | static inline constexpr auto red = _internal::ansi_color( color( 222, 12, 17 ) ); 8 | static inline constexpr auto green = _internal::ansi_color( color( 33, 201, 41 ) ); 9 | static inline constexpr auto green2 = _internal::ansi_color( color( 12, 222, 154 ) ); 10 | static inline constexpr auto blue = _internal::ansi_color( color( 14, 70, 220 ) ); 11 | static inline constexpr auto pinkish = _internal::ansi_color( color( 254, 90, 90 ) ); 12 | } // namespace clr 13 | 14 | #endif // TERMCOLORS_HPP -------------------------------------------------------------------------------- /ShaderCompile/utlnodehash.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SCell555/ShaderCompile/7ea74828baa22df9db5efad67b48abb7c5b3dbed/ShaderCompile/utlnodehash.h -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | - master 3 | 4 | pool: 5 | vmImage: 'windows-latest' 6 | 7 | steps: 8 | - checkout: self 9 | submodules: true 10 | - task: CMake@1 11 | inputs: 12 | cmakeArgs: '.' 13 | workingDirectory: '.' 14 | - task: CMake@1 15 | inputs: 16 | cmakeArgs: '--build . --parallel --config Release' 17 | workingDirectory: '.' 18 | - task: CopyFiles@2 19 | inputs: 20 | SourceFolder: 'scripts' 21 | Contents: '**' 22 | TargetFolder: $(Build.ArtifactStagingDirectory) 23 | - task: CopyFiles@2 24 | inputs: 25 | SourceFolder: 'Release' 26 | Contents: '*.exe' 27 | TargetFolder: $(Build.ArtifactStagingDirectory)/bin 28 | - task: PublishPipelineArtifact@1 29 | inputs: 30 | targetPath: $(Build.ArtifactStagingDirectory) 31 | - task: ArchiveFiles@2 32 | inputs: 33 | rootFolderOrFile: $(Build.ArtifactStagingDirectory) 34 | includeRootFolder: false 35 | archiveType: 7z 36 | archiveFile: $(Build.ArtifactStagingDirectory)/ShaderCompile$(Build.BuildId).7z 37 | - task: GitHubRelease@1 38 | inputs: 39 | gitHubConnection: 'release' 40 | repositoryName: '$(Build.Repository.Name)' 41 | action: 'create' 42 | target: '$(Build.SourceVersion)' 43 | tagSource: 'userSpecifiedTag' 44 | tag: 'build_$(Build.BuildId)_$(Build.BuildNumber)' 45 | releaseNotesSource: 'inline' 46 | changeLogCompareToRelease: 'lastFullRelease' 47 | changeLogType: 'commitBased' 48 | assets: | 49 | $(Build.ArtifactStagingDirectory)/ShaderCompile$(Build.BuildId).7z 50 | $(Build.ArtifactStagingDirectory)/bin/*.exe -------------------------------------------------------------------------------- /scripts/bin/process_shaders.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param ( 3 | [Parameter(Mandatory=$true, ValueFromPipeline=$true)][System.IO.FileInfo]$File, 4 | [Parameter(Mandatory=$true)][string]$Version, 5 | [Parameter(Mandatory=$false)][switch]$Dynamic, 6 | [Parameter(Mandatory=$false)][System.UInt32]$Threads 7 | ) 8 | 9 | if ($Version -notin @("20b", "30", "40", "41", "50", "51")) { 10 | return 11 | } 12 | 13 | $fileList = $File.OpenText() 14 | while ($null -ne ($line = $fileList.ReadLine())) { 15 | if ($line -match '^\s*$' -or $line -match '^\s*//') { 16 | continue 17 | } 18 | 19 | if ($Dynamic) { 20 | & "$PSScriptRoot\ShaderCompile" "-dynamic" "-ver" $Version "-shaderpath" $File.DirectoryName $line 21 | continue 22 | } 23 | 24 | if ($Threads -ne 0) { 25 | & "$PSScriptRoot\ShaderCompile" "-threads" $Threads "-ver" $Version "-shaderpath" $File.DirectoryName $line 26 | continue 27 | } 28 | 29 | & "$PSScriptRoot\ShaderCompile" "-ver" $Version "-shaderpath" $File.DirectoryName $line 30 | } 31 | $fileList.Close() 32 | -------------------------------------------------------------------------------- /scripts/stdshaders/buildshaders.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set TTEXE=..\..\devtools\bin\timeprecise.exe 4 | if not exist %TTEXE% goto no_ttexe 5 | goto no_ttexe_end 6 | 7 | :no_ttexe 8 | set TTEXE=time /t 9 | :no_ttexe_end 10 | 11 | echo. 12 | echo ==================== buildshaders %* ================== 13 | %TTEXE% -cur-Q 14 | set tt_start=%ERRORLEVEL% 15 | set tt_chkpt=%tt_start% 16 | 17 | 18 | REM **************** 19 | REM usage: buildshaders 20 | REM **************** 21 | 22 | setlocal 23 | set arg_filename=%1 24 | set shadercompilecommand=ShaderCompile.exe 25 | set targetdir=shaders 26 | set SrcDirBase=..\.. 27 | set shaderDir=shaders 28 | set SDKArgs=-local 29 | 30 | if "%1" == "" goto usage 31 | set inputbase=%1 32 | 33 | REM ignore -dx9_30 34 | if /i "%6" == "-dx9_30" shift /6 35 | 36 | if /i "%6" == "-force30" goto set_force30_arg 37 | goto set_force_end 38 | :set_force30_arg 39 | set IS30=1 40 | goto set_force_end 41 | :set_force_end 42 | 43 | if /i "%2" == "-game" goto set_mod_args 44 | goto build_shaders 45 | 46 | REM **************** 47 | REM USAGE 48 | REM **************** 49 | :usage 50 | echo. 51 | echo "usage: buildshaders [-game] [gameDir if -game was specified] [-source sourceDir]" 52 | echo " gameDir is where gameinfo.txt is (where it will store the compiled shaders)." 53 | echo " sourceDir is where the source code is (where it will find scripts and compilers)." 54 | echo "ex : buildshaders myshaders" 55 | echo "ex : buildshaders myshaders -game c:\steam\steamapps\sourcemods\mymod -source c:\mymod\src" 56 | goto :end 57 | 58 | REM **************** 59 | REM MOD ARGS - look for -game or the vproject environment variable 60 | REM **************** 61 | :set_mod_args 62 | 63 | if not exist "..\..\devtools\bin\ShaderCompile.exe" goto NoShaderCompile 64 | set ChangeToDir=%SrcDirBase%\devtools\bin\ 65 | 66 | if /i "%4" NEQ "-source" goto NoSourceDirSpecified 67 | set SrcDirBase=%~5 68 | 69 | REM ** use the -game parameter to tell us where to put the files 70 | set targetdir=%~3\shaders 71 | 72 | if not exist "%~3\gameinfo.txt" goto InvalidGameDirectory 73 | 74 | if not exist "%inputbase%.txt" goto InvalidInputFile 75 | 76 | goto build_shaders 77 | 78 | REM **************** 79 | REM ERRORS 80 | REM **************** 81 | :InvalidGameDirectory 82 | echo Error: "%~3" is not a valid game directory. 83 | echo (The -game directory must have a gameinfo.txt file) 84 | goto end 85 | 86 | :InvalidInputFile 87 | echo Error: "%inputbase%.txt" is not a valid file. 88 | goto end 89 | 90 | :NoSourceDirSpecified 91 | echo ERROR: If you specify -game on the command line, you must specify -source. 92 | goto usage 93 | goto end 94 | 95 | :NoShaderCompile 96 | echo - ERROR: ShaderCompile.exe doesn't exist in devtools\bin 97 | goto end 98 | 99 | REM **************** 100 | REM BUILD SHADERS 101 | REM **************** 102 | :build_shaders 103 | 104 | rem echo -------------------------------- 105 | rem echo %inputbase% 106 | rem echo -------------------------------- 107 | REM make sure that target dirs exist 108 | REM files will be built in these targets and copied to their final destination 109 | if not exist include mkdir include 110 | if not exist %shaderDir% mkdir %shaderDir% 111 | if not exist %shaderDir%\fxc mkdir %shaderDir%\fxc 112 | REM Nuke some files that we will add to later. 113 | 114 | set SHVER=20b 115 | if defined IS30 ( 116 | set SHVER=30 117 | ) 118 | 119 | title %1 %SHVER% 120 | 121 | echo Building inc files and worklist for %inputbase%... 122 | 123 | set DYNAMIC= 124 | if "%dynamic_shaders%" == "1" set DYNAMIC=-Dynamic 125 | powershell -NoLogo -ExecutionPolicy Bypass -Command "%SrcDirBase%\devtools\bin\process_shaders.ps1 %DYNAMIC% -Version %SHVER% '%inputbase%.txt'" 126 | 127 | REM **************** 128 | REM PC Shader copy 129 | REM Publish the generated files to the output dir using XCOPY 130 | REM This batch file may have been invoked standalone or slaved (master does final smart mirror copy) 131 | REM **************** 132 | :DoXCopy 133 | if not "%dynamic_shaders%" == "1" ( 134 | if not exist "%targetdir%" md "%targetdir%" 135 | if not "%targetdir%"=="%shaderDir%" xcopy %shaderDir%\*.* "%targetdir%" /e /y 136 | ) 137 | goto end 138 | 139 | REM **************** 140 | REM END 141 | REM **************** 142 | :end 143 | 144 | 145 | %TTEXE% -diff %tt_start% 146 | echo. --------------------------------------------------------------------------------