Skip to content

Commit

Permalink
Merge pull request #8117 from Unity-Technologies/internal/6000.0/staging
Browse files Browse the repository at this point in the history
Internal/6000.0/staging
  • Loading branch information
UnityAljosha authored Dec 18, 2024
2 parents a65be2c + ad407bb commit a66eeaf
Show file tree
Hide file tree
Showing 112 changed files with 32,849 additions and 359 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 @@ -88,18 +88,23 @@ protected void CreateDefaultVolumeProfileEditor()
}
m_EditorContainer.Add(s_DefaultVolumeProfileEditor.Create());
m_EditorContainer.Q<HelpBox>("volume-override-info-box").text = volumeInfoBoxLabel.text;

if (m_DefaultVolumeProfileFoldoutExpanded.value)
m_EditorContainer.style.display = DisplayStyle.Flex;
}

/// <summary>
/// Destroys the Default Volume Profile editor.
/// </summary>
protected void DestroyDefaultVolumeProfileEditor()
{
m_EditorContainer.style.display = DisplayStyle.None;
m_EditorContainer?.Clear();

if (s_DefaultVolumeProfileEditor != null)
s_DefaultVolumeProfileEditor.Destroy();
s_DefaultVolumeProfileEditor = null;
s_DefaultVolumeProfileSerializedProperty = null;
m_EditorContainer?.Clear();
}

/// <summary>
Expand All @@ -124,8 +129,6 @@ public abstract class DefaultVolumeProfileSettingsContextMenu<TSetting, TRenderP

