Files
UnrealEngineUWP/Engine/Source/Developer/ShaderFormatVectorVM/Private/VectorVMBackend.cpp
Marcus Wassmer 5bb93c997e Copying //UE4/Dev-Rendering to //UE4/Dev-Main (Source: //UE4/Dev-Rendering @ 3249742)
#lockdown Nick.Penwarden
#rb none

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

Change 3232283 on 2016/12/13 by Ben.Woodhouse

	D3D12 - downgrade root signature size warning to a log following a discussion with Microsoft. There's not much we can actually do about it, and it's not relevant to all hardware
	#jira UE-36999

Change 3232641 on 2016/12/13 by Mark.Satterthwaite

	- Eliminate redundant state changes in MetalRHI in the state cache.
	- Add a new debug level for setting buffers to nil prior to calls to set*Bytes so that the tool doesn't display incorrect data.
	- Make testing for validation & statistics features use the same EMetalFeatures API as everything else for consistency.
	- Cache the fallback depth-stencil texture in the state cache and ignore it for determining whether a pass can restart - if we are using this texture its contents are worthless anyway.

Change 3232661 on 2016/12/13 by Mark.Satterthwaite

	Re-enable Metal SM5 & DFAO/DistanceFieldShadowing on Intel for 10.12.2 or later.

Change 3232759 on 2016/12/13 by Ben.Woodhouse

	Fix memory leak on XB1 when calling GPURealloc with count of 0, suggested on UDN
	https://udn.unrealengine.com/questions/326660/gpurealloc-leak.html

Change 3232803 on 2016/12/13 by Ben.Marsh

	Add UT to the populate DDC job, and cook UT and Fortnite for Mac as well.

Change 3232836 on 2016/12/13 by Ben.Marsh

	Split cooks to populate DDC into separate nodes for each platform. May help to reduce number of timeouts on remote VMs.

Change 3232974 on 2016/12/13 by Rolando.Caloca

	DR - Refactor common code to UWorld::RecreateScene
	#jira UE-36719
	PR #2824

Change 3232976 on 2016/12/13 by Ben.Marsh

	Add missing dependency on tools node for Mac cooks. Need to compile SCW first.

Change 3233289 on 2016/12/13 by Olaf.Piesche

	Fixing potentially broken spot/point light fade with old content; initialize new properties properly

Change 3233811 on 2016/12/13 by Mark.Satterthwaite

	Fix compiling QA-Material tessellation shaders that don't need to emit from Hull or sample in Domain the HSOut buffer which was confusing MetalBackend.

Change 3233854 on 2016/12/13 by Mark.Satterthwaite

	More information about texture type validation errors in Metal.

Change 3234650 on 2016/12/14 by Rolando.Caloca

	DR - vk - Fix bad aspect on depth cubemaps

Change 3234651 on 2016/12/14 by Rolando.Caloca

	DR - vk - Fix for 32 bit crash on dump layer

Change 3234813 on 2016/12/14 by Guillaume.Abadie

	Fixes texture mask static lighting when using GBuffer selective outputs.

	#jira UE-39527

Change 3235047 on 2016/12/14 by Uriel.Doyon

	Refactored HLOD texture streaming strategy to separate forced load from visibility.
	Added an incremental update in the last stage of the texture streaming update load to clear any pending work.
	Added an option "All" to the "BuildMateriaTexturelStreamingData" command to force rebuild everything.

Change 3235317 on 2016/12/14 by Uriel.Doyon

	Removed timed primitives in the texture streaming since it was not used and there is now a fallback implementation in UPrimitiveComponent::GetStreamingTextureInfo.

Change 3235431 on 2016/12/14 by Rolando.Caloca

	DR - Fix for Vulkan drawing black

Change 3236788 on 2016/12/15 by Mark.Satterthwaite

	Fix 10.11.6 support (aka -nometalv2): the stencil view workaround necessitates a mid-render blit and the way things were setup resulted in the HasValidRenderTargets assert firing. Refactored the code to separate the concept or valid render-states in the cache from active render-states in the render-pass. Now it works as intended and will be needed for 4.15.

