Remove Unlink from asset reference

This commit is contained in:
Wojtek Figat
2021-02-10 11:37:14 +01:00
parent adbb467206
commit 81e41d51c8
35 changed files with 80 additions and 124 deletions

View File

@@ -138,7 +138,7 @@ bool ViewportIconsRendererService::Init()
void ViewportIconsRendererService::Dispose()
{
QuadModel.Unlink();
QuadModel = nullptr;
for (int32 i = 0; i < ARRAY_COUNT(InstanceBuffers); i++)
InstanceBuffers[i].Release();
ActorTypeToIconType.Clear();

View File

@@ -78,14 +78,6 @@ public:
return _asset ? _asset->GetOrCreateManagedInstance() : nullptr;
}
/// <summary>
/// Clears the asset reference.
/// </summary>
FORCE_INLINE void Unlink()
{
OnSet(nullptr);
}
/// <summary>
/// Gets the asset property value as string.
/// </summary>
@@ -135,7 +127,7 @@ protected:
if (_asset == asset)
{
Unload();
Unlink();
OnSet(nullptr);
}
}
};

View File

@@ -38,7 +38,7 @@ Asset::LoadResult SkeletonMask::load()
void SkeletonMask::unload(bool isReloading)
{
Skeleton.Unlink();
Skeleton = nullptr;
_maskedNodes.Resize(0);
_mask.Resize(0);
}

View File

@@ -487,7 +487,7 @@ void DebugDrawService::Dispose()
DebugDrawPsDepthTest.Release();
DebugDrawPsDepthTest.Release();
SAFE_DELETE(DebugDrawVB);
DebugDrawShader.Unlink();
DebugDrawShader = nullptr;
}
void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTextureView* depthBuffer, bool enableDepthTest)

View File

@@ -201,7 +201,7 @@ void Foliage::RemoveFoliageType(int32 index)
FoliageTypes[i].Index--;
}
auto& item = FoliageTypes[index];
item.Model.Unlink();
item.Model = nullptr;
item.Entries.Release();
FoliageTypes.RemoveAtKeepOrder(index);

View File

@@ -13,10 +13,10 @@
#include "Engine/Platform/Windows/WindowsWindow.h"
#include "Engine/Render2D/Render2D.h"
#include "Engine/Engine/CommandLine.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Engine/EngineService.h"
#include "Engine/Profiler/Profiler.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Core/Utilities.h"
GPUPipelineState* GPUPipelineState::Spawn(const SpawnParams& params)
@@ -230,10 +230,10 @@ void GPUDevice::preDispose()
RenderTargetPool::Flush();
// Release resources
_res->DefaultMaterial.Unlink();
_res->DefaultNormalMap.Unlink();
_res->DefaultWhiteTexture.Unlink();
_res->DefaultBlackTexture.Unlink();
_res->DefaultMaterial = nullptr;
_res->DefaultNormalMap = nullptr;
_res->DefaultWhiteTexture = nullptr;
_res->DefaultBlackTexture = nullptr;
SAFE_DELETE_GPU_RESOURCE(_res->PS_CopyLinear);
SAFE_DELETE_GPU_RESOURCE(_res->PS_Clear);
SAFE_DELETE_GPU_RESOURCE(_res->FullscreenTriangleVB);

View File

@@ -79,7 +79,7 @@ void Lightmap::EnsureSize(int32 size)
{
// Unlink texture that cannot be loaded
LOG(Warning, "Lightmap::EnsureSize failed to load texture");
texture.Unlink();
texture = nullptr;
}
else
{
@@ -88,7 +88,7 @@ void Lightmap::EnsureSize(int32 size)
{
// Unlink texture and import new with valid size
LOG(Info, "Changing lightmap {0}:{1} size from {2} to {3}", _index, textureIndex, texture->GetTexture()->Size(), size);
texture.Unlink();
texture = nullptr;
}
}
}

View File

