Skip to content

Fixed some render texture leaks. #3050

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 12 commits into from
Jan 15, 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 @@ -203,7 +203,7 @@ override public void PurgeUnusedResources(int currentFrameIndex)
var list = kvp.Value;
list.RemoveAll(obj =>
{
if (obj.frameIndex < s_CurrentFrameIndex)
if (ShouldReleaseResource(obj.frameIndex, s_CurrentFrameIndex))
{
obj.resource.Release();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ abstract class RenderGraphResourcePool<Type> : IRenderGraphResourcePool where Ty
List<(int, Type)> m_FrameAllocatedResources = new List<(int, Type)>();

protected static int s_CurrentFrameIndex;
const int kStaleResourceLifetime = 10;

// Release the GPU resource itself
protected abstract void ReleaseInternalResource(Type res);
Expand Down Expand Up @@ -123,5 +124,13 @@ public override void LogResources(RenderGraphLogger logger)
foreach (var element in allocationList)
logger.LogLine("[{0}]\t[{1:#.##} MB]\t{2}", index++, element.size / 1024.0f, element.name);
}

static protected bool ShouldReleaseResource(int lastUsedFrameIndex, int currentFrameIndex)
{
// We need to have a delay of a few frames before releasing resources for good.
// Indeed, when having multiple off-screen cameras, they are rendered in a separate SRP render call and thus with a different frame index than main camera
// This causes texture to be deallocated/reallocated every frame if the two cameras don't need the same buffers.
return (lastUsedFrameIndex + kStaleResourceLifetime) < currentFrameIndex;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ override public void PurgeUnusedResources(int currentFrameIndex)
var list = kvp.Value;
list.RemoveAll(obj =>
{
if (obj.frameIndex < s_CurrentFrameIndex)
if (ShouldReleaseResource(obj.frameIndex, s_CurrentFrameIndex))
{
obj.resource.Release();
return true;
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 @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed undo-redo on layered lit editor.
- Fixed tesselation culling, big triangles using lit tesselation shader would dissapear when camera is too close to them (case 1299116)
- Fixed issue with compositor related custom passes still active after disabling the compositor (case 1305330)
- Fixed some render texture leaks.

### Changed
- Change the source value for the ray tracing frame index iterator from m_FrameCount to the camera frame count (case 1301356).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,8 @@ Matrix4x4 ComputePixelCoordToWorldSpaceViewDirectionMatrix(ViewConstants viewCon

void Dispose()
{
HDRenderPipeline.DestroyVolumetricHistoryBuffers(this);

VolumeManager.instance.DestroyStack(volumeStack);

if (m_HistoryRTSystem != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ void GenerateMip(CommandBuffer cmd, Texture source, Vector3Int sourceOffset, int
public void Release()
{
ClearTextures();
m_Atlas.Release();
CoreUtils.Destroy(m_Atlas);
CoreUtils.Destroy(m_MipMapGenerationTemp);
}

public static long GetApproxCacheSizeInByte(int elementSize, int elementCount, GraphicsFormat format, bool hasMipMaps)
Expand Down