Change 3236850 on 2016/12/15 by Mark.Satterthwaite

	Make changing the Metal Shader Version project setting prompt the user to restart for the changes to take effect.
	#jira UE-39801

Change 3237002 on 2016/12/15 by Benjamin.Hyder

	submitting updated TM-Shadermodels map

Change 3237312 on 2016/12/15 by Rolando.Caloca

	DR - Change more macros to lambdas

Change 3237394 on 2016/12/15 by Mark.Satterthwaite

	Add Metal-specific permutations of TBasePassHS - they affect the C++ definition on all platforms but are only cached or used on Metal - because the way we compile the combined VS+HS tessellation stage requires that the combined VS + HS HLSL code references the same resources, otherwise we get incorrect resouce bindings and subsequently fail to render properly. Long-term the Metal tessellation code will need to be refactored so that the vertex shader stage is emitted as a separate shader from the hull shader stage as this but will keep cropping back up and continue to complicate the engine.
	#jira UE-39799

Change 3237490 on 2016/12/15 by Daniel.Wright

	Fixed ULandscapeComponent::GetUsedMaterials

Change 3237597 on 2016/12/15 by Ben.Woodhouse

	Disable timestamp queries on pre-Maxwell nvidia hardware. Local testing suggests that this is the major cause of instability in the UE4.14 release.

	It's possible that we could be more targeted by only excluding Fermi and older hardware, but identifying fermi hardware by device ID is difficult in practice, since the range overlaps with Kepler.

Change 3237654 on 2016/12/15 by Daniel.Wright

	Non-editor compile fix

Change 3238229 on 2016/12/16 by Rolando.Caloca

	DR - Remove ExcludeRect from inner RHI Clear methods; ensure will happen if trying to use it

Change 3238236 on 2016/12/16 by Rolando.Caloca

	DR - Compile fixes

Change 3238280 on 2016/12/16 by Marc.Olano

	Small optimization to Lanczos-3 upsample shader code.

Change 3238321 on 2016/12/16 by Rolando.Caloca

	DR - Compile fix

Change 3238331 on 2016/12/16 by Rolando.Caloca

	DR - compile fix

Change 3238495 on 2016/12/16 by Marc.Olano

	Replace TEA random number generator with PCG.

	Was only used in #if-disabled reference rendering, but ldoes make better quality reference rendering when enabled.

Change 3238496 on 2016/12/16 by Marc.Olano

	Tone mapping fix for OR-31752, cherry picked from Orion 3208273

	Assumption that green is approximates luminance fails on red/blue HDR content, resulting in ugly black artifacts. Go back to luminance.

Change 3238520 on 2016/12/16 by Rolando.Caloca

	DR - CIS Fix

Change 3238571 on 2016/12/16 by Rolando.Caloca

	DR - CIS fix

Change 3238605 on 2016/12/16 by Daniel.Wright

	Sharing IndirectLightingCacheTextureSampler samplers

Change 3238626 on 2016/12/16 by Daniel.Wright

	Ray Traced Distance Field Shadow optimizations
	* Tighter light space tile culling
	* Skip ray marching pixels before the RTDF cascade near distance, or further than the cascade far distance
	* Depth bounds test on upsample
	* Created FLightTileIntersectionParameters for encapsulation of light tile culling functionality
	* RTDF shadow time went from 1.8ms -> .8ms and 3.1ms -> 1.2ms in FortGPUTestbed on 7870 with these changes

Change 3238652 on 2016/12/16 by Rolando.Caloca

	DR - RHI clear methods no longer have an ExcludeRect, use DrawClearQuad functions instead

Change 3238855 on 2016/12/16 by Rolando.Caloca

	DR - Added FRHITexture2D GetSizeXY

Change 3238881 on 2016/12/16 by Rolando.Caloca

	DR - CIS fix

Change 3239008 on 2016/12/16 by Arne.Schober

	DR - Fixing accidently returning a stackpointer in EnqueueRenderCommands

Change 3239012 on 2016/12/16 by Arne.Schober

	DR - missing file

Change 3239255 on 2016/12/17 by Rolando.Caloca

	DR - Remove shader clears from D3D11

