浏览代码

Merge pull request #993 from Unity-Technologies/leak-fix

Fixed a leak in the decal system
/main
GitHub 7 年前
当前提交
b3c966b0
共有 3 个文件被更改,包括 26 次插入18 次删除
  1. 12
      ScriptableRenderPipeline/Core/CoreRP/TextureCache.cs
  2. 30
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalSystem.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs

12
ScriptableRenderPipeline/Core/CoreRP/TextureCache.cs


using System;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.Rendering;
#if UNITY_EDITOR

public void Release()
{
Texture.DestroyImmediate(m_Cache); // do I need this?
CoreUtils.Destroy(m_Cache);
}
}

{
m_CubeMipLevelPropName = Shader.PropertyToID("_cubeMipLvl");
m_cubeSrcTexPropName = Shader.PropertyToID("_srcCubeTexture");
}
}
else

{
if (m_CacheNoCubeArray)
{
Texture.DestroyImmediate(m_CacheNoCubeArray);
CoreUtils.Destroy(m_CacheNoCubeArray);
if (m_CubeBlitMaterial) Material.DestroyImmediate(m_CubeBlitMaterial);
CoreUtils.Destroy(m_CubeBlitMaterial);
if (m_Cache)
Texture.DestroyImmediate(m_Cache);
CoreUtils.Destroy(m_Cache);
}
private void TransferToPanoCache(CommandBuffer cmd, int sliceIndex, Texture texture)

30
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalSystem.cs


// Core\CoreRP\ShaderLibrary\UnityInstancing.hlsl
// #if defined(SHADER_API_VULKAN) && defined(SHADER_API_MOBILE)
// #define UNITY_INSTANCED_ARRAY_SIZE 250
private const int kDrawIndexedBatchSize = 250;
private const int kDrawIndexedBatchSize = 250;
// cube mesh bounds for decal
static Vector4 kMin = new Vector4(-0.5f, -1.0f, -0.5f, 1.0f);

m_DiffuseTexture = m_Material.GetTexture("_BaseColorMap");
m_NormalTexture = m_Material.GetTexture("_NormalMap");
m_MaskTexture = m_Material.GetTexture("_MaskMap");
m_Blend = m_Material.GetFloat("_DecalBlend");
m_Blend = m_Material.GetFloat("_DecalBlend");
}
public DecalSet(Material material)

normalToWorldBatch[instanceCount].m23 = m_NormalTexIndex;
normalToWorldBatch[instanceCount].m33 = m_MaskTexIndex;
// clustered forward data
m_DecalDatas[m_DecalDatasCount].worldToDecal = decalToWorldBatch[instanceCount].inverse;
// clustered forward data
m_DecalDatas[m_DecalDatasCount].worldToDecal = decalToWorldBatch[instanceCount].inverse;
instanceCount++;
if (instanceCount == kDrawIndexedBatchSize)
{

InitializeMaterialValues(); // refresh in case they changed in the UI
UpdateTextureCache(cmd);
}
public void RenderIntoDBuffer(CommandBuffer cmd)
{
if(m_NumResults == 0)

{
m_PropertyBlock.SetMatrixArray(HDShaderIDs._NormalToWorldID, m_NormalToWorld[batchIndex]);
cmd.DrawMeshInstanced(m_DecalMesh, 0, KeyMaterial, 0, m_DecalToWorld[batchIndex], totalToDraw, m_PropertyBlock);
}
}
public Material KeyMaterial
{
get

private int m_NormalTexIndex = -1;
private int m_MaskTexIndex = -1;
}
public void AddDecal(DecalProjectorComponent decal)
{
if (decal.CullIndex != DecalProjectorComponent.kInvalidIndex) //do not add the same decal more than once

foreach (var pair in m_DecalSets)
{
pair.Value.RenderIntoDBuffer(cmd);
}
}
}
public void SetAtlas(CommandBuffer cmd)

public void CreateDrawData()
{
m_DecalDatasCount = 0;
m_DecalDatasCount = 0;
// reallocate if needed
if (m_DecalsVisibleThisFrame > m_DecalDatas.Length)
{

{
pair.Value.CreateDrawData();
}
}
public void Cleanup()
{
m_DecalAtlas.Release();
CoreUtils.Destroy(m_DecalMesh);
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


// For debugging
MousePositionDebug.instance.Cleanup();
DecalSystem.instance.Cleanup();
m_MaterialList.ForEach(material => material.Cleanup());
CoreUtils.Destroy(m_CopyStencilForNoLighting);

正在加载...
取消
保存