Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -5,6 +5,7 @@
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph.Serialization;
using UnityEngine;
using GraphicsDeviceType = UnityEngine.Rendering.GraphicsDeviceType;

namespace UnityEditor.ShaderGraph.UnitTests
{
Expand Down Expand Up @@ -67,8 +68,22 @@ public void ImportMulti(string directory)
string sourceDir = Path.GetFullPath(directory).TrimEnd(Path.DirectorySeparatorChar);
string dirName = Path.GetFileName(sourceDir);

string targetUnityDir = "Assets/Testing/ImportTests/" + dirName;
string targetDir = Application.dataPath + "/Testing/ImportTests/" + dirName;
DirectoryCopy(sourceDir, targetDir, true, true);
try
{
AssetDatabase.StartAssetEditing();
DirectoryCopy(sourceDir, targetDir, true, true);
}
finally
{
AssetDatabase.StopAssetEditing();
}

// import all the files in the directory
// NOTE: this is important, as our shader generation relies on the AssetDatabase being fully populated
// so we can lookup file paths by GUID.
AssetDatabase.ImportAsset(targetUnityDir, ImportAssetOptions.ImportRecursive | ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);

foreach (var assetFullPath in Directory.GetFiles(targetDir, "*.shader*", SearchOption.TopDirectoryOnly))
{
Expand Down Expand Up @@ -133,6 +148,36 @@ public void TestImportAsset(string unityLocalPath, string fullPath)
string shader2 = generator2.generatedShader;

Assert.AreEqual(shader, shader2, $"Importing the graph {unityLocalPath} twice resulted in different generated shaders.");

// Texture test won't work on platforms that don't support more than 16 samplers

bool isGL =
(SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLCore) ||
(SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES2) ||
(SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3);

bool isOSX =
(Application.platform == RuntimePlatform.OSXEditor) ||
(Application.platform == RuntimePlatform.OSXPlayer);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vulkan doesn't guarantee more than 16 either. I suspect most desktop implementations actually provide more than 16, but the hardware requirements for the spec are derived from OpenGL ES 3.1, so it's not guaranteed without checking.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it at least passes on Windows Editor / Vulkan on my box.

bool samplersSupported = !(isOSX && isGL);
if (!samplersSupported && fullPath.Contains("TextureTest"))
{
// skip the compile test -- we know this shader won't compile on these platforms
}
else
{
// now create a Unity Shader from the string
var compiledShader = ShaderUtil.CreateShaderAsset(shader, true);
compiledShader.hideFlags = HideFlags.HideAndDontSave;

Assert.NotNull(compiledShader);

// compile all the shader passes to see if there are any errors
var mat = new Material(compiledShader) { hideFlags = HideFlags.HideAndDontSave };
for (int pass = 0; pass < mat.passCount; pass++)
ShaderUtil.CompilePass(mat, pass, true);
}
}
}

Expand Down
Loading