@@ -298,8 +298,8 @@ void Scene::OnDeleteObject()
{
// Cleanup
LightmapsData.UnloadLightmaps();
CSGData.Model.Unlink();
CSGData.CollisionData.Unlink();
CSGData.Model = nullptr;
CSGData.CollisionData = nullptr;
// Base
Actor::OnDeleteObject();

View File

@@ -40,8 +40,7 @@ void NavMesh::SaveNavMesh()
// Check if has no navmesh data generated (someone could just remove navmesh volumes or generate for empty scene)
if (Data.Tiles.IsEmpty())
{
// Keep asset reference valid
DataAsset.Unlink();
DataAsset = nullptr;
return;
}

View File

@@ -557,7 +557,7 @@ void OnShaderReloading(Asset* obj)
void CleanupGPUParticlesSorting()
{
GPUParticlesSorting.Unlink();
GPUParticlesSorting = nullptr;
}
void DrawEmitterGPU(RenderContext& renderContext, ParticleBuffer* buffer, DrawCall& drawCall, DrawPass drawModes, StaticFlags staticFlags, ParticleEmitterInstance& emitterData, const RenderModulesIndices& renderModulesIndices)

View File

@@ -522,7 +522,7 @@ void Render2DService::Dispose()
Lines.Resize(0);
Lines2.Resize(0);
GUIShader.Unlink();
GUIShader = nullptr;
PsoDepth.Dispose();
PsoNoDepth.Dispose();

View File

@@ -196,7 +196,7 @@ void AmbientOcclusionPass::Dispose()
SAFE_DELETE_GPU_RESOURCE(_psApplyHalf);
// Release asset
_shader.Unlink();
_shader = nullptr;
}
void AmbientOcclusionPass::Render(RenderContext& renderContext)

View File

@@ -55,11 +55,9 @@ void FXAA::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline state
// Cleanup
_psFXAA.Delete();
// Release asset
_shader.Unlink();
_shader = nullptr;
}
void FXAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureView* output)

View File

@@ -82,15 +82,13 @@ void SMAA::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline states
// Cleanup
_psEdge.Delete();
_psBlend.Delete();
SAFE_DELETE_GPU_RESOURCE(_psNeighbor);
// Release assets
_shader.Unlink();
_areaTex.Unlink();
_searchTex.Unlink();
_shader = nullptr;
_areaTex = nullptr;
_searchTex = nullptr;
}
void SMAA::Render(RenderContext& renderContext, GPUTexture* input, GPUTextureView* output)

View File

@@ -42,8 +42,9 @@ void TAA::Dispose()
// Base
RendererPass::Dispose();
// Cleanup
_psTAA = nullptr;
_shader.Unlink();
_shader = nullptr;
}
bool TAA::NeedMotionVectors(RenderContext& renderContext)

View File

@@ -305,7 +305,7 @@ void release()
SAFE_DELETE_GPU_RESOURCE(_psInscatterS);
SAFE_DELETE_GPU_RESOURCE(_psInscatterN);
SAFE_DELETE_GPU_RESOURCE(_psCopyInscatterNAdd);
_shader.Unlink();
_shader = nullptr;
SAFE_DELETE(_task);
SAFE_DELETE_GPU_RESOURCE(AtmosphereTransmittance);
SAFE_DELETE_GPU_RESOURCE(AtmosphereIrradiance);

View File

@@ -121,11 +121,9 @@ void ColorGradingPass::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline state
// Cleanup
_psLut.Delete();
// Release assets
_shader.Unlink();
_shader = nullptr;
}
GPUTexture* ColorGradingPass::RenderLUT(RenderContext& renderContext)

View File

