Files
UnrealEngineUWP/Engine/Source/Runtime/Renderer/Private/GPUFastFourierTransform.cpp
Chris Bunner ab9d8e35b1 Copying //UE4/Dev-Rendering to //UE4/Dev-Main (Source: //UE4/Dev-Rendering @ 3388261)
#lockdown Nick.Penwarden
#rb None

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

Change 3358140 on 2017/03/22 by Rolando.Caloca

	DR - Fix copy to cube face
	- Compile fix when using dump layer
	- Add new error enum

Change 3358301 on 2017/03/22 by Mitchell.Wilson

	Initial check in of LODs in InfiltratorForward. First pass on optimization in level. Adding a visibility track for SceneCapture2D in tunnel section.

Change 3358477 on 2017/03/22 by Mitchell.Wilson

	Updating Skeletal Mesh DPW_Robot_Export to resolve screen size being too low for LOD1. Cleaned up LOD1 which was showing some visible popping when transitioning.

Change 3358529 on 2017/03/22 by Mark.Satterthwaite

	Globally disable clang's "constant-logical-operand" warning when running under Distcc - it is much easier and less invasive than constantly fixing the code.

Change 3358745 on 2017/03/22 by Mark.Satterthwaite

	Disable another warning (parentheses-equality) under Distcc because again the separation of preprocessing from compilation means it turns up where it isn't expected.

Change 3358837 on 2017/03/22 by Joe.Graf

	Merge of pull request #3214 for the RenderDocPlugin

	#CodeReview: matt.kuhlenschmidt, marcus.wassmer
	#rb: marcus.wassmer

Change 3359112 on 2017/03/22 by Ben.Salem

	Update perf monitor to include frame time by default. Also, use only  game/PIE world timers when in editor, instead of all worlds combined.

	#tests Ran several Showdown test runs with plugin!

Change 3359363 on 2017/03/22 by Joe.Graf

	First pass at non-unity & no pch compilation

Change 3359449 on 2017/03/22 by Joe.Graf

	Added missing null check when exporting a EXR on Linux (UE-40268)

	#CodeReview: dmitry.rekman
	#rb: n/a

Change 3360349 on 2017/03/23 by Guillaume.Abadie

	Fixes TAA's AA_FORCE_ALPHA_CLAMP causing DOF layouts.

	#jira UE-42920

Change 3360405 on 2017/03/23 by Marcus.Wassmer

	Better method for detecting Kepler

Change 3360718 on 2017/03/23 by Daniel.Wright

	Planar reflections handle views smaller than the render target in a general way
	* Fixes planar reflections with adaptive pixel density (ViewFamily size larger than actual views combined)
	* Planar reflections are now supported in splitscreen

Change 3360758 on 2017/03/23 by Daniel.Wright

	[Copy] Added new light property bCastVolumetricShadow, which defaults to true for directional and sky lights, but false for point / spot lights as supporting volumetric fog shadowing has significant GPU overhead

Change 3360762 on 2017/03/23 by Daniel.Wright

	[Copy] Texture flags are now properly routed to RHICreateTexture3D from the render target pool

Change 3360768 on 2017/03/23 by Daniel.Wright

	[Copy] Disabled GPUProfiler histogram by default, controlled by r.ProfileGPU.ShowEventHistogram

Change 3360770 on 2017/03/23 by Daniel.Wright

	[Copy] Disabled fast clears on CustomDepth, saves .2ms on xbox

Change 3360771 on 2017/03/23 by Daniel.Wright

	[Copy] Particle lights no longer force tiled deferred lighting.  Tiled deferred lighting is only used if enough unshadowed lights + particle lights are on screen.  Saves 1.5ms Xbox with one particle light.

Change 3360774 on 2017/03/23 by Daniel.Wright

	[Copy] Distance field cvar comments

Change 3360782 on 2017/03/23 by Daniel.Wright

	[Copy] Disabled selection color on Volume materials

Change 3360795 on 2017/03/23 by Daniel.Wright

	[Copy] Volume materials now specify Albedo and Extinction, which is more intuitive than Scattering and Absorption.  Albedo is [0-1] reflectance, while Extinction is a world space density.

Change 3360799 on 2017/03/23 by Daniel.Wright

	[Copy] Cinematic scalability levels get 2x volumetric fog resolution in x and y

Change 3360806 on 2017/03/23 by Daniel.Wright

	[Copy] Fixed volumetric fog being offset when viewport min is not 0

Change 3360809 on 2017/03/23 by Daniel.Wright

	[Copy] Volumetric fog now adds a bias to the inverse squared light falloff denominator, prevents extreme aliasing from the hotspot.  Can be controlled with r.VolumetricFog.InverseSquaredLightDistanceBiasScale.

Change 3361651 on 2017/03/23 by Brian.Karis

	Higher quality sharp SSR at quality 4

Change 3361678 on 2017/03/23 by Brian.Karis

	Fresnel darkens diffuse for clearcoat.

Change 3361683 on 2017/03/23 by Brian.Karis

	Fixed SSR artifact

Change 3361691 on 2017/03/23 by Brian.Karis

	Chagned min roughness limit

Change 3361707 on 2017/03/23 by Brian.Karis

	Added inverse film tone map

Change 3361726 on 2017/03/23 by Brian.Karis

	Better precision inverse

Change 3361758 on 2017/03/23 by Brian.Karis

	Material flag normal curvature to roughness is no longer forward only.

Change 3361765 on 2017/03/23 by Brian.Karis

	Update ACES

Change 3361774 on 2017/03/23 by Brian.Karis

	Cleaned up alpha support and disabled screen edge clipping.

Change 3362478 on 2017/03/24 by Guillaume.Abadie

	Cherry pick 3316084's PostProcessing.cpp: Fixes a bug in Circle DOF where the apply pass was no longer using the downres DOF's TAA output.

	#author Brian.Karis

	#jira UE-42920

Change 3362738 on 2017/03/24 by Rolando.Caloca

	DR - Hide scene capture on IF

Change 3362890 on 2017/03/24 by Guillaume.Abadie

	Renames r.SceneAlpha to r.PostProcessing.PropagateAlpha

Change 3363665 on 2017/03/24 by Mark.Satterthwaite

	PR #3414: Add command line option "-noheartbeatthread" to disable heart beat thread (Contributed by JeffRous)

Change 3363866 on 2017/03/24 by Arne.Schober

	DR - Updated NVAPI
	#RB Marcus.Wassmer

Change 3364300 on 2017/03/24 by Brian.Karis

	SSR use dynamic velocity

Change 3364372 on 2017/03/24 by Brian.Karis

	Fix changing off axis projection velocities.

Change 3364373 on 2017/03/24 by Brian.Karis

	Enabled velocity drawing in scene captures

Change 3365531 on 2017/03/27 by Guillaume.Abadie

	Computes the material's screen position material expression directly from the pixel shader SvPosition

Change 3365764 on 2017/03/27 by Chris.Bunner

	Lowering severity of crash for missing values in scalability.ini.

	#jira UE-41331

Change 3365916 on 2017/03/27 by Guillaume.Abadie

	Exposes the viewport offset within the view property material expression

Change 3365979 on 2017/03/27 by Brian.Karis

	Fixed skylight intensity from double applying

Change 3365987 on 2017/03/27 by Brian.Karis

	Stopped post process indirect lighting intensity from scaling skylight reflections

Change 3365991 on 2017/03/27 by Brian.Karis

	Fix for static analysis

Change 3366028 on 2017/03/27 by Daniel.Wright

	Volumetric fog supports static shadowing from Stationary lights
	* Using bilinear on static shadowmap depths + 1 PCF to smooth out results

Change 3366029 on 2017/03/27 by Daniel.Wright

	Static shadow depth maps for Stationary point and spot lights are 2x higher res by default (4x more texels), which is more appropriate for volumetric fog

Change 3366055 on 2017/03/27 by Guillaume.Abadie

	Cherry picks 3251469: Implements scene capture component's CaptureSortPriority to control GPU execution order in order to manage inter dependencies.

Change 3366447 on 2017/03/27 by Simon.Tourangeau

	Fix IES light profile importer.
	- Bug in the LM-63-1986 format importer.

Change 3366836 on 2017/03/27 by Brian.Karis

	ClearUAV now supports int types

Change 3367435 on 2017/03/28 by Benjamin.Hyder

	Submitting Decal Automation map for initial approval

Change 3367572 on 2017/03/28 by Chris.Bunner

	Changed ClampedPow {max(abs(x),0.00001)} to PositiveClampedPow {max(x,0)} to give more expected results to Power node in material graphs.

	#jira UE-42989

Change 3367756 on 2017/03/28 by Olaf.Piesche

	Niagara material usage flags

Change 3367835 on 2017/03/28 by Marcus.Wassmer

	Fix crash when TileRenderer runs before anything else.  Make explicit behavior when rendering at a time when there is no valid scene.

Change 3367837 on 2017/03/28 by Marcus.Wassmer

	Missed a file.

Change 3367838 on 2017/03/28 by Richard.Wallis

	Updated items from original shelved version by Mark Satt:

	- Added MetalBackend.cpp to change main function string to have an initial crc + code length zero's

	**Description below taken from Mark Satt's original verison of this in CL3343280**

	Updated for Dev-Rendering's PSOs & integrates Richard's work on RHI shader libraries.

	Replace the FShaderCache's cook-time binary shader cache with Dmitriy Dyomin's standalone FShaderCodeLibrary that saves all shader byte-code arrays to files named by the FSHAHash. This de-duplicates shaders so we only ever store the byte code once. Includes optional support for generating a platform specific library file - which Metal implements to provide a single Metal library. The platform-native implementation can perform more de-duplication and in the case of Metal has lower file overheads and will compress more efficiently.

	- All of the support code for the FShaderCache's cook caching is gone, which affects all platforms. The FShaderCodeLibrary is currently  supported by Cook-By-The-Book but can be used with iterate or child cookers - only DLC cooking requires further work.
	- With further modifications it should be possible to support Cook-on-the-Fly as well (output directories would be needed in FShaderCodeLibrary::InitForCooking) and the file-access pattern should be changed to use async. IO so that Material loading is not considered complete until all required byte-code arrays are loaded into the FShaderCodeLibrary.
	- For Metal archiving shaders this way will compile with debug information and the FShaderCodeLibrary, with some help from extensions to IShaderFormat, will save the debug information out into separate files during cooking - these can then be used to debug the game without having to locally recompile, recook & repackage but the shipped byte-code is stripped. Global shader caches are also subject to de-duplication in the library in order to support Metal's shader stripping.
	- File Move operations need to respect the 'Replace' flag - for FShaderCodeLibrary to work we need Move to be atomic.
	- This bumps the object version and will cause all content to recook.
	- Native library support is optional - only Metal currently implements one, but so could Vulkan and D3D12. For Metal the big advantages are further de-duplication where different materials generate the same MetalSL text but a different FSHAHash, that the single Metal library has lower overhead and that as a single file it all compresses far better (esp. with LZMA - 5x smaller).

Change 3367854 on 2017/03/28 by Mark.Satterthwaite

	Don't track or record draw call resources for non-OpenGL shader platforms in the shader-cache as it is unnecessary and makes it slower on the CPU than it needs to be.

Change 3367877 on 2017/03/28 by Brian.Karis

	Fixed linux build hopefully

Change 3368001 on 2017/03/28 by Mark.Satterthwaite

	Compile fixes from Richard's checkin caused by not having visibility to all platforms from my original shelves.

Change 3368019 on 2017/03/28 by Mark.Satterthwaite

	And another fix for Windows compilation of MetalShaderFormat.

Change 3368042 on 2017/03/28 by Mark.Satterthwaite

	And a couple of simpler MSVC errors.

Change 3368271 on 2017/03/28 by Mark.Satterthwaite

	Make SceneRenderTargets compile again.

Change 3368691 on 2017/03/28 by Daniel.Wright

	[Copy from BenW] Renamed r.Shadow.MaxCSMShadowResolution to r.Shadow.MaxCSMResolution to match scalability inis

Change 3369689 on 2017/03/29 by Marcus.Wassmer

	Fix non editor compile for now

Change 3369862 on 2017/03/29 by Marcus.Wassmer

	Get the rest of the things compiling again.

Change 3369896 on 2017/03/29 by Chris.Bunner

	Enabling AMD HDR support by default.

	#jira UE-42113

Change 3370535 on 2017/03/29 by Marcus.Wassmer

	DR - Fix template explicit instantiation for ClearUAV permutations
	#RB Brian.Karis, Arne.Schober

Change 3370704 on 2017/03/29 by Rolando.Caloca

	DR - Rewrote GPU Skin Cache
	- Per section buffers
	- Limited memory per non-editor worlds (control with r.SkinCache.SceneMemoryLimitInMB)
	Copied from 3370529

Change 3371389 on 2017/03/30 by Richard.Wallis

	Remove temp working directories after archive packages built.

Change 3371641 on 2017/03/30 by Rolando.Caloca

	DR - Copy 3371640 (fix mem leak)

Change 3372436 on 2017/03/30 by Uriel.Doyon

	Added flags in UPrimitiveComponent to keep track of its state in the streaming manager.
	This allows to avoid unnecessary callback and processing in begin destroy reattach and being destroy logic.

	Removed the limitation of only processing UMeshComponent when handling spawed primitive.
	This releases the level manager from having to manage dynamic primitives.
	This improves performance by not having to manage dynamic references in the level manager.

	Primitives managed as dynamic now have a callback when ever their proxy is udpated, handling
	many cases automatically where previously a manual callback to notify would have been required.

	Fixed an issue where primitives with no reference to streaming textures would loose they dynamic state
	because of lack of references in the streamer.

Change 3372740 on 2017/03/30 by Chris.Bunner

	[Experimental] Partial compute post process pipeline (r.PostProcess.PreferCompute).
	StencilSceneTexture added to deferred list.
	A few known issues to be fixed in a follow-up CL.

Change 3372765 on 2017/03/30 by Uriel.Doyon

	Disabled concurrent call to NotifyPrimitiveUpdated while we don't have a safe concurrent update

Change 3372979 on 2017/03/30 by Richard.Hinckley

	#jira UE-43501
	The stencil buffer can now use single-channel bitmasks that ignore depth. This makes it possible to detect overlaps between stencil objects.

Change 3373053 on 2017/03/30 by Simon.Tourangeau

	LPV Fade support
	- mostly integrated from CL 2959511

Change 3373272 on 2017/03/30 by Uriel.Doyon

	Added support for the concurrent update of dynamic primitives by the streaming manager.

Change 3373450 on 2017/03/30 by Rolando.Caloca

	DR - FNT - Fix bad data for odd texcoord channels used on skin cache passthrough factory
	Copy 3373364

	#jira UE-43492

Change 3373470 on 2017/03/30 by Marcus.Wassmer

	Nvidia Aftermath support

Change 3374187 on 2017/03/31 by Chris.Bunner

	Volume texture support for CombineLUTs/Tonemap compute pass.
	Refactored common param code to shared sub-class in CombineLUTs and Tonemap PS/CS.
	Skip compute post process out-of-bounds writes.
	Unsigned type conversion fixes.
	Trimmed compute post process shader inputs.