Change 3239690 on 2016/12/19 by Rolando.Caloca

	DR - vk - Misc fixes from 1.0.37.00 SDK warnings

Change 3239964 on 2016/12/19 by Rolando.Caloca

	DR - Fix click on editor not showing selected

Change 3239995 on 2016/12/19 by Rolando.Caloca

	DR - Enable dist field on GL4 & Vulkan SM5

Change 3240162 on 2016/12/19 by Daniel.Wright

	Added EnableDepthBoundsTest / DisableDepthBoundsTest to RHIUtilites to share some common code

Change 3240163 on 2016/12/19 by Daniel.Wright

	Distance field self shadowing controls for hiding world position offset self-shadow artifacts
	* Removed static mesh build settings DistanceFieldBias, which shrunk the distance field, breaking AO and shadows
	* Added DistanceFieldSelfShadowBias, which prevents occlusion close to the surface only, maintaining shadows on the ground and AO on the ground

Change 3240271 on 2016/12/19 by Daniel.Wright

	Use 16 bit indices for distance field objects culled to tiles, when 16 bit will be enough.  Saves 10mb of tile culling buffers.

Change 3240282 on 2016/12/19 by Rolando.Caloca

	DR - Proper fix for hit proxies clear
	- Added missing stencil ref to DrawClearQuad

Change 3240316 on 2016/12/19 by Rolando.Caloca

	DR - vk - Fixed some new 1.0.37.0 warnings

Change 3240354 on 2016/12/19 by Rolando.Caloca

	DR - Dev shaders on sm4/5

Change 3240759 on 2016/12/20 by Rolando.Caloca

	DR - Fix bad crc on GL element declarations

Change 3240895 on 2016/12/20 by Rolando.Caloca

	DR - vk - Swapchain fixes

Change 3241057 on 2016/12/20 by Rolando.Caloca

	DR - vk - Fix resize on desktop

Change 3241112 on 2016/12/20 by Rolando.Caloca

	DR - vk - Fix 1.0.37.0 warnings
	- Ignore some warnings we know we can't fix

Change 3241310 on 2016/12/20 by Rolando.Caloca

	DR - vk - Fix crash

Change 3241417 on 2016/12/20 by Daniel.Wright

	[Copy] Fixed race condition with FPrecomputedLightVolume::Data which was exposed when switching lighting scenarios

Change 3241990 on 2016/12/21 by Daniel.Wright

	Converted DistanceFieldVolume data to BulkData
	* FDistanceFieldVolumeData Serialize time from .7s on PS4 to 0s

Change 3242005 on 2016/12/21 by Daniel.Wright

	Removed unused !USE_DEPTH_RANGE_LISTS path to reduce complexity

Change 3242295 on 2016/12/21 by Bob.Tellez

	Duplicating CL#3242294 from //Fortnite/Main

	#UE4 Re-applying the fix for rendering editor primitives when r.EarlyZPassOnlyMaterialMasking is enabled

Change 3242487 on 2016/12/21 by Marcus.Wassmer

	Fix typo

Change 3243091 on 2016/12/22 by Daniel.Wright

	Fixed too many groups dispatched for TConeTraceScreenGridGlobalOcclusionCS

Change 3243161 on 2016/12/22 by Uriel.Doyon

	New async tasks for the streaming update. Optimizing the biggest frame cost.

Change 3243179 on 2016/12/22 by Uriel.Doyon

	Fixed possible invalid access from the async FNormalizeLightmapTexelFactorTask

Change 3243236 on 2016/12/22 by Daniel.Wright

	Fixed DFAO bilateral upsample
	* Depth buffer was being unbound due to lack of DepthRead_StencilNop

Change 3243452 on 2016/12/23 by Ben.Woodhouse

	Bring back 1024 render query limit workaround on D3D12 which was lost during the merge from partners
	#jira UE-35247

Change 3243512 on 2016/12/23 by Uriel.Doyon

	Improved task system for texture streaming.

Change 3243742 on 2016/12/26 by Rolando.Caloca

	DR - vk - Fix UAV clears
	- Removed old validation layer
	- Print found device layers

Change 3243745 on 2016/12/27 by Rolando.Caloca

	DR - vk - Fix for texture cube arrays
	- Warning for ClearUAVs

Change 3243762 on 2016/12/27 by Rolando.Caloca

	DR - vk - Always use pipeline cache

Change 3244450 on 2016/12/31 by Rolando.Caloca

	DR - vk - Pre reqs for separate transfer queue

Change 3244453 on 2016/12/31 by Rolando.Caloca

	DR - vk - Win32 compile fix

Change 3244756 on 2017/01/03 by Marcus.Wassmer

	Copying //Tasks/UE4/Dev-Niagara@3244743 to Dev-Rendering (//UE4/Dev-Rendering)

Change 3244757 on 2017/01/03 by Marcus.Wassmer

	Niagara is still experimental in non-task branches.

Change 3245059 on 2017/01/03 by Benjamin.Hyder

	Submitting TM-TrigNodes map

Change 3245500 on 2017/01/03 by Olaf.Piesche

	Compile fix #1 for post-merge problems

Change 3245572 on 2017/01/03 by Olaf.Piesche

	(Speculative) fix #2 for post-merge build problem. Hopefully fixes public distribution level error for cross compiler tool.

Change 3245683 on 2017/01/03 by Marcus.Wassmer

	Fix some niagara warnings

Change 3245732 on 2017/01/03 by Marcus.Wassmer

	Fix Niagara compile on clang platforms.
	Fix a few warnings / static analysis things as well.

Change 3246403 on 2017/01/04 by Rolando.Caloca

	DR - vk - Fix bogus warning

Change 3246432 on 2017/01/04 by Marcus.Wassmer

	Copying //Tasks/UE4/Dev-Niagara@3246424 to Dev-Rendering (//UE4/Dev-Rendering)

Change 3246538 on 2017/01/04 by Rolando.Caloca

	DR - vk - Show hitch time for compute psos

Change 3246580 on 2017/01/04 by Rolando.Caloca

	DR - vk - compile fix

Change 3246610 on 2017/01/04 by Rolando.Caloca

	DR - Compute PSO pre reqs

Change 3246707 on 2017/01/04 by Marcus.Wassmer

	Add missing integer operations to UnrealMathDirectX.h

Change 3246786 on 2017/01/04 by Marcus.Wassmer

	Avoid public dependency build errors.  Should probably just remove the DDCUtils module instead

Change 3246828 on 2017/01/04 by Olaf.Piesche

	UE-39249; need to check the view as well as the view family in CheckAndUpdateLastFrame; scene captures use a different family, but each eye for VR uses a different scene view.

Change 3247026 on 2017/01/04 by Rolando.Caloca

	DR - Remove CrossCompilerTool as it's not required anymore

Change 3247086 on 2017/01/04 by Marcus.Wassmer

	Remove includes for Core.h monolithic header

Change 3247227 on 2017/01/04 by Marcus.Wassmer

	Fix typo and compile errors.

Change 3247228 on 2017/01/04 by Marcus.Wassmer

	Use crossplatform intrinsics

Change 3247229 on 2017/01/04 by Marcus.Wassmer

	Implement missing integer NEON operations.
	Change NEON vectorint to match name and sign from other platforms

Change 3247245 on 2017/01/04 by Marcus.Wassmer

	Fixing various warnings/errors from clang platforms (Mac/Linux)

Change 3247331 on 2017/01/04 by Marcus.Wassmer

	More Mac/clang fixes

Change 3247958 on 2017/01/05 by Marcus.Wassmer

	VectorInt < - > Float ops should be conversions not reinterpret cast

Change 3247959 on 2017/01/05 by Marcus.Wassmer

	Add missing ops to non-vector header

Change 3247964 on 2017/01/05 by Rolando.Caloca

	DR - Temp fix for crash
	#jira UE-40211

Change 3248067 on 2017/01/05 by Rolando.Caloca

	DR - Static analysis fixes
	#jira UE-40167

Change 3248284 on 2017/01/05 by Rolando.Caloca

	DR - Linuix Compile fix
	#jira UE-40260

