浏览代码

Update directory structure of graphic test

- Move framework in framework directory
- Move scene in RenderPipeline/LowEndMobile directory
- Add RenderPipeline/HDRenderPipeline
/Branch_Batching2
sebastienlagarde 8 年前
当前提交
c95acc41
共有 24 个文件被更改,包括 234 次插入9 次删除
  1. 9
      Assets/GraphicsTests/Framework.meta
  2. 9
      Assets/GraphicsTests/RenderPipeline/LowEndMobilePipeline.meta
  3. 207
      Assets/GraphicsTests/Framework/Editor/TestFramework.cs
  4. 9
      Assets/GraphicsTests/RenderPipeline/LowEndMobilePipeline/Scenes.meta
  5. 9
      Assets/GraphicsTests/Scenes.meta
  6. 0
      /Assets/GraphicsTests/Framework/Editor/TestFramework.cs.meta
  7. 0
      /Assets/GraphicsTests/Framework/Editor/SetupSceneForRenderPipelineTestEditor.cs
  8. 0
      /Assets/GraphicsTests/Framework/Editor/SetupSceneForRenderPipelineTestEditor.cs.meta
  9. 0
      /Assets/GraphicsTests/Framework/Editor/TestFrameworkCustomBuild.cs
  10. 0
      /Assets/GraphicsTests/Framework/Editor/TestFrameworkCustomBuild.cs.meta
  11. 0
      /Assets/GraphicsTests/Framework/Editor.meta
  12. 0
      /Assets/GraphicsTests/Framework/SetupSceneForRenderPipelineTest.cs.meta
  13. 0
      /Assets/GraphicsTests/Framework/SetupSceneForRenderPipelineTest.cs
  14. 0
      /Assets/GraphicsTests/RenderPipeline/LowEndMobilePipeline/Assets.meta
  15. 0
      /Assets/GraphicsTests/RenderPipeline/LowEndMobilePipeline/Assets
  16. 0
      /Assets/GraphicsTests/Framework/GotoNextScene.cs
  17. 0
      /Assets/GraphicsTests/Framework/GotoNextScene.cs.meta
  18. 0
      /ImageTemplates/LowEndMobilePipeline/Scenes
  19. 0
      /Assets/GraphicsTests/RenderPipeline/LowEndMobilePipeline/Scenes

9
Assets/GraphicsTests/Framework.meta


fileFormatVersion: 2
guid: 8305d4811b3aa624ea663e2d7841e470
folderAsset: yes
timeCreated: 1495206710
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/GraphicsTests/RenderPipeline/LowEndMobilePipeline.meta


fileFormatVersion: 2
guid: 6cc80706fb944a2499efc62666d48a2b
folderAsset: yes
timeCreated: 1495206216
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

207
Assets/GraphicsTests/Framework/Editor/TestFramework.cs


