Skip to content

Commit 0435a56

Browse files
YohannVaastUnityEvergreen
authored andcommitted
Render Graph - Disable FBF for PS4 & PS5
1 parent e7e0609 commit 0435a56

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ public interface IRasterRenderGraphBuilder : IRenderAttachmentRenderGraphBuilder
324324
/// to match the index passed to SetInputAttachment for this texture.
325325
///
326326
/// </summary>
327+
/// <remarks>
328+
/// This API is not universally supported across all platforms. In particular, using input attachments in combination with MSAA may be unsupported on certain targets.
329+
/// To ensure compatibility, use `RenderGraphUtils.IsFramebufferFetchSupportedOnCurrentPlatform` to verify support at runtime, as platform capabilities may vary.
330+
/// </remarks>
327331
/// <param name="tex">Texture to use during this pass.</param>
328332
/// <param name="index">Index the shader will use to access this texture.</param>
329333
/// <param name="flags">How this pass will access the texture. Default value is set to AccessFlag.Read. Writing is currently not supported on any platform. </param>

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using UnityEngine.Experimental.Rendering;
4+
using static UnityEngine.Rendering.RenderGraphModule.RenderGraph;
45

56
namespace UnityEngine.Rendering.RenderGraphModule
67
{
@@ -401,6 +402,8 @@ public void SetRenderAttachment(TextureHandle tex, int index, AccessFlags flags,
401402

402403
public void SetInputAttachment(TextureHandle tex, int index, AccessFlags flags, int mipLevel, int depthSlice)
403404
{
405+
CheckFrameBufferFetchEmulationIsSupported(tex);
406+
404407
CheckUseFragment(tex, false);
405408
var versionedTextureHandle = new TextureHandle(UseResource(tex.handle, flags));
406409
m_RenderPass.SetFragmentInputRaw(versionedTextureHandle, index, flags, mipLevel, depthSlice);
@@ -492,6 +495,25 @@ void CheckResource(in ResourceHandle res, bool checkTransientReadWrite = false)
492495
}
493496
}
494497

498+
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
499+
void CheckFrameBufferFetchEmulationIsSupported(in TextureHandle tex)
500+
{
501+
if (enableValidityChecks)
502+
{
503+
if (!Util.RenderGraphUtils.IsFramebufferFetchEmulationSupportedOnCurrentPlatform())
504+
{
505+
throw new InvalidOperationException($"This API is not supported on the current platform: {SystemInfo.graphicsDeviceType}");
506+
}
507+
508+
if (!Util.RenderGraphUtils.IsFramebufferFetchEmulationMSAASupportedOnCurrentPlatform())
509+
{
510+
var sourceInfo = m_RenderGraph.GetRenderTargetInfo(tex);
511+
if (sourceInfo.bindMS)
512+
throw new InvalidOperationException($"This API is not supported with MSAA attachments on the current platform: {SystemInfo.graphicsDeviceType}");
513+
}
514+
}
515+
}
516+
495517
public void SetShadingRateImageAttachment(in TextureHandle sriTextureHandle)
496518
{
497519
CheckNotUseFragment(sriTextureHandle);

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

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public static partial class RenderGraphUtils
1717
/// <returns>Returns true if the shader features required by the copy pass is supported for MSAA, otherwise will it return false.</returns>
1818
public static bool CanAddCopyPassMSAA()
1919
{
20+
if (!IsFramebufferFetchEmulationMSAASupportedOnCurrentPlatform())
21+
return false;
22+
2023
return Blitter.CanCopyMSAA();
2124
}
2225

@@ -27,6 +30,9 @@ public static bool CanAddCopyPassMSAA()
2730
/// <returns>Returns true if the shader features required by the copy pass is supported for MSAA, otherwise will it return false.</returns>
2831
public static bool CanAddCopyPassMSAA(in TextureDesc sourceDesc)
2932
{
33+
if (!IsFramebufferFetchEmulationMSAASupportedOnCurrentPlatform())
34+
return false;
35+
3036
return Blitter.CanCopyMSAA(sourceDesc.bindTextureMS);
3137
}
3238

@@ -37,9 +43,53 @@ public static bool CanAddCopyPassMSAA(in TextureDesc sourceDesc)
3743
/// <returns>Returns true if the shader features required by the copy pass is supported for MSAA, otherwise will it return false.</returns>
3844
public static bool CanAddCopyPassMSAA(bool bindTextureMS)
3945
{
46+
if (!IsFramebufferFetchEmulationMSAASupportedOnCurrentPlatform())
47+
return false;
48+
4049
return Blitter.CanCopyMSAA(bindTextureMS);
4150
}
4251

52+
internal static bool IsFramebufferFetchEmulationSupportedOnCurrentPlatform()
53+
{
54+
#if PLATFORM_WEBGL
55+
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3)
56+
return false;
57+
#endif
58+
return true;
59+
}
60+
61+
internal static bool IsFramebufferFetchEmulationMSAASupportedOnCurrentPlatform()
62+
{
63+
// TODO: Temporarily disable this utility pending a more efficient solution for supporting or disabling framebuffer fetch emulation on PS4/PS5.
64+
return (SystemInfo.graphicsDeviceType != GraphicsDeviceType.PlayStation4
65+
&& SystemInfo.graphicsDeviceType != GraphicsDeviceType.PlayStation5 && SystemInfo.graphicsDeviceType != GraphicsDeviceType.PlayStation5NGGC);
66+
}
67+
68+
/// <summary>
69+
/// Determines whether framebuffer fetch is supported on the current platform for the given texture.
70+
/// This includes checking both general support for framebuffer fetch emulation and specific support
71+
/// for multisampled (MSAA) textures.
72+
/// </summary>
73+
/// <param name="graph">The RenderGraph adding this pass to.</param>
74+
/// <param name="tex">The texture handle to validate for framebuffer fetch compatibility.</param>
75+
/// <returns>
76+
/// Returns true if framebuffer fetch is supported on the current platform for the given texture;
77+
/// otherwise, returns false.
78+
/// </returns>
79+
public static bool IsFramebufferFetchSupportedOnCurrentPlatform(this RenderGraph graph, in TextureHandle tex)
80+
{
81+
if (!IsFramebufferFetchEmulationSupportedOnCurrentPlatform())
82+
return false;
83+
84+
if (!IsFramebufferFetchEmulationMSAASupportedOnCurrentPlatform())
85+
{
86+
var sourceInfo = graph.GetRenderTargetInfo(tex);
87+
if (sourceInfo.msaaSamples > 1)
88+
return sourceInfo.bindMS;
89+
}
90+
return true;
91+
}
92+
4393
/// <summary>
4494
/// Checks whether the copy pass can be used between the given source and destination textures within the RenderGraph.
4595
/// </summary>
@@ -55,10 +105,8 @@ public static bool CanAddCopyPass(this RenderGraph graph, TextureHandle source,
55105
if (!graph.nativeRenderPassesEnabled)
56106
return false;
57107

58-
#if PLATFORM_WEBGL
59-
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3)
108+
if (!IsFramebufferFetchEmulationSupportedOnCurrentPlatform())
60109
return false;
61-
#endif
62110

63111
var sourceInfo = graph.GetRenderTargetInfo(source);
64112
var destinationInfo = graph.GetRenderTargetInfo(destination);

0 commit comments

Comments
 (0)