Change 3374233 on 2017/03/31 by Chris.Bunner

	Removed several redundant post process compute fences and resource transitions.
	Added testing CVar to force compute post processes to async (r.PostProcess.ForceAsyncDispatch).

Change 3374412 on 2017/03/31 by Rolando.Caloca

	DR - Fix static analysis

Change 3374544 on 2017/03/31 by Richard.Wallis

	FShaderCache Parallel-Context-Aware Merged with FShaderCache Single Library.

	Future Work
	- This was done before Engine PSO were in so this now needs a refector in the recording and playback on pipeline states instead an emulate PSO in OpenGL Driver.
	- Remove FShaderCacheState and replace the logic with FGraphicsPipelineStateInitializer which should be able to record from the RHI current pipeline state
	- This would reduce the Locking required as it's naturally per thread/context and only the final record would need a lock

Change 3374588 on 2017/03/31 by Richard.Wallis

	Windows Compile Fixes

Change 3374810 on 2017/03/31 by Benjamin.Hyder

	updating recommended GPU drivers

Change 3375207 on 2017/03/31 by Rolando.Caloca

	DR - vk - Fixed swapchain format selection for some Linux platforms

Change 3375248 on 2017/03/31 by Rolando.Caloca

	DR - vk - Prefer D32S8

Change 3375495 on 2017/03/31 by Rolando.Caloca

	DR - vk - Update to sdk 1.0.42.2

Change 3375496 on 2017/03/31 by Rolando.Caloca

	DR - Force compiling with updated Vulkan SDK

Change 3375636 on 2017/03/31 by Mark.Satterthwaite

	Copying Metal improvements from task stream, with some modifications:
	- Off-by-default implementations for MTLFence & MTLHeap, including some small changes to the RHI interface for parallel contexts.
	- Support for Apple's Instruments "Points of Interest" tool.
	- Consolidation of some Mac & iOS compiler, memory and thread handling code.
	- Fixes for Metal not having implicit buffer SRV typecasting for DistanceField effects.
	- Improvements to the internal FMetalDebug layer, still off by default.
	- Limited support for Xcode automatic code-signing for iOS/tvOS.
	- Minimisation of render-target changes in some rendering code, esp. SceneOcclusion, DBufferDecals.
	- Added RHISetResourceAliasability_RenderThread to FDynamicRHI for RHIs to implement simple render-target aliasing.
	- Added FApplePlatformObject, a custom block allocator for Objective-C types (with NSZombie support) which is now used in MetalRHI to decrease allocation costs of Objective-C types.
	- Smattering of lesser fixes.

Change 3375654 on 2017/03/31 by Mark.Satterthwaite

	Incremental Windows build fix.

Change 3375656 on 2017/04/01 by Mark.Satterthwaite

	Correct extern declaration, including the module export macro which Mac unhelpfully doesn't enforce (for now...).

Change 3375797 on 2017/04/01 by Mark.Satterthwaite

	Nullability qualifiers to fix Mac build-farm compilation: perversely this is not a problem for local builds...

Change 3375798 on 2017/04/01 by Mark.Satterthwaite

	Fix the first mis-merge in ParticleGpuSimulation - these changes clearly weren't properly resolved in the task-stream.

Change 3375835 on 2017/04/01 by Mark.Satterthwaite

	Try again with nullability and fix the occlusion changes as the PSO work wasn't merged correctly.

Change 3376143 on 2017/04/02 by Mark.Satterthwaite

	Switch back to flat dSYMs for Dev-Rendering - they don't work with Instruments etc. but they are required by our build system.

Change 3376324 on 2017/04/03 by Chris.Bunner

	Fixed cvar re-registration log spam and flagged a testing-only cvar as such.

Change 3376726 on 2017/04/03 by Benjamin.Hyder

	Submitting initial HDR test map (WIP)

Change 3376756 on 2017/04/03 by Guillaume.Abadie

	Fixes scene captures ordering's backward compatibility.

	Before, 2d scene captures were rendered before cube scene captures. The CaptureSortPriority broke backward compatibility by settings this new member to 0 in the USceneCaptureComponent's constructor. Since it is a higher come first policy, this CL set the default of this value to 1 in USceneCaptureComponent2D's constructor.

Change 3377378 on 2017/04/03 by Arne.Schober

	DR - Fix ShaderRecompiling over and over again
	#RB Chris.Bunner

Change 3377512 on 2017/04/03 by Daniel.Wright

	[Copy] Fixed profilegpu in d3d12 - initialize FLongGPUTaskPS when it is safe to do so, and fixed FSlateRHIRenderer's incorrect usage of draw events

Change 3377518 on 2017/04/03 by Daniel.Wright

	[Copy] Distance field atlas coalesces updates to reduce RHIUpdateTexture3D memory overhead on d3d12

Change 3377526 on 2017/04/03 by Daniel.Wright

	[Copy] "Ran out of GPU queries!" log only happens once

Change 3377535 on 2017/04/03 by Daniel.Wright

	[Copy] Fixed unreferenced local variable

Change 3377539 on 2017/04/03 by Daniel.Wright

	[Copy] Xbox One RHIGetResourceInfo takes ESRAM into account - fixes render target pool 'VRamInKB request failed' messages

Change 3377546 on 2017/04/03 by Daniel.Wright

	[Copy] Added r.LightMaxDrawDistanceScale for local light scalability

Change 3377553 on 2017/04/03 by Daniel.Wright

	[Copy] Removed NEW_ESRAM_ALLOCATOR define and old unused path

Change 3377560 on 2017/04/03 by Daniel.Wright

	[Copy] Fixed two d3d12 refcounting bugs causing -norhithread crashes

Change 3377565 on 2017/04/03 by Daniel.Wright

	[Copy] Fixed Xbox One deleting GPU resources before the GPU is done reading from them (GRHINeedsExtraDeletionLatency was false)

Change 3377572 on 2017/04/03 by Daniel.Wright

	[Copy] Disabled point / spot lights with MaxDrawDistance on LowPC

Change 3377586 on 2017/04/03 by Daniel.Wright

	Fixed compile error

Change 3377699 on 2017/04/03 by David.Hill

	FFT Code.  Moved over from raven and refactored

	#review-3374589 @guillaume.abadie

Change 3377910 on 2017/04/03 by David.Hill

	GPU FFT: Fix Linux Build
	adding a missing template<> to an IMPLEMENT_SHADER_TYPE

Change 3378751 on 2017/04/04 by Marcus.Wassmer

	HQ particle lights now spawn attached to the same socket as their parent module.

Change 3378819 on 2017/04/04 by Richard.Wallis

	Should be no need to protect shader cache against RHI thread now.

Change 3378823 on 2017/04/04 by Richard.Wallis

	FRHIShaderLibrary Opaque Type

	- Base FRHIShaderLibrary has no Create*Shader functions and is passed to Overloaded RHICreate*Shader functions instead of creation directly through the library.
	- Assumed that only Native libraries will end up in the RHICreate*Shader functions.
	- ShaderCache and ShaderCode Libraries now inherit from a common factory interface.

Change 3378883 on 2017/04/04 by Arne.Schober

	DR - Fix DCC build

Change 3378885 on 2017/04/04 by Richard.Wallis

	Metal resource cast compile fix post merge.

Change 3378946 on 2017/04/04 by Chris.Bunner

	SM4 assert fix.

Change 3378953 on 2017/04/04 by Chris.Bunner

	Fixed type-correctness on legacy BreakMA material nodes and set more flexible formats to global attributes which should result in much more forgiving graphs for users.
	Allowed material nodes to opt out of mask-based pin coloration.
	#tests Compiled most Paragon materials + QAGame test maps.

	#jira UE-39885

Change 3379189 on 2017/04/04 by Arne.Schober

	DR - Fix aftermath staging

Change 3379229 on 2017/04/04 by Arne.Schober

	DR - Fix missing include

Change 3379374 on 2017/04/04 by Mark.Satterthwaite

	Revert an accidentally merged change in MacPlatformProcess that relies on further changes from the Metal task stream.

Change 3379505 on 2017/04/04 by Rolando.Caloca

	DR - Fix mismatched interpolators

Change 3379539 on 2017/04/04 by Mark.Satterthwaite

	No FFT for any hlslcc platform - the IR for one or more RWTexture2D isn't quite right...

	#jira UE-43626

Change 3379561 on 2017/04/04 by Rolando.Caloca

	DR - Fix root signature issues on D3D12 PC

Change 3379590 on 2017/04/04 by Mark.Satterthwaite

	Back out changelist 3379539 & change the shader slightly instead, the HLSLCC library generates bogus IR when you have an inout RWTexture.

	#jira UE-43626

Change 3379917 on 2017/04/04 by Uriel.Doyon

	Fix to input mismatch

Change 3380578 on 2017/04/05 by Chris.Bunner

	Shader type fixes.

	#jira UE-43652

Change 3380639 on 2017/04/05 by Rolando.Caloca

	DR - Expose GetOrCreate PSO and document

Change 3380821 on 2017/04/05 by Guillaume.Abadie

	Fixes a crash in USceneCaptureComponent::UpdateDeferredCaptures()

	#jira UE-43642

Change 3381092 on 2017/04/05 by Guillaume.Abadie

	Cherry pick 3362517: Implements TAA's scene color unpremultiplication from alpha channel to reduce DOF alpha channel temporal ghosting.

	This CL take the oportunity to transform AA_ALPHA to an compile time enumeration, and add a basic TAA compile time configuration validation to improve readability of the different TAA passes' configurations.

Change 3381300 on 2017/04/05 by Mark.Satterthwaite

	Quick fix for changes to MetalRHI's render-thread safe texture creation not correctly handling AVFoundation video player handing us an IOSurface.

	#jira UE-43597

Change 3381359 on 2017/04/05 by Guillaume.Abadie

	Back out changelist 3381092

Change 3381421 on 2017/04/05 by Mark.Satterthwaite

	Amended CL #3380995 from Richard Wallis to address crash in the Material Editor under the validation layer - when there are no textures bound the default pass descriptor assigns store actions, which means we can't override them with our deferred store actions.

	#jira UE-43689

Change 3381422 on 2017/04/05 by Mark.Satterthwaite

	Absolute time queries can't be batched in Metal but I also can't rely on them being started with a call to BeginQuery - only EndQuery.

	#jira UE-43691

Change 3381503 on 2017/04/05 by Daniel.Wright

	More intuitive controls for Volumetric Fog
	* Removed ScatteringScale / AbsorptionScale on Exponential Height Fog and added Albedo / Extinction
	* InscatteringColorCubemap is now supported by Volumetric Fog
	* Particle lights have a default VolumetricScatteringIntensity of 0 to avoid trailing
	* Tweaked GVolumetricFogDepthDistributionScale better for nearby details
	* Volume Materials have twice the interpolators available

Change 3381527 on 2017/04/05 by Mark.Satterthwaite

	Disable Private GPU storage for PVRTC texture formats on iOS Metal - these require more changes to the blit-encoder usage as PVRTC has strange requirements.

Change 3381671 on 2017/04/05 by Mark.Satterthwaite

	Better error message for failure to compile shaders remotely from PC for Metal.

Change 3381769 on 2017/04/05 by Rolando.Caloca

	DR - Added lock texture array 2d on Vulkan

Change 3382003 on 2017/04/05 by Mark.Satterthwaite

	Remove the automatic Metal aliasing/re-use when releasing some resource types as it doesn't work as intended.

Change 3382030 on 2017/04/05 by Zachary.Wilson

	Fix compiling Metal text shaders from PC broken in merge from task stream.
	#submitter mark.satterthwaite

	#jira UE-43652

Change 3382880 on 2017/04/06 by Mark.Satterthwaite

	Michael Trepka's CL #3379927:
	VolumetricFogVoxelization implementation for Mac

Change 3383315 on 2017/04/06 by Mark.Satterthwaite

	Partially revert CL #3382003 - the emulated Metal heaps require invoking makeAliasable in order to reclaim memory.

	#jira UE-43739

Change 3384639 on 2017/04/07 by Marcus.Wassmer

	Move ShaderResource version bump to RenderingObjectVersion

Change 3384704 on 2017/04/07 by Mark.Satterthwaite

	Compile fix for merge.

Change 3384933 on 2017/04/07 by Rolando.Caloca

	DR - Fix skin cache crash with BP (copy 3384714)

Change 3385104 on 2017/04/07 by Mark.Satterthwaite

	Fix MetalRHI's abs(int2) handling - it can't be translated to fabs(int2) as that won't compile. Also rebuild hlslcc for my sanity.

	#jira UE-43783

Change 3385105 on 2017/04/07 by Mark.Satterthwaite

	Force a shader rebuild to ensure that everybody picks up the fix for #jira UE-43783

	#jira UE-43783

Change 3385118 on 2017/04/07 by Arne.Schober

	DR - [OR-37359] - Fix disapearing Decals when StencilLod Fade is enabled
	#RB none

Change 3385149 on 2017/04/07 by Marcus.Wassmer

	Fix skincache motion blur

Change 3385189 on 2017/04/07 by Rolando.Caloca

	DR - Fix swapchain format for editor on Vulkan

Change 3385287 on 2017/04/07 by Mark.Satterthwaite

	Enable SM5 on Intel as of 10.12.4 and later.

Change 3385347 on 2017/04/07 by Rolando.Caloca

	DR - Temp fix for GL4 corruption on editor
	#jira UE-43785

Change 3385363 on 2017/04/07 by Rolando.Caloca

	DR - Actually fix all win platforms for GL bug
	#jira UE-43785

Change 3385557 on 2017/04/07 by Arne.Schober

	DR - [UE-43205] - Fix mesh paint
	#RB none

Change 3385608 on 2017/04/07 by Daniel.Wright

	Fixed SampleCmp being used on a non-depth texture, causing a d3d error

Change 3385980 on 2017/04/10 by Rolando.Caloca

	DR - Remove transition functions RHIClearColor* RHIClearDepthStencilTexture

Change 3386042 on 2017/04/10 by Rolando.Caloca

	DR - Fix metal merge issue

Change 3386157 on 2017/04/10 by Rolando.Caloca

	DR - Remove VS2013 libs generation off hlslcc & glslang (to match main)

Change 3386356 on 2017/04/10 by Chris.Bunner

	Resolving merge errors.

Change 3386414 on 2017/04/10 by Chris.Bunner

	Resolved merge issue in RendererScene.cpp.

Change 3386700 on 2017/04/10 by Mark.Satterthwaite

	Silence documentation warnings.

Change 3387178 on 2017/04/10 by Chris.Bunner

	Removed invalid mask correction on MakeMA material nodes.

Change 3388177 on 2017/04/11 by Marcus.Wassmer

	Disable ensure that is no longer relevant now that we bind clear colors on texture creation

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

	Static analysis fix.

[CL 3388266 by Chris Bunner in Main branch]
2017-04-11 10:32:07 -04:00

2274 lines
80 KiB
C++

