Skip to content

Commit

Permalink
[HDRP] nullref fullscreen passthrough when the customRender callback …
Browse files Browse the repository at this point in the history
…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
alelievr and sebastienlagarde committed Jun 17, 2021
1 parent 48f2d2e commit 17e0ea0
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 7 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed sceneview debug mode rendering (case 1211436)
- Fixed Pixel Displacement that could be set on tessellation shader while it's not supported.
- Fixed an issue where disabled reflection probes were still sent into the the ray tracing light cluster.
- Fixed nullref when enabling fullscreen passthrough in HDRP Camera.

### Changed
- Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1187,16 +1187,16 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c
out var hdCamera,
out var cullingParameters);

VFXCameraXRSettings cameraXRSettings;
cameraXRSettings.viewTotal = hdCamera.xr.enabled ? 2U : 1U;
cameraXRSettings.viewCount = (uint)hdCamera.viewCount;
cameraXRSettings.viewOffset = (uint)hdCamera.xr.multipassId;

VFXManager.PrepareCamera(camera, cameraXRSettings);

// Note: In case of a custom render, we have false here and 'TryCull' is not executed
if (!skipRequest)
{
VFXCameraXRSettings cameraXRSettings;
cameraXRSettings.viewTotal = hdCamera.xr.enabled ? 2U : 1U;
cameraXRSettings.viewCount = (uint)hdCamera.viewCount;
cameraXRSettings.viewOffset = (uint)hdCamera.xr.multipassId;

VFXManager.PrepareCamera(camera, cameraXRSettings);

var needCulling = true;

// In XR multipass, culling results can be shared if the pass has the same culling id
Expand All @@ -1219,6 +1219,12 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c
skipRequest = !TryCull(camera, hdCamera, renderContext, m_SkyManager, cullingParameters, m_Asset, ref cullingResults);
}

if (additionalCameraData.hasCustomRender && additionalCameraData.fullscreenPassthrough)
{
Debug.LogWarning("HDRP Camera custom render is not supported when Fullscreen Passthrough is enabled. Please either disable Fullscreen Passthrough in the camera settings or remove all customRender callbacks attached to this camera.");
continue;
}

if (additionalCameraData != null && additionalCameraData.hasCustomRender)
{
skipRequest = true;
Expand Down

0 comments on commit 17e0ea0

Please sign in to comment.