forked from Unity-Technologies/Graphics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HDRP] nullref fullscreen passthrough when the customRender callback …
…is used (Unity-Technologies#4902) * Fix nullref when enabling fullscreen passthrough in HDRP Cameras * Updated changelog * Fix hdcamera null in callback * Fix nullref again * Correctly fix the error with fullscreen passthrough + add a warning message * Cleanup code * Added a test for begin/end camera rendering Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
- Loading branch information
1 parent
48f2d2e
commit 17e0ea0
Showing
7 changed files
with
146 additions
and
7 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
TestProjects/HDRP_Tests/Assets/GraphicTests/HDRP_PlayModeTests.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
TestProjects/HDRP_Tests/Assets/GraphicTests/HDRP_PlayModeTests/HDRP_PlayModeTests.asmdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "HDRP_PlayModeTests", | ||
"rootNamespace": "", | ||
"references": [ | ||
"UnityEngine.TestRunner", | ||
"Unity.RenderPipelines.HighDefinition.Runtime" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": true, | ||
"precompiledReferences": [ | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": false, | ||
"defineConstraints": [ | ||
"UNITY_INCLUDE_TESTS" | ||
], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
7 changes: 7 additions & 0 deletions
7
...Projects/HDRP_Tests/Assets/GraphicTests/HDRP_PlayModeTests/HDRP_PlayModeTests.asmdef.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
...s/HDRP_Tests/Assets/GraphicTests/HDRP_PlayModeTests/RenderPipelineManagerCallbackTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using UnityEngine; | ||
using UnityEngine.Rendering; | ||
using UnityEngine.TestTools; | ||
using System.Collections.Generic; | ||
using UnityEngine.Rendering.HighDefinition; | ||
|
||
public class RenderPipelineManagerCallbackTests | ||
{ | ||
const int k_RenderCount = 10; | ||
|
||
int begin = 0; | ||
int end = 0; | ||
|
||
public Camera SetupTest() | ||
{ | ||
begin = 0; | ||
end = 0; | ||
|
||
GameObject go = new GameObject(); | ||
var camera = go.AddComponent<Camera>(); | ||
|
||
RenderPipelineManager.beginCameraRendering += CountBeginCameraRender; | ||
RenderPipelineManager.endCameraRendering += CountEndCameraRender; | ||
|
||
return camera; | ||
} | ||
|
||
void CountBeginCameraRender(ScriptableRenderContext context, Camera camera) => begin++; | ||
|
||
void CountEndCameraRender(ScriptableRenderContext context, Camera camera) => end++; | ||
|
||
public bool CheckResult(int expectedValue) | ||
{ | ||
RenderPipelineManager.beginCameraRendering -= CountBeginCameraRender; | ||
RenderPipelineManager.endCameraRendering -= CountEndCameraRender; | ||
|
||
return begin == end && begin == expectedValue; | ||
} | ||
|
||
[UnityTest] | ||
public bool BeginAndEndCameraRenderingCallbackMatch_Camera() | ||
{ | ||
var camera = SetupTest(); | ||
for (int i = 0; i < k_RenderCount; i++) | ||
camera.Render(); | ||
return CheckResult(k_RenderCount); | ||
} | ||
|
||
[UnityTest] | ||
public bool BeginAndEndCameraRenderingCallbackMatch_RenderToTexture() | ||
{ | ||
var camera = SetupTest(); | ||
camera.targetTexture = new RenderTexture(1, 1, 32, RenderTextureFormat.ARGB32); | ||
camera.targetTexture.Create(); | ||
for (int i = 0; i < k_RenderCount; i++) | ||
camera.Render(); | ||
return CheckResult(k_RenderCount); | ||
} | ||
|
||
[UnityTest] | ||
public bool BeginAndEndCameraRenderingCallbackMatch_CustomRender() | ||
{ | ||
var camera = SetupTest(); | ||
var additionalData = camera.gameObject.AddComponent<HDAdditionalCameraData>(); | ||
additionalData.customRender += (_, _) => {}; | ||
for (int i = 0; i < k_RenderCount; i++) | ||
camera.Render(); | ||
return CheckResult(k_RenderCount); | ||
} | ||
|
||
[UnityTest] | ||
public bool BeginAndEndCameraRenderingCallbackMatch_FullscreenPassthrough() | ||
{ | ||
var camera = SetupTest(); | ||
var additionalData = camera.gameObject.AddComponent<HDAdditionalCameraData>(); | ||
additionalData.fullscreenPassthrough = true; | ||
for (int i = 0; i < k_RenderCount; i++) | ||
camera.Render(); | ||
// Fullscreen passthrough don't trigger begin/end camera rendering | ||
return CheckResult(0); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...P_Tests/Assets/GraphicTests/HDRP_PlayModeTests/RenderPipelineManagerCallbackTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters