Files
UnrealEngineUWP/Engine/Source/Developer/ShaderFormatVectorVM/Private/VectorVMShaderCompiler.cpp
shaun kime c39e5304a8 #ROBOMERGE-AUTHOR: shaun.kime
Catching up 4.20 to Dev-Niagara as of CL 4111104
#rb none
#tests PC and PS4 auto-tests pass

Change 4075849 by Wyeth.Johnson

	Metadata on location and velocity modules, new DI

Change 4076028 by Frank.Fella

	Niagara - Fix an issue where the list of relevant scripts in the shared script view model could get out of sync when changing properties on an emitter such as interpolated spawning and gpu simulation.  This could result in an emitter recompiling forever if it started as GPU and was then switched to CPU and then a force compile was requested since it would include the GPU script when determing the compile status, but it would never compile it.

	#jira UE-59220

Change 4076925 by Frank.Fella

	Niagara - Adding and removing pins from an assignment node wasn't correctly invalidating the graph which I broke with my crash fix 4058428 since I thought the refresh call would do that.

	#jira UE-59249

Change 4076971 by Frank.Fella

	Niagara - Made few changes to stack issue handling while fixing an issue where the stack error wouldn't change when the compile error changed.
	+ Changed the unique identifier for stack issues to be automatically generated from a hash of the combined stack editor data key and the long description of the error.
	+ Changed the stack issue unique identifier from an FName to an FString to avoid poluting the name table with lots of generated hash strings.
	+ Encapsulated all of the stack issue data to validate the required inputs.

	#jira UE-59251

Change 4076974 by Frank.Fella

	Niagara - Minor change missed in last checkin.

Change 4076990 by Frank.Fella

	Niagara - Fix the assignment node so that it uses a "Begin Defaults" node instead of a regular input node when it's hooking up linked defaults.

	#jira UE-59224

Change 4077392 by jonathan.lindquist

	Changing pin order

Change 4077426 by Wyeth.Johnson

	transform position DI

Change 4077636 by Frank.Fella

	Niagara - Fix an issue where the stack function input collection wasn't generating errors correctly due to data being cached between refreshes which became stale.

	#jira UE-59269

Change 4078004 by jonathan.lindquist

	Submitting progress on a module

Change 4078009 by jonathan.lindquist

	changing a variable name in rotate around point

Change 4078043 by Frank.Fella

	Niagara - Fix the stack function input so that it cleans up properly when removing pins from assignment nodes, also fix undo for the remove operation.

	#jira UE-59271

Change 4078063 by Shaun.Kime

	Fixing debug particle data texture usage

	#tests n/a

Change 4079110 by jonathan.lindquist

	Submitting a cone mask function

Change 4079161 by jonathan.lindquist

	Adding a new cone mask module

Change 4079164 by jonathan.lindquist

	Adding a description to the cone mask function

Change 4079166 by jonathan.lindquist

	Submitting a new cone mask dynamic input

Change 4079988 by Yannick.Lange

	Set persistend guid for if node input pins on creating a new output pin.

Change 4080531 by jonathan.lindquist

	New cone based mask for curl noise contributions. Additional meta data descriptions for other inputs.

Change 4080541 by jonathan.lindquist

	Exposing the cone axis variable

Change 4080544 by jonathan.lindquist

	One more meta data tweak :D

Change 4081107 by Shaun.Kime

	Fixing underlying GPU collision system after Rendering refactored to use the FSceneTexturesUniformParameters instead of individual textures. Note that GPU collision only works with the primary back buffer. We will need more work to support split-screen or PIP.

	#tests Collsion test GPU now is functional, but we still get a few nondeterministic strays in different directions keeping me from turning it on at the moment

Change 4081111 by Shaun.Kime

	Updating the compile GUID because the previous change adjusted generated code

	#tests n/a

Change 4081231 by Shaun.Kime

	Allowing several descriptions to be multiline, accessible by Shift + Enter.

	#tests created descriptions for both module fields and modules themselves that were multi-line. confirmed UI was correct.

Change 4081552 by Jonathan.Lindquist

	Additional tooltips/documentation

Change 4081566 by Jonathan.Lindquist

	Changing split linear color's pin order

Change 4081646 by Shaun.Kime

	Added tooltips to the parameter map get and set nodes that should grealy improve understanding.

	#tests n/a

Change 4082769 by Yannick.Lange

	Pins and parameters unique name on creation

Change 4082792 by Yannick.Lange

	Fix: Adding a property pin to a Niagara Module Script map node creates a duplicate of that property in the Properties menu

	#jira UE-58823

Change 4082851 by jonathan.lindquist

	Ensuring that the latest version of this content is available for Simon

