Skip to content

Commit 8700510

Browse files
Merge pull request #8293 from Unity-Technologies/internal/6000.5/staging
Internal/6000.5/staging
2 parents 78b9591 + 04fc1fe commit 8700510

77 files changed

Lines changed: 3422 additions & 345 deletions

File tree

Some content is hidden

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

Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/create-ray-tracing-context.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Follow these steps:
99
## Load the ray tracing resources
1010
The [`RayTracingContext`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext) needs a few utility shaders that the [`RayTracingResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources) object supplies. You can load these resources in several different ways.
1111

12-
If your project uses SRP (Scriptable Render Pipeline), load the resources via [`RayTracingResources.LoadFromRenderPipelineResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext.LoadFromRenderPipelineResources()). This always works in the Editor.
12+
If your project uses SRP (Scriptable Render Pipeline), load the resources via [`RayTracingResources.LoadFromRenderPipelineResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources.LoadFromRenderPipelineResources()). This always works in the Editor.
1313
```C#
1414
var rtResources = new RayTracingResources();
1515
bool result = rtResources.LoadFromRenderPipelineResources();
@@ -49,9 +49,12 @@ rtResources.LoadFromAssetBundle(asssetBundle);
4949
## Create the context
5050
Once the [`RayTracingResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources) are loaded, use them to create the [`RayTracingContext`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext).
5151
```C#
52-
// Choose a backend
53-
var backend = RayTracingContext.IsBackendSupported(RayTracingBackend.Hardware) ? RayTracingBackend.Hardware : RayTracingBackend.Compute;
52+
var context = new RayTracingContext(rtResources);
53+
```
54+
55+
By default, Unity checks if the device supports hardware ray tracing, and selects either hardware ray tracing or compute shaders. To manually select the backend, pass in a `RayTracingBackend`. For example:
5456

55-
// Create the context
57+
```C#
58+
var backend = RayTracingBackend.Compute;
5659
var context = new RayTracingContext(backend, rtResources);
5760
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Release your ray tracing objects
2+
3+
You must free up the memory your ray tracing objects use after you finish with them.
4+
5+
Dispose of the following:
6+
7+
- Scratch buffers. Use [`GraphicsBuffer.Dispose`](xref:UnityEngine.GraphicsBuffer.Dispose()) after you've executed the final command buffer.
8+
- Ray tracing acceleration structures. Use [`IRayTracingAccelStruct.Dispose`](xref:UnityEngine.Rendering.UnifiedRayTracing.IRayTracingAccelStruct.Dispose()) after you've executed the final command buffer.
9+
- Ray tracing context. Use [`RayTracingContext.Dispose`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext.Dispose()) after you dispose of all its acceleration structures.
10+
11+
**Note**: Unity automatically disposes of [`RayTracingResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources) and [`IRayTracingShader`](xref:UnityEngine.Rendering.UnifiedRayTracing.IRayTracingShader).
12+
13+
For example:
14+
15+
```C#
16+
RayTracingContext rtContext = new RayTracingContext(rtResources);
17+
IRayTracingShader rtShader = rtContext.LoadRayTracingShader("Assets/yourShader.urtshader");
18+
IRayTracingAccelStruct rtAccelStruct = rtContext.CreateAccelerationStructure(new AccelerationStructureOptions());
19+
GraphicsBuffer rtScratchBuffer = RayTracingHelper.CreateScratchBufferForBuild(rtAccelStruct);
20+
21+
// ... create and dispatch your ray tracing command buffers ...
22+
23+
rtScratchBuffer.Dispose();
24+
rtAccelStruct.Dispose();
25+
rtContext.Dispose();
26+
```

Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/unified-ray-tracing-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ The `UnifiedRayTracing` API enables you to write ray tracing code that can execu
1212
|[Execute your ray tracing code](execute-shader.md)|How to execute your ray tracing shader.|
1313
|[Sample code](trace-camera-rays-full-sample.md)|Complete code example showcasing tracing rays from the scene's camera.|
1414
|[Unified ray tracing shader code reference](shader-code-reference.md)|API reference for the unified ray tracing shader code.|
15-
15+
|[Release your ray tracing objects](release-resources.md)|Learn how to release your ray tracing resources.|

Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/workflow.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ To use the API to trace rays in Unity, follow these steps:
55
3. Create a shader.
66
4. Build your acceleration structure.
77
5. Execute your shader.
8+
6. Dispose of your objects.
89

910
## Create the ray tracing context
1011

@@ -53,3 +54,5 @@ rtShader.Dispatch(cmd, traceScratchBuffer, threadCountX, threadCountY, threadCou
5354

5455
For more information, refer to [Execute your ray tracing code](execute-shader.md).
5556

57+
## Dispose of your objects
58+
For more information, refer to [Release your ray tracing objects](release-resources.md).

Packages/com.unity.render-pipelines.core/Editor/SampleDependencyImportSystem/SampleDependencyImporter.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.IO;
43
using UnityEditor;
@@ -40,7 +39,6 @@ static SampleDependencyImporter()
4039

4140
PackageInfo m_PackageInfo;
4241
SampleList m_SampleList;
43-
List<Sample> m_Samples;
4442

4543
VisualElement injectingElement;
4644
VisualElement _panelRoot;
@@ -100,6 +98,7 @@ internal void RefreshSampleButtons()
10098

10199
var bound = Mathf.Min(sampleContainers.Count, m_SampleList.samples.Length);
102100

101+
// Foreach sample
103102
for (int i=0; i<bound; i++)
104103
{
105104
// Check if the sample has dependencies, if not just skip the injection.
@@ -155,16 +154,20 @@ internal void RefreshSampleButtons()
155154

156155
// Need to copy i for the lambda.
157156
var index = i;
158-
// On click of the imported button, import the dependencies first then call the original button logic.
157+
// On click of the imported button, import the dependencies first then use the package manager API to trigger the regular sample import logic.
159158
injectedButton.clicked += () =>
160159
{
161160
ImportSampleDependencies(index);
162161

163-
using (var ev = NavigationSubmitEvent.GetPooled())
162+
// After importing the dependencies, we can call the package manager API import logic.
163+
foreach (Sample sample in Sample.FindByPackage(m_PackageInfo.name, m_PackageInfo.version))
164164
{
165-
ev.target = importButton;
166-
importButton.SendEvent(ev);
165+
if (sample.displayName == m_SampleList.samples[index].displayName)
166+
{
167+
sample.Import(Sample.ImportOptions.HideImportWindow | Sample.ImportOptions.OverridePreviousImports);
168+
}
167169
}
170+
168171
};
169172
}
170173
else // We may need to update the button text after the sample import here.

Packages/com.unity.render-pipelines.core/Editor/Tools/MaterialUpgrader/MaterialUpgrader.Utils.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace UnityEditor.Rendering
1212
/// </summary>
1313
public partial class MaterialUpgrader
1414
{
15+
internal static readonly string k_DialogKey = $"{nameof(UnityEditor)}.{nameof(Rendering)}.{nameof(MaterialUpgrader)}.ConfirmMaterialConversion";
16+
1517
#region Internal API
1618
/// <summary>
1719
/// Represents an entry describing material properties
@@ -344,15 +346,15 @@ static void PerformUpgrade(List<MaterialUpgradeEntry> materialUpgrades, List<Mat
344346

345347
bool CanPerformUpgrade()
346348
{
347-
const string title = "Material Upgrader";
348-
const string message = "This operation will overwrite existing materials in your project.\n\nPlease ensure you have a backup before proceeding.";
349+
const string title = "Confirm Material Conversion";
350+
const string message = "This action will modify materials and cannot be easily undone. It is strongly recommended to have a backup or use version control before continuing.";
349351
const string proceed = "Proceed";
350352
const string cancel = "Cancel";
351353

352354
if (Application.isBatchMode)
353355
return true;
354356

355-
return EditorUtility.DisplayDialog(title, message, proceed, cancel);
357+
return EditorUtility.DisplayDialog(title, message, proceed, cancel, DialogOptOutDecisionType.ForThisMachine, k_DialogKey);
356358
}
357359

358360
if (CanPerformUpgrade())
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Collections.Generic;
2+
using UnityEngine;
3+
using UnityEngine.Rendering;
4+
5+
namespace UnityEditor.Rendering
6+
{
7+
class MaterialUpgraderEditMenus
8+
{
9+
private static readonly List<MaterialUpgrader> s_Empty = new List<MaterialUpgrader>();
10+
11+
public static List<MaterialUpgrader> GetCurrentSRPUpgraders()
12+
{
13+
if (!GraphicsSettings.isScriptableRenderPipelineEnabled)
14+
return s_Empty;
15+
16+
return MaterialUpgrader.FetchAllUpgradersForPipeline(GraphicsSettings.currentRenderPipelineAssetType);
17+
}
18+
19+
[MenuItem("Edit/Rendering/Materials/Convert All Built-In Materials to Current SRP", true)]
20+
internal static bool UpgradeMaterialsProjectValidate()
21+
{
22+
return GraphicsSettings.isScriptableRenderPipelineEnabled;
23+
}
24+
25+
[MenuItem("Edit/Rendering/Materials/Convert All Built-In Materials to Current SRP", priority = CoreUtils.Priorities.editMenuPriority + 1)]
26+
internal static void UpgradeMaterialsProject()
27+
{
28+
MaterialUpgrader.UpgradeProjectFolder(GetCurrentSRPUpgraders(), "Upgrade to SRP Material");
29+
}
30+
31+
[MenuItem("Edit/Rendering/Materials/Convert Selected Built-In Materials to Current SRP", true)]
32+
internal static bool UpgradeMaterialsSelectionValidate()
33+
{
34+
if (Selection.objects.Length == 0 || !GraphicsSettings.isScriptableRenderPipelineEnabled)
35+
return false;
36+
37+
foreach (var obj in Selection.objects)
38+
{
39+
if (obj is not Material)
40+
return false;
41+
}
42+
43+
return true;
44+
}
45+
46+
[MenuItem("Edit/Rendering/Materials/Convert Selected Built-In Materials to Current SRP", priority = CoreUtils.Priorities.editMenuPriority + 2)]
47+
internal static void UpgradeMaterialsSelection()
48+
{
49+
MaterialUpgrader.UpgradeSelection(GetCurrentSRPUpgraders(), "Upgrade to SRP Material");
50+
}
51+
}
52+
}

Packages/com.unity.render-pipelines.core/Editor/Tools/MaterialUpgrader/MaterialUpgraderEditMenus.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugUI.Fields.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,11 @@ protected override VisualElement Create()
875875

876876
this.ScheduleTracked(field, () => field.schedule.Execute(() =>
877877
{
878-
if (currentIndex >= 0 && currentIndex < enumNames.Length)
879-
field.SetValueWithoutNotify(enumNames[currentIndex].text);
878+
// https://jira.unity3d.com/browse/UUM-138138: Clamp currentIndex to 0. This matches old IMGUI
879+
// DebugUIDrawer behavior where a negative index is sometimes used to denote an invalid/none value.
880+
int index = Mathf.Max(0, currentIndex);
881+
if (index < enumNames.Length)
882+
field.SetValueWithoutNotify(enumNames[index].text);
880883
}).Every(100));
881884

882885
m_AdditionalSearchText = string.Join(",", field.choices);

Packages/com.unity.render-pipelines.core/Runtime/Debugging/DebugUI.Panel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public VisualElement Create(DebugUI.Context context)
5656
container.AddToClassList("unity-inspector-element");
5757

5858
var content = new VisualElement();
59+
5960
foreach (var child in children)
6061
{
6162
if (context == Context.Editor && child.isRuntimeOnly)
@@ -67,6 +68,7 @@ public VisualElement Create(DebugUI.Context context)
6768
if (childUIElement != null)
6869
content.Add(childUIElement);
6970
}
71+
7072
container.Add(content);
7173

7274
return container;

0 commit comments

Comments
 (0)