Bug: "RenderTexture.Create failed: colorFormat & depthStencilFormat cannot both be none." when DBuffer decals and camera output to texture, + fix

Hi,

I’m seeing my console flooded with this message every frame:

RenderTexture.Create failed: colorFormat & depthStencilFormat cannot both be none.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

There is no trace beyond that. After some digging, it appears the messages come from the URP Decal render feature when DBuffer decals are in use, and the camera is set to output to a texture. In this case, on 2022.3 URP the cameraData.cameraTargetDescriptor has depthBufferBits = 0. This is true even if requiresDepthTexture = true. Thus the existing initialisation code in DBufferRenderPass below has a graphics format of ‘None’ and zero depth buffer bits:

var depthDesc = cameraData.cameraTargetDescriptor;
depthDesc.graphicsFormat = GraphicsFormat.None; //Depth only rendering
depthDesc.depthStencilFormat = cameraData.cameraTargetDescriptor.depthStencilFormat;
depthDesc.msaaSamples = 1;

Hence the error occurs. To fix the error, the following adjustment is needed in DBufferRenderPass:

var depthDesc = cameraData.cameraTargetDescriptor;
depthDesc.graphicsFormat = GraphicsFormat.None; //Depth only rendering
depthDesc.depthStencilFormat = cameraData.cameraTargetDescriptor.depthStencilFormat;
depthDesc.msaaSamples = 1;
depthDesc.depthBufferBits = 32; // <-- new

(As an aside, it also appears that the DecalRendererFeature calls the m_DBufferRenderPass.Setup method at least twice per frame for forward rendering - once on line 540, again on line 554. One of these is certainly surplus.)

Cheers,
Elliot