Change 4082875 by Yannick.Lange

	Parameter, source and dest pins of a parameter map node have a subcategories. Only pins with the parameter subcategory will be found by the graph.

	#jira UE-57692

Change 4083076 by Wyeth.Johnson

	Gnomon asset for example content

Change 4083783 by Frank.Fella

	Niagara - Fix issues with drag/drop
	+ Don't allow the user to drop a module if the usage flags of the target script aren't supported.
	+ Allow dragging to different scripts event if they are in different graphs, or different emitters.
	+ Transfer rapid iteration paramters correctly when moving modules between scripts.
	+ Fix undo for rapid iteration paramters when undoing a move.

	#jira UE-59340
	#jira UE-59401

Change 4083999 by Bradut.Palas

	Improved functionality of module dependencies: intercategory module dependencies now work, module order is fixed.

	#tests none
	#jira UE-58200

Change 4084002 by Shaun.Kime

	Validating modules reads and writes.
	You cannot read/write from particles namespace in system and emitter scripts
	You cannot write to user or NPC namespaces ever
	You cannot write to system/emitter namespaces in particle scripts

	#tests auto-tests pass

Change 4084419 by jonathan.lindquist

	Changing default texture assignments to work with the new project directory.

Change 4084595 by jonathan.lindquist

	Submitting a new material that will generate a 3d sphere on a sprite using world position offset and pixel depth offset.

Change 4084603 by Jonathan.Lindquist

	New thumbnail

Change 4084607 by jonathan.lindquist

	Submitting final variable settings for the skeletal mesh reproduction particle system

Change 4084649 by jonathan.lindquist

	Finalizing sampling mesh code after exploring multiple approaches.

Change 4084746 by Frank.Fella

	Niagara - When creating the render state in the niagara component, also send the dynamic data the same frame since the emitter might not actually tick the next frame.

	#jira UE-57696

	#tests engine tests.

Change 4085536 by Yannick.Lange

	Fix assert attempting to add a Niagara emitter parameter to a system before tracking an emitter.
	Also passes all graphs to the add button, to avoid any use of Graphs[0] in SNiagaraParameterMapView.

	#jira UE-58832

Change 4085757 by Yannick.Lange

	Prevent circular connections when trying to connect pins

	#jira UE-55541

Change 4086086 by Bradut.Palas

	Fixing static code analysis issues by moving the RefreshIssues call inside the FunctionCallNode nullcheck

	#tests none

Change 4086155 by jonathan.lindquist

	Updating meta data etc.

Change 4086965 by Olaf.Piesche

	Fixing uniform buffer alignment and padding to 16 bytes for all vector types; bumping vec2 and vec3 uniforms to vec4, and adding component mask to code chunk for accesses to uniform chunks according to their initial type
	OpenGL requires this since because adherence to the std140 memory layout is shaky at best when it comes to sub-16-byte vector types

Change 4086968 by Olaf.Piesche

	Making division by 0xFFFFFFFF explicitly unsigned, because OpenGL otherwise assumes it's a signed int, just dividing by -1

Change 4086975 by Frank.Fella

	Niagara - Renderer update fixes.
	+ Trigger data object changed when adding, removing, and changing the enabled state of renderers so that the simulation updates.
	+ Fix undo for changing the enabled state on renderers.

	#jira UE-57696
	#jira UE-59390

Change 4087008 by Frank.Fella

	Niagara - When refreshing the sequencer tracks in the emitter/system editor don't set sequencer the time to 0.  This fixes an issue where modifying data in the timeline and undo would reset the time to 0 when paused rather than resimulating.

	#jira UE-59463

Change 4087030 by Shaun.Kime

	Fixing when you can create certain pin types to prevent invalid types from appearing in the list.

	#tests autotests pass on PC

Change 4087271 by jonathan.lindquist

	Adding an option to clamp particles.velocity's magnitude.

Change 4087279 by Wyeth.Johnson

	Comments and dependencies

Change 4087333 by Wyeth.Johnson

	Bitmask useage flags on forces to adhere to standards, plus dependencies

Change 4087636 by Wyeth.Johnson

	Age related dependencies on update modules

Change 4087702 by Shaun.Kime

	Getting translation set up for Frank's rapid iteration parameter rework in support for default dynamic inputs

	#tests n/a

Change 4087992 by jonathan.lindquist

	Adding a limit force module

Change 4088872 by Yannick.Lange

	Fix renaming variables will not work if the user is only changing capitalization.
	#jira UE-59119

Change 4088891 by Yannick.Lange

	Fix adding a new attribute makes it hidden in the attribute spreadsheet. Now shows the added attribute when doing a new capture.
	#jira UE-57167

Change 4089072 by Yannick.Lange

	Reorder parameter list categories

Change 4089164 by jonathan.lindquist

	Adding a velocity clamp feature and an acceleration clamp

