Skip to content

Commit 0181123

Browse files
author
Evergreen
committed
[Port] [6000.3] RenderGraph - Fix a crash on old IOS devices due to attachments exceeding the maximum Pixel Storage size
1 parent 352bd31 commit 0181123

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/Compiler/PassesData.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using UnityEngine.Rendering;
66
using System.Collections.Generic;
77
using Unity.Collections;
8+
using UnityEngine.Experimental.Rendering;
89

910
namespace 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.

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/Compiler/ResourcesData.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Runtime.CompilerServices;
33
using Unity.Collections;
44
using UnityEngine.Rendering;
5+
using UnityEngine.Experimental.Rendering;
56

67
namespace UnityEngine.Rendering.RenderGraphModule.NativeRenderPassCompiler
78
{
@@ -29,6 +30,7 @@ internal struct ResourceUnversionedData
2930
public readonly int height;
3031
public readonly int volumeDepth;
3132
public readonly int msaaSamples;
33+
public readonly GraphicsFormat graphicsFormat;
3234

3335
public int latestVersionNumber; // mostly readonly, can be decremented only if all passes using the last version are culled
3436

@@ -62,6 +64,7 @@ public ResourceUnversionedData(TextureResource rll, ref RenderTargetInfo info, r
6264
discard = desc.discardBuffer;
6365
bindMS = info.bindMS;
6466
textureUVOrigin = rll.textureUVOrigin;
67+
graphicsFormat = desc.format;
6568
}
6669

6770
public ResourceUnversionedData(IRenderGraphResource rll, ref BufferDesc _, bool isResourceShared)
@@ -87,6 +90,7 @@ public ResourceUnversionedData(IRenderGraphResource rll, ref BufferDesc _, bool
8790
discard = false;
8891
bindMS = false;
8992
textureUVOrigin = TextureUVOriginSelection.Unknown;
93+
graphicsFormat = GraphicsFormat.None;
9094
}
9195

9296
public ResourceUnversionedData(IRenderGraphResource rll, ref RayTracingAccelerationStructureDesc _, bool isResourceShared)
@@ -112,6 +116,7 @@ public ResourceUnversionedData(IRenderGraphResource rll, ref RayTracingAccelerat
112116
discard = false;
113117
bindMS = false;
114118
textureUVOrigin = TextureUVOriginSelection.Unknown;
119+
graphicsFormat = GraphicsFormat.None;
115120
}
116121

117122
public void InitializeNullResource()

0 commit comments

Comments
 (0)