Files
UnrealEngineUWP/Engine/Source/Developer/ShaderPreprocessor/Private/ShaderPreprocessor.cpp
Chris Bunner 81ef7a206b Copying //UE4/Dev-Rendering to //UE4/Dev-Main (Source: //UE4/Dev-Rendering @ 3461187)
#lockdown Nick.Penwarden

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3388286 on 2017/04/11 by Chris.Bunner

	Fix mips in texture GnmUAV creation.

Change 3388287 on 2017/04/11 by Chris.Bunner

	Improved PS/CS code sharing for TemporalAA.

Change 3388291 on 2017/04/11 by Chris.Bunner

	HLODs now correctly hide their children in shadow maps.
	Propagate bCastFarShadow flag on HLOD generation.

	#jira UE-42254

Change 3388448 on 2017/04/11 by Brian.Karis

	Better handle divide by zero

Change 3388449 on 2017/04/11 by Brian.Karis

	Optimizations to shading model math.

	PR #3340: Bug fixes related to shader TODOs (Contributed by vgfx)


Change 3388455 on 2017/04/11 by Uriel.Doyon

	Changed Remove for RemoveSwap when clearing dynamic component references

Change 3388612 on 2017/04/11 by Simon.Tourangeau

	Support shaders in projects and in plugins
	When searching for a shader it will
	- First look in Engine/Shaders as usual
	- Then in project's Shader folder
	- Then in all enabled plugin Shader folders

	Project or plugin must be loaded in PostConfigInit phase
	Tested in PIE, engine (cooked, packaged)

Change 3388819 on 2017/04/11 by Arne.Schober

	DR - Faster MorpthTarget implementation. Changed the previous Gather aproach to a scatter based one. Reaching about 110GB/s on PS4 which is up to 4x faster than the previous implementation. On PC DX11 the impact is lower due to unecessary UAV barriers but still 2x faster on AMD and up to 6x faster on Nvidia Hardware.
	#RB Lina.Halper, Rolando.Caloca

Change 3388862 on 2017/04/11 by Guillaume.Abadie

	Allows Motion Blur and TAA in scene capture 2d.

Change 3388953 on 2017/04/11 by Uriel.Doyon

	Fixed issue where lights from hidden levels where affecting the lighting build, by checking if the light is registered before adding it.
	#UE-43220

Change 3389138 on 2017/04/11 by Arne.Schober

	DR - Fix crash when opening a Level without Contentbrowser open.
	#RB Matt.Kuhlenschmidt

Change 3389400 on 2017/04/11 by Uriel.Doyon

	- Renamed FMaterialResource::IsSeparateTranslucencyEnabled() to FMaterialResource::IsTranslucencyAfterDOFEnabled()
	- Removed different logic to determine if translucency after DOF was enabled, and centralized it into a single function: FSceneViewFamily::AllowTranslucencyAfterDOF()
	- FSceneRenderTargets::FinishRenderingSeparateTranslucency() now only resolves a single view, allowing better Begin/Finish scopes.
	- Renamed FSceneRenderTargets::SeparateTranslucencyDepthRT into FSceneRenderTargets::DownsampledTranslucencyDepthRT since this one is only allocated when rendering in downsampled mode.
	- Standard translucency is now rendered in the same resolution than translucency after DOF. (downsampled or full resolution)
	- Removed RenderTranslucencyParallel and merged it's logic into RenderTranslucency. Renamed DrawAllTranslucencyPasses to RenderViewTranslucency and added a parallel version RenderViewTranslucencyParallel.
	- Moved all debug draw logic (VisualizeLPV, ViewMeshElements and SimpleElementCollector) to a common place.
	- New option "r.AllowDownsampledStandardTranslucency" to control the downsampling of standard translucency. Affect blend module materials

	#jira UE-39505

Change 3389860 on 2017/04/12 by Richard.Wallis

	UE-41407 Cable actor does not render correctly in viewport on Mac.

	Build the mesh at creation time - call into exisiting mesh create function.

Change 3390933 on 2017/04/12 by Arne.Schober

	DR - potential fix for UE-43125 where the this pointer might get invalidated in the middle of the function
	#RB Marcus.Wassmer

Change 3391010 on 2017/04/12 by Ben.Marsh

	Compile UE4Game non-unity for Mac as part of nightly builds in //UE4/Dev-Rendering.

Change 3391412 on 2017/04/12 by Uriel.Doyon

	Mesh Decals are now sorted according to the component TranslucencySortPriority.
	#jira UE-43053

