Skip to content

Commit

Permalink
[RPW]Shader Stripping Watcher
Browse files Browse the repository at this point in the history
- Bring back the callback to notify when a shader variant has been processed.
- Fixing this[ yamato job](https://yamato-artifactviewer.prd.cds.internal.unity3d.com/bfd11010-3cc0-495c-aa6b-1d019a56c210%2FTest_Report_1%2FUtrTestReport1/TestReport.html
)
  • Loading branch information
alex-vazquez-unity3d committed May 11, 2022
1 parent 3148eb7 commit deecca5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ protected bool TryStripShaderVariants([DisallowNull] TShader shader, TShaderVari
}

ShaderStripping.reporter.OnShaderProcessed(shader, shaderVariant, renderPipelineTag,(uint)beforeStrippingInputShaderVariantCount, (uint)compilerDataList.Count, stripTimeMs);
ShaderStrippingWatcher.OnShaderProcessed(shader, shaderVariant, (uint)compilerDataList.Count, stripTimeMs);

error = null;
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using UnityEngine;

namespace UnityEditor.Rendering
{
/// <summary>
/// Notifies when shader variants have been stripped
/// </summary>
public static class ShaderStrippingWatcher
{
/// <summary>
/// Callback when a shader has been stripped
/// </summary>
/// <param name="shader">The shader</param>
/// <param name="shaderVariant">The variant</param>
/// <param name="variantsOut">The output variants after the stripping process</param>
/// <param name="stripTimeMs">The total amount of time to strip the variants</param>
/// <typeparam name="TShader">The shader</typeparam>
/// <typeparam name="TShaderVariant">The variant</typeparam>
public delegate void OnShaderStrippedCallbackHandler<TShader, TShaderVariant>(TShader shader, TShaderVariant shaderVariant, uint variantsOut, double stripTimeMs)
where TShader : UnityEngine.Object;

/// <summary>
/// Callback for <see cref="Shader"/>
/// </summary>
public static event OnShaderStrippedCallbackHandler<Shader, ShaderSnippetData> shaderProcessed;

/// <summary>
/// Callback for <see cref="ComputeShader"/>
/// </summary>
public static event OnShaderStrippedCallbackHandler<ComputeShader, string> computeShaderProcessed;

internal static void OnShaderProcessed<TShader, TShaderVariant>(TShader shader, TShaderVariant shaderVariant, uint variantsOut, double stripTimeMs)
where TShader : UnityEngine.Object
{
if (typeof(TShader) == typeof(Shader))
{
shaderProcessed?.Invoke((Shader)Convert.ChangeType(shader, typeof(Shader)), (ShaderSnippetData)Convert.ChangeType(shaderVariant, typeof(ShaderSnippetData)), variantsOut, stripTimeMs);
}
else if (typeof(TShader) == typeof(ComputeShader))
{
computeShaderProcessed?.Invoke((ComputeShader)Convert.ChangeType(shader, typeof(ComputeShader)), shaderVariant.ToString(), variantsOut, stripTimeMs);
}
}
}
}

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 @@ -38,7 +38,7 @@ static IEnumerable<BuildTestDescription> GetBuildTests()
[Timeout(k_BuildTimeout), Version("1"), UnityTest, Performance]
public IEnumerator Build([ValueSource(nameof(GetBuildTests))] BuildTestDescription testDescription)
{
HDRPreprocessShaders.shaderPreprocessed += ReportShaderStrippingData;
ShaderStrippingWatcher.shaderProcessed += ReportShaderStrippingData;

using (new EditorLogWatcher(OnEditorLogWritten))
{
Expand All @@ -48,12 +48,12 @@ public IEnumerator Build([ValueSource(nameof(GetBuildTests))] BuildTestDescripti
EditorPerformanceTests.ReportShaderSize(buildReport, k_ShaderNameFilter);
}

HDRPreprocessShaders.shaderPreprocessed -= ReportShaderStrippingData;
ShaderStrippingWatcher.shaderProcessed -= ReportShaderStrippingData;

yield return null;
}

static void ReportShaderStrippingData(Shader shader, ShaderSnippetData data, int currentVariantCount, double strippingTime)
void ReportShaderStrippingData(Shader shader, ShaderSnippetData data, uint currentVariantCount, double strippingTime)
{
if (!shader.name.Contains(k_ShaderNameFilter))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"Unity.PerformanceTesting",
"Unity.RenderPipelines.HighDefinition.Runtime",
"Unity.RenderPipelines.Core.Runtime",
"Unity.RenderPipelines.Core.Editor",
"Unity.GraphicTests.Performance.Runtime",
"UnityEngine.TestRunner",
"Unity.GraphicTests.Performance.Editor",
Expand All @@ -25,4 +26,4 @@
],
"versionDefines": [],
"noEngineReferences": false
}
}

0 comments on commit deecca5

Please sign in to comment.