Change 4089953 by Bradut.Palas

	Disabled modules no longer display errors.
	Also, enabling/disabling modules is now registered with the Undo system
	Also fixed the GUID generation for all issues, now issues are properly differentiated from each other on refresh.

	#tests none

Change 4090194 by Shaun.Kime

	Fixing auto tests after acceleration force defaulted to world instead of local

	#tests all pass

Change 4090195 by Shaun.Kime

	Cleaning up UI for code view

	#tests n/a

Change 4090198 by jonathan.lindquist

	Setting the fallback vector to 0,0,0

Change 4090430 by jonathan.lindquist

	Removing a reciprocal operation from the node. Now we use a single divide. Also, I added another length calculation to provide the proper length of the input fallback vector. This is important for cases in which the user specifies that the fallback vector should be 0,0,0 or another unnormalized value. Previously, the fallback vector length always returned 1.

Change 4090512 by Shaun.Kime

	Fix for crash during Jonathan's deletion of the Set node in SolveForcesInVelocity.

	#tests n/a

Change 4090534 by jonathan.lindquist

	New acceleration limit

Change 4090676 by Olaf.Piesche

	GPU Spawning auto test

Change 4090770 by Shaun.Kime

	Curl noise bug test case

Change 4090796 by Olaf.Piesche

	Added missing abs for GPU sim

Change 4091368 by Bradut.Palas

	Also removing issues from disabled input collections and renderer items

	#tests none

Change 4091417 by Simon.Tovey

	Making emitter local space a constant embeded directly into emitter and particle scripts.
	Allows a lot of optimization and exposes the value to emitter scripts properly.

Change 4091727 by jonathan.lindquist

	Exposing delta time as an advanced input and organizing the graph

Change 4091788 by Bradut.Palas

	#jira UE-54678 fIxing issues with refresh of skeletal mesh details
	#tests none

Change 4092040 by Frank.Fella

	Niagara - Fix some issues with modify, transactions, and change ids which was causing assets to be dirty or modified on load, or were allowing internal operation to be undone.
	+ Move some transactions from public utility functions into private functions called by menu items in the UNiagaraNodeWithDynamicPins.
	+ Prevent a few modify calls in UNiagaraEmitter from marking the package dirty since they're sometimes called as a result of compiling and in the other cases earlier modifies would have already marked the package dirty.
	+ In the system view model, don't create transactions when adding an emitter if the system view model is in emitter asset mode since the user should be able to undo it.
	+ In the system toolkit when opening an emitter asset initialize, clean up, and propagate the rapid iteration parameters before copying the emitter to prevent the change ids from getting out of sync after the compile completes.
	+ In the system toolkit when trying to see if an emitter has changed using the change ids, use the last synced id from the copied emitter instead of the original emitter since duplicating the emitter can change the id, and there's not way to set it externally.

	#jira UE-59517
	#jira UE-59566

Change 4092700 by jonathan.lindquist

	Removed param groups. We're now using inline bools to enable or disable limits on velocity and acceleration

Change 4093032 by Shaun.Kime

	Fixing display of errors

	#tests now errors in compilation properly display

Change 4093172 by Shaun.Kime

	Curl noise cpu/gpu test map

	#tests added last known good

Change 4094156 by Damien.Pernuit

	Fixed crash in the editor when opening a Niagara Emitter/Script containing outdated script functions.
	Fixed incorrect type cast, FNiagaraFloat instead of FNiagaraInt32.

Change 4094515 by Tim.Gautier

	Enabled Niagara + Niagara Extras in QAGame

Change 4094674 by jonathan.lindquist

	submitting an example of variable defaults not working as intended

Change 4094712 by Damien.Pernuit

	Niagara - Houdini:

	Houdini Niagara Data Interface:
	- Removed the GetCSVFloatValueByString function as String aren't currently supported by Niagara.
	- Particles in the CSV file can now be updated over time (not just spawned)
	- Added GetParticlePositionAtTime, GetParticleValueAtTime, GetParticleVectorValueAtTime returning a linearly interpolated value for a given particle at a given time.
	- Added GetParticleIndexesAtTime for getting the previous/next row indexes and weight to access the values for a given particle at a given time and handle the interpolation of the values.
	- Added GetCSVVectorValue for accessing a Vector value at a given row/col.

	Houdini CSV Assets now looks for the following attributes in the CSV "Title" line:
	- pos for position.
	- id and # for particle ID.
	- alive and life for calculating a particles LifeTime.

Change 4094932 by Frank.Fella

	Niagara - Fix a few more issues where asset editors would open with their assets modified.
	+ Fix rapid iteration parameter preparation so that it doesn't modify the parameter store if it doesn't change after syncing with the graphs and propagating from dependencies.  This fixes the emitter editor allowing changes to be applied on open.
	+ Refactor the change notification for the script tool kit so that it uses the graph change and property change messages to determine if any changes have been made and can be applied.

	#jira UE-59517
	#tests auto tests

