Skip to content

Commit

Permalink
Merge pull request #8093 from Unity-Technologies/internal/master
Browse files Browse the repository at this point in the history
Internal/master
  • Loading branch information
UnityAljosha authored Aug 20, 2024
2 parents 344fe7e + 92378cf commit fc267ad
Show file tree
Hide file tree
Showing 928 changed files with 83,547 additions and 12,428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ public class StandardRenderRequest : MonoBehaviour

## Other useful information

* On [Universal Render Pipeline (URP)](https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@17.0/manual/User-Render-Requests.html).
* On [Universal Render Pipeline (URP)](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@17.0/manual/User-Render-Requests.html).
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This document describes the main principles of a render graph and an overview of

Before you can write render passes with the [RenderGraph](../api/UnityEngine.Rendering.RenderGraphModule.RenderGraph.html) API, you need to know the following foundational principles:

- You no longer handle resources directly and instead use render graph system-specific handles. All RenderGraph APIs use these handles to manipulate resources. The resource types a render graph manages are [RTHandles](rthandle-system.md), [ComputeBuffers](https://docs.unity3d.com/ScriptReference/ComputeBuffer.html), and [RendererLists](../api/UnityEngine.Experimental.Rendering.RendererList.html).
- You no longer handle resources directly and instead use render graph system-specific handles. All RenderGraph APIs use these handles to manipulate resources. The resource types a render graph manages are [RTHandles](rthandle-system.md), [ComputeBuffers](xref:UnityEngine.ComputeBuffer), and [RendererLists](xref:UnityEngine.Rendering.RendererList).
- Actual resource references are only accessible within the execution code of a render pass.
- The framework requires an explicit declaration of render passes. Each render pass must state which resources it reads from and/or writes to.
- There is no persistence between each execution of a render graph. This means that the resources you create inside one execution of the render graph cannot carry over to the next execution.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The render graph system

The render graph system sits on top of Unity's Scriptable Render Pipeline (SRP). It allows you to author a custom SRP in a maintainable and modular way. Unity's High Definition Render Pipeline (HDRP) uses the render graph system.
The render graph system sits on top of Unity's Scriptable Render Pipeline (SRP). It allows you to author a custom SRP in a maintainable and modular way. Both Unity's High Definition Render Pipeline (HDRP) and Unity's Universal Render Pipeline (URP) use the render graph system.

You use the [RenderGraph](../api/UnityEngine.Rendering.RenderGraphModule.RenderGraph.html) API to create a render graph. A render graph is a high-level representation of the custom SRP's render passes, which explicitly states how the render passes use resources.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This document describes the main principles of the RTHandle (RTHandle) system.
The RTHandle system is an abstraction on top of Unity's [RenderTexture](https://docs.unity3d.com/ScriptReference/RenderTexture.html) API. It makes it trivial to reuse render textures across Cameras that use various resolutions. The following principles are the foundation of how the RTHandle system works:

- You no longer allocate render textures yourself with a fixed resolution. Instead, you declare a render texture using a scale related to the full screen at a given resolution. The RTHandle system allocates the texture only once for the whole render pipeline so that it can reuse it for different Cameras.
- There is now the concept of reference size. This is the resolution the application uses for rendering. It is your responsibility to declare it before the render pipeline renders every Camera at a particular resolution. For information on how to do this, see the [Updating the RTHandle system](#updating-the-rthandle-system) section.
- There is now the concept of reference size. This is the resolution the application uses for rendering. It is your responsibility to declare it before the render pipeline renders every Camera at a particular resolution. For information on how to do this, see the [Updating the RTHandle system](rthandle-system-using.md#updating-the-rthandle-system) section.
- Internally, the RTHandle system tracks the largest reference size you declare. It uses this as the actual size of render textures. The largest reference size is the maximum size.
- Every time you declare a new reference size for rendering, the RTHandle system checks if it is larger than the current recorded largest reference size. If it is, the RTHandle system reallocates all render textures internally to fit the new size and replaces the largest reference size with the new size.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# What's new in SRP Core version 17 / Unity 6

This page contains an overview of new features, improvements, and issues resolved in version 17 of the Scriptable Render Pipeline (SRP) Core package, embedded in Unity 6.

## Improvements

### Render graph system optimization

The render graph system API and compiler are now carefully optimized to reduce their cost on the main CPU thread. To prevent Unity compiling the render graph each frame, there's now a caching system so Unity only compiles when the rendering is different from the previous frame. This means performance on the main CPU thread should be faster, especially in non-development builds.

### Native Render Pass support in the render graph system

The render graph system API now provides automatic Native Render Pass support using the `AddRasterRenderPass` API. This means Unity can use framebuffer fetch operations on platforms with tile-based GPUs, which improves performance.

Native Render Pass support is implemented in the Universal Render Pipeline (URP). For more information, refer to [Render graph system](https://docs.unity3d.com/Packages/[email protected]/manual/render-graph.html) in the URP manual.

**Note:** You can't use the `AddRasterRenderPass` API with the existing `AddRenderPass` API. Instead, use the new `AddComputePass` and `AddUnsafePass` APIs.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ The list of pages is as follows:

- [12](whats-new-12.md)
- [13](whats-new-13.md)
- [17](whats-new-17.md)
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class CommandBufferGenerator
// Functions for unsafe (wrapper around Commandbuffer) only
static List<FunctionInfo> unsafeFunctions = new List<FunctionInfo> {
"SetRenderTarget",
"Clear"
"Clear",
"RequestAsyncReadbackIntoNativeArray",
};
// Generated file header
static string preamble =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Rendering;
Expand Down Expand Up @@ -397,13 +398,30 @@ protected override Enum DoGUI(Rect rect, GUIContent label, DebugUI.BitField fiel
}
}


/// <summary>
/// Builtin Drawer for Foldout Debug Items.
/// </summary>
[DebugUIDrawer(typeof(DebugUI.Foldout))]
public sealed class DebugUIDrawerFoldout : DebugUIDrawer
{
const int k_HeaderVerticalMargin = 2;
static void DisplayColumns(Rect drawRect, List<GUIContent> rowContents)
{
drawRect.x += EditorGUIUtility.labelWidth;
drawRect.width = DebugWindow.Styles.foldoutColumnWidth;

int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0; //be at left of rects
for (int i = 0; i < rowContents.Count; i++)
{
EditorGUI.LabelField(drawRect, rowContents[i], EditorStyles.miniBoldLabel);

// Offset the rect to the next possible column
drawRect.x += DebugWindow.Styles.foldoutColumnWidth;
}
EditorGUI.indentLevel = indent;
}

/// <summary>
/// Implement this to execute processing before UI rendering.
Expand Down Expand Up @@ -432,34 +450,9 @@ public override void Begin(DebugUI.Widget widget, DebugState state)

bool previousValue = (bool)w.GetValue();
bool value = CoreEditorUtils.DrawHeaderFoldout(title, previousValue, isTitleHeader: w.isHeader, customMenuContextAction: fillContextMenuAction);

if (previousValue != value)
Apply(w, s, value);

Rect drawRect = GUILayoutUtility.GetLastRect();
if (w.columnLabels != null && value)
{
int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0; //be at left of rects

if (w.isHeader) // display column labels on a separate row for header-styled foldouts
{
drawRect = GUILayoutUtility.GetRect(1f, 1f, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight);
drawRect.x -= EditorGUIUtility.labelWidth / 2;
}

for (int i = 0; i < w.columnLabels.Length; i++)
{
var columnRect = drawRect;
columnRect.x += EditorGUIUtility.labelWidth + i * DebugWindow.Styles.foldoutColumnWidth;
columnRect.width = DebugWindow.Styles.foldoutColumnWidth;
string label = w.columnLabels[i] ?? "";
string tooltip = w.columnTooltips?.ElementAtOrDefault(i) ?? "";
EditorGUI.LabelField(columnRect, EditorGUIUtility.TrTextContent(label, tooltip), EditorStyles.miniBoldLabel);
}
EditorGUI.indentLevel = indent;
}

EditorGUI.indentLevel++;
}

Expand All @@ -472,6 +465,12 @@ public override void Begin(DebugUI.Widget widget, DebugState state)
public override bool OnGUI(DebugUI.Widget widget, DebugState state)
{
var w = Cast<DebugUI.Foldout>(widget);
if (w.opened && w.columnLabels != null)
{
var drawRect = PrepareControlRect(EditorGUIUtility.singleLineHeight);
drawRect.x = 0;
DisplayColumns(drawRect, w.rowContents);
}
return w.opened;
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal
#define UNIFIED_RT_GROUP_SIZE_X 64
#define UNIFIED_RT_GROUP_SIZE_Y 1

#include "Packages/com.unity.rendering.light-transport/Runtime/UnifiedRayTracing/FetchGeometry.hlsl"
#include "Packages/com.unity.rendering.light-transport/Runtime/UnifiedRayTracing/TraceRay.hlsl"
#include "Packages/com.unity.rendering.light-transport/Runtime/UnifiedRayTracing/Common.hlsl"
Expand Down Expand Up @@ -146,3 +150,46 @@ void RayGenExecute(UnifiedRT::DispatchInfo dispatchInfo)
_SkyOcclusionOut[probeId].yzw *= lerp(1.0f, radianceToIrradianceFactor, pow(windowL1, 1.125f));
}
}

#ifdef UNIFIED_RT_BACKEND_COMPUTE

#pragma kernel EncodeShadingDirection

StructuredBuffer<float3> _SkyShadingPrecomputedDirection;
StructuredBuffer<float3> _SkyShadingDirections;
RWStructuredBuffer<uint> _SkyShadingIndices;

uint _ProbeCount;

uint LinearSearchClosestDirection(float3 direction)
{
int indexMax = 255;
float bestDot = -10.0f;
int bestIndex = 0;

for (int index=0; index< indexMax; index++)
{
float currentDot = dot(direction, _SkyShadingPrecomputedDirection[index]);
if (currentDot > bestDot)
{
bestDot = currentDot;
bestIndex = index;
}
}
return bestIndex;
}

[numthreads(64, 1, 1)]
void EncodeShadingDirection(uint probeId : SV_DispatchThreadID)
{
if (probeId >= _ProbeCount)
return;

uint bestDirectionIndex = 255;
float norm = length(_SkyShadingDirections[probeId]);
if (norm > 0.0001f)
bestDirectionIndex = LinearSearchClosestDirection(_SkyShadingDirections[probeId] / norm);

_SkyShadingIndices[probeId] = bestDirectionIndex;
}
#endif

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

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public abstract class LightingBaker : IDisposable
/// <param name="probePositions">The probe positions. Also contains reflection probe positions used for normalization.</param>
public abstract void Initialize(bool bakeProbeOcclusion, NativeArray<Vector3> probePositions);

/// <summary>
/// This is called before the start of baking to allow allocating necessary resources.
/// </summary>
/// <param name="bakeProbeOcclusion">Whether to bake occlusion for mixed lights for each probe.</param>
/// <param name="probePositions">The probe positions. Also contains reflection probe positions used for normalization.</param>
/// <param name="bakedRenderingLayerMasks">The rendering layer masks assigned to each probe. It is used when fixing seams between subdivision levels</param>
public abstract void Initialize(bool bakeProbeOcclusion, NativeArray<Vector3> probePositions, NativeArray<uint> bakedRenderingLayerMasks);

/// <summary>
/// Run a step of light baking. Baking is considered done when currentStep property equals stepCount.
/// If isThreadSafe is true, this method may be called from a different thread.
Expand Down Expand Up @@ -73,6 +81,9 @@ class DefaultLightTransport : LightingBaker
public NativeArray<float> validityResults;
public NativeArray<Vector4> occlusionResults;

// Baked in a other job, but used in this one if available when fixing seams
private NativeArray<uint> renderingLayerMasks;

public override ulong currentStep => (ulong)bakedProbeCount;
public override ulong stepCount => (ulong)positions.Length;

Expand All @@ -99,6 +110,18 @@ public override void Initialize(bool bakeProbeOcclusion, NativeArray<Vector3> pr
occlusionResults = new NativeArray<Vector4>(positions.Length, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
}

public override void Initialize(bool bakeProbeOcclusion, NativeArray<Vector3> probePositions, NativeArray<uint> bakedRenderingLayerMasks)
{
renderingLayerMasks.Dispose();
if (bakedRenderingLayerMasks.IsCreated)
{
renderingLayerMasks = new NativeArray<uint>(bakedRenderingLayerMasks.Length, Allocator.Persistent);
renderingLayerMasks.CopyFrom(bakedRenderingLayerMasks);
}

Initialize(bakeProbeOcclusion, probePositions);
}

public override bool Step()
{
if (input == null)
Expand Down Expand Up @@ -131,7 +154,7 @@ public override bool Step()
// When baking reflection probes, we want to skip this step
if (m_BakingBatch != null)
{
FixSeams(s_BakeData.positionRemap, positions, irradiance, validity);
FixSeams(s_BakeData.positionRemap, positions, irradiance, validity, renderingLayerMasks);
}

return true;
Expand All @@ -143,6 +166,7 @@ public override void Dispose()
validityResults.Dispose();
if (bakeProbeOcclusion)
occlusionResults.Dispose();
renderingLayerMasks.Dispose();
}
}

Expand Down Expand Up @@ -902,19 +926,20 @@ internal static void BakeAdjustmentVolume(ProbeVolumeBakingSet bakingSet, ProbeA
if (!failed && skyOcclusionJob.shadingDirections.IsCreated)
skyOcclusionJob.Encode();

// Bake rendering layers
var layerMaskJob = renderingLayerOverride ?? new DefaultRenderingLayer();
layerMaskJob.Initialize(bakingSet, uniquePositions.AsArray());
while (!failed && layerMaskJob.currentStep < layerMaskJob.stepCount)
failed |= !layerMaskJob.Step();

// Bake probe SH
var lightingJob = lightingOverride ?? new DefaultLightTransport();
lightingJob.Initialize(ProbeVolumeLightingTab.GetLightingSettings().mixedBakeMode != MixedLightingMode.IndirectOnly, uniquePositions.AsArray());
lightingJob.Initialize(ProbeVolumeLightingTab.GetLightingSettings().mixedBakeMode != MixedLightingMode.IndirectOnly, uniquePositions.AsArray(), layerMaskJob.renderingLayerMasks);
if (lightingJob is DefaultLightTransport defaultLightingJob)
defaultLightingJob.jobs = jobs;
while (!failed && lightingJob.currentStep < lightingJob.stepCount)
failed |= !lightingJob.Step();

// Bake rendering layers
var layerMaskJob = renderingLayerOverride ?? new DefaultRenderingLayer();
layerMaskJob.Initialize(bakingSet, uniquePositions.AsArray());
while (!failed && layerMaskJob.currentStep < layerMaskJob.stepCount)
failed |= !layerMaskJob.Step();

// Upload new data in cells
foreach ((int uniqueProbeIndex, int cellIndex, int i) in bakedProbes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static internal bool CanFreezePlacement()
if (!ProbeReferenceVolume.instance.supportLightingScenarios)
return false;

// Check if all the scene datas in the scene have a baking set, if not then we cannot enable this option.
// Check if all the scene datas in the scene have a baking set, if not then we cannot enable this option.
var sceneDataList = GetPerSceneDataList();
if (sceneDataList.Count == 0)
return false;
Expand Down
Loading

0 comments on commit fc267ad

Please sign in to comment.