Skip to content

Commit a66eeaf

Browse files
authored
Merge pull request #8117 from Unity-Technologies/internal/6000.0/staging
Internal/6000.0/staging
2 parents a65be2c + ad407bb commit a66eeaf

File tree

112 files changed

+32849
-359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+32849
-359
lines changed

Packages/com.unity.render-pipelines.core/Documentation~/render-graph-writing-a-render-pipeline.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This page covers the process of how to use the RenderGraph API to write a render
77
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.
88

99
```c#
10+
using UnityEngine.Rendering;
1011
using UnityEngine.Rendering.RenderGraphModule;
1112

1213
public class MyRenderPipeline : RenderPipeline
@@ -21,8 +22,11 @@ public class MyRenderPipeline : RenderPipeline
2122
void CleanupRenderGraph()
2223
{
2324
m_RenderGraph.Cleanup();
24-
m_RenderGraph = null;
25+
m_RenderGraph = null;
2526
}
27+
28+
...
29+
2630
}
2731
```
2832

Packages/com.unity.render-pipelines.core/Editor/Settings/PropertyDrawers/DefaultVolumeProfileSettingsPropertyDrawer.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,23 @@ protected void CreateDefaultVolumeProfileEditor()
8888
}
8989
m_EditorContainer.Add(s_DefaultVolumeProfileEditor.Create());
9090
m_EditorContainer.Q<HelpBox>("volume-override-info-box").text = volumeInfoBoxLabel.text;
91+
92+
if (m_DefaultVolumeProfileFoldoutExpanded.value)
93+
m_EditorContainer.style.display = DisplayStyle.Flex;
9194
}
9295

9396
/// <summary>
9497
/// Destroys the Default Volume Profile editor.
9598
/// </summary>
9699
protected void DestroyDefaultVolumeProfileEditor()
97100
{
101+
m_EditorContainer.style.display = DisplayStyle.None;
102+
m_EditorContainer?.Clear();
103+
98104
if (s_DefaultVolumeProfileEditor != null)
99105
s_DefaultVolumeProfileEditor.Destroy();
100106
s_DefaultVolumeProfileEditor = null;
101107
s_DefaultVolumeProfileSerializedProperty = null;
102-
m_EditorContainer?.Clear();
103108
}
104109

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

125130
void IRenderPipelineGraphicsSettingsContextMenu<TSetting>.PopulateContextMenu(TSetting setting, PropertyDrawer _, ref GenericMenu menu)
126131
{
127-
menu.AddSeparator("");
128-
129132
bool canCreateNewAsset = RenderPipelineManager.currentPipeline is TRenderPipeline;
130133
VolumeProfileUtils.AddVolumeProfileContextMenuItems(ref menu,
131134
setting.volumeProfile,

Packages/com.unity.render-pipelines.core/Editor/Volume/VolumeProfileUtils.cs

-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,6 @@ public static void EnsureAllOverridesForDefaultProfile(VolumeProfile profile, Vo
240240
{
241241
VolumeManager.instance.OnVolumeProfileChanged(profile);
242242
EditorUtility.SetDirty(profile);
243-
AssetDatabase.SaveAssets();
244-
AssetDatabase.Refresh();
245243
}
246244
}
247245

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.Debug.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,9 @@ CellInstancedDebugProbes CreateInstancedProbes(Cell cell)
10891089
if (cell.debugProbes != null)
10901090
return cell.debugProbes;
10911091

1092+
if (HasActiveStreamingRequest(cell))
1093+
return null;
1094+
10921095
int maxSubdiv = GetMaxSubdivision() - 1;
10931096

10941097
if (!cell.data.bricks.IsCreated || cell.data.bricks.Length == 0 || !cell.data.probePositions.IsCreated || !cell.loaded)

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.Streaming.cs

+5
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,11 @@ void UpdateDiskStreaming(CommandBuffer cmd)
14501450
}
14511451
}
14521452