Change 4094978 by Damien.Pernuit

	Niagara - Houdini:

	Houdini Niagara Data Interface:
	- Since we can now update particles over time, renamed/modified most of the functions to make a clear distinction between row indexes (row) and particle ids (N)
	- Replaced GetNumberOfPointsInCSV by GetNumberOfRowsInCSV and GetNumberOfParticlesInCSV
	- Renamed GetParticleIndexesAtTime to GetRowIndexesForParticleAtTime and GetLastParticleIndexAtTime to GetLastRowIndexAtTime
	- Fixed some DI Functions that were using floats for input parameter instead of using integers.

Change 4095428 by Damien.Pernuit

	Niagara - Houdini:

	Houdini Niagara Data Interface:
	Fixed incorrect behavior of the GetLastRowIndexAtTime and GetParticleIndexesToSpawnAtTime functions due to supporting particle update over time.

	Houdini CSV Asset:
	Fixed missing UPropery for SpawnTimes and LifeValues array.

Change 4096355 by Damien.Pernuit

	Houdini Niagara:

	Fixed performance warning for UHoudiniCSV::GetParticleLifeAtTime()

Change 4096419 by Damien.Pernuit

	Niagara - Houdini:

	Houdini Niagara Data Interface:
	Added GetParticleLifeAtTime for accessing a given particle's life at a given time value.
	Fixed GetParticleVectorValueAtTime not bound properly.
	Fixed GetRowIndexesForParticleAtTime returning incorrect values when the time value was past the particle's last update.

Change 4096466 by Damien.Pernuit

	Niagara - Houdini:
	- Added GetNumberOfColumnsInCSV to the Houdini Data Interface
	- Added descriptions to the functions exposed by the DI

Change 4096528 by Damien.Pernuit

	Niagara - Houdini:

	Houdini CSV Asset:
	- As the DI expects the values to be sorted by time, if it's not the case, the CSV importer will sort them on import.
	- As the DI spawning functions relies on the particle IDs starting at zero and increment, the CSV importer will fix the particles IDs on import if it's not the case.

Change 4096838 by Yannick.Lange

	Fix focus search box on add parameter menu

	#jira UE-59502

Change 4097205 by Bradut.Palas

	Fixes for metadata details in script toolkit (now the apply and compile buttons refresh and sort the metadata collection). The metadata functionality is fixed. Delete, add and modify work just as before, but the sorting isn't applied because refreshing the whole collection is skipped for internal changes.
	#jira UE-58745
	#jira UE-59589

	#tests none

Change 4097593 by Shaun.Kime

	Now generating compiler debug info for VM shaders just like the rest of Materials using the r.DumpShaderDebugInfo

	#tests now properly generate data in a VM folder sibling to other generated debug shader data

Change 4097721 by Frank.Fella

	Niagara - Make the lifetime of stack entries well defined so that we can safely remove delegate bindings and clear out pointers.

Change 4097962 by Bradut.Palas

	Stack issues now update fix delegates on each refresh, even if the fix GUIDs don't change, to account for other possible changes in the graph. Had to introduce unique identifiers for fixes too, now the issue entry is using the same recycle mechanism for fixes that the base stack entry uses for issues.

	#tests none

Change 4098063 by Frank.Fella

	Niagara - Fix input initialization for drag/drop with a "Set Variables" node.

	#jira UE-57699

Change 4098192 by Damien.Pernuit

	Niagara - Houdini:

	Houdini CSV Asset:
	When importing the CSV file, the importer creates a list of the row indexes updating each particle.
	This greatly improves performance when accessing data in large files with a lot of particles updating over time.

Change 4098406 by Damien.Pernuit

	Niagara - Houdini:

	Houdini Niagara Data Interface:
	Added helper functions for accessing Color and Velocity values in the CSV file.

	Houdini CSV Asset:
	The importer now looks for the Color (Cd, color), Alpha (A, Alpha) and velocity (V) attributes.

Change 4099945 by Frank.Fella

	Niagara - Fix op description tool tip and keyword searches in the graph add menu, fix and standardize tool tip handling for script objects in menus, and add support for keyword searches for user defined scripts to match the built in ops.

	#jira UE-59402

Change 4100451 by Shaun.Kime

	Fixing wyeth's torus error, which was caused by us not properly initializing defaults. We now initialize defaults in three waves in spawn scripts. Wave 1 are any straight up constants at the top of the spawn function. Wave 2 is inlined in spawn just before the function that needs them is called. Wave 3 is at the bottom of spawn in a section called HandleMissingDefaultValues.
	Also updated the error and warning messages to be much clearer text.

	#jira UE-59723, UE-59762

	#tests auto-tests pass

