Skip to content

Commit

Permalink
Merge pull request #8110 from Unity-Technologies/internal/master
Browse files Browse the repository at this point in the history
Internal/master
  • Loading branch information
UnityAljosha authored Nov 28, 2024
2 parents ba62a59 + 15f0495 commit 0ad4df7
Show file tree
Hide file tree
Showing 400 changed files with 32,987 additions and 5,301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This page covers the process of how to use the RenderGraph API to write a render
To begin, your render pipeline needs to maintain at least one instance of [RenderGraph](../api/UnityEngine.Rendering.RenderGraphModule.RenderGraph.html). This is the main entry point for the API. You can use more than one instance of a render graph, but be aware that Unity does not share resources across `RenderGraph` instances so for optimal memory usage, only use one instance.

```c#
using UnityEngine.Rendering;
using UnityEngine.Rendering.RenderGraphModule;

public class MyRenderPipeline : RenderPipeline
Expand All @@ -21,8 +22,11 @@ public class MyRenderPipeline : RenderPipeline
void CleanupRenderGraph()
{
m_RenderGraph.Cleanup();
m_RenderGraph = null;
m_RenderGraph = null;
}

...

}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class CommandBufferGenerator
new FunctionInfo("SetFoveatedRenderingMode", textureArg: "", modifiesGlobalState: true),
new FunctionInfo("ConfigureFoveatedRendering", textureArg: "", modifiesGlobalState: true),
new FunctionInfo("SetWireframe", textureArg: "", modifiesGlobalState: true),
};
new FunctionInfo("SetShadingRateFragmentSize", textureArg: "", modifiesGlobalState: false),
new FunctionInfo("SetShadingRateCombiner", textureArg: "", modifiesGlobalState: false),
};

// Functions for unsafe (wrapper around Commandbuffer) only
static List<FunctionInfo> unsafeFunctions = new List<FunctionInfo> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal webgpu
#define UNIFIED_RT_GROUP_SIZE_X 64
#define UNIFIED_RT_GROUP_SIZE_Y 1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using Unity.Collections;
using UnityEditor;
Expand All @@ -8,7 +9,7 @@
using UnityEngine.LightTransport.PostProcessing;
using UnityEngine.Rendering.Sampling;
using UnityEngine.Rendering.UnifiedRayTracing;

using UnityEngine.SceneManagement;
using TouchupVolumeWithBoundsList = System.Collections.Generic.List<(UnityEngine.Rendering.ProbeReferenceVolume.Volume obb, UnityEngine.Bounds aabb, UnityEngine.Rendering.ProbeAdjustmentVolume volume)>;

namespace UnityEngine.Rendering
Expand Down Expand Up @@ -584,13 +585,16 @@ public void Dispose()
}
}

// The contribution from all Baked and Mixed lights in the scene should be disabled to avoid double contribution.
static void UpdateLightStatus()
{
var lightingSettings = ProbeVolumeLightingTab.GetLightingSettings();

// The contribution from all Baked and Mixed lights in the scene should be disabled to avoid double contribution.
var lights = Object.FindObjectsByType<Light>(FindObjectsSortMode.None);
foreach (var light in lights)
var sceneLights = new Dictionary<Scene, List<Light>>();

// Modify each baked light, take note of which scenes they belong to.
var allLights = Object.FindObjectsByType<Light>(FindObjectsSortMode.None);
foreach (var light in allLights)
{
if (light.lightmapBakeType != LightmapBakeType.Realtime)
{
Expand All @@ -600,6 +604,56 @@ static void UpdateLightStatus()
bakingOutput.mixedLightingMode = lightingSettings.mixedBakeMode;
light.bakingOutput = bakingOutput;
}

// Take note of the lights from each scene
var scene = light.gameObject.scene;
if (!sceneLights.TryGetValue(scene, out var sceneLightList))
{
sceneLightList = new List<Light>();
sceneLights.Add(scene, sceneLightList);
}
sceneLightList.Add(light);
}

// Now we make the modifications persistent by modifying Lighting Data Assets (LDA) on disk.
string ldaFolderPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(m_BakingSet));
for (int i = 0; i < m_BakingSet.sceneGUIDs.Count; i++)
{
string guid = m_BakingSet.sceneGUIDs[i];
Scene scene = SceneManager.GetSceneByPath(AssetDatabase.GUIDToAssetPath(guid));
if (!scene.isLoaded)
continue;

LightingDataAsset prevLDA = Lightmapping.GetLightingDataAssetForScene(scene);
LightingDataAsset newLDA = prevLDA;

// If the scene has no (modifiable) LDA, create a new one.
bool isDefaultLDA = prevLDA && prevLDA.hideFlags.HasFlag(HideFlags.NotEditable);
if (prevLDA == null || isDefaultLDA)
{
newLDA = new LightingDataAsset(scene);
}

// Update the LDA with the new light settings
if (sceneLights.TryGetValue(scene, out var lights))
newLDA.SetLights(lights.ToArray());
else
newLDA.SetLights(Array.Empty<Light>());

// If the scene was using the builtin/default LDA before, copy over environment lighting, so it doesn't change.
if (prevLDA != null)
{
newLDA.SetAmbientProbe(prevLDA.GetAmbientProbe());
newLDA.SetDefaultReflectionCubemap(prevLDA.GetDefaultReflectionCubemap());
}

// Save the LDA to disk and assign it to the scene.
if (newLDA != prevLDA)
{
string ldaPath = $"{ldaFolderPath}/LightingData-{i}.asset".Replace('\\', '/');
AssetDatabase.CreateAsset(newLDA, ldaPath);
Lightmapping.SetLightingDataAssetForScene(scene, newLDA);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ static void FixSeams(NativeArray<int> positionRemap, NativeArray<Vector3> positi
// the dilation process consits in doing a trilinear sample of the higher subdivision brick and override the lower subdiv with that
// We have to mark the probes on the boundary as valid otherwise leak reduction at runtime will interfere with this method


// Use an indirection structure to ensure mem usage stays reasonable
VoxelToBrickCache cache = new VoxelToBrickCache();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
using UnityEditor.Build.Reporting;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

namespace UnityEditor.Rendering
{
class ProbeVolumeBuildProcessor : BuildPlayerProcessor, IProcessSceneWithReport
class ProbeVolumeBuildProcessor : BuildPlayerProcessor, IPostprocessBuildWithReport
{
const string kTempAPVStreamingAssetsPath = "TempAPVStreamingAssets";

Expand All @@ -18,15 +17,27 @@ string GetTempAPVStreamingAssetsPath()
return Path.Combine(libraryPath, kTempAPVStreamingAssetsPath);
}

void PrepareStreamableAsset(ProbeVolumeStreamableAsset asset, string basePath, bool useStreamingAsset)
// Include an asset in the build. The mechanism for doing so depends on whether we are using StreamingAssets path.
static void IncludeStreamableAsset(ProbeVolumeStreamableAsset asset, string basePath, bool useStreamingAsset)
{
asset.UpdateAssetReference(useStreamingAsset);

if (useStreamingAsset)
{
asset.ClearAssetReferenceForBuild();
CopyStreamableAsset(asset, basePath);
}
else
{
asset.EnsureAssetLoaded();
}
}

// Ensure that an asset is not included in the build.
static void StripStreambleAsset(ProbeVolumeStreamableAsset asset)
{
asset.ClearAssetReferenceForBuild();
}

void CopyStreamableAsset(ProbeVolumeStreamableAsset asset, string basePath)
static void CopyStreamableAsset(ProbeVolumeStreamableAsset asset, string basePath)
{
var assetPath = asset.GetAssetPath();
if (!File.Exists(assetPath))
Expand Down Expand Up @@ -60,6 +71,9 @@ void GetProbeVolumeProjectSettings(BuildTarget target, out bool supportProbeVolu
}
}

// Keep track of which assets we touched during the build, so we can restore them after the build.
private static HashSet<ProbeVolumeBakingSet> s_BakingSetsProcessedLastBuild = new();

public override void PrepareForBuild(BuildPlayerContext buildPlayerContext)
{
GetProbeVolumeProjectSettings(buildPlayerContext.BuildPlayerOptions.target, out bool supportProbeVolume, out var maxSHBands);
Expand Down Expand Up @@ -89,16 +103,15 @@ public override void PrepareForBuild(BuildPlayerContext buildPlayerContext)

Directory.CreateDirectory(tempStreamingAssetsPath);

HashSet<ProbeVolumeBakingSet> processedBakingSets = new HashSet<ProbeVolumeBakingSet>();

s_BakingSetsProcessedLastBuild.Clear();
foreach (var scene in buildPlayerContext.BuildPlayerOptions.scenes)
{
var sceneGUID = AssetDatabase.AssetPathToGUID(scene);
var bakingSet = ProbeVolumeBakingSet.GetBakingSetForScene(sceneGUID);
if (bakingSet != null)
{
// Already processed (different scenes can belong to the same baking set).
if (processedBakingSets.Contains(bakingSet))
if (s_BakingSetsProcessedLastBuild.Contains(bakingSet))
continue;

if (!bakingSet.cellSharedDataAsset.IsValid()) // Not baked
Expand All @@ -111,89 +124,53 @@ public override void PrepareForBuild(BuildPlayerContext buildPlayerContext)

bool useStreamingAsset = !GraphicsSettings.GetRenderPipelineSettings<ProbeVolumeGlobalSettings>().probeVolumeDisableStreamingAssets;

PrepareStreamableAsset(bakingSet.cellSharedDataAsset, basePath, useStreamingAsset);
PrepareStreamableAsset(bakingSet.cellBricksDataAsset, basePath, useStreamingAsset);
IncludeStreamableAsset(bakingSet.cellSharedDataAsset, basePath, useStreamingAsset);
IncludeStreamableAsset(bakingSet.cellBricksDataAsset, basePath, useStreamingAsset);
// For now we always strip support data in build as it's mostly unsupported.
// Later we'll need a proper option to strip it or not.
bool stripSupportData = true;
if (!stripSupportData)
PrepareStreamableAsset(bakingSet.cellSupportDataAsset, basePath, useStreamingAsset);
if (stripSupportData)
StripStreambleAsset(bakingSet.cellSupportDataAsset);
else
IncludeStreamableAsset(bakingSet.cellSupportDataAsset, basePath, useStreamingAsset);

foreach (var scenario in bakingSet.scenarios)
{
PrepareStreamableAsset(scenario.Value.cellDataAsset, basePath, useStreamingAsset);
IncludeStreamableAsset(scenario.Value.cellDataAsset, basePath, useStreamingAsset);
if (maxSHBands == ProbeVolumeSHBands.SphericalHarmonicsL2)
PrepareStreamableAsset(scenario.Value.cellOptionalDataAsset, basePath, useStreamingAsset);
PrepareStreamableAsset(scenario.Value.cellProbeOcclusionDataAsset, basePath, useStreamingAsset);
IncludeStreamableAsset(scenario.Value.cellOptionalDataAsset, basePath, useStreamingAsset);
else
StripStreambleAsset(scenario.Value.cellOptionalDataAsset);
IncludeStreamableAsset(scenario.Value.cellProbeOcclusionDataAsset, basePath, useStreamingAsset);
}

processedBakingSets.Add(bakingSet);
s_BakingSetsProcessedLastBuild.Add(bakingSet);
}
}

buildPlayerContext.AddAdditionalPathToStreamingAssets(tempStreamingAssetsPath, AdaptiveProbeVolumes.kAPVStreamingAssetsPath);
}

private static bool IsBundleBuild(BuildReport report, bool isPlaying)
{
// We are entering playmode, so not building a bundle.
if (isPlaying)
return false;

// Addressable builds do not provide a BuildReport. Because the Addressables package
// only supports AssetBundle builds, we infer that this is not a player build.
if (report == null)
return true;

return report.summary.buildType == BuildType.AssetBundle;
}

// This codepath handles the case of building asset bundles, i.e. not a full player build. It updates the references
// to individual data assets in the baking sets for each scene, such that the assets are included in the bundle.
public override int callbackOrder => 1;
public void OnProcessScene(Scene scene, BuildReport report)
public void OnPostprocessBuild(BuildReport report)
{
// Only run for bundle builds.
if (!IsBundleBuild(report, Application.isPlaying))
return;

// Only run when APV is enabled.
GetProbeVolumeProjectSettings(EditorUserBuildSettings.activeBuildTarget, out bool supportProbeVolume, out var maxSHBands);
if (!supportProbeVolume)
return;

// Reload the map from scene to baking set if we couldn't find the specific baking set.
if (ProbeVolumeBakingSet.sceneToBakingSet == null || ProbeVolumeBakingSet.sceneToBakingSet.Count == 0)
ProbeVolumeBakingSet.SyncBakingSets();

// Get the baking set for the scene.
var bakingSet = ProbeVolumeBakingSet.GetBakingSetForScene(scene.GetGUID());
if (bakingSet == null || !bakingSet.cellSharedDataAsset.IsValid())
if (s_BakingSetsProcessedLastBuild == null || s_BakingSetsProcessedLastBuild.Count == 0)
return;

bool useStreamingAsset = !GraphicsSettings.GetRenderPipelineSettings<ProbeVolumeGlobalSettings>().probeVolumeDisableStreamingAssets;
if (useStreamingAsset)
// Go over each asset reference we touched during the last build, make sure asset references are intact.
foreach (var bakingSet in s_BakingSetsProcessedLastBuild)
{
Debug.LogWarning(
"Attempted to build an Asset Bundle containing Adaptive Probe Volume data, but streaming assets are enabled. This is unsupported. " +
"To use Adaptive Probe Volumes with Asset Bundles, please check 'Probe Volume Disable Streaming Assets' under Graphics Settings.");
bakingSet.cellBricksDataAsset.EnsureAssetLoaded();
bakingSet.cellSharedDataAsset.EnsureAssetLoaded();
bakingSet.cellSupportDataAsset.EnsureAssetLoaded();
foreach (var scenario in bakingSet.scenarios)
{
scenario.Value.cellDataAsset.EnsureAssetLoaded();
scenario.Value.cellOptionalDataAsset.EnsureAssetLoaded();
scenario.Value.cellProbeOcclusionDataAsset.EnsureAssetLoaded();
}
}

// Update all the asset references.
bakingSet.cellSharedDataAsset.UpdateAssetReference(useStreamingAsset);
bakingSet.cellBricksDataAsset.UpdateAssetReference(useStreamingAsset);

bool stripSupportData = true;
if (!stripSupportData)
bakingSet.cellSupportDataAsset.UpdateAssetReference(false);

foreach (var scenario in bakingSet.scenarios)
{
scenario.Value.cellDataAsset.UpdateAssetReference(useStreamingAsset);
if (maxSHBands == ProbeVolumeSHBands.SphericalHarmonicsL2)
scenario.Value.cellOptionalDataAsset.UpdateAssetReference(useStreamingAsset);
scenario.Value.cellProbeOcclusionDataAsset.UpdateAssetReference(useStreamingAsset);
}
s_BakingSetsProcessedLastBuild.Clear();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma kernel DilateCell

#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch webgpu

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.Rendering;
using UnityEditor.SceneManagement;
Expand Down Expand Up @@ -510,7 +511,9 @@ void SaveTempBakingSetIfNeeded()
string path = string.IsNullOrEmpty(scene.path) ?
ProbeVolumeBakingSet.GetDirectory("Assets/", "Untitled") :
ProbeVolumeBakingSet.GetDirectory(scene.path, scene.name);
path = System.IO.Path.Combine(path, activeSet.name + ".asset");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
path = Path.Combine(path, activeSet.name + ".asset");
path = AssetDatabase.GenerateUniqueAssetPath(path);

AssetDatabase.CreateAsset(activeSet, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#pragma kernel VoxelizeProbeVolumeData
#pragma kernel Subdivide

#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch webgpu

// #pragma enable_d3d11_debug_symbols

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal webgpu switch
#define UNIFIED_RT_GROUP_SIZE_X 64
#define UNIFIED_RT_GROUP_SIZE_Y 1

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0ad4df7

Please sign in to comment.