1453+
bool HasActiveStreamingRequest(Cell cell)
1454+
{
1455+
return diskStreamingEnabled && m_ActiveStreamingRequests.Exists(x => x.cell == cell);
1456+
}
1457+
14531458
[Conditional("UNITY_EDITOR")]
14541459
[Conditional("DEVELOPMENT_BUILD")]
14551460
void LogStreaming(string log)

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/Compiler/CompilerContextData.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public ref ResourceVersionedData VersionedResourceData(ResourceHandle h)
9898
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9999
public ReadOnlySpan<ResourceReaderData> Readers(ResourceHandle h)
100100
{
101-
int firstReader = ResourcesData.IndexReader(h, 0);
101+
int firstReader = resources.IndexReader(h, 0);
102102
int numReaders = resources[h].numReaders;
103103
return resources.readerData[h.iType].MakeReadOnlySpan(firstReader, numReaders);
104104
}
@@ -114,7 +114,7 @@ public ref ResourceReaderData ResourceReader(ResourceHandle h, int i)
114114
throw new Exception("Invalid reader id");
115115
}
116116
#endif
117-
return ref resources.readerData[h.iType].ElementAt(ResourcesData.IndexReader(h, 0) + i);
117+
return ref resources.readerData[h.iType].ElementAt(resources.IndexReader(h, 0) + i);
118118
}
119119