Change 3248288 on 2017/01/05 by Rolando.Caloca

	DR - Linux compile fix
	#jira UE-40264

Change 3248399 on 2017/01/05 by Brian.Karis

	Filtered importance sampling for envmap prefiltering.

	Fixed SSR on clearcoat with skylight only.

Change 3248503 on 2017/01/05 by Rolando.Caloca

	DR - Linux fixes
	#jira UE-40264

Change 3248666 on 2017/01/05 by Brian.Karis

	Fix GL compile error

Change 3248740 on 2017/01/05 by Marcus.Wassmer

	Fix linux and clang errors/warnings

Change 3248851 on 2017/01/05 by Marcus.Wassmer

	Simplest fix for ES2 compile errors

Change 3249217 on 2017/01/06 by Simon.Tovey

	Speculative fix for static analysis warning

Change 3249296 on 2017/01/06 by Ben.Woodhouse

	XB1/Fast semantics:
	Add missing L1/L2 cache flush on transition to readable (or RW). The missing cache flush was causing indeterminism when reading from a texture shortly after writing to it as a render target.
	This fixes bloom and diffuse irradiance issues
	The bug has been there for a while, but CL 3227787 (drawclear early out) caused it to manifest
	#jira UE-39727
	#jira UE-40238

Change 3249300 on 2017/01/06 by Ben.Woodhouse

	Remove workaround for diffuse irradiance (redundant clear). No longer necessary with CL 3249296

Change 3249387 on 2017/01/06 by Rolando.Caloca

	DR - Fix GL clear issues
	#jira UE-40254

Change 3249435 on 2017/01/06 by Ben.Woodhouse

	Duplicated from UT CL 3238664
	Fix dbuffer decal rendering issues in fullscreen on PC. Also fixes crash in editor when viewing dbuffer materials.
	Pass clearcolor in RT params for system textures to workaround a bug with ClearColorTexture not working in fullscreen mode on DX11. Make sure dbuffer targets are bound if we're rendering mesh decals
	#jira UT-6891
	#jira UE-39842

Change 3249721 on 2017/01/06 by Marcus.Wassmer

	Remove final references to non-existent Niagara data

Change 3249742 on 2017/01/06 by Marcus.Wassmer

	Fix missing GPU particles on Mac.
	Pointers getting reused is causing the blendstate equality operator to fail.
	Simple workaround until we have time for a proper fix.

[CL 3249983 by Marcus Wassmer in Main branch]
2017-01-06 17:51:46 -05:00