Change 3392117 on 2017/04/13 by Guillaume.Abadie

	Integrates Raven's experimental PCSS for cascaded shadow map hidden behind a CVar.

Change 3392179 on 2017/04/13 by Guillaume.Abadie

	Attempts to fix linux compilation by removing mistakenly submitted dead code.

Change 3392231 on 2017/04/13 by Guillaume.Abadie

	Fixes a wrong enum value real quick in FRenderingObjectVersion I introduced after main integration... Oups...

Change 3393879 on 2017/04/14 by Guillaume.Abadie

	Attempts to fix linux compilation warning.

Change 3393881 on 2017/04/14 by Guillaume.Abadie

	Back out changelist 3393879

Change 3393882 on 2017/04/14 by Guillaume.Abadie

	Attempts #2 to fix linux compilation error.

Change 3394100 on 2017/04/14 by Chris.Bunner

	Corrected material shared sampler usage with mip-biasing.

Change 3394174 on 2017/04/14 by Rolando.Caloca

	DR - Change ensure to warning

Change 3394221 on 2017/04/14 by Marcus.Wassmer

	Fix poseable mesh bounds calculation.

Change 3396238 on 2017/04/17 by David.Hill

	Fix Bloom with LensFlare
	Duplicating fix - will also fix directly in 4.16

	#jira 44050

Change 3397055 on 2017/04/17 by Joe.Graf

	Fixed Windows specific assumptions in Slate File Dialog Window's file filtering that lead to crashes

	#CodeReview: matt.kuhlenschmidt
	#rb: n/a

Change 3397921 on 2017/04/18 by Joe.Graf

	Rewrote SlateFileDlgWindow's file filtering to allow for extensionless file selection and to remove the O(n^2) file filtering

	#CodeReview: arciel.rekman, matt.kuhlenschmidt
	#rb: n/a

Change 3398406 on 2017/04/18 by Rolando.Caloca

	DR - Fix shaders in plugins on Mac

Change 3399546 on 2017/04/19 by Benjamin.Hyder

	Updating content for test levels (HDR, Bloom_FFT, DistanceFields_IndirectShadows)

Change 3399725 on 2017/04/19 by Guillaume.Abadie

	Avoids compiling PCSS shaders for SM4.

Change 3400295 on 2017/04/19 by Michael.Trepka

	Fixed metal shader compile errors in MorphTargets.usf

Change 3400457 on 2017/04/19 by Michael.Trepka

	Merged Rolando's shader fixes

Change 3400473 on 2017/04/19 by Arne.Schober

	DR - provide Aftermath Reason when init failed.
	#RB none

Change 3400699 on 2017/04/19 by Arne.Schober

	DR - Fixed Text macro
	#RB none

Change 3402280 on 2017/04/20 by Simon.Tovey

	Minor cascade fix

	#tests no crash

	#jira UE-41560

Change 3402517 on 2017/04/20 by Arne.Schober

	DR - Fix static analysis warning
	#RB none

Change 3403897 on 2017/04/21 by Arne.Schober

	DR - [UE-43898] - Someone missed a shaderversion bump which poisoned the DCC
	#RB None
	#jira UE-43898

Change 3404591 on 2017/04/21 by Olaf.Piesche

	#jira UE-41979
	Should never be crashing there, unless the mesh is changed after Init of the effect instance; this change safeguards against the number of mesh sections (and hence materials) changing after creation of the dynamic data to avoid the crash.

Change 3407451 on 2017/04/25 by Daniel.Wright

	Fixed Indirect Lighting Cache updates caused by capsule indirect shadows forcing point samples, breaking primitives using ILCQ_Volume

Change 3407452 on 2017/04/25 by Daniel.Wright

	Added r.AOJitterConeDirections, although disabled by default because it requires the temporal filter to be much stronger

Change 3408397 on 2017/04/25 by Daniel.Wright

	ViewFamily.bRealtimeUpdate is set to false if Slate is throttling (like when toggling show flags).  Volumetric fog discards the temporal history when not realtime, so you can see changes immediately.

Change 3408428 on 2017/04/25 by Daniel.Wright

	Changed 'r.AOMaxObjectsPerCullTile' default back to 512 as 256 causes artifacts with RTDF shadows

Change 3409764 on 2017/04/26 by Daniel.Wright

	Force dumping shader debug info for Global shaders when r.ShaderDevelopmentMode is enabled.  Most of the shaders you want to look at in a GPU capture are global shaders, and global shaders create few debug files.  'recompileshaders global' time 35s -> 38s for SM5.