using System;
using System.Collections;
using System.IO;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEditor.SceneManagement;
using Object = UnityEngine.Object;
using UnityEngine.Experimental.Rendering;
using UnityEngine.TestTools;
namespace UnityEditor.Experimental.Rendering
{
public class GraphicsTests
{
// path where the tests live
private static readonly string[] s_Path =
{
"GraphicsTests",
"RenderPipeline"
};
private static readonly string[] s_PipelinePath =
{
"LowEndMobilePipeline",
"HDRenderPipeline",
};
// info that gets generated for use
// in a dod way
public struct TestInfo
{
public string name;
public float threshold;
public string relativePath;
public int frameWait;
public override string ToString()
{
return name;
}
}
// collect the scenes that we can use
public static class CollectScenes
{
public static IEnumerable scenes
{
get
{
var absoluteScenesPath = s_Path.Aggregate(Application.dataPath, Path.Combine);
foreach (var pipelinePath in s_PipelinePath)
{
var filesPath = Path.Combine(absoluteScenesPath, pipelinePath);
// find all the scenes
var allPaths = System.IO.Directory.GetFiles(filesPath, "*.unity", System.IO.SearchOption.AllDirectories);
// construct all the needed test infos
foreach (var path in allPaths)
{
var p = new FileInfo(path);
var split = s_Path.Aggregate("", Path.Combine);
split = string.Format("{0}{1}", split, Path.DirectorySeparatorChar);
var splitPaths = p.FullName.Split(new[] { split }, StringSplitOptions.RemoveEmptyEntries);
yield return new TestInfo
{
name = p.Name,
relativePath = splitPaths.Last(),
threshold = 0.02f,
frameWait = 100
};
}
}
}
}
}
[TearDown]
public void TearDown()
{
var testSetup = Object.FindObjectOfType<SetupSceneForRenderPipelineTest>();
if (testSetup == null)
return;
testSetup.TearDown();
}
[UnityTest]
public IEnumerator TestScene([ValueSource(typeof(CollectScenes), "scenes")]TestInfo testInfo)
{
var prjRelativeGraphsPath = s_Path.Aggregate("Assets", Path.Combine);
var filePath = Path.Combine(prjRelativeGraphsPath, testInfo.relativePath);
// open the scene
EditorSceneManager.OpenScene(filePath);
var testSetup = Object.FindObjectOfType<SetupSceneForRenderPipelineTest> ();
Assert.IsNotNull(testSetup, "No SetupSceneForRenderPipelineTest in scene " + testInfo.name);
Assert.IsNotNull(testSetup.cameraToUse, "No configured camera in <SetupSceneForRenderPipelineTest>");
testSetup.Setup();
for (int i = 0; i < testInfo.frameWait; ++i)
{
yield return null;
}
while (Lightmapping.isRunning)
{
yield return null;
}
var rtDesc = new RenderTextureDescriptor (
testSetup.width,
testSetup.height,
testSetup.hdr ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32,
24);
rtDesc.sRGB = PlayerSettings.colorSpace == ColorSpace.Linear;
// render the scene
var tempTarget = RenderTexture.GetTemporary (rtDesc);
var oldTarget = testSetup.cameraToUse.targetTexture;
testSetup.cameraToUse.targetTexture = tempTarget;
testSetup.cameraToUse.Render ();
testSetup.cameraToUse.targetTexture = oldTarget;
// Readback the rendered texture
var oldActive = RenderTexture.active;
RenderTexture.active = tempTarget;
var captured = new Texture2D(tempTarget.width, tempTarget.height, TextureFormat.ARGB32, false);
captured.ReadPixels(new Rect(0, 0, testSetup.width, testSetup.height), 0, 0);
RenderTexture.active = oldActive;
var rootPath = Directory.GetParent(Application.dataPath).ToString();
var templatePath = Path.Combine(rootPath.ToString(), "ImageTemplates");
// find the reference image
var dumpFileLocation = Path.Combine(templatePath, string.Format("{0}.{1}", testInfo.relativePath, "png"));
if (!File.Exists(dumpFileLocation))
{
// no reference exists, create it
var fileInfo = new FileInfo (dumpFileLocation);
fileInfo.Directory.Create();
var generated = captured.EncodeToPNG();
File.WriteAllBytes(dumpFileLocation, generated);
Assert.Fail("Template file not found for {0}, creating it at {1}.", testInfo.name, dumpFileLocation);
}
var template = File.ReadAllBytes(dumpFileLocation);
var fromDisk = new Texture2D(2, 2);
fromDisk.LoadImage(template, false);
var areEqual = CompareTextures(fromDisk, captured, testInfo.threshold);
if (!areEqual)
{
var failedPath = Path.Combine(rootPath.ToString(), "Failed");
Directory.CreateDirectory(failedPath);
var misMatchLocationResult = Path.Combine(failedPath, string.Format("{0}.{1}", testInfo.name, "png"));
var misMatchLocationTemplate = Path.Combine(failedPath, string.Format("{0}.template.{1}", testInfo.name, "png"));
var generated = captured.EncodeToPNG();
File.WriteAllBytes(misMatchLocationResult, generated);
File.WriteAllBytes(misMatchLocationTemplate, template);
}
Assert.IsTrue(areEqual, "Scene from {0}, did not match .template file.", testInfo.relativePath);
}
// compare textures, use RMS for this
private bool CompareTextures(Texture2D fromDisk, Texture2D captured, float threshold)
{
if (fromDisk == null || captured == null)
return false;
if (fromDisk.width != captured.width
|| fromDisk.height != captured.height)
return false;
var pixels1 = fromDisk.GetPixels();
var pixels2 = captured.GetPixels();
if (pixels1.Length != pixels2.Length)
return false;
int numberOfPixels = pixels1.Length;
float sumOfSquaredColorDistances = 0;
for (int i = 0; i < numberOfPixels; i++)
{
Color p1 = pixels1[i];
Color p2 = pixels2[i];
Color diff = p1 - p2;
diff = diff * diff;
sumOfSquaredColorDistances += (diff.r + diff.g + diff.b) / 3.0f;
}
float rmse = Mathf.Sqrt(sumOfSquaredColorDistances / numberOfPixels);
return rmse < threshold;
}
}
}