Change 4100568 by Shaun.Kime

	Removing the old compile debug file generation and now unified with the existing shader compiler workflow for the future.
	If r.DumpShaderDebugInfo=1, make sure that we generate the assembly, ush, and params files in the Saved\ShaderDebugInfo\VM\<SYSTEM_NAME>\<EMITTER_NAME>\<SCRIPT_NAME_AND_USAGE_ID_IF_NONZERO>

	#jira UE-59767
	#tests auto-tests pass

Change 4100913 by jonathan.lindquist

	changing the pin order

Change 4100932 by jonathan.lindquist

	setting the input pin order on a, b and alpha

Change 4101546 by jonathan.lindquist

	Submitting a dynamic input that returns the exec index as an int

Change 4101734 by Shaun.Kime

	Fixing static analysis errors

	#tests n/a

Change 4101736 by Shaun.Kime

	Creating new last known good for GPU Functional Test auto-test
	#tests n/a

Change 4102305 by Simon.Tovey

	Fix for VM Crash

	#codereivew Frank.Fella, Shaun.Kime, Olaf.Piesche

Change 4102552 by Yannick.Lange

	Tooltip variable types

	#jira UE-59520

Change 4102599 by Yannick.Lange

	New variables in maps or parameter view will get the name Namespace.NewVariable. This is not an actual fix for UE-59633, but gives the user the incentive to rename variables.

	#codereveiw Shaun.Kime

Change 4102752 by Yannick.Lange

	Fix auto expanding all the sections for the niagara parameters list view.

	#jira UE-59121

Change 4102779 by Yannick.Lange

	Fix auto expanding all the sections for the niagara parameters list view. Fix incorrect comment changelist: 4102752

	#jira UE-59121

Change 4103419 by Shaun.Kime

	Fixing build issues

	#tests n/a

Change 4103522 by Damien.Pernuit

	Houdini - Niagara:
	Big renaming pass on the  Houdini CSV Assets  and Data Interface to follow naming conventions:
	Replaced the GetCSVXXX functions by GetXXXX (GetCSVPosition is now GetPosition)
	Always use "row" instead of "line", "Point" instead of "Particle", "PointID" instead of "N" or "ID" etc.

	Houdini Data Interface:
	- Added the GetVectorValueEx and GetPointVectorValueAtTimeEx functions that allow the user to decide how the vector conversion from houdini to unreal's coordinate system is handled.
	- Replaced the GetParticleLifeAtTime function by GetPointLife, that returns the life of a particle at spawn time.
	- Added the GetPointType function returning the type of a given point.

	Houdini CSV Asset:
	- Added the editable SourceTitleRow UProperty.
	Editing this will trigger a reimport of the source CSV file and might be used to fix/modify column titles in the file.
	- Added support for "type" attributes.
	- Removed the unused StringValues buffer and GetCSVStringValues() functions.
	- Added assetTags so the Houdini CSV asset thumbnails show more infos on the CSV data.
	- Added the "FindSourceCSV" asset action to browse to the source CSV file.

Change 4104008 by Shaun.Kime

	Missing header in Monolithic builds

	Fixed indent issues, was using spaces vs tabs

	#jira UE-59705

Change 4105249 by Simon.Tovey

	Fixes in VMM backend and propagation visitors to ensure proper optimization for VM external function calls.

	also adding a visitor to strip empty stats scopes.

Change 4105250 by Simon.Tovey

	Updated windows binaries for hlslcc

Change 4105283 by Yannick.Lange

	Fix creating an input parameter node from an input pin.

	#jira UE-57362

Change 4105509 by Yannick.Lange

	Fix being able to drop parameters in the system view on incorrect execution categories.

Change 4105726 by Wyeth.Johnson

	Fix detection of valid toolchain directories with Visual Studio 2017 desktop (change by Ben.Marsh)

Change 4105727 by Shaun.Kime

	Fixing nightly build due to missing GetAssetTags definition due to mismatches in WITH_EDITORONLY_DATA

	#tests n/a

Change 4106034 by Damien.Pernuit

	Houdini-Niagara:
	Houdini CSV Asset:
	- Fixed build break due to GetAssetRegistryTags()
	- Replaced the different hardcoded ColumnIndexes member variables by an array.

Change 4106254 by Frank.Fella

	Niagara - Fix playback issues where completed systems wouldn't simulate again until you pressed play.

	#jira UE-58616
	#jira UE-58721

Change 4106617 by Frank.Fella

	Niagara - Prevent crash on shutdown.

	#jira UE-59516

Change 4106623 by Frank.Fella

	Niagara - Fix static analysis warning for posible null dereference in UNiagaraScriptItemGroup