@@ -66,21 +66,17 @@ void DepthOfFieldPass::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline states
// Cleanup
SAFE_DELETE_GPU_RESOURCE(_psDofDepthBlurGeneration);
SAFE_DELETE_GPU_RESOURCE(_psBokehGeneration);
SAFE_DELETE_GPU_RESOURCE(_psDoNotGenerateBokeh);
SAFE_DELETE_GPU_RESOURCE(_psBokeh);
SAFE_DELETE_GPU_RESOURCE(_psBokehComposite);
// Release assets
_shader.Unlink();
_defaultBokehHexagon.Unlink();
_defaultBokehOctagon.Unlink();
_defaultBokehCircle.Unlink();
_defaultBokehCross.Unlink();
// Release resources
_shader = nullptr;
_defaultBokehHexagon = nullptr;
_defaultBokehOctagon = nullptr;
_defaultBokehCircle = nullptr;
_defaultBokehCross = nullptr;
SAFE_DELETE_GPU_RESOURCE(_bokehBuffer);
SAFE_DELETE_GPU_RESOURCE(_bokehIndirectArgsBuffer);
}

View File

@@ -244,15 +244,13 @@ void EyeAdaptationPass::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline states
// Cleanup
SAFE_DELETE_GPU_RESOURCE(_psManual);
SAFE_DELETE_GPU_RESOURCE(_psLuminanceMap);
SAFE_DELETE_GPU_RESOURCE(_psBlendLuminance);
SAFE_DELETE_GPU_RESOURCE(_psApplyLuminance);
SAFE_DELETE_GPU_RESOURCE(_psHistogram);
// Release asset
_shader.Unlink();
_shader = nullptr;
}
bool EyeAdaptationPass::setupResources()

View File

@@ -62,11 +62,9 @@ void ForwardPass::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline states
// Cleanup
SAFE_DELETE_GPU_RESOURCE(_psApplyDistortion);
// Release assets
_shader.Unlink();
_shader = nullptr;
}
void ForwardPass::Render(RenderContext& renderContext, GPUTexture* input, GPUTexture* output)

View File

@@ -77,14 +77,11 @@ void GBufferPass::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline state
// Cleanup
SAFE_DELETE_GPU_RESOURCE(_psDebug);
// Release assets
_gBufferShader.Unlink();
_skyModel.Unlink();
_boxModel.Unlink();
_gBufferShader = nullptr;
_skyModel = nullptr;
_boxModel = nullptr;
#if USE_EDITOR
SAFE_DELETE(_lightmapUVsDensityMaterialShader);
SAFE_DELETE(_vertexColorsMaterialShader);

View File

@@ -102,8 +102,9 @@ void HistogramPass::Dispose()
// Base
RendererPass::Dispose();
// Cleanup
SAFE_DELETE_GPU_RESOURCE(_histogramBuffer);
_shader.Unlink();
_shader = nullptr;
}
bool HistogramPass::setupResources()

View File

@@ -164,7 +164,7 @@ void LightPass::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline states
// Cleanup
_psLightDir.Delete();
_psLightPointNormal.Delete();
_psLightPointInverted.Delete();
@@ -172,9 +172,7 @@ void LightPass::Dispose()
_psLightSpotInverted.Delete();
SAFE_DELETE_GPU_RESOURCE(_psLightSkyNormal);
SAFE_DELETE_GPU_RESOURCE(_psLightSkyInverted);
// Release assets
_sphereModel.Unlink();
_sphereModel = nullptr;
}
void LightPass::RenderLight(RenderContext& renderContext, GPUTextureView* lightBuffer)

View File

@@ -134,16 +134,14 @@ void MotionBlurPass::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline state
// Cleanup
SAFE_DELETE_GPU_RESOURCE(_psCameraMotionVectors);
SAFE_DELETE_GPU_RESOURCE(_psMotionVectorsDebug);
SAFE_DELETE_GPU_RESOURCE(_psTileMax);
SAFE_DELETE_GPU_RESOURCE(_psTileMaxVariable);
SAFE_DELETE_GPU_RESOURCE(_psNeighborMax);
SAFE_DELETE_GPU_RESOURCE(_psMotionBlur);
// Release asset
_shader.Unlink();
_shader = nullptr;
}
void MotionBlurPass::RenderMotionVectors(RenderContext& renderContext)

View File

