比较提交

...
此合并请求有变更与目标分支冲突。
/ScriptableRenderPipeline/Core/TextureCache.cs
/Tests/CoreTests.meta
/Tests/CoreTests

1 次代码提交

作者 SHA1 备注 提交日期
Frédéric Vauchelles eb462aff Updated texture cache with texture update count property 7 年前
共有 7 个文件被更改,包括 98 次插入34 次删除
  1. 44
      ScriptableRenderPipeline/Core/TextureCache.cs
  2. 8
      Tests/CoreTests.meta
  3. 8
      Tests/CoreTests/Editor.meta
  4. 61
      Tests/CoreTests/Editor/TextureCacheTests.cs
  5. 11
      Tests/CoreTests/Editor/TextureCacheTests.cs.meta

44
ScriptableRenderPipeline/Core/TextureCache.cs


using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.Collections.Generic;
namespace UnityEngine.Experimental.Rendering
{

get
{
#if UNITY_EDITOR
switch (EditorUserBuildSettings.activeBuildTarget)
switch (UnityEditor.EditorUserBuildSettings.activeBuildTarget)
case BuildTarget.iOS:
case BuildTarget.Android:
case BuildTarget.Tizen:
case BuildTarget.WSAPlayer:
case UnityEditor.BuildTarget.iOS:
case UnityEditor.BuildTarget.Android:
case UnityEditor.BuildTarget.Tizen:
case UnityEditor.BuildTarget.WSAPlayer:
// Note: We return true on purpose even if Windows Store Apps are running on Desktop.
return true;
default:

var probeFormat = TextureFormat.BC6H;
// On editor the texture is uncompressed when operating against mobile build targets
//#if UNITY_2017_2_OR_NEWER
//#else
// if (SystemInfo.SupportsTextureFormat(probeFormat) && !TextureCache.isMobileBuildTarget)
// format = probeFormat;
//#endif
return format;
}

{
get
{
//#if UNITY_2017_2_OR_NEWER
//#else
// return (SystemInfo.supportsCubemapArrayTextures && !TextureCache.isMobileBuildTarget);
//#endif
}
}

public uint countLRU;
#if UNITY_EDITOR
public Hash128 hash;
#endif
public uint updateCount;
};
private int m_NumTextures;

return sliceIndex;
var texId = (uint)texture.GetInstanceID();
#if UNITY_EDITOR
var hash = texture.imageContentsHash;
#endif
var updateCount = texture.updateCount;
//assert(TexID!=g_InvalidTexID);
if (texId == g_InvalidTexID) return 0;

Debug.Assert(m_SliceArray[sliceIndex].texId == texId);
bFoundAvailOrExistingSlice = true;
#if UNITY_EDITOR
bSwapSlice = bSwapSlice || (m_SliceArray[sliceIndex].hash != hash);
#endif
bSwapSlice = bSwapSlice || (m_SliceArray[sliceIndex].updateCount != updateCount);
}
// If no existing copy found in the array

if (bSwapSlice) // if this was a miss
{
#if UNITY_EDITOR
m_SliceArray[sliceIndex].hash = hash;
#endif
m_SliceArray[sliceIndex].updateCount = updateCount;
// transfer new slice to sliceIndex from source texture
TransferToSlice(sliceIndex, texture);

{
if (m_SliceArray[i].countLRU < g_MaxFrameCount) ++m_SliceArray[i].countLRU; // next frame
}
//for(int q=1; q<m_numTextures; q++)
// assert(m_SliceArray[m_SortedIdxArray[q-1]].CountLRU>=m_SliceArray[m_SortedIdxArray[q]].CountLRU);
}
protected TextureCache()

8
Tests/CoreTests.meta


fileFormatVersion: 2
guid: f7dbbd5a5c998eb45af5af9e5702fc0c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Tests/CoreTests/Editor.meta


fileFormatVersion: 2
guid: aedf4443dd1f470469570e170988015e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

61
Tests/CoreTests/Editor/TextureCacheTests.cs


using NUnit.Framework;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
namespace UnityEditor.Experimental.Rendering
{
public class TextureCacheCounter : TextureCache
{
public int transferToSliceCallCount { get; private set; }
public TextureCacheCounter()
{
AllocTextureArray(8);
}
public override void TransferToSlice(int sliceIndex, Texture texture)
{
++transferToSliceCallCount;
}
}
[TestFixture]
public class TextureCacheTests
{
Texture2D m_Tex;
const int k_TextureSize = 8;
static readonly Color[] s_Pixels = new Color[k_TextureSize * k_TextureSize];
[OneTimeSetUp]
public void Setup()
{
m_Tex = new Texture2D(k_TextureSize, k_TextureSize, TextureFormat.ARGB32, false, true);
SetTextureColor(Color.blue); }
[Test]
public void TextureCacheAddSlice()
{
var cache = new TextureCacheCounter();
var slice = cache.FetchSlice(m_Tex);
Assert.True(slice >= 0);
Assert.AreEqual(1, cache.transferToSliceCallCount);
var slice2 = cache.FetchSlice(m_Tex);
Assert.AreEqual(slice, slice2);
Assert.AreEqual(1, cache.transferToSliceCallCount);
SetTextureColor(Color.red);
var slice3 = cache.FetchSlice(m_Tex);
Assert.AreEqual(slice, slice3);
Assert.AreEqual(2, cache.transferToSliceCallCount); }
void SetTextureColor(Color col)
{
for (var i = 0; i < s_Pixels.Length; ++i)
s_Pixels[i] = Color.blue;
m_Tex.SetPixels(s_Pixels);
m_Tex.Apply();
}
}
}

11
Tests/CoreTests/Editor/TextureCacheTests.cs.meta


fileFormatVersion: 2
guid: ac8bd2a0373f2d24782ffb8d77e7512d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存