#include "GPUFastFourierTransform.h"
#include "SceneUtils.h"
#include "GlobalShader.h"
#include "PostProcess/RenderTargetPool.h" // used for on-the-fly acquisition of
uint32 GPUFFT::MaxScanLineLength()
{
return 4096;
}
FString GPUFFT::FFT_TypeName(const FFT_XFORM_TYPE& XFormType)
{
if (XFormType == FFT_XFORM_TYPE::FORWARD_HORIZONTAL) return FString(TEXT("Forward Horizontal"));
if (XFormType == FFT_XFORM_TYPE::INVERSE_HORIZONTAL) return FString(TEXT("Inverse Horizontal"));
if (XFormType == FFT_XFORM_TYPE::FORWARD_VERTICAL) return FString(TEXT("Forward Vertical"));
if (XFormType == FFT_XFORM_TYPE::INVERSE_VERTICAL) return FString(TEXT("Inverse Vertical"));
return FString(TEXT("Error"));
}
bool GPUFFT::IsHorizontal(const FFT_XFORM_TYPE& XFormType)
{
return (XFormType == FFT_XFORM_TYPE::FORWARD_HORIZONTAL || XFormType == FFT_XFORM_TYPE::INVERSE_HORIZONTAL);
}
bool GPUFFT::IsForward(const FFT_XFORM_TYPE& XFormType)
{
return (XFormType == FFT_XFORM_TYPE::FORWARD_HORIZONTAL || XFormType == FFT_XFORM_TYPE::FORWARD_VERTICAL);
}
GPUFFT::FFTDescription::FFTDescription(const GPUFFT::FFT_XFORM_TYPE& XForm, const FIntPoint& XFormExtent)
:XFormType(XForm)
{
if (GPUFFT::IsHorizontal(XFormType))
{
SignalLength = XFormExtent.X;
NumScanLines = XFormExtent.Y;
}
else
{
SignalLength = XFormExtent.Y;
NumScanLines = XFormExtent.X;
}
}
FIntPoint GPUFFT::FFTDescription::TransformExtent() const
{
const bool bIsHornizontal = GPUFFT::IsHorizontal(XFormType);
FIntPoint Extent = (bIsHornizontal) ? FIntPoint(SignalLength, NumScanLines) : FIntPoint(NumScanLines, SignalLength);
return Extent;
}
bool GPUFFT::FFTDescription::IsHorizontal() const
{
return GPUFFT::IsHorizontal(XFormType);
}
bool GPUFFT::FFTDescription::IsForward() const
{
return GPUFFT::IsForward(XFormType);
}
FString GPUFFT::FFTDescription::FFT_TypeName() const
{
return GPUFFT::FFT_TypeName(XFormType);
}
namespace GPUFFT
{
// Encode the transform type in the lower two bits
static uint32 BitEncode(const GPUFFT::FFT_XFORM_TYPE& XFormType)
{
// put a 1 in the low bit for Horizontal
uint32 BitEncodedValue = GPUFFT::IsHorizontal(XFormType) ? 1 : 0;
// put a 1 in the second lowest bit for forward
if (GPUFFT::IsForward(XFormType))
{
BitEncodedValue |= 2;
}
return BitEncodedValue;
}
/**
* Computes the minimal number of bits required to represent the in number N
*/
uint32 BitSize(uint32 N)
{
uint32 Result = 0;
while (N > 0) {
N = N >> 1;
Result++;
}
return Result;
}
/**
* Decompose the input PowTwoLenght, as PowTwoLength = N X PowTwoBase X PowTwoBase X .. X PowTwoBase
* NB: This assumes the PowTwoLength and PowTwoBase are powers of two.
*/
TArray<uint32> GetFactors(const uint32 PowTwoLength, const uint32 PowTwoBase)
{
TArray<uint32> FactorList;
// Early out.
if (!FMath::IsPowerOfTwo(PowTwoLength) || !FMath::IsPowerOfTwo(PowTwoBase)) return FactorList;
const uint32 LogTwoLength = BitSize(PowTwoLength) - 1;
const uint32 LogTwoBase = BitSize(PowTwoBase) - 1;
const uint32 RemainderPower = LogTwoLength % LogTwoBase;
const uint32 BasePower = LogTwoLength / LogTwoBase;
for (uint32 idx = 0; idx < BasePower; idx++)
{
FactorList.Add(PowTwoBase);
}
if (RemainderPower != 0)
{
uint32 Factor = 1 << RemainderPower;
FactorList.Add(Factor);
}
return FactorList;
}
/**
* Double buffer to manage RenderTargets during multi-pass FFTs.
*/
class FDoubleBufferTargets
{
public:
FDoubleBufferTargets(FSceneRenderTargetItem& InitialSrc, FSceneRenderTargetItem& InitialDst) :
SrcIdx(0)
{
Targets[0] = &InitialSrc;
Targets[1] = &InitialDst;
}
void Swap() { SrcIdx = 1 - SrcIdx; }
// Return the index of the current Src target. If it is 0 than this is the original src, otherwise
// it is the original dst.
const uint32& GetSrcIdx() const { return SrcIdx; }
// Access to the render targets with a return by reference for clear ownership semantics
const FSceneRenderTargetItem& SrcTarget() const { return *Targets[SrcIdx]; }
FSceneRenderTargetItem& DstTarget() { return *Targets[1 - SrcIdx]; }
private:
uint32 SrcIdx;
FSceneRenderTargetItem* Targets[2];
};
}
namespace GPUFFT
{
class FReorderFFTPassCS : public FGlobalShader
{
// NB: the following is actually "public:"
// due to text in the DECLARE_SHADER_TYPE Macro
DECLARE_SHADER_TYPE(FReorderFFTPassCS, Global);
public:
typedef FFT_XFORM_TYPE FFT_XFORM_TYPE;
FReorderFFTPassCS() {};
FReorderFFTPassCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGlobalShader(Initializer)
{
using GPUFFTComputeShaderUtils::FComputeParameterBinder;
FComputeParameterBinder Binder(Initializer.ParameterMap);
Binder(SrcROTexture, TEXT("SrcSRV"))
(DstRWTexture, TEXT("DstUAV"))
(TransformType, TEXT("TransformType"))
(SrcRect, TEXT("SrcRect"))
(DstRect, TEXT("DstRect"))
(LogTransformLength, TEXT("LogTwoLength"))
(BitCount, TEXT("BitCount"));
}
// Used by IMPLEMENT_SHADER_TYPE2
static const TCHAR* GetSourceFilename() { return TEXT("GPUFastFourierTransform"); }
static const TCHAR* GetFunctionName() { return TEXT("ReorderFFTPassCS"); }
static bool ShouldCache(EShaderPlatform Platform)
{
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
OutEnvironment.SetDefine(TEXT("INCLUDE_REORDER_FFT_PASS"), 1);
}
void SetCSParamters(FRHICommandList& RHICmdList,
const FFT_XFORM_TYPE& XFormType,
const FTextureRHIRef& SrcTexture, const FIntRect& SrcRectValue, const FIntRect& DstRectValue, const uint32 TransformLength, const uint32 PowTwoSubLengthCount, const bool bScrubNaNs)
{
using GPUFFTComputeShaderUtils::FComputeParamterValueSetter;
const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader();
// Set up the input. We have to do this explicitly because the FFT dispatches multiple compute shaders and manages their input/output.
FComputeParamterValueSetter ParamSetter(RHICmdList, ShaderRHI);
ParamSetter(SrcROTexture, SrcTexture);
// Translate the transform type.
uint32 TransformTypeValue = GPUFFT::BitEncode(XFormType);
if (bScrubNaNs)
{
TransformTypeValue |= 4;
}
const uint32 BitCountValue = BitSize(PowTwoSubLengthCount) - 1;
const uint32 LogTwoTransformLength = BitSize(TransformLength) - 1;
ParamSetter(TransformType, TransformTypeValue)
(SrcRect, SrcRectValue)
(DstRect, DstRectValue)
(LogTransformLength, LogTwoTransformLength)
(BitCount, BitCountValue);
}
// Method for use with the FScopedUAVBind
FShaderResourceParameter& DestinationResourceParamter() { return DstRWTexture; }
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
Ar << SrcROTexture
<< DstRWTexture
<< TransformType
<< SrcRect
<< DstRect
<< LogTransformLength
<< BitCount;
return bShaderHasOutdatedParameters;
}
public:
FShaderResourceParameter SrcROTexture;
FShaderResourceParameter DstRWTexture;
FShaderParameter TransformType;
FShaderParameter SrcRect;
FShaderParameter DstRect;
FShaderParameter LogTransformLength;
FShaderParameter BitCount;
};
class FGroupShardSubFFTPassCS : public FGlobalShader
{
// NB: the following is actually "public:"
// due to text in the DECLARE_SHADER_TYPE Macro
DECLARE_SHADER_TYPE(FGroupShardSubFFTPassCS, Global);
public:
typedef FFT_XFORM_TYPE FFT_XFORM_TYPE;
FGroupShardSubFFTPassCS() {};
FGroupShardSubFFTPassCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGlobalShader(Initializer)
{
using GPUFFTComputeShaderUtils::FComputeParameterBinder;
FComputeParameterBinder Binder(Initializer.ParameterMap);
Binder(SrcROTexture, TEXT("SrcTexture"))
(DstRWTexture, TEXT("DstTexture"))
(TransformType, TEXT("TransformType"))
(SrcRect, TEXT("SrcWindow"))
(TransformLength, TEXT("TransformLength"))
(NumSubRegions, TEXT("NumSubRegions"));
}
// Used by IMPLEMENT_SHADER_TYPE2
static const TCHAR* GetSourceFilename() { return TEXT("GPUFastFourierTransform"); }
static const TCHAR* GetFunctionName() { return TEXT("GroupSharedSubComplexFFTCS"); }
static uint32 SubPassLength() { return 2048;}
static uint32 Radix() { return 2; }
static bool ShouldCache(EShaderPlatform Platform)
{
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
OutEnvironment.SetDefine(TEXT("INCLUDE_GROUP_SHARED_SUB_COMPLEX_FFT"), 1);
OutEnvironment.SetDefine(TEXT("SCAN_LINE_LENGTH"), FGroupShardSubFFTPassCS::SubPassLength());
OutEnvironment.SetDefine(TEXT("RADIX"), FGroupShardSubFFTPassCS::Radix());
}
void SetCSParamters(FRHICommandList& RHICmdList,
const FFT_XFORM_TYPE& XFormType,
const uint32 TransformLengthValue,
const FIntRect& WindowValue,
const FTextureRHIRef& SrcTexture,
const uint32 SubRegionCount)
{
using GPUFFTComputeShaderUtils::FComputeParamterValueSetter;
const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader();
// Set up the input. We have to do this explicitly because the FFT dispatches multiple compute shaders and manages their input/output.
FComputeParamterValueSetter ParamSetter(RHICmdList, ShaderRHI);
ParamSetter(SrcROTexture, SrcTexture);
// Translate the transform type.
uint32 TransformTypeValue = GPUFFT::BitEncode(XFormType);
ParamSetter(TransformType, TransformTypeValue)
(SrcRect, WindowValue)
(TransformLength, TransformLengthValue)
(NumSubRegions, SubRegionCount);
}
// Method for use with the FScopedUAVBind
FShaderResourceParameter& DestinationResourceParamter() { return DstRWTexture; }
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
Ar << SrcROTexture
<< DstRWTexture
<< TransformType
<< SrcRect
<< TransformLength
<< NumSubRegions;
return bShaderHasOutdatedParameters;
}
public:
FShaderResourceParameter SrcROTexture;
FShaderResourceParameter DstRWTexture;
FShaderParameter TransformType;
FShaderParameter SrcRect;
FShaderParameter TransformLength;
FShaderParameter NumSubRegions;
};
class FComplexFFTPassCS : public FGlobalShader
{
// NB: the following is actually "public:"
// due to text in the DECLARE_SHADER_TYPE Macro
DECLARE_SHADER_TYPE(FComplexFFTPassCS, Global);
public:
typedef FFT_XFORM_TYPE FFT_XFORM_TYPE;
FComplexFFTPassCS() {};
FComplexFFTPassCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGlobalShader(Initializer)
{
using GPUFFTComputeShaderUtils::FComputeParameterBinder;
FComputeParameterBinder Binder(Initializer.ParameterMap);
Binder(SrcROTexture, TEXT("SrcSRV"))
(DstRWTexture, TEXT("DstUAV"))
(TransformType, TEXT("TransformType"))
(SrcRect, TEXT("SrcRect"))
(DstRect, TEXT("DstRect"))
(BitCount, TEXT("BitCount"))
(PowTwoLength, TEXT("PowTwoLength"));
}
// Used by IMPLEMENT_SHADER_TYPE2
static const TCHAR* GetSourceFilename() { return TEXT("GPUFastFourierTransform"); }
static const TCHAR* GetFunctionName() { return TEXT("ComplexFFTPassCS"); }
static bool ShouldCache(EShaderPlatform Platform)
{
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
OutEnvironment.SetDefine(TEXT("INCLUDE_COMPLEX_FFT_PASS"), 1);
}
void SetCSParamters(FRHICommandList& RHICmdList,
const FFT_XFORM_TYPE& XFormType,
const FTextureRHIRef& SrcTexture, const FIntRect& SrcRectValue, const FIntRect& DstRectValue, const uint32 TransformLength, const uint32 PassLength, const bool bScrubNaNs)
{
const uint32 BitCountValue = BitSize(TransformLength);
const uint32 PowTwo = PassLength; // The pass number should be log(2, PassLength)
using GPUFFTComputeShaderUtils::FComputeParamterValueSetter;
const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader();
// Set up the input. We have to do this explicitly because the FFT dispatches multiple compute shaders and manages their input/output.
FComputeParamterValueSetter ParamSetter(RHICmdList, ShaderRHI);
ParamSetter(SrcROTexture, SrcTexture);
// Translate the transform type.
uint32 TransformTypeValue = GPUFFT::BitEncode(XFormType);
if (bScrubNaNs)
{
TransformTypeValue |= 4;
}
ParamSetter(TransformType, TransformTypeValue)
(SrcRect, SrcRectValue)
(DstRect, DstRectValue)
(BitCount, BitCountValue)
(PowTwoLength, PowTwo);
}
// Method for use with the FScopedUAVBind
FShaderResourceParameter& DestinationResourceParamter() { return DstRWTexture; }
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
Ar << SrcROTexture
<< DstRWTexture
<< TransformType
<< SrcRect
<< DstRect
<< BitCount
<< PowTwoLength;
return bShaderHasOutdatedParameters;
}
public:
FShaderResourceParameter SrcROTexture;
FShaderResourceParameter DstRWTexture;
FShaderParameter TransformType;
FShaderParameter SrcRect;
FShaderParameter DstRect;
FShaderParameter BitCount;
FShaderParameter PowTwoLength;
};
class FPackTwoForOneFFTPassCS : public FGlobalShader
{
// NB: the following is actually "public:"
// due to text in the DECLARE_SHADER_TYPE Macro
DECLARE_SHADER_TYPE(FPackTwoForOneFFTPassCS, Global);
public:
typedef FFT_XFORM_TYPE FFT_XFORM_TYPE;
FPackTwoForOneFFTPassCS() {};
FPackTwoForOneFFTPassCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGlobalShader(Initializer)
{
using GPUFFTComputeShaderUtils::FComputeParameterBinder;
FComputeParameterBinder Binder(Initializer.ParameterMap);
Binder(SrcROTexture, TEXT("SrcSRV"))
(DstRWTexture, TEXT("DstUAV"))
(TransformType, TEXT("TransformType"))
(DstRect, TEXT("DstRect"));
}
// Used by IMPLEMENT_SHADER_TYPE2
static const TCHAR* GetSourceFilename() { return TEXT("GPUFastFourierTransform"); }
static const TCHAR* GetFunctionName() { return TEXT("PackTwoForOneFFTPassCS"); }
static bool ShouldCache(EShaderPlatform Platform)
{
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
OutEnvironment.SetDefine(TEXT("INCLUDE_PACK_TWOFORONE_FFT_PASS"), 1);
}
void SetCSParamters(FRHICommandList& RHICmdList,
const FFT_XFORM_TYPE& XFormType,
const FTextureRHIRef& SrcTexture, const FIntRect& DstRectValue)
{
using GPUFFTComputeShaderUtils::FComputeParamterValueSetter;
const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader();
// Set up the input. We have to do this explicitly because the FFT dispatches multiple compute shaders and manages their input/output.
FComputeParamterValueSetter ParamSetter(RHICmdList, ShaderRHI);
ParamSetter(SrcROTexture, SrcTexture);
// Translate the transform type.
uint32 TransformTypeValue = GPUFFT::BitEncode(XFormType);
ParamSetter(TransformType, TransformTypeValue)
(DstRect, DstRectValue);
}
// Method for use with the FScopedUAVBind
FShaderResourceParameter& DestinationResourceParamter() { return DstRWTexture; }
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
Ar << SrcROTexture
<< DstRWTexture
<< TransformType
<< DstRect;
return bShaderHasOutdatedParameters;
}
public:
FShaderResourceParameter SrcROTexture;
FShaderResourceParameter DstRWTexture;
FShaderParameter TransformType;
FShaderParameter DstRect;
};
class FCopyWindowCS : public FGlobalShader
{
// NB: the following is actually "public:"
// due to text in the DECLARE_SHADER_TYPE Macro
DECLARE_SHADER_TYPE(FCopyWindowCS, Global);
public:
FCopyWindowCS() {};
FCopyWindowCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGlobalShader(Initializer)
{
using GPUFFTComputeShaderUtils::FComputeParameterBinder;
FComputeParameterBinder Binder(Initializer.ParameterMap);
Binder(SrcROTexture, TEXT("SrcSRV"))
(DstRWTexture, TEXT("DstUAV"))
(SrcRect, TEXT("SrcRect"))
(DstRect, TEXT("DstRect"))
(PreFilter, TEXT("BrightPixelGain"));
}
// Used by IMPLEMENT_SHADER_TYPE2
static const TCHAR* GetSourceFilename() { return TEXT("GPUFastFourierTransform"); }
static const TCHAR* GetFunctionName() { return TEXT("CopyWindowCS"); }
static uint32 XThreadCount() { return 1; }
static uint32 YThreadCount() { return 32; }
static bool ShouldCache(EShaderPlatform Platform)
{
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
OutEnvironment.SetDefine(TEXT("INCLUDE_COPY_WINDOW"), 1);
OutEnvironment.SetDefine(TEXT("X_THREAD_COUNT"), XThreadCount());
OutEnvironment.SetDefine(TEXT("Y_THREAD_COUNT"), YThreadCount());
}
void SetCSParamters(FRHICommandList& RHICmdList,
const FIntRect& SrcRectValue,
const FTextureRHIRef& SrcTexture, const FIntRect& DstRectValue,
const FPreFilter& PreFilterValue)
{
using GPUFFTComputeShaderUtils::FComputeParamterValueSetter;
const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader();
// Set up the input. We have to do this explicitly because the FFT dispatches multiple compute shaders and manages their input/output.
FComputeParamterValueSetter ParamSetter(RHICmdList, ShaderRHI);
ParamSetter(SrcROTexture, SrcTexture);
ParamSetter(SrcRect, SrcRectValue)
(DstRect, DstRectValue)
(PreFilter, PreFilterValue);
}
// Method for use with the FScopedUAVBind
FShaderResourceParameter& DestinationResourceParamter() { return DstRWTexture; }
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
Ar << SrcROTexture
<< DstRWTexture
<< SrcRect
<< DstRect
<< PreFilter;
return bShaderHasOutdatedParameters;
}
public:
FShaderResourceParameter SrcROTexture;
FShaderResourceParameter DstRWTexture;
FShaderParameter SrcRect;
FShaderParameter DstRect;
FShaderParameter PreFilter;
};
class FComplexMultiplyImagesCS : public FGlobalShader
{
// NB: the following is actually "public:"
// due to text in the DECLARE_SHADER_TYPE Macro
DECLARE_SHADER_TYPE(FComplexMultiplyImagesCS, Global);
public:
FComplexMultiplyImagesCS() {};
FComplexMultiplyImagesCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGlobalShader(Initializer)
{
using GPUFFTComputeShaderUtils::FComputeParameterBinder;
FComputeParameterBinder Binder(Initializer.ParameterMap);
Binder(SrcROTexture, TEXT("SrcSRV"))
(KnlROTexture, TEXT("KnlSRV"))
(DstRWTexture, TEXT("DstUAV"))
(SrcRect, TEXT("SrcRect"))
(DataLayout, TEXT("DataLayout"));
}
// Used by IMPLEMENT_SHADER_TYPE2
static const TCHAR* GetSourceFilename() { return TEXT("GPUFastFourierTransform"); }
static const TCHAR* GetFunctionName() { return TEXT("ComplexMultiplyImagesCS"); }
static bool ShouldCache(EShaderPlatform Platform)
{
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
OutEnvironment.SetDefine(TEXT("INCLUDE_COMPLEX_MULTIPLY_IMAGES"), 1);
}
void SetCSParamters(FRHICommandList& RHICmdList,
const bool bHorizontalScanlines,
const FIntRect& SrcRectValue,
const FTextureRHIRef& SrcTexture,
const FTextureRHIRef& KnlTexture)
{
using GPUFFTComputeShaderUtils::FComputeParamterValueSetter;
const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader();
const uint32 DataLayoutValue = (bHorizontalScanlines) ? 1 : 0;
// Set up the input. We have to do this explicitly because the FFT dispatches multiple compute shaders and manages their input/output.
FComputeParamterValueSetter ParamSetter(RHICmdList, ShaderRHI);
ParamSetter(SrcROTexture, SrcTexture)
(KnlROTexture, KnlTexture)
(SrcRect, SrcRectValue)
(DataLayout, DataLayoutValue);
}
// Method for use with the FScopedUAVBind
FShaderResourceParameter& DestinationResourceParamter() { return DstRWTexture; }
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
Ar << SrcROTexture
<< KnlROTexture
<< DstRWTexture
<< SrcRect
<< DataLayout;
return bShaderHasOutdatedParameters;
}
public:
FShaderResourceParameter SrcROTexture;
FShaderResourceParameter KnlROTexture;
FShaderResourceParameter DstRWTexture;
FShaderParameter SrcRect;
FShaderParameter DataLayout;
};
class FGSComplexTransformBaseCS : public FGlobalShader
{
public:
typedef FFT_XFORM_TYPE FFT_XFORM_TYPE;
FGSComplexTransformBaseCS() {};
FGSComplexTransformBaseCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGlobalShader(Initializer)
{
using GPUFFTComputeShaderUtils::FComputeParameterBinder;
FComputeParameterBinder Binder(Initializer.ParameterMap);
Binder(SrcROTexture, TEXT("SrcTexture"))
(DstRWTexture, TEXT("DstTexture"))
(TransformType, TEXT("TransformType"))
(SrcRectMin, TEXT("SrcRectMin"))
(SrcRectMax, TEXT("SrcRectMax"))
(DstExtent, TEXT("DstExtent"))
(DstRect, TEXT("DstRect"))
(BrightPixelGain, TEXT("BrightPixelGain"));
}
void SetCSParamters(FRHICommandList& RHICmdList,
const FFT_XFORM_TYPE& XFormType,
const FTextureRHIRef& SrcTexture, const FIntRect& SrcRect, const FIntRect& DstRectValue,
const GPUFFT::FPreFilter& PreFilterParameters = GPUFFT::FPreFilter(TNumericLimits<float>::Max(), TNumericLimits<float>::Lowest(), 0.f))
{
using GPUFFTComputeShaderUtils::FComputeParamterValueSetter;
const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader();
// Set up the input. We have to do this explicitly because the FFT dispatches multiple compute shaders and manages their input/output.
FComputeParamterValueSetter ParamSetter(RHICmdList, ShaderRHI);
ParamSetter(SrcROTexture, SrcTexture);
// Translate the transform type.
uint32 TransformTypeValue = GPUFFT::BitEncode(XFormType);
// We have a valid prefilter if the min is less than the max
if (PreFilterParameters.Component(0) < PreFilterParameters.Component(1))
{
// Encode a bool to turn on the pre-filter.
TransformTypeValue |= 4;
}
ParamSetter(TransformType, TransformTypeValue)
(SrcRectMin, SrcRect.Min)
(SrcRectMax, SrcRect.Max)
(DstRect, DstRectValue)
(DstExtent, DstRectValue.Size())
(BrightPixelGain, PreFilterParameters);
}
// Method for use with the FScopedUAVBind
FShaderResourceParameter& DestinationResourceParamter() { return DstRWTexture; }
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
Ar << SrcROTexture
<< DstRWTexture
<< TransformType
<< SrcRectMin
<< SrcRectMax
<< DstExtent
<< DstRect
<< BrightPixelGain;
return bShaderHasOutdatedParameters;
}
public:
FShaderResourceParameter SrcROTexture;
FShaderResourceParameter DstRWTexture;
FShaderParameter TransformType;
FShaderParameter SrcRectMin;
FShaderParameter SrcRectMax;
FShaderParameter DstExtent;
FShaderParameter DstRect;
FShaderParameter BrightPixelGain;
};
template <int PowRadixSignalLength>
class TGSComplexTransformCS : public FGSComplexTransformBaseCS
{
// NB: the following is actually "public:"
// due to text in the DECLARE_SHADER_TYPE Macro
DECLARE_SHADER_TYPE(TGSComplexTransformCS, Global);
// Used by IMPLEMENT_SHADER_TYPE2
static const TCHAR* GetSourceFilename() { return TEXT("GPUFastFourierTransform"); }
static const TCHAR* GetFunctionName() { return TEXT("GroupSharedComplexFFTCS"); }
static bool ShouldCache(EShaderPlatform Platform)
{
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
OutEnvironment.SetDefine(TEXT("INCLUDE_GROUP_SHARED_COMPLEX_FFT"), 1);
OutEnvironment.SetDefine(TEXT("SCAN_LINE_LENGTH"), PowRadixSignalLength);
}
/** Default constructor **/
TGSComplexTransformCS() {};
public:
TGSComplexTransformCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGSComplexTransformBaseCS(Initializer)
{}
};
template < int PowRadixSignalLength>
class TGSTwoForOneTransformCS : public FGSComplexTransformBaseCS
{
// NB: the following is actually "public:"
// due to text in the DECLARE_SHADER_TYPE Macro
DECLARE_SHADER_TYPE(TGSTwoForOneTransformCS, Global);
// Used by IMPLEMENT_SHADER_TYPE2
static const TCHAR* GetSourceFilename() { return TEXT("GPUFastFourierTransform"); }
static const TCHAR* GetFunctionName() { return TEXT("GroupSharedTwoForOneFFTCS"); }
static bool ShouldCache(EShaderPlatform Platform)
{
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
OutEnvironment.SetDefine(TEXT("INCLUDE_GROUP_SHARED_TWO_FOR_ONE_FFT"), 1);
OutEnvironment.SetDefine(TEXT("SCAN_LINE_LENGTH"), PowRadixSignalLength);
}
/** Default constructor **/
TGSTwoForOneTransformCS() {};
public:
TGSTwoForOneTransformCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGSComplexTransformBaseCS(Initializer)
{}
};
/**
* Base class used for 1d convolution.
*/
class FGSConvolutionBaseCS : public FGlobalShader
{
public:
FGSConvolutionBaseCS() {};
FGSConvolutionBaseCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGlobalShader(Initializer)
{
using GPUFFTComputeShaderUtils::FComputeParameterBinder;
FComputeParameterBinder Binder(Initializer.ParameterMap);
Binder(SrcROTexture, TEXT("SrcTexture"))
(DstRWTexture, TEXT("DstTexture"))
(SrcRectMin, TEXT("SrcRectMin"))
(SrcRectMax, TEXT("SrcRectMax"))
(DstExtent, TEXT("DstExtent"))
(TransformType, TEXT("TransformType"));
}
// @todo - template this on KernelType. Have KernelType know how to do its own SetShaderValue
// Note: We pass in the 2d spectral size (transform size) to help the filter
void SetCSParamters(FRHICommandList& RHICmdList, const FFT_XFORM_TYPE& XFormType,
const FTextureRHIRef& SrcTexture, const FIntRect& SrcRect, const FIntPoint& DstExtentValue)
{
using GPUFFTComputeShaderUtils::FComputeParamterValueSetter;
// Translate the transform type.
uint32 TransformTypeValue = GPUFFT::BitEncode(XFormType);
const bool bUseAlpha = true;
if (bUseAlpha)
{
TransformTypeValue |= 8;
}
const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader();
// Set up the input. We have to do this explicitly because the FFT dispatches multiple compute shaders and manages their input/output.
FComputeParamterValueSetter ParamSetter(RHICmdList, ShaderRHI);
ParamSetter(SrcROTexture, SrcTexture); // set the texture
// set all the other parameters
ParamSetter(SrcRectMin, SrcRect.Min)
(SrcRectMax, SrcRect.Max)
(DstExtent, DstExtentValue)
(TransformType, TransformTypeValue);
}
// Method for use with the FScopedUAVBind
FShaderResourceParameter& DestinationResourceParamter() { return DstRWTexture; }
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGlobalShader::Serialize(Ar);
Ar << SrcROTexture
<< DstRWTexture
<< SrcRectMin
<< SrcRectMax
<< DstExtent
<< TransformType;
return bShaderHasOutdatedParameters;
}
public:
FShaderResourceParameter SrcROTexture;
FShaderResourceParameter DstRWTexture;
FShaderParameter SrcRectMin;
FShaderParameter SrcRectMax;
FShaderParameter DstExtent;
FShaderParameter TransformType;
};
/**
* Common class used by the shader permutations of the convolution with texture
*/
class FGSConvolutionWithTextureKernelBaseCS : public FGSConvolutionBaseCS
{
public:
FGSConvolutionWithTextureKernelBaseCS() {};
FGSConvolutionWithTextureKernelBaseCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGSConvolutionBaseCS(Initializer)
{
GPUFFTComputeShaderUtils::FComputeParameterBinder Binder(Initializer.ParameterMap);
Binder(FilterSrcROTexture, TEXT("FilterTexture"));
}
// Used by IMPLEMENT_SHADER_TYPE2
static const TCHAR* GetSourceFilename() { return TEXT("GPUFastFourierTransform"); }
static const TCHAR* GetFunctionName() { return TEXT("GSConvolutionWithTextureCS"); }
// @todo - template this on KernelType. Have KernelType know how to do its own SetShaderValue
// Note: We pass in the 2d spectral size (transform size) to help the filter
void SetCSParamters(FRHICommandList& RHICmdList,
const FFT_XFORM_TYPE& XFormType,
const FTextureRHIRef& FilterSrcTexture,
const FTextureRHIRef& SrcTexture, const FIntRect& SrcRect, const FIntPoint& DstExtentValue)
{
FGSConvolutionBaseCS::SetCSParamters(RHICmdList, XFormType, SrcTexture, SrcRect, DstExtentValue);
// additional source input for sampling the spectral texture
const FComputeShaderRHIParamRef ShaderRHI = GetComputeShader();
GPUFFTComputeShaderUtils::FComputeParamterValueSetter ParamSetter(RHICmdList, ShaderRHI);
// set the texture
ParamSetter(FilterSrcROTexture, FilterSrcTexture);
}
// FShader interface.
virtual bool Serialize(FArchive& Ar) override
{
bool bShaderHasOutdatedParameters = FGSConvolutionBaseCS::Serialize(Ar);
Ar << FilterSrcROTexture;
return bShaderHasOutdatedParameters;
}
public:
FShaderResourceParameter FilterSrcROTexture;
};
template <int PowRadixSignalLength>
class TGSConvolutionWithTexturerCS : public FGSConvolutionWithTextureKernelBaseCS
{
// NB: the following is actually "public:"
// due to text in the DECLARE_SHADER_TYPE Macro
DECLARE_SHADER_TYPE(TGSConvolutionWithTexturerCS, Global);
static bool ShouldCache(EShaderPlatform Platform)
{
return IsFeatureLevelSupported(Platform, ERHIFeatureLevel::SM5);
}
static void ModifyCompilationEnvironment(EShaderPlatform Platform, FShaderCompilerEnvironment& OutEnvironment)
{
FGlobalShader::ModifyCompilationEnvironment(Platform, OutEnvironment);
OutEnvironment.SetDefine(TEXT("INCLUDE_GROUP_SHARED_CONVOLUTION_WITH_TEXTURE"), 1);
OutEnvironment.SetDefine(TEXT("SCAN_LINE_LENGTH"), PowRadixSignalLength);
}
/** Default constructor **/
TGSConvolutionWithTexturerCS() {};
public:
TGSConvolutionWithTexturerCS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
: FGSConvolutionWithTextureKernelBaseCS(Initializer)
{}
};
void SwapContents(FSceneRenderTargetItem& TmpBuffer, FSceneRenderTargetItem& DstBuffer)
{
// Swap the pointers
FSceneRenderTargetItem TmpDst = DstBuffer;
DstBuffer = TmpBuffer;
TmpBuffer = TmpDst;
}
} // end namespace
IMPLEMENT_SHADER_TYPE3(GPUFFT::FReorderFFTPassCS, SF_Compute);
IMPLEMENT_SHADER_TYPE3(GPUFFT::FGroupShardSubFFTPassCS, SF_Compute);
IMPLEMENT_SHADER_TYPE3(GPUFFT::FComplexFFTPassCS, SF_Compute);
IMPLEMENT_SHADER_TYPE3(GPUFFT::FPackTwoForOneFFTPassCS, SF_Compute);
IMPLEMENT_SHADER_TYPE3(GPUFFT::FCopyWindowCS, SF_Compute);
IMPLEMENT_SHADER_TYPE3(GPUFFT::FComplexMultiplyImagesCS, SF_Compute);
#define GROUPSHARED_COMPLEX_TRANSFORM(_Length) \
typedef GPUFFT::TGSComplexTransformCS< _Length> FGSComplexTransformCSLength##_Length; \
IMPLEMENT_SHADER_TYPE2(FGSComplexTransformCSLength##_Length, SF_Compute);
GROUPSHARED_COMPLEX_TRANSFORM(2) GROUPSHARED_COMPLEX_TRANSFORM(16) GROUPSHARED_COMPLEX_TRANSFORM(128) GROUPSHARED_COMPLEX_TRANSFORM(1024)
GROUPSHARED_COMPLEX_TRANSFORM(4) GROUPSHARED_COMPLEX_TRANSFORM(32) GROUPSHARED_COMPLEX_TRANSFORM(256) GROUPSHARED_COMPLEX_TRANSFORM(2048)
GROUPSHARED_COMPLEX_TRANSFORM(8) GROUPSHARED_COMPLEX_TRANSFORM(64) GROUPSHARED_COMPLEX_TRANSFORM(512) GROUPSHARED_COMPLEX_TRANSFORM(4096)
// NB: FFTBLOCK(8192, false/true) won't work because the max number of threads in a group 1024 is less than the requested 8192 / 2
#undef GROUPSHARED_COMPLEX_TRANSFORM
#define GROUPSHARED_TWO_FOR_ONE_TRANSFORM(_Length) \
typedef GPUFFT::TGSTwoForOneTransformCS<_Length> FGSTwoForOneTransformCSLength##_Length; \
IMPLEMENT_SHADER_TYPE2(FGSTwoForOneTransformCSLength##_Length, SF_Compute);
GROUPSHARED_TWO_FOR_ONE_TRANSFORM(2) GROUPSHARED_TWO_FOR_ONE_TRANSFORM(16) GROUPSHARED_TWO_FOR_ONE_TRANSFORM(128) GROUPSHARED_TWO_FOR_ONE_TRANSFORM(1024)
GROUPSHARED_TWO_FOR_ONE_TRANSFORM(4) GROUPSHARED_TWO_FOR_ONE_TRANSFORM(32) GROUPSHARED_TWO_FOR_ONE_TRANSFORM(256) GROUPSHARED_TWO_FOR_ONE_TRANSFORM(2048)
GROUPSHARED_TWO_FOR_ONE_TRANSFORM(8) GROUPSHARED_TWO_FOR_ONE_TRANSFORM(64) GROUPSHARED_TWO_FOR_ONE_TRANSFORM(512) GROUPSHARED_TWO_FOR_ONE_TRANSFORM(4096)
// NB: FFTBLOCK(8192, false/true) won't work because the max number of threads in a group 1024 is less than the requested 8192 / 2
#undef GROUPSHARED_TWO_FOR_ONE_TRANSFORM
#define GROUPSHARED_CONVOLUTION_WTEXTURE(_Length) \
typedef GPUFFT::TGSConvolutionWithTexturerCS<_Length > FGSConvolutionWithTextureCSLength##_Length; \
IMPLEMENT_SHADER_TYPE2(FGSConvolutionWithTextureCSLength##_Length, SF_Compute);
GROUPSHARED_CONVOLUTION_WTEXTURE(2) GROUPSHARED_CONVOLUTION_WTEXTURE(16) GROUPSHARED_CONVOLUTION_WTEXTURE(128) GROUPSHARED_CONVOLUTION_WTEXTURE(1024)
GROUPSHARED_CONVOLUTION_WTEXTURE(4) GROUPSHARED_CONVOLUTION_WTEXTURE(32) GROUPSHARED_CONVOLUTION_WTEXTURE(256) GROUPSHARED_CONVOLUTION_WTEXTURE(2048)
GROUPSHARED_CONVOLUTION_WTEXTURE(8) GROUPSHARED_CONVOLUTION_WTEXTURE(64) GROUPSHARED_CONVOLUTION_WTEXTURE(512) GROUPSHARED_CONVOLUTION_WTEXTURE(4096)
//GROUPSHARED_CONVOLUTION_WTEXTURE(2, 8192)
// NB: FFTBLOCK(2, 4196, false/true) won't work because the max number of threads in a group 1024 is less than the requested 4196 / 2
#undef GROUPSHARED_CONVOLUTION_WTEXTURE
namespace
{
using namespace GPUFFT;
FCopyWindowCS* GetCopyWindowCS(const FGPUFFTShaderContext::ShaderMapType& ShaderMap)
{
return ShaderMap.GetShader<FCopyWindowCS>();
}
FComplexMultiplyImagesCS* GetComplexMultiplyImagesCS(const FGPUFFTShaderContext::ShaderMapType& ShaderMap)
{
return ShaderMap.GetShader<FComplexMultiplyImagesCS>();
}
FGroupShardSubFFTPassCS* GetGroupSharedSubFFTPassCS(const FGPUFFTShaderContext::ShaderMapType& ShaderMap, const uint32 TransformLength)
{
return ShaderMap.GetShader<FGroupShardSubFFTPassCS>();
}
FReorderFFTPassCS* GetReorderFFTPassCS(const FGPUFFTShaderContext::ShaderMapType& ShaderMap)
{
return ShaderMap.GetShader<FReorderFFTPassCS>();
}
FPackTwoForOneFFTPassCS* GetPackTwoForOneFFTPassCS(const FGPUFFTShaderContext::ShaderMapType& ShaderMap, const uint32 TransformLength)
{
return ShaderMap.GetShader<FPackTwoForOneFFTPassCS>();
}
FComplexFFTPassCS* GetComplexFFTPassCS(const FGPUFFTShaderContext::ShaderMapType& ShaderMap, const uint32 TransformLength)
{
FComplexFFTPassCS* Result = ShaderMap.GetShader<FComplexFFTPassCS>();
return Result;
}
// Shader Permutation picker.
FGSComplexTransformBaseCS* GetComplexFFTCS(const FGPUFFTShaderContext::ShaderMapType& ShaderMap, const uint32 TransformLength)
{
FGSComplexTransformBaseCS* Result = NULL;
#define GET_COMPLEX_SHADER(_LENGTH) ShaderMap.GetShader<TGSComplexTransformCS<_LENGTH>>();
switch (TransformLength)
{
case 2: Result = GET_COMPLEX_SHADER(2); break;
case 4: Result = GET_COMPLEX_SHADER(4); break;
case 8: Result = GET_COMPLEX_SHADER(8); break;
case 16: Result = GET_COMPLEX_SHADER(16); break;
case 32: Result = GET_COMPLEX_SHADER(32); break;
case 64: Result = GET_COMPLEX_SHADER(64); break;
case 128: Result = GET_COMPLEX_SHADER(128); break;
case 256: Result = GET_COMPLEX_SHADER(256); break;
case 512: Result = GET_COMPLEX_SHADER(512); break;
case 1024: Result = GET_COMPLEX_SHADER(1024); break;
case 2048: Result = GET_COMPLEX_SHADER(2048); break;
case 4096: Result = GET_COMPLEX_SHADER(4096); break;
//case 8192: Result = GET_COMPLEX_SHADER(2, 8192); break;
default:
ensureMsgf(0, TEXT("The FFT block height is not supported"));
break;
}
#undef GET_COMPLEX_SHADER
return Result;
}
// Shader Permutation picker.
FGSComplexTransformBaseCS* GetTwoForOneFFTCS(const FGPUFFTShaderContext::ShaderMapType& ShaderMap, const uint32 TransformLength)
{
FGSComplexTransformBaseCS* Result = NULL;
#define GET_TWOFORONE_SHADER(_LENGTH) ShaderMap.GetShader<TGSTwoForOneTransformCS<_LENGTH>>();
switch (TransformLength)
{
case 2: Result = GET_TWOFORONE_SHADER(2); break;
case 4: Result = GET_TWOFORONE_SHADER(4); break;
case 8: Result = GET_TWOFORONE_SHADER(8); break;
case 16: Result = GET_TWOFORONE_SHADER(16); break;
case 32: Result = GET_TWOFORONE_SHADER(32); break;
case 64: Result = GET_TWOFORONE_SHADER(64); break;
case 128: Result = GET_TWOFORONE_SHADER(128); break;
case 256: Result = GET_TWOFORONE_SHADER(256); break;
case 512: Result = GET_TWOFORONE_SHADER(512); break;
case 1024: Result = GET_TWOFORONE_SHADER(1024); break;
case 2048: Result = GET_TWOFORONE_SHADER(2048); break;
case 4096: Result = GET_TWOFORONE_SHADER(4096); break;
//case 8192: Result = GET_TWOFORONE_SHADER(2, 8192); break;
default:
ensureMsgf(0, TEXT("The FFT block height is not supported"));
break;
}
#undef GET_TWOFORONE_SHADER
return Result;
}
FGSConvolutionWithTextureKernelBaseCS* GetConvolutionWithTextureKernelCS(const FGPUFFTShaderContext::ShaderMapType& ShaderMap, const uint32 TransformLength)
{
FGSConvolutionWithTextureKernelBaseCS* Result = NULL;
// Get the spectral filter.
#define GET_GROUP_SHARED_TEXTURE_FILTER(_LENGTH) ShaderMap.GetShader< TGSConvolutionWithTexturerCS<_LENGTH> >();
switch (TransformLength)
{
case 2: Result = GET_GROUP_SHARED_TEXTURE_FILTER(2); break;
case 4: Result = GET_GROUP_SHARED_TEXTURE_FILTER(4); break;
case 8: Result = GET_GROUP_SHARED_TEXTURE_FILTER(8); break;
case 16: Result = GET_GROUP_SHARED_TEXTURE_FILTER(16); break;
case 32: Result = GET_GROUP_SHARED_TEXTURE_FILTER(32); break;
case 64: Result = GET_GROUP_SHARED_TEXTURE_FILTER(64); break;
case 128: Result = GET_GROUP_SHARED_TEXTURE_FILTER(128); break;
case 256: Result = GET_GROUP_SHARED_TEXTURE_FILTER(256); break;
case 512: Result = GET_GROUP_SHARED_TEXTURE_FILTER(512); break;
case 1024: Result = GET_GROUP_SHARED_TEXTURE_FILTER(1024); break;
case 2048: Result = GET_GROUP_SHARED_TEXTURE_FILTER(2048); break;
case 4096: Result = GET_GROUP_SHARED_TEXTURE_FILTER(4096); break;
//case 8192: Result = GET_GROUP_SHARED_TEXTURE_FILTER(2, 8192); break;
default:
ensureMsgf(0, TEXT("The FFT block height is not supported"));
break;
}
#undef GET_GROUP_SHARED_TEXTURE_FILTER
return Result;
}
/**
* Single Pass that Copies a sub-region of a buffer and potentially
* boosts the intensity of select pixels.
*
* Assumes the dst buffer is large enough to hold the result.
* The Src float4 data is interpreted as a pair of independent complex numbers.
* The Knl float4 data is interpreted as a pair of independent complex numbers
*
* @param Context - container for RHI and ShanderMap
* @param SrcWindow - The region of interest to copy.
* @param SrcTexture - SRV the source image buffer.
* @param DstWindow - The target location for the images.
*
* @param DstUAV - UAV, the destination buffer that will hold the result of the single pass
* @param Prefilter - Optional filter to boost selected pixels.
*/
void DispatchCopyWindowCS(FGPUFFTShaderContext& Context,
const FIntRect& SrcWindow, const FTextureRHIRef& SrcTexture,
const FIntRect& DstWindow, FUnorderedAccessViewRHIRef& DstUAV,
const FPreFilter& PreFilter = FPreFilter(TNumericLimits<float>::Max(), TNumericLimits<float>::Lowest(), 0.f))
{
using namespace GPUFFTComputeShaderUtils;
// The size of the dst
const FIntPoint DstExtent = DstWindow.Size();
const uint32 XThreadCount = FCopyWindowCS::XThreadCount();
const uint32 YThreadCount = FCopyWindowCS::YThreadCount();
// Number of thread groups
const uint32 XGroups = ( DstExtent.X / XThreadCount ) + ( (DstExtent.X % XThreadCount == 0) ? 0 : 1 );
const uint32 YGroups = ( DstExtent.Y / YThreadCount ) + ( (DstExtent.Y % YThreadCount == 0) ? 0 : 1 );
const FGPUFFTShaderContext::ShaderMapType& ShaderMap = Context.GetShaderMap();
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
SCOPED_DRAW_EVENTF(RHICmdList, CopyWindowCS, TEXT("FFT Multipass: Copy Subwindow"));
// Get pointer to the shader
FCopyWindowCS* ComputeShader = GetCopyWindowCS(ShaderMap);
SetRenderTarget(RHICmdList, FTextureRHIRef(), FTextureRHIRef());
RHICmdList.SetComputeShader(ComputeShader->GetComputeShader());
// Bind output
FScopedUAVBind ScopedBind = FScopedUAVBind::BindOutput(RHICmdList, *ComputeShader, DstUAV);
ComputeShader->SetCSParamters(RHICmdList, SrcWindow, SrcTexture, DstWindow, PreFilter);
// Dispatch with a single thread-group for each "column" in the result where the transform direction is the "row" direction.
RHICmdList.DispatchComputeShader(XGroups, YGroups, 1);
}
/**
*
* Single Pass that computes the Frequency Space convolution of two buffers
* that have already been transformed into frequency space.
*
* This is really means the complex product of two buffers divided
* by the correct values to "normalize" the effect of the kernel buffer.
*
* In this case, each float4 is viewed as a pair of complex numbers,
* and the product of float4 Src, Knl is computed
* as float4(ComplexMult(Src.xy, Knl.xy) / Na, ComplexMult(Src.zw, Knl.zw)/Nb)
* where Na and Nb are related to the sums of the weights in the kernel buffer.
*
* Assumes the dst buffer is large enough to hold the result.
* The Src float4 data is interpreted as a pair of independent complex numbers.
* The Knl float4 data is interpreted as a pair of independent complex numbers
*
* @param Context - container for RHI and ShanderMap
* @param bHorizontalFirst - Describes the layout of the transformed data.
* bHorizontalFirst == true for data that was transformed as
* Vertical::ComplexFFT following Horizontal::TwoForOneRealFFT
* bHorizontalFirst == false for data that was transformed as
* Horizontal::ComplexFFT following Vertical::TwoForOneRealFFT
* @param SrcTexture - SRV the source image buffer.
* @param KnlTexture - SRV the kernel image buffer.
*
* @param DstUAV - UAV, the destination buffer that will hold the result of the single pass
*
*/
void DispatchComplexMultiplyImagesCS(FGPUFFTShaderContext& Context,
const bool bHorizontalScanlines,
const FIntRect& SrcWindow, const FTextureRHIRef& SrcTexture,
const FTextureRHIRef& KnlTexure,
FUnorderedAccessViewRHIRef& DstUAV)
{
using namespace GPUFFTComputeShaderUtils;
// The size of the dst
const FIntPoint DstExtent = SrcWindow.Size();
const FGPUFFTShaderContext::ShaderMapType& ShaderMap = Context.GetShaderMap();
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
SCOPED_DRAW_EVENTF(RHICmdList, ComplexMultiplyImagesCS, TEXT("FFT Multipass: Convolution in freq-space"));
// Get pointer to the shader
FComplexMultiplyImagesCS* ComputeShader = GetComplexMultiplyImagesCS(ShaderMap);
SetRenderTarget(RHICmdList, FTextureRHIRef(), FTextureRHIRef());
RHICmdList.SetComputeShader(ComputeShader->GetComputeShader());
// Bind output
FScopedUAVBind ScopedBind = FScopedUAVBind::BindOutput(RHICmdList, *ComputeShader, DstUAV);
ComputeShader->SetCSParamters(RHICmdList, bHorizontalScanlines, SrcWindow, SrcTexture, KnlTexure);
// Align the scanlines in the direction of the first transform.
const uint32 NumScanLines = (bHorizontalScanlines) ? DstExtent.Y : DstExtent.X;
const uint32 SignalLength = (!bHorizontalScanlines) ? DstExtent.Y : DstExtent.X;
// Dispatch with a single thread-group for each "column."
// Configured this way because the entire column will share the same normalization values (retrieved from the kernel)
//RHICmdList.DispatchComputeShader(1, ThreadGroupsPerScanline, NumScanLines);
RHICmdList.DispatchComputeShader(1, 1, NumScanLines);
}
/**
* Single Pass that separates or merges the transform of four real signals from
* viewed as the transform of two complex signals.
*
* Assumes the dst buffer is large enough to hold the result.
* The Src float4 data is interprets as a pair of independent complex numbers.
*
* @param Context - container for RHI and ShanderMap
* @param FFTDesc - Metadata that describes the underlying complex FFT
* @param SrcTexture - SRV the source image buffer
* @param DstUAV - UAV, the destination buffer that will hold the result of the single pass
*
* The data in the SrcTexture and DstUAV is aligned with (0,0).
* FFTDesc.IsHorizontal() indicates the transform direction in the buffer that needs to be spit/merged
* FFTDesc.IsForward() indicates spit (true) vs merge (false).
*/
void DispatchPackTwoForOneFFTPassCS(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const FTextureRHIRef& SrcTexture, FUnorderedAccessViewRHIRef& DstUAV)
{
using namespace GPUFFTComputeShaderUtils;
const FGPUFFTShaderContext::ShaderMapType& ShaderMap = Context.GetShaderMap();
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
const uint32 TransformLength = FFTDesc.SignalLength;
const FString TransformName = FFTDesc.FFT_TypeName();
// A real signal of length 'TransformLenght' requires only TransformLength / 2 + 1 complex coefficients,
const uint32 RealTransformLength = ( TransformLength / 2 ) + 1;
// The splitting into two real signals (isForward) or joinging back into a single signal
const uint32 ResultingLength = (FFTDesc.IsForward()) ? 2 * RealTransformLength : TransformLength;
SCOPED_DRAW_EVENTF(RHICmdList, PackTwoForOneFFTPass, TEXT("FFT Multipass: TwoForOne Combine/split result of %s of size %d"), *TransformName, TransformLength);
FIntPoint DstExtent = FFTDesc.TransformExtent();
if (FFTDesc.IsHorizontal())
{
DstExtent.X = ResultingLength;
}
else
{
DstExtent.Y = ResultingLength;
}
// Get pointer to the shader
FPackTwoForOneFFTPassCS* ComputeShader = GetPackTwoForOneFFTPassCS(ShaderMap, TransformLength);
SetRenderTarget(RHICmdList, FTextureRHIRef(), FTextureRHIRef());
RHICmdList.SetComputeShader(ComputeShader->GetComputeShader());
// Bind output
FScopedUAVBind ScopedBind = FScopedUAVBind::BindOutput(RHICmdList, *ComputeShader, DstUAV);
ComputeShader->SetCSParamters(RHICmdList, FFTDesc.XFormType, SrcTexture, FIntRect(FIntPoint(0, 0), DstExtent));
// Dispatch with a single thread-group for each "column" in the result where the transform direction is the "row" direction.
RHICmdList.DispatchComputeShader(1, 1, RealTransformLength);
}
/**
* Single Pass of a multi-pass complex FFT.
* Assumes the dst buffer is large enough to hold the result.
* The Src float4 data is interpt as a pair of independent complex numbers.
*
* @param Context - container for RHI and ShanderMap
* @param FFTDesc - Metadata that describes the underlying complex FFT
* @param PassStage - The Depth at which this FFT pass lives.
* @param SrcTexture - SRV the source image buffer
* @param SrcRct - The region in the Src buffer where the image to transform lives.
* @param DstUAV - UAV, the destination buffer that will hold the result of the single pass
*
*/
void DispatchComplexFFTPassCS(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const uint32 PassLength,
const FTextureRHIRef& SrcTexture, const FIntRect& SrcWindow,
FUnorderedAccessViewRHIRef& DstUAV,
const bool bScrubNaNs = false)
{
// Using multiple radix two passes.
const uint32 Radix = 2;
using namespace GPUFFTComputeShaderUtils;
const FGPUFFTShaderContext::ShaderMapType& ShaderMap = Context.GetShaderMap();
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
const uint32 TransformLength = FFTDesc.SignalLength;
const FString TransformName = FFTDesc.FFT_TypeName();
SCOPED_DRAW_EVENTF(RHICmdList, ComplexFFTPass, TEXT("FFT Multipass: Pass %d of Complex %s of size %d"), PassLength, *TransformName, TransformLength);
FIntPoint DstExtent = FFTDesc.TransformExtent();
// Get a base pointer to the shader
FComplexFFTPassCS* ComputeShader = GetComplexFFTPassCS(ShaderMap, TransformLength);
SetRenderTarget(RHICmdList, FTextureRHIRef(), FTextureRHIRef());
RHICmdList.SetComputeShader(ComputeShader->GetComputeShader());
// Bind output
FScopedUAVBind ScopedBind = FScopedUAVBind::BindOutput(RHICmdList, *ComputeShader, DstUAV);
ComputeShader->SetCSParamters(RHICmdList, FFTDesc.XFormType, SrcTexture, SrcWindow, FIntRect(FIntPoint(0, 0), DstExtent), TransformLength, PassLength, bScrubNaNs);
RHICmdList.DispatchComputeShader(1, 1, TransformLength / Radix);
}
/**
* Single Pass of a multi-pass complex FFT that just reorders data for
* a group shared subpass to consume.
*
* Assumes the dst buffer is large enough to hold the result.
* The Src float4 data is interpt as a pair of independent complex numbers.
*
* @param Context - container for RHI and ShanderMap
* @param FFTDesc - Metadata that describes the underlying complex FFT
* @param SrcRct - The region in the Src buffer where the image to transform lives.
* @param SrcTexture - SRV the source image buffer
* @param DstRect - The target Window.
* @param DstUAV - UAV, the destination buffer that will hold the result of the single pass
*
*/
void DispatchReorderFFTPassCS(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const FIntRect& SrcWindow, const FTextureRHIRef& SrcTexture,
const FIntRect& DstWindow, FUnorderedAccessViewRHIRef& DstUAV,
const bool bScrubNaNs = false)
{
// Using multiple radix two passes.
const uint32 Radix = 2;
using namespace GPUFFTComputeShaderUtils;
const FGPUFFTShaderContext::ShaderMapType& ShaderMap = Context.GetShaderMap();
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
const uint32 TransformLength = FFTDesc.SignalLength;
const FString TransformName = FFTDesc.FFT_TypeName();
// Breaks the data into the correct number of sub-transforms for the later group-shared pass.
const uint32 SubLength = TransformLength / FGroupShardSubFFTPassCS::SubPassLength();
SCOPED_DRAW_EVENTF(RHICmdList, ReorderFFTPass, TEXT("FFT Multipass: Complex %s Reorder pass of size %d"), *TransformName, TransformLength);
FIntPoint DstExtent = FFTDesc.TransformExtent();
// Get a base pointer to the shader
FReorderFFTPassCS* ComputeShader = GetReorderFFTPassCS(ShaderMap);
SetRenderTarget(RHICmdList, FTextureRHIRef(), FTextureRHIRef());
RHICmdList.SetComputeShader(ComputeShader->GetComputeShader());
// Bind output
FScopedUAVBind ScopedBind = FScopedUAVBind::BindOutput(RHICmdList, *ComputeShader, DstUAV);
ComputeShader->SetCSParamters(RHICmdList, FFTDesc.XFormType, SrcTexture, SrcWindow, DstWindow, TransformLength, SubLength, bScrubNaNs);
RHICmdList.DispatchComputeShader(1, 1, TransformLength / Radix);
}
/**
* A Group Shared Single Pass of a multi-pass complex FFT.
* Assumes the dst buffer is large enough to hold the result.
* The Src float4 data is interpt as a pair of independent complex numbers.
*
* @param Context - container for RHI and ShanderMap
* @param FFTDesc - Metadata that describes the underlying complex FFT
* @param SrcTexture - SRV the source image buffer
* @param SrcRct - The region in the Src buffer where the image to transform lives.
* @param DstUAV - UAV, the destination buffer that will hold the result of the single pass
*
*/
void DispatchGSSubComplexFFTPassCS(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const FTextureRHIRef& SrcTexture, const FIntRect& SrcWindow,
FUnorderedAccessViewRHIRef& DstUAV)
{
using namespace GPUFFTComputeShaderUtils;
const FGPUFFTShaderContext::ShaderMapType& ShaderMap = Context.GetShaderMap();
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
const uint32 TransformLength = FFTDesc.SignalLength;
const FString TransformName = FFTDesc.FFT_TypeName();
const uint32 NumSubRegions = TransformLength / FGroupShardSubFFTPassCS::SubPassLength();
SCOPED_DRAW_EVENTF(RHICmdList, GSSubComplexFFTPass, TEXT("FFT Multipass: %d GS Subpasses Complex %s of size %d"),
NumSubRegions, *TransformName, FGroupShardSubFFTPassCS::SubPassLength());
// The window on which a single transform acts.
FIntRect SubPassWindow = SrcWindow;
if (FFTDesc.IsHorizontal())
{
SubPassWindow.Max.X = SubPassWindow.Min.X + FGroupShardSubFFTPassCS::SubPassLength();
}
else
{
SubPassWindow.Max.Y = SubPassWindow.Min.Y + FGroupShardSubFFTPassCS::SubPassLength();
}
FIntPoint DstExtent = FFTDesc.TransformExtent();
// Get a base pointer to the shader
FGroupShardSubFFTPassCS* ComputeShader = GetGroupSharedSubFFTPassCS(ShaderMap, TransformLength);
SetRenderTarget(RHICmdList, FTextureRHIRef(), FTextureRHIRef());
RHICmdList.SetComputeShader(ComputeShader->GetComputeShader());
// Bind output
FScopedUAVBind ScopedBind = FScopedUAVBind::BindOutput(RHICmdList, *ComputeShader, DstUAV);
ComputeShader->SetCSParamters(RHICmdList, FFTDesc.XFormType, TransformLength, SubPassWindow, SrcTexture, NumSubRegions);
// The number of signals to transform simultaneously (i.e. number of scan lines)
const uint32 NumSignals = FFTDesc.IsHorizontal() ? SubPassWindow.Size().Y : SubPassWindow.Size().X;
RHICmdList.DispatchComputeShader(1, 1, NumSignals);
}
/**
* Complex 1D FFT of two independent complex signals.
* Assumes the dst buffer is large enough to hold the result.
* The Src float4 data is interpt as a pair of independent complex numbers.
*
* @param Context - container for RHI and ShanderMap
* @param FFTDesc - Metadata that describes the underlying complex FFT
* @param SrcTexture - SRV the source image buffer
* @param SrcRct - The region in the Src buffer where the image to transform lives.
* @param DstUAV - UAV, the destination buffer that will hold the result of the 1d complex FFT
*
*/
void DispatchGSComplexFFTCS(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const FTextureRHIRef& SrcTexture, const FIntRect& SrcRect,
FUnorderedAccessViewRHIRef& DstUAV)
{
using namespace GPUFFTComputeShaderUtils;
const FGPUFFTShaderContext::ShaderMapType& ShaderMap = Context.GetShaderMap();
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
const uint32 TransformLength = FFTDesc.SignalLength;
const FString TransformName = FFTDesc.FFT_TypeName();
const FIntPoint DstExtent = FFTDesc.TransformExtent();
SCOPED_DRAW_EVENTF(RHICmdList, ComplexFFTImage, TEXT("FFT: Complex %s of size %d"), *TransformName, TransformLength);
// Get a base pointer to the shader
FGSComplexTransformBaseCS* ComputeShader = GetComplexFFTCS(ShaderMap, TransformLength);
SetRenderTarget(RHICmdList, FTextureRHIRef(), FTextureRHIRef());
RHICmdList.SetComputeShader(ComputeShader->GetComputeShader());
// Bind output
FScopedUAVBind ScopedBind = FScopedUAVBind::BindOutput(RHICmdList, *ComputeShader, DstUAV);
ComputeShader->SetCSParamters(RHICmdList, FFTDesc.XFormType, SrcTexture, SrcRect, FIntRect(FIntPoint(0, 0), DstExtent));
// The number of signals to transform simultaneously (i.e. number of scan lines)
const uint32 NumSignals = FFTDesc.IsHorizontal() ? SrcRect.Size().Y : SrcRect.Size().X;
RHICmdList.DispatchComputeShader(1, 1, NumSignals);
}
/**
* Real 1D FFT of four independent real signals.
* Assumes the dst buffer is large enough to hold the result.
* The Src float4 data is interptd as 4 independent real numbers.
* The Dst float4 data will be two complex numbers.
*
* @param Context - container for RHI and ShanderMap
* @param FFTDesc - Metadata that describes the underlying complex FFT
* @param SrcTexture - SRV the source image buffer
* @param SrcRct - The region in the Src buffer where the image to transform lives.
* @param DstUAV - UAV, the destination buffer that will hold the result of the 1d complex FFT
* @param DstRect - Where to write the tranform data in the Dst buffer
* @param PreFilter - Used to boost the intensity of already bright pixels.
*
*/
void DispatchGSTwoForOneFFTCS(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const FTextureRHIRef& SrcTexture, const FIntRect& SrcRect,
FUnorderedAccessViewRHIRef& DstUAV, const FIntRect& DstRect,
const FPreFilter& PreFilter)
{
using namespace GPUFFTComputeShaderUtils;
const FGPUFFTShaderContext::ShaderMapType& ShaderMap = Context.GetShaderMap();
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
const uint32 TransformLength = FFTDesc.SignalLength;
const FString TransformName = FFTDesc.FFT_TypeName();
SCOPED_DRAW_EVENTF(RHICmdList, FRCPassFFT, TEXT("FFT: Two-For-One %s of size %d of buffer %d x %d"), *TransformName, TransformLength, SrcRect.Size().X, SrcRect.Size().Y);
// Get a base pointer to the shader
FGSComplexTransformBaseCS* ComputeShader = GetTwoForOneFFTCS(ShaderMap, TransformLength);
// DJH - do we need this SetRenderTarget?
SetRenderTarget(RHICmdList, FTextureRHIRef(), FTextureRHIRef());
RHICmdList.SetComputeShader(ComputeShader->GetComputeShader());
FScopedUAVBind ScopedBind = FScopedUAVBind::BindOutput(RHICmdList, *ComputeShader, DstUAV);
ComputeShader->SetCSParamters(RHICmdList, FFTDesc.XFormType, SrcTexture, SrcRect, DstRect, PreFilter);
// The number of signals to transform simultaneously (i.e. number of scan lines)
const uint32 NumScanLines = (FFTDesc.IsHorizontal()) ? SrcRect.Size().Y : SrcRect.Size().X;
RHICmdList.DispatchComputeShader(1, 1, NumScanLines);
}
/**
* Complex 1D FFT followed by multiplication in with kernel and inverse transform.
*
* @param Context - container for RHI and ShanderMap
* @param FFTDesc - Metadata that describes the underlying complex FFT
* @param PreTransformedKernel - Pre-transformed kernel used in the convolution.
* @param SrcTexture - SRV the source image buffer
* @param SrcRct - The region in the Src buffer where the image to transform lives.
* @param DstUAV - UAV, the destination buffer that will hold the result of the 1d complex FFT
* @param DstRect - Where to write the tranform data in the Dst buffer
*
*/
void DispatchGSConvolutionWithTextureCS(FGPUFFTShaderContext& Context,
const FFTDescription& FFTDesc,
const FTextureRHIRef& PreTransformedKernel,
const FTextureRHIRef& SrcTexture,
const FIntRect& SrcRect,
FUnorderedAccessViewRHIRef& DstUAV)
{
using GPUFFTComputeShaderUtils::FScopedUAVBind;
const FGPUFFTShaderContext::ShaderMapType& ShaderMap = Context.GetShaderMap();
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
// Transform particulars
const uint32 SignalLength = FFTDesc.SignalLength;
const FString XFormDirName = FFTDesc.FFT_TypeName();
const bool bIsHornizontal = FFTDesc.IsHorizontal();
const FIntPoint& SrcRectSize = SrcRect.Size();
// The number of signals to transform simultaneously (i.e. number of scan lines)
// NB: This may be different from the FFTDesc.NumScanlines.
const uint32 NumSignals = (bIsHornizontal) ? SrcRectSize.Y : SrcRectSize.X;
SCOPED_DRAW_EVENTF(RHICmdList, FRCPassFFTBloom, TEXT("FFT: Apply %s Transform, Multiply Texture, and InverseTransform size %d of buffer %d x %d"), *XFormDirName, SignalLength, SrcRectSize.X, SrcRectSize.Y);
// Get a base pointer to the shader
FGSConvolutionWithTextureKernelBaseCS* ComputeShader = GetConvolutionWithTextureKernelCS(ShaderMap, SignalLength);
SetRenderTarget(RHICmdList, FTextureRHIRef(), FTextureRHIRef());
RHICmdList.SetComputeShader(ComputeShader->GetComputeShader());
FScopedUAVBind ScopedBind = FScopedUAVBind::BindOutput(RHICmdList, *ComputeShader, DstUAV);
ComputeShader->SetCSParamters(RHICmdList, FFTDesc.XFormType, PreTransformedKernel, SrcTexture, SrcRect, SrcRect.Size());
RHICmdList.DispatchComputeShader(1, 1, NumSignals);
}
} // end anonymous namespace
void GPUFFT::CopyImage2D(FGPUFFTShaderContext& Context,
const FIntRect& SrcWindow, const FTextureRHIRef& SrcTexture,
const FIntRect& DstWindow, FUnorderedAccessViewRHIRef& DstUAV,
const FPreFilter& PreFilter)
{
DispatchCopyWindowCS(Context, SrcWindow, SrcTexture, DstWindow, DstUAV, PreFilter);
}
void GPUFFT::ComplexFFTImage1D::Requirements(const FFTDescription& FFTDesc, FIntPoint& MinBufferSize, bool& bUseMultipass)
{
MinBufferSize = FFTDesc.TransformExtent();
bUseMultipass = !FitsInGroupSharedMemory(FFTDesc);
}
bool GPUFFT::ComplexFFTImage1D::GroupShared(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const FIntRect& SrcWindow, const FTextureRHIRef& SrcTexture, FUnorderedAccessViewRHIRef& DstUAV)
{
bool SuccessValue = true;
check(FMath::IsPowerOfTwo(FFTDesc.SignalLength));
if (FitsInGroupSharedMemory(FFTDesc))
{
DispatchGSComplexFFTCS(Context, FFTDesc, SrcTexture, SrcWindow, DstUAV);
}
else
{
SuccessValue = false;
// @todo
ensureMsgf(0, TEXT("The FFT size is too large for group shared memory"));
// Do forward expensive transform
}
return SuccessValue;
}
bool GPUFFT::ComplexFFTImage1D::MultiPass(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const FIntRect& Window, const FTextureRHIRef& SrcTexture, FSceneRenderTargetItem& DstBuffer,
FSceneRenderTargetItem& TmpBuffer,
const bool bScrubNaNs)
{
bool SuccessValue = true;
const uint32 TransformLength = FFTDesc.SignalLength;
const FFT_XFORM_TYPE XFormType = FFTDesc.XFormType;
// The direction of the transform must be a power of two.
check(FMath::IsPowerOfTwo(TransformLength));
// Command list
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
// The number of iterations required.
const uint32 Log2TransformLength = BitSize(TransformLength) - 1;
// Double buffer to manage the Dst and Tmp buffers.
GPUFFT::FDoubleBufferTargets Targets(TmpBuffer, DstBuffer);
FIntPoint DstExtent = FFTDesc.TransformExtent();
const FIntRect XFormWindow(FIntPoint(0, 0), DstExtent);
// Testing code branch: Breaks the transform into Log2(TransformLength) number of passes.
// this is the slowest algorithm, and uses no group-shared storage.
if (0)
{
DispatchComplexFFTPassCS(Context, FFTDesc, 1, SrcTexture, Window, Targets.DstTarget().UAV, bScrubNaNs);
for (uint32 Ns = 2; Ns < TransformLength; Ns *= 2)
{
// Make it safe to read from the buffer we just wrote to.
RHICmdList.TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, Targets.DstTarget().UAV);
Targets.Swap();
auto HasValidTargets = [&Targets, &DstExtent]()->bool
{
// Verify that the buffers being used are big enough. Note that we are checking the "src" buffer, but due
// to the double buffering we will end up testing both buffers.
FIntPoint SrcBufferSize = Targets.SrcTarget().ShaderResourceTexture->GetTexture2D()->GetSizeXY();
bool Fits = !(SrcBufferSize.X < DstExtent.X) && !(SrcBufferSize.Y < DstExtent.Y);
return Fits;
};
checkf(HasValidTargets(), TEXT("FFT: Allocated Buffers too small."));
DispatchComplexFFTPassCS(Context, FFTDesc, Ns, Targets.SrcTarget().ShaderResourceTexture, XFormWindow, Targets.DstTarget().UAV);
}
// If this transform requires an even number of passes
// this swap will insure that the "DstBuffer" is filled last.
if (Log2TransformLength % 2 == 0)
{
SwapContents(TmpBuffer, DstBuffer);
}
}
else
// Reorder, followed by a High-level group-shared pass followed by Log2(TransformLength / SubPassLength() ) simple passes.
// In total 2 + Log2(TransformLength / SubPassLength() ) passes. This will be on the order of 3 or 4 passes
// compared with 12 or more ..
{
// Re-order the data so we can do a pass of group-shared transforms
DispatchReorderFFTPassCS(Context, FFTDesc, Window, SrcTexture, XFormWindow, Targets.DstTarget().UAV);
RHICmdList.TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, Targets.DstTarget().UAV);
Targets.Swap();
DispatchGSSubComplexFFTPassCS(Context, FFTDesc, Targets.SrcTarget().ShaderResourceTexture, XFormWindow, Targets.DstTarget().UAV);
for (uint32 Ns = FGroupShardSubFFTPassCS::SubPassLength(); Ns < TransformLength; Ns *= 2)
{
// Make it safe to read from the buffer we just wrote to.
RHICmdList.TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, Targets.DstTarget().UAV);
Targets.Swap();
auto HasValidTargets = [&Targets, &DstExtent]()->bool
{
// Verify that the buffers being used are big enough. Note that we are checking the "src" buffer, but due
// to the double buffering we will end up testing both buffers.
FIntPoint SrcBufferSize = Targets.SrcTarget().ShaderResourceTexture->GetTexture2D()->GetSizeXY();
bool Fits = !(SrcBufferSize.X < DstExtent.X) && !(SrcBufferSize.Y < DstExtent.Y);
return Fits;
};
checkf(HasValidTargets(), TEXT("FFT: Allocated Buffers too small."));
DispatchComplexFFTPassCS(Context, FFTDesc, Ns, Targets.SrcTarget().ShaderResourceTexture, XFormWindow, Targets.DstTarget().UAV);
}
if (Targets.GetSrcIdx() != 0)
{
SwapContents(TmpBuffer, DstBuffer);
}
}
return SuccessValue;
}
void GPUFFT::TwoForOneRealFFTImage1D::Requirements(const FFTDescription& FFTDesc, FIntPoint& MinBufferSize, bool& bUseMultipass)
{
FFTDescription TmpDesc = FFTDesc;
// The two-for-one produces a result that has two additional elements in the transform direction.
TmpDesc.SignalLength += 2;
MinBufferSize = TmpDesc.TransformExtent();
bUseMultipass = !FitsInGroupSharedMemory(FFTDesc);
}
bool GPUFFT::TwoForOneRealFFTImage1D::GroupShared(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const FIntRect& SrcWindow, const FTextureRHIRef& SrcTexture,
const FIntRect& DstWindow, FUnorderedAccessViewRHIRef& DstUAV,
const FPreFilter& PreFilter)
{
bool SuccessValue = true;
if (FitsInGroupSharedMemory(FFTDesc))
{
DispatchGSTwoForOneFFTCS(Context, FFTDesc, SrcTexture, SrcWindow, DstUAV, DstWindow, PreFilter);
}
else
{
SuccessValue = false;
// @todo
ensureMsgf(0, TEXT("The FFT size is too large for group shared memory"));
// Do forward expensive transform
}
return SuccessValue;
}
bool GPUFFT::TwoForOneRealFFTImage1D::MultiPass(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const FIntRect& SrcWindow, const FTextureRHIRef& SrcTexture,
FSceneRenderTargetItem& DstBuffer,
FSceneRenderTargetItem& TmpBuffer,
const FPreFilter& PreFilter)
{
bool SuccessValue = true;
if (FFTDesc.IsForward())
{
// Only filter on the forward transform.
if (IsActive(PreFilter))
{
// Copy data into DstBuffer
CopyImage2D(Context, SrcWindow, SrcTexture, SrcWindow, DstBuffer.UAV, PreFilter);
Context.GetRHICmdList().TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, DstBuffer.UAV);
// Transform as 2 sets of complex data, putting the result in the DstBuffer. This performs multiple dispatches.
// Transform into DstBuffer.
SuccessValue = SuccessValue &&
ComplexFFTImage1D::MultiPass(Context, FFTDesc, SrcWindow, DstBuffer.ShaderResourceTexture, TmpBuffer /*result*/, DstBuffer/*tmp*/, true /*scrub nans*/);
}
else
{
// Transform as 2 sets of complex data, putting the result in the DstBuffer. This performs multiple dispatches.
SuccessValue = SuccessValue &&
ComplexFFTImage1D::MultiPass(Context, FFTDesc, SrcWindow, SrcTexture, DstBuffer /*result*/, TmpBuffer/*tmp*/, true /*scrub nans*/);
SwapContents(DstBuffer, TmpBuffer);
}
Context.GetRHICmdList().TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, TmpBuffer.UAV);
// Unpack the complex transform into transform of real data
DispatchPackTwoForOneFFTPassCS(Context, FFTDesc, TmpBuffer.ShaderResourceTexture, DstBuffer.UAV);
}
else // Inverse transform.
{
// Pack the 4 transforms of real data as 2 transforms of complex data
DispatchPackTwoForOneFFTPassCS(Context, FFTDesc, SrcTexture, DstBuffer.UAV);
Context.GetRHICmdList().TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, DstBuffer.UAV);
// Transform as complex data
SuccessValue = SuccessValue &&
ComplexFFTImage1D::MultiPass(Context, FFTDesc, SrcWindow, DstBuffer.ShaderResourceTexture, TmpBuffer/*result*/, DstBuffer/*tmp*/);
SwapContents(TmpBuffer, DstBuffer);
}
return SuccessValue;
}
bool GPUFFT::FFTImage2D(FGPUFFTShaderContext& Context, const FIntPoint& FrequencySize, bool bHorizontalFirst,
const FIntRect& ROIRect, const FTextureRHIRef& SrcTexture,
FSceneRenderTargetItem& DstBuffer,
FSceneRenderTargetItem& TmpBuffer)
{
using GPUFFT::FFTDescription;
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
// This will be for the actual output.
const FIntRect FFTResultRect = ROIRect;
const FIntPoint ImageSpaceExtent = ROIRect.Size();
// Set up the transform descriptions
FFTDescription TwoForOneFFTDesc = (bHorizontalFirst) ? FFTDescription(FFT_XFORM_TYPE::FORWARD_HORIZONTAL, FrequencySize) : FFTDescription(FFT_XFORM_TYPE::FORWARD_VERTICAL, FrequencySize);
FFTDescription ComplexFFTDesc = (bHorizontalFirst) ? FFTDescription(FFT_XFORM_TYPE::FORWARD_VERTICAL, FrequencySize) : FFTDescription(FFT_XFORM_TYPE::FORWARD_HORIZONTAL, FrequencySize);
// The two-for-one transform data storage has two additional elements.
const uint32 FrequencyPadding = 2;
// This additional elements translate to two additional scanlines that need to be transformed by the complex fft
ComplexFFTDesc.NumScanLines += FrequencyPadding;
// Temp Double Buffers
const FIntPoint TmpExent = (bHorizontalFirst) ? FIntPoint(FrequencySize.X + FrequencyPadding, ImageSpaceExtent.Y) : FIntPoint(ImageSpaceExtent.X, FrequencySize.Y + FrequencyPadding);
const FIntRect TmpRect = FIntRect(FIntPoint(0, 0), TmpExent);
// Perform the transforms and convolutions.
bool SuccessValue = true;
// Two-for-one transform: SrcTexture fills the TmpBuffer
if (FitsInGroupSharedMemory(TwoForOneFFTDesc))
{
// Horizontal FFT: input -> tmp buffer 0
SuccessValue = SuccessValue &&
TwoForOneRealFFTImage1D::GroupShared(Context, TwoForOneFFTDesc, ROIRect, SrcTexture, TmpRect, TmpBuffer.UAV);
//->dst
}
else
{
// use the dst buffer as a dummy buffer
FSceneRenderTargetItem& DmyBuffer = DstBuffer;
// Horizontal FFT: input -> TmpBuffer
SuccessValue = SuccessValue &&
TwoForOneRealFFTImage1D::MultiPass(Context, TwoForOneFFTDesc, ROIRect, SrcTexture, TmpBuffer /*dst*/, DmyBuffer/*tmp*/);
//->dst
}
RHICmdList.TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, TmpBuffer.UAV);
// Complex transform in the other direction: TmpBuffer fills DstBuffer
if (FitsInGroupSharedMemory(ComplexFFTDesc))
{
SuccessValue = SuccessValue &&
ComplexFFTImage1D::GroupShared(Context, ComplexFFTDesc, TmpRect, TmpBuffer.ShaderResourceTexture, DstBuffer.UAV);
}
else
{
SuccessValue = SuccessValue &&
ComplexFFTImage1D::MultiPass(Context, ComplexFFTDesc, TmpRect, TmpBuffer.ShaderResourceTexture, DstBuffer, TmpBuffer);
}
return SuccessValue;
}
void GPUFFT::ConvolutionWithTextureImage1D::Requirements(const FFTDescription& FFTDesc, FIntPoint& MinBufferSize, bool& bUseMultipass)
{
bUseMultipass = !FitsInGroupSharedMemory(FFTDesc);
MinBufferSize = FFTDesc.TransformExtent();
}
bool GPUFFT::ConvolutionWithTextureImage1D::GroupShared(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const FTextureRHIRef& TransformedKernel,
const FIntRect& SrcWindow,
const FTextureRHIRef& SrcTexture,
FUnorderedAccessViewRHIRef& DstUAV)
{
bool SuccessValue = true;
if (FitsInGroupSharedMemory(FFTDesc))
{
DispatchGSConvolutionWithTextureCS(Context, FFTDesc, TransformedKernel, SrcTexture, SrcWindow, DstUAV);
}
else
{
SuccessValue = false;
// @todo
ensureMsgf(0, TEXT("The FFT size is too large for group shared memory"));
}
return SuccessValue;
}
bool GPUFFT::ConvolutionWithTextureImage1D::MultiPass(FGPUFFTShaderContext& Context, const FFTDescription& FFTDesc,
const FTextureRHIRef& TransformedKernel,
const FIntRect& SrcWindow,
const FTextureRHIRef& SrcTexture,
FSceneRenderTargetItem& DstBuffer,
FSceneRenderTargetItem& TmpBuffer)
{
bool SuccessValue = true;
// Frequency Space size.
const FIntPoint TargetExtent = FFTDesc.TransformExtent();
const FIntRect TargetRect(FIntPoint(0, 0), TargetExtent);
// Forward transform: Results in DstBuffer
SuccessValue = SuccessValue &&
ComplexFFTImage1D::MultiPass(Context, FFTDesc, SrcWindow, SrcTexture, DstBuffer, TmpBuffer);
Context.GetRHICmdList().TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, DstBuffer.UAV);
// Convolution: Results in TmpBuffer
DispatchComplexMultiplyImagesCS(Context, FFTDesc.IsHorizontal(), TargetRect, DstBuffer.ShaderResourceTexture, TransformedKernel, TmpBuffer.UAV);
Context.GetRHICmdList().TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, TmpBuffer.UAV);
// Inverse Transform: Results in DstBuffer
FFTDescription InvFFTDesc = FFTDesc;
InvFFTDesc.XFormType = GetInverseOfXForm(FFTDesc.XFormType);
// testing. Verify that the forward transform works.
SuccessValue = SuccessValue &&
ComplexFFTImage1D::MultiPass(Context, InvFFTDesc, TargetRect, TmpBuffer.ShaderResourceTexture, DstBuffer, TmpBuffer);
Context.GetRHICmdList().TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, DstBuffer.UAV);
// Copy back to the correct sized sub-window
DispatchCopyWindowCS(Context, TargetRect, DstBuffer.ShaderResourceTexture, SrcWindow, TmpBuffer.UAV);
SwapContents(TmpBuffer, DstBuffer);
return SuccessValue;
}
FIntPoint GPUFFT::Convolution2DBufferSize(const FIntPoint& FrequencySize, const bool bHorizontalFirst, const FIntPoint& ROIExtent)
{
using GPUFFT::FFTDescription;
using GPUFFT::FFT_XFORM_TYPE;
FFTDescription TwoForOneFFTDesc;
TwoForOneFFTDesc.XFormType = bHorizontalFirst ? FFT_XFORM_TYPE::FORWARD_HORIZONTAL : FFT_XFORM_TYPE::FORWARD_VERTICAL;
TwoForOneFFTDesc.SignalLength = bHorizontalFirst ? FrequencySize.X : FrequencySize.Y;
TwoForOneFFTDesc.NumScanLines = (bHorizontalFirst) ? ROIExtent.Y : ROIExtent.X;
FFTDescription ConvolutionFFTDesc;
ConvolutionFFTDesc.XFormType = bHorizontalFirst ? FFT_XFORM_TYPE::FORWARD_VERTICAL : FFT_XFORM_TYPE::FORWARD_HORIZONTAL;
ConvolutionFFTDesc.SignalLength = bHorizontalFirst ? FrequencySize.Y : FrequencySize.X;
ConvolutionFFTDesc.NumScanLines = TwoForOneFFTDesc.SignalLength + 2;
FFTDescription TwoForOneIvnFFTDesc = TwoForOneFFTDesc;
TwoForOneIvnFFTDesc.XFormType = GetInverseOfXForm(TwoForOneFFTDesc.XFormType);
FIntPoint BufferSize;
if (FitsInGroupSharedMemory(ConvolutionFFTDesc))
{
FFTDescription TmpDesc = TwoForOneFFTDesc;
TmpDesc.SignalLength += 2;
BufferSize = TmpDesc.TransformExtent();
}
else
{
// a larger buffer is needed when the convolution can't be done in group-shared
BufferSize = ConvolutionFFTDesc.TransformExtent();
}
return BufferSize;
}
bool GPUFFT::ConvolutionWithTextureImage2D(FGPUFFTShaderContext& Context, const FIntPoint& FrequencySize, bool bHorizontalFirst,
const FTextureRHIRef& TransformedKernel,
const FIntRect& ROIRect, const FTextureRHIRef& SrcTexture,
FUnorderedAccessViewRHIRef& ResultUAV,
FSceneRenderTargetItem& TmpBuffer0,
FSceneRenderTargetItem& TmpBuffer1,
const FPreFilter& PreFilter)
{
using GPUFFT::FFTDescription;
FRHICommandListImmediate& RHICmdList = Context.GetRHICmdList();
// This will be for the actual output.
const FIntRect FFTResultRect = ROIRect;
const FIntPoint ROISize = ROIRect.Size();
//DoubleBufferTargets TmpBuffers(Context, TmpExent, PixelFormat);
// Set up the transform descriptions
FFTDescription TwoForOneFFTDesc;
TwoForOneFFTDesc.XFormType = bHorizontalFirst ? FFT_XFORM_TYPE::FORWARD_HORIZONTAL : FFT_XFORM_TYPE::FORWARD_VERTICAL;
TwoForOneFFTDesc.SignalLength = bHorizontalFirst ? FrequencySize.X : FrequencySize.Y;
TwoForOneFFTDesc.NumScanLines = (bHorizontalFirst) ? ROISize.Y : ROISize.X;
// The output has two more elements
FIntRect TwoForOneOutputRect;
{
FFTDescription TmpDesc = TwoForOneFFTDesc;
TmpDesc.SignalLength += 2;
TwoForOneOutputRect = FIntRect(FIntPoint(0, 0), TmpDesc.TransformExtent());
}
FFTDescription ConvolutionFFTDesc;
ConvolutionFFTDesc.XFormType = bHorizontalFirst ? FFT_XFORM_TYPE::FORWARD_VERTICAL : FFT_XFORM_TYPE::FORWARD_HORIZONTAL;
ConvolutionFFTDesc.SignalLength = bHorizontalFirst ? FrequencySize.Y : FrequencySize.X;
ConvolutionFFTDesc.NumScanLines = TwoForOneFFTDesc.SignalLength + 2; // two-for-one transform generated two additional elements
FFTDescription TwoForOneIvnFFTDesc = TwoForOneFFTDesc;
TwoForOneIvnFFTDesc.XFormType = GetInverseOfXForm(TwoForOneFFTDesc.XFormType);
// Perform the transforms and convolutions.
bool SuccessValue = true;
// ---- Two For One Transform ---
// Horizontal FFT: input -> tmp buffer 0
if (FitsInGroupSharedMemory(TwoForOneFFTDesc))
{
SuccessValue = SuccessValue &&
TwoForOneRealFFTImage1D::GroupShared(Context, TwoForOneFFTDesc, ROIRect, SrcTexture, TwoForOneOutputRect, TmpBuffer0.UAV, PreFilter);
//->dst
}
else
{
SuccessValue = SuccessValue &&
TwoForOneRealFFTImage1D::MultiPass(Context, TwoForOneFFTDesc, ROIRect, SrcTexture, TmpBuffer0, TmpBuffer1, PreFilter);
}
RHICmdList.TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, TmpBuffer0.UAV);
// ---- 1 D Convolution ---
if (FitsInGroupSharedMemory(ConvolutionFFTDesc))
{
// Vertical FFT / Filter / Vertical InvFFT : tmp buffer 0 -> tmp buffer 1
SuccessValue = SuccessValue &&
ConvolutionWithTextureImage1D::GroupShared(Context, ConvolutionFFTDesc, TransformedKernel, TwoForOneOutputRect, TmpBuffer0.ShaderResourceTexture, TmpBuffer1.UAV);
//->src
}
else
{
SuccessValue = SuccessValue &&
ConvolutionWithTextureImage1D::MultiPass(Context, ConvolutionFFTDesc, TransformedKernel, TwoForOneOutputRect, TmpBuffer0.ShaderResourceTexture, TmpBuffer1, TmpBuffer0);
}
RHICmdList.TransitionResource(EResourceTransitionAccess::ERWBarrier, EResourceTransitionPipeline::EComputeToCompute, TmpBuffer1.UAV);
// ---- Inverse Two For One ---
if (FitsInGroupSharedMemory(TwoForOneIvnFFTDesc))
{
// Horizontal InvFFT: tmp buffer 1 -> result
SuccessValue = SuccessValue &&
TwoForOneRealFFTImage1D::GroupShared(Context, TwoForOneIvnFFTDesc, TwoForOneOutputRect, TmpBuffer1.ShaderResourceTexture, ROIRect, ResultUAV);
//->dst
}
else
{
// TmpBuffer1 -> TmpBuffer0
SuccessValue = SuccessValue &&
TwoForOneRealFFTImage1D::MultiPass(Context, TwoForOneIvnFFTDesc, TwoForOneOutputRect, TmpBuffer1.ShaderResourceTexture, TmpBuffer0, TmpBuffer1);
RHICmdList.TransitionResource(EResourceTransitionAccess::EReadable, EResourceTransitionPipeline::EComputeToCompute, TmpBuffer0.UAV);
DispatchCopyWindowCS(Context, TwoForOneOutputRect, TmpBuffer0.ShaderResourceTexture, ROIRect, ResultUAV);
}
return SuccessValue;
}