Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8ba3080
[Port] [6000.1] Custom mesh water surface normal map fades out when Y…
svc-reach-platform-support May 19, 2025
75ba90e
[Port] [6000.1] Force high memory budget during dilation
svc-reach-platform-support May 19, 2025
ac4572a
[Port] [6000.1] HDRP: Re-enable allocation-checks on Metal.
svc-reach-platform-support May 19, 2025
6687fb5
Backport for Case UUM-104198
venkify May 20, 2025
45dfbff
[Port] [6000.1] [Upscaling] Fix FSR2 crash & DX11 missing depth, upgr…
svc-reach-platform-support May 21, 2025
f70d97f
[Port] [6000.1] DOCG-7040: replace "deformer" with "water decal"
svc-reach-platform-support May 21, 2025
add83ff
[Port] [6000.1] UUM-103836 Trying to use invalid GBuffers in Wirefram…
svc-reach-platform-support May 21, 2025
f5e22d0
[Port] [6000.1] docs: Fix accessibility issues
svc-reach-platform-support May 21, 2025
248de6e
[Port] [6000.1] [VFX] Restore the usage of global textures for textur…
svc-reach-platform-support May 22, 2025
21002b9
[Port] [6000.1] [VFX] Fix rendering of volumetric output connected to…
svc-reach-platform-support May 22, 2025
51b6651
[Port] [6000.1] UUM-103975 : Missing packed material data in CreateDr…
svc-reach-platform-support May 22, 2025
9a3fea2
[Port] [6000.1] [VFX] Fixed matrix 4x4 was overflowing in a context b…
svc-reach-platform-support May 22, 2025
97d4049
[Port] [6000.1] [URP] Fix UUM-85291: Disabled Pass Merging for Screen…
svc-reach-platform-support May 22, 2025
d1390a7
Disabling unstable tests
Daniel-Dobzinski May 23, 2025
04b8ada
[Port] [6000.1] [VFX] Fixed an NRE when using CTRL+5 shortcut
svc-reach-platform-support May 24, 2025
ea261c0
[Port] [6000.1] [VFX][Fix] Account for Custom Pass cullng results in …
svc-reach-platform-support May 24, 2025
5617081
[Port] [6000.1] Update .buginfo for `Post-processing and Compositing`
svc-reach-platform-support May 24, 2025
08394b2
6000.1: Fix IndexOutOfRangeException Exception by allocating size wit…
vrethinachalam May 24, 2025
db60212
[Port] [6000.1] DOCG-7151 Improve journey to API docs of core graphic…
svc-reach-platform-support May 26, 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
@@ -0,0 +1,12 @@
---
uid: srp-core-api-index
---

# Scriptable Render Pipeline Core scripting API

This is the documentation for the scripting APIs of the Scriptable Render Pipeline (SRP) Core package.

**Note**: URP and HDRP are built on the Scriptable Render Pipeline (SRP) Core package, but have their own class types. For more information, refer to the following:

- [Universal Render Pipeline (URP) Scripting API](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@17.1/api/index.html)
- [High Definition Render Pipeline (HDRP) Scripting API](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@17.1/api/index.html)
Original file line number Diff line number Diff line change
Expand Up @@ -1419,11 +1419,14 @@ static void ApplyPostBakeOperations()
if (m_BakingSet.hasDilation)
{
// This subsequent block needs to happen AFTER we call WriteBakingCells.
// Otherwise in cases where we change the spacing between probes, we end up loading cells with a certain layout in ForceSHBand
// Otherwise, in cases where we change the spacing between probes, we end up loading cells with a certain layout in ForceSHBand
// And then we unload cells using the wrong layout in PerformDilation (after WriteBakingCells updates the baking set object) which leads to a broken internal state.

// Don't use Disk streaming to avoid having to wait for it when doing dilation.
probeRefVolume.ForceNoDiskStreaming(true);
// Increase the memory budget to make sure we can fit the current cell and all its neighbors when doing dilation.
var prevMemoryBudget = probeRefVolume.memoryBudget;
probeRefVolume.ForceMemoryBudget(ProbeVolumeTextureMemoryBudget.MemoryBudgetHigh);
// Force maximum sh bands to perform baking, we need to store what sh bands was selected from the settings as we need to restore it after.
var prevSHBands = probeRefVolume.shBands;
probeRefVolume.ForceSHBand(ProbeVolumeSHBands.SphericalHarmonicsL2);
Expand All @@ -1434,8 +1437,9 @@ static void ApplyPostBakeOperations()
using (new BakingCompleteProfiling(BakingCompleteProfiling.Stages.PerformDilation))
PerformDilation();

// Need to restore the original state
// Restore the original state.
probeRefVolume.ForceNoDiskStreaming(false);
probeRefVolume.ForceMemoryBudget(prevMemoryBudget);
probeRefVolume.ForceSHBand(prevSHBands);
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
area: Post-processing and UI Features
area: Post-processing and Compositing
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ public partial class RenderGraphViewer
"Compute Pass"
};

