Skip to content

[HDRP]Fix history buffer allocation for AOVs when the request does not come in first frame #4361

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 3 commits into from
Apr 29, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ public void ResetReferenceSize(int width, int height)
m_RTHandleSystem.ResetReferenceSize(width, height);
}

/// <summary>
/// Queries the number of RT handle buffers allocated for a buffer ID.
/// </summary>
/// <param name="bufferId">The buffer ID to query.</param>
public int GetNumFramesAllocated(int bufferId)
{
if (!m_RTHandles.ContainsKey(bufferId))
return 0;

return m_RTHandles[bufferId].Length;
}

void Swap()
{
foreach (var item in m_RTHandles)
Expand Down
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 @@ -173,6 +173,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed material Emission properties not begin animated when recording an animation (case 1328108).
- Fixed fog precision in some camera positions (case 1329603).
- Fixed contact shadows tile coordinates calculations.
- Fixed issue with history buffer allocation for AOVs when the request does not come in first frame.

### 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 @@ -731,9 +731,11 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp,
// If we have a mismatch with color buffer format we need to reallocate the pyramid
var hdPipeline = (HDRenderPipeline)(RenderPipelineManager.currentPipeline);
bool forceReallocPyramid = false;
if (m_NumColorPyramidBuffersAllocated > 0)
int colorBufferID = (int)HDCameraFrameHistoryType.ColorBufferMipChain;
int numColorPyramidBuffersAllocated = m_HistoryRTSystem.GetNumFramesAllocated(colorBufferID);
if (numColorPyramidBuffersAllocated > 0)
{
var currPyramid = GetCurrentFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain);
var currPyramid = GetCurrentFrameRT(colorBufferID);
if (currPyramid != null && currPyramid.rt.graphicsFormat != hdPipeline.GetColorBufferFormat())
{
forceReallocPyramid = true;
Expand All @@ -746,8 +748,19 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp,
if (isHistoryColorPyramidRequired) // Superset of case above
numColorPyramidBuffersRequired = 2;

// Check if we have any AOV requests that require history buffer allocations (the actual allocation happens later in this function)
foreach (var aovRequest in aovRequests)
{
var aovHistory = GetHistoryRTHandleSystem(aovRequest);
if (aovHistory.GetNumFramesAllocated(colorBufferID) != numColorPyramidBuffersRequired)
{
forceReallocPyramid = true;
break;
}
}

// Handle the color buffers
if (m_NumColorPyramidBuffersAllocated != numColorPyramidBuffersRequired || forceReallocPyramid)
if (numColorPyramidBuffersAllocated != numColorPyramidBuffersRequired || forceReallocPyramid)
{
// Reinit the system.
colorPyramidHistoryIsValid = false;
Expand Down Expand Up @@ -775,9 +788,6 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp,
}
BindHistoryRTHandleSystem(cameraHistory);
}

// Mark as init.
m_NumColorPyramidBuffersAllocated = numColorPyramidBuffersRequired;
}

// Handle the volumetric fog buffers
Expand Down Expand Up @@ -1210,7 +1220,6 @@ public RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSyst

HDAdditionalCameraData m_AdditionalCameraData = null; // Init in Update
BufferedRTHandleSystem m_HistoryRTSystem = new BufferedRTHandleSystem();
int m_NumColorPyramidBuffersAllocated = 0;
int m_NumVolumetricBuffersAllocated = 0;
float m_AmbientOcclusionResolutionScale = 0.0f; // Factor used to track if history should be reallocated for Ambient Occlusion
float m_ScreenSpaceAccumulationResolutionScale = 0.0f; // Use another scale if AO & SSR don't have the same resolution
Expand Down