Change 3411659 on 2017/04/27 by Daniel.Wright

	[Copy] Set Xbox One engine default screen percentage to 83.33 (1600x900), as ESRAM choices are dependent on this

Change 3411660 on 2017/04/27 by Daniel.Wright

	[Copy] Global distance field composite shader has a version for each flattened axis, which improves efficiency when updating a slab which is what camera movement typically causes

Change 3411667 on 2017/04/27 by Daniel.Wright

	[Copy] Discard distance field AO history buffer if it doesn't match the new buffer size.  This prevents reading uinitialized data after a scene render target resize.

Change 3411668 on 2017/04/27 by Daniel.Wright

	[Copy] Better indirect capsule shadow draw event info

Change 3411669 on 2017/04/27 by Daniel.Wright

	[Copy] Pass down FeatureLevel to AddSubjectPrimitive and GatherShadowsForPrimitiveInner instead of calling the scene's virtual function.  Showed up prominently in a sampling profile.

Change 3411755 on 2017/04/27 by Daniel.Wright

	[Copy] Occlusion queries are now always done before the base pass if a nearly full prepass is being used(DDM_AllOccluders or DDM_AllOpaque)
	* Removed r.OcclusionQueryLocation

Change 3411827 on 2017/04/27 by Daniel.Wright

	[Copy] Much cheaper implementation of IsForwardShadingEnabled which showed up prominently in sampling profiles - inlined function and no more unnecessary thread safety overhead

Change 3411829 on 2017/04/27 by Daniel.Wright

	Added an ensure to console manager when doing FindTConsoleVariableData* on a FAutoConsoleVariableRef

Change 3411837 on 2017/04/27 by Daniel.Wright

	[Copy] Worked around slow memcpy's being used to sort FSortedLightSceneInfo

Change 3411838 on 2017/04/27 by Daniel.Wright

	[Copy] Skip tracking MaterialRenderProxyMap on cooked platforms

Change 3411843 on 2017/04/27 by Daniel.Wright

	[Copy] Fixed r.ParallelShadows on PS4 and enabled by default engine-wide (saves 5ms RT with CSM)
	* Gnm was not tracking DepthClearValue when a depth target was set but not cleared
	* Gnm has a bug where TargetsNeedingEliminateFastClear does not persist across commandlist breaks.  Moved FinishRenderingGBuffer before RenderShadowDepthMaps to workaround (accidentally not in this changelist)
	* Shadow depth rendering was not using BindClearMRTValues to populate GNM parallel commandlist TargetsNeedingEliminateFastClear values

Change 3411873 on 2017/04/27 by Daniel.Wright

	[Copy] Deferred uniform expression caching.  Setting multiple parameters on a material only causes its uniform expressions to be recached once.
	* 280 calls to CacheUniformExpressions -> 120 during Fortnite combat (6.5ms -> 3.4ms)

Change 3411891 on 2017/04/27 by Daniel.Wright

	[Copy] GatherShadowPrimitives optimizations
	* Total GatherShadowPrimivies went from 2.3ms -> 1.3ms on PS4 with these changes in GPUPerfTest (duplicated 3x)
	* Much flatter primitive octree (16 -> 256 max primitives)
	* Primitives are culled against the shadow frustum before FPrimitiveSceneInfo or FPrimitiveSceneProxy are dereferenced in FilterPrimitiveForShadows
	* FilterPrimitiveForShadows work is done in a ParallelFor.  Primitive octree nodes are processed in different jobs.
	* StaticMeshWholeSceneShadowBatchVisibility now only stores entries for meshes with bRequiresPerElementVisibility (landscape).  Previously it was allocating and zeroing 500Kb 3x per frame (main view + 2 cascades) which cost ~.8ms on PS4.

Change 3412192 on 2017/04/27 by Michael.Trepka

	Fixed Clang compile errors in FortniteGame, partial copy of CL 3313426

Change 3412547 on 2017/04/27 by Daniel.Wright

	Fixed leak of FShadowMapAllocation and FLightMapAllocation's found by licensee

Change 3414239 on 2017/04/28 by Arne.Schober

	DR - UE-44500 - Removed use of Structured Buffer from MorphTargets due to HLSLCC not supporting it.

	#RB none
	#jira UE-44500

Change 3414754 on 2017/04/28 by Daniel.Wright

	Added VolumetricFogEmissive to ExponentialHeightFogComponent
	* Volumetric fog does not yet support precomputed lighting, so this is the only way to get an ambient lighting term