static readonly string[] k_PassTypeNamesNotMergedMessage =
{
"This is a Legacy Render Pass. Only Raster Render Passes can be merged.",
"This is an Unsafe Render Pass. Only Raster Render Passes can be merged.",
"Pass merging was disabled.",
"This is a Compute Pass. Only Raster Render Passes can be merged."
};

static partial class Names
{
public const string kPanelContainer = "panel-container";
Expand Down Expand Up @@ -370,8 +378,7 @@ void CreateTextElement(VisualElement parent, string text, string className = nul
else
{
CreateTextElement(passItem, "Pass break reasoning", Classes.kSubHeaderText);
var msg = $"This is a {k_PassTypeNames[(int) firstPassData.type]}. Only Raster Render Passes can be merged.";
msg = msg.Replace("a Unsafe", "an Unsafe");
string msg = k_PassTypeNamesNotMergedMessage[(int)firstPassData.type];
CreateTextElement(passItem, msg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,7 @@ public static class DynamicArrayExtensions
}
}

// C# SUCKS
// Had to copy paste because it's apparently impossible to pass a sort delegate where T is Comparable<T>, otherwise some boxing happens and allocates...
// A copy/paste because it's apparently impossible to pass a sort delegate where T is Comparable<T>, otherwise some boxing happens and allocates...
// So two identical versions of the function, one with delegate but no Comparable and the other with just the comparable.
static int Partition<T>(Span<T> data, int left, int right, DynamicArray<T>.SortComparer comparer) where T : new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,7 @@ private void UpdateRendererInstancesAndBatches(in GPUDrivenRendererGroupData ren

Profiler.BeginSample("InstanceCullingBatcher.BuildBatch");
{
m_InstanceCullingBatcher.BuildBatch(
instances,
rendererData.materialID,
rendererData.meshID,
rendererData, true);

m_InstanceCullingBatcher.BuildBatch(instances, rendererData, true);
}
Profiler.EndSample();

Expand Down Expand Up @@ -234,15 +229,11 @@ private void UpdateRendererBatches(in GPUDrivenRendererGroupData rendererData, I

Profiler.BeginSample("InstanceCullingBatcher.BuildBatch");
{
m_InstanceCullingBatcher.BuildBatch(
instances.AsArray(),
rendererData.materialID,
rendererData.meshID,
rendererData, false);
instances.Dispose();
m_InstanceCullingBatcher.BuildBatch(instances.AsArray(), rendererData, false);
}
Profiler.EndSample();

instances.Dispose();
}
Profiler.EndSample();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
using Unity.Burst;
using UnityEngine.Profiling;

[assembly: RegisterGenericJobType(typeof(UnityEngine.Rendering.RegisterNewInstancesJob<UnityEngine.Rendering.BatchMeshID>))]
[assembly: RegisterGenericJobType(typeof(UnityEngine.Rendering.RegisterNewInstancesJob<UnityEngine.Rendering.BatchMaterialID>))]
[assembly: RegisterGenericJobType(typeof(UnityEngine.Rendering.FindNonRegisteredInstancesJob<UnityEngine.Rendering.BatchMeshID>))]
[assembly: RegisterGenericJobType(typeof(UnityEngine.Rendering.FindNonRegisteredInstancesJob<UnityEngine.Rendering.BatchMaterialID>))]

namespace UnityEngine.Rendering
{
internal delegate void OnCullingCompleteCallback(JobHandle jobHandle, in BatchCullingContext cullingContext, in BatchCullingOutput cullingOutput);
Expand Down Expand Up @@ -191,48 +186,109 @@ public void Execute(int startIndex, int count)
}

[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)]
internal struct FindNonRegisteredInstancesJob<T> : IJobParallelForBatch where T : unmanaged
internal struct FindNonRegisteredMeshesJob : IJobParallelForBatch
{
public const int k_BatchSize = 128;

[ReadOnly] public NativeArray<int> instanceIDs;
[ReadOnly] public NativeParallelHashMap<int, T> hashMap;
[ReadOnly] public NativeParallelHashMap<int, BatchMeshID> hashMap;

[WriteOnly] public NativeList<int>.ParallelWriter outInstancesWriter;

public unsafe void Execute(int startIndex, int count)
{
int* notFoundinstanceIDs = stackalloc int[k_BatchSize];
int length = 0;
int* notFoundinstanceIDsPtr = stackalloc int[k_BatchSize];
var notFoundinstanceIDs = new UnsafeList<int>(notFoundinstanceIDsPtr, k_BatchSize);

notFoundinstanceIDs.Length = 0;

for (int i = startIndex; i < startIndex + count; ++i)
{
int instanceID = instanceIDs[i];

if (!hashMap.ContainsKey(instanceID))
notFoundinstanceIDs[length++] = instanceID;
notFoundinstanceIDs.AddNoResize(instanceID);
}

outInstancesWriter.AddRangeNoResize(notFoundinstanceIDs, length);
outInstancesWriter.AddRangeNoResize(notFoundinstanceIDsPtr, notFoundinstanceIDs.Length);
}
}

[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)]
internal struct RegisterNewInstancesJob<T> : IJobParallelFor where T : unmanaged
internal struct FindNonRegisteredMaterialsJob : IJobParallelForBatch
{
public const int k_BatchSize = 128;

[ReadOnly] public NativeArray<int> instanceIDs;
[ReadOnly] public NativeArray<T> batchIDs;
[ReadOnly] public NativeArray<GPUDrivenPackedMaterialData> packedMaterialDatas;
[ReadOnly] public NativeParallelHashMap<int, BatchMaterialID> hashMap;

[WriteOnly] public NativeParallelHashMap<int, T>.ParallelWriter hashMap;
[WriteOnly] public NativeList<int>.ParallelWriter outInstancesWriter;
[WriteOnly] public NativeList<GPUDrivenPackedMaterialData>.ParallelWriter outPackedMaterialDatasWriter;

public unsafe void Execute(int index)
public unsafe void Execute(int startIndex, int count)
{
int* notFoundinstanceIDsPtr = stackalloc int[k_BatchSize];
var notFoundinstanceIDs = new UnsafeList<int>(notFoundinstanceIDsPtr, k_BatchSize);

GPUDrivenPackedMaterialData* notFoundPackedMaterialDatasPtr = stackalloc GPUDrivenPackedMaterialData[k_BatchSize];
var notFoundPackedMaterialDatas = new UnsafeList<GPUDrivenPackedMaterialData>(notFoundPackedMaterialDatasPtr, k_BatchSize);

notFoundinstanceIDs.Length = 0;
notFoundPackedMaterialDatas.Length = 0;

for (int i = startIndex; i < startIndex + count; ++i)
{
int instanceID = instanceIDs[i];

if (!hashMap.ContainsKey(instanceID))
{
notFoundinstanceIDs.AddNoResize(instanceID);
notFoundPackedMaterialDatas.AddNoResize(packedMaterialDatas[i]);
}
}

outInstancesWriter.AddRangeNoResize(notFoundinstanceIDsPtr, notFoundinstanceIDs.Length);
outPackedMaterialDatasWriter.AddRangeNoResize(notFoundPackedMaterialDatasPtr, notFoundPackedMaterialDatas.Length);
}
}

[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)]
internal struct RegisterNewMeshesJob : IJobParallelFor
{
public const int k_BatchSize = 128;

[ReadOnly] public NativeArray<int> instanceIDs;
[ReadOnly] public NativeArray<BatchMeshID> batchIDs;

[WriteOnly] public NativeParallelHashMap<int, BatchMeshID>.ParallelWriter hashMap;

public void Execute(int index)
{
hashMap.TryAdd(instanceIDs[index], batchIDs[index]);
}
}

[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)]
internal struct RegisterNewMaterialsJob : IJobParallelFor
{
public const int k_BatchSize = 128;

[ReadOnly] public NativeArray<int> instanceIDs;
[ReadOnly] public NativeArray<GPUDrivenPackedMaterialData> packedMaterialDatas;
[ReadOnly] public NativeArray<BatchMaterialID> batchIDs;

[WriteOnly] public NativeParallelHashMap<int, BatchMaterialID>.ParallelWriter batchMaterialHashMap;
[WriteOnly] public NativeParallelHashMap<int, GPUDrivenPackedMaterialData>.ParallelWriter packedMaterialHashMap;

public void Execute(int index)
{
var instanceID = instanceIDs[index];
batchMaterialHashMap.TryAdd(instanceID, batchIDs[index]);
packedMaterialHashMap.TryAdd(instanceID, packedMaterialDatas[index]);
}
}

[BurstCompile(DisableSafetyChecks = true, OptimizeFor = OptimizeFor.Performance)]
internal struct RemoveDrawInstanceIndicesJob : IJob
{
Expand Down Expand Up @@ -468,7 +524,7 @@ public void ProcessRenderer(int i)
{
var materialID = rendererData.materialID[materialIndex];
bool isFound = packedMaterialDataHash.TryGetValue(materialID, out packedMaterialData);
Assert.IsTrue(isFound);
Assert.IsTrue(isFound, "Packed material data not found.");
}
supportsIndirect &= packedMaterialData.isIndirectSupported;

Expand Down Expand Up @@ -1011,41 +1067,45 @@ public void PostCullBeginCameraRendering(RenderRequestBatcherContext context)
private void RegisterBatchMeshes(NativeArray<int> meshIDs)
{
var newMeshIDs = new NativeList<int>(meshIDs.Length, Allocator.TempJob);
new FindNonRegisteredInstancesJob<BatchMeshID>
new FindNonRegisteredMeshesJob
{
instanceIDs = meshIDs,
hashMap = m_BatchMeshHash,
outInstancesWriter = newMeshIDs.AsParallelWriter()
}
.ScheduleBatch(meshIDs.Length, FindNonRegisteredInstancesJob<BatchMeshID>.k_BatchSize).Complete();
.ScheduleBatch(meshIDs.Length, FindNonRegisteredMeshesJob.k_BatchSize).Complete();
var newBatchMeshIDs = new NativeArray<BatchMeshID>(newMeshIDs.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
m_BRG.RegisterMeshes(newMeshIDs.AsArray(), newBatchMeshIDs);

int totalMeshesNum = m_BatchMeshHash.Count() + newBatchMeshIDs.Length;
m_BatchMeshHash.Capacity = Math.Max(m_BatchMeshHash.Capacity, Mathf.CeilToInt(totalMeshesNum / 1023.0f) * 1024);

new RegisterNewInstancesJob<BatchMeshID>
new RegisterNewMeshesJob
{
instanceIDs = newMeshIDs.AsArray(),
batchIDs = newBatchMeshIDs,
hashMap = m_BatchMeshHash.AsParallelWriter()
}
.Schedule(newMeshIDs.Length, RegisterNewInstancesJob<BatchMeshID>.k_BatchSize).Complete();
.Schedule(newMeshIDs.Length, RegisterNewMeshesJob.k_BatchSize).Complete();

newMeshIDs.Dispose();
newBatchMeshIDs.Dispose();
}

private void RegisterBatchMaterials(in NativeArray<int> usedMaterialIDs)
private void RegisterBatchMaterials(in NativeArray<int> usedMaterialIDs, in NativeArray<GPUDrivenPackedMaterialData> usedPackedMaterialDatas)
{
Debug.Assert(usedMaterialIDs.Length == usedPackedMaterialDatas.Length, "Each material ID should correspond to one packed material data.");
var newMaterialIDs = new NativeList<int>(usedMaterialIDs.Length, Allocator.TempJob);
new FindNonRegisteredInstancesJob<BatchMaterialID>
var newPackedMaterialDatas = new NativeList<GPUDrivenPackedMaterialData>(usedMaterialIDs.Length, Allocator.TempJob);
new FindNonRegisteredMaterialsJob
{
instanceIDs = usedMaterialIDs,
packedMaterialDatas = usedPackedMaterialDatas,
hashMap = m_BatchMaterialHash,
outInstancesWriter = newMaterialIDs.AsParallelWriter()
outInstancesWriter = newMaterialIDs.AsParallelWriter(),
outPackedMaterialDatasWriter = newPackedMaterialDatas.AsParallelWriter()
}
.ScheduleBatch(usedMaterialIDs.Length, FindNonRegisteredInstancesJob<BatchMaterialID>.k_BatchSize).Complete();
.ScheduleBatch(usedMaterialIDs.Length, FindNonRegisteredMaterialsJob.k_BatchSize).Complete();

var newBatchMaterialIDs = new NativeArray<BatchMaterialID>(newMaterialIDs.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
m_BRG.RegisterMaterials(newMaterialIDs.AsArray(), newBatchMaterialIDs);
Expand All @@ -1054,15 +1114,18 @@ private void RegisterBatchMaterials(in NativeArray<int> usedMaterialIDs)
m_BatchMaterialHash.Capacity = Math.Max(m_BatchMaterialHash.Capacity, Mathf.CeilToInt(totalMaterialsNum / 1023.0f) * 1024);
m_PackedMaterialHash.Capacity = m_BatchMaterialHash.Capacity;

new RegisterNewInstancesJob<BatchMaterialID>
new RegisterNewMaterialsJob
{
instanceIDs = newMaterialIDs.AsArray(),
packedMaterialDatas = newPackedMaterialDatas.AsArray(),
batchIDs = newBatchMaterialIDs,
hashMap = m_BatchMaterialHash.AsParallelWriter()
batchMaterialHashMap = m_BatchMaterialHash.AsParallelWriter(),
packedMaterialHashMap = m_PackedMaterialHash.AsParallelWriter()
}
.Schedule(newMaterialIDs.Length, RegisterNewInstancesJob<BatchMaterialID>.k_BatchSize).Complete();
.Schedule(newMaterialIDs.Length, RegisterNewMaterialsJob.k_BatchSize).Complete();

newMaterialIDs.Dispose();
newPackedMaterialDatas.Dispose();
newBatchMaterialIDs.Dispose();
}

Expand All @@ -1078,15 +1141,13 @@ public JobHandle SchedulePackedMaterialCacheUpdate(NativeArray<int> materialIDs,

public void BuildBatch(
NativeArray<InstanceHandle> instances,
NativeArray<int> usedMaterialIDs,
NativeArray<int> usedMeshIDs,
in GPUDrivenRendererGroupData rendererData,
bool registerMaterialsAndMeshes)
{
if (registerMaterialsAndMeshes)
{
RegisterBatchMaterials(usedMaterialIDs);
RegisterBatchMeshes(usedMeshIDs);
RegisterBatchMaterials(rendererData.materialID, rendererData.packedMaterialData);
RegisterBatchMeshes(rendererData.meshID);
}

new CreateDrawBatchesJob
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ internal bool Allocate(int numberOfBrickChunks, List<BrickChunkAlloc> outAllocat
if (!ignoreErrorLog)
Debug.LogError("Cannot allocate more brick chunks, probe volume brick pool is full.");

Deallocate(outAllocations);
outAllocations.Clear();
return false; // failure case, pool is full
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,11 @@ public void SetVertexSamplingEnabled(bool value)
m_VertexSampling = value;
}

internal void ForceMemoryBudget(ProbeVolumeTextureMemoryBudget budget)
{
m_MemoryBudget = budget;
}

// This is used for steps such as dilation that require the maximum order allowed to be loaded at all times. Should really never be used as a general purpose function.
internal void ForceSHBand(ProbeVolumeSHBands shBands)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
area: Post-processing and UI Features
area: Post-processing and Compositing
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ internal static string MakePassMergeMessage(CompilerContextData ctx, in PassData
case PassBreakReason.DifferentShadingRateStates:
message += $"{prevPassName} uses different shading rate states than {passName}.";
break;
case PassBreakReason.PassMergingDisabled:
message += "The pass merging is disabled.";
break;
default:
throw new ArgumentOutOfRangeException();
}
Expand Down
Loading