Hi everyone,
an update on our progress.
We’ve landed dozens of small fixes and optimizations to the URP RenderGraph adoption in the next patch release. The URP passes now better declare their resource usage, making sure that render graph can correctly optimize resource re-usage and merge passes.
An important change is that global textures that you set through the RenderGraph API (builder.SetGlobalTextureAfterPass) will be automatically unset (set to a black texture) after the RenderGraph is done executing. This was mentioned here already. The clearing was previously behind a define. This will help you to avoid hard-to-discover bugs where a frame by accident is using the global texture of a previous frame. We noticed a number of such issues in URP. Those were not discovered by our automated testing because the test scenes are static so the resources don’t change over frames. These are now all fixed.
As a reminder, when you create a TextureHandle using RenderGraph.CreateTexture, that handle is only valid until the RenderGraph ends executing in that frame. Every camera currently has it’s own RenderGraph so its only valid per frame/per camera. RG will assign/allocate an RTHandle/RenderTexture automatically and that could (by coincidence) be the same as last frame, but that’s not guaranteed. Therefore, every global texture that is set using RG needs to be cleared to avoid bugs. This will now be done automatically when you set a global with the RenderGraph API. However, the behavior of the other APIs to set a global texture is unchanged (commandBuffer.SetGlobalTexture, Shader.SetGlobalTexture). These you can still use for RTHandles that you manage yourself and import in the RenderGraph.
We also made a small change to the TextureDesc that provides the parameters to create a TextureHandle. This now has a single format (either for color or for depth stencil). This avoids subtle bugs. A TextureHandle only points to a single resource, either color or depth stencil, not up to two like a RenderTexture. It is recommended to use this TextureDesc.format instead of TextureDesc.colorFormat or TextureDesc.depthBufferBits to set the format. The later legacy properties are slightly more expensive to call and depthBufferBits does not give you the exact format you want. For example, when copying descriptors, desc1.depthBufferBits=desc2.depthBufferBits can result in desc1 having a different depthStencilFormat than desc2. When doing desc1.format=desc2.format, you can be sure it’s exactly the same.
Additionally, we fixed a number of bugs with regards to the depth stencil format of the _CameraDepthAttachment and the _CameraDepthTexture. URP allows you to configure the format of these resources on the Renderer so they can be different. Be careful when using cameraData.cameraTargetDescriptor to get the depth stencil format of the current depth target. Those are not necessarily the same. This descriptor is for the backbuffer. It’s is much safer to use resource.GetDescriptor(renderGraph) to have the correct info of a resource, for example when making a copy.
The RenderGraph samples will be updated to reflect these best practices.
Currently, we are investigating a number of issues with MSAA. Also, we are looking into the use case to get new CullResults. Likely we are missing API here that we will add soon.
As always, you can get a better understanding by looking at the commits in the Graphics repo. The changes will ship in 6000.0.22f1.