Change 4106983 by Shaun.Kime

	Fix to prevent PS4 compiler warning during cook on ambiguous uses of AtomicAdd.

	#tests doesn't cause cook errors now

Change 4106988 by Shaun.Kime

	Resaved test assets with latest non-zero version

	#tests cooking no longer complains about file versions

Change 4106992 by Shaun.Kime

	Now when errors appear in a cook for Niagara GPU shaders, we see them in the same location as the cook log

	#tests n/a

Change 4108852 by Simon.Tovey

	Fix for transforms in emitter scripts.
	Param->Dataset bindings weren't handling structs correctly.

Change 4109260 by Wyeth.Johnson

	Normalize Vector dynamic input

Change 4109748 by Marcus.Wassmer

	olaf.piesche: Fresh build of hlslcc for Mac

Change 4110624 by Rolando.Caloca

	-fresh build of hlslcc for Linux
	-fixed a warning in NiagaraStackModuleItem.cpp

Change 4111103 by Shaun.Kime

	Fixing nightly build issues with redundant left and right side of &&
	CI Issue:
	d:\build\++ue4+dev-niagara+compile\sync\engine\plugins\fx\niagara\source\niagaraeditor\private\viewmodels\niagarasystemviewmodel.cpp(1425): warning V501: There are identical sub-expressions 'bStartedPlaying == false' to the left and to the right of the '&&' operator.

	#tests auto-tests pass

Change 4111104 by Shaun.Kime

	Fix for CI issue:
	d:\build\++ue4+dev-niagara+compile\sync\engine\plugins\fx\niagara\source\niagaraeditor\private\viewmodels\stack\niagarastackscriptitemgroup.cpp(553): warning V595: The 'SourceModuleItem' pointer was utilized before it was verified against nullptr. Check lines: 553, 554.

	#tests auto-tests pass

#ROBOMERGE-SOURCE: CL 4113881 in //UE4/Release-4.20/...
#ROBOMERGE-BOT: RELEASE (Release-4.20 -> Release-Staging-4.20)

[CL 4114750 by shaun kime in Staging-4.20 branch]
2018-06-05 20:16:37 -04:00

248 lines
9.2 KiB
C++

// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.
#include "ShaderFormatVectorVM.h"
#include "VectorVMBackend.h"
#include "CoreMinimal.h"
#include "Misc/FileHelper.h"
#include "ShaderCore.h"
#include "CrossCompilerCommon.h"
#include "ShaderCompilerCommon.h"
#include "ShaderPreprocessor.h"
#include "VectorVM.h"
DEFINE_LOG_CATEGORY_STATIC(LogVectorVMShaderCompiler, Log, All);
DECLARE_STATS_GROUP(TEXT("VectorVM"), STATGROUP_VectorVM, STATCAT_Advanced);
DECLARE_CYCLE_STAT(TEXT("VectorVM - Compiler - CompileShader_VectorVM"), STAT_VectorVM_Compiler_CompileShader_VectorVM, STATGROUP_VectorVM);
DECLARE_CYCLE_STAT(TEXT("VectorVM - Compiler - PreprocessShader"), STAT_VectorVM_Compiler_CompileShader_VectorVMPreprocessShader, STATGROUP_VectorVM);
DECLARE_CYCLE_STAT(TEXT("VectorVM - Compiler - CrossCompilerContextRun"), STAT_VectorVM_Compiler_CompileShader_CrossCompilerContextRun, STATGROUP_VectorVM);
/**
* Compile a shader for the VectorVM on Windows.
* @param Input - The input shader code and environment.
* @param Output - Contains shader compilation results upon return.
*/
bool CompileShader_VectorVM(const FShaderCompilerInput& Input, FShaderCompilerOutput& Output, const FString& WorkingDirectory, uint8 Version)
{
return false;
}
//TODO: Move to this output living in the shader eco-system with the compute shaders too but for now just do things more directly.
bool CompileShader_VectorVM(const FShaderCompilerInput& Input, FShaderCompilerOutput& Output,const FString& WorkingDirectory, uint8 Version, FVectorVMCompilationOutput& VMCompilationOutput)
{
SCOPE_CYCLE_COUNTER(STAT_VectorVM_Compiler_CompileShader_VectorVM);
FString PreprocessedShader;
FShaderCompilerDefinitions AdditionalDefines;
EHlslCompileTarget HlslCompilerTarget = HCT_FeatureLevelSM5;
ECompilerFlags PlatformFlowControl = CFLAG_AvoidFlowControl;
AdditionalDefines.SetDefine(TEXT("COMPILER_HLSLCC"), 1);
AdditionalDefines.SetDefine(TEXT("COMPILER_VECTORVM"), 1);
const bool bDumpDebugInfo = (Input.DumpDebugInfoPath != TEXT("") && IFileManager::Get().DirectoryExists(*Input.DumpDebugInfoPath));
AdditionalDefines.SetDefine(TEXT("FORCE_FLOATS"), (uint32)1);
if (Input.bSkipPreprocessedCache)
{
if (!FFileHelper::LoadFileToString(PreprocessedShader, *Input.VirtualSourceFilePath))
{
return false;
}
// Remove const as we are on debug-only mode
CrossCompiler::CreateEnvironmentFromResourceTable(PreprocessedShader, (FShaderCompilerEnvironment&)Input.Environment);
}
else
{
SCOPE_CYCLE_COUNTER(STAT_VectorVM_Compiler_CompileShader_VectorVMPreprocessShader);
if (!PreprocessShader(PreprocessedShader, Output, Input, AdditionalDefines))
{
// The preprocessing stage will add any relevant errors.
return false;
}
}
//TODO: Need to remove any unsupported features here?
char* ShaderSource = NULL;
char* ErrorLog = NULL;
const EHlslShaderFrequency Frequency = HSF_VertexShader;
// Write out the preprocessed file and a batch file to compile it if requested (DumpDebugInfoPath is valid)
if (bDumpDebugInfo)
{
FArchive* FileWriter = IFileManager::Get().CreateFileWriter(*(Input.DumpDebugInfoPath / Input.GetSourceFilename()));
if (FileWriter)
{
auto AnsiSourceFile = StringCast<ANSICHAR>(*PreprocessedShader);
FileWriter->Serialize((ANSICHAR*)AnsiSourceFile.Get(), AnsiSourceFile.Length());
{
FString Line = CrossCompiler::CreateResourceTableFromEnvironment(Input.Environment);
FileWriter->Serialize(TCHAR_TO_ANSI(*Line), Line.Len());
}
FileWriter->Close();
delete FileWriter;
}
if (Input.bGenerateDirectCompileFile)
{
FFileHelper::SaveStringToFile(CreateShaderCompilerWorkerDirectCommandLine(Input), *(Input.DumpDebugInfoPath / TEXT("DirectCompile.txt")));
}
}
//Is stuff like this needed? What others?
uint32 CCFlags = HLSLCC_NoPreprocess;
//CCFlags |= HLSLCC_PrintAST;
//CCFlags |= HLSLCC_UseFullPrecisionInPS;
//TODO: Do this later when we implement the rest of the shader plumbing stuff.
// if (bDumpDebugInfo)
// {
// const FString VVMFile = (Input.DumpDebugInfoPath / TEXT("Output.vvm"));
// const FString USFFile = (Input.DumpDebugInfoPath / Input.GetSourceFilename());
// const FString CCBatchFileContents = CreateCrossCompilerBatchFile(USFFile, VVMFile, *Input.EntryPointName, Frequency, Version, CCFlags);
// if (!CCBatchFileContents.IsEmpty())
// {
// const TCHAR * ScriptName = PLATFORM_WINDOWS ? TEXT("CrossCompile.bat") : TEXT("CrossCompile.sh");
// FFileHelper::SaveStringToFile(CCBatchFileContents, *(Input.DumpDebugInfoPath / ScriptName));
// }
// }
//NEEDED?
// Required as we added the RemoveUniformBuffersFromSource() function (the cross-compiler won't be able to interpret comments w/o a preprocessor)
//CCFlags &= ~HLSLCC_NoPreprocess;
FVectorVMCodeBackend VVMBackEnd(CCFlags, HlslCompilerTarget, VMCompilationOutput);
FVectorVMLanguageSpec VVMLanguageSpec;
bool Result = false;
FHlslCrossCompilerContext CrossCompilerContext(CCFlags, Frequency, HlslCompilerTarget);
if (CrossCompilerContext.Init(TCHAR_TO_ANSI(*Input.VirtualSourceFilePath), &VVMLanguageSpec))
{
SCOPE_CYCLE_COUNTER(STAT_VectorVM_Compiler_CompileShader_CrossCompilerContextRun);
Result = CrossCompilerContext.Run(
TCHAR_TO_ANSI(*PreprocessedShader),
TCHAR_TO_ANSI(*Input.EntryPointName),
&VVMBackEnd,
&ShaderSource,
&ErrorLog
) ? 1 : 0;
}
if (ErrorLog)
{
int32 SrcLen = FPlatformString::Strlen(ErrorLog);
int32 DestLen = FPlatformString::ConvertedLength<TCHAR, ANSICHAR>(ErrorLog, SrcLen);
TArray<TCHAR> Converted;
Converted.AddUninitialized(DestLen);
FPlatformString::Convert<ANSICHAR, TCHAR>(Converted.GetData(), DestLen, ErrorLog, SrcLen);
Converted.Add(0);
VMCompilationOutput.Errors = Converted.GetData();
TArray<FString> OutputByLines;
PreprocessedShader.ParseIntoArrayLines(OutputByLines, false);
FString OutputHlsl;
for (int32 i = 0; i < OutputByLines.Num(); i++)
{
UE_LOG(LogVectorVMShaderCompiler, Warning, TEXT("/*%d*/%s"), i, *OutputByLines[i]);
}
}
else
{
VMCompilationOutput.Errors.Empty();
}
//TODO: Try to get rid of the CompilationOutput and have the vm bytecode life in the shader eco-system as the compute shader version will.
// int32 SourceLen = VVMBackEnd.ByteCode.Num();//ShaderSource ? FCStringAnsi::Strlen(ShaderSource) : 0;
// if (SourceLen > 0)
// {
// if (bDumpDebugInfo)
// {
// const FString GLSLFile = (Input.DumpDebugInfoPath / TEXT("Output.vvm"));
//
// if (SourceLen > 0)
// {
// uint32 Len = FCStringAnsi::Strlen(TCHAR_TO_ANSI(*Input.VirtualSourceFilePath)) + FCStringAnsi::Strlen(TCHAR_TO_ANSI(*Input.EntryPointName)) + FCStringAnsi::Strlen(ShaderSource) + 20;
// char* Dest = (char*)malloc(Len);
// FCStringAnsi::Snprintf(Dest, Len, "// ! %s:%s\n%s", (const char*)TCHAR_TO_ANSI(*Input.VirtualSourceFilePath), (const char*)TCHAR_TO_ANSI(*Input.EntryPointName), (const char*)ShaderSource);
// free(ShaderSource);
// ShaderSource = Dest;
// SourceLen = FCStringAnsi::Strlen(ShaderSource);
//
// FArchive* FileWriter = IFileManager::Get().CreateFileWriter(*(Input.DumpDebugInfoPath / Input.VirtualSourceFilePath + TEXT(".vvm")));
// if (FileWriter)
// {
// FileWriter->Serialize(ShaderSource,SourceLen+1);
// FileWriter->Close();
// delete FileWriter;
// }
// }
// }
//HMMMM....?
// #if VALIDATE_GLSL_WITH_DRIVER
// PrecompileShader(Output, Input, ShaderSource, Version, Frequency);
// #else // VALIDATE_GLSL_WITH_DRIVER
//SourceLen = FCStringAnsi::Strlen(ShaderSource);
// Output.Target = Input.Target;
//BuildShaderOutput(Output, Input, ShaderSource, SourceLen, Version);
// Output.bSucceeded = true;
//Should we add optional data to define the register allocations etc so that someone can just write hlsl directly and have it become a niagara sim?
// Output.ShaderCode.GetWriteAccess().Append((uint8*)VVMBackEnd.ByteCode.GetData(), VVMBackEnd.ByteCode.Num());
// Output.ShaderCode.FinalizeShaderCode();
//#endif // VALIDATE_GLSL_WITH_DRIVER
// }
// else
// {
//ES2 Command line is throwing me off. Is this needed?
// if (bDumpDebugInfo)
// {
// // Generate the batch file to help track down cross-compiler issues if necessary
// const FString VVMFile = (Input.DumpDebugInfoPath / TEXT("Output.vvm"));
// const FString VVMBatchFileContents = CreateCommandLineGLSLES2(VVMFile, (Input.DumpDebugInfoPath / TEXT("Output.asm")), Version, Frequency, false);
// if (!VVMBatchFileContents.IsEmpty())
// {
// FFileHelper::SaveStringToFile(VVMBatchFileContents, *(Input.DumpDebugInfoPath / TEXT("VVMCompile.bat")));
// }
// }
//
// Output.bSucceeded = false;
//
// FString Tmp = ANSI_TO_TCHAR(ErrorLog);
// TArray<FString> ErrorLines;
// Tmp.ParseIntoArray(ErrorLines, TEXT("\n"), true);
// for (int32 LineIndex = 0; LineIndex < ErrorLines.Num(); ++LineIndex)
// {
// const FString& Line = ErrorLines[LineIndex];
// CrossCompiler::ParseHlslccError(Output.Errors, Line);
// }
// }
if (ShaderSource)
{
UE_LOG(LogVectorVMShaderCompiler, Warning, TEXT("%s"), (const char*)ShaderSource);
free(ShaderSource);
}
if (VMCompilationOutput.Errors.Len() != 0)
{
UE_LOG(LogVectorVMShaderCompiler, Warning, TEXT("%s"), *VMCompilationOutput.Errors);
free(ErrorLog);
}
return Result;
}