Skip to content

Commit f257d0e

Browse files
PaulDemeulenaereEvergreen
authored andcommitted
[VFX] Fix Error Feedback with CustomHLSL
Fix wrong error feedback with relative path, add a missing check using base path. Issue technically introduced at https://github.cds.internal.unity3d.com/unity/unity/commit/de946b09b4e9e9f3e06853c8f5465f5403f5ec96 but this isn't a regression since it's a new error feedback.
1 parent f649986 commit f257d0e

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

Packages/com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/HLSL/CustomHLSL.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ internal override void GenerateErrors(VFXErrorReporter report)
243243
base.GenerateErrors(report);
244244
var hlslValidator = new CustomHLSLBlockFunctionValidator();
245245
ParseCodeIfNeeded();
246-
foreach(var error in hlslValidator.Validate(m_AvailableFunction.values, m_Function, includes))
246+
247+
var basePath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(GetGraph().GetResource()));
248+
foreach(var error in hlslValidator.Validate(m_AvailableFunction.values, m_Function, basePath, includes))
247249
{
248250
report.RegisterError(string.Empty, error.type, error.message, this);
249251
}

Packages/com.unity.visualeffectgraph/Editor/Models/Operators/Implementations/CustomHLSL.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace UnityEditor.VFX.Operator
1111
{
1212
abstract class CustomHLSLFunctionValidator
1313
{
14-
public IEnumerable<IHLSMessage> Validate(IEnumerable<string> functions, HLSLFunction selectedFunction, IEnumerable<string> includes)
14+
public IEnumerable<IHLSMessage> Validate(IEnumerable<string> functions, HLSLFunction selectedFunction, string basePath, IEnumerable<string> includes)
1515
{
1616
if (functions == null || selectedFunction == null)
1717
{
@@ -63,7 +63,10 @@ public IEnumerable<IHLSMessage> Validate(IEnumerable<string> functions, HLSLFunc
6363
var guid = AssetDatabase.AssetPathToGUID(include);
6464
if (string.IsNullOrEmpty(guid))
6565
{
66-
yield return new HLSLMissingIncludeFile(include);
66+
//Try with Relative Path
67+
guid = AssetDatabase.AssetPathToGUID(Path.Combine(basePath, include));
68+
if (string.IsNullOrEmpty(guid))
69+
yield return new HLSLMissingIncludeFile(include);
6770
}
6871
}
6972

@@ -270,7 +273,9 @@ internal override void GenerateErrors(VFXErrorReporter report)
270273
base.GenerateErrors(report);
271274
var hlslValidator = new CustomHLSLOperatorFunctionValidator();
272275
ParseCodeIfNeeded();
273-
foreach(var error in hlslValidator.Validate(m_AvailableFunctions.values, m_Function, includes))
276+
277+
var basePath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(GetGraph().GetResource()));
278+
foreach (var error in hlslValidator.Validate(m_AvailableFunctions.values, m_Function, basePath, includes))
274279
{
275280
report.RegisterError(string.Empty, error.type, error.message, this);
276281
}

Tests/SRPTests/Projects/VisualEffectGraph_HDRP/Assets/AllTests/Editor/Tests/CustomHLSLOperatorTest.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
22
using System;
33
using System.Collections;
4+
using System.IO;
45
using System.Linq;
56
using System.Reflection;
67

@@ -180,6 +181,33 @@ public IEnumerator Check_CustomHLSL_Operator_No_Function()
180181
Assert.AreEqual("No valid HLSL function has been provided. You should write at least one function that returns a value", report.description);
181182
}
182183

184+
[UnityTest]
185+
public IEnumerator Check_CustomHLSL_Operator_IncludePath_Relative_Path_Success()
186+
{
187+
// Arrange
188+
var hlslOperator = ScriptableObject.CreateInstance<CustomHLSL>();
189+
CustomHLSLBlockTest.CreateShaderFile(defaultHlslCode, out var shaderIncludePath);
190+
shaderIncludePath = Path.GetFileName(shaderIncludePath);
191+
192+
var hlslCode = string.Format("#include \"{0}\"", shaderIncludePath);
193+
hlslCode += @"
194+
float3 Transform(float3 a, float3 b)
195+
{
196+
return a + b;
197+
}";
198+
hlslOperator.SetSettingValue("m_HLSLCode", hlslCode);
199+
MakeSimpleGraphWithCustomHLSL(hlslOperator, out var view, out var graph);
200+
201+
yield return null;
202+
203+
// Act
204+
graph.errorManager.GenerateErrors();
205+
206+
// Assert
207+
var report = graph.errorManager.errorReporter.GetDirtyModelErrors(hlslOperator);
208+
Assert.IsTrue(!report.Any());
209+
}
210+
183211
[UnityTest]
184212
public IEnumerator Check_CustomHLSL_Operator_IncludePath_Fail()
185213
{

0 commit comments

Comments
 (0)