120120
// Data per graph level renderpass

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/Compiler/NativePassCompiler.Debug.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ internal void GenerateNativeCompilerDebugData(ref RenderGraph.DebugData debugDat
351351
var numReaders = outputDataVersioned.numReaders;
352352
for (var i = 0; i < numReaders; ++i)
353353
{
354-
var depIdx = ResourcesData.IndexReader(output.resource, i);
354+
var depIdx = ctx.resources.IndexReader(output.resource, i);
355355
ref var dep = ref ctx.resources.readerData[output.resource.iType].ElementAt(depIdx);
356356

357357
var outputDependencyPass = ctx.passData[dep.passId];

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/Compiler/NativePassCompiler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ void FindResourceUsageRanges()
594594
var numReaders = pointToVer.numReaders;
595595
for (var i = 0; i < numReaders; ++i)
596596
{
597-
var depIdx = ResourcesData.IndexReader(outputResource, i);
597+
var depIdx = ctx.resources.IndexReader(outputResource, i);
598598
ref var dep = ref ctx.resources.readerData[outputResource.iType].ElementAt(depIdx);
599599
ref var depPass = ref ctx.passData.ElementAt(dep.passId);
600600
if (pass.asyncCompute != depPass.asyncCompute)

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/Compiler/ResourcesData.cs

+20-9
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ public void SetWritingPass(CompilerContextData ctx, ResourceHandle h, int passId
146146
public void RegisterReadingPass(CompilerContextData ctx, ResourceHandle h, int passId, int index)
147147
{
148148
#if DEVELOPMENT_BUILD || UNITY_EDITOR
149-
if (numReaders >= ResourcesData.MaxReaders)
149+
if (numReaders >= ctx.resources.MaxReaders)
150150
{
151151
string passName = ctx.GetPassName(passId);
152152
string resourceName = ctx.GetResourceName(h);
153-
throw new Exception($"Maximum '{ResourcesData.MaxReaders}' passes can use a single graph output as input. Pass {passName} is trying to read {resourceName}.");
153+
throw new Exception($"Maximum '{ctx.resources.MaxReaders}' passes can use a single graph output as input. Pass {passName} is trying to read {resourceName}.");
154154
}
155155
#endif
156-
ctx.resources.readerData[h.iType][ResourcesData.IndexReader(h, numReaders)] = new ResourceReaderData
156+
ctx.resources.readerData[h.iType][ctx.resources.IndexReader(h, numReaders)] = new ResourceReaderData
157157
{
158158
passId = passId,
159159
inputSlot = index
@@ -167,13 +167,13 @@ public void RemoveReadingPass(CompilerContextData ctx, ResourceHandle h, int pas
167167
{
168168
for (int r = 0; r < numReaders;)
169169
{
170-
ref var reader = ref ctx.resources.readerData[h.iType].ElementAt(ResourcesData.IndexReader(h, r));
170+
ref var reader = ref ctx.resources.readerData[h.iType].ElementAt(ctx.resources.IndexReader(h, r));
171171
if (reader.passId == passId)
172172
{
173173
// It should be removed, switch with the end of the list if we're not already at the end of it
174174
if (r < numReaders - 1)
175175
{
176-
reader = ctx.resources.readerData[h.iType][ResourcesData.IndexReader(h, numReaders - 1)];
176+
reader = ctx.resources.readerData[h.iType][ctx.resources.IndexReader(h, numReaders - 1)];
177177
}
178178

179179
numReaders--;
@@ -193,8 +193,9 @@ internal class ResourcesData
193193
public NativeList<ResourceUnversionedData>[] unversionedData; // Flattened fixed size array storing info per resource id shared between all versions.
194194
public NativeList<ResourceVersionedData>[] versionedData; // Flattened fixed size array storing up to MaxVersions versions per resource id.
195195
public NativeList<ResourceReaderData>[] readerData; // Flattened fixed size array storing up to MaxReaders per resource id per version.
196-
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.
197-
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.
196+
197+
public int MaxVersions;
198+
public int MaxReaders;
198199

199200
public DynamicArray<Name>[] resourceNames;
200201

@@ -229,6 +230,9 @@ public void Clear()
229230

230231
public void Initialize(RenderGraphResourceRegistry resources)
231232
{
233+
uint maxReaders = 0;
234+
uint maxWriters = 0;
235+
232236
for (int t = 0; t < (int)RenderGraphResourceType.Count; t++)
233237
{
234238
RenderGraphResourceType resourceType = (RenderGraphResourceType) t;
@@ -287,8 +291,15 @@ public void Initialize(RenderGraphResourceRegistry resources)
287291
default:
288292
throw new Exception("Unsupported resource type: " + t);
289293
}
294+
295+
maxReaders = Math.Max(maxReaders, rll.readCount);
296+
maxWriters = Math.Max(maxWriters, rll.writeCount);
290297
}
291298

299+
// The first resource is a null resource, so we need to add 1 to the count.
300+
MaxReaders = (int)maxReaders + 1;
301+
MaxVersions = (int)maxWriters + 1;
302+
292303
// Clear the other caching structures, they will be filled later
293304
versionedData[t].Resize(MaxVersions * numResources, NativeArrayOptions.ClearMemory);
294305
readerData[t].Resize(MaxVersions * MaxReaders * numResources, NativeArrayOptions.ClearMemory);
@@ -297,7 +308,7 @@ public void Initialize(RenderGraphResourceRegistry resources)
297308

298309
// Flatten array index
299310
[MethodImpl(MethodImplOptions.AggressiveInlining)]
300-
public static int Index(ResourceHandle h)
311+
public int Index(ResourceHandle h)
301312
{
302313
#if UNITY_EDITOR // Hot path
303314
if (h.version < 0 || h.version >= MaxVersions)
@@ -308,7 +319,7 @@ public static int Index(ResourceHandle h)
308319

309320
// Flatten array index
310321
[MethodImpl(MethodImplOptions.AggressiveInlining)]
311-
public static int IndexReader(ResourceHandle h, int readerID)
322+
public int IndexReader(ResourceHandle h, int readerID)
312323
{
313324
#if UNITY_EDITOR // Hot path
314325
if (h.version < 0 || h.version >= MaxVersions)

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilders.cs

+2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ private ResourceHandle UseResource(in ResourceHandle handle, AccessFlags flags,
219219
}
220220

221221
m_RenderPass.AddResourceRead(versioned);
222+
m_Resources.IncrementReadCount(handle);
222223

223224
if ((flags & AccessFlags.Read) == 0)
224225
{
@@ -232,6 +233,7 @@ private ResourceHandle UseResource(in ResourceHandle handle, AccessFlags flags,
232233
if ((flags & AccessFlags.Read) != 0)
233234
{
234235
m_RenderPass.AddResourceRead(m_Resources.GetZeroVersionedHandle(handle));
236+
m_Resources.IncrementReadCount(handle);
235237
}
236238
}
237239

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphPass.cs

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ public void Clear()
9696
colorBufferMaxIndex = -1;
9797
fragmentInputMaxIndex = -1;
9898
randomAccessResourceMaxIndex = -1;
99+
100+
// We do not need to clear colorBufferAccess and fragmentInputAccess as we have the colorBufferMaxIndex and fragmentInputMaxIndex
101+
// which are reset above so we only clear depthAccess here.
102+
depthAccess = default(TextureAccess);
99103
}
100104

101105
// Check if the pass has any render targets set-up

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs

+6
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,12 @@ internal void IncrementWriteCount(in ResourceHandle res)
349349
m_RenderGraphResources[res.iType].resourceArray[res.index].IncrementWriteCount();
350350
}
351351

352+
internal void IncrementReadCount(in ResourceHandle res)
353+
{
354+
CheckHandleValidity(res);
355+
m_RenderGraphResources[res.iType].resourceArray[res.index].IncrementReadCount();
356+
}
357+
352358
internal void NewVersion(in ResourceHandle res)
353359
{
354360
CheckHandleValidity(res);

Packages/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs

+9
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class IRenderGraphResource
128128
public bool requestFallBack;
129129
public bool forceRelease;
130130
public uint writeCount;
131+
public uint readCount;
131132
public int cachedHash;
132133
public int transientPassIndex;
133134
public int sharedResourceLastFrameUsed;
@@ -145,6 +146,7 @@ public virtual void Reset(IRenderGraphResourcePool _ = null)
145146
requestFallBack = false;
146147
forceRelease = false;
147148
writeCount = 0;
149+
readCount = 0;
148150
version = 0;
149151
}
150152

@@ -166,6 +168,13 @@ public virtual void IncrementWriteCount()
166168
writeCount++;
167169
}
168170

171+
// readCount is currently not used in the HDRP Compiler.
172+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
173+
public virtual void IncrementReadCount()
174+
{
175+
readCount++;
176+
}
177+
169178
[MethodImpl(MethodImplOptions.AggressiveInlining)]
170179
public virtual int NewVersion()
171180
{

Packages/com.unity.render-pipelines.core/Runtime/STP/StpPreTaa.compute

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#pragma multi_compile _ DISABLE_TEXTURE2D_X_ARRAY
99

10-
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
10+
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch glcore
1111

1212
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
1313
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"

Packages/com.unity.render-pipelines.core/Runtime/STP/StpSetup.compute

+17-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#pragma multi_compile _ DISABLE_TEXTURE2D_X_ARRAY
1616

17-
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
17+
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch glcore
1818

1919
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
2020
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
@@ -395,7 +395,14 @@ StpF2 StpPatDatMotH(StpW2 o) { return LOAD_TEXTURE2D_X_LOD(_StpInputMotion, o, 0
395395
StpH3 StpPatDatColH(StpW2 o) { return (StpH3)LOAD_TEXTURE2D_X_LOD(_StpInputColor, o, 0).rgb; }
396396
StpF1 StpPatDatZH(StpW2 o) { return LOAD_TEXTURE2D_X_LOD(_StpInputDepth, o, 0).x; }
397397
// This provides a place to convert Z from depth to linear if not inlined and actually loaded.
398-
StpF1 StpPatFixZH(StpF1 z) { return 1.0 / (STP_ZBUFFER_PARAMS_Z * z + STP_ZBUFFER_PARAMS_W); }
398+
StpF1 StpPatFixZH(StpF1 z)
399+
{
400+
#if !UNITY_REVERSED_Z
401+
// Reverse Z if necessary as STP expects reversed Z input
402+
z = 1.0 - z;
403+
#endif
404+
return 1.0 / (STP_ZBUFFER_PARAMS_Z * z + STP_ZBUFFER_PARAMS_W);
405+
}
399406
StpU1 StpPatDatRH(StpW2 o) {
400407
#if defined(ENABLE_STENCIL_RESPONSIVE)
401408
return GetStencilValue(LOAD_TEXTURE2D_X_LOD(_StpInputStencil, o, 0).xy);
@@ -432,7 +439,14 @@ StpF2 StpPatDatMotF(StpMU2 o) { return LOAD_TEXTURE2D_X_LOD(_StpInputMotion, o,
432439
StpMF3 StpPatDatColF(StpMU2 o) { return (StpMF3)LOAD_TEXTURE2D_X_LOD(_StpInputColor, o, 0).rgb; }
433440
StpF1 StpPatDatZF(StpMU2 o) { return LOAD_TEXTURE2D_X_LOD(_StpInputDepth, o, 0).x; }
434441
// This provides a place to convert Z from depth to linear if not inlined and actually loaded.
435-
StpF1 StpPatFixZF(StpF1 z) { return 1.0 / (STP_ZBUFFER_PARAMS_Z * z + STP_ZBUFFER_PARAMS_W); }
442+
StpF1 StpPatFixZF(StpF1 z)
443+
{
444+
#if !UNITY_REVERSED_Z
445+
// Reverse Z if necessary as STP expects reversed Z input
446+
z = 1.0 - z;
447+
#endif
448+
return 1.0 / (STP_ZBUFFER_PARAMS_Z * z + STP_ZBUFFER_PARAMS_W);
449+
}
436450
StpU1 StpPatDatRF(StpMU2 o) {
437451
#if defined(ENABLE_STENCIL_RESPONSIVE)
438452
return GetStencilValue(LOAD_TEXTURE2D_X_LOD(_StpInputStencil, o, 0).xy);

Packages/com.unity.render-pipelines.core/Runtime/STP/StpTaa.compute

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#pragma multi_compile _ DISABLE_TEXTURE2D_X_ARRAY
99

10-
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
10+
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch glcore
1111

1212
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
1313
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"

0 commit comments

Comments
 (0)