From 79bd77e2ebd32e17a096d7a7c352c18b1395ca8d Mon Sep 17 00:00:00 2001 From: Unity Technologies <@unity> Date: Wed, 16 Oct 2024 00:00:00 +0000 Subject: [PATCH] com.unity.entities.graphics@1.4.3 ## [1.4.3] - 2024-10-16 ### Fixed * Entities graphics constantly allocating more memory without releasing it until next time system update is called. --- CHANGELOG.md | 7 ++++- .../EntitiesGraphicsSystem.cs | 28 +++++++++++++++---- ValidationExceptions.json | 17 +++++++---- package.json | 8 +++--- 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea64fe5..0de41ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ uid: changelog # Changelog +## [1.4.3] - 2024-10-16 + +### Fixed +* Entities graphics constantly allocating more memory without releasing it until next time system update is called. + + ## [1.4.2] - 2024-10-04 ### Changed @@ -17,7 +23,6 @@ uid: changelog * Enable entities motion vector pass participation for URP. * PruneUploadBufferPool API to request pruning of the upload buffer pool. - ### Fixed * GameObjects that depend on vertex shader logic to generate procedural motion vectors through object motion vector passes will now also do the same when baked to Entities and rendered through Entities Graphics. diff --git a/Unity.Entities.Graphics/EntitiesGraphicsSystem.cs b/Unity.Entities.Graphics/EntitiesGraphicsSystem.cs index 92d47f7..3ca6504 100644 --- a/Unity.Entities.Graphics/EntitiesGraphicsSystem.cs +++ b/Unity.Entities.Graphics/EntitiesGraphicsSystem.cs @@ -744,6 +744,7 @@ public unsafe partial class EntitiesGraphicsSystem : SystemBase const float kMaxBatchGrowFactor = 2f; const int kNumNewChunksPerThread = 1; // TODO: Tune this const int kNumScatteredIndicesPerThread = 8; // TODO: Tune this + const int kMaxCullingPassesWithoutAllocatorRewind = 1024; const int kMaxChunkMetadata = 1 * 1024 * 1024; const ulong kMaxGPUAllocatorMemory = 1024 * 1024 * 1024; // 1GiB of potential memory space @@ -783,7 +784,7 @@ public unsafe partial class EntitiesGraphicsSystem : SystemBase #if UNITY_EDITOR float m_CamMoveDistance; #endif - + int m_NumberOfCullingPassesAccumulatedWithoutAllocatorRewind; #if UNITY_EDITOR private EntitiesGraphicsPerThreadStats* m_PerThreadStats = null; private EntitiesGraphicsStats m_Stats; @@ -1067,6 +1068,8 @@ protected override void OnCreate() m_ThreadLocalAllocators = new ThreadLocalAllocator(-1); + m_NumberOfCullingPassesAccumulatedWithoutAllocatorRewind = 0; + if (ErrorShaderEnabled) { m_ErrorMaterial = EntitiesGraphicsUtils.LoadErrorMaterial(); @@ -1285,11 +1288,7 @@ protected override void OnUpdate() // Make sure any release jobs that have stored pointers in temp allocated // memory have finished before we rewind - m_CullingJobReleaseDependency.Complete(); - m_CullingJobReleaseDependency = default; - m_ReleaseDependency.Complete(); - m_ReleaseDependency = default; - m_ThreadLocalAllocators.Rewind(); + RewindThreadLocalAllocator(); m_LastSystemVersionAtLastUpdate = LastSystemVersion; @@ -1428,6 +1427,16 @@ private void ResetLod() m_ResetLod = true; } + private void RewindThreadLocalAllocator() + { + m_CullingJobReleaseDependency.Complete(); + m_CullingJobReleaseDependency = default; + m_ReleaseDependency.Complete(); + m_ReleaseDependency = default; + m_ThreadLocalAllocators.Rewind(); + m_NumberOfCullingPassesAccumulatedWithoutAllocatorRewind = 0; + } + // This function does only return a meaningful IncludeExcludeListFilter object when called from a BRG culling callback. static IncludeExcludeListFilter GetPickingIncludeExcludeListFilterForCurrentCullingCallback(EntityManager entityManager, in BatchCullingContext cullingContext) { @@ -1494,6 +1503,13 @@ private JobHandle OnPerformCulling(BatchRendererGroup rendererGroup, BatchCullin return m_CullingJobDependency; } + //if we have accumulated too many culling passes without rewinding the allocator in system update, force the rewind here. Otherwise when system update doesn't tick but culling does, we might run out of memory + if (m_NumberOfCullingPassesAccumulatedWithoutAllocatorRewind == kMaxCullingPassesWithoutAllocatorRewind) + { + RewindThreadLocalAllocator(); + } + ++m_NumberOfCullingPassesAccumulatedWithoutAllocatorRewind; + var lodParams = LODGroupExtensions.CalculateLODParams(cullingContext.lodParameters); JobHandle cullingDependency; diff --git a/ValidationExceptions.json b/ValidationExceptions.json index ca50f45..7ddb748 100644 --- a/ValidationExceptions.json +++ b/ValidationExceptions.json @@ -3,29 +3,34 @@ { "ValidationTest": "API Updater Configuration Validation", "ExceptionMessage": "stdout:\nAPIUpdater Configuration Validation\n-----------------------------------\n\nConfiguration Validation Tests (Failed: 0, Total: 1, Ignored 0):\n----------------------------------------------------------------\n\n\nAuto Generated Tests (Failed: 1, Total: 1, Ignored 0):\n------------------------------------------------------\n1) Expected updates not applied for configuration:\n[*] System.SByte [*] Unity.Rendering.MaterialMeshInfo::Submesh -> * Unity.Rendering.MaterialMeshInfo::SubMesh\n\nInput : unsafe class Test : object { System.SByte Method(System.SByte memberValue, Unity.Rendering.MaterialMeshInfo obj) { System.SByte local = obj.Submesh; return Method(obj.Submesh, obj); } }\nExpected: unsafe class Test : object { System.UInt16 Method(System.UInt16 memberValue, Unity.Rendering.MaterialMeshInfo obj) { System.UInt16 local = obj.SubMesh; return Method(obj.SubMesh, obj); } }\nActual : unsafe class Test : object { System.SByte Method(System.SByte memberValue, Unity.Rendering.MaterialMeshInfo obj) { System.SByte local = obj.SubMesh; return Method(obj.SubMesh, obj); } }\n\n\nBase type validation (Failed: 0, Total: 0, Ignored 0):\n------------------------------------------------------\nstderr:\n", - "PackageVersion": "1.4.2" + "PackageVersion": "1.4.3" }, { "ValidationTest": "API Validation", "ExceptionMessage": "Breaking changes require a new major version.", - "PackageVersion": "1.4.2" - } + "PackageVersion": "1.4.3" + }, + { + "ValidationTest": "API Validation", + "ExceptionMessage": "Additions require a new minor or major version.", + "PackageVersion": "1.4.3" + } ], "WarningExceptions": [ { "ValidationTest": "Manifest Validation", "ExceptionMessage": "Package dependency com.unity.entities@0.60.0-preview.88 must be promoted to production before this package is promoted to production. (Except for core packages)", - "PackageVersion": "1.4.2" + "PackageVersion": "1.4.3" }, { "ValidationTest": "Folder Structure Validation", "ExceptionMessage": "The Resources Directory should not be used in packages. For more guidance, please visit https://docs.unity3d.com/Manual/BestPracticeUnderstandingPerformanceInUnity6.html", - "PackageVersion": "1.4.2" + "PackageVersion": "1.4.3" }, { "ValidationTest": "Package Lifecycle Validation", "ExceptionMessage": "com.unity.entities.graphics has never been promoted to production before. Please contact Release Management through slack in #devs-pkg-promotion to promote the first version of your package before trying to use this automated pipeline. Read more about this error and potential solutions at https://docs.unity3d.com/Packages/com.unity.package-validation-suite@latest/index.html?preview=1&subfolder=/manual/lifecycle_validation_error.html#the-very-first-version-of-a-package-must-be-promoted-by-release-management", - "PackageVersion": "1.4.2" + "PackageVersion": "1.4.3" } ] } diff --git a/package.json b/package.json index 1e57f84..9bff652 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.entities.graphics", "displayName": "Entities Graphics", - "version": "1.4.2", + "version": "1.4.3", "unity": "2022.3", "unityRelease": "11f1", "description": "The Entities Graphics package provides systems and components for drawing meshes using DOTS, including support for instanced mesh rendering and LOD.", @@ -17,15 +17,15 @@ "unity" ], "_upm": { - "changelog": "### Changed\n\n* Updated Burst dependency to version 1.8.18\n* Updated entities packages dependencies\n\n### Added\n\n* The new `ProceduralMotion_Tag` tag component data type informs Entities Graphics that an Entity needs to participate in the object motion vector pass. The tag is automatically added for entities that go through the builtin MeshRendererBaker path.\n* Enable entities motion vector pass participation for URP.\n* PruneUploadBufferPool API to request pruning of the upload buffer pool.\n\n\n### Fixed\n\n* GameObjects that depend on vertex shader logic to generate procedural motion vectors through object motion vector passes will now also do the same when baked to Entities and rendered through Entities Graphics." + "changelog": "### Fixed\n* Entities graphics constantly allocating more memory without releasing it until next time system update is called." }, "upmCi": { - "footprint": "0272692301aadf6ab8f8a54a59dd19a7ea2445c3" + "footprint": "6a13371f12053bdd67b593a0076cbd3c777a3351" }, "documentationUrl": "https://docs.unity3d.com/Packages/com.unity.entities.graphics@1.4/manual/index.html", "repository": { "url": "https://github.cds.internal.unity3d.com/unity/dots.git", "type": "git", - "revision": "f9f023a1661a1a7a17264c9907b75c9b46434416" + "revision": "97e332ca8068d973f6571bcb144c924ebd679c79" } }