Skip to content

Commit e712a77

Browse files
raquelpecesEvergreen
authored andcommitted
Create a dummy color for binding when MSAA samples mismatch in depth copy pass
1 parent f0004a6 commit e712a77

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

Packages/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private static void ExecutePass(RasterCommandBuffer cmd, PassData passData, RTHa
132132

133133
copyDepthMaterial.SetTexture(ShaderConstants._CameraDepthAttachment, source);
134134
copyDepthMaterial.SetFloat(ShaderConstants._ZWriteShaderHandle, passData.copyToDepth ? 1.0f : 0.0f);
135-
Blitter.BlitTexture(cmd, source, scaleBias, copyDepthMaterial, 0);
135+
Blitter.BlitTexture(cmd, source, scaleBias, copyDepthMaterial, 0);
136136
}
137137

138138
/// <summary>
@@ -176,7 +176,7 @@ public void Render(RenderGraph renderGraph, TextureHandle destination, TextureHa
176176
var canSampleMSAADepth = sourceDesc.bindTextureMS && SystemInfo.supportsMultisampledTextures != 0;
177177

178178
Debug.Assert(!hasMSAA || canUseResolvedDepth || canSampleMSAADepth || !dstHasDepthFormat
179-
, "Can't copy depth to destiation with depth format due to MSAA and platform/API limitations: no resolved depth resource (bindMS), depth resolve unsupported, and MSAA depth sampling unsupported.");
179+
, "Can't copy depth to destination with depth format due to MSAA and platform/API limitations: no resolved depth resource (bindMS), depth resolve unsupported, and MSAA depth sampling unsupported.");
180180

181181
// Having a different pass name than profilingSampler.name is bad practice but this method was public before we cleaned up this naming
182182
using (var builder = renderGraph.AddRasterRenderPass<PassData>(passName, out var passData, profilingSampler))
@@ -238,8 +238,34 @@ public void Render(RenderGraph renderGraph, TextureHandle destination, TextureHa
238238
// binding a dummy color target as a workaround to an OSX issue in Editor scene view (UUM-47698).
239239
// Also required for preview camera rendering for grid drawn with builtin RP (UUM-55171).
240240
// Also required for render gizmos (UUM-91335).
241+
// When MSAA is enabled with Dbuffer can cause sample count mismatches between active color and depth target; create a dummy color target to resolve. (UUM-131330)
241242
if (cameraData.isSceneViewCamera || cameraData.isPreviewCamera || UnityEditor.Handles.ShouldRenderGizmos())
242-
builder.SetRenderAttachment(resourceData.activeColorTexture, 0);
243+
{
244+
// get info for the active color
245+
var activeColorInfo = renderGraph.GetRenderTargetInfo(resourceData.activeColorTexture);
246+
247+
// destination depth info (the texture we created earlier)
248+
var destInfo = renderGraph.GetRenderTargetInfo(destination);
249+
250+
// if samples mismatch, create a dummy color RT with dest's samples
251+
if (activeColorInfo.msaaSamples != destInfo.msaaSamples)
252+
{
253+
TextureHandle dummyColor = renderGraph.CreateTexture(new TextureDesc(activeColorInfo.width, activeColorInfo.height, false, true)
254+
{
255+
name = "Copy Depth Editor Dummy Color",
256+
slices = activeColorInfo.volumeDepth,
257+
format = activeColorInfo.format,
258+
msaaSamples = (MSAASamples)destInfo.msaaSamples, // match the depth target
259+
clearBuffer = false,
260+
bindTextureMS = activeColorInfo.bindMS
261+
});
262+
builder.SetRenderAttachment(dummyColor, 0);
263+
}
264+
else
265+
{
266+
builder.SetRenderAttachment(resourceData.activeColorTexture, 0);
267+
}
268+
}
243269
#endif
244270
}
245271
else

0 commit comments

Comments
 (0)