Files
UnrealEngineUWP/Engine/Shaders/Shared/SubstrateDefinitions.h

98 lines
4.5 KiB
C
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
/*================================================================================================
SubstrateDefinitions.ush: used in ray tracing shaders and C++ code to define common constants
!!! Changing this file requires recompilation of the engine !!!
=================================================================================================*/
#pragma once
#ifndef __cplusplus
// Change this to force recompilation of all Substrate dependent shaders (for instance https://guidgenerator.com/online-guid-generator.aspx)
#pragma message("UESHADERMETADATA_VERSION B013B52C-494E-4FC3-9EB5-B16B754E5CA4")
#endif
// Closure offsets are packed into 32bits, each entry using SUBSTRATE_CLOSURE_OFFSET_BIT_COUNT bits
#define SUBSTRATE_MAX_CLOSURE_COUNT_FOR_CLOSUREOFFSET 8u
#define SUBSTRATE_CLOSURE_OFFSET_BIT_COUNT 4u
#define SUBSTRATE_CLOSURE_OFFSET_BIT_MASK 0xF
// We can only ever use SUBSTRATE_MAX_CLOSURE_COUNT_FOR_CLOSUREOFFSET for Lumen, so we use that as a global closure count limit today.
#define SUBSTRATE_MAX_CLOSURE_COUNT SUBSTRATE_MAX_CLOSURE_COUNT_FOR_CLOSUREOFFSET
#define SUBSTRATE_MAX_OPERATOR_COUNT 15
// It this is changed, STATE_BIT_COUNT_SHAREDLOCALBASESID and HEADER_BIT_COUNT_SHAREDLOCALBASES_COUNT also needs to be updated
#define SUBSTRATE_MAX_SHAREDLOCALBASES_REGISTERS 4
#define SUBSTRATE_PACKED_SHAREDLOCALBASIS_STRIDE_BYTES 4
// As of today, a fully simplified material is a slab with all features allowed. It can thus be complex if anisotropy is enabled and in this case eats up to 32bytes.
// SUBSTRATE_TODO: fully simplified should remove all features but fuzz maybe.
#define SUBSTRATE_FULLY_SIMPLIFIED_NUM_UINTS (32/4)
#define SUBSTRATE_BSDF_TYPE_SLAB 0
#define SUBSTRATE_BSDF_TYPE_VOLUMETRICFOGCLOUD 1
#define SUBSTRATE_BSDF_TYPE_UNLIT 2
#define SUBSTRATE_BSDF_TYPE_HAIR 3
#define SUBSTRATE_BSDF_TYPE_SINGLELAYERWATER 4
#define SUBSTRATE_BSDF_TYPE_EYE 5
// When more than 7 BSDF must exists, please update STATE_BIT_COUNT_BSDF and FSubstrateClassification.ShadingModels packing in Substrate.ush
// The size of Substrate material classification tiles on screen
#define SUBSTRATE_TILE_SIZE 8
#define SUBSTRATE_TILE_SIZE_DIV_AS_SHIFT 3
// The default thickness of a layer is considered to be 0.01 centimeter = 0.1 millimeter
#define SUBSTRATE_LAYER_DEFAULT_THICKNESS_CM 0.01f
// Min Fuzz Roughness to avoid numerical issue
#define SUBSTRATE_MIN_FUZZ_ROUGHNESS 0.02f
#define SUBSTRATE_BASE_PASS_MRT_OUTPUT_COUNT 3
Big Strata core update! - Completely changed the way we evaluate and represent the material topology. - A topology is now represented as a tree to allow any horizontal/vertical operations (almost like a kdtree). - This allows for correct translucent material coverage/transmittance evaluation, as well as correct BSDFs luminance weight (finally). - All the operations to be able to do that are expended in HLSLTranslator instead of letting the compiler handle it (otherwise was too slow, leading to bugs and could not even debug shaders). This means no conditional BSDF packing. - There is no more Material/layer/BSDFs array: only a Tree or operators, some of them being BSDF at leaves. - Parameter blending has also been updated: when enabled on a node, it will be forced on all the oprator child / in the sub tree. - Parameter blending is applied on an inlinedbsdf on the StrataData. When it is the root of the parameter blending subtree, it is promoted to a fully fledged BSDF operator node to allow other regular operators. - The inlinedbsdf is not longer in premultiplied mode. Horizontal/Vertical/Add parameter blending operators have been updated to reflect that. This allows for simpler/unified/clearer code. - Vertical blending now uses the new simple "layering of two slabs with uncorelated coverage" math I have RnD'd. See GetVerticalLayeringInfo in ShadingCommon.ush. Follow up to this CL: - CompileStrataBlendFunction should use parameter blending. - Add more compilation debug output - Update material vizualisation - Fix Rough refraction - Fix decals - Fix debug probes - Pack FStrataBSDF - Move all StrataCompilationInfoCreateSingleBSDFMaterial into into the strata tree and rework cost evaluation and material LOD - Expand graph visit such as UpdateBSDFWeightAfterOperatorVisit to be specific to operators for the compiler to have to do less search to inline what we know already - Fix STRATA_TODO: operation using parameter blending are not actually discarded so they still occupy a pot in the opeartion arrays in the compiler and in the shader also. #rb charles.derousiers #preflight https://horde.devtools.epicgames.com/job/620a5f5d803d9066e67de938 #fyi charles.derousiers [CL 18993400 by Sebastien Hillaire in ue5-main branch]
2022-02-15 03:09:30 -05:00
#define SUBSTRATE_SSS_DATA_UINT_COUNT 2
#define SUBSTRATE_OPERATOR_WEIGHT 0
#define SUBSTRATE_OPERATOR_VERTICAL 1
#define SUBSTRATE_OPERATOR_HORIZONTAL 2
#define SUBSTRATE_OPERATOR_ADD 3
#define SUBSTRATE_OPERATOR_BSDF 4
#define SUBSTRATE_OPERATOR_BSDF_LEGACY 5
// This must map directly to ESubstrateTileMaterialType
#define SUBSTRATE_TILE_TYPE_SIMPLE 0
#define SUBSTRATE_TILE_TYPE_SINGLE 1
#define SUBSTRATE_TILE_TYPE_COMPLEX 2
#define SUBSTRATE_TILE_TYPE_COMPLEX_SPECIAL 3
#define SUBSTRATE_TILE_TYPE_ROUGH_REFRACT 4
#define SUBSTRATE_TILE_TYPE_ROUGH_REFRACT_SSS_WITHOUT 5
#define SUBSTRATE_TILE_TYPE_DECAL_SIMPLE 6
#define SUBSTRATE_TILE_TYPE_DECAL_SINGLE 7
#define SUBSTRATE_TILE_TYPE_DECAL_COMPLEX 8
#define SUBSTRATE_TILE_TYPE_COUNT 9
#define SUBSTRATE_MATERIAL_TYPE_SIMPLE 0
#define SUBSTRATE_MATERIAL_TYPE_SINGLE 1
#define SUBSTRATE_MATERIAL_TYPE_COMPLEX 2
#define SUBSTRATE_MATERIAL_TYPE_COMPLEX_SPECIAL 3
#define SUBSTRATE_TILE_ENCODING_16BITS 0
#define SUBSTRATE_TILE_ENCODING_8BITS 1
// Specular profile
#define SUBSTRATE_SPECULAR_PROFILE_ENTRY_LIGHT 0u
#define SUBSTRATE_SPECULAR_PROFILE_ENTRY_ENV 1u
#define SUBSTRATE_SPECULAR_PROFILE_ENTRY_COUNT 2u
// sizeof(FRHIDrawIndirectParameters) = 4 uints = 16 bytes
#define GetSubstrateTileTypeDrawIndirectArgOffset_Byte(x) (x * 16)
#define GetSubstrateTileTypeDrawIndirectArgOffset_DWord(x) (x * 4)
Fix for async compute on platforms with memory boundary restrictions on async compute dispatch indirect arguments *** This change will incur a full shader invalidation across all platforms *** Issues: - Some platforms require async compute dispatch indirect arguments to not cross specific memory boundaries - This places restrictions on the valid sizes for a dispatch indirect argument set. We were not conforming to these restrictions which could result in GPU crashes on these async passes Fixes: - FRHIDispatchIndirectParameters is padded out to meet per-platform memory boundary restrictions - This is driven via new per-platform preprocessor define PLATFORM_DISPATCH_INDIRECT_ARGUMENT_BOUNDARY_SIZE - Some platforms require FRHIDispatchIndirectParameters to align with their internal structure hence we cannot universally size to meet all platform's requirements - Introduce new FRHIDispatchIndirectParametersNoPadding for uses when we explicitly do not want the padding and otherwise avoid the memory boundary restrictions - Revise and expand indirect argument validation code to catch further such issues in the future - Update shaders which write to dispatch indirect argument buffers to account for optional per-platform padding - New utility function WriteDispatchIndirectArgs introduced to faciliate this - platforms which require other than the default nonpadded dispatch indirect arguments must define DISPATCH_INDIRECT_UINT_COUNT and their own WriteDispatchIndirectArgs in their CommonPlatform.ush - move creation of DispatchIndirectGraphicsCommandSignature command signature to be per-platform - DispatchIndirectGraphicsCommandSignature and DispatchIndirectComputeCommandSignature stride changed to account for additional padding on impacted platforms Testing: - ran Lyra with and without async compute Lumen on impacted platforms as well as Win64 - ran FN replay on impacted platforms #rb Krzysztof.Narkowicz, Ben.Woodhouse, Benjamin.Rouveyrol #jira UE-167950 #preflight 6359563b2e6690262a11bc06 [CL 22862498 by eric mcdaniel in ue5-main branch]
2022-10-31 10:15:11 -04:00
// sizeof(FRHIDispatchIndirectParameters) can vary per-platform
#ifdef __cplusplus
#define GetSubstrateTileTypeDispatchIndirectArgOffset_Byte(x) (x * sizeof(FRHIDispatchIndirectParameters))
#define GetSubstrateTileTypeDispatchIndirectArgOffset_DWord(x) (x * sizeof(FRHIDispatchIndirectParameters) / sizeof(uint32))
Fix for async compute on platforms with memory boundary restrictions on async compute dispatch indirect arguments *** This change will incur a full shader invalidation across all platforms *** Issues: - Some platforms require async compute dispatch indirect arguments to not cross specific memory boundaries - This places restrictions on the valid sizes for a dispatch indirect argument set. We were not conforming to these restrictions which could result in GPU crashes on these async passes Fixes: - FRHIDispatchIndirectParameters is padded out to meet per-platform memory boundary restrictions - This is driven via new per-platform preprocessor define PLATFORM_DISPATCH_INDIRECT_ARGUMENT_BOUNDARY_SIZE - Some platforms require FRHIDispatchIndirectParameters to align with their internal structure hence we cannot universally size to meet all platform's requirements - Introduce new FRHIDispatchIndirectParametersNoPadding for uses when we explicitly do not want the padding and otherwise avoid the memory boundary restrictions - Revise and expand indirect argument validation code to catch further such issues in the future - Update shaders which write to dispatch indirect argument buffers to account for optional per-platform padding - New utility function WriteDispatchIndirectArgs introduced to faciliate this - platforms which require other than the default nonpadded dispatch indirect arguments must define DISPATCH_INDIRECT_UINT_COUNT and their own WriteDispatchIndirectArgs in their CommonPlatform.ush - move creation of DispatchIndirectGraphicsCommandSignature command signature to be per-platform - DispatchIndirectGraphicsCommandSignature and DispatchIndirectComputeCommandSignature stride changed to account for additional padding on impacted platforms Testing: - ran Lyra with and without async compute Lumen on impacted platforms as well as Win64 - ran FN replay on impacted platforms #rb Krzysztof.Narkowicz, Ben.Woodhouse, Benjamin.Rouveyrol #jira UE-167950 #preflight 6359563b2e6690262a11bc06 [CL 22862498 by eric mcdaniel in ue5-main branch]
2022-10-31 10:15:11 -04:00
#else
#define GetSubstrateTileTypeDispatchIndirectArgOffset_Byte(x) (x * DISPATCH_INDIRECT_UINT_COUNT * 4)
#define GetSubstrateTileTypeDispatchIndirectArgOffset_DWord(x) (x * DISPATCH_INDIRECT_UINT_COUNT)
Fix for async compute on platforms with memory boundary restrictions on async compute dispatch indirect arguments *** This change will incur a full shader invalidation across all platforms *** Issues: - Some platforms require async compute dispatch indirect arguments to not cross specific memory boundaries - This places restrictions on the valid sizes for a dispatch indirect argument set. We were not conforming to these restrictions which could result in GPU crashes on these async passes Fixes: - FRHIDispatchIndirectParameters is padded out to meet per-platform memory boundary restrictions - This is driven via new per-platform preprocessor define PLATFORM_DISPATCH_INDIRECT_ARGUMENT_BOUNDARY_SIZE - Some platforms require FRHIDispatchIndirectParameters to align with their internal structure hence we cannot universally size to meet all platform's requirements - Introduce new FRHIDispatchIndirectParametersNoPadding for uses when we explicitly do not want the padding and otherwise avoid the memory boundary restrictions - Revise and expand indirect argument validation code to catch further such issues in the future - Update shaders which write to dispatch indirect argument buffers to account for optional per-platform padding - New utility function WriteDispatchIndirectArgs introduced to faciliate this - platforms which require other than the default nonpadded dispatch indirect arguments must define DISPATCH_INDIRECT_UINT_COUNT and their own WriteDispatchIndirectArgs in their CommonPlatform.ush - move creation of DispatchIndirectGraphicsCommandSignature command signature to be per-platform - DispatchIndirectGraphicsCommandSignature and DispatchIndirectComputeCommandSignature stride changed to account for additional padding on impacted platforms Testing: - ran Lyra with and without async compute Lumen on impacted platforms as well as Win64 - ran FN replay on impacted platforms #rb Krzysztof.Narkowicz, Ben.Woodhouse, Benjamin.Rouveyrol #jira UE-167950 #preflight 6359563b2e6690262a11bc06 [CL 22862498 by eric mcdaniel in ue5-main branch]
2022-10-31 10:15:11 -04:00
#endif