Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt URP to use RTHandles - P1 #5346

Merged
merged 117 commits into from
Nov 17, 2021
Merged

Adapt URP to use RTHandles - P1 #5346

merged 117 commits into from
Nov 17, 2021

Conversation

sandy-carter-unity
Copy link
Contributor

@sandy-carter-unity sandy-carter-unity commented Aug 13, 2021

Purpose of this PR

This is a refactor of #4018 made in a way which focuses on backwards compatibility, what-you-use-is-what-you get allocation of targets and without the dynamic scaling changes which will be moved to a p2 PR. The reason for doing it in such a modular way is to have a testing friendly state from which other features dependent on RTHandles can start their work before dynamic scaling lands.

This first part contains a lot high level of refactoring in the way that resources are passed around and created. The second part and other features leveraging RTHandles should not require so many changes.

This PR aims to replace usage of RenderTargetHandle to use RTHandles instead in order to support setting UnityEngine.XR.XRSettings.renderViewportScale in URP.

RTHandle is a SRP core utility class that helps manage unity RenderTexture resources and has DynamicResolutionHandler support. It is currently being used by HDRP and RenderGraph modules. The class also has built-in support for render target dynamic scaling. This will add dynamic resolution support to URP and unifies URP’s render texture management. It also opens the way for URP to integrate with RenderGraph in the future.


Testing status

The current failing tests are also failing on the master branch.
I've looked closely at the test pipeline and this PR does not add new fails.
Additionally, any of the commits behind HEAD pass all tests locally and on Yamato so bisecting is possible.

I am also working with QA and XR QA to validate in depth.


Comments to reviewers

See Left to do.

FAQ

Why add [Obsolete] and then ignore them in places?

The switch to RTHandles is backwards compatible with uses of RenderTargetIdentifiers. This is so users creating their own passes can still have their projects working in the future release. However, we want this compatibility layer to be gone in future versions so that RTHandle dynamic scaling in XR works across the board. This probably will impact RenderGraph also.
Disabling the warnings happens for the cases where we still use the obsolete API for backwards compatibility purposes.
That being said, there might be ways to reduce the disables and still be backwards compatible, please let me know if there are.

Color and Depth in the same RenderTarget

The nature of RTHandles prevents the combination of color and depth/stencil in the same RTHandle.
Therefore, and RTHandle is equivalent to one GPU render texture

Converting this to RTHandles requires removing all GetTemporaryRTs and replacing them with RTHandles which are allocated to last longer than one frame.
When they are (re)allocated, the reference changes, this target creation is now moved to before setup and in a lot of cases moved to within the Universal Renderer.
In terms of allocated GPU resourced, it should be the same due to the above use of depthBufferBits on the color attachment.


Left to do

  • Fix Memory allocation fails in Renderer2D.
  • In depth testing within XR contexts.
  • Check Uninitialized Background Type
    • Not an issue with scaling off (same as master).
    • Could be a problem with scaling on
  • Move URP specific changes out of CoreUtils
  • Y-Flip of GameView in sample depth
    • Flipped in master
  • Warnings such as CommandBuffer: temporary render texture _GBuffer2 not found while executing (SetGlobalTexture)
  • Add VRTextureUsage to RTHandles.Alloc
  • Allocation in NativeRenderPass
  • Enable dynamic resolution (to be done in p2 of this series)
  • Have you updated the changelog? Each package has a CHANGELOG.md file.
  • Have you updated or added the documentation for your PR? When you add a new feature, change a property name, or change the behavior of a feature, it's best practice to include related documentation changes in the same PR. If you do add documentation, make sure to add the relevant Graphics Docs team member as a reviewer of the PR. If you are not sure which person to add, see the Docs team contacts sheet.

@github-actions
Copy link

github-actions bot commented Aug 13, 2021

Hi! This comment will help you figure out which jobs to run before merging your PR. The suggestions are dynamic based on what files you have changed.
Link to Yamato: https://unity-ci.cds.internal.unity3d.com/project/902/
Search for your PR branch using the search bar at the top, then add the following segment(s) to the end of the URL (you may need multiple tabs depending on how many packages you change)

URP
/jobDefinition/.yamato%252Fall-urp.yml%2523PR_URP_trunk
With changes to URP packages, you should also run
/jobDefinition/.yamato%2Fall-lightmapping.yml%23PR_Lightmapping_trunk

SRP Core
You could run ABV on your branch before merging your PR, but it will start A LOT of jobs. Please be responsible about it and run it only when you feel the PR is ready:
/jobDefinition/.yamato%252F_abv.yml%2523all_project_ci_trunk
Be aware that any modifications to the Core package impacts everyone in the Graphics repo so please discuss the PR with your lead.

Depending on the scope of your PR, you may need to run more jobs than what has been suggested. Please speak to your lead or a Graphics SDET (#devs-graphics-automation) if you are unsure.

@sandy-carter-unity sandy-carter-unity force-pushed the universal/xr/rt-handles-p1 branch 6 times, most recently from f697dbb to 973e68e Compare September 3, 2021 01:30
@sandy-carter-unity sandy-carter-unity force-pushed the universal/xr/rt-handles-p1 branch 3 times, most recently from f51a0fb to cdde383 Compare September 15, 2021 17:22
@sandy-carter-unity sandy-carter-unity force-pushed the universal/xr/rt-handles-p1 branch 5 times, most recently from aed13a9 to 9f09647 Compare September 16, 2021 00:59
@sandy-carter-unity sandy-carter-unity requested review from a team and removed request for phi-lira November 8, 2021 15:06
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved again for urp qa(double assignage)

@phi-lira phi-lira changed the base branch from master to universal/staging November 10, 2021 09:11
@Verasl Verasl self-requested a review November 10, 2021 09:29

The `ScriptableRendererFeature` has a new virtual function called `SetupRenderPasses` which is called when render targets are allocated and ready to be used.

If your code uses `renderer.cameraColorTarget` or `renderer.cameraDepthTarget` inside of the `AddRenderPasses` override, then that use needs to be moved to `SetupRenderPasses`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this affect passes added from e.g. components rather than renderer features?

Is there a point in the ScriptableRenderPass where the user can assume that render targets are allocated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with features was that universal renderer was calling AddRenderPasses before allocation, by design.
The targets are allocated right after in the Setup of the ScriptableRenderer.
If components are trying to access targets before the setup, then it's too early. Anytime after this is fine.

Comment on lines +46 to +47
* `RenderingUtils.ReAllocateIfNeeded`
* `ShadowUtils.ShadowRTReAllocateIfNeeded`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't really feel like helper functions, but more like something you need to use. Can we move them into a more official sounding class?

Copy link
Contributor

@pbbastian pbbastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving so that we can get this in :D Consider the other comments to be fix in follow-up PR

/// <param name="mipMapBias">Bias applied to mipmaps during filtering.</param>
/// <param name="name">Name of the RTHandle.</param>
/// <returns></returns>
internal static bool ReAllocateIfNeeded(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are in our upgrade guide, they should be public

@phi-lira phi-lira changed the base branch from universal/staging to master November 16, 2021 21:25
@phi-lira
Copy link
Contributor

Yamato was green on previous changeset. Merged master to solve conflicts with changelog.
Got approval from @Verasl on slack. Merging this one.

@phi-lira phi-lira merged commit d48795e into master Nov 17, 2021
@phi-lira phi-lira deleted the universal/xr/rt-handles-p1 branch November 17, 2021 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.