@@ -167,19 +167,17 @@ void PostProcessingPass::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline states
// Cleanup
SAFE_DELETE_GPU_RESOURCE(_psThreshold);
SAFE_DELETE_GPU_RESOURCE(_psScale);
SAFE_DELETE_GPU_RESOURCE(_psBlurH);
SAFE_DELETE_GPU_RESOURCE(_psBlurV);
SAFE_DELETE_GPU_RESOURCE(_psGenGhosts);
_psComposite.Delete();
// Release assets
_shader.Unlink();
_defaultLensColor.Unlink();
_defaultLensDirt.Unlink();
_defaultLensStar.Unlink();
_shader = nullptr;
_defaultLensColor = nullptr;
_defaultLensDirt = nullptr;
_defaultLensStar = nullptr;
}
void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input, GPUTexture* output, GPUTexture* colorGradingLUT)

View File

@@ -333,7 +333,7 @@ void ProbesRenderer::Release()
SAFE_DELETE_GPU_RESOURCE(_psAccDiffuseIrradiance);
SAFE_DELETE_GPU_RESOURCE(_psAccumulateCubeFaces);
SAFE_DELETE_GPU_RESOURCE(_psCopyFrameLHB);
_shader.Unlink();
_shader = nullptr;
SAFE_DELETE_GPU_RESOURCE(_output);
SAFE_DELETE(_task);
SAFE_DELETE_GPU_RESOURCE(_probe);

View File

@@ -324,15 +324,13 @@ void ReflectionsPass::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline states
// Cleanup
SAFE_DELETE_GPU_RESOURCE(_psProbeNormal);
SAFE_DELETE_GPU_RESOURCE(_psProbeInverted);
SAFE_DELETE_GPU_RESOURCE(_psCombinePass);
// Release assets
_shader.Unlink();
_sphereModel.Unlink();
_preIntegratedGF.Unlink();
_shader = nullptr;
_sphereModel = nullptr;
_preIntegratedGF = nullptr;
}
bool sortProbes(EnvironmentProbe* const& p1, EnvironmentProbe* const& p2)

View File

@@ -152,16 +152,14 @@ void ScreenSpaceReflectionsPass::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline states
// Cleanup
SAFE_DELETE_GPU_RESOURCE(_psRayTracePass);
SAFE_DELETE_GPU_RESOURCE(_psCombinePass);
SAFE_DELETE_GPU_RESOURCE(_psTemporalPass);
SAFE_DELETE_GPU_RESOURCE(_psMixPass);
_psResolvePass.Delete();
// Release assets
_shader.Unlink();
_preIntegratedGF.Unlink();
_shader = nullptr;
_preIntegratedGF = nullptr;
}
void ScreenSpaceReflectionsPass::Render(RenderContext& renderContext, GPUTextureView* reflectionsRT, GPUTextureView* lightBuffer)

View File

@@ -193,11 +193,12 @@ void ShadowsPass::Dispose()
// Base
RendererPass::Dispose();
// Cleanup
_psShadowDir.Delete();
_psShadowPoint.Delete();
_psShadowSpot.Delete();
_shader.Unlink();
_sphereModel.Unlink();
_shader = nullptr;
_sphereModel = nullptr;
SAFE_DELETE_GPU_RESOURCE(_shadowMapCSM);
SAFE_DELETE_GPU_RESOURCE(_shadowMapCube);
}

View File

@@ -69,7 +69,7 @@ void BitonicSort::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline states
// Cleanup
SAFE_DELETE_GPU_RESOURCE(_dispatchArgsBuffer);
_cb = nullptr;
_indirectArgsCS = nullptr;
@@ -77,9 +77,7 @@ void BitonicSort::Dispose()
_innerSortCS = nullptr;
_outerSortCS = nullptr;
_copyIndicesCS = nullptr;
// Release asset
_shader.Unlink();
_shader = nullptr;
}
void BitonicSort::Sort(GPUContext* context, GPUBuffer* sortingKeysBuffer, GPUBuffer* countBuffer, uint32 counterOffset, bool sortAscending, GPUBuffer* sortedIndicesBuffer)