Change 3416859 on 2017/05/01 by Arne.Schober

	DR - Remove FeatureLevel from the Clear Functions to reduce area of error
	#RB Rolando.Caloca

Change 3420750 on 2017/05/03 by Arne.Schober

	DR - [UE-44497] - Fix several PS4 validation layer issues
	#RB Marcus.Wassmer

Change 3422869 on 2017/05/04 by Benjamin.Hyder

	Fix compile error from merge.

Change 3423938 on 2017/05/04 by Marc.Olano

	[UE-44453] Fix bloom problems by moving saturate after vector math

Change 3424494 on 2017/05/04 by Olaf.Piesche

	#jira UE-44589
	When using FindTCosoleVariableData, the CVar can not be an FAutoConsoleVariable.

	#tests as described in jira ticket

Change 3424754 on 2017/05/04 by Uriel.Doyon

	Fixed call to get texture compressor module outside the main thread.
	#jira UE-42168

Change 3425447 on 2017/05/05 by Uriel.Doyon

	#buildfix

Change 3427042 on 2017/05/05 by Arne.Schober

	DR -  Fix one of my typos
	#RB none

Change 3428119 on 2017/05/08 by Marcus.Wassmer

	Fix UE-44733
	static analysis warning.

Change 3428222 on 2017/05/08 by Uriel.Doyon

	Fixed bad condition in translucency rendering
	#jira UE-44452

Change 3429794 on 2017/05/08 by Uriel.Doyon

	Fixed issues with lightshafts and low res translucency.

	#jira UE-44452

Change 3430921 on 2017/05/09 by Rolando.Caloca

	DR -  Get additional function pointers for D3DReflect, Compile and Disassemble instructions from the same DLL when compiling D3D11 shaders.
	- Also fixes using the correct fxc.exe path to match the DLL we distribute.

Change 3431156 on 2017/05/09 by Rolando.Caloca

	DR - Remove unused code

Change 3431396 on 2017/05/09 by David.Hill

	Copy of changes made directly in 4.16  ( CL 341037 )
	to be submitted to dev-rendering

	#jira UE-44641

Change 3431400 on 2017/05/09 by Rolando.Caloca

	DR - Fix typo

Change 3431527 on 2017/05/09 by David.Hill

	#rb: none

	Oops.
	comment out r.ShaderDevelopmentMode =1

Change 3431590 on 2017/05/09 by Daniel.Wright

	Removed early return landmine in USceneCaptureComponent2D::Serialize

Change 3431591 on 2017/05/09 by Daniel.Wright

	Disallow map building while in PIE, or PIE while buildling lighting

Change 3431594 on 2017/05/09 by Daniel.Wright

	Added RenderTargetFormat to UTextureRenderTarget2D, with choices of 8 bit, 16fp, 32fp and 1, 2 or 4 channels.

Change 3431667 on 2017/05/09 by Daniel.Wright

	Volumetric fog now supersamples lighting when the history is not available, reducing noise on areas that just came on-screen or after a camera cut.
	* The number of samples is controlled by r.VolumetricFog.HistoryMissSupersampleCount, defaults to 4, cinematic scalability uses 16
	* Under fast camera movement, volumetric fog cost went from 1.79ms -> 1.97ms with 4 samples, on a 970GTX

Change 3432366 on 2017/05/10 by Richard.Wallis

	Fix for MetalRHI Asserts When Using "Profile GPU" With RHI-Thread/Parallel-Execution.  Don't insert events when not in RHIThread or the actual single-threaded-render thread.

	#jira UE-36006

Change 3432367 on 2017/05/10 by Richard.Wallis

	Fix for Metal ReStartRenderPass assert with profiling.  macOS metal asserts when using "profileGPU" even with -norhithread argument set.

	Added no action to the allowed render pass restart store actions for the depth buffer avoiding the assert.  Interested to know the details if this is not a valid assumption to make - throwing away the depth buffer after a render pass I think would be a common case.

	#jira UE-44322

Change 3432409 on 2017/05/10 by Richard.Wallis

	Merged across CL 3415890 from Release-4.16 fix for (jira UE-43895)

	Fix for deferred store actions getting cleared when we don't have a valid render target.

Change 3432833 on 2017/05/10 by Daniel.Wright

	Fixed Ocean compile error

Change 3432874 on 2017/05/10 by Marc.Olano

	Improved captions for Noise and VectorNoise material nodes

Change 3432947 on 2017/05/10 by Richard.Wallis

	Fix for shared Material Native Shader Libraries Don't Function With Iterative Cooking.   Keep latest versions of shader byte code in native shared material packaged build in an intermediate directory than can be reused on a later iterative cook.

	- Doesn't handle deletion of the intermediate directory contents.  Assumed to be a higher level requirement on non iterative cook flag.

	#jira UE-44657

Change 3433484 on 2017/05/10 by Arne.Schober

	DR - UE-44393 - Move ShaderPlatform into TShaderMap for extra debuginformation when it fails to find a proper shader. Also log when Gobalshaders are verified and recompiled.
	#jira UE-44393
	#RB Daniel.Wright

Change 3433515 on 2017/05/10 by Arne.Schober

	DR - Fix a bug where recompileshaders changed while compiling causes a crash where the chached local vertex factories are mutated while been used.
	#RB Daniel.Wright

Change 3433606 on 2017/05/10 by Daniel.Wright

	Fixed static shadowing of volumetric fog and translucency causing shadowing past the lightmass importance volume.

Change 3433619 on 2017/05/10 by Daniel.Wright

	Skip recapturing reflection captures when PropagateLightingScenarioChange is being called for a level unload.  This leaves stale results in reflection captures around when hiding a level in the editor, but avoids the double recapture that happens when swapping lighting scenarios in game, and the unnecessary reflection capture update when exiting PIE.

Change 3433795 on 2017/05/10 by Arne.Schober

	DR - add cmdline to select a GPU vendor when multiple GPUs from differnt Vendors are installed into the same Machine
	#RB marcus.Wassmer

Change 3433941 on 2017/05/10 by Daniel.Wright

	Cone vs tile bounding sphere intersection tests for Light Grid culling of spotlights, which provides much tighter culling than just View space tile AABB vs light bounding sphere.
	* Forward shading BasePass 3.7ms -> 2.4ms in a scene with 24 spotlights on 970GTX
	* Volumetric fog 2.87ms -> 2.09ms in the same scene

Change 3435139 on 2017/05/11 by Daniel.Wright

	Restored GTextureRenderTarget2DMaxSizeX which is used by Ocean

Change 3435297 on 2017/05/11 by Arne.Schober

	DR - Remove manual AlignOf and use C++11 keyword instead
	#RB Steve.Robb

Change 3435367 on 2017/05/11 by Daniel.Wright

	Circle vertex buffer for slightly tighter voxelization of volumetric fog shadowed lights
	* 1.5ms -> 1.38ms on 970 GTX with 24 spotlights

Change 3435522 on 2017/05/11 by Brian.Karis

	Dither opacity mask now stacks properly for non parallel polys. Dither is randomized by triangle normal.

Change 3436063 on 2017/05/11 by Daniel.Wright

	Disabled CLB_AggressiveBatching for PC d3d12 as it causes flickering artifacts in lighting

Change 3436269 on 2017/05/11 by Uriel.Doyon

	Fixed UVChannel data possibly not up-to-date depending on user manips.

Change 3436611 on 2017/05/12 by Simon.Tovey

	Improved name and tooltip for static mesh property controlling generation of alias tables for uniform sampling.

Change 3436676 on 2017/05/12 by Simon.Tovey

	Fix for fixed bounds being "invalid" unless set via the toolbar option.

Change 3436700 on 2017/05/12 by Simon.Tovey

	Crash fix.
	Issue found in https://udn.unrealengine.com/questions/355944/crash-in-fdynamicspriteemitterdatagetdynamicmeshel.html

	Particle proxies would have stale material resource pointers if the material is changed while the system was invisible.
	If the old material is freed during this time, the next time the system renders it will crash.

Change 3437367 on 2017/05/12 by Brian.Karis

	Fixed bug with small UV charts not packing.

Change 3437860 on 2017/05/12 by Arne.Schober

	DR - Fix alignment compile error in win32 where according to ABI alignment is 4 for int64
	#RB none

Change 3437972 on 2017/05/12 by Arne.Schober

	DR - Fix alignment compile error in win32 where according to ABI function calls cannot take alingned structures. In all of the cases the copy was completely unnecessary.
	#RB none

Change 3437975 on 2017/05/12 by Chris.Bunner

	Added calculation for MaterialParamsEx to MeshDecals.usf.

	#jira UE-43052

Change 3438109 on 2017/05/12 by Rolando.Caloca

	DR - Support for -nomcpp on SCW

