You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change3244756on 2017/01/03 by Marcus.Wassmer Copying //Tasks/UE4/Dev-Niagara@3244743 to Dev-Rendering (//UE4/Dev-Rendering) Change 3248667 on 2017/01/05 by Olaf.Piesche Resaving default asset because of engine verison issue; maybe unnecessary, but resaving niagara engine content to be sure #jira UE-40160 Change 3249324 on 2017/01/06 by Marcus.Wassmer Resave with an actual version to stop cook warning Change 3249611 on 2017/01/06 by Marcus.Wassmer Just remove warning-causing niagara data for now. Change 3308052 on 2017/02/16 by Rolando.Caloca DR - Check for Vulkan SDK, and only use it if it's newer or the same as the headers we distribute Change 3308109 on 2017/02/16 by Rolando.Caloca DR - Upgrade glslang to 1.0.39.1 Change 3308111 on 2017/02/16 by Rolando.Caloca DR - Update Vulkan distribution to 1.0.39.1 Change 3308153 on 2017/02/16 by Rolando.Caloca DR - Updated glslang libs Change 3308842 on 2017/02/17 by Rolando.Caloca DR - Fixed copy/paste Change 3310007 on 2017/02/17 by Chris.Bunner Back out CL 3221219 - causing MIC generation issues and superseded by CL 3273971. #jira UE-37792 Change 3310154 on 2017/02/17 by Chris.Bunner Assert when attempting to add a custom material attribute already in the base attributes list. Change 3310155 on 2017/02/17 by Chris.Bunner PR #3231: Validate material index before accessing (Contributed by projectgheist) #jira UE-41774, UE-41788 Change 3310162 on 2017/02/17 by Chris.Bunner PR #3252: Added MobileMaterialInterface to UsedMaterials (Contributed by projectgheist) #jira UE-41823, UE-41950 Change 3310176 on 2017/02/17 by Chris.Bunner Merging CL 3233886: AMD HDR support (requires r.AMDSupportsHDRDisplayOutput=1 in ini). Update to AGS 5.0.5. Partial code tidy up. Change 3310187 on 2017/02/17 by Chris.Bunner Preserve constant expressions rather than always casting after translating a material attribute. Losing the notion of constant means we can't correctly detect used properties and falsely enable e.g. PDO. Happened because of the incorrect component masks in BreakMaterialNodes which then had to be downcast to the correct type which is done as an inline fragment rather than swizzle expression. #jira UE-41594 Change 3310215 on 2017/02/17 by Chris.Bunner Prevent SpeedTree node compiling for skeletal meshes (not supported as uses more UV sets than available). More descriptive error for missing Cubemap UV input on TextureSample material node . #jira UE-33098 Change 3310838 on 2017/02/18 by Joe.Graf Moved some private functions to public for a licensee #CodeReview: matt.kuhlenschmidt #rb: n/a Change 3311876 on 2017/02/20 by Rolando.Caloca DR - Expose skin cache cvar r.SkinCache.AccumulationBufferSizeInKB #jira UE-42014 Change 3314139 on 2017/02/21 by Rolando.Caloca DR - Minor cleanup pass - Remove FVulkanPendingState - Renamed some classes for clarity - Hoist pending UAVs for flush out to pending compute state Change 3314642 on 2017/02/21 by Rolando.Caloca DR - Some more renaming Change3315431on 2017/02/21 by Ben.Salem Properly set default values for test time out and tick. We now will default to ticking once per second, and tracking the macro stats of GPU/Render/Game thread time. #tests Ran showdown demo several times Change 3316710 on 2017/02/22 by Rolando.Caloca DR - hlslcc - Fix refract intrinsic Change 3316718 on 2017/02/22 by Rolando.Caloca DR - hlslcc - Built libs to pick up change from 3316710 - refract fix Change 3316820 on 2017/02/22 by Benjamin.Hyder updating Tm-TrigNodes map Change 3317192 on 2017/02/22 by Benjamin.Hyder Updating QA-Decals map Change 3317528 on 2017/02/22 by Benjamin.Hyder Updating QA-Decals map Change 3317639 on 2017/02/22 by Benjamin.Hyder Updating Decal on Complex Mesh example in QA-Decals Change 3317764 on 2017/02/22 by Benjamin.Hyder Final updates to QA-Decals Change 3318319 on 2017/02/22 by Rolando.Caloca DR - minor reorg/rename Change 3318379 on 2017/02/22 by Rolando.Caloca DR - more cleanup Change 3321181 on 2017/02/24 by Rolando.Caloca DR - Fix GL bug Change 3321247 on 2017/02/24 by Rolando.Caloca DR - Fix misc bugs Change 3321898 on 2017/02/24 by Chris.Bunner Only issue clear TLV dispatch if required. #jira UERNDR-193 Change 3321904 on 2017/02/24 by Chris.Bunner Added comment for potential future optimization. Change 3322013 on 2017/02/24 by Uriel.Doyon Fixed separate translucency being affected by Gaussian DOF #jira UE-40489 Change 3322517 on 2017/02/24 by Uriel.Doyon Fixed issue with InvestigateTexture command removing budget limit. Fixed StreamingBounds show flag not working. It nows shows the streaming bound for the currently selected textures. #jira UE-40485 Change 3323470 on 2017/02/27 by Chad.Garyet Removing DDC job from dev-rendering Change 3323479 on 2017/02/27 by Chad.Garyet Removing RDU agent type Change 3323519 on 2017/02/27 by Chad.Garyet removing NCL/LHR/SEA agent types to clean up space Change 3323639 on 2017/02/27 by Benjamin.Hyder More updates to QA-Decals Change 3324207 on 2017/02/27 by Uriel.Doyon Fixed typo ScaleTexturesByGlobalMyBias -> ScaleTexturesByGlobalMipBias Removed bad merge in FStreamingTextureLevelContext::GetBuildDataIndexRef Change 3324396 on 2017/02/27 by Uriel.Doyon Fixed an issue with the Streaming Bounds show flag interferring with the static level data initialization #jira UE-40485 Change 3325227 on 2017/02/28 by Chris.Bunner Fix-up AMD AGS libs. Change 3325566 on 2017/02/28 by Uriel.Doyon Fixed possible out-of-bound access in GetUsedTexture() when passing ERHIFeatureLevel::Num Change 3326009 on 2017/02/28 by Uriel.Doyon Better fix for 3325566, as the previous fix would ignore the material instance overrides. Change 3327058 on 2017/03/01 by Benjamin.Hyder Preparing TM_Shadermodels map for automation Change 3328222 on 2017/03/01 by Chris.Bunner Prevent decals from drawing in separate translucency pass. Whilst user control and material relevance were already removed, if the flag was checked before being disabled (by swapping to decal domain) this was still being read in the render loop, now explicitly ignores decals. #jira UE-42449, UE-42446 Change 3329848 on 2017/03/02 by Uriel.Doyon Added some extra logs to help track UE-42168 Change 3329977 on 2017/03/02 by Rolando.Caloca DR - Fix bad clear value Change 3330008 on 2017/03/02 by Benjamin.Hyder More preparations for QA-Decals automation Change 3330754 on 2017/03/02 by Daniel.Wright Prominent comment explaining reflection env async compute usage and why it's not overlapped with anything Change 3331451 on 2017/03/03 by Marc.Olano Manually unroll simplex noise loop to avoid PSO bug on AMD/Metal Change 3331839 on 2017/03/03 by Rolando.Caloca DR - hlslcc - add missing file to project Change 3332247 on 2017/03/03 by Rolando.Caloca DR - Fix for integrated intel PR #3305 #jira UE-42393 Change 3332259 on 2017/03/03 by Rolando.Caloca DR - Fix bad index into pixel formats PR #3237 #jira UE-41855 Change 3332305 on 2017/03/03 by Rolando.Caloca DR - OpenGL SRV for index buffers PR #3271 #jira UE-32618 Change 3332313 on 2017/03/03 by Rolando.Caloca DR - Fix for integrated intel (properly) PR #3305 #jira UE-42393 Change 3332317 on 2017/03/03 by Rolando.Caloca DR - OpenGL SRV for index buffers (properly) PR #3271 #jira UE-32618 Change 3332368 on 2017/03/03 by Rolando.Caloca DR - Minor fixes so -sm4 and -sm5 can be used on windows with OpenGL/Vulkan Change 3333690 on 2017/03/06 by Daniel.Wright [Copy] Changing movable skylight properties no longer affects static draw lists Change 3333693 on 2017/03/06 by Daniel.Wright [Copy] Added 'r.AOListMeshDistanceFields' which dumps out mesh distance fields sorted by memory size, useful for directing content optimizations Change3333705on 2017/03/06 by Daniel.Wright [Copy] Mesh distance fields are now 8 bit fixed point by default, but can be changed back to 16 bit floating piont with a project setting. * 8 bit uses half memory but introduces error for thin surfaces or large meshes. Change 3333721 on 2017/03/06 by David.Hill DecalProxy: Copy float FadeScreenSize to FDeferredDecalProxy for use in the render thread. This avoids pointer chasing to the UDecalComponent (game thread component). Change 3333772 on 2017/03/06 by Daniel.Wright [Copy] Scene motion blur data is only updated for the main renderer frames. Fixes scene captures and planar reflections breaking object motion blur. Change 3333790 on 2017/03/06 by Daniel.Wright [Copy] Mesh distance field generation uses Embree, for a 2.5x speedup * Can switch back to old kDOP generation with 'r.DistanceFieldBuild.UseEmbree 0' for debugging Change 3333822 on 2017/03/06 by Daniel.Wright [Copy] Moved mesh distance field code into MeshDistanceFieldUtilities.cpp * Moved FMeshUtilities to its own header so the 8k line MeshUtilites.cpp file can be further split up Change 3333827 on 2017/03/06 by Daniel.Wright [Copy] Range compress 8bit distance fields - gets one extra bit of precision on average Change 3333828 on 2017/03/06 by Daniel.Wright [Copy] Raised High ShadowQuality to 2048 as 1024 for CSM is way too low Change 3333831 on 2017/03/06 by Daniel.Wright Non-editor compile fix Change 3333836 on 2017/03/06 by Daniel.Wright [Copy] Workaround for gobal distance field volume textures being bloated by 4x on PS4 due to the recommended tiling modes. They now use a 2d tiling mode which avoids the bloat, saving 96Mb. Change 3333843 on 2017/03/06 by Daniel.Wright [Copy] Added OcclusionExponent to skylight component * Useful for brightening up indoors without losing contact shadows as MinOcclusion does Change 3333845 on 2017/03/06 by Daniel.Wright [Copy] Capsule shadow BP functions Change 3333850 on 2017/03/06 by Daniel.Wright [Copy] Added OcclusionCombineMode to skylight component Change 3333854 on 2017/03/06 by Daniel.Wright [Copy] Gnm properly registers clears as GPU work so those events show up in profilegpu Change 3333857 on 2017/03/06 by Daniel.Wright [Copy] Clear light attenuation for local lights with a quad covering their screen extents * Clearing the entire light attenuation buffer costs .1ms on PS4. This optimization lowers the minimum cost of a shadow casting light from .15ms -> .03ms. * Shadowed lights in Fortnite with 25 lights 3.7ms -> 1.42ms on PS4 Change 3333860 on 2017/03/06 by Daniel.Wright [Copy] Flush deferred deletes when reallocating distance field atlas to reduce peak memory Change 3333861 on 2017/03/06 by Daniel.Wright [Copy] Disable all distance field features on Intel cards as HD 4000 hangs in the RHICreateTexture3D call to allocate the large atlas Change 3333869 on 2017/03/06 by Daniel.Wright [Copy] Volumetric Fog using a volume texture mapped to the camera frustum * Volumetric fog can be enabled on an Exponential Height Fog component with additional controls * Lights have a VolumetricScatteringIntensity * New cvars r.VolumetricFog, r.VolumetricFog.GridPixelSize, r.VolumetricFog.GridSizeZ, r.VolumetricFog.DepthDistributionScale * Lighting features supported: * Directional light with CSM and a light function * Point / spot lights without shadows / light functions / IES profiles * Skylight with occlusion from distance fields * Analytical height fog covers the view range past where the volumetric fog ends * Temporal reprojection is used on the volumetric fog scattering and extinction to achieve stability * Translucency integrates properly into volumetric fog * Height fog StartDistance is not supported by volumetric fog and should be set to 0. Change 3333894 on 2017/03/06 by Daniel.Wright [Copy] Initialize GDummyVolumetricFogGlobalDataUniformBuffer outside of parallel rendering Change 3333902 on 2017/03/06 by Daniel.Wright [Copy] Better handling of volumetric fog enabled with distance of 0 Change 3333903 on 2017/03/06 by Daniel.Wright [Copy] Fixed volumetric fog trying to render light functions for a point light Change 3333908 on 2017/03/06 by Daniel.Wright [Copy] Volumetric materials * Added new material domain Volume, which can output Scattering, Absorption and Emissive. All properties are in world space densities. * Particle systems using the Volume domain are voxelized based on their ParticlePosition and ParticleRadius * Volumetric fog integration is now energy conservative - scattering is integrated against transmission over the depth of each slice. * Added bOverrideLightColorsWithFogInscatteringColors to exponential height fog, which can be enabled to make Volumetric Fog match Height fog more closely Change 3334134 on 2017/03/06 by Daniel.Wright [Copy from Michael Trepka] Added Embree 2.14.0 and changed MeshUtilities to use it as this solves issues with Embree leaking TLS keys. UnrealLightmass is still using older Embree 2.7.0 until we can find time to properly test it with the new version. Also, invalidated distance field DDC to force it to rebuild with updated Embree. Change 3334420 on 2017/03/06 by Daniel.Wright Fixed RTDF shadows Change 3335467 on 2017/03/07 by Benjamin.Hyder Initial submission of QA-Decals map to EngineTest Change 3335556 on 2017/03/07 by Daniel.Wright Changed mesh distance field default format back to R16f Change 3338020 on 2017/03/08 by Daniel.Wright Disable volumetric fog in vertex shaders for feature levels which don't support it Change 3339394 on 2017/03/09 by Chris.Bunner Correctly handle material texture translation error edge case. #jira UE-42579, UE-42670 Change 3339992 on 2017/03/09 by Daniel.Wright Only compile volumetric fog shaders on supporting platforms Change 3341858 on 2017/03/10 by Arne.Schober Copying //UE4/Dev-Rendering-PSO to Dev-Rendering (//UE4/Dev-Rendering) #RB Rolando.Caloca, Marcus.Wassmer, Daniel.Wright, Nick.Penwarden, Mark.Satterthwaite Change 3342004 on 2017/03/10 by Arne.Schober Copying //UE4/Dev-Rendering-PSO to Dev-Rendering (//UE4/Dev-Rendering) Fix unity build #RB Marcus.Wassmer Change 3343307 on 2017/03/13 by Marcus.Wassmer Update showflags when we are guaranteed it will happen in all possible ways to spawn the scenecapture. (drag into editor, PIE, -game, etc) Change 3343732 on 2017/03/13 by Rolando.Caloca DR - Vulkan compute pipeline & refactor Change 3344846 on 2017/03/14 by Rolando.Caloca DR - Android compile fixes Change 3344883 on 2017/03/14 by Rolando.Caloca DR - Add missing stencil load/store to PSO initializer Change 3344985 on 2017/03/14 by Rolando.Caloca DR - Made load/store actions uint8 Change 3345141 on 2017/03/14 by Rolando.Caloca DR - vk - Rework render pass hash Change 3345304 on 2017/03/14 by Benjamin.Hyder Updating TM-Distancefields map to include TemplateFloor mesh Change 3345387 on 2017/03/14 by Rolando.Caloca DR - Add _RenderThread calls for Create*Shader so RHIs can choose not to stall when creating Change 3345388 on 2017/03/14 by Rolando.Caloca DR - Do not stall when creating shaders on Vulkan Change 3345722 on 2017/03/14 by Chris.Bunner PR #3357: MinimalAPI add to many material expressions (Contributed by DeanoC) #jira UE-42752 Change 3345723 on 2017/03/14 by Chris.Bunner Reduce log verbosity causing spamming during landscape editing. #jira UE-42714 Change 3345725 on 2017/03/14 by Chris.Bunner [Duplicate 3341860] Fixed material translation error with multiple connections from custom interpolator nodes. Change 3345726 on 2017/03/14 by Chris.Bunner Typo fixes. Change 3345732 on 2017/03/14 by Rolando.Caloca DR - Decouple vertex declaration off BSS Change 3345746 on 2017/03/14 by Chris.Bunner Added sign() intrinsic material graph node and delisted material function workaround. Change 3346042 on 2017/03/14 by Chris.Bunner Implement missing size query interface for FRenderTargetResources. #jira UE-41672 Change 3346387 on 2017/03/14 by Daniel.Wright [Copy] Added VolumetricScatteringIntensity to particle lights Change 3346389 on 2017/03/14 by Daniel.Wright [Copy] Clamp Volumetric material attributes to fp16 range to avoid INFs Disable volumetric fog when the fog show flag is disabled Change 3346392 on 2017/03/14 by Daniel.Wright [Copy] Fixed skylight being much too bright on volumetric fog Change 3346406 on 2017/03/14 by Daniel.Wright [Copy] CSM resolution is now controlled by r.Shadow.MaxCSMResolution. * Changed HighPC to use 1024 MaxShadowResolution (max for all non-CSM shadows), saves 60Mb in Fortnite Change 3346412 on 2017/03/14 by Daniel.Wright [Copy] TexCreate_ReduceMemoryWithTilingMode for translucency lighting 3d textures, saves 13Mb Change3346414on 2017/03/14 by Daniel.Wright [Copy] TexCreate_ReduceMemoryWithTilingMode for volumetric fog 3d textures, saves 13Mb Change 3346415 on 2017/03/14 by Daniel.Wright [Copy] Missing file from cl 3338451 Change 3346421 on 2017/03/14 by Daniel.Wright [Copy] Fixed NaNs in volumetric fog due to rendering when height fog is disabled * Volumetric fog converts NaNs to black now so they don't spread Change 3346422 on 2017/03/14 by Daniel.Wright [Copy] Fixed NaN in volumetric fog with low density values Change 3346423 on 2017/03/14 by Daniel.Wright [Copy] Changed default VolumetricFogScatteringDistribution to .2 Change 3346430 on 2017/03/14 by Daniel.Wright [Copy] New translucent material option to compute fog per pixel instead of the default per vertex Change 3346432 on 2017/03/14 by Daniel.Wright [Copy] Moved Volumetric Fog parameters to view uniform buffer for translucency pass Fixed lifetimes of temporary Volumetric Fog render targets Change 3346526 on 2017/03/14 by Daniel.Wright [Copy] Volumetric Fog supports point and spot light shadows * These lights are injected separately so that per-light resources can be bound (shadow depth map, static shadow depth map) * Forward lighting of local lights can be forced with 'r.VolumetricFog.InjectShadowedLightsSeparately 0' * Shadowed lights come at a cost: 2.9ms for volumetric fog on 970 -> 4.2ms with shadowing Change 3347053 on 2017/03/15 by Rolando.Caloca DR - android compile fix Change 3347384 on 2017/03/15 by Rolando.Caloca DR - Fix merge issue Change 3347643 on 2017/03/15 by Marcus.Wassmer Fix some bugs with the 'disable stationary skylight ffor the project' feature. Fixes lighting in Persona on Paragon. Change 3347979 on 2017/03/15 by Rolando.Caloca DR - Allow to automatically apply cached rendertargets to PSO initializer Change 3348024 on 2017/03/15 by Rolando.Caloca DR - Remove NullPS on Vulkan to avoid deadlock Change 3348303 on 2017/03/15 by Rolando.Caloca DR - Fix for debugging SCW with material SRT Change 3348357 on 2017/03/15 by Marcus.Wassmer Fix stencildither and a stencilref bug that was probably breaking decals sometimes. Change 3348549 on 2017/03/15 by Marcus.Wassmer Hopefully fix static analysis for potential nullptr access. Change 3348614 on 2017/03/15 by Marcus.Wassmer Duplicate some switch changes to fix crash on launch. Change 3349369 on 2017/03/16 by Gil.Gribb Fixed botched merge Change 3349947 on 2017/03/16 by Rolando.Caloca DR - Fix for mismatched primitive type Change 3349956 on 2017/03/16 by Benjamin.Hyder initial updates to TM-DistanceFields map Change 3350151 on 2017/03/16 by Rolando.Caloca DR - Fix UT compile issue Change 3350155 on 2017/03/16 by Rolando.Caloca DR - Catch mismatched primitive type on PSOs on D3D11 Change 3350192 on 2017/03/16 by Daniel.Wright Fix for point light shadow depths rendering with wrong cull mode due to PSO refactor Change 3350736 on 2017/03/16 by Daniel.Wright Fixed formatting from merge Change 3350881 on 2017/03/16 by Rolando.Caloca DR - Fix texture arrays as UAVs on Metal Change 3350927 on 2017/03/16 by Rolando.Caloca DR - Fix warning Change 3350935 on 2017/03/16 by Daniel.Wright Fix for materials with non-Surface domains being skipped in mesh passes Change 3351583 on 2017/03/17 by Marcus.Wassmer Fix clang platforms Change 3351917 on 2017/03/17 by Marcus.Wassmer Fix linux compile Change 3351973 on 2017/03/17 by Marcus.Wassmer Fix mismatched rendertargetformat Change 3352038 on 2017/03/17 by Daniel.Wright Enabled GetAndOrCreateGraphicsPipelineState ensures in Development for testing Change 3352110 on 2017/03/17 by Marcus.Wassmer Fix missing RT PSO apply Change 3352695 on 2017/03/17 by Arne.Schober DR - Remove PSO Rendertarget check in DX12 Resolve with Shader. #RB Rolando.Caloca Change 3352960 on 2017/03/17 by Arne.Schober DR - Fix some things that slipped trough the PSO merge #RB none Change 3353150 on 2017/03/18 by Rolando.Caloca DR - compile fix Change 3353205 on 2017/03/18 by Arne.Schober DR - Fix Incremental Compile and PS4 runtime error where CMASK is not allowed for ThickTile Mode #RB none Change 3353207 on 2017/03/18 by Arne.Schober DR - Fix Confusion #RB none Change 3355183 on 2017/03/20 by Nick.Bullard Fixed up Content orginzation for Decals automation tests in EngineTest Change 3355627 on 2017/03/20 by Arne.Schober DR - [UE-43094] - removed ensure in comporiton graph as control of the clear color cannot be gurantueed. Change 3356342 on 2017/03/21 by Marcus.Wassmer Fix clang errors Change 3356591 on 2017/03/21 by Arne.Schober DR - Fix ensure message #RB none Change 3356873 on 2017/03/21 by Arne.Schober DR - Fix comparission of undefined values in RendertargetApply Check Change 3357261 on 2017/03/21 by Marcus.Wassmer Fix LinuxEditor compile Change 3357294 on 2017/03/21 by Marcus.Wassmer Add missing SSE functions Change 3357351 on 2017/03/21 by Frank.Fella Fix win32 and linux compiler errors Change 3357370 on 2017/03/21 by Arne.Schober DR - disable ensure in test builds #RB Marcus.Wassmer [CL 3357449 by Marcus Wassmer in Main branch]
1029 lines
39 KiB
C++
1029 lines
39 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
// ShaderCompileWorker.cpp : Defines the entry point for the console application.
|
|
//
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "RequiredProgramMainCPPInclude.h"
|
|
#include "ShaderCore.h"
|
|
#include "ExceptionHandling.h"
|
|
#include "IShaderFormat.h"
|
|
#include "IShaderFormatModule.h"
|
|
|
|
#define DEBUG_USING_CONSOLE 0
|
|
|
|
// this is for the protocol, not the data, bump if FShaderCompilerInput or ProcessInputFromArchive changes (also search for the second one with the same name, todo: put into one header file)
|
|
const int32 ShaderCompileWorkerInputVersion = 7;
|
|
// this is for the protocol, not the data, bump if FShaderCompilerOutput or WriteToOutputArchive changes (also search for the second one with the same name, todo: put into one header file)
|
|
const int32 ShaderCompileWorkerOutputVersion = 3;
|
|
// this is for the protocol, not the data, bump if FShaderCompilerOutput or WriteToOutputArchive changes (also search for the second one with the same name, todo: put into one header file)
|
|
const int32 ShaderCompileWorkerSingleJobHeader = 'S';
|
|
// this is for the protocol, not the data, bump if FShaderCompilerOutput or WriteToOutputArchive changes (also search for the second one with the same name, todo: put into one header file)
|
|
const int32 ShaderCompileWorkerPipelineJobHeader = 'P';
|
|
|
|
enum class ESCWErrorCode
|
|
{
|
|
Success,
|
|
GeneralCrash,
|
|
BadShaderFormatVersion,
|
|
BadInputVersion,
|
|
BadSingleJobHeader,
|
|
BadPipelineJobHeader,
|
|
CantDeleteInputFile,
|
|
CantSaveOutputFile,
|
|
NoTargetShaderFormatsFound,
|
|
CantCompileForSpecificFormat,
|
|
};
|
|
|
|
double LastCompileTime = 0.0;
|
|
|
|
static bool GShaderCompileUseXGE = false;
|
|
static ESCWErrorCode GFailedErrorCode = ESCWErrorCode::Success;
|
|
|
|
static void WriteXGESuccessFile(const TCHAR* WorkingDirectory)
|
|
{
|
|
// To signal compilation completion, create a zero length file in the working directory.
|
|
delete IFileManager::Get().CreateFileWriter(*FString::Printf(TEXT("%s/Success"), WorkingDirectory), FILEWRITE_EvenIfReadOnly);
|
|
}
|
|
|
|
#if USING_CODE_ANALYSIS
|
|
FUNCTION_NO_RETURN_START static inline void ExitWithoutCrash(ESCWErrorCode ErrorCode, const FString& Message) FUNCTION_NO_RETURN_END;
|
|
#endif
|
|
|
|
static inline void ExitWithoutCrash(ESCWErrorCode ErrorCode, const FString& Message)
|
|
{
|
|
GFailedErrorCode = ErrorCode;
|
|
FCString::Snprintf(GErrorExceptionDescription, sizeof(GErrorExceptionDescription), TEXT("%s"), *Message);
|
|
UE_LOG(LogShaders, Fatal, TEXT("%s"), *Message);
|
|
}
|
|
|
|
static const TArray<const IShaderFormat*>& GetShaderFormats()
|
|
{
|
|
static bool bInitialized = false;
|
|
static TArray<const IShaderFormat*> Results;
|
|
|
|
if (!bInitialized)
|
|
{
|
|
bInitialized = true;
|
|
Results.Empty(Results.Num());
|
|
|
|
TArray<FName> Modules;
|
|
FModuleManager::Get().FindModules(SHADERFORMAT_MODULE_WILDCARD, Modules);
|
|
|
|
if (!Modules.Num())
|
|
{
|
|
ExitWithoutCrash(ESCWErrorCode::NoTargetShaderFormatsFound, TEXT("No target shader formats found!"));
|
|
}
|
|
|
|
for (int32 Index = 0; Index < Modules.Num(); Index++)
|
|
{
|
|
IShaderFormat* Format = FModuleManager::LoadModuleChecked<IShaderFormatModule>(Modules[Index]).GetShaderFormat();
|
|
if (Format != nullptr)
|
|
{
|
|
Results.Add(Format);
|
|
}
|
|
}
|
|
}
|
|
return Results;
|
|
}
|
|
|
|
static const IShaderFormat* FindShaderFormat(FName Name)
|
|
{
|
|
const TArray<const IShaderFormat*>& ShaderFormats = GetShaderFormats();
|
|
|
|
for (int32 Index = 0; Index < ShaderFormats.Num(); Index++)
|
|
{
|
|
TArray<FName> Formats;
|
|
ShaderFormats[Index]->GetSupportedFormats(Formats);
|
|
for (int32 FormatIndex = 0; FormatIndex < Formats.Num(); FormatIndex++)
|
|
{
|
|
if (Formats[FormatIndex] == Name)
|
|
{
|
|
return ShaderFormats[Index];
|
|
}
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
/** Processes a compilation job. */
|
|
static void ProcessCompilationJob(const FShaderCompilerInput& Input,FShaderCompilerOutput& Output,const FString& WorkingDirectory)
|
|
{
|
|
const IShaderFormat* Compiler = FindShaderFormat(Input.ShaderFormat);
|
|
if (!Compiler)
|
|
{
|
|
ExitWithoutCrash(ESCWErrorCode::CantCompileForSpecificFormat, FString::Printf(TEXT("Can't compile shaders for format %s"), *Input.ShaderFormat.ToString()));
|
|
}
|
|
|
|
// Compile the shader directly through the platform dll (directly from the shader dir as the working directory)
|
|
Compiler->CompileShader(Input.ShaderFormat, Input, Output, WorkingDirectory);
|
|
}
|
|
|
|
|
|
class FWorkLoop
|
|
{
|
|
public:
|
|
FWorkLoop(const TCHAR* ParentProcessIdText,const TCHAR* InWorkingDirectory,const TCHAR* InInputFilename,const TCHAR* InOutputFilename, TMap<FString, uint16>& InFormatVersionMap)
|
|
: ParentProcessId(FCString::Atoi(ParentProcessIdText))
|
|
, WorkingDirectory(InWorkingDirectory)
|
|
, InputFilename(InInputFilename)
|
|
, OutputFilename(InOutputFilename)
|
|
, InputFilePath(FString(InWorkingDirectory) + InInputFilename)
|
|
, OutputFilePath(FString(InWorkingDirectory) + InOutputFilename)
|
|
, FormatVersionMap(InFormatVersionMap)
|
|
{
|
|
}
|
|
|
|
void Loop()
|
|
{
|
|
UE_LOG(LogShaders, Log, TEXT("Entering job loop"));
|
|
|
|
while(true)
|
|
{
|
|
TArray<FJobResult> SingleJobResults;
|
|
TArray<FPipelineJobResult> PipelineJobResults;
|
|
|
|
// Read & Process Input
|
|
{
|
|
FArchive* InputFilePtr = OpenInputFile();
|
|
if(!InputFilePtr)
|
|
{
|
|
break;
|
|
}
|
|
|
|
UE_LOG(LogShaders, Log, TEXT("Processing shader"));
|
|
|
|
ProcessInputFromArchive(InputFilePtr, SingleJobResults, PipelineJobResults);
|
|
|
|
LastCompileTime = FPlatformTime::Seconds();
|
|
|
|
// Close the input file.
|
|
delete InputFilePtr;
|
|
}
|
|
|
|
// Prepare for output
|
|
FArchive* OutputFilePtr = CreateOutputArchive();
|
|
check(OutputFilePtr);
|
|
WriteToOutputArchive(OutputFilePtr, SingleJobResults, PipelineJobResults);
|
|
|
|
// Close the output file.
|
|
delete OutputFilePtr;
|
|
|
|
// Change the output file name to requested one
|
|
IFileManager::Get().Move(*OutputFilePath, *TempFilePath);
|
|
|
|
if (GShaderCompileUseXGE)
|
|
{
|
|
// To signal compilation completion, create a zero length file in the working directory.
|
|
WriteXGESuccessFile(*WorkingDirectory);
|
|
|
|
// We only do one pass per process when using XGE.
|
|
break;
|
|
}
|
|
}
|
|
|
|
UE_LOG(LogShaders, Log, TEXT("Exiting job loop"));
|
|
}
|
|
|
|
private:
|
|
struct FJobResult
|
|
{
|
|
FShaderCompilerOutput CompilerOutput;
|
|
};
|
|
|
|
struct FPipelineJobResult
|
|
{
|
|
FString PipelineName;
|
|
TArray<FJobResult> SingleJobs;
|
|
};
|
|
|
|
const int32 ParentProcessId;
|
|
const FString WorkingDirectory;
|
|
const FString InputFilename;
|
|
const FString OutputFilename;
|
|
|
|
const FString InputFilePath;
|
|
const FString OutputFilePath;
|
|
TMap<FString, uint16> FormatVersionMap;
|
|
FString TempFilePath;
|
|
|
|
/** Opens an input file, trying multiple times if necessary. */
|
|
FArchive* OpenInputFile()
|
|
{
|
|
FArchive* InputFile = nullptr;
|
|
bool bFirstOpenTry = true;
|
|
while(!InputFile && !GIsRequestingExit)
|
|
{
|
|
// Try to open the input file that we are going to process
|
|
InputFile = IFileManager::Get().CreateFileReader(*InputFilePath,FILEREAD_Silent);
|
|
|
|
if(!InputFile && !bFirstOpenTry)
|
|
{
|
|
CheckExitConditions();
|
|
// Give up CPU time while we are waiting
|
|
FPlatformProcess::Sleep(0.01f);
|
|
}
|
|
bFirstOpenTry = false;
|
|
}
|
|
return InputFile;
|
|
}
|
|
|
|
void VerifyFormatVersions(TMap<FString, uint16>& ReceivedFormatVersionMap)
|
|
{
|
|
for (auto Pair : ReceivedFormatVersionMap)
|
|
{
|
|
auto* Found = FormatVersionMap.Find(Pair.Key);
|
|
if (Found)
|
|
{
|
|
if (Pair.Value != *Found)
|
|
{
|
|
ExitWithoutCrash(ESCWErrorCode::BadShaderFormatVersion, FString::Printf(TEXT("Mismatched shader version for format %s; did you forget to build ShaderCompilerWorker?"), *Pair.Key, *Found, Pair.Value));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void ProcessInputFromArchive(FArchive* InputFilePtr, TArray<FJobResult>& OutSingleJobResults, TArray<FPipelineJobResult>& OutPipelineJobResults)
|
|
{
|
|
FArchive& InputFile = *InputFilePtr;
|
|
int32 InputVersion;
|
|
InputFile << InputVersion;
|
|
if (ShaderCompileWorkerInputVersion != InputVersion)
|
|
{
|
|
ExitWithoutCrash(ESCWErrorCode::BadInputVersion, FString::Printf(TEXT("Exiting due to ShaderCompilerWorker expecting input version %d, got %d instead! Did you forget to build ShaderCompilerWorker?"), ShaderCompileWorkerInputVersion, InputVersion));
|
|
}
|
|
|
|
TMap<FString, uint16> ReceivedFormatVersionMap;
|
|
InputFile << ReceivedFormatVersionMap;
|
|
|
|
VerifyFormatVersions(ReceivedFormatVersionMap);
|
|
|
|
// Individual jobs
|
|
{
|
|
int32 SingleJobHeader = ShaderCompileWorkerSingleJobHeader;
|
|
InputFile << SingleJobHeader;
|
|
if (ShaderCompileWorkerSingleJobHeader != SingleJobHeader)
|
|
{
|
|
ExitWithoutCrash(ESCWErrorCode::BadSingleJobHeader, FString::Printf(TEXT("Exiting due to ShaderCompilerWorker expecting job header %d, got %d instead! Did you forget to build ShaderCompilerWorker?"), ShaderCompileWorkerSingleJobHeader, SingleJobHeader));
|
|
}
|
|
|
|
int32 NumBatches = 0;
|
|
InputFile << NumBatches;
|
|
|
|
// Flush cache, to make sure we load the latest version of the input file.
|
|
// (Otherwise quick changes to a shader file can result in the wrong output.)
|
|
FlushShaderFileCache();
|
|
|
|
for (int32 BatchIndex = 0; BatchIndex < NumBatches; BatchIndex++)
|
|
{
|
|
// Deserialize the job's inputs.
|
|
FShaderCompilerInput CompilerInput;
|
|
InputFile << CompilerInput;
|
|
|
|
if (IsValidRef(CompilerInput.SharedEnvironment))
|
|
{
|
|
// Merge the shared environment into the per-shader environment before calling into the compile function
|
|
CompilerInput.Environment.Merge(*CompilerInput.SharedEnvironment);
|
|
}
|
|
|
|
// Process the job.
|
|
FShaderCompilerOutput CompilerOutput;
|
|
ProcessCompilationJob(CompilerInput, CompilerOutput, WorkingDirectory);
|
|
|
|
// Serialize the job's output.
|
|
FJobResult& JobResult = *new(OutSingleJobResults) FJobResult;
|
|
JobResult.CompilerOutput = CompilerOutput;
|
|
}
|
|
}
|
|
|
|
// Shader pipeline jobs
|
|
{
|
|
int32 PipelineJobHeader = ShaderCompileWorkerPipelineJobHeader;
|
|
InputFile << PipelineJobHeader;
|
|
if (ShaderCompileWorkerPipelineJobHeader != PipelineJobHeader)
|
|
{
|
|
ExitWithoutCrash(ESCWErrorCode::BadPipelineJobHeader, FString::Printf(TEXT("Exiting due to ShaderCompilerWorker expecting pipeline job header %d, got %d instead! Did you forget to build ShaderCompilerWorker?"), ShaderCompileWorkerSingleJobHeader, PipelineJobHeader));
|
|
}
|
|
|
|
int32 NumPipelines = 0;
|
|
InputFile << NumPipelines;
|
|
|
|
for (int32 Index = 0; Index < NumPipelines; ++Index)
|
|
{
|
|
FPipelineJobResult& PipelineJob = *new(OutPipelineJobResults) FPipelineJobResult;
|
|
|
|
InputFile << PipelineJob.PipelineName;
|
|
|
|
int32 NumStages = 0;
|
|
InputFile << NumStages;
|
|
|
|
TArray<FShaderCompilerInput> CompilerInputs;
|
|
CompilerInputs.AddDefaulted(NumStages);
|
|
|
|
for (int32 StageIndex = 0; StageIndex < NumStages; ++StageIndex)
|
|
{
|
|
// Deserialize the job's inputs.
|
|
InputFile << CompilerInputs[StageIndex];
|
|
|
|
if (IsValidRef(CompilerInputs[StageIndex].SharedEnvironment))
|
|
{
|
|
// Merge the shared environment into the per-shader environment before calling into the compile function
|
|
CompilerInputs[StageIndex].Environment.Merge(*CompilerInputs[StageIndex].SharedEnvironment);
|
|
}
|
|
}
|
|
|
|
ProcessShaderPipelineCompilationJob(PipelineJob, CompilerInputs);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ProcessShaderPipelineCompilationJob(FPipelineJobResult& PipelineJob, TArray<FShaderCompilerInput>& CompilerInputs)
|
|
{
|
|
checkf(CompilerInputs.Num() > 0, TEXT("Exiting due to Pipeline %s having zero jobs!"), *PipelineJob.PipelineName);
|
|
|
|
// Process the job.
|
|
FShaderCompilerOutput FirstCompilerOutput;
|
|
CompilerInputs[0].bCompilingForShaderPipeline = true;
|
|
CompilerInputs[0].bIncludeUsedOutputs = false;
|
|
ProcessCompilationJob(CompilerInputs[0], FirstCompilerOutput, WorkingDirectory);
|
|
|
|
// Serialize the job's output.
|
|
{
|
|
FJobResult& JobResult = *new(PipelineJob.SingleJobs) FJobResult;
|
|
JobResult.CompilerOutput = FirstCompilerOutput;
|
|
}
|
|
|
|
bool bEnableRemovingUnused = true;
|
|
|
|
//#todo-rco: Only remove for pure VS & PS stages
|
|
for (int32 Index = 0; Index < CompilerInputs.Num(); ++Index)
|
|
{
|
|
auto Stage = CompilerInputs[Index].Target.Frequency;
|
|
if (Stage != SF_Vertex && Stage != SF_Pixel)
|
|
{
|
|
bEnableRemovingUnused = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
for (int32 Index = 1; Index < CompilerInputs.Num(); ++Index)
|
|
{
|
|
if (bEnableRemovingUnused && PipelineJob.SingleJobs.Last().CompilerOutput.bSupportsQueryingUsedAttributes)
|
|
{
|
|
CompilerInputs[Index].bIncludeUsedOutputs = true;
|
|
CompilerInputs[Index].bCompilingForShaderPipeline = true;
|
|
CompilerInputs[Index].UsedOutputs = PipelineJob.SingleJobs.Last().CompilerOutput.UsedAttributes;
|
|
}
|
|
|
|
FShaderCompilerOutput CompilerOutput;
|
|
ProcessCompilationJob(CompilerInputs[Index], CompilerOutput, WorkingDirectory);
|
|
|
|
// Serialize the job's output.
|
|
FJobResult& JobResult = *new(PipelineJob.SingleJobs) FJobResult;
|
|
JobResult.CompilerOutput = CompilerOutput;
|
|
}
|
|
}
|
|
|
|
FArchive* CreateOutputArchive()
|
|
{
|
|
FArchive* OutputFilePtr = nullptr;
|
|
const double StartTime = FPlatformTime::Seconds();
|
|
bool bResult = false;
|
|
|
|
// It seems XGE does not support deleting files.
|
|
// Don't delete the input file if we are running under Incredibuild.
|
|
// Instead, we signal completion by creating a zero byte "Success" file after the output file has been fully written.
|
|
if (!GShaderCompileUseXGE)
|
|
{
|
|
do
|
|
{
|
|
// Remove the input file so that it won't get processed more than once
|
|
bResult = IFileManager::Get().Delete(*InputFilePath);
|
|
}
|
|
while (!bResult && (FPlatformTime::Seconds() - StartTime < 2));
|
|
|
|
if (!bResult)
|
|
{
|
|
ExitWithoutCrash(ESCWErrorCode::CantDeleteInputFile, FString::Printf(TEXT("Couldn't delete input file %s, is it readonly?"), *InputFilePath));
|
|
}
|
|
}
|
|
|
|
// To make sure that the process waiting for results won't read unfinished output file,
|
|
// we use a temp file name during compilation.
|
|
do
|
|
{
|
|
FGuid Guid;
|
|
FPlatformMisc::CreateGuid(Guid);
|
|
TempFilePath = WorkingDirectory + Guid.ToString();
|
|
} while (IFileManager::Get().FileSize(*TempFilePath) != INDEX_NONE);
|
|
|
|
const double StartTime2 = FPlatformTime::Seconds();
|
|
|
|
do
|
|
{
|
|
// Create the output file.
|
|
OutputFilePtr = IFileManager::Get().CreateFileWriter(*TempFilePath,FILEWRITE_EvenIfReadOnly);
|
|
}
|
|
while (!OutputFilePtr && (FPlatformTime::Seconds() - StartTime2 < 2));
|
|
|
|
if (!OutputFilePtr)
|
|
{
|
|
ExitWithoutCrash(ESCWErrorCode::CantSaveOutputFile, FString::Printf(TEXT("Couldn't save output file %s"), *TempFilePath));
|
|
}
|
|
|
|
return OutputFilePtr;
|
|
}
|
|
|
|
void WriteToOutputArchive(FArchive* OutputFilePtr, TArray<FJobResult>& SingleJobResults, TArray<FPipelineJobResult>& PipelineJobResults)
|
|
{
|
|
FArchive& OutputFile = *OutputFilePtr;
|
|
|
|
int32 OutputVersion = ShaderCompileWorkerOutputVersion;
|
|
OutputFile << OutputVersion;
|
|
|
|
int32 ErrorCode = (int32)ESCWErrorCode::Success;
|
|
OutputFile << ErrorCode;
|
|
|
|
int32 ErrorStringLength = 0;
|
|
OutputFile << ErrorStringLength;
|
|
OutputFile << ErrorStringLength;
|
|
|
|
{
|
|
int32 SingleJobHeader = ShaderCompileWorkerSingleJobHeader;
|
|
OutputFile << SingleJobHeader;
|
|
|
|
int32 NumBatches = SingleJobResults.Num();
|
|
OutputFile << NumBatches;
|
|
|
|
for (int32 ResultIndex = 0; ResultIndex < SingleJobResults.Num(); ResultIndex++)
|
|
{
|
|
FJobResult& JobResult = SingleJobResults[ResultIndex];
|
|
OutputFile << JobResult.CompilerOutput;
|
|
}
|
|
}
|
|
|
|
{
|
|
int32 PipelineJobHeader = ShaderCompileWorkerPipelineJobHeader;
|
|
OutputFile << PipelineJobHeader;
|
|
int32 NumBatches = PipelineJobResults.Num();
|
|
OutputFile << NumBatches;
|
|
|
|
for (int32 ResultIndex = 0; ResultIndex < PipelineJobResults.Num(); ResultIndex++)
|
|
{
|
|
auto& PipelineJob = PipelineJobResults[ResultIndex];
|
|
OutputFile << PipelineJob.PipelineName;
|
|
int32 NumStageJobs = PipelineJob.SingleJobs.Num();
|
|
OutputFile << NumStageJobs;
|
|
for (int32 Index = 0; Index < NumStageJobs; ++Index)
|
|
{
|
|
FJobResult& JobResult = PipelineJob.SingleJobs[Index];
|
|
OutputFile << JobResult.CompilerOutput;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Called in the idle loop, checks for conditions under which the helper should exit */
|
|
void CheckExitConditions()
|
|
{
|
|
if (!InputFilename.Contains(TEXT("Only")))
|
|
{
|
|
UE_LOG(LogShaders, Log, TEXT("InputFilename did not contain 'Only', exiting after one job."));
|
|
FPlatformMisc::RequestExit(false);
|
|
}
|
|
|
|
#if PLATFORM_MAC || PLATFORM_LINUX
|
|
if (!FPlatformMisc::IsDebuggerPresent() && ParentProcessId > 0)
|
|
{
|
|
// If the parent process is no longer running, exit
|
|
if (!FPlatformProcess::IsApplicationRunning(ParentProcessId))
|
|
{
|
|
FString FilePath = FString(WorkingDirectory) + InputFilename;
|
|
checkf(IFileManager::Get().FileSize(*FilePath) == INDEX_NONE, TEXT("Exiting due to the parent process no longer running and the input file is present!"));
|
|
UE_LOG(LogShaders, Log, TEXT("Parent process no longer running, exiting"));
|
|
FPlatformMisc::RequestExit(false);
|
|
}
|
|
}
|
|
|
|
const double CurrentTime = FPlatformTime::Seconds();
|
|
// If we have been idle for 20 seconds then exit
|
|
if (CurrentTime - LastCompileTime > 20.0)
|
|
{
|
|
UE_LOG(LogShaders, Log, TEXT("No jobs found for 20 seconds, exiting"));
|
|
FPlatformMisc::RequestExit(false);
|
|
}
|
|
#else
|
|
// Don't do these if the debugger is present
|
|
//@todo - don't do these if Unreal is being debugged either
|
|
if (!IsDebuggerPresent())
|
|
{
|
|
if (ParentProcessId > 0)
|
|
{
|
|
FString FilePath = FString(WorkingDirectory) + InputFilename;
|
|
|
|
bool bParentStillRunning = true;
|
|
HANDLE ParentProcessHandle = OpenProcess(SYNCHRONIZE, false, ParentProcessId);
|
|
// If we couldn't open the process then it is no longer running, exit
|
|
if (ParentProcessHandle == nullptr)
|
|
{
|
|
checkf(IFileManager::Get().FileSize(*FilePath) == INDEX_NONE, TEXT("Exiting due to OpenProcess(ParentProcessId) failing and the input file is present!"));
|
|
UE_LOG(LogShaders, Log, TEXT("Couldn't OpenProcess, Parent process no longer running, exiting"));
|
|
FPlatformMisc::RequestExit(false);
|
|
}
|
|
else
|
|
{
|
|
// If we did open the process, that doesn't mean it is still running
|
|
// The process object stays alive as long as there are handles to it
|
|
// We need to check if the process has signaled, which indicates that it has exited
|
|
uint32 WaitResult = WaitForSingleObject(ParentProcessHandle, 0);
|
|
if (WaitResult != WAIT_TIMEOUT)
|
|
{
|
|
checkf(IFileManager::Get().FileSize(*FilePath) == INDEX_NONE, TEXT("Exiting due to WaitForSingleObject(ParentProcessHandle) signaling and the input file is present!"));
|
|
UE_LOG(LogShaders, Log, TEXT("WaitForSingleObject signaled, Parent process no longer running, exiting"));
|
|
FPlatformMisc::RequestExit(false);
|
|
}
|
|
CloseHandle(ParentProcessHandle);
|
|
}
|
|
}
|
|
|
|
const double CurrentTime = FPlatformTime::Seconds();
|
|
// If we have been idle for 20 seconds then exit
|
|
if (CurrentTime - LastCompileTime > 20.0)
|
|
{
|
|
UE_LOG(LogShaders, Log, TEXT("No jobs found for 20 seconds, exiting"));
|
|
FPlatformMisc::RequestExit(false);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
};
|
|
|
|
static FName NAME_PCD3D_SM5(TEXT("PCD3D_SM5"));
|
|
static FName NAME_PCD3D_SM4(TEXT("PCD3D_SM4"));
|
|
static FName NAME_PCD3D_ES3_1(TEXT("PCD3D_ES31"));
|
|
static FName NAME_PCD3D_ES2(TEXT("PCD3D_ES2"));
|
|
static FName NAME_GLSL_150(TEXT("GLSL_150"));
|
|
static FName NAME_GLSL_150_MAC(TEXT("GLSL_150_MAC"));
|
|
static FName NAME_SF_PS4(TEXT("SF_PS4"));
|
|
static FName NAME_SF_XBOXONE(TEXT("SF_XBOXONE"));
|
|
static FName NAME_GLSL_430(TEXT("GLSL_430"));
|
|
static FName NAME_GLSL_150_ES2(TEXT("GLSL_150_ES2"));
|
|
static FName NAME_GLSL_150_ES2_NOUB(TEXT("GLSL_150_ES2_NOUB"));
|
|
static FName NAME_GLSL_150_ES31(TEXT("GLSL_150_ES31"));
|
|
static FName NAME_GLSL_ES2(TEXT("GLSL_ES2"));
|
|
static FName NAME_GLSL_ES2_WEBGL(TEXT("GLSL_ES2_WEBGL"));
|
|
static FName NAME_GLSL_ES2_IOS(TEXT("GLSL_ES2_IOS"));
|
|
static FName NAME_SF_METAL(TEXT("SF_METAL"));
|
|
static FName NAME_SF_METAL_MRT(TEXT("SF_METAL_MRT"));
|
|
static FName NAME_GLSL_310_ES_EXT(TEXT("GLSL_310_ES_EXT"));
|
|
static FName NAME_SF_METAL_SM5(TEXT("SF_METAL_SM5"));
|
|
static FName NAME_VULKAN_ES3_1_ANDROID(TEXT("SF_VULKAN_ES31_ANDROID"));
|
|
static FName NAME_VULKAN_ES3_1(TEXT("SF_VULKAN_ES31"));
|
|
static FName NAME_VULKAN_SM4_UB(TEXT("SF_VULKAN_SM4_UB"));
|
|
static FName NAME_VULKAN_SM4(TEXT("SF_VULKAN_SM4"));
|
|
static FName NAME_VULKAN_SM5(TEXT("SF_VULKAN_SM5"));
|
|
static FName NAME_SF_METAL_SM4(TEXT("SF_METAL_SM4"));
|
|
static FName NAME_SF_METAL_MACES3_1(TEXT("SF_METAL_MACES3_1"));
|
|
static FName NAME_GLSL_ES3_1_ANDROID(TEXT("GLSL_ES3_1_ANDROID"));
|
|
|
|
static EShaderPlatform FormatNameToEnum(FName ShaderFormat)
|
|
{
|
|
if (ShaderFormat == NAME_PCD3D_SM5) return SP_PCD3D_SM5;
|
|
if (ShaderFormat == NAME_PCD3D_SM4) return SP_PCD3D_SM4;
|
|
if (ShaderFormat == NAME_PCD3D_ES3_1) return SP_PCD3D_ES3_1;
|
|
if (ShaderFormat == NAME_PCD3D_ES2) return SP_PCD3D_ES2;
|
|
if (ShaderFormat == NAME_GLSL_150) return SP_OPENGL_SM4;
|
|
if (ShaderFormat == NAME_GLSL_150_MAC) return SP_OPENGL_SM4_MAC;
|
|
if (ShaderFormat == NAME_SF_PS4) return SP_PS4;
|
|
if (ShaderFormat == NAME_SF_XBOXONE) return SP_XBOXONE;
|
|
if (ShaderFormat == NAME_GLSL_430) return SP_OPENGL_SM5;
|
|
if (ShaderFormat == NAME_GLSL_150_ES2) return SP_OPENGL_PCES2;
|
|
if (ShaderFormat == NAME_GLSL_150_ES2_NOUB) return SP_OPENGL_PCES2;
|
|
if (ShaderFormat == NAME_GLSL_150_ES31) return SP_OPENGL_PCES3_1;
|
|
if (ShaderFormat == NAME_GLSL_ES2) return SP_OPENGL_ES2_ANDROID;
|
|
if (ShaderFormat == NAME_GLSL_ES2_WEBGL) return SP_OPENGL_ES2_WEBGL;
|
|
if (ShaderFormat == NAME_GLSL_ES2_IOS) return SP_OPENGL_ES2_IOS;
|
|
if (ShaderFormat == NAME_SF_METAL) return SP_METAL;
|
|
if (ShaderFormat == NAME_SF_METAL_MRT) return SP_METAL_MRT;
|
|
if (ShaderFormat == NAME_GLSL_310_ES_EXT) return SP_OPENGL_ES31_EXT;
|
|
if (ShaderFormat == NAME_SF_METAL_SM5) return SP_METAL_SM5;
|
|
if (ShaderFormat == NAME_VULKAN_SM4) return SP_VULKAN_SM4;
|
|
if (ShaderFormat == NAME_VULKAN_SM5) return SP_VULKAN_SM5;
|
|
if (ShaderFormat == NAME_VULKAN_ES3_1_ANDROID) return SP_VULKAN_ES3_1_ANDROID;
|
|
if (ShaderFormat == NAME_VULKAN_ES3_1) return SP_VULKAN_PCES3_1;
|
|
if (ShaderFormat == NAME_VULKAN_SM4_UB) return SP_VULKAN_SM4;
|
|
if (ShaderFormat == NAME_SF_METAL_SM4) return SP_METAL_SM4;
|
|
if (ShaderFormat == NAME_SF_METAL_MACES3_1) return SP_METAL_MACES3_1;
|
|
if (ShaderFormat == NAME_GLSL_ES3_1_ANDROID) return SP_OPENGL_ES3_1_ANDROID;
|
|
return SP_NumPlatforms;
|
|
}
|
|
|
|
static void DirectCompile(const TArray<const class IShaderFormat*>& ShaderFormats)
|
|
{
|
|
// Find all the info required for compiling a single shader
|
|
TArray<FString> Tokens, Switches;
|
|
FCommandLine::Parse(FCommandLine::Get(), Tokens, Switches);
|
|
|
|
FString InputFile;
|
|
|
|
FName FormatName;
|
|
FString Entry = TEXT("Main");
|
|
bool bPipeline = false;
|
|
EShaderFrequency Frequency = SF_Pixel;
|
|
TArray<FString> UsedOutputs;
|
|
bool bIncludeUsedOutputs = false;
|
|
uint64 CFlags = 0;
|
|
for (const FString& Token : Tokens)
|
|
{
|
|
if (Switches.Contains(Token))
|
|
{
|
|
if (Token.StartsWith(TEXT("format=")))
|
|
{
|
|
FormatName = FName(*Token.RightChop(7));
|
|
}
|
|
else if (Token.StartsWith(TEXT("entry=")))
|
|
{
|
|
Entry = Token.RightChop(6);
|
|
}
|
|
else if (Token.StartsWith(TEXT("cflags=")))
|
|
{
|
|
CFlags = FCString::Atoi64(*Token.RightChop(7));
|
|
}
|
|
else if (!FCString::Strcmp(*Token, TEXT("ps")))
|
|
{
|
|
Frequency = SF_Pixel;
|
|
}
|
|
else if (!FCString::Strcmp(*Token, TEXT("vs")))
|
|
{
|
|
Frequency = SF_Vertex;
|
|
}
|
|
else if (!FCString::Strcmp(*Token, TEXT("hs")))
|
|
{
|
|
Frequency = SF_Hull;
|
|
}
|
|
else if (!FCString::Strcmp(*Token, TEXT("ds")))
|
|
{
|
|
Frequency = SF_Domain;
|
|
}
|
|
else if (!FCString::Strcmp(*Token, TEXT("gs")))
|
|
{
|
|
Frequency = SF_Geometry;
|
|
}
|
|
else if (!FCString::Strcmp(*Token, TEXT("cs")))
|
|
{
|
|
Frequency = SF_Compute;
|
|
}
|
|
else if (!FCString::Strcmp(*Token, TEXT("pipeline")))
|
|
{
|
|
bPipeline = true;
|
|
}
|
|
else if (Token.StartsWith(TEXT("usedoutputs=")))
|
|
{
|
|
FString Outputs = Token.RightChop(12);
|
|
bIncludeUsedOutputs = true;
|
|
FString LHS, RHS;
|
|
while (Outputs.Split(TEXT("+"), &LHS, &RHS))
|
|
{
|
|
Outputs = RHS;
|
|
UsedOutputs.Add(LHS);
|
|
}
|
|
UsedOutputs.Add(Outputs);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (InputFile.Len() == 0)
|
|
{
|
|
InputFile = Token;
|
|
}
|
|
}
|
|
}
|
|
|
|
FString Dir = FPlatformProcess::UserTempDir();
|
|
|
|
FShaderCompilerInput Input;
|
|
Input.EntryPointName = Entry;
|
|
Input.ShaderFormat = FormatName;
|
|
Input.SourceFilename = InputFile;
|
|
Input.Target.Platform = FormatNameToEnum(FormatName);
|
|
Input.Target.Frequency = Frequency;
|
|
Input.bSkipPreprocessedCache = true;
|
|
|
|
auto AddResourceTableEntry = [](TMap<FString, FResourceTableEntry>& Map, const FString& Name, const FString& UBName, int32 Type, int32 ResourceIndex)
|
|
{
|
|
FResourceTableEntry LambdaEntry;
|
|
LambdaEntry.UniformBufferName = UBName;
|
|
LambdaEntry.Type = Type;
|
|
LambdaEntry.ResourceIndex = ResourceIndex;
|
|
Map.Add(Name, LambdaEntry);
|
|
};
|
|
|
|
// Sample setup for Uniform Buffers as SCW does not rely on the Engine/Renderer. These change quite infrequently...
|
|
Input.Environment.ResourceTableLayoutHashes.Add(TEXT("View"), 178850472);
|
|
Input.Environment.ResourceTableLayoutHashes.Add(TEXT("InstancedView"), 178257920);
|
|
Input.Environment.ResourceTableLayoutHashes.Add(TEXT("BuiltinSamplers"), 134219776);
|
|
Input.Environment.ResourceTableLayoutHashes.Add(TEXT("Primitive"), 18874368);
|
|
Input.Environment.ResourceTableLayoutHashes.Add(TEXT("DrawRectangleParameters"), 3145728);
|
|
Input.Environment.ResourceTableLayoutHashes.Add(TEXT("SpeedTreeData"), 39845888);
|
|
Input.Environment.ResourceTableLayoutHashes.Add(TEXT("GBuffers"), 16842752);
|
|
Input.Environment.ResourceTableLayoutHashes.Add(TEXT("PrimitiveFade"), 1048576);
|
|
Input.Environment.ResourceTableLayoutHashes.Add(TEXT("VectorFieldVis"), 9437184);
|
|
Input.Environment.ResourceTableLayoutHashes.Add(TEXT("Material"), 6815848);
|
|
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_GlobalDistanceFieldTexture0_UB"), TEXT("View"), 9, 0);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_GlobalDistanceFieldSampler0_UB"), TEXT("View"), 8, 1);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_GlobalDistanceFieldTexture1_UB"), TEXT("View"), 9, 2);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_GlobalDistanceFieldSampler1_UB"), TEXT("View"), 8, 3);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_GlobalDistanceFieldTexture2_UB"), TEXT("View"), 9, 4);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_GlobalDistanceFieldSampler2_UB"), TEXT("View"), 8, 5);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_GlobalDistanceFieldTexture3_UB"), TEXT("View"), 9, 6);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_GlobalDistanceFieldSampler3_UB"), TEXT("View"), 8, 7);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_AtmosphereTransmittanceTexture_UB"), TEXT("View"), 9, 8);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_AtmosphereTransmittanceTextureSampler_UB"), TEXT("View"), 8, 9);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_AtmosphereIrradianceTexture_UB"), TEXT("View"), 9, 10);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_AtmosphereIrradianceTextureSampler_UB"), TEXT("View"), 8, 11);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_AtmosphereInscatterTexture_UB"), TEXT("View"), 9, 12);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_AtmosphereInscatterTextureSampler_UB"), TEXT("View"), 8, 13);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_PerlinNoiseGradientTexture"), TEXT("View"), 9, 14);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_PerlinNoiseGradientTextureSampler"), TEXT("View"), 8, 15);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_PerlinNoise3DTexture"), TEXT("View"), 9, 16);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("View_PerlinNoise3DTextureSampler"), TEXT("View"), 8, 17);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("BuiltinSamplers_Bilinear"), TEXT("BuiltinSamplers"), 8, 0);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("BuiltinSamplers_BilinearClamped"), TEXT("BuiltinSamplers"), 8, 1);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("BuiltinSamplers_Point"), TEXT("BuiltinSamplers"), 8, 2);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("BuiltinSamplers_PointClamped"), TEXT("BuiltinSamplers"), 8, 3);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("BuiltinSamplers_Trilinear"), TEXT("BuiltinSamplers"), 8, 4);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("BuiltinSamplers_TrilinearClamped"), TEXT("BuiltinSamplers"), 8, 5);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferATexture"), TEXT("GBuffers"), 9, 0);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferBTexture"), TEXT("GBuffers"), 9, 1);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferCTexture"), TEXT("GBuffers"), 9, 2);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferDTexture"), TEXT("GBuffers"), 9, 3);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferETexture"), TEXT("GBuffers"), 9, 4);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferVelocityTexture"), TEXT("GBuffers"), 9, 5);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferATextureNonMS"), TEXT("GBuffers"), 9, 6);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferBTextureNonMS"), TEXT("GBuffers"), 9, 7);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferCTextureNonMS"), TEXT("GBuffers"), 9, 8);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferDTextureNonMS"), TEXT("GBuffers"), 9, 9);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferETextureNonMS"), TEXT("GBuffers"), 9, 10);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferVelocityTextureNonMS"), TEXT("GBuffers"), 9, 11);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferATextureMS"), TEXT("GBuffers"), 9, 12);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferBTextureMS"), TEXT("GBuffers"), 9, 13);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferCTextureMS"), TEXT("GBuffers"), 9, 14);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferDTextureMS"), TEXT("GBuffers"), 9, 15);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferETextureMS"), TEXT("GBuffers"), 9, 16);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferVelocityTextureMS"), TEXT("GBuffers"), 9, 17);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferATextureSampler"), TEXT("GBuffers"), 8, 18);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferBTextureSampler"), TEXT("GBuffers"), 8, 19);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferCTextureSampler"), TEXT("GBuffers"), 8, 20);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferDTextureSampler"), TEXT("GBuffers"), 8, 21);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferETextureSampler"), TEXT("GBuffers"), 8, 22);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("GBuffers_GBufferVelocityTextureSampler"), TEXT("GBuffers"), 8, 23);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Clamp_WorldGroupSettings"), TEXT("Material"), 8, 1);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Wrap_WorldGroupSettings"), TEXT("Material"), 8, 0);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_0"), TEXT("Material"), 9, 0);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_1"), TEXT("Material"), 9, 1);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_2"), TEXT("Material"), 9, 2);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_3"), TEXT("Material"), 9, 3);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_4"), TEXT("Material"), 9, 4);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_5"), TEXT("Material"), 9, 5);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_6"), TEXT("Material"), 9, 6);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_7"), TEXT("Material"), 9, 7);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_0Sampler"), TEXT("Material"), 8, 8);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_1Sampler"), TEXT("Material"), 8, 9);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_2Sampler"), TEXT("Material"), 8, 10);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_3Sampler"), TEXT("Material"), 8, 11);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_4Sampler"), TEXT("Material"), 8, 12);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_5Sampler"), TEXT("Material"), 8, 13);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_6Sampler"), TEXT("Material"), 8, 14);
|
|
AddResourceTableEntry(Input.Environment.ResourceTableMap, TEXT("Material_Texture2D_7Sampler"), TEXT("Material"), 8, 15);
|
|
|
|
|
|
uint32 CFlag = 0;
|
|
while (CFlags != 0)
|
|
{
|
|
if ((CFlags & 1) != 0)
|
|
{
|
|
Input.Environment.CompilerFlags.Add(CFlag);
|
|
}
|
|
CFlags = (CFlags >> (uint64)1);
|
|
++CFlag;
|
|
}
|
|
|
|
Input.bCompilingForShaderPipeline = bPipeline;
|
|
Input.bIncludeUsedOutputs = bIncludeUsedOutputs;
|
|
Input.UsedOutputs = UsedOutputs;
|
|
|
|
FShaderCompilerOutput Output;
|
|
|
|
for (const IShaderFormat* Format : ShaderFormats)
|
|
{
|
|
TArray<FName> SupportedFormats;
|
|
Format->GetSupportedFormats(SupportedFormats);
|
|
for (FName SupportedName : SupportedFormats)
|
|
{
|
|
if (SupportedName == FormatName)
|
|
{
|
|
Format->CompileShader(FormatName, Input, Output, Dir);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
UE_LOG(LogShaders, Warning, TEXT("Unable to find shader compiler backend for format %s!"), *FormatName.ToString());
|
|
}
|
|
|
|
|
|
/**
|
|
* Main entrypoint, guarded by a try ... except.
|
|
* This expects 4 parameters:
|
|
* The image path and name
|
|
* The working directory path, which has to be unique to the instigating process and thread.
|
|
* The parent process Id
|
|
* The thread Id corresponding to this worker
|
|
*/
|
|
static int32 GuardedMain(int32 argc, TCHAR* argv[], bool bDirectMode)
|
|
{
|
|
GEngineLoop.PreInit(argc, argv, TEXT("-NOPACKAGECACHE -Multiprocess"));
|
|
#if DEBUG_USING_CONSOLE
|
|
GLogConsole->Show( true );
|
|
#endif
|
|
|
|
// We just enumerate the shader formats here for debugging.
|
|
const TArray<const class IShaderFormat*>& ShaderFormats = GetShaderFormats();
|
|
check(ShaderFormats.Num());
|
|
TMap<FString, uint16> FormatVersionMap;
|
|
for (int32 Index = 0; Index < ShaderFormats.Num(); Index++)
|
|
{
|
|
TArray<FName> OutFormats;
|
|
ShaderFormats[Index]->GetSupportedFormats(OutFormats);
|
|
check(OutFormats.Num());
|
|
for (int32 InnerIndex = 0; InnerIndex < OutFormats.Num(); InnerIndex++)
|
|
{
|
|
UE_LOG(LogShaders, Display, TEXT("Available Shader Format %s"), *OutFormats[InnerIndex].ToString());
|
|
uint16 Version = ShaderFormats[Index]->GetVersion(OutFormats[InnerIndex]);
|
|
FormatVersionMap.Add(OutFormats[InnerIndex].ToString(), Version);
|
|
}
|
|
}
|
|
|
|
LastCompileTime = FPlatformTime::Seconds();
|
|
|
|
if (bDirectMode)
|
|
{
|
|
DirectCompile(ShaderFormats);
|
|
}
|
|
else
|
|
{
|
|
#if PLATFORM_WINDOWS
|
|
//@todo - would be nice to change application name or description to have the ThreadId in it for debugging purposes
|
|
SetConsoleTitle(argv[3]);
|
|
#endif
|
|
|
|
FWorkLoop WorkLoop(argv[2], argv[1], argv[4], argv[5], FormatVersionMap);
|
|
WorkLoop.Loop();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int32 GuardedMainWrapper(int32 ArgC, TCHAR* ArgV[], const TCHAR* CrashOutputFile, bool bDirectMode)
|
|
{
|
|
// We need to know whether we are using XGE now, in case an exception
|
|
// is thrown before we parse the command line inside GuardedMain.
|
|
GShaderCompileUseXGE = (ArgC > 6) && FCString::Strcmp(ArgV[6], TEXT("-xge")) == 0;
|
|
|
|
int32 ReturnCode = 0;
|
|
#if PLATFORM_WINDOWS
|
|
if (FPlatformMisc::IsDebuggerPresent())
|
|
#endif
|
|
{
|
|
ReturnCode = GuardedMain(ArgC, ArgV, bDirectMode);
|
|
}
|
|
#if PLATFORM_WINDOWS
|
|
else
|
|
{
|
|
// Don't want 32 dialogs popping up when SCW fails
|
|
GUseCrashReportClient = false;
|
|
__try
|
|
{
|
|
GIsGuarded = 1;
|
|
ReturnCode = GuardedMain(ArgC, ArgV, bDirectMode);
|
|
GIsGuarded = 0;
|
|
}
|
|
__except( ReportCrash( GetExceptionInformation() ) )
|
|
{
|
|
FArchive& OutputFile = *IFileManager::Get().CreateFileWriter(CrashOutputFile,FILEWRITE_NoFail);
|
|
|
|
int32 OutputVersion = ShaderCompileWorkerOutputVersion;
|
|
OutputFile << OutputVersion;
|
|
|
|
if (GFailedErrorCode == ESCWErrorCode::Success)
|
|
{
|
|
GFailedErrorCode = ESCWErrorCode::GeneralCrash;
|
|
}
|
|
int32 ErrorCode = (int32)GFailedErrorCode;
|
|
OutputFile << ErrorCode;
|
|
|
|
// Note: Can't use FStrings here as SEH can't be used with destructors
|
|
int32 CallstackLength = FCString::Strlen(GErrorHist);
|
|
OutputFile << CallstackLength;
|
|
|
|
int32 ExceptionInfoLength = FCString::Strlen(GErrorExceptionDescription);
|
|
OutputFile << ExceptionInfoLength;
|
|
|
|
OutputFile.Serialize(GErrorHist, CallstackLength * sizeof(TCHAR));
|
|
OutputFile.Serialize(GErrorExceptionDescription, ExceptionInfoLength * sizeof(TCHAR));
|
|
|
|
int32 NumBatches = 0;
|
|
OutputFile << NumBatches;
|
|
|
|
// Close the output file.
|
|
delete &OutputFile;
|
|
|
|
if (GShaderCompileUseXGE)
|
|
{
|
|
ReturnCode = 1;
|
|
WriteXGESuccessFile(ArgV[1]);
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
FEngineLoop::AppPreExit();
|
|
FEngineLoop::AppExit();
|
|
|
|
return ReturnCode;
|
|
}
|
|
|
|
IMPLEMENT_APPLICATION(ShaderCompileWorker, "ShaderCompileWorker")
|
|
|
|
|
|
/**
|
|
* Application entry point
|
|
*
|
|
* @param ArgC Command-line argument count
|
|
* @param ArgV Argument strings
|
|
*/
|
|
|
|
INT32_MAIN_INT32_ARGC_TCHAR_ARGV()
|
|
{
|
|
// FPlatformProcess::OpenProcess only implemented for windows atm
|
|
#if PLATFORM_WINDOWS
|
|
if (ArgC == 4 && FCString::Strcmp(ArgV[1], TEXT("-xgemonitor")) == 0)
|
|
{
|
|
// Open handles to the two processes
|
|
FProcHandle EngineProc = FPlatformProcess::OpenProcess(FCString::Atoi(ArgV[2]));
|
|
FProcHandle BuildProc = FPlatformProcess::OpenProcess(FCString::Atoi(ArgV[3]));
|
|
|
|
if (EngineProc.IsValid() && BuildProc.IsValid())
|
|
{
|
|
// Whilst the build is still in progress
|
|
while (FPlatformProcess::IsProcRunning(BuildProc))
|
|
{
|
|
// Check that the engine is still alive.
|
|
if (!FPlatformProcess::IsProcRunning(EngineProc))
|
|
{
|
|
// The engine has shutdown before the build was stopped.
|
|
// Kill off the build process
|
|
FPlatformProcess::TerminateProc(BuildProc);
|
|
break;
|
|
}
|
|
|
|
FPlatformProcess::Sleep(0.01f);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
#endif
|
|
TCHAR OutputFilePath[PLATFORM_MAX_FILEPATH_LENGTH] = TEXT("");
|
|
bool bDirectMode = false;
|
|
for (int32 Index = 1; Index < ArgC; ++Index)
|
|
{
|
|
if (FCString::Strcmp(ArgV[Index], TEXT("-directcompile")) == 0)
|
|
{
|
|
bDirectMode = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!bDirectMode)
|
|
{
|
|
if (ArgC < 6)
|
|
{
|
|
printf("ShaderCompileWorker is called by UE4, it requires specific command like arguments.\n");
|
|
return -1;
|
|
}
|
|
|
|
// Game exe can pass any number of parameters through with appGetSubprocessCommandline
|
|
// so just make sure we have at least the minimum number of parameters.
|
|
check(ArgC >= 6);
|
|
|
|
FCString::Strncpy(OutputFilePath, ArgV[1], PLATFORM_MAX_FILEPATH_LENGTH);
|
|
FCString::Strncat(OutputFilePath, ArgV[5], PLATFORM_MAX_FILEPATH_LENGTH);
|
|
}
|
|
|
|
const int32 ReturnCode = GuardedMainWrapper(ArgC, ArgV, OutputFilePath, bDirectMode);
|
|
return ReturnCode;
|
|
}
|