55using UnityEngine . Rendering ;
66using System . Collections . Generic ;
77using Unity . Collections ;
8+ using UnityEngine . Experimental . Rendering ;
89
910namespace UnityEngine . Rendering . RenderGraphModule . NativeRenderPassCompiler
1011{
@@ -1013,6 +1014,12 @@ public static PassBreakAudit CanMerge(CompilerContextData contextData, int activ
10131014 }
10141015 }
10151016
1017+ // Determines if the pixel storage limit is reached after adding the new 'pass to merge' attachments to the current native render pass.
1018+ if ( TotalAttachmentsSizeExceedPixelStorageLimit ( contextData , ref nativePass , ref attachmentsToTryAdding ) )
1019+ {
1020+ return new PassBreakAudit ( PassBreakReason . AttachmentLimitReached , passIdToMerge ) ;
1021+ }
1022+
10161023 // We check first if we are at risk of having too many subpasses,
10171024 // only then we do the costlier subpass merging check, short circuiting it whenever possible
10181025 bool canAddAnExtraSubpass = ( nativePass . numGraphPasses < NativePassCompiler . k_MaxSubpass ) ;
@@ -1025,6 +1032,34 @@ public static PassBreakAudit CanMerge(CompilerContextData contextData, int activ
10251032 return new PassBreakAudit ( PassBreakReason . Merged , passIdToMerge ) ;
10261033 }
10271034
1035+ static bool TotalAttachmentsSizeExceedPixelStorageLimit ( CompilerContextData contextData , ref NativePassData nativePass , ref FixedAttachmentArray < PassFragmentData > attachmentsToTryAdding )
1036+ {
1037+ // TODO: We are currently only checking for iOS GPU Family 1 to 3 since the storage size is much more restricted (16 bytes for Family 1 and 32 for Family 2 & 3).
1038+ // This is temporary. Later on, we should check all iOS GPU Families but also Android (Vulkan) to avoid the same potential restrictions.
1039+ if ( Application . platform == RuntimePlatform . IPhonePlayer && SystemInfo . maxTiledPixelStorageSize <= 32 )
1040+ {
1041+ int totalSize = 0 ;
1042+
1043+ // Iterate over current attachments
1044+ for ( int i = 0 ; i < nativePass . fragments . size ; ++ i )
1045+ {
1046+ ref readonly var unvResource = ref contextData . UnversionedResourceData ( nativePass . fragments [ i ] . resource ) ;
1047+ totalSize += SystemInfo . GetTiledRenderTargetStorageSize ( unvResource . graphicsFormat , unvResource . msaaSamples ) ;
1048+ }
1049+
1050+ // Iterate over new attachments to add
1051+ for ( int i = 0 ; i < attachmentsToTryAdding . size ; ++ i )
1052+ {
1053+ ref readonly var unvResource = ref contextData . UnversionedResourceData ( attachmentsToTryAdding [ i ] . resource ) ;
1054+ totalSize += SystemInfo . GetTiledRenderTargetStorageSize ( unvResource . graphicsFormat , unvResource . msaaSamples ) ;
1055+ }
1056+
1057+ return totalSize > SystemInfo . maxTiledPixelStorageSize ;
1058+ }
1059+
1060+ return false ;
1061+ }
1062+
10281063 // This function follows the structure of TryMergeNativeSubPass but only tests if the new native subpass can be
10291064 // merged with the last one, allowing for early returns. It does not modify the state
10301065 // ref for nativePass is used for performance reasons. The method should not modify nativePass.
0 commit comments