Skip to content

[HDRP] Fixed max shadow crash #2760

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

Merged
merged 5 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed issue with saving some quality settings in volume overrides (case 1293747)
- Fixed NullReferenceException in HDRenderPipeline.UpgradeResourcesIfNeeded (case 1292524)
- Fixed SSGI texture allocation when not using the RenderGraph.
- Fixed NullReference Exception when setting Max Shadows On Screen to 0 in the HDRP asset.

### Changed
- Removed the material pass probe volumes evaluation mode.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4208,6 +4208,9 @@ static void RenderLightLoopDebugOverlay(in DebugParameters debugParameters,

static void RenderShadowsDebugOverlay(in DebugParameters debugParameters, in HDShadowManager.ShadowDebugAtlasTextures atlasTextures, CommandBuffer cmd, MaterialPropertyBlock mpb)
{
if (HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams.maxShadowRequests == 0)
return;

LightingDebugSettings lightingDebug = debugParameters.debugDisplaySettings.data.lightingDebugSettings;
if (lightingDebug.shadowDebugMode != ShadowMapDebugMode.None)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ private HDShadowManager()

public void InitShadowManager(RenderPipelineResources renderPipelineResources, HDShadowInitParameters initParams, Shader clearShader)
{
// Even when shadows are disabled (maxShadowRequests == 0) we need to allocate compute buffers to avoid having
// resource not bound errors when dispatching a compute shader.
m_ShadowDataBuffer = new ComputeBuffer(Mathf.Max(initParams.maxShadowRequests, 1), System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData)));
m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData)));
m_MaxShadowRequests = initParams.maxShadowRequests;
m_ShadowRequestCount = 0;

if (initParams.maxShadowRequests == 0)
return;

m_ClearShadowMaterial = CoreUtils.CreateEngineMaterial(clearShader);
m_BlitShadowMaterial = CoreUtils.CreateEngineMaterial(renderPipelineResources.shaders.shadowBlitPS);

Expand All @@ -332,11 +342,6 @@ public void InitShadowManager(RenderPipelineResources renderPipelineResources, H
m_AreaLightShadowAtlas = new HDDynamicShadowAtlas(renderPipelineResources, initParams.areaLightShadowAtlas.shadowAtlasResolution, initParams.areaLightShadowAtlas.shadowAtlasResolution,
HDShaderIDs._ShadowmapAreaAtlas, m_ClearShadowMaterial, initParams.maxShadowRequests, initParams, HDShadowAtlas.BlurAlgorithm.EVSM, depthBufferBits: initParams.areaLightShadowAtlas.shadowAtlasDepthBits, name: "Area Light Shadow Map Atlas");

m_ShadowDataBuffer = new ComputeBuffer(initParams.maxShadowRequests, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData)));
m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData)));

m_MaxShadowRequests = initParams.maxShadowRequests;

cachedShadowManager.InitPunctualShadowAtlas(renderPipelineResources, initParams.cachedPunctualLightShadowAtlas, initParams.cachedPunctualLightShadowAtlas,
HDShaderIDs._CachedShadowmapAtlas, m_ClearShadowMaterial, initParams.maxShadowRequests, initParams: initParams, depthBufferBits: initParams.punctualLightShadowAtlas.shadowAtlasDepthBits, name: "Cached Shadow Map Atlas");
if (ShaderConfig.s_AreaLights == 1)
Expand Down Expand Up @@ -392,6 +397,9 @@ public static DirectionalShadowAlgorithm GetDirectionalShadowAlgorithm()

public void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb)
{
if (m_MaxShadowRequests == 0)
return;

cb._CascadeShadowCount = (uint)(m_CascadeCount + 1);
cb._ShadowAtlasSize = new Vector4(m_Atlas.width, m_Atlas.height, 1.0f / m_Atlas.width, 1.0f / m_Atlas.height);
cb._CascadeShadowAtlasSize = new Vector4(m_CascadeAtlas.width, m_CascadeAtlas.height, 1.0f / m_CascadeAtlas.width, 1.0f / m_CascadeAtlas.height);
Expand Down Expand Up @@ -596,6 +604,9 @@ public void UpdateCullingParameters(ref ScriptableCullingParameters cullingParam

public void LayoutShadowMaps(LightingDebugSettings lightingDebugSettings)
{
if (m_MaxShadowRequests == 0)
return;

cachedShadowManager.UpdateDebugSettings(lightingDebugSettings);

m_Atlas.UpdateDebugSettings(lightingDebugSettings);
Expand Down Expand Up @@ -627,6 +638,9 @@ public void LayoutShadowMaps(LightingDebugSettings lightingDebugSettings)

unsafe public void PrepareGPUShadowDatas(CullingResults cullResults, HDCamera camera)
{
if (m_MaxShadowRequests == 0)
return;

int shadowIndex = 0;

m_ShadowDatas.Clear();
Expand Down Expand Up @@ -787,6 +801,9 @@ public int GetShadowRequestCount()

public void Clear()
{
if (m_MaxShadowRequests == 0)
return;

// Clear the shadows atlas infos and requests
m_Atlas.Clear();
m_CascadeAtlas.Clear();
Expand Down Expand Up @@ -897,6 +914,10 @@ public void Dispose()
{
m_ShadowDataBuffer.Dispose();
m_DirectionalShadowDataBuffer.Dispose();

if (m_MaxShadowRequests == 0)
return;

m_Atlas.Release();
if (ShaderConfig.s_AreaLights == 1)
m_AreaLightShadowAtlas.Release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3252,6 +3252,9 @@ out ScriptableCullingParameters cullingParams
else
cullingParams.cullingOptions &= ~CullingOptions.NeedsReflectionProbes;

if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.ShadowMaps) || currentAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams.maxShadowRequests == 0)
cullingParams.cullingOptions &= ~CullingOptions.ShadowCasters;

return true;
}

Expand Down