Change 3438889 on 2017/05/15 by Chris.Bunner

	Nullptr check in a few material uniform expressions.

Change 3439351 on 2017/05/15 by Chris.Bunner

	Added tooltip to Power material expression.

Change 3439763 on 2017/05/15 by Daniel.Wright

	Apply passed in DistanceBiasSqr to line lights - allows volumetric fog to reduce aliasing on line lights

Change 3439764 on 2017/05/15 by Daniel.Wright

	Fixed order of operations with bTreatMaxDepthUnshadowed - manifested as unfiltered static shadow depth lookups

Change 3440722 on 2017/05/16 by Guillaume.Abadie

	Exposes Scene capture's FOV to blueprints

Change 3441680 on 2017/05/16 by Uriel.Doyon

	Added units to point light intensity, to allow the user to specify the value in candelas or lumens.
	New point light actors now configure the intensity in candelas by default.
	Replaced viewport exposure settings by an EV100 slider.
	Hidding the tone mapper in the show flag now still applies the exposure.
	Added a new AutoExposure method called EV100 which allows to specify :
	- MinEV100, MaxEV100
	- Calibration Constnat
	- Exposure Compensation
	#jira UE-42783

Change 3441884 on 2017/05/16 by Uriel.Doyon

	Fixed StreamingDistanceMultiplier not being applied to the texture streaming data.

Change 3442800 on 2017/05/17 by Gil.Gribb

	Fixed botched merge.

Change 3442896 on 2017/05/17 by Gil.Gribb

	UE4 - Allowed the possibility of running the RHI "thread" on task threads instead and cleaned up and unified the conditionals involved. By default we still have a dedicated RHI thread because it tested slightly faster.

Change 3443951 on 2017/05/17 by Richard.Wallis

	Added Apple override allocator macro - each command encoder type needs it's own allocator queue.

Change 3444787 on 2017/05/17 by Daniel.Wright

	Fixed DBuffer decal default normal (used when DBuffer decals enabled, but not decals rendered) not reconstructing zero properly, adding -.008 to WorldNormal which then caused artifacts with forward lighting specular on materials with roughness near 0.

Change 3444882 on 2017/05/17 by Daniel.Wright

	Added comment to  FClearValueBinding::DefaultNormal8Bit to make the dependency on shader decode clear

Change 3444883 on 2017/05/17 by Brian.Karis

	Improved contact shadows

Change 3445048 on 2017/05/17 by Daniel.Wright

	Fixed particle lights in forward shading, they were not setting the lighting channel mask properly

Change 3445107 on 2017/05/17 by Michael.Trepka

	Changed the order of operations in FMetalStateCache::SetRenderState to work around an issue with some Intel drivers where they would not recalculate the raster state in some edge cases.

	#jira UE-43725

Change 3445212 on 2017/05/17 by Uriel.Doyon

	Added a -CSV option to ListTextures command

Change 3445947 on 2017/05/18 by Richard.Wallis

	Clone of Release-4.16 Stream CL 3437181 and CL 3442450 - fix(s) for black rendering on macOS El Cap with Nvidia GPU.  Move sampling of EyeAdaption texture to pixel shader for Mac Metal using shader language version <= 1 only.

Change 3446545 on 2017/05/18 by Chris.Bunner

	Removed hardcoded (and unused) MRT write from Decal shaders.

	#jira UE-45095

Change 3446568 on 2017/05/18 by Marc.Olano

	Sobol and image-based importance sampling C++ functions and blueprint nodes

Change 3446988 on 2017/05/18 by Marc.Olano

	Fix build error: missing include

Change 3446990 on 2017/05/18 by Marc.Olano

	Cell-indexed Sobol sampling for shaders (in MonteCarlo.usf) and materials (Sobol and TemporalSobol nodes)

Change 3447142 on 2017/05/18 by Rolando.Caloca

	DR - RWLock instead of mutex for PSO cache

Change 3447144 on 2017/05/18 by Uriel.Doyon

	Moved shading model code to SetGBufferFromShadingModel(). This allows the code to be reused in other shader files.

Change 3447794 on 2017/05/18 by Brian.Karis

	Virtual texturing foundation code

Change 3448944 on 2017/05/19 by Arciel.Rekman

	Fix non-unity Linux (and Mac, etc) builds.

	- Mac fix is tentative, did not try.

Change 3449183 on 2017/05/19 by Marcus.Wassmer

	Duplicate fix for reflection captures to happen after sequencer updates.

Change 3449196 on 2017/05/19 by Uriel.Doyon

	Handling RCM_MinMax when reading FloatRGBA textures.
	This fixes pixel inspector always reading 1 for scene color values greater than one.

Change 3451652 on 2017/05/22 by Rolando.Caloca

	DR - Compile fix

	#jira UE-45245

Change 3451660 on 2017/05/22 by Chris.Bunner

	Additional compile fix.

	#jira UE-45245

Change 3451897 on 2017/05/22 by Daniel.Wright

	Moved RTDF shadow project back after the base pass, since it samples the GBuffer for subsurface shadowing.  Removed r.DFShadowAsyncCompute which was relying on the previous ordering.

Change 3452055 on 2017/05/22 by Rolando.Caloca

	DR - Switch compile fix

	#jira UE-45265

Change 3452089 on 2017/05/22 by Rolando.Caloca

	DR - Compile fix

	#jira UE-45246

Change 3452108 on 2017/05/22 by Rolando.Caloca

	DR - Compile fix

	#jira UE-45246

Change 3452179 on 2017/05/22 by Brian.Karis

	Exposed dimensions. Fixed static analysis.

Change 3452734 on 2017/05/22 by Daniel.Wright

	When post processing is disabled, TPT_TranslucencyAfterDOF translucency gets forced into the standard translucency pass.

Change 3452770 on 2017/05/22 by Daniel.Wright

	Static light source shapes drawn into reflection captures handle SourceLength via scaled sphere

Change 3452861 on 2017/05/22 by Rolando.Caloca

	DR - Switch compile fix

Change 3452952 on 2017/05/22 by Brian.Karis

	Small VT fixes

Change 3453647 on 2017/05/23 by Richard.Wallis

	Fix for tessellation shaders on Mac (Metal v1.2) failing to compile.

	#jira UE-45227

Change 3454844 on 2017/05/23 by Uriel.Doyon

	Fixed extra X16 on some point lights
	#jira UE-45250

Change 3454934 on 2017/05/23 by Chris.Bunner

	Backing out changelists 3441680, 3454636 and 3454844 for the sake of integration stability.

Change 3457131 on 2017/05/24 by Arne.Schober

	DR - [UE-45317] - Fix Depthbuffer not available for resolve in Forward mode

	#jira UE-45317
	#RB Chris.Bunner

Change 3457141 on 2017/05/24 by Marc.Olano

	Sobol bug fixes

Change 3457953 on 2017/05/24 by Brian.Karis

	Fix static analysis

	#jira UE-45315
	#jira UE-45314
	#jira UE-45313

Change 3459064 on 2017/05/25 by Chris.Bunner

	Fix for out of bounds material translation crash.

	#jira UE-45406

Change 3459700 on 2017/05/25 by Brian.Karis

	Revert using sprite index buffer because the vert order is different.

Change 3459847 on 2017/05/25 by Chris.Bunner

	Fixing ensure in RenderTestMap.

[CL 3461201 by Chris Bunner in Main branch]
2017-05-26 08:22:50 -04:00

