Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3511048
[Port] [6000.2] DOCG - General Bug Bash Aug 2025 PR
svc-reach-platform-support Aug 22, 2025
f135fca
[Port] [6000.2] DOCG-7358 Scene Color Node docs improvements
svc-reach-platform-support Aug 22, 2025
cbae7e5
[Port] [6000.2] DOCG-7309 Branch node docs improvements
svc-reach-platform-support Aug 22, 2025
72ac3ea
[Port] [6000.2] DOCG-7283 Improve Replace Color node docs
markg-unity Aug 22, 2025
4fdbd2f
[Port] [6000.2] DOCG-7073 Custom interpolator node docs improvements
markg-unity Aug 22, 2025
ae4b0e5
[Port] [6000.2] DOCG-7115 Improve Scene Depth Difference node docs
svc-reach-platform-support Aug 22, 2025
14623e0
[Port] [6000.2] DOCG-7438 Improve Emission node docs
svc-reach-platform-support Aug 22, 2025
bc50e01
[Port] [6000.2] DOCG-7342 Improvements to Dither node docs
svc-reach-platform-support Aug 22, 2025
86c0686
[Backport] OutOfMemory exception in the console and unreleased memory…
belgaard Aug 22, 2025
7ff6c4a
[Port] [6000.2] DOCG-7257: Fix typo
svc-reach-platform-support Aug 22, 2025
2086c64
[Port] [6000.2] DOCG-7262: Link to latest version of Manual docs
svc-reach-platform-support Aug 22, 2025
b258639
[Port] [6000.2] Add conditional shader renaming for Autodesk Interact…
mseonkim-unity Aug 26, 2025
ecde8ef
[Port] [6000.2] DOCG-7288 port descript fix
svc-reach-platform-support Aug 26, 2025
c3ff062
[Port] [6000.2] DOCG-7195 Update volumetric fog with light layers note
svc-reach-platform-support Aug 26, 2025
7f48fd9
[6000.2][UUM-111385] Fix WebGL 2D with shadowed lighting
kennytann Sep 2, 2025
86e043c
[Port] [6000.2] [UUM-101919][6000.3][2D] Fix Light Batching Debugger …
svc-reach-platform-support Sep 2, 2025
35685ea
[Port] [6000.2] DOCG-7369 Improve Object node docs
svc-reach-platform-support Sep 2, 2025
4867644
[UUM-115756] [UUM-115757] Disabling 2 tests on PS4
christian-sasseville Sep 2, 2025
d7f5a4f
[Port] [6000.2] docg-7338: Fix Parallax Mapping image
svc-reach-platform-support Sep 2, 2025
295918b
[Port] [6000.2] docg-7367: Add section about https://unity.com/blog/e…
svc-reach-platform-support Sep 2, 2025
475ed45
[Port] [6000.2] docg-7320: Unexposed properties revert to default values
svc-reach-platform-support Sep 2, 2025
ba52e78
[Port] [6000.2] docs/graphics/docg-7326: Improve explanation of Unpac…
svc-reach-platform-support Sep 2, 2025
469b614
[Port] [6000.2] DOCG-6643: Improve quality of Blackboard page in VFX …
svc-reach-platform-support Sep 2, 2025
1a82bb3
[Port] [6000.2] docg-7339: Clarify Reoriented option for Normal Blend…
svc-reach-platform-support Sep 2, 2025
8407e9a
[Port] [6000.2] docg-7367: add Lerp formula and additional info
svc-reach-platform-support Sep 2, 2025
24003ad
[Port] [6000.2] docs/graphics/docg-7270: add comment to basic test code
svc-reach-platform-support Sep 2, 2025
d555481
[Port] [6000.2] docg-7769: Add Additional resources section
svc-reach-platform-support Sep 2, 2025
242cdbe
[Port] [6000.2] docg-7723: Change link
svc-reach-platform-support Sep 2, 2025
280aae3
[Port] [6000.2] DOCG-7365 Shader Graph feedback improvements
svc-reach-platform-support Sep 3, 2025
e844777
[Port] [6000.2] [UUM-115779] Fix artifacts caused by tiled deferred l…
svc-reach-platform-support Sep 4, 2025
fc72ced
[Port] [6000.2] UUM-115123 - Disallow GPU Driven for MeshRenderers wh…
svc-reach-platform-support Sep 4, 2025
80dddd2
[Port] [6000.2] DOCG-7264: Remove screenshots from node landing page
ocarrere Sep 4, 2025
649da10
[Port] [6000.2] docg-7781: Fix typo
svc-reach-platform-support Sep 4, 2025
6119bd8
[Port] [6000.2] [UUM-70734] Fix for Size of ShadowCaster2D with Casti…
svc-reach-platform-support Sep 8, 2025
94f291f
[6000.2] Fix Multiple errors occur when setting the Render Object Eve…
Sep 8, 2025
c2e8eb9
[Port] [6000.2] UUM-116018 : Fix GRDLightMaps test
svc-reach-platform-support Sep 9, 2025
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 @@ -1005,27 +1005,36 @@ internal static void BakeAdjustmentVolume(ProbeVolumeBakingSet bakingSet, ProbeA

if (!failed)
{
for (int c = 0; c < bakingCells.Length; c++)
// Validate baking cells size before any global state modifications
var chunkSizeInProbes = ProbeBrickPool.GetChunkSizeInProbeCount();
var hasVirtualOffsets = m_BakingSet.settings.virtualOffsetSettings.useVirtualOffset;
var hasRenderingLayers = m_BakingSet.useRenderingLayers;

if (ValidateBakingCellsSize(bakingCells, chunkSizeInProbes, hasVirtualOffsets, hasRenderingLayers))
{
ref var cell = ref bakingCells[c];
ComputeValidityMasks(cell);
}

// Write result to disk
WriteBakingCells(bakingCells);
for (int c = 0; c < bakingCells.Length; c++)
{
ref var cell = ref bakingCells[c];
ComputeValidityMasks(cell);
}

// Reload everything
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
// Attempt to write the result to disk
if (WriteBakingCells(bakingCells))
{
// Reload everything
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

if (m_BakingSet.hasDilation)
{
// Force reloading of data
foreach (var data in prv.perSceneDataList)
data.Initialize();
if (m_BakingSet.hasDilation)
{
// Force reloading of data
foreach (var data in prv.perSceneDataList)
data.Initialize();

InitDilationShaders();
PerformDilation();
InitDilationShaders();
PerformDilation();
}
}
}
}
}
Expand All @@ -1045,6 +1054,7 @@ internal static void BakeAdjustmentVolume(ProbeVolumeBakingSet bakingSet, ProbeA
bakingSet.settings.virtualOffsetSettings.useVirtualOffset = savedVirtualOffset;
bakingSet.useRenderingLayers = savedRenderingLayers;

m_BakingBatch?.Dispose();
m_BakingBatch = null;
m_BakingSet = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Unity.Collections;
using UnityEngine.SceneManagement;
using UnityEditor;

using System.Runtime.InteropServices;
using Brick = UnityEngine.Rendering.ProbeBrickIndex.Brick;

namespace UnityEngine.Rendering
Expand Down Expand Up @@ -187,7 +187,8 @@ static NativeList<Vector3> ApplySubdivisionResults(ProbeSubdivisionResult result
int positionStart = positions.Length;

ConvertBricksToPositions(bricks, out var probePositions, out var brickSubdivLevels);
DeduplicateProbePositions(in probePositions, in brickSubdivLevels, m_BakingBatch, positions, out var probeIndices);
if (!DeduplicateProbePositions(in probePositions, in brickSubdivLevels, m_BakingBatch, positions, out var probeIndices))
return new NativeList<Vector3>(Allocator.Persistent);

BakingCell cell = new BakingCell()
{
Expand All @@ -206,9 +207,22 @@ static NativeList<Vector3> ApplySubdivisionResults(ProbeSubdivisionResult result
return positions;
}

private static void DeduplicateProbePositions(in Vector3[] probePositions, in int[] brickSubdivLevel, BakingBatch batch,
// We know that the current limitation on native containers is this. When an integer overflow bug (https://jira.unity3d.com/browse/UUM-113721) has been fixed, we can raise the limit
// This and related work is tracked by https://jira.unity3d.com/browse/GFXLIGHT-1738
static readonly long k_MaxNumberOfPositions = 67180350;

static bool DeduplicateProbePositions(in Vector3[] probePositions, in int[] brickSubdivLevel, BakingBatch batch,
NativeList<Vector3> uniquePositions, out int[] indices)
{
long numberOfPositions = (long)probePositions.Length + batch.positionToIndex.Count;
if (numberOfPositions > k_MaxNumberOfPositions)
{
Debug.LogError($"The number of Adaptive Probe Volume (APV) probes Unity generated exceeds the current system limit of {k_MaxNumberOfPositions} probes per Baking Set. Reduce density either by adjusting the general Probe Spacing in the Lighting window, or by modifying the Adaptive Probe Volumes in the scene to limit where the denser subdivision levels are used.");
indices = null;

return false;
}

indices = new int[probePositions.Length];
int uniqueIndex = batch.positionToIndex.Count;

Expand All @@ -234,6 +248,8 @@ private static void DeduplicateProbePositions(in Vector3[] probePositions, in in
uniqueIndex++;
}
}

return true;
}

static ProbeSubdivisionResult GetBricksFromLoaded()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,63 @@ static void ExtractBakingCells()

static long AlignRemainder16(long count) => count % 16L;

/// <summary>
/// Calculates support data chunk size based on provided configuration.
/// </summary>
/// <param name="chunkSizeInProbes">Number of probes per chunk</param>
/// <param name="hasVirtualOffsets">Whether virtual offsets are enabled</param>
/// <param name="hasRenderingLayers">Whether rendering layers are enabled</param>
/// <returns>The size in bytes of a single support data chunk</returns>
static int CalculateSupportDataChunkSize(int chunkSizeInProbes, bool hasVirtualOffsets, bool hasRenderingLayers)
{
int supportPositionChunkSize = UnsafeUtility.SizeOf<Vector3>() * chunkSizeInProbes;
int supportValidityChunkSize = UnsafeUtility.SizeOf<float>() * chunkSizeInProbes;
int supportTouchupChunkSize = UnsafeUtility.SizeOf<float>() * chunkSizeInProbes;
int supportLayerMaskChunkSize = hasRenderingLayers ? UnsafeUtility.SizeOf<byte>() * chunkSizeInProbes : 0;
int supportOffsetsChunkSize = hasVirtualOffsets ? UnsafeUtility.SizeOf<Vector3>() * chunkSizeInProbes : 0;

return supportPositionChunkSize + supportValidityChunkSize +
supportOffsetsChunkSize + supportLayerMaskChunkSize + supportTouchupChunkSize;
}

/// <summary>
/// Validates that the baking cells can be written without exceeding system limits.
/// This method performs size calculations without accessing any global state.
/// </summary>
/// <param name="bakingCells">Array of baking cells to validate</param>
/// <param name="chunkSizeInProbes">Number of probes per chunk</param>
/// <param name="hasVirtualOffsets">Whether virtual offsets are enabled</param>
/// <param name="hasRenderingLayers">Whether rendering layers are enabled</param>
/// <returns>True if cells can be written safely, false if they exceed limits</returns>
static bool ValidateBakingCellsSize(BakingCell[] bakingCells, int chunkSizeInProbes, bool hasVirtualOffsets, bool hasRenderingLayers)
{
if (bakingCells == null || bakingCells.Length == 0)
return true;

int supportDataChunkSize = CalculateSupportDataChunkSize(chunkSizeInProbes, hasVirtualOffsets, hasRenderingLayers);

// Calculate total chunks count - need to call AnalyzeBrickForIndirectionEntries to get shChunkCount
// Create a copy to avoid modifying the original cells during validation
var tempCells = new BakingCell[bakingCells.Length];
int totalChunksCount = 0;
for (var i = 0; i < bakingCells.Length; ++i)
{
tempCells[i] = bakingCells[i]; // Shallow copy is sufficient for this validation
AnalyzeBrickForIndirectionEntries(ref tempCells[i]);
totalChunksCount += tempCells[i].shChunkCount;
}

// Perform the critical size check
long supportDataTotalSize = (long)totalChunksCount * supportDataChunkSize;
if (supportDataTotalSize > int.MaxValue)
{
Debug.LogError($"The size of the Adaptive Probe Volume (APV) baking set chunks exceed the current system limit of {int.MaxValue}, unable to save the baked cell assets. Reduce density either by adjusting the general Probe Spacing in the Lighting window, or by modifying the Adaptive Probe Volumes in the scene to limit where the denser subdivision levels are used.");
return false;
}

return true;
}

static void WriteNativeArray<T>(System.IO.FileStream fs, NativeArray<T> array) where T : struct
{
unsafe
Expand All @@ -736,7 +793,7 @@ static void WriteNativeArray<T>(System.IO.FileStream fs, NativeArray<T> array) w
}

/// <summary>
/// This method converts a list of baking cells into 5 separate assets:
/// This method attempts to convert a list of baking cells into 5 separate assets:
/// 2 assets per baking state:
/// CellData: a binary flat file containing L0L1 probes data
/// CellOptionalData: a binary flat file containing L2 probe data (when present)
Expand All @@ -745,7 +802,7 @@ static void WriteNativeArray<T>(System.IO.FileStream fs, NativeArray<T> array) w
/// CellSharedData: a binary flat file containing bricks data
/// CellSupportData: a binary flat file containing debug data (stripped from player builds if building without debug shaders)
/// </summary>
unsafe static void WriteBakingCells(BakingCell[] bakingCells)
static unsafe bool WriteBakingCells(BakingCell[] bakingCells)
{
m_BakingSet.GetBlobFileNames(m_BakingSet.lightingScenario, out var cellDataFilename, out var cellBricksDataFilename, out var cellOptionalDataFilename, out var cellProbeOcclusionDataFilename, out var cellSharedDataFilename, out var cellSupportDataFilename);

Expand Down Expand Up @@ -846,16 +903,16 @@ unsafe static void WriteBakingCells(BakingCell[] bakingCells)
// Brick data
using var bricks = new NativeArray<Brick>(m_TotalCellCounts.bricksCount, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

// CellSupportData
m_BakingSet.supportPositionChunkSize = sizeof(Vector3) * chunkSizeInProbes;
m_BakingSet.supportValidityChunkSize = sizeof(float) * chunkSizeInProbes;
m_BakingSet.supportOffsetsChunkSize = hasVirtualOffsets ? sizeof(Vector3) * chunkSizeInProbes : 0;
m_BakingSet.supportTouchupChunkSize = sizeof(float) * chunkSizeInProbes;
m_BakingSet.supportLayerMaskChunkSize = hasRenderingLayers ? sizeof(byte) * chunkSizeInProbes : 0;
// CellSupportData - use pure helper function for calculation
m_BakingSet.supportPositionChunkSize = UnsafeUtility.SizeOf<Vector3>() * chunkSizeInProbes;
m_BakingSet.supportValidityChunkSize = UnsafeUtility.SizeOf<float>() * chunkSizeInProbes;
m_BakingSet.supportOffsetsChunkSize = hasVirtualOffsets ? UnsafeUtility.SizeOf<Vector3>() * chunkSizeInProbes : 0;
m_BakingSet.supportTouchupChunkSize = UnsafeUtility.SizeOf<float>() * chunkSizeInProbes;
m_BakingSet.supportLayerMaskChunkSize = hasRenderingLayers ? UnsafeUtility.SizeOf<byte>() * chunkSizeInProbes : 0;

m_BakingSet.supportDataChunkSize = m_BakingSet.supportPositionChunkSize + m_BakingSet.supportValidityChunkSize + m_BakingSet.supportOffsetsChunkSize + m_BakingSet.supportLayerMaskChunkSize + m_BakingSet.supportTouchupChunkSize;
var supportDataTotalSize = m_TotalCellCounts.chunksCount * m_BakingSet.supportDataChunkSize;
using var supportData = new NativeArray<byte>(supportDataTotalSize, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
m_BakingSet.supportDataChunkSize = CalculateSupportDataChunkSize(chunkSizeInProbes, hasVirtualOffsets, hasRenderingLayers);
long supportDataTotalSize = (long)m_TotalCellCounts.chunksCount * m_BakingSet.supportDataChunkSize;
using var supportData = new NativeArray<byte>((int)supportDataTotalSize, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

var sceneStateHash = m_BakingSet.GetBakingHashCode();
var startCounts = new CellCounts();
Expand Down Expand Up @@ -1093,6 +1150,8 @@ unsafe static void WriteBakingCells(BakingCell[] bakingCells)
m_BakingSet.cellSupportDataAsset = new ProbeVolumeStreamableAsset(kAPVStreamingAssetsPath, cellSupportDescs, m_BakingSet.supportDataChunkSize, bakingSetGUID, AssetDatabase.AssetPathToGUID(cellSupportDataFilename));

EditorUtility.SetDirty(m_BakingSet);

return true;
}

unsafe static void WriteDilatedCells(List<Cell> cells)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,19 @@ static internal void RecomputeVOForDebugOnly()
// Make sure unloading happens.
prv.PerformPendingOperations();

// Write back the assets.
WriteBakingCells(m_BakingBatch.cells.ToArray());
// Validate baking cells size before writing
var bakingCellsArray = m_BakingBatch.cells.ToArray();
var chunkSizeInProbes = ProbeBrickPool.GetChunkSizeInProbeCount();
var hasVirtualOffsets = m_BakingSet.settings.virtualOffsetSettings.useVirtualOffset;
var hasRenderingLayers = m_BakingSet.useRenderingLayers;

if (ValidateBakingCellsSize(bakingCellsArray, chunkSizeInProbes, hasVirtualOffsets, hasRenderingLayers))
{
// Write back the assets.
WriteBakingCells(bakingCellsArray);
}

m_BakingBatch?.Dispose();
m_BakingBatch = null;

foreach (var data in prv.perSceneDataList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,15 @@ internal int GetBakingHashCode()
}
}

class BakingBatch
class BakingBatch : IDisposable
{
public Dictionary<int, HashSet<string>> cellIndex2SceneReferences = new ();
public List<BakingCell> cells = new ();
// Used to retrieve probe data from it's position in order to fix seams
public Dictionary<int, int> positionToIndex = new ();
public NativeHashMap<int, int> positionToIndex;
// Allow to get a mapping to subdiv level with the unique positions. It stores the minimum subdiv level found for a given position.
// Can be probably done cleaner.
public Dictionary<int, int> uniqueBrickSubdiv = new ();
public NativeHashMap<int, int> uniqueBrickSubdiv;
// Mapping for explicit invalidation, whether it comes from the auto finding of occluders or from the touch up volumes
// TODO: This is not used yet. Will soon.
public Dictionary<Vector3, bool> invalidatedPositions = new ();
Expand Down Expand Up @@ -306,6 +306,19 @@ public BakingBatch(Vector3Int cellCount)
maxBrickCount = cellCount * ProbeReferenceVolume.CellSize(ProbeReferenceVolume.instance.GetMaxSubdivision());
inverseScale = ProbeBrickPool.kBrickCellCount / ProbeReferenceVolume.instance.MinBrickSize();
offset = ProbeReferenceVolume.instance.ProbeOffset();

// Initialize NativeHashMaps with reasonable initial capacity
// Using a larger capacity to reduce allocations during baking
positionToIndex = new NativeHashMap<int, int>(100000, Allocator.Persistent);
uniqueBrickSubdiv = new NativeHashMap<int, int>(100000, Allocator.Persistent);
}

public void Dispose()
{
if (positionToIndex.IsCreated)
positionToIndex.Dispose();
if (uniqueBrickSubdiv.IsCreated)
uniqueBrickSubdiv.Dispose();
}

public int GetProbePositionHash(Vector3 position)
Expand Down Expand Up @@ -1202,6 +1215,7 @@ static void OnBakeCancelled()
static void CleanBakeData()
{
s_BakeData.Dispose();
m_BakingBatch?.Dispose();
m_BakingBatch = null;
s_AdjustmentVolumes = null;

Expand Down Expand Up @@ -1478,6 +1492,15 @@ static void ApplyPostBakeOperations()
// Use the globalBounds we just computed, as the one in probeRefVolume doesn't include scenes that have never been baked
probeRefVolume.globalBounds = globalBounds;

// Validate baking cells size before any state modifications
var bakingCellsArray = m_BakedCells.Values.ToArray();
var chunkSizeInProbes = ProbeBrickPool.GetChunkSizeInProbeCount();
var hasVirtualOffsets = m_BakingSet.settings.virtualOffsetSettings.useVirtualOffset;
var hasRenderingLayers = m_BakingSet.useRenderingLayers;

if (!ValidateBakingCellsSize(bakingCellsArray, chunkSizeInProbes, hasVirtualOffsets, hasRenderingLayers))
return; // Early exit if validation fails

PrepareCellsForWriting(isBakingSceneSubset);

m_BakingSet.chunkSizeInBricks = ProbeBrickPool.GetChunkSizeInBrickCount();
Expand All @@ -1488,9 +1511,13 @@ static void ApplyPostBakeOperations()

m_BakingSet.scenarios.TryAdd(m_BakingSet.lightingScenario, new ProbeVolumeBakingSet.PerScenarioDataInfo());

// Convert baking cells to runtime cells
// Attempt to convert baking cells to runtime cells
bool succeededWritingBakingCells;
using (new BakingCompleteProfiling(BakingCompleteProfiling.Stages.WriteBakedData))
WriteBakingCells(m_BakedCells.Values.ToArray());
succeededWritingBakingCells = WriteBakingCells(m_BakedCells.Values.ToArray());

if (!succeededWritingBakingCells)
return;

// Reset internal structures depending on current bake.
Debug.Assert(probeRefVolume.EnsureCurrentBakingSet(m_BakingSet));
Expand Down Expand Up @@ -1534,6 +1561,7 @@ static void ApplyPostBakeOperations()
}

// Mark stuff as up to date
m_BakingBatch?.Dispose();
m_BakingBatch = null;
foreach (var probeVolume in GetProbeVolumeList())
probeVolume.OnBakeCompleted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ public class MaterialUpgrader
/// <summary>
/// Retrieves path to new shader.
/// </summary>
public string NewShaderPath
{
get => m_NewShader;
}
public string NewShaderPath => m_NewShader;

/// <summary>
/// Retrieves path to old shader.
/// </summary>
public string OldShaderPath => m_OldShader;

MaterialFinalizer m_Finalizer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ private static void AllowGPUDrivenRenderingRecursively(Transform transform, bool
private void OnValidate()
{
OnDisable();
OnEnable();
if (enabled)
OnEnable();
}
}
}
Loading