void IRenderPipelineGraphicsSettingsContextMenu<TSetting>.PopulateContextMenu(TSetting setting, PropertyDrawer _, ref GenericMenu menu)
{
menu.AddSeparator("");

bool canCreateNewAsset = RenderPipelineManager.currentPipeline is TRenderPipeline;
VolumeProfileUtils.AddVolumeProfileContextMenuItems(ref menu,
setting.volumeProfile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ public static void EnsureAllOverridesForDefaultProfile(VolumeProfile profile, Vo
{
VolumeManager.instance.OnVolumeProfileChanged(profile);
EditorUtility.SetDirty(profile);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,9 @@ CellInstancedDebugProbes CreateInstancedProbes(Cell cell)
if (cell.debugProbes != null)
return cell.debugProbes;

if (HasActiveStreamingRequest(cell))
return null;

int maxSubdiv = GetMaxSubdivision() - 1;

if (!cell.data.bricks.IsCreated || cell.data.bricks.Length == 0 || !cell.data.probePositions.IsCreated || !cell.loaded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,11 @@ void UpdateDiskStreaming(CommandBuffer cmd)
}
}

bool HasActiveStreamingRequest(Cell cell)
{
return diskStreamingEnabled && m_ActiveStreamingRequests.Exists(x => x.cell == cell);
}

[Conditional("UNITY_EDITOR")]
[Conditional("DEVELOPMENT_BUILD")]
void LogStreaming(string log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ref ResourceVersionedData VersionedResourceData(ResourceHandle h)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ReadOnlySpan<ResourceReaderData> Readers(ResourceHandle h)
{
int firstReader = ResourcesData.IndexReader(h, 0);
int firstReader = resources.IndexReader(h, 0);
int numReaders = resources[h].numReaders;
return resources.readerData[h.iType].MakeReadOnlySpan(firstReader, numReaders);
}
Expand All @@ -114,7 +114,7 @@ public ref ResourceReaderData ResourceReader(ResourceHandle h, int i)
throw new Exception("Invalid reader id");
}
#endif
return ref resources.readerData[h.iType].ElementAt(ResourcesData.IndexReader(h, 0) + i);
return ref resources.readerData[h.iType].ElementAt(resources.IndexReader(h, 0) + i);
}

// Data per graph level renderpass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ internal void GenerateNativeCompilerDebugData(ref RenderGraph.DebugData debugDat
var numReaders = outputDataVersioned.numReaders;
for (var i = 0; i < numReaders; ++i)
{
var depIdx = ResourcesData.IndexReader(output.resource, i);
var depIdx = ctx.resources.IndexReader(output.resource, i);
ref var dep = ref ctx.resources.readerData[output.resource.iType].ElementAt(depIdx);

var outputDependencyPass = ctx.passData[dep.passId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void FindResourceUsageRanges()
var numReaders = pointToVer.numReaders;
for (var i = 0; i < numReaders; ++i)
{
var depIdx = ResourcesData.IndexReader(outputResource, i);
var depIdx = ctx.resources.IndexReader(outputResource, i);
ref var dep = ref ctx.resources.readerData[outputResource.iType].ElementAt(depIdx);
ref var depPass = ref ctx.passData.ElementAt(dep.passId);
if (pass.asyncCompute != depPass.asyncCompute)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ public void SetWritingPass(CompilerContextData ctx, ResourceHandle h, int passId
public void RegisterReadingPass(CompilerContextData ctx, ResourceHandle h, int passId, int index)
{
#if DEVELOPMENT_BUILD || UNITY_EDITOR
if (numReaders >= ResourcesData.MaxReaders)
if (numReaders >= ctx.resources.MaxReaders)
{
string passName = ctx.GetPassName(passId);
string resourceName = ctx.GetResourceName(h);
throw new Exception($"Maximum '{ResourcesData.MaxReaders}' passes can use a single graph output as input. Pass {passName} is trying to read {resourceName}.");
throw new Exception($"Maximum '{ctx.resources.MaxReaders}' passes can use a single graph output as input. Pass {passName} is trying to read {resourceName}.");
}
#endif
ctx.resources.readerData[h.iType][ResourcesData.IndexReader(h, numReaders)] = new ResourceReaderData
ctx.resources.readerData[h.iType][ctx.resources.IndexReader(h, numReaders)] = new ResourceReaderData
{
passId = passId,
inputSlot = index
Expand All @@ -167,13 +167,13 @@ public void RemoveReadingPass(CompilerContextData ctx, ResourceHandle h, int pas
{
for (int r = 0; r < numReaders;)
{
ref var reader = ref ctx.resources.readerData[h.iType].ElementAt(ResourcesData.IndexReader(h, r));
ref var reader = ref ctx.resources.readerData[h.iType].ElementAt(ctx.resources.IndexReader(h, r));
if (reader.passId == passId)
{
// It should be removed, switch with the end of the list if we're not already at the end of it
if (r < numReaders - 1)
{
reader = ctx.resources.readerData[h.iType][ResourcesData.IndexReader(h, numReaders - 1)];
reader = ctx.resources.readerData[h.iType][ctx.resources.IndexReader(h, numReaders - 1)];
}

numReaders--;
Expand All @@ -193,8 +193,9 @@ internal class ResourcesData
public NativeList<ResourceUnversionedData>[] unversionedData; // Flattened fixed size array storing info per resource id shared between all versions.
public NativeList<ResourceVersionedData>[] versionedData; // Flattened fixed size array storing up to MaxVersions versions per resource id.
public NativeList<ResourceReaderData>[] readerData; // Flattened fixed size array storing up to MaxReaders per resource id per version.
public const int MaxVersions = 20; // A quite arbitrary limit should be enough for most graphs. Increasing it shouldn't be a problem but will use more memory as these lists use a fixed size upfront allocation.
public const int MaxReaders = 100; // A quite arbitrary limit should be enough for most graphs. Increasing it shouldn't be a problem but will use more memory as these lists use a fixed size upfront allocation.

public int MaxVersions;
public int MaxReaders;

public DynamicArray<Name>[] resourceNames;

Expand Down Expand Up @@ -229,6 +230,9 @@ public void Clear()

public void Initialize(RenderGraphResourceRegistry resources)
{
uint maxReaders = 0;
uint maxWriters = 0;

for (int t = 0; t < (int)RenderGraphResourceType.Count; t++)
{
RenderGraphResourceType resourceType = (RenderGraphResourceType) t;
Expand Down Expand Up @@ -287,8 +291,15 @@ public void Initialize(RenderGraphResourceRegistry resources)
default:
throw new Exception("Unsupported resource type: " + t);
}

maxReaders = Math.Max(maxReaders, rll.readCount);
maxWriters = Math.Max(maxWriters, rll.writeCount);
}

// The first resource is a null resource, so we need to add 1 to the count.
MaxReaders = (int)maxReaders + 1;
MaxVersions = (int)maxWriters + 1;

// Clear the other caching structures, they will be filled later
versionedData[t].Resize(MaxVersions * numResources, NativeArrayOptions.ClearMemory);
readerData[t].Resize(MaxVersions * MaxReaders * numResources, NativeArrayOptions.ClearMemory);
Expand All @@ -297,7 +308,7 @@ public void Initialize(RenderGraphResourceRegistry resources)

// Flatten array index
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Index(ResourceHandle h)
public int Index(ResourceHandle h)
{
#if UNITY_EDITOR // Hot path
if (h.version < 0 || h.version >= MaxVersions)
Expand All @@ -308,7 +319,7 @@ public static int Index(ResourceHandle h)

// Flatten array index
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int IndexReader(ResourceHandle h, int readerID)
public int IndexReader(ResourceHandle h, int readerID)
{
#if UNITY_EDITOR // Hot path
if (h.version < 0 || h.version >= MaxVersions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ private ResourceHandle UseResource(in ResourceHandle handle, AccessFlags flags,
}

m_RenderPass.AddResourceRead(versioned);
m_Resources.IncrementReadCount(handle);

if ((flags & AccessFlags.Read) == 0)
{
Expand All @@ -232,6 +233,7 @@ private ResourceHandle UseResource(in ResourceHandle handle, AccessFlags flags,
if ((flags & AccessFlags.Read) != 0)
{
m_RenderPass.AddResourceRead(m_Resources.GetZeroVersionedHandle(handle));
m_Resources.IncrementReadCount(handle);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public void Clear()
colorBufferMaxIndex = -1;
fragmentInputMaxIndex = -1;
randomAccessResourceMaxIndex = -1;

// We do not need to clear colorBufferAccess and fragmentInputAccess as we have the colorBufferMaxIndex and fragmentInputMaxIndex
// which are reset above so we only clear depthAccess here.
depthAccess = default(TextureAccess);
}

// Check if the pass has any render targets set-up
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ internal void IncrementWriteCount(in ResourceHandle res)
m_RenderGraphResources[res.iType].resourceArray[res.index].IncrementWriteCount();
}

internal void IncrementReadCount(in ResourceHandle res)
{
CheckHandleValidity(res);
m_RenderGraphResources[res.iType].resourceArray[res.index].IncrementReadCount();
}

internal void NewVersion(in ResourceHandle res)
{
CheckHandleValidity(res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class IRenderGraphResource
public bool requestFallBack;
public bool forceRelease;
public uint writeCount;
public uint readCount;
public int cachedHash;
public int transientPassIndex;
public int sharedResourceLastFrameUsed;
Expand All @@ -145,6 +146,7 @@ public virtual void Reset(IRenderGraphResourcePool _ = null)
requestFallBack = false;
forceRelease = false;
writeCount = 0;
readCount = 0;
version = 0;
}

Expand All @@ -166,6 +168,13 @@ public virtual void IncrementWriteCount()
writeCount++;
}

// readCount is currently not used in the HDRP Compiler.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual void IncrementReadCount()
{
readCount++;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public virtual int NewVersion()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma multi_compile _ DISABLE_TEXTURE2D_X_ARRAY

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

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma multi_compile _ DISABLE_TEXTURE2D_X_ARRAY

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

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
Expand Down Expand Up @@ -395,7 +395,14 @@ StpF2 StpPatDatMotH(StpW2 o) { return LOAD_TEXTURE2D_X_LOD(_StpInputMotion, o, 0
StpH3 StpPatDatColH(StpW2 o) { return (StpH3)LOAD_TEXTURE2D_X_LOD(_StpInputColor, o, 0).rgb; }
StpF1 StpPatDatZH(StpW2 o) { return LOAD_TEXTURE2D_X_LOD(_StpInputDepth, o, 0).x; }
// This provides a place to convert Z from depth to linear if not inlined and actually loaded.
StpF1 StpPatFixZH(StpF1 z) { return 1.0 / (STP_ZBUFFER_PARAMS_Z * z + STP_ZBUFFER_PARAMS_W); }
StpF1 StpPatFixZH(StpF1 z)
{
#if !UNITY_REVERSED_Z
// Reverse Z if necessary as STP expects reversed Z input
z = 1.0 - z;
#endif
return 1.0 / (STP_ZBUFFER_PARAMS_Z * z + STP_ZBUFFER_PARAMS_W);
}
StpU1 StpPatDatRH(StpW2 o) {
#if defined(ENABLE_STENCIL_RESPONSIVE)
return GetStencilValue(LOAD_TEXTURE2D_X_LOD(_StpInputStencil, o, 0).xy);
Expand Down Expand Up @@ -432,7 +439,14 @@ StpF2 StpPatDatMotF(StpMU2 o) { return LOAD_TEXTURE2D_X_LOD(_StpInputMotion, o,
StpMF3 StpPatDatColF(StpMU2 o) { return (StpMF3)LOAD_TEXTURE2D_X_LOD(_StpInputColor, o, 0).rgb; }
StpF1 StpPatDatZF(StpMU2 o) { return LOAD_TEXTURE2D_X_LOD(_StpInputDepth, o, 0).x; }
// This provides a place to convert Z from depth to linear if not inlined and actually loaded.
StpF1 StpPatFixZF(StpF1 z) { return 1.0 / (STP_ZBUFFER_PARAMS_Z * z + STP_ZBUFFER_PARAMS_W); }
StpF1 StpPatFixZF(StpF1 z)
{
#if !UNITY_REVERSED_Z
// Reverse Z if necessary as STP expects reversed Z input
z = 1.0 - z;
#endif
return 1.0 / (STP_ZBUFFER_PARAMS_Z * z + STP_ZBUFFER_PARAMS_W);
}
StpU1 StpPatDatRF(StpMU2 o) {
#if defined(ENABLE_STENCIL_RESPONSIVE)
return GetStencilValue(LOAD_TEXTURE2D_X_LOD(_StpInputStencil, o, 0).xy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma multi_compile _ DISABLE_TEXTURE2D_X_ARRAY

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

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
Expand Down
Loading

0 comments on commit a66eeaf

Please sign in to comment.