175 lines
5.2 KiB
C++

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "ShaderPreprocessor.h"
#include "Misc/FileHelper.h"
#include "Misc/Paths.h"
#include "Misc/ScopeLock.h"
#include "Modules/ModuleManager.h"
#include "PreprocessorPrivate.h"
IMPLEMENT_MODULE(FDefaultModuleImpl, ShaderPreprocessor);
/**
* Append defines to an MCPP command line.
* @param OutOptions - Upon return contains MCPP command line parameters as a string appended to the current string.
* @param Definitions - Definitions to add.
*/
static void AddMcppDefines(FString& OutOptions, const TMap<FString,FString>& Definitions)
{
for (TMap<FString,FString>::TConstIterator It(Definitions); It; ++It)
{
OutOptions += FString::Printf(TEXT(" -D%s=%s"), *(It.Key()), *(It.Value()));
}
}
/**
* Helper class used to load shader source files for MCPP.
*/
class FMcppFileLoader
{
public:
/** Initialization constructor. */
explicit FMcppFileLoader(const FShaderCompilerInput& InShaderInput)
: ShaderInput(InShaderInput)
{
// SourceFilename is expected to be relative to the engine shader folder
InputShaderFile = ShaderInput.SourceFilename;
// If there is no extension then we can end up with an extra version of this file
if (FPaths::GetExtension(InputShaderFile) != TEXT("usf"))
{
InputShaderFile += TEXT(".usf");
}
// Attempt to keep filename reference and map add logic the same as the file contents callback
FString Filename = GetRelativeShaderFilename(InputShaderFile);
FString InputShaderSource;
if (LoadShaderSourceFile(*Filename, InputShaderSource))
{
InputShaderSource = FString::Printf(TEXT("%s\n#line 1\n%s"), *ShaderInput.SourceFilePrefix, *InputShaderSource);
CachedFileContents.Add(Filename, StringToArray<ANSICHAR>(*InputShaderSource, InputShaderSource.Len()));
}
}
/** Returns the input shader filename to pass to MCPP. */
const FString& GetInputShaderFilename() const
{
return InputShaderFile;
}
/** Retrieves the MCPP file loader interface. */
file_loader GetMcppInterface()
{
file_loader Loader;
Loader.get_file_contents = GetFileContents;
Loader.user_data = (void*)this;
return Loader;
}
private:
/** Holder for shader contents (string + size). */
typedef TArray<ANSICHAR> FShaderContents;
/** MCPP callback for retrieving file contents. */
static int GetFileContents(void* InUserData, const ANSICHAR* InFilename, const ANSICHAR** OutContents, size_t* OutContentSize)
{
FMcppFileLoader* This = (FMcppFileLoader*)InUserData;
FString Filename = GetRelativeShaderFilename(ANSI_TO_TCHAR(InFilename));
FShaderContents* CachedContents = This->CachedFileContents.Find(Filename);
if (!CachedContents)
{
FString FileContents;
if (This->ShaderInput.Environment.IncludeFileNameToContentsMap.Contains(Filename))
{
FileContents = FString(UTF8_TO_TCHAR(This->ShaderInput.Environment.IncludeFileNameToContentsMap.FindRef(Filename).GetData()));
}
else
{
LoadShaderSourceFile(*Filename,FileContents);
}
if (FileContents.Len() > 0)
{
CachedContents = &This->CachedFileContents.Add(Filename,StringToArray<ANSICHAR>(*FileContents, FileContents.Len()));
}
}
if (OutContents)
{
*OutContents = CachedContents ? CachedContents->GetData() : NULL;
}
if (OutContentSize)
{
*OutContentSize = CachedContents ? CachedContents->Num() : 0;
}
return !!CachedContents;
}
/** Shader input data. */
const FShaderCompilerInput& ShaderInput;
/** File contents are cached as needed. */
TMap<FString,FShaderContents> CachedFileContents;
/** The input shader filename. */
FString InputShaderFile;
};
/**
* Preprocess a shader.
* @param OutPreprocessedShader - Upon return contains the preprocessed source code.
* @param ShaderOutput - ShaderOutput to which errors can be added.
* @param ShaderInput - The shader compiler input.
* @param AdditionalDefines - Additional defines with which to preprocess the shader.
* @returns true if the shader is preprocessed without error.
*/
bool PreprocessShader(
FString& OutPreprocessedShader,
FShaderCompilerOutput& ShaderOutput,
const FShaderCompilerInput& ShaderInput,
const FShaderCompilerDefinitions& AdditionalDefines
)
{
// Skip the cache system and directly load the file path (used for debugging)
if (ShaderInput.bSkipPreprocessedCache)
{
return FFileHelper::LoadFileToString(OutPreprocessedShader, *ShaderInput.SourceFilename);
}
FString McppOptions;
FString McppOutput, McppErrors;
ANSICHAR* McppOutAnsi = NULL;
ANSICHAR* McppErrAnsi = NULL;
bool bSuccess = false;
// MCPP is not threadsafe.
static FCriticalSection McppCriticalSection;
FScopeLock McppLock(&McppCriticalSection);
FMcppFileLoader FileLoader(ShaderInput);
AddMcppDefines(McppOptions, ShaderInput.Environment.GetDefinitions());
AddMcppDefines(McppOptions, AdditionalDefines.GetDefinitionMap());
int32 Result = mcpp_run(
TCHAR_TO_ANSI(*McppOptions),
TCHAR_TO_ANSI(*FileLoader.GetInputShaderFilename()),
&McppOutAnsi,
&McppErrAnsi,
FileLoader.GetMcppInterface()
);
McppOutput = McppOutAnsi;
McppErrors = McppErrAnsi;
if (ParseMcppErrors(ShaderOutput.Errors, McppErrors, true))
{
// exchange strings
FMemory::Memswap( &OutPreprocessedShader, &McppOutput, sizeof(FString) );
bSuccess = true;
}
return bSuccess;
}