View File

@@ -81,14 +81,12 @@ void MultiScaler::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline states
// Cleanup
SAFE_DELETE_GPU_RESOURCE(_psHalfDepth);
_psBlur5.Delete();
_psBlur9.Delete();
_psBlur13.Delete();
// Release asset
_shader.Unlink();
_shader = nullptr;
}
void MultiScaler::Filter(const FilterMode mode, GPUContext* context, const int32 width, const int32 height, GPUTextureView* src, GPUTextureView* dst, GPUTextureView* tmp)
@@ -121,7 +119,7 @@ void MultiScaler::Filter(const FilterMode mode, GPUContext* context, const int32
ps = &_psBlur13;
break;
default:
CRASH;
CRASH;
return;
}
@@ -177,7 +175,7 @@ void MultiScaler::Filter(const FilterMode mode, GPUContext* context, const int32
ps = &_psBlur13;
break;
default:
CRASH;
CRASH;
return;
}

View File

@@ -89,26 +89,19 @@ void VolumetricFogPass::Dispose()
// Base
RendererPass::Dispose();
// Delete pipeline states
// Cleanup
_psInjectLight.Delete();
_csInitialize = nullptr;
_csLightScattering.Clear();
_csFinalIntegration = nullptr;
SAFE_DELETE_GPU_RESOURCE(_vbCircleRasterize);
SAFE_DELETE_GPU_RESOURCE(_ibCircleRasterize);
// Release assets
_shader.Unlink();
_shader = nullptr;
}
float ComputeZSliceFromDepth(float SceneDepth, const VolumetricFogOptions& options, int32 GridSizeZ)
float ComputeZSliceFromDepth(float sceneDepth, const VolumetricFogOptions& options, int32 gridSizeZ)
{
// This must match frustum voxels depth distribution
// See ComputeNormalizedZSliceFromDepth() in VolumetricFog.shader
return SceneDepth / options.Distance * GridSizeZ;
return sceneDepth / options.Distance * (float)gridSizeZ;
}
bool VolumetricFogPass::Init(RenderContext& renderContext, GPUContext* context, VolumetricFogOptions& options)

View File

@@ -499,7 +499,7 @@ void ShadowsOfMordor::Builder::releaseResources()
SAFE_DELETE_GPU_RESOURCE(_psRenderCacheModel);
SAFE_DELETE_GPU_RESOURCE(_psRenderCacheTerrain);
SAFE_DELETE_GPU_RESOURCE(_psBlurCache);
_shader.Unlink();
_shader = nullptr;
SAFE_DELETE_GPU_RESOURCE(_irradianceReduction);

View File

@@ -21,7 +21,7 @@ void TerrainChunk::Init(TerrainPatch* patch, uint16 x, uint16 z)
_yHeight = 1;
_heightmapUVScaleBias = Vector4(1.0f, 1.0f, _x, _z) * (1.0f / TerrainPatch::CHUNKS_COUNT_EDGE);
_perInstanceRandom = (_patch->_terrain->_id.C ^ _x ^ _z) * (1.0f / MAX_uint32);
OverrideMaterial.Unlink();
OverrideMaterial = nullptr;
}
bool TerrainChunk::PrepareDraw(const RenderContext& renderContext)

View File

@@ -64,12 +64,12 @@ void TerrainPatch::Init(Terrain* terrain, int16 x, int16 z)
{
Chunks[i].Init(this, i % CHUNKS_COUNT_EDGE, i / CHUNKS_COUNT_EDGE);
}
Heightmap.Unlink();
Heightmap = nullptr;
for (int32 i = 0; i < TERRAIN_MAX_SPLATMAPS_COUNT; i++)
{
Splatmap[i].Unlink();
Splatmap[i] = nullptr;
}
_heightfield.Unlink();
_heightfield = nullptr;
#if TERRAIN_UPDATING
_cachedHeightMap.Resize(0);
_cachedHolesMask.Resize(0);