You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rb none #lockdown nick.penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 3292215 on 2017/02/08 by Nick.Shin HTML5 emscripten: wasm and wbegl2 support - emscripten toolchain #jira UEPLAT-1437 Switch [to] web assembly #rb none Change 3293994 on 2017/02/09 by Nick.Shin HTML5 emscripten: wasm and webgl2 support - OSX toolchain #jira UEPLAT-1437 Switch [to] web assembly #rb none Change 3317951 on 2017/02/22 by Nick.Shin HTML5 emscripten: wasm & webgl2 support - RC1 - emscripten toolchain WARNING: emscripten/incoming/source/include/libc/bit (the file) might need to be deleted first #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 #rb none Change 3318669 on 2017/02/23 by Nick.Shin HTML5 emscripten: wasm & webgl2 support - RC1 - OSX toolchain #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 #rb none Change 3462146 on 2017/05/26 by Nick.Shin HTML5 - merge from Release-4.16 to Dev-Mobile #jira none #rb none #rnx Change 3504996 on 2017/06/22 by Cosmin.Sulea UEMOB-362 - Add per-texture and per-format compression quality override settings #rb Dmitriy.Dyomin #jira UEMOB-362 #codereview Dmitriy.Dyomin #codereview Jack.Porter Change 3505056 on 2017/06/22 by Cosmin.Sulea Back out changelist 3504996 - due to errors generated in xboxOne, PS4 and Switch versions #rb none Change 3508049 on 2017/06/23 by Nick.Shin HTML5 toolchain notes corrections #jira none #rb none #rnx Change 3508663 on 2017/06/24 by Nick.Shin HTML5LaunchHelper.exe on linux - redo - it seems that i need to also check-in the exe and pdb file instead of having CIS make and checking-in them itself... - modified c# program to output a version number to help track which version of HTML5LaunchHelper is running... #jira UE-45302 HTML5LaunchHelper.exe hosts the files in the current working directory on Linux #rnx #rb none Change 3509210 on 2017/06/26 by Dmitriy.Dyomin ExposureScale will be applied during tonemap pass when MobileHDR is on #rb jack.porter #codereview Allan.Bentham Change 3511058 on 2017/06/27 by Cosmin.Sulea UEMOB-362 - Add per-texture and per-format compression quality override settings - resubmitted #rb Dmitriy.Dyomin #jira UEMOB-362 #codereview Dmitriy.Dyomin Change 3511069 on 2017/06/27 by Jack.Porter PS4, XboxOne and Switch fixes for changes to ITextureFormat interface #rb Dmitriy.Dyomin #jira UEMOB-362 Change 3513028 on 2017/06/28 by Jack.Porter Merging //UE4/Dev-Main to Dev-Mobile (//UE4/Dev-Mobile) #rb None Change 3517409 on 2017/06/30 by Jack.Porter Merging //UE4/Dev-Main to Dev-Mobile (//UE4/Dev-Mobile) #rb None Change 3517730 on 2017/06/30 by Cosmin.Sulea UEMOB-328 - Improve handling of iOS signing key on remote Mac system keychain when using remote toolchain #rb Jack.Porter #jira UEMOB-328 #codereview: peter.sauerbrei Change 3517757 on 2017/06/30 by Cosmin.Sulea UE-46245 - Building with remote toolchain does not use Project Setting for iOS signing identity which can cause signing errors #rb Jack.Porter #jira UE-46245 #codereview: peter.sauerbrei Change 3518149 on 2017/06/30 by Adrian.Chelu UE-43035 Tilt axis for X and Z are not consistent between Android and iOS devices #rb Jack.Porter #jira UE-46245 #codereview: Chris Babcock <chris.babcock@epicgames.com> Change 3524242 on 2017/07/06 by Nick.Shin HTML5 - refraction shader note: this CL also contains fixes to webgl2 [float4 vs half2] and a [% vs Mod()] material custom function changes to some TM-ShaderModels shaders specifically: fixes to and similar with: DitherTemporalAA #jria UE-46434 No Refraction in QA Game TM-Shadermodels HTML5 #rb none #rn #codereview jack.porter dmitriy.dyomin Change 3535295 on 2017/07/13 by Allan.Bentham #jira UEMOB-390 Add Android cpu stats. add 'stat AndroidCPU' to android's console spinner UI. increase GetCPUState's core count support to 16. #jira UE-45888 Use cvar value to limit android cpu stat update rate. #rb none Change 3535306 on 2017/07/13 by Allan.Bentham Add missing pragma once #rb none Change 3537047 on 2017/07/13 by Ben.Marsh Fixing case of iOS directories, pt1 #rb none Change 3537051 on 2017/07/13 by Ben.Marsh Fixing case of iOS directories, pt2 #rb none Change 3537373 on 2017/07/14 by Allan.Bentham Add scope level android egl error verification. work around minor issue with invalid egl config property. #rb chris.babcock Change3541735on 2017/07/18 by Allan.Bentham Add 'sustained performance mode' support for API 24+ devices. #jira UEMOB-386 #rb chris.babcock Change 3543001 on 2017/07/18 by Sorin.Gradinaru #jira UE-45766 Improved Virtual Keyboard cannot receive non-English characters. - for Android, add an native EditBox above the virtual keyboard to receive the text and pass it to the object from the slate #rb Chris.Babcock Change 3554399 on 2017/07/25 by Nick.Shin STATS disabled for non multi-threaded platforms #jira UE-47485 ( Pri:1 - 4.18 ) Crash running Stat Command test in TM-Core on Firefox #rnx #rb none Change 3554402 on 2017/07/25 by Nick.Shin STATS TaskGraph disabled for non multi-threaded platforms #jira UE-47486 ( Pri:1 - 4.18 ) QAGame hard locks on Firefox when triggering Task Graph Benchmark test #rb none #rnx Change 3556957 on 2017/07/26 by Nick.Shin HTML5 - WASM enabled by default - part 1 -- commenting out asmjs stuff begin sunsetting ASM.JS note to self: CL#3462146 "backout" asmjs #jira UEMOB-416 WASM enabled by default #rnx #rb none Change 3557654 on 2017/07/26 by Nick.Shin HTML5 - WASM enabled by default - part 2 -- remove asmjs code sunsetting ASM.JS note to self: CL#3462146 "backout" asmjs #jira UEMOB-416 WASM enabled by default #rn #rb none Change 3557910 on 2017/07/27 by Jack.Porter Support Client configuration when packaging in the editor #jira UE-39973 #rb Dmitriy.Dyomin Change3557917on 2017/07/27 by Jack.Porter Missing file from CL 3557910 #rb trivial Change 3559642 on 2017/07/27 by Nick.Shin STATS TaskGraph disabled for non multi-threaded platforms - both "LockFree stress test" and "task graph benchmark" are disabled - no multi-threading for WASM exist yet (note: ASM.JS has been sunsetted) - stat command crash "fixed" - but, font size are totally broken - i can look at this (much) later... - new bug: physx will crash on "gc and level load stress test" -- please bug this as a new jira #jira UE-47486 ( Pri:1 - 4.18 ) QAGame hard locks on Firefox when triggering Task Graph Benchmark test #rb none #rnx Change 3565656 on 2017/07/31 by Dmitriy.Dyomin Added a way to lock level position in Word Composition #jira UE-47713 #rb none Change 3565757 on 2017/08/01 by Dmitriy.Dyomin compile fix #rb none Change 3567446 on 2017/08/01 by Chris.Babcock Allow addElement and addElements to only insert once with once="true" attribute in UPL #jira UE-47951 #ue4 #android #rb Peter.Sauerbrei Change 3567592 on 2017/08/01 by Chris.Babcock Use absolute path for repositories for Gradle #jira UE-47952 #ue4 #android #rb Tim.Lincoln Change 3568690 on 2017/08/02 by Chris.Babcock Removed warnings for once attribute in UPL #ue4 #android #rb none Change 3569975 on 2017/08/02 by Chris.Babcock Add <baseBuildGradleAdditions> to UPL to allow additions to the root-level build.gradle #jira UE-47995 #ue4 #android #rb Tim.Lincoln Change 3570117 on 2017/08/02 by Chris.Babcock Add <setBoolFromPropertyContains> to UPL - sets bool to true if string list in ini matches contains attribute #jira UE-47996 #ue4 #android #rb Jack.Porter Change 3571552 on 2017/08/03 by Chris.Babcock Removed unneeded settings.gradle file (generated) #jira UE-48041 #ue4 #android #rb none Change 3572224 on 2017/08/04 by Dmitriy.Dyomin Better selection tracking in world composition #rb none Change 3573662 on 2017/08/04 by Nick.Shin HTML5 remove PreLoadMap "feature" (was only available/used with HTML5) - asyncronous loads are not allowed during UEngine::LoadMap() - the files/code will be repurposed for pakfile CHUNK support #jira UEMOB-425 HTML5 streaming content investigation (part 1 of 2) #rn #rb none Change 3574471 on 2017/08/07 by Dmitriy.Dyomin Export ULevelStreamingKismet::LoadLevelInstance function #rb none Change 3576262 on 2017/08/08 by Dmitriy.Dyomin Fixed: widget clipping issues in world composition #rb none Change 3576845 on 2017/08/08 by Nick.Shin set HTML5LaunchHelper application's icon to UE4.ico #jira UE-19225 HTML5LaunchHelper application does not have an unreal icon #rb none #rnx Change 3578313 on 2017/08/09 by Dmitriy.Dyomin Added: an RHI call to invalidate/clear cached state, RHIInvalidateCachedState #jira UEMOB-435 #rb jack.porter Change 3578364 on 2017/08/09 by Dmitriy.Dyomin Vertex Fog is disabled on mobile by default. If scene uses vertex fog - Mobile preview and device will show on screen message: PROJECT HAS VERTEX FOG ON MOBILE DISABLED This saves about 90 instructions in VS and a few in PS #jira UEMOB-166 #rb jack.porter Change 3578703 on 2017/08/09 by Nick.Shin set HTML5LaunchHelper application's icon to UE4.ico forgot to check in exe and pdb file #jira UE-19225 HTML5LaunchHelper application does not have an unreal icon #rb none #rnx Change 3578961 on 2017/08/09 by Peter.Sauerbrei deprecate IOS 8 as the minimum OS supported. #jira UEMOB-429 #rb chris.babcock Change 3579319 on 2017/08/09 by Peter.Sauerbrei fixes for compile errors with Xcode 9 beta 4 #rb none Change 3579356 on 2017/08/09 by Peter.Sauerbrei modified minimum IOS to build with #rb chris.babcock Change 3579687 on 2017/08/09 by Chris.Babcock Fix GoogleVR Gradle packaging #jira UE-48239 #ue4 #android #rb none Change 3579921 on 2017/08/10 by Dmitriy.Dyomin GitHub 3670 : More zoom levels for World Composition (300) #contributedby: user37337 #jira UE-45977 #3670 #rb none Change 3580576 on 2017/08/10 by Peter.Sauerbrei detection of iPad Pro 10.5 and IPad Pro 12.9 (2nd Gen) #rb chris.babcock Change 3580611 on 2017/08/10 by Chris.Babcock Set online provider back to GooglePlay and remove forcing IAP permission (contributed by umerov1999) #jira UE-48185 #PR #3876 #ue4 #android #rb Peter.Sauerbrei Change 3582166 on 2017/08/11 by Nick.Shin nuke PLATFORM_HTML5_WIN32 PLATFORM_HTML5_WIN32 code removal tested successfully with (force rebuild and repackaging): * Win64 server (WindowsServer) * Win64 client (WindowsNoEditor) * HTML5 client all playing together via websocket net driver (i've attached a screen shot of this in jira) code changes touches: physics, audio and main build files #jira UEMOB-433 Remove Win32 SDL "HTML5 Simulator" code #rb ben.marsh #rnx #codereview josh.adams #fyi ori.cohen, aaron.mclera Change 3582474 on 2017/08/11 by Chris.Babcock Don't use V2 signing for Gear VR APKs #jira UE-48354 #ue4 #android #rb Peter.Sauerbrei Change 3582614 on 2017/08/11 by Chris.Babcock Filter out unneeded architectures from APK for Gradle builds #jira UE-48355 #ue4 #android #rb Peter.Sauerbrei Change 3582923 on 2017/08/11 by Nick.Shin backport release 4.17 to dev-mobile #jira none #rb none #rnx Change 3582924 on 2017/08/11 by Nick.Shin FNetworkFileServerHttp - error gracefully when port is already in use #jira UE-46409 [CrashReport] Assertion on Mac: Could not create a libwebsocket - FNetworkFileServerHttp::Init() #rnx #rb none Change 3582925 on 2017/08/11 by Nick.Shin HTML5 - turn off pak file compression in favor of gzip packages #jira UE-46729 HTML5 - on shipping builds - turn off pak file compression in favor of gzip packages #rn #rb none Change 3583943 on 2017/08/14 by Cosmin.Sulea UEMOB-363 - second iteration - Project wide texture quality control by texture group #rb Dmitriy Dyomin #jira UEMOB-363 Change 3583967 on 2017/08/14 by Cosmin.Sulea Back out changelist 3583943 #rb none Change 3584121 on 2017/08/14 by Peter.Sauerbrei fix for mac compile failure #rb none Change 3587877 on 2017/08/15 by Peter.Sauerbrei josh's suggested fix is not working for Xcode 8.3, so brute forcing for now #rb none Change 3588612 on 2017/08/15 by Peter.Sauerbrei Xcode 9 project compatbility updates #rb chris.babcock #codereview michael.trepka Change 3589223 on 2017/08/15 by Dmitriy.Dyomin Fixed: bNavigationAutoUpdateEnabled was not always working when reopeinig the map Fixed: Navigation Build was not clearing some mesh tiles when bNavigationAutoUpdateEnabled is enabled Fixed: Streaming out a level in editor was not always updating NavMesh debug draw #rb lukasz.furman Change 3589900 on 2017/08/16 by Dmitriy.Dyomin Support vulkan validation layers on Android, only in Debug and Development configuration (requires r.Vulkan.EnableValidation=1) #codereview chris.babcock, rolando.caloca #rb none Change 3590592 on 2017/08/16 by Nick.Shin HTML5 emscripten 1.37.19 OSX #jira UE-47813 #rb none #rn HTML5 emscripten 1.37.19 OSX Change 3590597 on 2017/08/16 by Nick.Shin HTML5 emscripten 1.37.19 Linux #jira UE-47813 #rb none #rn HTML5 emscripten 1.37.19 Linux Change 3590624 on 2017/08/16 by Nick.Shin HTML5 emscripten 1.37.19 toolchain #jira UE-47813 #rb none #rn HTML5 emscripten 1.37.19 toolchain Change 3591720 on 2017/08/16 by Chris.Babcock Enable Gradle by default and add button to accept Android SDK license to project settings #jira UE-48519 #ue4 #android #rb Tim.Lincoln #fyi Peter.Sauerbrei Change 3591998 on 2017/08/16 by Chris.Babcock Fix nonunity build #ue4 #android #rb none Change 3592407 on 2017/08/17 by Nick.Shin HTML5 emscripten 1.37.19 Win64 #jira UE-47813 #rb none #rn HTML5 emscripten 1.37.19 Win64 Change 3592479 on 2017/08/17 by Nick.Shin HTML5 3rd Party Libs - compiled with emscripten 1.37.19 #jira UE-47813 #rb none #rn HTML5 3rd Party Libs - compiled with emscripten 1.37.19 toolchain Change 3592480 on 2017/08/17 by Nick.Shin HTML5 emscripten 1.37.19 toolchain Epic edits as well as setting UE4 HTML c# scripts to use new toolchain #jira UE-47813 #rb none #rn HTML5 emscripten 1.37.19 toolchain Epic edits Change 3592481 on 2017/08/17 by Nick.Shin HTML5 remove old emscripten toolchain #jira UE-47813 #rb none #rn HTML5 remove old emscripten toolchain Change 3592485 on 2017/08/17 by Nick.Shin HTML5 undo CanUseXGE - this might be breaking CIS for HTML5 builds... #jira UE-47813 #rb none #rnx Change 3592549 on 2017/08/17 by Dmitriy.Dyomin Added GetDiskTotalAndFreeSpace for IOS and Android #jira UE-46479 #codereview chris.babcock, peter.sauerbrei #rb none Change 3594045 on 2017/08/17 by Peter.Sauerbrei comment about potential failure case in the remote tool chain #rb none Change 3594342 on 2017/08/17 by Peter.Sauerbrei Merging //UE4/Main/... to //UE4/Dev-Mobile/... #rb none Change 3594920 on 2017/08/17 by Peter.Sauerbrei fix for non-unity builds (accidentally merged something incorrectly) #rb none Change 3595347 on 2017/08/17 by Chris.Babcock merge fixes for Android #ue4 #android #rb Peter.Sauerbrei #lockdown Peter.Sauerbrei Change 3595752 on 2017/08/17 by Chris.Babcock Update Facebook plugin to support Gradle #jira UE-48569 #ue4 #android #fyi Josh.Markiewicz #rb none #lockdown Peter.Sauerbrei Change 3595849 on 2017/08/17 by Chris.Babcock Fix issue with libovrplatformloader.so for non armv7 targets #jira UE-48533 #ue4 #android #rb none #lockdown Peter.Sauerbrei Change 3596419 on 2017/08/18 by Peter.Sauerbrei fix for Mac Editor build failure #rb none Change 3597023 on 2017/08/18 by Peter.Sauerbrei fix for game editor build failure #rb none Change 3597032 on 2017/08/18 by Peter.Sauerbrei fix for app bundle id in Info-Editor.plist #rb none Change 3597034 on 2017/08/18 by Peter.Sauerbrei put back the info.plist, found the real problem #rb none Change 3597197 on 2017/08/18 by Peter.Sauerbrei pull Info.plist from the build products #rb none [CL 3600450 by Chris Babcock in Main branch]
846 lines
28 KiB
C++
846 lines
28 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "HAL/FileManager.h"
|
|
#include "Misc/CommandLine.h"
|
|
#include "Containers/IndirectArray.h"
|
|
#include "Stats/Stats.h"
|
|
#include "Async/AsyncWork.h"
|
|
#include "Misc/ConfigCacheIni.h"
|
|
#include "ImageCore.h"
|
|
#include "Modules/ModuleManager.h"
|
|
#include "Interfaces/ITextureFormat.h"
|
|
#include "Interfaces/ITextureFormatModule.h"
|
|
#include "TextureCompressorModule.h"
|
|
#include "PixelFormat.h"
|
|
|
|
#include "ispc_texcomp.h"
|
|
|
|
DEFINE_LOG_CATEGORY_STATIC(LogTextureFormatIntelISPCTexComp, Log, All);
|
|
|
|
// increment this if you change anything that will affect compression in this file, including FORCED_NORMAL_MAP_COMPRESSION_SIZE_VALUE
|
|
#define BASE_ISPC_DX11_FORMAT_VERSION 3
|
|
|
|
// For debugging intermediate image results by saving them out as files.
|
|
#define DEBUG_SAVE_INTERMEDIATE_IMAGES 0
|
|
|
|
/**
|
|
* Macro trickery for supported format names.
|
|
*/
|
|
#define ENUM_SUPPORTED_FORMATS(op) \
|
|
op(BC6H) \
|
|
op(BC7)
|
|
|
|
#define DECL_FORMAT_NAME(FormatName) static FName GTextureFormatName##FormatName = FName(TEXT(#FormatName));
|
|
ENUM_SUPPORTED_FORMATS(DECL_FORMAT_NAME);
|
|
#undef DECL_FORMAT_NAME
|
|
|
|
#define DECL_FORMAT_NAME_ENTRY(FormatName) GTextureFormatName##FormatName ,
|
|
static FName GSupportedTextureFormatNames[] =
|
|
{
|
|
ENUM_SUPPORTED_FORMATS(DECL_FORMAT_NAME_ENTRY)
|
|
};
|
|
#undef DECL_FORMAT_NAME_ENTRY
|
|
#undef ENUM_SUPPORTED_FORMATS
|
|
|
|
#define ENUM_ASTC_FORMATS(op) \
|
|
op(ASTC_RGB) \
|
|
op(ASTC_RGBA) \
|
|
op(ASTC_RGBAuto) \
|
|
op(ASTC_NormalAG) \
|
|
op(ASTC_NormalRG)
|
|
|
|
#define DECL_FORMAT_NAME(FormatName) static FName GTextureFormatName##FormatName = FName(TEXT(#FormatName));
|
|
ENUM_ASTC_FORMATS(DECL_FORMAT_NAME);
|
|
#undef DECL_FORMAT_NAME
|
|
#undef ENUM_ASTC_FORMATS
|
|
|
|
// BC6H, BC7, ASTC all have 16-byte block size
|
|
#define BLOCK_SIZE_IN_BYTES 16
|
|
|
|
|
|
// Bitmap compression types.
|
|
enum EBitmapCompression
|
|
{
|
|
BCBI_RGB = 0,
|
|
BCBI_RLE8 = 1,
|
|
BCBI_RLE4 = 2,
|
|
BCBI_BITFIELDS = 3,
|
|
};
|
|
|
|
// .BMP file header.
|
|
#pragma pack(push,1)
|
|
struct FBitmapFileHeader
|
|
{
|
|
uint16 bfType;
|
|
uint32 bfSize;
|
|
uint16 bfReserved1;
|
|
uint16 bfReserved2;
|
|
uint32 bfOffBits;
|
|
friend FArchive& operator<<(FArchive& Ar, FBitmapFileHeader& H)
|
|
{
|
|
Ar << H.bfType << H.bfSize << H.bfReserved1 << H.bfReserved2 << H.bfOffBits;
|
|
return Ar;
|
|
}
|
|
};
|
|
#pragma pack(pop)
|
|
|
|
// .BMP subheader.
|
|
#pragma pack(push,1)
|
|
struct FBitmapInfoHeader
|
|
{
|
|
uint32 biSize;
|
|
uint32 biWidth;
|
|
int32 biHeight;
|
|
uint16 biPlanes;
|
|
uint16 biBitCount;
|
|
uint32 biCompression;
|
|
uint32 biSizeImage;
|
|
uint32 biXPelsPerMeter;
|
|
uint32 biYPelsPerMeter;
|
|
uint32 biClrUsed;
|
|
uint32 biClrImportant;
|
|
friend FArchive& operator<<(FArchive& Ar, FBitmapInfoHeader& H)
|
|
{
|
|
Ar << H.biSize << H.biWidth << H.biHeight;
|
|
Ar << H.biPlanes << H.biBitCount;
|
|
Ar << H.biCompression << H.biSizeImage;
|
|
Ar << H.biXPelsPerMeter << H.biYPelsPerMeter;
|
|
Ar << H.biClrUsed << H.biClrImportant;
|
|
return Ar;
|
|
}
|
|
};
|
|
#pragma pack(pop)
|
|
|
|
|
|
void SaveImageAsBMP( FArchive& Ar, const uint8* RawData, int SourceBytesPerPixel, int SizeX, int SizeY )
|
|
{
|
|
FBitmapFileHeader bmf;
|
|
FBitmapInfoHeader bmhdr;
|
|
|
|
// File header.
|
|
bmf.bfType = 'B' + (256 * (int32)'M');
|
|
bmf.bfReserved1 = 0;
|
|
bmf.bfReserved2 = 0;
|
|
int32 biSizeImage = SizeX * SizeY * 3;
|
|
bmf.bfOffBits = sizeof(FBitmapFileHeader) + sizeof(FBitmapInfoHeader);
|
|
bmhdr.biBitCount = 24;
|
|
|
|
bmf.bfSize = bmf.bfOffBits + biSizeImage;
|
|
Ar << bmf;
|
|
|
|
// Info header.
|
|
bmhdr.biSize = sizeof(FBitmapInfoHeader);
|
|
bmhdr.biWidth = SizeX;
|
|
bmhdr.biHeight = SizeY;
|
|
bmhdr.biPlanes = 1;
|
|
bmhdr.biCompression = BCBI_RGB;
|
|
bmhdr.biSizeImage = biSizeImage;
|
|
bmhdr.biXPelsPerMeter = 0;
|
|
bmhdr.biYPelsPerMeter = 0;
|
|
bmhdr.biClrUsed = 0;
|
|
bmhdr.biClrImportant = 0;
|
|
Ar << bmhdr;
|
|
|
|
bool bIsRGBA16 = (SourceBytesPerPixel == 8);
|
|
|
|
//NOTE: Each row must be 4-byte aligned in a BMP.
|
|
int PaddingX = Align(SizeX * 3, 4) - SizeX * 3;
|
|
|
|
// Upside-down scanlines.
|
|
for (int32 i = SizeY - 1; i >= 0; i--)
|
|
{
|
|
const uint8* ScreenPtr = &RawData[i*SizeX*SourceBytesPerPixel];
|
|
for (int32 j = SizeX; j > 0; j--)
|
|
{
|
|
uint8 R, G, B;
|
|
if (bIsRGBA16)
|
|
{
|
|
R = ScreenPtr[1];
|
|
G = ScreenPtr[3];
|
|
B = ScreenPtr[5];
|
|
ScreenPtr += 8;
|
|
}
|
|
else
|
|
{
|
|
R = ScreenPtr[0];
|
|
G = ScreenPtr[1];
|
|
B = ScreenPtr[2];
|
|
ScreenPtr += 4;
|
|
}
|
|
Ar << R;
|
|
Ar << G;
|
|
Ar << B;
|
|
}
|
|
for (int32 j = 0; j < PaddingX; ++j)
|
|
{
|
|
int8 PadByte = 0;
|
|
Ar << PadByte;
|
|
}
|
|
}
|
|
}
|
|
|
|
#define MAGIC_FILE_CONSTANT 0x5CA1AB13
|
|
|
|
// little endian
|
|
#pragma pack(push,1)
|
|
struct astc_header
|
|
{
|
|
uint8_t magic[4];
|
|
uint8_t blockdim_x;
|
|
uint8_t blockdim_y;
|
|
uint8_t blockdim_z;
|
|
uint8_t xsize[3];
|
|
uint8_t ysize[3]; // x-size, y-size and z-size are given in texels;
|
|
uint8_t zsize[3]; // block count is inferred
|
|
};
|
|
#pragma pack(pop)
|
|
|
|
void SaveImageAsASTC(FArchive& Ar, uint8* RawData, int SizeX, int SizeY, int block_width, int block_height)
|
|
{
|
|
astc_header file_header;
|
|
|
|
uint32_t magic = MAGIC_FILE_CONSTANT;
|
|
FMemory::Memcpy(file_header.magic, &magic, 4);
|
|
file_header.blockdim_x = block_width;
|
|
file_header.blockdim_y = block_height;
|
|
file_header.blockdim_z = 1;
|
|
|
|
int32 xsize = SizeX;
|
|
int32 ysize = SizeY;
|
|
int32 zsize = 1;
|
|
|
|
FMemory::Memcpy(file_header.xsize, &xsize, 3);
|
|
FMemory::Memcpy(file_header.ysize, &ysize, 3);
|
|
FMemory::Memcpy(file_header.zsize, &zsize, 3);
|
|
|
|
Ar.Serialize(&file_header, sizeof(file_header));
|
|
|
|
size_t height_in_blocks = (SizeY + block_height - 1) / block_height;
|
|
size_t width_in_blocks = (SizeX + block_width - 1) / block_width;
|
|
int stride = width_in_blocks * BLOCK_SIZE_IN_BYTES;
|
|
Ar.Serialize(RawData, height_in_blocks * stride);
|
|
}
|
|
|
|
struct FMultithreadSettings
|
|
{
|
|
int iScansPerTask;
|
|
int iNumTasks;
|
|
};
|
|
|
|
template <typename EncoderSettingsType>
|
|
struct FMultithreadedCompression
|
|
{
|
|
typedef void(*CompressFunction)(EncoderSettingsType* pEncSettings, FImage* pInImage, FCompressedImage2D* pOutImage, int yStart, int yEnd, int SliceIndex);
|
|
|
|
static void Compress(FMultithreadSettings &MultithreadSettings, EncoderSettingsType &EncoderSettings, FImage &Image, FCompressedImage2D &OutCompressedImage, CompressFunction FunctionCallback, bool bUseTasks)
|
|
{
|
|
if (bUseTasks)
|
|
{
|
|
class FIntelCompressWorker : public FNonAbandonableTask
|
|
{
|
|
public:
|
|
FIntelCompressWorker(EncoderSettingsType* pEncSettings, FImage* pInImage, FCompressedImage2D* pOutImage, int yStart, int yEnd, int SliceIndex, CompressFunction InFunctionCallback)
|
|
: mpEncSettings(pEncSettings)
|
|
, mpInImage(pInImage)
|
|
, mpOutImage(pOutImage)
|
|
, mYStart(yStart)
|
|
, mYEnd(yEnd)
|
|
, mSliceIndex(SliceIndex)
|
|
, mCallback(InFunctionCallback)
|
|
{
|
|
}
|
|
|
|
void DoWork()
|
|
{
|
|
mCallback(mpEncSettings, mpInImage, mpOutImage, mYStart, mYEnd, mSliceIndex);
|
|
}
|
|
|
|
FORCEINLINE TStatId GetStatId() const
|
|
{
|
|
RETURN_QUICK_DECLARE_CYCLE_STAT(FIntelCompressWorker, STATGROUP_ThreadPoolAsyncTasks);
|
|
}
|
|
|
|
EncoderSettingsType* mpEncSettings;
|
|
FImage* mpInImage;
|
|
FCompressedImage2D* mpOutImage;
|
|
int mYStart;
|
|
int mYEnd;
|
|
int mSliceIndex;
|
|
CompressFunction mCallback;
|
|
};
|
|
typedef FAsyncTask<FIntelCompressWorker> FIntelCompressTask;
|
|
|
|
// One less task because we'll do the final + non multiple of 4 inside this task
|
|
TIndirectArray<FIntelCompressTask> CompressionTasks;
|
|
const int NumStasksPerSlice = MultithreadSettings.iNumTasks + 1;
|
|
CompressionTasks.Reserve(NumStasksPerSlice * Image.NumSlices - 1);
|
|
for (int SliceIndex = 0; SliceIndex < Image.NumSlices; ++SliceIndex)
|
|
{
|
|
for (int iTask = 0; iTask < NumStasksPerSlice; ++iTask)
|
|
{
|
|
// Create a new task unless it's the last task in the last slice (that one will run on current thread, after these threads have been started)
|
|
if (SliceIndex < (Image.NumSlices - 1) || iTask < (NumStasksPerSlice - 1))
|
|
{
|
|
auto* AsyncTask = new(CompressionTasks) FIntelCompressTask(&EncoderSettings, &Image, &OutCompressedImage, iTask * MultithreadSettings.iScansPerTask, (iTask + 1) * MultithreadSettings.iScansPerTask, SliceIndex, FunctionCallback);
|
|
AsyncTask->StartBackgroundTask();
|
|
}
|
|
}
|
|
}
|
|
FunctionCallback(&EncoderSettings, &Image, &OutCompressedImage, MultithreadSettings.iScansPerTask * MultithreadSettings.iNumTasks, Image.SizeY, Image.NumSlices - 1);
|
|
|
|
// Wait for all tasks to complete
|
|
for (int32 TaskIndex = 0; TaskIndex < CompressionTasks.Num(); ++TaskIndex)
|
|
{
|
|
CompressionTasks[TaskIndex].EnsureCompletion();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int SliceIndex = 0; SliceIndex < Image.NumSlices; ++SliceIndex)
|
|
{
|
|
FunctionCallback(&EncoderSettings, &Image, &OutCompressedImage, 0, Image.SizeY, SliceIndex);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
/**
|
|
* BC6H Compression function
|
|
*/
|
|
static void IntelBC6HCompressScans(bc6h_enc_settings* pEncSettings, FImage* pInImage, FCompressedImage2D* pOutImage, int yStart, int yEnd, int SliceIndex)
|
|
{
|
|
check(pInImage->Format == ERawImageFormat::RGBA16F);
|
|
check((yStart % 4) == 0);
|
|
check((pInImage->SizeX % 4) == 0);
|
|
check((yStart >= 0) && (yStart <= pInImage->SizeY));
|
|
check((yEnd >= 0) && (yEnd <= pInImage->SizeY));
|
|
|
|
const int InStride = pInImage->SizeX * 8;
|
|
const int OutStride = pInImage->SizeX / 4 * BLOCK_SIZE_IN_BYTES;
|
|
const int InSliceSize = pInImage->SizeY * InStride;
|
|
const int OutSliceSize = pInImage->SizeY / 4 * OutStride;
|
|
|
|
uint8* pInTexels = reinterpret_cast<uint8*>(&pInImage->RawData[0]) + InSliceSize * SliceIndex;
|
|
uint8* pOutTexels = reinterpret_cast<uint8*>(&pOutImage->RawData[0]) + OutSliceSize * SliceIndex;
|
|
|
|
rgba_surface insurface;
|
|
insurface.ptr = pInTexels + (yStart * InStride);
|
|
insurface.width = pInImage->SizeX;
|
|
insurface.height = yEnd - yStart;
|
|
insurface.stride = pInImage->SizeX * 8;
|
|
|
|
pOutTexels += yStart / 4 * OutStride;
|
|
CompressBlocksBC6H(&insurface, pOutTexels, pEncSettings);
|
|
}
|
|
|
|
/**
|
|
* BC7 Compression function
|
|
*/
|
|
static void IntelBC7CompressScans(bc7_enc_settings* pEncSettings, FImage* pInImage, FCompressedImage2D* pOutImage, int yStart, int yEnd, int SliceIndex)
|
|
{
|
|
check(pInImage->Format == ERawImageFormat::BGRA8);
|
|
check((yStart % 4) == 0);
|
|
check((pInImage->SizeX % 4) == 0);
|
|
check((yStart >= 0) && (yStart <= pInImage->SizeY));
|
|
check((yEnd >= 0) && (yEnd <= pInImage->SizeY));
|
|
|
|
const int InStride = pInImage->SizeX * 4;
|
|
const int OutStride = pInImage->SizeX / 4 * BLOCK_SIZE_IN_BYTES;
|
|
const int InSliceSize = pInImage->SizeY * InStride;
|
|
const int OutSliceSize = pInImage->SizeY / 4 * OutStride;
|
|
|
|
uint8* pInTexels = reinterpret_cast<uint8*>(&pInImage->RawData[0]) + InSliceSize * SliceIndex;
|
|
uint8* pOutTexels = reinterpret_cast<uint8*>(&pOutImage->RawData[0]) + OutSliceSize * SliceIndex;
|
|
|
|
// Switch byte order for compressors input
|
|
for ( int y=yStart; y < yEnd; ++y )
|
|
{
|
|
uint8* pInTexelsSwap = pInTexels + (y * InStride);
|
|
for ( int x=0; x < pInImage->SizeX; ++x )
|
|
{
|
|
const uint8 r = pInTexelsSwap[0];
|
|
pInTexelsSwap[0] = pInTexelsSwap[2];
|
|
pInTexelsSwap[2] = r;
|
|
|
|
pInTexelsSwap += 4;
|
|
}
|
|
}
|
|
|
|
rgba_surface insurface;
|
|
insurface.ptr = pInTexels + (yStart * InStride);
|
|
insurface.width = pInImage->SizeX;
|
|
insurface.height = yEnd - yStart;
|
|
insurface.stride = pInImage->SizeX * 4;
|
|
|
|
pOutTexels += yStart / 4 * OutStride;
|
|
CompressBlocksBC7(&insurface, pOutTexels, pEncSettings);
|
|
}
|
|
|
|
#define MAX_QUALITY_BY_SIZE 4
|
|
#define FORCED_NORMAL_MAP_COMPRESSION_SIZE_VALUE 4
|
|
|
|
static uint16 GetDefaultCompressionBySizeValue()
|
|
{
|
|
// start at default quality, then lookup in .ini file
|
|
int32 CompressionModeValue = 0;
|
|
GConfig->GetInt(TEXT("/Script/UnrealEd.CookerSettings"), TEXT("DefaultASTCQualityBySize"), CompressionModeValue, GEngineIni);
|
|
|
|
FParse::Value(FCommandLine::Get(), TEXT("-astcqualitybysize="), CompressionModeValue);
|
|
CompressionModeValue = FMath::Min<uint32>(CompressionModeValue, MAX_QUALITY_BY_SIZE);
|
|
|
|
return CompressionModeValue;
|
|
}
|
|
|
|
static EPixelFormat GetQualityFormat(int& BlockWidth, int& BlockHeight, int32 OverrideSizeValue = -1)
|
|
{
|
|
// Note: ISPC only supports 8x8 and higher quality, and only one speed (fast)
|
|
// convert to a string
|
|
EPixelFormat Format = PF_Unknown;
|
|
switch (OverrideSizeValue >= 0 ? OverrideSizeValue : GetDefaultCompressionBySizeValue())
|
|
{
|
|
case 0: //Format = PF_ASTC_12x12; BlockWidth = BlockHeight = 12; break;
|
|
case 1: //Format = PF_ASTC_10x10; BlockWidth = BlockHeight = 10; break;
|
|
case 2: Format = PF_ASTC_8x8; BlockWidth = BlockHeight = 8; break;
|
|
case 3: Format = PF_ASTC_6x6; BlockWidth = BlockHeight = 6; break;
|
|
case 4: Format = PF_ASTC_4x4; BlockWidth = BlockHeight = 4; break;
|
|
default: UE_LOG(LogTemp, Fatal, TEXT("Max quality higher than expected"));
|
|
}
|
|
|
|
return Format;
|
|
}
|
|
|
|
struct FASTCEncoderSettings : public astc_enc_settings
|
|
{
|
|
FName TextureFormatName;
|
|
};
|
|
|
|
|
|
/**
|
|
* ASTC Compression function
|
|
*/
|
|
static void IntelASTCCompressScans(FASTCEncoderSettings* pEncSettings, FImage* pInImage, FCompressedImage2D* pOutImage, int yStart, int yEnd, int SliceIndex)
|
|
{
|
|
check(pInImage->Format == ERawImageFormat::BGRA8);
|
|
check((yStart % pEncSettings->block_height) == 0);
|
|
check((pInImage->SizeX % pEncSettings->block_width) == 0);
|
|
check((yStart >= 0) && (yStart <= pInImage->SizeY));
|
|
check((yEnd >= 0) && (yEnd <= pInImage->SizeY));
|
|
|
|
const int InStride = pInImage->SizeX * 4;
|
|
const int OutStride = pInImage->SizeX / pEncSettings->block_width * BLOCK_SIZE_IN_BYTES;
|
|
const int InSliceSize = pInImage->SizeY * InStride;
|
|
const int OutSliceSize = pInImage->SizeY / pEncSettings->block_height * OutStride;
|
|
|
|
uint8* pInTexels = reinterpret_cast<uint8*>(&pInImage->RawData[0]) + InSliceSize * SliceIndex;
|
|
uint8* pOutTexels = reinterpret_cast<uint8*>(&pOutImage->RawData[0]) + OutSliceSize * SliceIndex;
|
|
|
|
if (pEncSettings->TextureFormatName == GTextureFormatNameASTC_RGB)
|
|
{
|
|
// Switch byte order for compressors input (BGRA -> RGBA)
|
|
// Force A=255
|
|
for (int y = yStart; y < yEnd; ++y)
|
|
{
|
|
uint8* pInTexelsSwap = pInTexels + (y * InStride);
|
|
for (int x = 0; x < pInImage->SizeX; ++x)
|
|
{
|
|
const uint8 r = pInTexelsSwap[0];
|
|
pInTexelsSwap[0] = pInTexelsSwap[2];
|
|
pInTexelsSwap[2] = r;
|
|
pInTexelsSwap[3] = 255;
|
|
|
|
pInTexelsSwap += 4;
|
|
}
|
|
}
|
|
}
|
|
else if (pEncSettings->TextureFormatName == GTextureFormatNameASTC_RGBA)
|
|
{
|
|
// Switch byte order for compressors input (BGRA -> RGBA)
|
|
for (int y = yStart; y < yEnd; ++y)
|
|
{
|
|
uint8* pInTexelsSwap = pInTexels + (y * InStride);
|
|
for (int x = 0; x < pInImage->SizeX; ++x)
|
|
{
|
|
const uint8 r = pInTexelsSwap[0];
|
|
pInTexelsSwap[0] = pInTexelsSwap[2];
|
|
pInTexelsSwap[2] = r;
|
|
|
|
pInTexelsSwap += 4;
|
|
}
|
|
}
|
|
}
|
|
else if (pEncSettings->TextureFormatName == GTextureFormatNameASTC_NormalAG)
|
|
{
|
|
// Switch byte order for compressors input (BGRA -> RGBA)
|
|
// Re-normalize
|
|
// Set any unused RGB components to 0, an unused A to 255.
|
|
for (int y = yStart; y < yEnd; ++y)
|
|
{
|
|
uint8* pInTexelsSwap = pInTexels + (y * InStride);
|
|
for (int x = 0; x < pInImage->SizeX; ++x)
|
|
{
|
|
FVector Normal = FVector(pInTexelsSwap[2] / 255.0f * 2.0f - 1.0f, pInTexelsSwap[1] / 255.0f * 2.0f - 1.0f, pInTexelsSwap[0] / 255.0f * 2.0f - 1.0f);
|
|
Normal = Normal.GetSafeNormal();
|
|
pInTexelsSwap[0] = 0;
|
|
pInTexelsSwap[1] = FMath::FloorToInt((Normal.Y * 0.5f + 0.5f) * 255.999f);
|
|
pInTexelsSwap[2] = 0;
|
|
pInTexelsSwap[3] = FMath::FloorToInt((Normal.X * 0.5f + 0.5f) * 255.999f);
|
|
|
|
pInTexelsSwap += 4;
|
|
}
|
|
}
|
|
}
|
|
else if (pEncSettings->TextureFormatName == GTextureFormatNameASTC_NormalRG)
|
|
{
|
|
// Switch byte order for compressors input (BGRA -> RGBA)
|
|
// Re-normalize
|
|
// Set any unused RGB components to 0, an unused A to 255.
|
|
for (int y = yStart; y < yEnd; ++y)
|
|
{
|
|
uint8* pInTexelsSwap = pInTexels + (y * InStride);
|
|
for (int x = 0; x < pInImage->SizeX; ++x)
|
|
{
|
|
FVector Normal = FVector(pInTexelsSwap[2] / 255.0f * 2.0f - 1.0f, pInTexelsSwap[1] / 255.0f * 2.0f - 1.0f, pInTexelsSwap[0] / 255.0f * 2.0f - 1.0f);
|
|
Normal = Normal.GetSafeNormal();
|
|
pInTexelsSwap[0] = FMath::FloorToInt((Normal.X * 0.5f + 0.5f) * 255.999f);
|
|
pInTexelsSwap[1] = FMath::FloorToInt((Normal.Y * 0.5f + 0.5f) * 255.999f);
|
|
pInTexelsSwap[2] = 0;
|
|
pInTexelsSwap[3] = 255;
|
|
|
|
pInTexelsSwap += 4;
|
|
}
|
|
}
|
|
}
|
|
|
|
rgba_surface insurface;
|
|
insurface.ptr = pInTexels + (yStart * InStride);
|
|
insurface.width = pInImage->SizeX;
|
|
insurface.height = yEnd - yStart;
|
|
insurface.stride = pInImage->SizeX * 4;
|
|
|
|
pOutTexels += yStart / pEncSettings->block_height * OutStride;
|
|
CompressBlocksASTC(&insurface, pOutTexels, pEncSettings);
|
|
}
|
|
|
|
/**
|
|
* Intel BC texture format handler.
|
|
*/
|
|
class FTextureFormatIntelISPCTexComp : public ITextureFormat
|
|
{
|
|
public:
|
|
FTextureFormatIntelISPCTexComp()
|
|
{
|
|
}
|
|
virtual ~FTextureFormatIntelISPCTexComp()
|
|
{
|
|
}
|
|
virtual bool AllowParallelBuild() const override
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// Return the version for the DX11 formats BC6H and BC7 (not ASTC)
|
|
virtual uint16 GetVersion(
|
|
FName Format,
|
|
const struct FTextureBuildSettings* BuildSettings = nullptr
|
|
) const override
|
|
{
|
|
return BASE_ISPC_DX11_FORMAT_VERSION;
|
|
}
|
|
|
|
// Since we want to have per texture [group] compression settings, we need to have the key based on the texture
|
|
virtual FString GetDerivedDataKeyString(const class UTexture& Texture) const override
|
|
{
|
|
return TEXT("");
|
|
}
|
|
|
|
virtual void GetSupportedFormats(TArray<FName>& OutFormats) const override
|
|
{
|
|
for (int32 i = 0; i < ARRAY_COUNT(GSupportedTextureFormatNames); ++i)
|
|
{
|
|
OutFormats.Add(GSupportedTextureFormatNames[i]);
|
|
}
|
|
}
|
|
|
|
virtual FTextureFormatCompressorCaps GetFormatCapabilities() const override
|
|
{
|
|
return FTextureFormatCompressorCaps(); // Default capabilities.
|
|
}
|
|
|
|
static void SetupScans(const FImage& InImage, int BlockWidth, int BlockHeight, FCompressedImage2D& OutCompressedImage, FMultithreadSettings &MultithreadSettings)
|
|
{
|
|
const int AlignedSizeX = AlignArbitrary(InImage.SizeX, BlockWidth);
|
|
const int AlignedSizeY = AlignArbitrary(InImage.SizeY, BlockHeight);
|
|
const int WidthInBlocks = AlignedSizeX / BlockWidth;
|
|
const int HeightInBlocks = AlignedSizeY / BlockHeight;
|
|
const int SizePerSlice = WidthInBlocks * HeightInBlocks * BLOCK_SIZE_IN_BYTES;
|
|
OutCompressedImage.RawData.AddUninitialized(SizePerSlice * InImage.NumSlices);
|
|
OutCompressedImage.SizeX = FMath::Max(AlignedSizeX, BlockWidth);
|
|
OutCompressedImage.SizeY = FMath::Max(AlignedSizeY, BlockHeight);
|
|
|
|
// When we allow async tasks to execute we do so with BlockHeight lines of the image per task
|
|
// This isn't optimal for long thin textures, but works well with how ISPC works
|
|
MultithreadSettings.iScansPerTask = BlockHeight;
|
|
MultithreadSettings.iNumTasks = FMath::Max((AlignedSizeY / MultithreadSettings.iScansPerTask) - 1, 0);
|
|
}
|
|
|
|
static void PadImageToBlockSize(FImage &InOutImage, int BlockWidth, int BlockHeight, int BytesPerPixel)
|
|
{
|
|
const int AlignedSizeX = AlignArbitrary(InOutImage.SizeX, BlockWidth);
|
|
const int AlignedSizeY = AlignArbitrary(InOutImage.SizeY, BlockHeight);
|
|
const int AlignedSliceSize = AlignedSizeX * AlignedSizeY * BytesPerPixel;
|
|
const int AlignedTotalSize = AlignedSliceSize * InOutImage.NumSlices;
|
|
const int OriginalSliceSize = InOutImage.SizeX * InOutImage.SizeY * BytesPerPixel;
|
|
|
|
// Early out if no padding is necessary
|
|
if (AlignedSizeX == InOutImage.SizeX && AlignedSizeY == InOutImage.SizeY)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Allocate temp buffer
|
|
//@TODO: Optimize away this temp buffer (could avoid last FMemory::Memcpy)
|
|
TArray<uint8> TempBuffer;
|
|
TempBuffer.SetNumUninitialized(AlignedTotalSize);
|
|
|
|
const int PaddingX = AlignedSizeX - InOutImage.SizeX;
|
|
const int PaddingY = AlignedSizeY - InOutImage.SizeY;
|
|
const int SrcStride = InOutImage.SizeX * BytesPerPixel;
|
|
const int DstStride = AlignedSizeX * BytesPerPixel;
|
|
|
|
for (int SliceIndex = 0; SliceIndex < InOutImage.NumSlices; ++SliceIndex)
|
|
{
|
|
uint8* DstData = ((uint8*)TempBuffer.GetData()) + SliceIndex * AlignedSliceSize;
|
|
const uint8* SrcData = ((uint8*)InOutImage.RawData.GetData()) + SliceIndex * OriginalSliceSize;
|
|
|
|
// Copy all of SrcData and pad on X-axis:
|
|
for (int Y = 0; Y < InOutImage.SizeY; ++Y)
|
|
{
|
|
FMemory::Memcpy(DstData, SrcData, SrcStride);
|
|
SrcData += SrcStride - BytesPerPixel; // Src: Last pixel on this row
|
|
DstData += SrcStride; // Dst: Beginning of the padded region at the end of this row
|
|
for (int PadX = 0; PadX < PaddingX; PadX++)
|
|
{
|
|
// Replicate right-most pixel as padding on X-axis
|
|
FMemory::Memcpy(DstData, SrcData, BytesPerPixel);
|
|
DstData += BytesPerPixel;
|
|
}
|
|
SrcData += BytesPerPixel; // Src & Dst: Beginning of next row
|
|
}
|
|
|
|
// Replicate last row as padding on Y-axis:
|
|
SrcData = DstData - DstStride; // Src: Beginning of the last row (of DstData)
|
|
for (int PadY = 0; PadY < PaddingY; PadY++)
|
|
{
|
|
FMemory::Memcpy(DstData, SrcData, DstStride);
|
|
DstData += DstStride; // Dst: Beginning of the padded region at the end of this row
|
|
}
|
|
}
|
|
|
|
// Replace InOutImage with the new data
|
|
InOutImage.RawData.Empty(AlignedTotalSize);
|
|
InOutImage.RawData.SetNumUninitialized(AlignedTotalSize);
|
|
FMemory::Memcpy(InOutImage.RawData.GetData(), TempBuffer.GetData(), AlignedTotalSize);
|
|
InOutImage.SizeX = AlignedSizeX;
|
|
InOutImage.SizeY = AlignedSizeY;
|
|
}
|
|
|
|
virtual bool CompressImage(
|
|
const FImage& InImage,
|
|
const struct FTextureBuildSettings& BuildSettings,
|
|
bool bImageHasAlphaChannel,
|
|
FCompressedImage2D& OutCompressedImage
|
|
) const override
|
|
{
|
|
check(InImage.SizeX > 0);
|
|
check(InImage.SizeY > 0);
|
|
check(InImage.NumSlices > 0);
|
|
|
|
bool bCompressionSucceeded = false;
|
|
|
|
int BlockWidth = 0;
|
|
int BlockHeight = 0;
|
|
|
|
const bool bUseTasks = true;
|
|
FMultithreadSettings MultithreadSettings;
|
|
|
|
EPixelFormat CompressedPixelFormat = PF_Unknown;
|
|
if ( BuildSettings.TextureFormatName == GTextureFormatNameBC6H )
|
|
{
|
|
FImage Image;
|
|
InImage.CopyTo(Image, ERawImageFormat::RGBA16F, EGammaSpace::Linear);
|
|
|
|
bc6h_enc_settings settings;
|
|
GetProfile_bc6h_basic(&settings);
|
|
|
|
SetupScans(Image, 4, 4, OutCompressedImage, MultithreadSettings);
|
|
PadImageToBlockSize(Image, 4, 4, 4*2);
|
|
FMultithreadedCompression<bc6h_enc_settings>::Compress(MultithreadSettings, settings, Image, OutCompressedImage, &IntelBC6HCompressScans, bUseTasks);
|
|
|
|
CompressedPixelFormat = PF_BC6H;
|
|
bCompressionSucceeded = true;
|
|
}
|
|
else if ( BuildSettings.TextureFormatName == GTextureFormatNameBC7 )
|
|
{
|
|
FImage Image;
|
|
InImage.CopyTo(Image, ERawImageFormat::BGRA8, BuildSettings.GetGammaSpace());
|
|
|
|
bc7_enc_settings settings;
|
|
if ( bImageHasAlphaChannel )
|
|
{
|
|
GetProfile_alpha_basic(&settings);
|
|
}
|
|
else
|
|
{
|
|
GetProfile_basic(&settings);
|
|
}
|
|
|
|
SetupScans(Image, 4, 4, OutCompressedImage, MultithreadSettings);
|
|
PadImageToBlockSize(Image, 4, 4, 4*1);
|
|
FMultithreadedCompression<bc7_enc_settings>::Compress(MultithreadSettings, settings, Image, OutCompressedImage, &IntelBC7CompressScans, bUseTasks);
|
|
|
|
CompressedPixelFormat = PF_BC7;
|
|
bCompressionSucceeded = true;
|
|
}
|
|
else
|
|
{
|
|
bool bIsRGBColorASTC = (BuildSettings.TextureFormatName == GTextureFormatNameASTC_RGB ||
|
|
((BuildSettings.TextureFormatName == GTextureFormatNameASTC_RGBAuto) && !bImageHasAlphaChannel));
|
|
bool bIsRGBAColorASTC = (BuildSettings.TextureFormatName == GTextureFormatNameASTC_RGBA ||
|
|
((BuildSettings.TextureFormatName == GTextureFormatNameASTC_RGBAuto) && bImageHasAlphaChannel));
|
|
bool bIsNormalMap = (BuildSettings.TextureFormatName == GTextureFormatNameASTC_NormalAG ||
|
|
BuildSettings.TextureFormatName == GTextureFormatNameASTC_NormalRG);
|
|
|
|
CompressedPixelFormat = GetQualityFormat( BlockWidth, BlockHeight, bIsNormalMap ? FORCED_NORMAL_MAP_COMPRESSION_SIZE_VALUE : BuildSettings.CompressionQuality );
|
|
|
|
FASTCEncoderSettings EncoderSettings;
|
|
if (BuildSettings.TextureFormatName == GTextureFormatNameASTC_NormalAG)
|
|
{
|
|
GetProfile_astc_alpha_fast(&EncoderSettings, BlockWidth, BlockHeight);
|
|
EncoderSettings.TextureFormatName = BuildSettings.TextureFormatName;
|
|
bCompressionSucceeded = true;
|
|
}
|
|
else if (BuildSettings.TextureFormatName == GTextureFormatNameASTC_NormalRG)
|
|
{
|
|
GetProfile_astc_fast(&EncoderSettings, BlockWidth, BlockHeight);
|
|
EncoderSettings.TextureFormatName = BuildSettings.TextureFormatName;
|
|
bCompressionSucceeded = true;
|
|
}
|
|
else if (bIsRGBColorASTC)
|
|
{
|
|
GetProfile_astc_fast(&EncoderSettings, BlockWidth, BlockHeight);
|
|
EncoderSettings.TextureFormatName = GTextureFormatNameASTC_RGB;
|
|
bCompressionSucceeded = true;
|
|
}
|
|
else if (bIsRGBAColorASTC)
|
|
{
|
|
GetProfile_astc_alpha_fast(&EncoderSettings, BlockWidth, BlockHeight);
|
|
EncoderSettings.TextureFormatName = GTextureFormatNameASTC_RGBA;
|
|
bCompressionSucceeded = true;
|
|
}
|
|
|
|
if (bCompressionSucceeded)
|
|
{
|
|
FImage Image;
|
|
InImage.CopyTo(Image, ERawImageFormat::BGRA8, BuildSettings.GetGammaSpace());
|
|
|
|
SetupScans(Image, EncoderSettings.block_width, EncoderSettings.block_height, OutCompressedImage, MultithreadSettings);
|
|
PadImageToBlockSize(Image, EncoderSettings.block_width, EncoderSettings.block_height, 4 * 1);
|
|
|
|
#if DEBUG_SAVE_INTERMEDIATE_IMAGES
|
|
//@DEBUG (save padded input as BMP):
|
|
static bool SaveInputOutput = false;
|
|
static volatile int32 Counter = 0;
|
|
int LocalCounter = Counter;
|
|
if (SaveInputOutput) // && LocalCounter < 10 && Image.SizeX >= 1024)
|
|
{
|
|
const FString FileName = FString::Printf(TEXT("Smedis-Input-%d.bmp"), FPlatformTLS::GetCurrentThreadId());
|
|
FArchive* FileWriter = IFileManager::Get().CreateFileWriter(*FileName);
|
|
SaveImageAsBMP(*FileWriter, Image.RawData.GetData(), 4, Image.SizeX, Image.SizeY);
|
|
delete FileWriter;
|
|
FPlatformAtomics::InterlockedIncrement(&Counter);
|
|
}
|
|
#endif
|
|
|
|
FMultithreadedCompression<FASTCEncoderSettings>::Compress(MultithreadSettings, EncoderSettings, Image, OutCompressedImage, &IntelASTCCompressScans, bUseTasks);
|
|
|
|
#if DEBUG_SAVE_INTERMEDIATE_IMAGES
|
|
//@DEBUG (save swizzled/fixed-up input as BMP):
|
|
if (SaveInputOutput) // && LocalCounter < 10 && Image.SizeX >= 1024)
|
|
{
|
|
const FString FileName = FString::Printf(TEXT("Smedis-InputSwizzled-%d.bmp"), FPlatformTLS::GetCurrentThreadId());
|
|
FArchive* FileWriter = IFileManager::Get().CreateFileWriter(*FileName);
|
|
SaveImageAsBMP(*FileWriter, Image.RawData.GetData(), 4, Image.SizeX, Image.SizeY);
|
|
delete FileWriter;
|
|
FPlatformAtomics::InterlockedIncrement(&Counter);
|
|
}
|
|
|
|
//@DEBUG (save output as .astc file):
|
|
if (SaveInputOutput)// && LocalCounter < 10 && Image.SizeX >= 1024)
|
|
{
|
|
const FString FileName = FString::Printf(TEXT("Smedis-Output-%d.astc"), FPlatformTLS::GetCurrentThreadId());
|
|
FArchive* FileWriter = IFileManager::Get().CreateFileWriter(*FileName);
|
|
SaveImageAsASTC(*FileWriter, OutCompressedImage.RawData.GetData(), OutCompressedImage.SizeX, OutCompressedImage.SizeY, EncoderSettings.block_width, EncoderSettings.block_height);
|
|
delete FileWriter;
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
OutCompressedImage.PixelFormat = CompressedPixelFormat;
|
|
OutCompressedImage.SizeX = InImage.SizeX;
|
|
OutCompressedImage.SizeY = InImage.SizeY;
|
|
|
|
return bCompressionSucceeded;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Module for DXT texture compression.
|
|
*/
|
|
static ITextureFormat* Singleton = NULL;
|
|
|
|
class FTextureFormatIntelISPCTexCompModule : public ITextureFormatModule
|
|
{
|
|
public:
|
|
FTextureFormatIntelISPCTexCompModule()
|
|
{
|
|
mDllHandle = nullptr;
|
|
}
|
|
|
|
virtual ~FTextureFormatIntelISPCTexCompModule()
|
|
{
|
|
delete Singleton;
|
|
Singleton = NULL;
|
|
|
|
if ( mDllHandle != nullptr )
|
|
{
|
|
FPlatformProcess::FreeDllHandle(mDllHandle);
|
|
mDllHandle = nullptr;
|
|
}
|
|
}
|
|
|
|
virtual ITextureFormat* GetTextureFormat()
|
|
{
|
|
if (!Singleton)
|
|
{
|
|
#if PLATFORM_WINDOWS
|
|
#if PLATFORM_64BITS
|
|
mDllHandle = FPlatformProcess::GetDllHandle(TEXT("../../../Engine/Binaries/ThirdParty/IntelISPCTexComp/Win64-Release/ispc_texcomp.dll"));
|
|
#else //32-bit platform
|
|
mDllHandle = FPlatformProcess::GetDllHandle(TEXT("../../../Engine/Binaries/ThirdParty/IntelISPCTexComp/Win32-Release/ispc_texcomp.dll"));
|
|
#endif
|
|
#elif PLATFORM_MAC
|
|
mDllHandle = FPlatformProcess::GetDllHandle(TEXT("libispc_texcomp.dylib"));
|
|
#elif PLATFORM_LINUX
|
|
mDllHandle = FPlatformProcess::GetDllHandle(TEXT("../../../Engine/Binaries/ThirdParty/IntelISPCTexComp/Linux64-Release/libispc_texcomp.so"));
|
|
#endif
|
|
Singleton = new FTextureFormatIntelISPCTexComp();
|
|
}
|
|
return Singleton;
|
|
}
|
|
|
|
void* mDllHandle;
|
|
};
|
|
|
|
IMPLEMENT_MODULE(FTextureFormatIntelISPCTexCompModule, TextureFormatIntelISPCTexComp);
|