142 lines
4.7 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "VectorVMBackend.h"
#include "ShaderFormatVectorVM.h"
#include "hlslcc.h"
#include "hlslcc_private.h"
#include "compiler.h"
PRAGMA_DISABLE_SHADOW_VARIABLE_WARNINGS
#include "glsl_parser_extras.h"
PRAGMA_POP
#include "hash_table.h"
#include "ir_rvalue_visitor.h"
#include "PackUniformBuffers.h"
#include "IRDump.h"
#include "OptValueNumbering.h"
#include "ir_optimization.h"
#include "ir_expression_flattening.h"
#include "ir.h"
#include "VectorVM.h"
#include "INiagaraCompiler.h"
#if !PLATFORM_WINDOWS
#define _strdup strdup
#endif
DEFINE_LOG_CATEGORY(LogVVMBackend);
bool FVectorVMCodeBackend::GenerateMain(EHlslShaderFrequency Frequency, const char* EntryPoint, exec_list* Instructions, _mesa_glsl_parse_state* ParseState)
{
//vm_debug_dump(Instructions, ParseState);
ir_function_signature* MainSig = NULL;
int NumFunctions = 0;
foreach_iter(exec_list_iterator, iter, *Instructions)
{
ir_instruction *ir = (ir_instruction *)iter.get();
ir_function* Function = ir->as_function();
if (Function)
{
if (strcmp(Function->name, "SimulateMain") == 0)
{
foreach_iter(exec_list_iterator, sigiter, *Function)
{
ir_function_signature* Sig = (ir_function_signature *)sigiter.get();
Sig->is_main = true;
}
}
}
}
//vm_debug_dump(Instructions, ParseState);
return true;
}
char* FVectorVMCodeBackend::GenerateCode(exec_list* ir, _mesa_glsl_parse_state* state, EHlslShaderFrequency Frequency)
{
vm_debug_print("========VECTOR VM BACKEND: Generate Code==============\n");
vm_debug_dump(ir, state);
if (state->error) return nullptr;
//Inline all functions.
vm_debug_print("== Initial misc ==\n");
bool progress = false;
do
{
//progress = do_function_inlining(ir);//Full optimization pass earlier will have already done this.
progress = do_mat_op_to_vec(ir);
progress = do_vec_op_to_scalar(ir) || progress;
progress = do_vec_index_to_swizzle(ir) || progress;
progress = do_copy_propagation(ir) || progress;
progress = do_copy_propagation_elements(ir) || progress;
} while (progress);
vm_debug_dump(ir, state);
if (state->error) return nullptr;
vm_debug_print("== Branches to selects ==\n");
vm_flatten_branches_to_selects(ir, state);
vm_debug_dump(ir, state);
vm_debug_print("== To Single Op ==\n");
vm_to_single_op(ir, state);
vm_debug_dump(ir, state);
if (state->error) return nullptr;
vm_debug_print("== Scalarize ==\n");
vm_scalarize_ops(ir, state);
vm_debug_dump(ir, state);
if (state->error) return nullptr;
vm_debug_print("== Merge Ops ==\n");
vm_merge_ops(ir, state);
vm_debug_dump(ir, state);
if (state->error) return nullptr;
vm_debug_print("== Propagate non-expressions ==\n");
vm_propagate_non_expressions_visitor(ir, state);
vm_debug_dump(ir, state);
if (state->error) return nullptr;
vm_debug_print("== Cleanup ==\n");
// Final cleanup
progress = false;
do
{
progress = do_dead_code(ir, false);
progress = do_dead_code_local(ir) || progress;
progress = do_swizzle_swizzle(ir) || progress;
progress = do_noop_swizzle(ir) || progress;
progress = do_copy_propagation(ir) || progress;
progress = do_copy_propagation_elements(ir) || progress;
progress = do_constant_propagation(ir) || progress;
} while (progress);
vm_debug_dump(ir, state);
if (state->error) return nullptr;
vm_gen_bytecode(ir, state, CompilationOutput);
return nullptr;// Cheat and emit the bytecode into he CompilationOutput. The return here is treat as a string so the 0's it contains prove problematic.
}
void FVectorVMLanguageSpec::SetupLanguageIntrinsics(_mesa_glsl_parse_state* State, exec_list* ir)
{
// //TODO: Need to add a way of stopping these being stripped if they're not used in the code.
// //We fine if the func is unused entirely but we need to keep the scalar signatures for when we scalarize the call.
// //Maybe we can just keep the wrong sig but still replace the ret val and params?
// make_intrinsic_genType(ir, State, "mad", ir_invalid_opcode, IR_INTRINSIC_FLOAT, 3, 1, 4);
make_intrinsic_genType(ir, State, "rand", ir_invalid_opcode, IR_INTRINSIC_FLOAT, 1, 1, 4);
make_intrinsic_genType(ir, State, "Modulo", ir_invalid_opcode, IR_INTRINSIC_FLOAT, 1, 1, 4);
// Dont need all these as we're only using the basic scalar function which we provide the signature for in the usf.
// make_intrinsic_genType(ir, State, "InputDataFloat", ir_invalid_opcode, IR_INTRINSIC_FLOAT, 2, 1, 1);
// make_intrinsic_genType(ir, State, "InputDataInt", ir_invalid_opcode, IR_INTRINSIC_INT, 2, 1, 1);
// make_intrinsic_genType(ir, State, "OutputDataFloat", ir_invalid_opcode, 0, 3, 1, 1);
// make_intrinsic_genType(ir, State, "OutputDataInt", ir_invalid_opcode, 0, 3, 1, 1);
// make_intrinsic_genType(ir, State, "AcquireIndex", ir_invalid_opcode, IR_INTRINSIC_INT, 2, 1, 1);
}