9
Assets/GraphicsTests/RenderPipeline/LowEndMobilePipeline/Scenes.meta


fileFormatVersion: 2
guid: 7a8c0a6569edfa341bc4c6875a5ca524
folderAsset: yes
timeCreated: 1495206216
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/GraphicsTests/Scenes.meta


fileFormatVersion: 2
guid: 22b5af213d3fd4ff4bc9e34ab9e8cc99
folderAsset: yes
timeCreated: 1493133658
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

/Assets/GraphicsTests/Editor/TestFramework.cs.meta → /Assets/GraphicsTests/Framework/Editor/TestFramework.cs.meta

/Assets/GraphicsTests/Editor/SetupSceneForRenderPipelineTestEditor.cs → /Assets/GraphicsTests/Framework/Editor/SetupSceneForRenderPipelineTestEditor.cs

/Assets/GraphicsTests/Editor/SetupSceneForRenderPipelineTestEditor.cs.meta → /Assets/GraphicsTests/Framework/Editor/SetupSceneForRenderPipelineTestEditor.cs.meta

/Assets/GraphicsTests/Editor/TestFrameworkCustomBuild.cs → /Assets/GraphicsTests/Framework/Editor/TestFrameworkCustomBuild.cs

/Assets/GraphicsTests/Editor/TestFrameworkCustomBuild.cs.meta → /Assets/GraphicsTests/Framework/Editor/TestFrameworkCustomBuild.cs.meta

/Assets/GraphicsTests/Editor.meta → /Assets/GraphicsTests/Framework/Editor.meta

/Assets/GraphicsTests/SetupSceneForRenderPipelineTest.cs.meta → /Assets/GraphicsTests/Framework/SetupSceneForRenderPipelineTest.cs.meta

/Assets/GraphicsTests/SetupSceneForRenderPipelineTest.cs → /Assets/GraphicsTests/Framework/SetupSceneForRenderPipelineTest.cs

/Assets/GraphicsTests/Assets.meta → /Assets/GraphicsTests/RenderPipeline/LowEndMobilePipeline/Assets.meta

/Assets/GraphicsTests/Assets → /Assets/GraphicsTests/RenderPipeline/LowEndMobilePipeline/Assets

/Assets/GraphicsTests/GotoNextScene.cs → /Assets/GraphicsTests/Framework/GotoNextScene.cs

/Assets/GraphicsTests/GotoNextScene.cs.meta → /Assets/GraphicsTests/Framework/GotoNextScene.cs.meta

/ImageTemplates/LowEnd → /ImageTemplates/LowEndMobilePipeline/Scenes

/Assets/GraphicsTests/Scenes/LowEnd → /Assets/GraphicsTests/RenderPipeline/LowEndMobilePipeline/Scenes

正在加载...
取消
保存